blob: 4e71bbaa195479c2b63ba822529ada314e1690ca [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 Iwai1194b5b2007-10-10 10:04:26 +020052 STAC_9200_GATEWAY,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010053 STAC_9200_MODELS
54};
55
56enum {
57 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020058 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020059 STAC_9205_DELL_M43,
60 STAC_9205_DELL_M44,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010061 STAC_9205_MODELS
62};
63
64enum {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010065 STAC_92HD73XX_REF,
66 STAC_92HD73XX_MODELS
67};
68
69enum {
Matthew Ranostaye035b842007-11-06 11:53:55 +010070 STAC_92HD71BXX_REF,
71 STAC_92HD71BXX_MODELS
72};
73
74enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010075 STAC_925x_REF,
76 STAC_M2_2,
77 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020078 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +010079 STAC_925x_MODELS
80};
81
82enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +010083 STAC_D945_REF,
84 STAC_D945GTP3,
85 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +020086 STAC_INTEL_MAC_V1,
87 STAC_INTEL_MAC_V2,
88 STAC_INTEL_MAC_V3,
89 STAC_INTEL_MAC_V4,
90 STAC_INTEL_MAC_V5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020091 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +010092 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +010093 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +010094 STAC_MACBOOK_PRO_V1,
95 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +020096 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +020097 STAC_IMAC_INTEL_20,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020098 STAC_922X_DELL_D81,
99 STAC_922X_DELL_D82,
100 STAC_922X_DELL_M81,
101 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100102 STAC_922X_MODELS
103};
104
105enum {
106 STAC_D965_REF,
107 STAC_D965_3ST,
108 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200109 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100110 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100111 STAC_927X_MODELS
112};
Matt Porter403d1942005-11-29 15:00:51 +0100113
Matt2f2f4252005-04-13 14:45:30 +0200114struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100115 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200116 unsigned int num_mixers;
117
Matt Porter403d1942005-11-29 15:00:51 +0100118 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +0200119 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +0100120 unsigned int line_switch: 1;
121 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100122 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100123 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +0200124 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200125
Takashi Iwai82599802007-07-31 15:56:24 +0200126 unsigned int gpio_mask, gpio_data;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100127 unsigned char aloopback_mask;
128 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200129
Matt2f2f4252005-04-13 14:45:30 +0200130 /* playback */
131 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100132 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200133
134 /* capture */
135 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200136 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200137 hda_nid_t *mux_nids;
138 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200139 hda_nid_t *dmic_nids;
140 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100141 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100142 unsigned int num_dmuxes;
Mattdabbed62005-06-14 10:19:34 +0200143 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +0200144
Matt2f2f4252005-04-13 14:45:30 +0200145 /* pin widgets */
146 hda_nid_t *pin_nids;
147 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200148 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200149 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200150
151 /* codec specific stuff */
152 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100153 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200154
155 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200156 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100157 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200158 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100159 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200160
Matt Porter403d1942005-11-29 15:00:51 +0100161 /* i/o switches */
162 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200163 unsigned int clfe_swap;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200164 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200165
Mattc7d4b2f2005-06-27 14:59:41 +0200166 struct hda_pcm pcm_rec[2]; /* PCM information */
167
168 /* dynamic controls and input_mux */
169 struct auto_pin_cfg autocfg;
170 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100171 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200172 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200173 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200174};
175
176static hda_nid_t stac9200_adc_nids[1] = {
177 0x03,
178};
179
180static hda_nid_t stac9200_mux_nids[1] = {
181 0x0c,
182};
183
184static hda_nid_t stac9200_dac_nids[1] = {
185 0x02,
186};
187
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100188static hda_nid_t stac92hd73xx_adc_nids[2] = {
189 0x1a, 0x1b
190};
191
192#define STAC92HD73XX_NUM_DMICS 2
193static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
194 0x13, 0x14, 0
195};
196
197#define STAC92HD73_DAC_COUNT 5
198static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
199 0x15, 0x16, 0x17, 0x18, 0x19,
200};
201
202static hda_nid_t stac92hd73xx_mux_nids[4] = {
203 0x28, 0x29, 0x2a, 0x2b,
204};
205
206static hda_nid_t stac92hd73xx_dmux_nids[2] = {
207 0x20, 0x21,
208};
209
Matthew Ranostaye035b842007-11-06 11:53:55 +0100210static hda_nid_t stac92hd71bxx_adc_nids[2] = {
211 0x12, 0x13,
212};
213
214static hda_nid_t stac92hd71bxx_mux_nids[2] = {
215 0x1a, 0x1b
216};
217
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100218static hda_nid_t stac92hd71bxx_dmux_nids[1] = {
219 0x1c,
220};
221
Matthew Ranostaye035b842007-11-06 11:53:55 +0100222static hda_nid_t stac92hd71bxx_dac_nids[2] = {
223 0x10, /*0x11, */
224};
225
226#define STAC92HD71BXX_NUM_DMICS 2
227static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
228 0x18, 0x19, 0
229};
230
Tobin Davis8e21c342007-01-08 11:04:17 +0100231static hda_nid_t stac925x_adc_nids[1] = {
232 0x03,
233};
234
235static hda_nid_t stac925x_mux_nids[1] = {
236 0x0f,
237};
238
239static hda_nid_t stac925x_dac_nids[1] = {
240 0x02,
241};
242
Takashi Iwaif6e98522007-10-16 14:27:04 +0200243#define STAC925X_NUM_DMICS 1
244static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
245 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200246};
247
Takashi Iwai1697055e2007-12-18 18:05:52 +0100248static hda_nid_t stac925x_dmux_nids[1] = {
249 0x14,
250};
251
Matt2f2f4252005-04-13 14:45:30 +0200252static hda_nid_t stac922x_adc_nids[2] = {
253 0x06, 0x07,
254};
255
256static hda_nid_t stac922x_mux_nids[2] = {
257 0x12, 0x13,
258};
259
Matt Porter3cc08dc2006-01-23 15:27:49 +0100260static hda_nid_t stac927x_adc_nids[3] = {
261 0x07, 0x08, 0x09
262};
263
264static hda_nid_t stac927x_mux_nids[3] = {
265 0x15, 0x16, 0x17
266};
267
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100268static hda_nid_t stac927x_dmux_nids[1] = {
269 0x1b,
270};
271
Matthew Ranostay7f168592007-10-18 17:38:17 +0200272#define STAC927X_NUM_DMICS 2
273static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
274 0x13, 0x14, 0
275};
276
Matt Porterf3302a52006-07-31 12:49:34 +0200277static hda_nid_t stac9205_adc_nids[2] = {
278 0x12, 0x13
279};
280
281static hda_nid_t stac9205_mux_nids[2] = {
282 0x19, 0x1a
283};
284
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100285static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100286 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100287};
288
Takashi Iwaif6e98522007-10-16 14:27:04 +0200289#define STAC9205_NUM_DMICS 2
290static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
291 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200292};
293
Mattc7d4b2f2005-06-27 14:59:41 +0200294static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200295 0x08, 0x09, 0x0d, 0x0e,
296 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200297};
298
Tobin Davis8e21c342007-01-08 11:04:17 +0100299static hda_nid_t stac925x_pin_nids[8] = {
300 0x07, 0x08, 0x0a, 0x0b,
301 0x0c, 0x0d, 0x10, 0x11,
302};
303
Matt2f2f4252005-04-13 14:45:30 +0200304static hda_nid_t stac922x_pin_nids[10] = {
305 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
306 0x0f, 0x10, 0x11, 0x15, 0x1b,
307};
308
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100309static hda_nid_t stac92hd73xx_pin_nids[12] = {
310 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
311 0x0f, 0x10, 0x11, 0x12, 0x13,
312 0x14, 0x22
313};
314
Matthew Ranostaye035b842007-11-06 11:53:55 +0100315static hda_nid_t stac92hd71bxx_pin_nids[10] = {
316 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
317 0x0f, 0x14, 0x18, 0x19, 0x1e,
318};
319
Matt Porter3cc08dc2006-01-23 15:27:49 +0100320static hda_nid_t stac927x_pin_nids[14] = {
321 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
322 0x0f, 0x10, 0x11, 0x12, 0x13,
323 0x14, 0x21, 0x22, 0x23,
324};
325
Matt Porterf3302a52006-07-31 12:49:34 +0200326static hda_nid_t stac9205_pin_nids[12] = {
327 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
328 0x0f, 0x14, 0x16, 0x17, 0x18,
329 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200330};
331
Matt Porter8b657272006-10-26 17:12:59 +0200332static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
333 struct snd_ctl_elem_info *uinfo)
334{
335 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
336 struct sigmatel_spec *spec = codec->spec;
337 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
338}
339
340static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
341 struct snd_ctl_elem_value *ucontrol)
342{
343 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
344 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100345 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200346
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100347 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200348 return 0;
349}
350
351static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
352 struct snd_ctl_elem_value *ucontrol)
353{
354 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
355 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100356 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200357
358 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100359 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200360}
361
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100362static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200363{
364 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
365 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200366 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200367}
368
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100369static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200370{
371 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
372 struct sigmatel_spec *spec = codec->spec;
373 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
374
375 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
376 return 0;
377}
378
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100379static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200380{
381 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
382 struct sigmatel_spec *spec = codec->spec;
383 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
384
Mattc7d4b2f2005-06-27 14:59:41 +0200385 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200386 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
387}
388
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200389#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
390
391static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
392 struct snd_ctl_elem_value *ucontrol)
393{
394 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100395 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200396 struct sigmatel_spec *spec = codec->spec;
397
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100398 ucontrol->value.integer.value[0] = !!(spec->aloopback &
399 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200400 return 0;
401}
402
403static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
404 struct snd_ctl_elem_value *ucontrol)
405{
406 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100408 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200409 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100410 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200411
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100412 idx_val = spec->aloopback_mask << idx;
413 if (ucontrol->value.integer.value[0])
414 val = spec->aloopback | idx_val;
415 else
416 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100417 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200418 return 0;
419
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100420 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200421
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100422 /* Only return the bits defined by the shift value of the
423 * first two bytes of the mask
424 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200425 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100426 kcontrol->private_value & 0xFFFF, 0x0);
427 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200428
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100429 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200430 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100431 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200432 } else {
433 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100434 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200435 }
436
437 snd_hda_codec_write_cache(codec, codec->afg, 0,
438 kcontrol->private_value >> 16, dac_mode);
439
440 return 1;
441}
442
Mattc7d4b2f2005-06-27 14:59:41 +0200443static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200444 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200445 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200446 {}
447};
448
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200449static struct hda_verb stac9200_eapd_init[] = {
450 /* set dac0mux for dac converter */
451 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
452 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
453 {}
454};
455
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100456static struct hda_verb stac92hd73xx_6ch_core_init[] = {
457 /* set master volume and direct control */
458 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
459 /* setup audio connections */
460 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
461 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
462 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
463 /* setup adcs to point to mixer */
464 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
465 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
466 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Front Mic */
467 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Mic */
468 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Line In */
469 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
470 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
471 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
472 /* setup import muxs */
473 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
474 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
475 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
476 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
477 {}
478};
479
480static struct hda_verb stac92hd73xx_8ch_core_init[] = {
481 /* set master volume and direct control */
482 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
483 /* setup audio connections */
484 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
485 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
486 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
487 /* connect hp ports to dac3 */
488 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
489 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
490 /* setup adcs to point to mixer */
491 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
492 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
493 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Front Mic */
494 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Mic */
495 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Line In */
496 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
497 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
498 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
499 /* setup import muxs */
500 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
501 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
502 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
503 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
504 {}
505};
506
507static struct hda_verb stac92hd73xx_10ch_core_init[] = {
508 /* set master volume and direct control */
509 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
510 /* setup audio connections */
511 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
512 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
513 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
514 /* dac3 is connected to import3 mux */
515 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
516 /* connect hp ports to dac4 */
517 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
518 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
519 /* setup adcs to point to mixer */
520 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
521 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
522 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Front Mic */
523 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Mic */
524 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Line In */
525 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
526 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
527 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
528 /* setup import muxs */
529 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
530 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
531 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
532 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
533 {}
534};
535
Matthew Ranostaye035b842007-11-06 11:53:55 +0100536static struct hda_verb stac92hd71bxx_core_init[] = {
537 /* set master volume and direct control */
538 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
539 /* connect headphone jack to dac1 */
540 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100541 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
542 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
543 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
544 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
545 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
546 /* unmute mono out node */
547 { 0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
548};
549
550static struct hda_verb stac92hd71bxx_analog_core_init[] = {
551 /* set master volume and direct control */
552 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
553 /* connect headphone jack to dac1 */
554 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay9b359472007-11-07 13:03:12 +0100555 /* connect ports 0d and 0f to audio mixer */
556 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2},
557 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100558 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Matthew Ranostay9b359472007-11-07 13:03:12 +0100559 /* unmute dac0 input in audio mixer */
560 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100561 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
562 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
563 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
564 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
565 /* unmute mono out node */
566 { 0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
567 {}
568};
569
Tobin Davis8e21c342007-01-08 11:04:17 +0100570static struct hda_verb stac925x_core_init[] = {
571 /* set dac0mux for dac converter */
572 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
573 {}
574};
575
Mattc7d4b2f2005-06-27 14:59:41 +0200576static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200577 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200578 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200579 {}
580};
581
Tobin Davis93ed1502006-09-01 21:03:12 +0200582static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200583 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200584 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200585 /* unmute node 0x1b */
586 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
587 /* select node 0x03 as DAC */
588 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
589 {}
590};
591
Matt Porter3cc08dc2006-01-23 15:27:49 +0100592static struct hda_verb stac927x_core_init[] = {
593 /* set master volume and direct control */
594 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
595 {}
596};
597
Matt Porterf3302a52006-07-31 12:49:34 +0200598static struct hda_verb stac9205_core_init[] = {
599 /* set master volume and direct control */
600 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
601 {}
602};
603
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200604#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200605 { \
606 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
607 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200608 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200609 .info = stac92xx_mux_enum_info, \
610 .get = stac92xx_mux_enum_get, \
611 .put = stac92xx_mux_enum_put, \
612 }
613
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100614#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200615 { \
616 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
617 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100618 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200619 .info = stac92xx_aloopback_info, \
620 .get = stac92xx_aloopback_get, \
621 .put = stac92xx_aloopback_put, \
622 .private_value = verb_read | (verb_write << 16), \
623 }
624
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100625static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200626 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
627 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200628 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200629 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
630 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200631 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200632 { } /* end */
633};
634
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100635static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100636 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
637
638 /* hardware gain controls */
Matthew Ranostay71685b92007-12-14 12:07:31 +0100639 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x13, 0x0, HDA_INPUT),
640 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x14, 0x0, HDA_INPUT),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100641
642 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
643 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
644
645 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
646 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
647
648 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
649 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
650
651 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
652 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
653
654 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
655 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
656
657 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
658 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
659
660 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
661 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
662 { } /* end */
663};
664
665static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100666 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
667
668 /* hardware gain controls */
Matthew Ranostay71685b92007-12-14 12:07:31 +0100669 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x13, 0x0, HDA_INPUT),
670 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x14, 0x0, HDA_INPUT),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100671
672 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
673 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
674
675 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
676 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
677
678 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
679 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
680
681 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
682 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
683
684 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
685 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
686
687 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
688 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
689
690 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
691 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
692 { } /* end */
693};
694
695static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100696 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
697
698 /* hardware gain controls */
Matthew Ranostay71685b92007-12-14 12:07:31 +0100699 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x13, 0x0, HDA_INPUT),
700 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x14, 0x0, HDA_INPUT),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100701
702 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
703 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
704
705 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
706 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
707
708 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
709 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
710
711 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
712 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
713
714 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
715 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
716
717 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
718 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
719
720 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
721 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
722 { } /* end */
723};
724
Matthew Ranostay541eee82007-12-14 12:08:04 +0100725static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100726 STAC_INPUT_SOURCE(2),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100727
728 /* hardware gain controls */
Matthew Ranostay9b359472007-11-07 13:03:12 +0100729 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x18, 0x0, HDA_OUTPUT),
730 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x19, 0x0, HDA_OUTPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100731
Matthew Ranostay9b359472007-11-07 13:03:12 +0100732 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
733 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
734 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
735
736 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
737 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
738 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
739
740 HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT),
741 HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100742 { } /* end */
743};
744
Matthew Ranostay541eee82007-12-14 12:08:04 +0100745static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +0100746 STAC_INPUT_SOURCE(2),
747 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
748
749 /* hardware gain controls */
750 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x18, 0x0, HDA_OUTPUT),
751 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x19, 0x0, HDA_OUTPUT),
752
753 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
754 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
755 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
756
757 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
758 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
759 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
760 { } /* end */
761};
762
Tobin Davis8e21c342007-01-08 11:04:17 +0100763static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200764 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +0100765 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
766 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
767 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
768 { } /* end */
769};
770
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100771static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200772 STAC_INPUT_SOURCE(2),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100773 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200774
775 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
776 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
777 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
778
779 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
780 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
781 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
782
783 { } /* end */
784};
785
786/* This needs to be generated dynamically based on sequence */
787static struct snd_kcontrol_new stac922x_mixer[] = {
788 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200789 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
790 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
791 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
792
793 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
794 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
795 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
796 { } /* end */
797};
798
799
800static struct snd_kcontrol_new stac927x_mixer[] = {
801 STAC_INPUT_SOURCE(3),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100802 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200803
804 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
805 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
806 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
807
808 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
809 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
810 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
811
812 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
813 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
814 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +0200815 { } /* end */
816};
817
Takashi Iwai1697055e2007-12-18 18:05:52 +0100818static struct snd_kcontrol_new stac_dmux_mixer = {
819 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
820 .name = "Digital Input Source",
821 /* count set later */
822 .info = stac92xx_dmux_enum_info,
823 .get = stac92xx_dmux_enum_get,
824 .put = stac92xx_dmux_enum_put,
825};
826
Matt2f2f4252005-04-13 14:45:30 +0200827static int stac92xx_build_controls(struct hda_codec *codec)
828{
829 struct sigmatel_spec *spec = codec->spec;
830 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200831 int i;
Matt2f2f4252005-04-13 14:45:30 +0200832
833 err = snd_hda_add_new_ctls(codec, spec->mixer);
834 if (err < 0)
835 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200836
837 for (i = 0; i < spec->num_mixers; i++) {
838 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
839 if (err < 0)
840 return err;
841 }
Takashi Iwai1697055e2007-12-18 18:05:52 +0100842 if (spec->num_dmuxes > 0) {
843 stac_dmux_mixer.count = spec->num_dmuxes;
844 err = snd_ctl_add(codec->bus->card,
845 snd_ctl_new1(&stac_dmux_mixer, codec));
846 if (err < 0)
847 return err;
848 }
Mattc7d4b2f2005-06-27 14:59:41 +0200849
Mattdabbed62005-06-14 10:19:34 +0200850 if (spec->multiout.dig_out_nid) {
851 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
852 if (err < 0)
853 return err;
854 }
855 if (spec->dig_in_nid) {
856 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
857 if (err < 0)
858 return err;
859 }
860 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200861}
862
Matt Porter403d1942005-11-29 15:00:51 +0100863static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200864 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200865 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
866};
867
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200868/*
869 STAC 9200 pin configs for
870 102801A8
871 102801DE
872 102801E8
873*/
874static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c016e2007-09-05 23:46:03 +0200875 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
876 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200877};
878
879/*
880 STAC 9200 pin configs for
881 102801C0
882 102801C1
883*/
884static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c016e2007-09-05 23:46:03 +0200885 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
886 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200887};
888
889/*
890 STAC 9200 pin configs for
891 102801C4 (Dell Dimension E310)
892 102801C5
893 102801C7
894 102801D9
895 102801DA
896 102801E3
897*/
898static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c016e2007-09-05 23:46:03 +0200899 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
900 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200901};
902
903
904/*
905 STAC 9200-32 pin configs for
906 102801B5 (Dell Inspiron 630m)
907 102801D8 (Dell Inspiron 640m)
908*/
909static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c016e2007-09-05 23:46:03 +0200910 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
911 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200912};
913
914/*
915 STAC 9200-32 pin configs for
916 102801C2 (Dell Latitude D620)
917 102801C8
918 102801CC (Dell Latitude D820)
919 102801D4
920 102801D6
921*/
922static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c016e2007-09-05 23:46:03 +0200923 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
924 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200925};
926
927/*
928 STAC 9200-32 pin configs for
929 102801CE (Dell XPS M1710)
930 102801CF (Dell Precision M90)
931*/
932static unsigned int dell9200_m23_pin_configs[8] = {
933 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
934 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
935};
936
937/*
938 STAC 9200-32 pin configs for
939 102801C9
940 102801CA
941 102801CB (Dell Latitude 120L)
942 102801D3
943*/
944static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c016e2007-09-05 23:46:03 +0200945 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
946 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200947};
948
949/*
950 STAC 9200-32 pin configs for
951 102801BD (Dell Inspiron E1505n)
952 102801EE
953 102801EF
954*/
955static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c016e2007-09-05 23:46:03 +0200956 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
957 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200958};
959
960/*
961 STAC 9200-32 pin configs for
962 102801F5 (Dell Inspiron 1501)
963 102801F6
964*/
965static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c016e2007-09-05 23:46:03 +0200966 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
967 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200968};
969
970/*
971 STAC 9200-32
972 102801CD (Dell Inspiron E1705/9400)
973*/
974static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c016e2007-09-05 23:46:03 +0200975 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
976 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200977};
978
979
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100980static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
981 [STAC_REF] = ref9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200982 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
983 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
984 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
985 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
986 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
987 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
988 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
989 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
990 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
991 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100992};
993
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100994static const char *stac9200_models[STAC_9200_MODELS] = {
995 [STAC_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200996 [STAC_9200_DELL_D21] = "dell-d21",
997 [STAC_9200_DELL_D22] = "dell-d22",
998 [STAC_9200_DELL_D23] = "dell-d23",
999 [STAC_9200_DELL_M21] = "dell-m21",
1000 [STAC_9200_DELL_M22] = "dell-m22",
1001 [STAC_9200_DELL_M23] = "dell-m23",
1002 [STAC_9200_DELL_M24] = "dell-m24",
1003 [STAC_9200_DELL_M25] = "dell-m25",
1004 [STAC_9200_DELL_M26] = "dell-m26",
1005 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001006 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001007};
1008
1009static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1010 /* SigmaTel reference board */
1011 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1012 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001013 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001014 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1015 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001016 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001017 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1018 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1019 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1020 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1021 "unknown Dell", STAC_9200_DELL_D22),
1022 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1023 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001024 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001025 "Dell Latitude D620", STAC_9200_DELL_M22),
1026 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1027 "unknown Dell", STAC_9200_DELL_D23),
1028 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1029 "unknown Dell", STAC_9200_DELL_D23),
1030 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1031 "unknown Dell", STAC_9200_DELL_M22),
1032 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1033 "unknown Dell", STAC_9200_DELL_M24),
1034 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1035 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001036 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001037 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001038 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001039 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001040 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001041 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001042 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001043 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001044 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001045 "Dell Precision M90", STAC_9200_DELL_M23),
1046 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1047 "unknown Dell", STAC_9200_DELL_M22),
1048 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1049 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001050 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001051 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001052 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001053 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1054 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1055 "unknown Dell", STAC_9200_DELL_D23),
1056 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1057 "unknown Dell", STAC_9200_DELL_D23),
1058 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1059 "unknown Dell", STAC_9200_DELL_D21),
1060 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1061 "unknown Dell", STAC_9200_DELL_D23),
1062 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1063 "unknown Dell", STAC_9200_DELL_D21),
1064 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1065 "unknown Dell", STAC_9200_DELL_M25),
1066 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1067 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001068 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001069 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1070 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1071 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001072 /* Panasonic */
1073 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001074 /* Gateway machines needs EAPD to be set on resume */
1075 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1076 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1077 STAC_9200_GATEWAY),
1078 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1079 STAC_9200_GATEWAY),
Matt Porter403d1942005-11-29 15:00:51 +01001080 {} /* terminator */
1081};
1082
Tobin Davis8e21c342007-01-08 11:04:17 +01001083static unsigned int ref925x_pin_configs[8] = {
1084 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1085 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
1086};
1087
1088static unsigned int stac925x_MA6_pin_configs[8] = {
1089 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1090 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
1091};
1092
Tobin Davis2c11f952007-05-17 09:36:34 +02001093static unsigned int stac925x_PA6_pin_configs[8] = {
1094 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1095 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
1096};
1097
Tobin Davis8e21c342007-01-08 11:04:17 +01001098static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +02001099 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
1100 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001101};
1102
1103static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1104 [STAC_REF] = ref925x_pin_configs,
1105 [STAC_M2_2] = stac925xM2_2_pin_configs,
1106 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +02001107 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001108};
1109
1110static const char *stac925x_models[STAC_925x_MODELS] = {
1111 [STAC_REF] = "ref",
1112 [STAC_M2_2] = "m2-2",
1113 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +02001114 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001115};
1116
1117static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1118 /* SigmaTel reference board */
1119 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001120 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +01001121 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
1122 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
1123 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +02001124 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +01001125 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
1126 {} /* terminator */
1127};
1128
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001129static unsigned int ref92hd73xx_pin_configs[12] = {
1130 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1131 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1132 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1133};
1134
1135static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1136 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1137};
1138
1139static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1140 [STAC_92HD73XX_REF] = "ref",
1141};
1142
1143static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1144 /* SigmaTel reference board */
1145 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1146 "DFI LanParty", STAC_92HD73XX_REF),
1147 {} /* terminator */
1148};
1149
Matthew Ranostaye035b842007-11-06 11:53:55 +01001150static unsigned int ref92hd71bxx_pin_configs[10] = {
1151 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1152 0x0181302e, 0x01114010, 0x01a19020, 0x90a000f0,
1153 0x90a000f0, 0x01452050,
1154};
1155
1156static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1157 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1158};
1159
1160static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1161 [STAC_92HD71BXX_REF] = "ref",
1162};
1163
1164static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1165 /* SigmaTel reference board */
1166 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1167 "DFI LanParty", STAC_92HD71BXX_REF),
1168 {} /* terminator */
1169};
1170
Matt Porter403d1942005-11-29 15:00:51 +01001171static unsigned int ref922x_pin_configs[10] = {
1172 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1173 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001174 0x40000100, 0x40000100,
1175};
1176
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001177/*
1178 STAC 922X pin configs for
1179 102801A7
1180 102801AB
1181 102801A9
1182 102801D1
1183 102801D2
1184*/
1185static unsigned int dell_922x_d81_pin_configs[10] = {
1186 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1187 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1188 0x01813122, 0x400001f2,
1189};
1190
1191/*
1192 STAC 922X pin configs for
1193 102801AC
1194 102801D0
1195*/
1196static unsigned int dell_922x_d82_pin_configs[10] = {
1197 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1198 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1199 0x01813122, 0x400001f1,
1200};
1201
1202/*
1203 STAC 922X pin configs for
1204 102801BF
1205*/
1206static unsigned int dell_922x_m81_pin_configs[10] = {
1207 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1208 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1209 0x40C003f1, 0x405003f0,
1210};
1211
1212/*
1213 STAC 9221 A1 pin configs for
1214 102801D7 (Dell XPS M1210)
1215*/
1216static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001217 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1218 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001219 0x508003f3, 0x405003f4,
1220};
1221
Matt Porter403d1942005-11-29 15:00:51 +01001222static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001223 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001224 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1225 0x02a19120, 0x40000100,
1226};
1227
1228static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001229 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1230 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001231 0x02a19320, 0x40000100,
1232};
1233
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001234static unsigned int intel_mac_v1_pin_configs[10] = {
1235 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1236 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001237 0x400000fc, 0x400000fb,
1238};
1239
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001240static unsigned int intel_mac_v2_pin_configs[10] = {
1241 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1242 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001243 0x400000fc, 0x400000fb,
1244};
1245
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001246static unsigned int intel_mac_v3_pin_configs[10] = {
1247 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1248 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1249 0x400000fc, 0x400000fb,
1250};
1251
1252static unsigned int intel_mac_v4_pin_configs[10] = {
1253 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1254 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1255 0x400000fc, 0x400000fb,
1256};
1257
1258static unsigned int intel_mac_v5_pin_configs[10] = {
1259 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1260 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1261 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001262};
1263
Takashi Iwai76c08822007-06-19 12:17:42 +02001264
Takashi Iwai19039bd2006-06-28 15:52:16 +02001265static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001266 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001267 [STAC_D945GTP3] = d945gtp3_pin_configs,
1268 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001269 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1270 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1271 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1272 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1273 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001274 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001275 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1276 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1277 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1278 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1279 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1280 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001281 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1282 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1283 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1284 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001285};
1286
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001287static const char *stac922x_models[STAC_922X_MODELS] = {
1288 [STAC_D945_REF] = "ref",
1289 [STAC_D945GTP5] = "5stack",
1290 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001291 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1292 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1293 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1294 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1295 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001296 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001297 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001298 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001299 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1300 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001301 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001302 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001303 [STAC_922X_DELL_D81] = "dell-d81",
1304 [STAC_922X_DELL_D82] = "dell-d82",
1305 [STAC_922X_DELL_M81] = "dell-m81",
1306 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001307};
1308
1309static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1310 /* SigmaTel reference board */
1311 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1312 "DFI LanParty", STAC_D945_REF),
1313 /* Intel 945G based systems */
1314 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1315 "Intel D945G", STAC_D945GTP3),
1316 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1317 "Intel D945G", STAC_D945GTP3),
1318 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1319 "Intel D945G", STAC_D945GTP3),
1320 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1321 "Intel D945G", STAC_D945GTP3),
1322 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1323 "Intel D945G", STAC_D945GTP3),
1324 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1325 "Intel D945G", STAC_D945GTP3),
1326 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1327 "Intel D945G", STAC_D945GTP3),
1328 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1329 "Intel D945G", STAC_D945GTP3),
1330 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1331 "Intel D945G", STAC_D945GTP3),
1332 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1333 "Intel D945G", STAC_D945GTP3),
1334 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1335 "Intel D945G", STAC_D945GTP3),
1336 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1337 "Intel D945G", STAC_D945GTP3),
1338 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1339 "Intel D945G", STAC_D945GTP3),
1340 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1341 "Intel D945G", STAC_D945GTP3),
1342 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1343 "Intel D945G", STAC_D945GTP3),
1344 /* Intel D945G 5-stack systems */
1345 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1346 "Intel D945G", STAC_D945GTP5),
1347 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1348 "Intel D945G", STAC_D945GTP5),
1349 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1350 "Intel D945G", STAC_D945GTP5),
1351 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1352 "Intel D945G", STAC_D945GTP5),
1353 /* Intel 945P based systems */
1354 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1355 "Intel D945P", STAC_D945GTP3),
1356 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1357 "Intel D945P", STAC_D945GTP3),
1358 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1359 "Intel D945P", STAC_D945GTP3),
1360 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1361 "Intel D945P", STAC_D945GTP3),
1362 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1363 "Intel D945P", STAC_D945GTP3),
1364 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1365 "Intel D945P", STAC_D945GTP5),
1366 /* other systems */
1367 /* Apple Mac Mini (early 2006) */
1368 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001369 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001370 /* Dell systems */
1371 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1372 "unknown Dell", STAC_922X_DELL_D81),
1373 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1374 "unknown Dell", STAC_922X_DELL_D81),
1375 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1376 "unknown Dell", STAC_922X_DELL_D81),
1377 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1378 "unknown Dell", STAC_922X_DELL_D82),
1379 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1380 "unknown Dell", STAC_922X_DELL_M81),
1381 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1382 "unknown Dell", STAC_922X_DELL_D82),
1383 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1384 "unknown Dell", STAC_922X_DELL_D81),
1385 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1386 "unknown Dell", STAC_922X_DELL_D81),
1387 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1388 "Dell XPS M1210", STAC_922X_DELL_M82),
Matt Porter403d1942005-11-29 15:00:51 +01001389 {} /* terminator */
1390};
1391
Matt Porter3cc08dc2006-01-23 15:27:49 +01001392static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001393 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1394 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1395 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1396 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001397};
1398
Tobin Davis93ed1502006-09-01 21:03:12 +02001399static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001400 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1401 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1402 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1403 0x40000100, 0x40000100
1404};
1405
Tobin Davis93ed1502006-09-01 21:03:12 +02001406static unsigned int d965_5st_pin_configs[14] = {
1407 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1408 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1409 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1410 0x40000100, 0x40000100
1411};
1412
Tobin Davis4ff076e2007-08-07 11:48:12 +02001413static unsigned int dell_3st_pin_configs[14] = {
1414 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1415 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001416 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001417 0x40c003fc, 0x40000100
1418};
1419
Tobin Davis93ed1502006-09-01 21:03:12 +02001420static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001421 [STAC_D965_REF] = ref927x_pin_configs,
1422 [STAC_D965_3ST] = d965_3st_pin_configs,
1423 [STAC_D965_5ST] = d965_5st_pin_configs,
1424 [STAC_DELL_3ST] = dell_3st_pin_configs,
1425 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001426};
1427
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001428static const char *stac927x_models[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001429 [STAC_D965_REF] = "ref",
1430 [STAC_D965_3ST] = "3stack",
1431 [STAC_D965_5ST] = "5stack",
1432 [STAC_DELL_3ST] = "dell-3stack",
1433 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001434};
1435
1436static struct snd_pci_quirk stac927x_cfg_tbl[] = {
1437 /* SigmaTel reference board */
1438 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1439 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001440 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001441 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
1442 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001443 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001444 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
1445 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
1446 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
1447 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
1448 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
1449 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
1450 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
1451 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
1452 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
1453 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
1454 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
1455 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
1456 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
1457 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
1458 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
1459 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001460 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001461 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_3ST),
1462 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001463 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001464 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
1465 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001466 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_3ST),
1467 /* Dell 3 stack systems with verb table in BIOS */
1468 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell ", STAC_DELL_BIOS),
1469 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
1470 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
1471 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
1472 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
1473 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02001474 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001475 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
1476 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
1477 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
1478 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
1479 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
1480 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
1481 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
1482 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
1483 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01001484 {} /* terminator */
1485};
1486
Matt Porterf3302a52006-07-31 12:49:34 +02001487static unsigned int ref9205_pin_configs[12] = {
1488 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +02001489 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
1490 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02001491};
1492
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001493/*
1494 STAC 9205 pin configs for
1495 102801F1
1496 102801F2
1497 102801FC
1498 102801FD
1499 10280204
1500 1028021F
1501*/
1502static unsigned int dell_9205_m42_pin_configs[12] = {
1503 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1504 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1505 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1506};
1507
1508/*
1509 STAC 9205 pin configs for
1510 102801F9
1511 102801FA
1512 102801FE
1513 102801FF (Dell Precision M4300)
1514 10280206
1515 10280200
1516 10280201
1517*/
1518static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001519 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1520 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1521 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1522};
1523
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001524static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001525 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1526 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1527 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1528};
1529
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001530static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001531 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001532 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1533 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1534 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02001535};
1536
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001537static const char *stac9205_models[STAC_9205_MODELS] = {
1538 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001539 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001540 [STAC_9205_DELL_M43] = "dell-m43",
1541 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001542};
1543
1544static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1545 /* SigmaTel reference board */
1546 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1547 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001548 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1549 "unknown Dell", STAC_9205_DELL_M42),
1550 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1551 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001552 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02001553 "Dell Precision", STAC_9205_DELL_M43),
1554 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
1555 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001556 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1557 "Dell Precision", STAC_9205_DELL_M43),
Matthew Ranostaye45e4592007-09-10 23:09:42 +02001558 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
1559 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001560 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1561 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1563 "unknown Dell", STAC_9205_DELL_M42),
1564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1565 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1567 "Dell Precision", STAC_9205_DELL_M43),
1568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001569 "Dell Precision M4300", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1571 "Dell Precision", STAC_9205_DELL_M43),
1572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1573 "Dell Inspiron", STAC_9205_DELL_M44),
1574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1575 "Dell Inspiron", STAC_9205_DELL_M44),
1576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1577 "Dell Inspiron", STAC_9205_DELL_M44),
1578 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1579 "Dell Inspiron", STAC_9205_DELL_M44),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1581 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001582 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1583 "Dell Inspiron", STAC_9205_DELL_M44),
Matt Porterf3302a52006-07-31 12:49:34 +02001584 {} /* terminator */
1585};
1586
Richard Fish11b44bb2006-08-23 18:31:34 +02001587static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1588{
1589 int i;
1590 struct sigmatel_spec *spec = codec->spec;
1591
1592 if (! spec->bios_pin_configs) {
1593 spec->bios_pin_configs = kcalloc(spec->num_pins,
1594 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1595 if (! spec->bios_pin_configs)
1596 return -ENOMEM;
1597 }
1598
1599 for (i = 0; i < spec->num_pins; i++) {
1600 hda_nid_t nid = spec->pin_nids[i];
1601 unsigned int pin_cfg;
1602
1603 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1604 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1605 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1606 nid, pin_cfg);
1607 spec->bios_pin_configs[i] = pin_cfg;
1608 }
1609
1610 return 0;
1611}
1612
Matthew Ranostay87d48362007-07-17 11:52:24 +02001613static void stac92xx_set_config_reg(struct hda_codec *codec,
1614 hda_nid_t pin_nid, unsigned int pin_config)
1615{
1616 int i;
1617 snd_hda_codec_write(codec, pin_nid, 0,
1618 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1619 pin_config & 0x000000ff);
1620 snd_hda_codec_write(codec, pin_nid, 0,
1621 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1622 (pin_config & 0x0000ff00) >> 8);
1623 snd_hda_codec_write(codec, pin_nid, 0,
1624 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1625 (pin_config & 0x00ff0000) >> 16);
1626 snd_hda_codec_write(codec, pin_nid, 0,
1627 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1628 pin_config >> 24);
1629 i = snd_hda_codec_read(codec, pin_nid, 0,
1630 AC_VERB_GET_CONFIG_DEFAULT,
1631 0x00);
1632 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1633 pin_nid, i);
1634}
1635
Matt2f2f4252005-04-13 14:45:30 +02001636static void stac92xx_set_config_regs(struct hda_codec *codec)
1637{
1638 int i;
1639 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02001640
Matthew Ranostay87d48362007-07-17 11:52:24 +02001641 if (!spec->pin_configs)
1642 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02001643
Matthew Ranostay87d48362007-07-17 11:52:24 +02001644 for (i = 0; i < spec->num_pins; i++)
1645 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1646 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02001647}
Matt2f2f4252005-04-13 14:45:30 +02001648
Takashi Iwai82599802007-07-31 15:56:24 +02001649static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001650{
Takashi Iwai82599802007-07-31 15:56:24 +02001651 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +02001652 /* Configure GPIOx as output */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001653 snd_hda_codec_write_cache(codec, codec->afg, 0,
1654 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001655 /* Configure GPIOx as CMOS */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001656 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001657 /* Assert GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001658 snd_hda_codec_write_cache(codec, codec->afg, 0,
1659 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001660 /* Enable GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001661 snd_hda_codec_write_cache(codec, codec->afg, 0,
1662 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001663}
1664
Matt2f2f4252005-04-13 14:45:30 +02001665/*
1666 * Analog playback callbacks
1667 */
1668static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1669 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001670 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001671{
1672 struct sigmatel_spec *spec = codec->spec;
1673 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1674}
1675
1676static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1677 struct hda_codec *codec,
1678 unsigned int stream_tag,
1679 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001680 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001681{
1682 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01001683 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02001684}
1685
1686static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1687 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001688 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001689{
1690 struct sigmatel_spec *spec = codec->spec;
1691 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1692}
1693
1694/*
Mattdabbed62005-06-14 10:19:34 +02001695 * Digital playback callbacks
1696 */
1697static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1698 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001699 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001700{
1701 struct sigmatel_spec *spec = codec->spec;
1702 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1703}
1704
1705static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1706 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001707 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001708{
1709 struct sigmatel_spec *spec = codec->spec;
1710 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1711}
1712
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001713static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1714 struct hda_codec *codec,
1715 unsigned int stream_tag,
1716 unsigned int format,
1717 struct snd_pcm_substream *substream)
1718{
1719 struct sigmatel_spec *spec = codec->spec;
1720 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1721 stream_tag, format, substream);
1722}
1723
Mattdabbed62005-06-14 10:19:34 +02001724
1725/*
Matt2f2f4252005-04-13 14:45:30 +02001726 * Analog capture callbacks
1727 */
1728static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1729 struct hda_codec *codec,
1730 unsigned int stream_tag,
1731 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001732 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001733{
1734 struct sigmatel_spec *spec = codec->spec;
1735
1736 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1737 stream_tag, 0, format);
1738 return 0;
1739}
1740
1741static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1742 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001743 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001744{
1745 struct sigmatel_spec *spec = codec->spec;
1746
1747 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1748 return 0;
1749}
1750
Mattdabbed62005-06-14 10:19:34 +02001751static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1752 .substreams = 1,
1753 .channels_min = 2,
1754 .channels_max = 2,
1755 /* NID is set in stac92xx_build_pcms */
1756 .ops = {
1757 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001758 .close = stac92xx_dig_playback_pcm_close,
1759 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02001760 },
1761};
1762
1763static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1764 .substreams = 1,
1765 .channels_min = 2,
1766 .channels_max = 2,
1767 /* NID is set in stac92xx_build_pcms */
1768};
1769
Matt2f2f4252005-04-13 14:45:30 +02001770static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1771 .substreams = 1,
1772 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02001773 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02001774 .nid = 0x02, /* NID to query formats and rates */
1775 .ops = {
1776 .open = stac92xx_playback_pcm_open,
1777 .prepare = stac92xx_playback_pcm_prepare,
1778 .cleanup = stac92xx_playback_pcm_cleanup
1779 },
1780};
1781
Matt Porter3cc08dc2006-01-23 15:27:49 +01001782static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1783 .substreams = 1,
1784 .channels_min = 2,
1785 .channels_max = 2,
1786 .nid = 0x06, /* NID to query formats and rates */
1787 .ops = {
1788 .open = stac92xx_playback_pcm_open,
1789 .prepare = stac92xx_playback_pcm_prepare,
1790 .cleanup = stac92xx_playback_pcm_cleanup
1791 },
1792};
1793
Matt2f2f4252005-04-13 14:45:30 +02001794static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02001795 .channels_min = 2,
1796 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001797 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001798 .ops = {
1799 .prepare = stac92xx_capture_pcm_prepare,
1800 .cleanup = stac92xx_capture_pcm_cleanup
1801 },
1802};
1803
1804static int stac92xx_build_pcms(struct hda_codec *codec)
1805{
1806 struct sigmatel_spec *spec = codec->spec;
1807 struct hda_pcm *info = spec->pcm_rec;
1808
1809 codec->num_pcms = 1;
1810 codec->pcm_info = info;
1811
Mattc7d4b2f2005-06-27 14:59:41 +02001812 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001813 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001814 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001815 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001816 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001817
1818 if (spec->alt_switch) {
1819 codec->num_pcms++;
1820 info++;
1821 info->name = "STAC92xx Analog Alt";
1822 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1823 }
Matt2f2f4252005-04-13 14:45:30 +02001824
Mattdabbed62005-06-14 10:19:34 +02001825 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1826 codec->num_pcms++;
1827 info++;
1828 info->name = "STAC92xx Digital";
1829 if (spec->multiout.dig_out_nid) {
1830 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1831 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1832 }
1833 if (spec->dig_in_nid) {
1834 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1835 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1836 }
1837 }
1838
Matt2f2f4252005-04-13 14:45:30 +02001839 return 0;
1840}
1841
Takashi Iwaic960a032006-03-23 17:06:28 +01001842static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1843{
1844 unsigned int pincap = snd_hda_param_read(codec, nid,
1845 AC_PAR_PIN_CAP);
1846 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1847 if (pincap & AC_PINCAP_VREF_100)
1848 return AC_PINCTL_VREF_100;
1849 if (pincap & AC_PINCAP_VREF_80)
1850 return AC_PINCTL_VREF_80;
1851 if (pincap & AC_PINCAP_VREF_50)
1852 return AC_PINCTL_VREF_50;
1853 if (pincap & AC_PINCAP_VREF_GRD)
1854 return AC_PINCTL_VREF_GRD;
1855 return 0;
1856}
1857
Matt Porter403d1942005-11-29 15:00:51 +01001858static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1859
1860{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001861 snd_hda_codec_write_cache(codec, nid, 0,
1862 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01001863}
1864
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001865#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001866
1867static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1868{
1869 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1870 struct sigmatel_spec *spec = codec->spec;
1871 int io_idx = kcontrol-> private_value & 0xff;
1872
1873 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1874 return 0;
1875}
1876
1877static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1878{
1879 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1880 struct sigmatel_spec *spec = codec->spec;
1881 hda_nid_t nid = kcontrol->private_value >> 8;
1882 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001883 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01001884
1885 spec->io_switch[io_idx] = val;
1886
1887 if (val)
1888 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001889 else {
1890 unsigned int pinctl = AC_PINCTL_IN_EN;
1891 if (io_idx) /* set VREF for mic */
1892 pinctl |= stac92xx_get_vref(codec, nid);
1893 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1894 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01001895
1896 /* check the auto-mute again: we need to mute/unmute the speaker
1897 * appropriately according to the pin direction
1898 */
1899 if (spec->hp_detect)
1900 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1901
Matt Porter403d1942005-11-29 15:00:51 +01001902 return 1;
1903}
1904
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001905#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
1906
1907static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
1908 struct snd_ctl_elem_value *ucontrol)
1909{
1910 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1911 struct sigmatel_spec *spec = codec->spec;
1912
1913 ucontrol->value.integer.value[0] = spec->clfe_swap;
1914 return 0;
1915}
1916
1917static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1918 struct snd_ctl_elem_value *ucontrol)
1919{
1920 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1921 struct sigmatel_spec *spec = codec->spec;
1922 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001923 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001924
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001925 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001926 return 0;
1927
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001928 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001929
1930 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1931 spec->clfe_swap ? 0x4 : 0x0);
1932
1933 return 1;
1934}
1935
Matt Porter403d1942005-11-29 15:00:51 +01001936#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1937 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1938 .name = xname, \
1939 .index = 0, \
1940 .info = stac92xx_io_switch_info, \
1941 .get = stac92xx_io_switch_get, \
1942 .put = stac92xx_io_switch_put, \
1943 .private_value = xpval, \
1944 }
1945
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001946#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
1947 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1948 .name = xname, \
1949 .index = 0, \
1950 .info = stac92xx_clfe_switch_info, \
1951 .get = stac92xx_clfe_switch_get, \
1952 .put = stac92xx_clfe_switch_put, \
1953 .private_value = xpval, \
1954 }
Matt Porter403d1942005-11-29 15:00:51 +01001955
Mattc7d4b2f2005-06-27 14:59:41 +02001956enum {
1957 STAC_CTL_WIDGET_VOL,
1958 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001959 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001960 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02001961};
1962
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001963static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001964 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1965 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001966 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001967 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001968};
1969
1970/* add dynamic controls */
1971static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1972{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001973 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001974
1975 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1976 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1977
1978 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1979 if (! knew)
1980 return -ENOMEM;
1981 if (spec->kctl_alloc) {
1982 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1983 kfree(spec->kctl_alloc);
1984 }
1985 spec->kctl_alloc = knew;
1986 spec->num_kctl_alloc = num;
1987 }
1988
1989 knew = &spec->kctl_alloc[spec->num_kctl_used];
1990 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001991 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001992 if (! knew->name)
1993 return -ENOMEM;
1994 knew->private_value = val;
1995 spec->num_kctl_used++;
1996 return 0;
1997}
1998
Matt Porter403d1942005-11-29 15:00:51 +01001999/* flag inputs as additional dynamic lineouts */
2000static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2001{
2002 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002003 unsigned int wcaps, wtype;
2004 int i, num_dacs = 0;
2005
2006 /* use the wcaps cache to count all DACs available for line-outs */
2007 for (i = 0; i < codec->num_nodes; i++) {
2008 wcaps = codec->wcaps[i];
2009 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002010
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002011 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
2012 num_dacs++;
2013 }
Matt Porter403d1942005-11-29 15:00:51 +01002014
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002015 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
2016
Matt Porter403d1942005-11-29 15:00:51 +01002017 switch (cfg->line_outs) {
2018 case 3:
2019 /* add line-in as side */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002020 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002021 cfg->line_out_pins[cfg->line_outs] =
2022 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002023 spec->line_switch = 1;
2024 cfg->line_outs++;
2025 }
2026 break;
2027 case 2:
2028 /* add line-in as clfe and mic as side */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002029 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002030 cfg->line_out_pins[cfg->line_outs] =
2031 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002032 spec->line_switch = 1;
2033 cfg->line_outs++;
2034 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002035 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002036 cfg->line_out_pins[cfg->line_outs] =
2037 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002038 spec->mic_switch = 1;
2039 cfg->line_outs++;
2040 }
2041 break;
2042 case 1:
2043 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002044 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002045 cfg->line_out_pins[cfg->line_outs] =
2046 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002047 spec->line_switch = 1;
2048 cfg->line_outs++;
2049 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002050 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002051 cfg->line_out_pins[cfg->line_outs] =
2052 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002053 spec->mic_switch = 1;
2054 cfg->line_outs++;
2055 }
2056 break;
2057 }
2058
2059 return 0;
2060}
2061
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002062
2063static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2064{
2065 int i;
2066
2067 for (i = 0; i < spec->multiout.num_dacs; i++) {
2068 if (spec->multiout.dac_nids[i] == nid)
2069 return 1;
2070 }
2071
2072 return 0;
2073}
2074
Matt Porter3cc08dc2006-01-23 15:27:49 +01002075/*
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002076 * Fill in the dac_nids table from the parsed pin configuration
2077 * This function only works when every pin in line_out_pins[]
2078 * contains atleast one DAC in its connection list. Some 92xx
2079 * codecs are not connected directly to a DAC, such as the 9200
2080 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002081 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002082static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02002083 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002084{
2085 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002086 int i, j, conn_len = 0;
2087 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2088 unsigned int wcaps, wtype;
2089
Mattc7d4b2f2005-06-27 14:59:41 +02002090 for (i = 0; i < cfg->line_outs; i++) {
2091 nid = cfg->line_out_pins[i];
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002092 conn_len = snd_hda_get_connections(codec, nid, conn,
2093 HDA_MAX_CONNECTIONS);
2094 for (j = 0; j < conn_len; j++) {
2095 wcaps = snd_hda_param_read(codec, conn[j],
2096 AC_PAR_AUDIO_WIDGET_CAP);
2097 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002098 if (wtype != AC_WID_AUD_OUT ||
2099 (wcaps & AC_WCAP_DIGITAL))
2100 continue;
2101 /* conn[j] is a DAC routed to this line-out */
2102 if (!is_in_dac_nids(spec, conn[j]))
2103 break;
2104 }
2105
2106 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002107 if (spec->multiout.num_dacs > 0) {
2108 /* we have already working output pins,
2109 * so let's drop the broken ones again
2110 */
2111 cfg->line_outs = spec->multiout.num_dacs;
2112 break;
2113 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002114 /* error out, no available DAC found */
2115 snd_printk(KERN_ERR
2116 "%s: No available DAC for pin 0x%x\n",
2117 __func__, nid);
2118 return -ENODEV;
2119 }
2120
2121 spec->multiout.dac_nids[i] = conn[j];
2122 spec->multiout.num_dacs++;
2123 if (conn_len > 1) {
2124 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002125 snd_hda_codec_write_cache(codec, nid, 0,
2126 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002127
2128 }
Mattc7d4b2f2005-06-27 14:59:41 +02002129 }
2130
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002131 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2132 spec->multiout.num_dacs,
2133 spec->multiout.dac_nids[0],
2134 spec->multiout.dac_nids[1],
2135 spec->multiout.dac_nids[2],
2136 spec->multiout.dac_nids[3],
2137 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02002138 return 0;
2139}
2140
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002141/* create volume control/switch for the given prefx type */
2142static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2143{
2144 char name[32];
2145 int err;
2146
2147 sprintf(name, "%s Playback Volume", pfx);
2148 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2149 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2150 if (err < 0)
2151 return err;
2152 sprintf(name, "%s Playback Switch", pfx);
2153 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2154 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2155 if (err < 0)
2156 return err;
2157 return 0;
2158}
2159
Mattc7d4b2f2005-06-27 14:59:41 +02002160/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002161static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002162 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002163{
Takashi Iwai19039bd2006-06-28 15:52:16 +02002164 static const char *chname[4] = {
2165 "Front", "Surround", NULL /*CLFE*/, "Side"
2166 };
Mattc7d4b2f2005-06-27 14:59:41 +02002167 hda_nid_t nid;
2168 int i, err;
2169
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002170 struct sigmatel_spec *spec = codec->spec;
2171 unsigned int wid_caps;
2172
2173
Mattc7d4b2f2005-06-27 14:59:41 +02002174 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01002175 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02002176 continue;
2177
2178 nid = spec->multiout.dac_nids[i];
2179
2180 if (i == 2) {
2181 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002182 err = create_controls(spec, "Center", nid, 1);
2183 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002184 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002185 err = create_controls(spec, "LFE", nid, 2);
2186 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002187 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002188
2189 wid_caps = get_wcaps(codec, nid);
2190
2191 if (wid_caps & AC_WCAP_LR_SWAP) {
2192 err = stac92xx_add_control(spec,
2193 STAC_CTL_WIDGET_CLFE_SWITCH,
2194 "Swap Center/LFE Playback Switch", nid);
2195
2196 if (err < 0)
2197 return err;
2198 }
2199
Mattc7d4b2f2005-06-27 14:59:41 +02002200 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002201 err = create_controls(spec, chname[i], nid, 3);
2202 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002203 return err;
2204 }
2205 }
2206
Matt Porter403d1942005-11-29 15:00:51 +01002207 if (spec->line_switch)
2208 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
2209 return err;
2210
2211 if (spec->mic_switch)
2212 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
2213 return err;
2214
Mattc7d4b2f2005-06-27 14:59:41 +02002215 return 0;
2216}
2217
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002218static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2219{
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002220 if (is_in_dac_nids(spec, nid))
2221 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002222 if (spec->multiout.hp_nid == nid)
2223 return 1;
2224 return 0;
2225}
2226
2227static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2228{
2229 if (!spec->multiout.hp_nid)
2230 spec->multiout.hp_nid = nid;
2231 else if (spec->multiout.num_dacs > 4) {
2232 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2233 return 1;
2234 } else {
2235 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2236 spec->multiout.num_dacs++;
2237 }
2238 return 0;
2239}
2240
2241/* add playback controls for Speaker and HP outputs */
2242static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2243 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002244{
2245 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002246 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002247 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02002248
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002249 old_num_dacs = spec->multiout.num_dacs;
2250 for (i = 0; i < cfg->hp_outs; i++) {
2251 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
2252 if (wid_caps & AC_WCAP_UNSOL_CAP)
2253 spec->hp_detect = 1;
2254 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
2255 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2256 if (check_in_dac_nids(spec, nid))
2257 nid = 0;
2258 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02002259 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002260 add_spec_dacs(spec, nid);
2261 }
2262 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002263 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002264 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2265 if (check_in_dac_nids(spec, nid))
2266 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002267 if (! nid)
2268 continue;
2269 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02002270 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02002271 for (i = 0; i < cfg->line_outs; i++) {
2272 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
2273 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2274 if (check_in_dac_nids(spec, nid))
2275 nid = 0;
2276 if (! nid)
2277 continue;
2278 add_spec_dacs(spec, nid);
2279 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002280 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
2281 static const char *pfxs[] = {
2282 "Speaker", "External Speaker", "Speaker2",
2283 };
2284 err = create_controls(spec, pfxs[i - old_num_dacs],
2285 spec->multiout.dac_nids[i], 3);
2286 if (err < 0)
2287 return err;
2288 }
2289 if (spec->multiout.hp_nid) {
2290 const char *pfx;
Takashi Iwai6020c002007-11-19 11:56:26 +01002291 if (old_num_dacs == spec->multiout.num_dacs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002292 pfx = "Master";
2293 else
2294 pfx = "Headphone";
2295 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
2296 if (err < 0)
2297 return err;
2298 }
Mattc7d4b2f2005-06-27 14:59:41 +02002299
2300 return 0;
2301}
2302
Matt Porter8b657272006-10-26 17:12:59 +02002303/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01002304static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02002305 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
2306 "Digital Mic 3", "Digital Mic 4"
2307};
2308
2309/* create playback/capture controls for input pins on dmic capable codecs */
2310static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
2311 const struct auto_pin_cfg *cfg)
2312{
2313 struct sigmatel_spec *spec = codec->spec;
2314 struct hda_input_mux *dimux = &spec->private_dimux;
2315 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
2316 int i, j;
2317
2318 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
2319 dimux->items[dimux->num_items].index = 0;
2320 dimux->num_items++;
2321
2322 for (i = 0; i < spec->num_dmics; i++) {
2323 int index;
2324 int num_cons;
2325 unsigned int def_conf;
2326
2327 def_conf = snd_hda_codec_read(codec,
2328 spec->dmic_nids[i],
2329 0,
2330 AC_VERB_GET_CONFIG_DEFAULT,
2331 0);
2332 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
2333 continue;
2334
2335 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01002336 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02002337 con_lst,
2338 HDA_MAX_NUM_INPUTS);
2339 for (j = 0; j < num_cons; j++)
2340 if (con_lst[j] == spec->dmic_nids[i]) {
2341 index = j;
2342 goto found;
2343 }
2344 continue;
2345found:
2346 dimux->items[dimux->num_items].label =
2347 stac92xx_dmic_labels[dimux->num_items];
2348 dimux->items[dimux->num_items].index = index;
2349 dimux->num_items++;
2350 }
2351
2352 return 0;
2353}
2354
Mattc7d4b2f2005-06-27 14:59:41 +02002355/* create playback/capture controls for input pins */
2356static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
2357{
2358 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002359 struct hda_input_mux *imux = &spec->private_imux;
2360 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
2361 int i, j, k;
2362
2363 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002364 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02002365
Takashi Iwai314634b2006-09-21 11:56:18 +02002366 if (!cfg->input_pins[i])
2367 continue;
2368 index = -1;
2369 for (j = 0; j < spec->num_muxes; j++) {
2370 int num_cons;
2371 num_cons = snd_hda_get_connections(codec,
2372 spec->mux_nids[j],
2373 con_lst,
2374 HDA_MAX_NUM_INPUTS);
2375 for (k = 0; k < num_cons; k++)
2376 if (con_lst[k] == cfg->input_pins[i]) {
2377 index = k;
2378 goto found;
2379 }
Mattc7d4b2f2005-06-27 14:59:41 +02002380 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002381 continue;
2382 found:
2383 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2384 imux->items[imux->num_items].index = index;
2385 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02002386 }
2387
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002388 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02002389 /*
2390 * Set the current input for the muxes.
2391 * The STAC9221 has two input muxes with identical source
2392 * NID lists. Hopefully this won't get confused.
2393 */
2394 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002395 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
2396 AC_VERB_SET_CONNECT_SEL,
2397 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02002398 }
2399 }
2400
Mattc7d4b2f2005-06-27 14:59:41 +02002401 return 0;
2402}
2403
Mattc7d4b2f2005-06-27 14:59:41 +02002404static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
2405{
2406 struct sigmatel_spec *spec = codec->spec;
2407 int i;
2408
2409 for (i = 0; i < spec->autocfg.line_outs; i++) {
2410 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2411 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2412 }
2413}
2414
2415static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
2416{
2417 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002418 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002419
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002420 for (i = 0; i < spec->autocfg.hp_outs; i++) {
2421 hda_nid_t pin;
2422 pin = spec->autocfg.hp_pins[i];
2423 if (pin) /* connect to front */
2424 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
2425 }
2426 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
2427 hda_nid_t pin;
2428 pin = spec->autocfg.speaker_pins[i];
2429 if (pin) /* connect to front */
2430 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
2431 }
Mattc7d4b2f2005-06-27 14:59:41 +02002432}
2433
Matt Porter3cc08dc2006-01-23 15:27:49 +01002434static 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 +02002435{
2436 struct sigmatel_spec *spec = codec->spec;
2437 int err;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002438 int hp_speaker_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002439
Matt Porter8b657272006-10-26 17:12:59 +02002440 if ((err = snd_hda_parse_pin_def_config(codec,
2441 &spec->autocfg,
2442 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002443 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002444 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01002445 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002446
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002447 /* If we have no real line-out pin and multiple hp-outs, HPs should
2448 * be set up as multi-channel outputs.
2449 */
2450 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2451 spec->autocfg.hp_outs > 1) {
2452 /* Copy hp_outs to line_outs, backup line_outs in
2453 * speaker_outs so that the following routines can handle
2454 * HP pins as primary outputs.
2455 */
2456 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
2457 sizeof(spec->autocfg.line_out_pins));
2458 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
2459 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
2460 sizeof(spec->autocfg.hp_pins));
2461 spec->autocfg.line_outs = spec->autocfg.hp_outs;
2462 hp_speaker_swap = 1;
2463 }
2464
Matt Porter403d1942005-11-29 15:00:51 +01002465 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
2466 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002467 if (spec->multiout.num_dacs == 0)
2468 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2469 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02002470
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002471 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
2472
2473 if (err < 0)
2474 return err;
2475
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002476 if (hp_speaker_swap == 1) {
2477 /* Restore the hp_outs and line_outs */
2478 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
2479 sizeof(spec->autocfg.line_out_pins));
2480 spec->autocfg.hp_outs = spec->autocfg.line_outs;
2481 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
2482 sizeof(spec->autocfg.speaker_pins));
2483 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
2484 memset(spec->autocfg.speaker_pins, 0,
2485 sizeof(spec->autocfg.speaker_pins));
2486 spec->autocfg.speaker_outs = 0;
2487 }
2488
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002489 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
2490
2491 if (err < 0)
2492 return err;
2493
2494 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
2495
2496 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002497 return err;
2498
Matt Porter8b657272006-10-26 17:12:59 +02002499 if (spec->num_dmics > 0)
2500 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
2501 &spec->autocfg)) < 0)
2502 return err;
2503
Mattc7d4b2f2005-06-27 14:59:41 +02002504 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01002505 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02002506 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002507
Takashi Iwai82bc9552006-03-21 11:24:42 +01002508 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002509 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002510 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002511 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02002512
2513 if (spec->kctl_alloc)
2514 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2515
2516 spec->input_mux = &spec->private_imux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01002517 if (!spec->dinput_mux)
2518 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002519
2520 return 1;
2521}
2522
Takashi Iwai82bc9552006-03-21 11:24:42 +01002523/* add playback controls for HP output */
2524static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
2525 struct auto_pin_cfg *cfg)
2526{
2527 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002528 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01002529 unsigned int wid_caps;
2530
2531 if (! pin)
2532 return 0;
2533
2534 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02002535 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01002536 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002537
2538 return 0;
2539}
2540
Richard Fish160ea0d2006-09-06 13:58:25 +02002541/* add playback controls for LFE output */
2542static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2543 struct auto_pin_cfg *cfg)
2544{
2545 struct sigmatel_spec *spec = codec->spec;
2546 int err;
2547 hda_nid_t lfe_pin = 0x0;
2548 int i;
2549
2550 /*
2551 * search speaker outs and line outs for a mono speaker pin
2552 * with an amp. If one is found, add LFE controls
2553 * for it.
2554 */
2555 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2556 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2557 unsigned long wcaps = get_wcaps(codec, pin);
2558 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2559 if (wcaps == AC_WCAP_OUT_AMP)
2560 /* found a mono speaker with an amp, must be lfe */
2561 lfe_pin = pin;
2562 }
2563
2564 /* if speaker_outs is 0, then speakers may be in line_outs */
2565 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2566 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2567 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2568 unsigned long cfg;
2569 cfg = snd_hda_codec_read(codec, pin, 0,
2570 AC_VERB_GET_CONFIG_DEFAULT,
2571 0x00);
2572 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
2573 unsigned long wcaps = get_wcaps(codec, pin);
2574 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2575 if (wcaps == AC_WCAP_OUT_AMP)
2576 /* found a mono speaker with an amp,
2577 must be lfe */
2578 lfe_pin = pin;
2579 }
2580 }
2581 }
2582
2583 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002584 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02002585 if (err < 0)
2586 return err;
2587 }
2588
2589 return 0;
2590}
2591
Mattc7d4b2f2005-06-27 14:59:41 +02002592static int stac9200_parse_auto_config(struct hda_codec *codec)
2593{
2594 struct sigmatel_spec *spec = codec->spec;
2595 int err;
2596
Kailang Yangdf694da2005-12-05 19:42:22 +01002597 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002598 return err;
2599
2600 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
2601 return err;
2602
Takashi Iwai82bc9552006-03-21 11:24:42 +01002603 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2604 return err;
2605
Richard Fish160ea0d2006-09-06 13:58:25 +02002606 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2607 return err;
2608
Takashi Iwai82bc9552006-03-21 11:24:42 +01002609 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002610 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002611 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002612 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02002613
2614 if (spec->kctl_alloc)
2615 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2616
2617 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002618 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002619
2620 return 1;
2621}
2622
Sam Revitch62fe78e2006-05-10 15:09:17 +02002623/*
2624 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2625 * funky external mute control using GPIO pins.
2626 */
2627
2628static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
2629{
2630 unsigned int gpiostate, gpiomask, gpiodir;
2631
2632 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2633 AC_VERB_GET_GPIO_DATA, 0);
2634
2635 if (!muted)
2636 gpiostate |= (1 << pin);
2637 else
2638 gpiostate &= ~(1 << pin);
2639
2640 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2641 AC_VERB_GET_GPIO_MASK, 0);
2642 gpiomask |= (1 << pin);
2643
2644 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2645 AC_VERB_GET_GPIO_DIRECTION, 0);
2646 gpiodir |= (1 << pin);
2647
2648 /* AppleHDA seems to do this -- WTF is this verb?? */
2649 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2650
2651 snd_hda_codec_write(codec, codec->afg, 0,
2652 AC_VERB_SET_GPIO_MASK, gpiomask);
2653 snd_hda_codec_write(codec, codec->afg, 0,
2654 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
2655
2656 msleep(1);
2657
2658 snd_hda_codec_write(codec, codec->afg, 0,
2659 AC_VERB_SET_GPIO_DATA, gpiostate);
2660}
2661
Takashi Iwai314634b2006-09-21 11:56:18 +02002662static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2663 unsigned int event)
2664{
2665 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002666 snd_hda_codec_write_cache(codec, nid, 0,
2667 AC_VERB_SET_UNSOLICITED_ENABLE,
2668 (AC_USRSP_EN | event));
Takashi Iwai314634b2006-09-21 11:56:18 +02002669}
2670
Mattc7d4b2f2005-06-27 14:59:41 +02002671static int stac92xx_init(struct hda_codec *codec)
2672{
2673 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002674 struct auto_pin_cfg *cfg = &spec->autocfg;
2675 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002676
Mattc7d4b2f2005-06-27 14:59:41 +02002677 snd_hda_sequence_write(codec, spec->init);
2678
Takashi Iwai82bc9552006-03-21 11:24:42 +01002679 /* set up pins */
2680 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02002681 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002682 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02002683 enable_pin_detect(codec, cfg->hp_pins[i],
2684 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01002685 /* force to enable the first line-out; the others are set up
2686 * in unsol_event
2687 */
2688 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2689 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02002690 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002691 /* fake event to set up pins */
2692 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2693 } else {
2694 stac92xx_auto_init_multi_out(codec);
2695 stac92xx_auto_init_hp_out(codec);
2696 }
2697 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01002698 hda_nid_t nid = cfg->input_pins[i];
2699 if (nid) {
2700 unsigned int pinctl = AC_PINCTL_IN_EN;
2701 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
2702 pinctl |= stac92xx_get_vref(codec, nid);
2703 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2704 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01002705 }
Matt Porter8b657272006-10-26 17:12:59 +02002706 if (spec->num_dmics > 0)
2707 for (i = 0; i < spec->num_dmics; i++)
2708 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
2709 AC_PINCTL_IN_EN);
2710
Takashi Iwai82bc9552006-03-21 11:24:42 +01002711 if (cfg->dig_out_pin)
2712 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2713 AC_PINCTL_OUT_EN);
2714 if (cfg->dig_in_pin)
2715 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2716 AC_PINCTL_IN_EN);
2717
Sam Revitch62fe78e2006-05-10 15:09:17 +02002718 if (spec->gpio_mute) {
2719 stac922x_gpio_mute(codec, 0, 0);
2720 stac922x_gpio_mute(codec, 1, 0);
2721 }
2722
Mattc7d4b2f2005-06-27 14:59:41 +02002723 return 0;
2724}
2725
Matt2f2f4252005-04-13 14:45:30 +02002726static void stac92xx_free(struct hda_codec *codec)
2727{
Mattc7d4b2f2005-06-27 14:59:41 +02002728 struct sigmatel_spec *spec = codec->spec;
2729 int i;
2730
2731 if (! spec)
2732 return;
2733
2734 if (spec->kctl_alloc) {
2735 for (i = 0; i < spec->num_kctl_used; i++)
2736 kfree(spec->kctl_alloc[i].name);
2737 kfree(spec->kctl_alloc);
2738 }
2739
Richard Fish11b44bb2006-08-23 18:31:34 +02002740 if (spec->bios_pin_configs)
2741 kfree(spec->bios_pin_configs);
2742
Mattc7d4b2f2005-06-27 14:59:41 +02002743 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02002744}
2745
Matt4e550962005-07-04 17:51:39 +02002746static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
2747 unsigned int flag)
2748{
2749 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2750 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002751
Takashi Iwaif9acba42007-05-29 18:01:06 +02002752 if (pin_ctl & AC_PINCTL_IN_EN) {
2753 /*
2754 * we need to check the current set-up direction of
2755 * shared input pins since they can be switched via
2756 * "xxx as Output" mixer switch
2757 */
2758 struct sigmatel_spec *spec = codec->spec;
2759 struct auto_pin_cfg *cfg = &spec->autocfg;
2760 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
2761 spec->line_switch) ||
2762 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
2763 spec->mic_switch))
2764 return;
2765 }
2766
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002767 /* if setting pin direction bits, clear the current
2768 direction bits first */
2769 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
2770 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
2771
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002772 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002773 AC_VERB_SET_PIN_WIDGET_CONTROL,
2774 pin_ctl | flag);
2775}
2776
2777static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
2778 unsigned int flag)
2779{
2780 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2781 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002782 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002783 AC_VERB_SET_PIN_WIDGET_CONTROL,
2784 pin_ctl & ~flag);
2785}
2786
Jiang Zhe40c1d302007-11-12 13:05:16 +01002787static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02002788{
2789 if (!nid)
2790 return 0;
2791 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Jiang Zhe40c1d302007-11-12 13:05:16 +01002792 & (1 << 31)) {
2793 unsigned int pinctl;
2794 pinctl = snd_hda_codec_read(codec, nid, 0,
2795 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2796 if (pinctl & AC_PINCTL_IN_EN)
2797 return 0; /* mic- or line-input */
2798 else
2799 return 1; /* HP-output */
2800 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002801 return 0;
2802}
2803
2804static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02002805{
2806 struct sigmatel_spec *spec = codec->spec;
2807 struct auto_pin_cfg *cfg = &spec->autocfg;
2808 int i, presence;
2809
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002810 presence = 0;
2811 for (i = 0; i < cfg->hp_outs; i++) {
Jiang Zhe40c1d302007-11-12 13:05:16 +01002812 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
Takashi Iwai314634b2006-09-21 11:56:18 +02002813 if (presence)
2814 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002815 }
Matt4e550962005-07-04 17:51:39 +02002816
2817 if (presence) {
2818 /* disable lineouts, enable hp */
2819 for (i = 0; i < cfg->line_outs; i++)
2820 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
2821 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002822 for (i = 0; i < cfg->speaker_outs; i++)
2823 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
2824 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002825 } else {
2826 /* enable lineouts, disable hp */
2827 for (i = 0; i < cfg->line_outs; i++)
2828 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
2829 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002830 for (i = 0; i < cfg->speaker_outs; i++)
2831 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
2832 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002833 }
2834}
2835
Takashi Iwai314634b2006-09-21 11:56:18 +02002836static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
2837{
2838 switch (res >> 26) {
2839 case STAC_HP_EVENT:
2840 stac92xx_hp_detect(codec, res);
2841 break;
2842 }
2843}
2844
Takashi Iwaicb53c622007-08-10 17:21:45 +02002845#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002846static int stac92xx_resume(struct hda_codec *codec)
2847{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002848 struct sigmatel_spec *spec = codec->spec;
2849
Richard Fish11b44bb2006-08-23 18:31:34 +02002850 stac92xx_set_config_regs(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002851 snd_hda_sequence_write(codec, spec->init);
2852 if (spec->gpio_mute) {
2853 stac922x_gpio_mute(codec, 0, 0);
2854 stac922x_gpio_mute(codec, 1, 0);
2855 }
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002856 snd_hda_codec_resume_amp(codec);
2857 snd_hda_codec_resume_cache(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002858 /* invoke unsolicited event to reset the HP state */
2859 if (spec->hp_detect)
2860 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Mattff6fdc32005-06-27 15:06:52 +02002861 return 0;
2862}
2863#endif
2864
Matt2f2f4252005-04-13 14:45:30 +02002865static struct hda_codec_ops stac92xx_patch_ops = {
2866 .build_controls = stac92xx_build_controls,
2867 .build_pcms = stac92xx_build_pcms,
2868 .init = stac92xx_init,
2869 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02002870 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002871#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002872 .resume = stac92xx_resume,
2873#endif
Matt2f2f4252005-04-13 14:45:30 +02002874};
2875
2876static int patch_stac9200(struct hda_codec *codec)
2877{
2878 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002879 int err;
Matt2f2f4252005-04-13 14:45:30 +02002880
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002881 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002882 if (spec == NULL)
2883 return -ENOMEM;
2884
2885 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002886 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002887 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002888 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
2889 stac9200_models,
2890 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02002891 if (spec->board_config < 0) {
2892 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
2893 err = stac92xx_save_bios_config_regs(codec);
2894 if (err < 0) {
2895 stac92xx_free(codec);
2896 return err;
2897 }
2898 spec->pin_configs = spec->bios_pin_configs;
2899 } else {
Matt Porter403d1942005-11-29 15:00:51 +01002900 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
2901 stac92xx_set_config_regs(codec);
2902 }
Matt2f2f4252005-04-13 14:45:30 +02002903
2904 spec->multiout.max_channels = 2;
2905 spec->multiout.num_dacs = 1;
2906 spec->multiout.dac_nids = stac9200_dac_nids;
2907 spec->adc_nids = stac9200_adc_nids;
2908 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02002909 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02002910 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002911 spec->num_adcs = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002912
Takashi Iwai1194b5b2007-10-10 10:04:26 +02002913 if (spec->board_config == STAC_9200_GATEWAY)
2914 spec->init = stac9200_eapd_init;
2915 else
2916 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002917 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002918
2919 err = stac9200_parse_auto_config(codec);
2920 if (err < 0) {
2921 stac92xx_free(codec);
2922 return err;
2923 }
Matt2f2f4252005-04-13 14:45:30 +02002924
2925 codec->patch_ops = stac92xx_patch_ops;
2926
2927 return 0;
2928}
2929
Tobin Davis8e21c342007-01-08 11:04:17 +01002930static int patch_stac925x(struct hda_codec *codec)
2931{
2932 struct sigmatel_spec *spec;
2933 int err;
2934
2935 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2936 if (spec == NULL)
2937 return -ENOMEM;
2938
2939 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002940 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002941 spec->pin_nids = stac925x_pin_nids;
2942 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2943 stac925x_models,
2944 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002945 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002946 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002947 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2948 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002949 err = stac92xx_save_bios_config_regs(codec);
2950 if (err < 0) {
2951 stac92xx_free(codec);
2952 return err;
2953 }
2954 spec->pin_configs = spec->bios_pin_configs;
2955 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2956 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2957 stac92xx_set_config_regs(codec);
2958 }
2959
2960 spec->multiout.max_channels = 2;
2961 spec->multiout.num_dacs = 1;
2962 spec->multiout.dac_nids = stac925x_dac_nids;
2963 spec->adc_nids = stac925x_adc_nids;
2964 spec->mux_nids = stac925x_mux_nids;
2965 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002966 spec->num_adcs = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002967 switch (codec->vendor_id) {
2968 case 0x83847632: /* STAC9202 */
2969 case 0x83847633: /* STAC9202D */
2970 case 0x83847636: /* STAC9251 */
2971 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02002972 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02002973 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01002974 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
2975 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02002976 break;
2977 default:
2978 spec->num_dmics = 0;
2979 break;
2980 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002981
2982 spec->init = stac925x_core_init;
2983 spec->mixer = stac925x_mixer;
2984
2985 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002986 if (!err) {
2987 if (spec->board_config < 0) {
2988 printk(KERN_WARNING "hda_codec: No auto-config is "
2989 "available, default to model=ref\n");
2990 spec->board_config = STAC_925x_REF;
2991 goto again;
2992 }
2993 err = -EINVAL;
2994 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002995 if (err < 0) {
2996 stac92xx_free(codec);
2997 return err;
2998 }
2999
3000 codec->patch_ops = stac92xx_patch_ops;
3001
3002 return 0;
3003}
3004
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003005static struct hda_input_mux stac92hd73xx_dmux = {
3006 .num_items = 4,
3007 .items = {
3008 { "Analog Inputs", 0x0b },
3009 { "CD", 0x08 },
3010 { "Digital Mic 1", 0x09 },
3011 { "Digital Mic 2", 0x0a },
3012 }
3013};
3014
3015static int patch_stac92hd73xx(struct hda_codec *codec)
3016{
3017 struct sigmatel_spec *spec;
3018 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
3019 int err = 0;
3020
3021 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3022 if (spec == NULL)
3023 return -ENOMEM;
3024
3025 codec->spec = spec;
3026 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
3027 spec->pin_nids = stac92hd73xx_pin_nids;
3028 spec->board_config = snd_hda_check_board_config(codec,
3029 STAC_92HD73XX_MODELS,
3030 stac92hd73xx_models,
3031 stac92hd73xx_cfg_tbl);
3032again:
3033 if (spec->board_config < 0) {
3034 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3035 " STAC92HD73XX, using BIOS defaults\n");
3036 err = stac92xx_save_bios_config_regs(codec);
3037 if (err < 0) {
3038 stac92xx_free(codec);
3039 return err;
3040 }
3041 spec->pin_configs = spec->bios_pin_configs;
3042 } else {
3043 spec->pin_configs = stac92hd73xx_brd_tbl[spec->board_config];
3044 stac92xx_set_config_regs(codec);
3045 }
3046
3047 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
3048 conn, STAC92HD73_DAC_COUNT + 2) - 1;
3049
3050 if (spec->multiout.num_dacs < 0) {
3051 printk(KERN_WARNING "hda_codec: Could not determine "
3052 "number of channels defaulting to DAC count\n");
3053 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
3054 }
3055
3056 switch (spec->multiout.num_dacs) {
3057 case 0x3: /* 6 Channel */
3058 spec->mixer = stac92hd73xx_6ch_mixer;
3059 spec->init = stac92hd73xx_6ch_core_init;
3060 break;
3061 case 0x4: /* 8 Channel */
3062 spec->multiout.hp_nid = 0x18;
3063 spec->mixer = stac92hd73xx_8ch_mixer;
3064 spec->init = stac92hd73xx_8ch_core_init;
3065 break;
3066 case 0x5: /* 10 Channel */
3067 spec->multiout.hp_nid = 0x19;
3068 spec->mixer = stac92hd73xx_10ch_mixer;
3069 spec->init = stac92hd73xx_10ch_core_init;
3070 };
3071
3072 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
3073 spec->aloopback_mask = 0x01;
3074 spec->aloopback_shift = 8;
3075
3076 spec->mux_nids = stac92hd73xx_mux_nids;
3077 spec->adc_nids = stac92hd73xx_adc_nids;
3078 spec->dmic_nids = stac92hd73xx_dmic_nids;
3079 spec->dmux_nids = stac92hd73xx_dmux_nids;
3080
3081 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
3082 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
3083 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003084 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003085 spec->dinput_mux = &stac92hd73xx_dmux;
3086 /* GPIO0 High = Enable EAPD */
3087 spec->gpio_mask = spec->gpio_data = 0x000001;
3088 stac92xx_enable_gpio_mask(codec);
3089
3090 err = stac92xx_parse_auto_config(codec, 0x22, 0x24);
3091
3092 if (!err) {
3093 if (spec->board_config < 0) {
3094 printk(KERN_WARNING "hda_codec: No auto-config is "
3095 "available, default to model=ref\n");
3096 spec->board_config = STAC_92HD73XX_REF;
3097 goto again;
3098 }
3099 err = -EINVAL;
3100 }
3101
3102 if (err < 0) {
3103 stac92xx_free(codec);
3104 return err;
3105 }
3106
3107 codec->patch_ops = stac92xx_patch_ops;
3108
3109 return 0;
3110}
3111
Matthew Ranostaye035b842007-11-06 11:53:55 +01003112static int patch_stac92hd71bxx(struct hda_codec *codec)
3113{
3114 struct sigmatel_spec *spec;
3115 int err = 0;
3116
3117 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3118 if (spec == NULL)
3119 return -ENOMEM;
3120
3121 codec->spec = spec;
3122 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
3123 spec->pin_nids = stac92hd71bxx_pin_nids;
3124 spec->board_config = snd_hda_check_board_config(codec,
3125 STAC_92HD71BXX_MODELS,
3126 stac92hd71bxx_models,
3127 stac92hd71bxx_cfg_tbl);
3128again:
3129 if (spec->board_config < 0) {
3130 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3131 " STAC92HD71BXX, using BIOS defaults\n");
3132 err = stac92xx_save_bios_config_regs(codec);
3133 if (err < 0) {
3134 stac92xx_free(codec);
3135 return err;
3136 }
3137 spec->pin_configs = spec->bios_pin_configs;
3138 } else {
3139 spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config];
3140 stac92xx_set_config_regs(codec);
3141 }
3142
Matthew Ranostay541eee82007-12-14 12:08:04 +01003143 switch (codec->vendor_id) {
3144 case 0x111d76b6: /* 4 Port without Analog Mixer */
3145 case 0x111d76b7:
3146 case 0x111d76b4: /* 6 Port without Analog Mixer */
3147 case 0x111d76b5:
3148 spec->mixer = stac92hd71bxx_mixer;
3149 spec->init = stac92hd71bxx_core_init;
3150 break;
3151 default:
3152 spec->mixer = stac92hd71bxx_analog_mixer;
3153 spec->init = stac92hd71bxx_analog_core_init;
3154 }
3155
3156 spec->aloopback_mask = 0x20;
3157 spec->aloopback_shift = 0;
3158
Matthew Ranostaye035b842007-11-06 11:53:55 +01003159 spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */
3160 stac92xx_enable_gpio_mask(codec);
3161
Matthew Ranostaye035b842007-11-06 11:53:55 +01003162 spec->mux_nids = stac92hd71bxx_mux_nids;
3163 spec->adc_nids = stac92hd71bxx_adc_nids;
3164 spec->dmic_nids = stac92hd71bxx_dmic_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003165 spec->dmux_nids = stac92hd71bxx_dmux_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01003166
3167 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
3168 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
3169 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003170 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01003171
3172 spec->multiout.num_dacs = 2;
3173 spec->multiout.hp_nid = 0x11;
3174 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
3175
3176 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
3177 if (!err) {
3178 if (spec->board_config < 0) {
3179 printk(KERN_WARNING "hda_codec: No auto-config is "
3180 "available, default to model=ref\n");
3181 spec->board_config = STAC_92HD71BXX_REF;
3182 goto again;
3183 }
3184 err = -EINVAL;
3185 }
3186
3187 if (err < 0) {
3188 stac92xx_free(codec);
3189 return err;
3190 }
3191
3192 codec->patch_ops = stac92xx_patch_ops;
3193
3194 return 0;
3195};
3196
Matt2f2f4252005-04-13 14:45:30 +02003197static int patch_stac922x(struct hda_codec *codec)
3198{
3199 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003200 int err;
Matt2f2f4252005-04-13 14:45:30 +02003201
Takashi Iwaie560d8d2005-09-09 14:21:46 +02003202 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02003203 if (spec == NULL)
3204 return -ENOMEM;
3205
3206 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003207 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003208 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003209 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
3210 stac922x_models,
3211 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003212 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003213 spec->gpio_mute = 1;
3214 /* Intel Macs have all same PCI SSID, so we need to check
3215 * codec SSID to distinguish the exact models
3216 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01003217 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003218 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003219
3220 case 0x106b0800:
3221 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02003222 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003223 case 0x106b0600:
3224 case 0x106b0700:
3225 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01003226 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003227 case 0x106b0e00:
3228 case 0x106b0f00:
3229 case 0x106b1600:
3230 case 0x106b1700:
3231 case 0x106b0200:
3232 case 0x106b1e00:
3233 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003234 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003235 case 0x106b1a00:
3236 case 0x00000100:
3237 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02003238 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003239 case 0x106b0a00:
3240 case 0x106b2200:
3241 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02003242 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003243 }
3244 }
3245
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003246 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02003247 if (spec->board_config < 0) {
3248 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
3249 "using BIOS defaults\n");
3250 err = stac92xx_save_bios_config_regs(codec);
3251 if (err < 0) {
3252 stac92xx_free(codec);
3253 return err;
3254 }
3255 spec->pin_configs = spec->bios_pin_configs;
3256 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01003257 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
3258 stac92xx_set_config_regs(codec);
3259 }
Matt2f2f4252005-04-13 14:45:30 +02003260
Matt2f2f4252005-04-13 14:45:30 +02003261 spec->adc_nids = stac922x_adc_nids;
3262 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01003263 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003264 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02003265 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003266
3267 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02003268 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02003269
3270 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003271
Matt Porter3cc08dc2006-01-23 15:27:49 +01003272 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003273 if (!err) {
3274 if (spec->board_config < 0) {
3275 printk(KERN_WARNING "hda_codec: No auto-config is "
3276 "available, default to model=ref\n");
3277 spec->board_config = STAC_D945_REF;
3278 goto again;
3279 }
3280 err = -EINVAL;
3281 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01003282 if (err < 0) {
3283 stac92xx_free(codec);
3284 return err;
3285 }
3286
3287 codec->patch_ops = stac92xx_patch_ops;
3288
Takashi Iwai807a46362007-05-29 19:01:37 +02003289 /* Fix Mux capture level; max to 2 */
3290 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
3291 (0 << AC_AMPCAP_OFFSET_SHIFT) |
3292 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3293 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3294 (0 << AC_AMPCAP_MUTE_SHIFT));
3295
Matt Porter3cc08dc2006-01-23 15:27:49 +01003296 return 0;
3297}
3298
3299static int patch_stac927x(struct hda_codec *codec)
3300{
3301 struct sigmatel_spec *spec;
3302 int err;
3303
3304 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3305 if (spec == NULL)
3306 return -ENOMEM;
3307
3308 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003309 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003310 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003311 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
3312 stac927x_models,
3313 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003314 again:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003315 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
3316 if (spec->board_config < 0)
3317 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3318 "STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02003319 err = stac92xx_save_bios_config_regs(codec);
3320 if (err < 0) {
3321 stac92xx_free(codec);
3322 return err;
3323 }
3324 spec->pin_configs = spec->bios_pin_configs;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003325 } else {
Matt Porter3cc08dc2006-01-23 15:27:49 +01003326 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
3327 stac92xx_set_config_regs(codec);
3328 }
3329
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003330 spec->adc_nids = stac927x_adc_nids;
3331 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
3332 spec->mux_nids = stac927x_mux_nids;
3333 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
3334 spec->multiout.dac_nids = spec->dac_nids;
3335
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003336 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02003337 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003338 case STAC_D965_5ST:
3339 /* GPIO0 High = Enable EAPD */
3340 spec->gpio_mask = spec->gpio_data = 0x00000001;
3341 spec->num_dmics = 0;
3342
Tobin Davis93ed1502006-09-01 21:03:12 +02003343 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003344 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003345 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003346 case STAC_DELL_BIOS:
Matthew Ranostayc481fca2008-01-07 12:18:28 +01003347 /* correct the front input jack as a mic */
3348 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130);
3349 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003350 case STAC_DELL_3ST:
3351 /* GPIO2 High = Enable EAPD */
3352 spec->gpio_mask = spec->gpio_data = 0x00000004;
3353 spec->dmic_nids = stac927x_dmic_nids;
3354 spec->num_dmics = STAC927X_NUM_DMICS;
3355
Tobin Davis93ed1502006-09-01 21:03:12 +02003356 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003357 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003358 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003359 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003360 break;
3361 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003362 /* GPIO0 High = Enable EAPD */
3363 spec->gpio_mask = spec->gpio_data = 0x00000001;
3364 spec->num_dmics = 0;
3365
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003366 spec->init = stac927x_core_init;
3367 spec->mixer = stac927x_mixer;
3368 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01003369
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003370 spec->aloopback_mask = 0x40;
3371 spec->aloopback_shift = 0;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003372
Takashi Iwai82599802007-07-31 15:56:24 +02003373 stac92xx_enable_gpio_mask(codec);
Matt Porter3cc08dc2006-01-23 15:27:49 +01003374 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003375 if (!err) {
3376 if (spec->board_config < 0) {
3377 printk(KERN_WARNING "hda_codec: No auto-config is "
3378 "available, default to model=ref\n");
3379 spec->board_config = STAC_D965_REF;
3380 goto again;
3381 }
3382 err = -EINVAL;
3383 }
Mattc7d4b2f2005-06-27 14:59:41 +02003384 if (err < 0) {
3385 stac92xx_free(codec);
3386 return err;
3387 }
Matt2f2f4252005-04-13 14:45:30 +02003388
3389 codec->patch_ops = stac92xx_patch_ops;
3390
3391 return 0;
3392}
3393
Matt Porterf3302a52006-07-31 12:49:34 +02003394static int patch_stac9205(struct hda_codec *codec)
3395{
3396 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02003397 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02003398
3399 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3400 if (spec == NULL)
3401 return -ENOMEM;
3402
3403 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003404 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003405 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003406 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
3407 stac9205_models,
3408 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003409 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02003410 if (spec->board_config < 0) {
3411 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
3412 err = stac92xx_save_bios_config_regs(codec);
3413 if (err < 0) {
3414 stac92xx_free(codec);
3415 return err;
3416 }
3417 spec->pin_configs = spec->bios_pin_configs;
3418 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02003419 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
3420 stac92xx_set_config_regs(codec);
3421 }
3422
3423 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003424 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02003425 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01003426 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02003427 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02003428 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003429 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003430 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02003431
3432 spec->init = stac9205_core_init;
3433 spec->mixer = stac9205_mixer;
3434
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003435 spec->aloopback_mask = 0x40;
3436 spec->aloopback_shift = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02003437 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02003438
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003439 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003440 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02003441 /* Enable SPDIF in/out */
3442 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
3443 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01003444
Takashi Iwai82599802007-07-31 15:56:24 +02003445 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
Matthew Ranostay87d48362007-07-17 11:52:24 +02003446 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
3447 * GPIO2 High = Headphone Mute
3448 */
Takashi Iwai82599802007-07-31 15:56:24 +02003449 spec->gpio_data = 0x00000005;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003450 break;
3451 default:
3452 /* GPIO0 High = EAPD */
3453 spec->gpio_mask = spec->gpio_data = 0x00000001;
3454 break;
3455 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02003456
Takashi Iwai82599802007-07-31 15:56:24 +02003457 stac92xx_enable_gpio_mask(codec);
Matt Porterf3302a52006-07-31 12:49:34 +02003458 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003459 if (!err) {
3460 if (spec->board_config < 0) {
3461 printk(KERN_WARNING "hda_codec: No auto-config is "
3462 "available, default to model=ref\n");
3463 spec->board_config = STAC_9205_REF;
3464 goto again;
3465 }
3466 err = -EINVAL;
3467 }
Matt Porterf3302a52006-07-31 12:49:34 +02003468 if (err < 0) {
3469 stac92xx_free(codec);
3470 return err;
3471 }
3472
3473 codec->patch_ops = stac92xx_patch_ops;
3474
3475 return 0;
3476}
3477
Matt2f2f4252005-04-13 14:45:30 +02003478/*
Guillaume Munch6d859062006-08-22 17:15:47 +02003479 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01003480 */
3481
Guillaume Munch99ccc562006-08-16 19:35:12 +02003482/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003483static hda_nid_t vaio_dacs[] = { 0x2 };
3484#define VAIO_HP_DAC 0x5
3485static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
3486static hda_nid_t vaio_mux_nids[] = { 0x15 };
3487
3488static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02003489 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01003490 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02003491 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003492 { "Mic Jack", 0x1 },
3493 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01003494 { "PCM", 0x3 },
3495 }
3496};
3497
3498static struct hda_verb vaio_init[] = {
3499 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003500 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01003501 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3502 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3503 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3504 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003505 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003506 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3507 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3508 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3509 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3510 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3511 {}
3512};
3513
Guillaume Munch6d859062006-08-22 17:15:47 +02003514static struct hda_verb vaio_ar_init[] = {
3515 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
3516 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3517 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3518 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3519/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
3520 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003521 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02003522 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3523 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3524/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
3525 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3526 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3527 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3528 {}
3529};
3530
Takashi Iwaidb064e52006-03-16 16:04:58 +01003531/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003532static struct hda_bind_ctls vaio_bind_master_vol = {
3533 .ops = &snd_hda_bind_vol,
3534 .values = {
3535 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3536 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3537 0
3538 },
3539};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003540
3541/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003542static struct hda_bind_ctls vaio_bind_master_sw = {
3543 .ops = &snd_hda_bind_sw,
3544 .values = {
3545 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3546 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3547 0,
3548 },
3549};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003550
3551static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003552 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3553 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003554 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3555 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3556 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3557 {
3558 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3559 .name = "Capture Source",
3560 .count = 1,
3561 .info = stac92xx_mux_enum_info,
3562 .get = stac92xx_mux_enum_get,
3563 .put = stac92xx_mux_enum_put,
3564 },
3565 {}
3566};
3567
Guillaume Munch6d859062006-08-22 17:15:47 +02003568static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003569 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3570 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Guillaume Munch6d859062006-08-22 17:15:47 +02003571 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3572 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3573 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3574 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
3575 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
3576 {
3577 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3578 .name = "Capture Source",
3579 .count = 1,
3580 .info = stac92xx_mux_enum_info,
3581 .get = stac92xx_mux_enum_get,
3582 .put = stac92xx_mux_enum_put,
3583 },
3584 {}
3585};
3586
3587static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01003588 .build_controls = stac92xx_build_controls,
3589 .build_pcms = stac92xx_build_pcms,
3590 .init = stac92xx_init,
3591 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02003592#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01003593 .resume = stac92xx_resume,
3594#endif
3595};
3596
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003597static int stac9872_vaio_init(struct hda_codec *codec)
3598{
3599 int err;
3600
3601 err = stac92xx_init(codec);
3602 if (err < 0)
3603 return err;
3604 if (codec->patch_ops.unsol_event)
3605 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
3606 return 0;
3607}
3608
3609static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
3610{
Jiang Zhe40c1d302007-11-12 13:05:16 +01003611 if (get_hp_pin_presence(codec, 0x0a)) {
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003612 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3613 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3614 } else {
3615 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3616 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3617 }
3618}
3619
3620static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
3621{
3622 switch (res >> 26) {
3623 case STAC_HP_EVENT:
3624 stac9872_vaio_hp_detect(codec, res);
3625 break;
3626 }
3627}
3628
3629static struct hda_codec_ops stac9872_vaio_patch_ops = {
3630 .build_controls = stac92xx_build_controls,
3631 .build_pcms = stac92xx_build_pcms,
3632 .init = stac9872_vaio_init,
3633 .free = stac92xx_free,
3634 .unsol_event = stac9872_vaio_unsol_event,
3635#ifdef CONFIG_PM
3636 .resume = stac92xx_resume,
3637#endif
3638};
3639
Guillaume Munch6d859062006-08-22 17:15:47 +02003640enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
3641 CXD9872RD_VAIO,
3642 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
3643 STAC9872AK_VAIO,
3644 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
3645 STAC9872K_VAIO,
3646 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003647 CXD9872AKD_VAIO,
3648 STAC_9872_MODELS,
3649};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003650
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003651static const char *stac9872_models[STAC_9872_MODELS] = {
3652 [CXD9872RD_VAIO] = "vaio",
3653 [CXD9872AKD_VAIO] = "vaio-ar",
3654};
3655
3656static struct snd_pci_quirk stac9872_cfg_tbl[] = {
3657 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
3658 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
3659 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01003660 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003661 {}
3662};
3663
Guillaume Munch6d859062006-08-22 17:15:47 +02003664static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01003665{
3666 struct sigmatel_spec *spec;
3667 int board_config;
3668
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003669 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
3670 stac9872_models,
3671 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01003672 if (board_config < 0)
3673 /* unknown config, let generic-parser do its job... */
3674 return snd_hda_parse_generic_codec(codec);
3675
3676 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3677 if (spec == NULL)
3678 return -ENOMEM;
3679
3680 codec->spec = spec;
3681 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02003682 case CXD9872RD_VAIO:
3683 case STAC9872AK_VAIO:
3684 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01003685 spec->mixer = vaio_mixer;
3686 spec->init = vaio_init;
3687 spec->multiout.max_channels = 2;
3688 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3689 spec->multiout.dac_nids = vaio_dacs;
3690 spec->multiout.hp_nid = VAIO_HP_DAC;
3691 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3692 spec->adc_nids = vaio_adcs;
3693 spec->input_mux = &vaio_mux;
3694 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003695 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003696 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02003697
3698 case CXD9872AKD_VAIO:
3699 spec->mixer = vaio_ar_mixer;
3700 spec->init = vaio_ar_init;
3701 spec->multiout.max_channels = 2;
3702 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3703 spec->multiout.dac_nids = vaio_dacs;
3704 spec->multiout.hp_nid = VAIO_HP_DAC;
3705 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3706 spec->adc_nids = vaio_adcs;
3707 spec->input_mux = &vaio_mux;
3708 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003709 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02003710 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003711 }
3712
Takashi Iwaidb064e52006-03-16 16:04:58 +01003713 return 0;
3714}
3715
3716
3717/*
Matt2f2f4252005-04-13 14:45:30 +02003718 * patch entries
3719 */
3720struct hda_codec_preset snd_hda_preset_sigmatel[] = {
3721 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
3722 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
3723 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
3724 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
3725 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
3726 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
3727 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02003728 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
3729 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
3730 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
3731 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
3732 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
3733 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01003734 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
3735 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
3736 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
3737 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
3738 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
3739 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
3740 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
3741 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
3742 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
3743 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01003744 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
3745 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
3746 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
3747 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
3748 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
3749 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02003750 /* The following does not take into account .id=0x83847661 when subsys =
3751 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
3752 * currently not fully supported.
3753 */
3754 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
3755 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
3756 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02003757 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
3758 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
3759 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
3760 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
3761 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
3762 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
3763 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
3764 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostay541eee82007-12-14 12:08:04 +01003765 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
3766 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003767 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01003768 { .id = 0x111d7608, .name = "92HD71BXX", .patch = patch_stac92hd71bxx },
3769 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
3770 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
3771 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
3772 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
3773 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
3774 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
3775 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
3776 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02003777 {} /* terminator */
3778};