blob: 299e02a26e5850a3e8c4037519b0781097461fe5 [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},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100466 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
467 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
468 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
469 /* setup import muxs */
470 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
471 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
472 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
473 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
474 {}
475};
476
477static struct hda_verb stac92hd73xx_8ch_core_init[] = {
478 /* set master volume and direct control */
479 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
480 /* setup audio connections */
481 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
482 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
483 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
484 /* connect hp ports to dac3 */
485 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
486 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
487 /* setup adcs to point to mixer */
488 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
489 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100490 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
491 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
492 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
493 /* setup import muxs */
494 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
495 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
496 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
497 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
498 {}
499};
500
501static struct hda_verb stac92hd73xx_10ch_core_init[] = {
502 /* set master volume and direct control */
503 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
504 /* setup audio connections */
505 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
506 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
507 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
508 /* dac3 is connected to import3 mux */
509 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
510 /* connect hp ports to dac4 */
511 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
512 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
513 /* setup adcs to point to mixer */
514 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
515 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100516 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
517 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
518 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
519 /* setup import muxs */
520 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
521 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
522 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
523 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
524 {}
525};
526
Matthew Ranostaye035b842007-11-06 11:53:55 +0100527static struct hda_verb stac92hd71bxx_core_init[] = {
528 /* set master volume and direct control */
529 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
530 /* connect headphone jack to dac1 */
531 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100532 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
533 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
534 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
535 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
536 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
537 /* unmute mono out node */
538 { 0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
539};
540
541static struct hda_verb stac92hd71bxx_analog_core_init[] = {
542 /* set master volume and direct control */
543 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
544 /* connect headphone jack to dac1 */
545 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay9b359472007-11-07 13:03:12 +0100546 /* connect ports 0d and 0f to audio mixer */
547 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2},
548 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100549 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
Matthew Ranostay9b359472007-11-07 13:03:12 +0100550 /* unmute dac0 input in audio mixer */
551 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100552 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
553 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
554 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
555 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
556 /* unmute mono out node */
557 { 0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
558 {}
559};
560
Tobin Davis8e21c342007-01-08 11:04:17 +0100561static struct hda_verb stac925x_core_init[] = {
562 /* set dac0mux for dac converter */
563 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
564 {}
565};
566
Mattc7d4b2f2005-06-27 14:59:41 +0200567static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200568 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200569 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200570 {}
571};
572
Tobin Davis93ed1502006-09-01 21:03:12 +0200573static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200574 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200575 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200576 /* unmute node 0x1b */
577 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
578 /* select node 0x03 as DAC */
579 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
580 {}
581};
582
Matt Porter3cc08dc2006-01-23 15:27:49 +0100583static struct hda_verb stac927x_core_init[] = {
584 /* set master volume and direct control */
585 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
586 {}
587};
588
Matt Porterf3302a52006-07-31 12:49:34 +0200589static struct hda_verb stac9205_core_init[] = {
590 /* set master volume and direct control */
591 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
592 {}
593};
594
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200595#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200596 { \
597 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
598 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200599 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200600 .info = stac92xx_mux_enum_info, \
601 .get = stac92xx_mux_enum_get, \
602 .put = stac92xx_mux_enum_put, \
603 }
604
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100605#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200606 { \
607 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
608 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100609 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200610 .info = stac92xx_aloopback_info, \
611 .get = stac92xx_aloopback_get, \
612 .put = stac92xx_aloopback_put, \
613 .private_value = verb_read | (verb_write << 16), \
614 }
615
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100616static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200617 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
618 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200619 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200620 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
621 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200622 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200623 { } /* end */
624};
625
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100626static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100627 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
628
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100629 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
630 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
631
632 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
633 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
634
635 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
636 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
637
638 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
639 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
640
641 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
642 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
643
644 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
645 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
646
647 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
648 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
649 { } /* end */
650};
651
652static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100653 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
654
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100655 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
656 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
657
658 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
659 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
660
661 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
662 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
663
664 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
665 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
666
667 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
668 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
669
670 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
671 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
672
673 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
674 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
675 { } /* end */
676};
677
678static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100679 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
680
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100681 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
682 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
683
684 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
685 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
686
687 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
688 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
689
690 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
691 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
692
693 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
694 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
695
696 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
697 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
698
699 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
700 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
701 { } /* end */
702};
703
Matthew Ranostay541eee82007-12-14 12:08:04 +0100704static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100705 STAC_INPUT_SOURCE(2),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100706
Matthew Ranostay9b359472007-11-07 13:03:12 +0100707 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
708 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
709 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
710
711 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
712 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
713 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
714
715 HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT),
716 HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100717 { } /* end */
718};
719
Matthew Ranostay541eee82007-12-14 12:08:04 +0100720static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +0100721 STAC_INPUT_SOURCE(2),
722 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
723
Matthew Ranostay541eee82007-12-14 12:08:04 +0100724 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
725 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
726 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
727
728 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
729 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
730 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
731 { } /* end */
732};
733
Tobin Davis8e21c342007-01-08 11:04:17 +0100734static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200735 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +0100736 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
737 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
738 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
739 { } /* end */
740};
741
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100742static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200743 STAC_INPUT_SOURCE(2),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100744 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200745
746 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
747 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
748 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
749
750 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
751 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
752 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
753
754 { } /* end */
755};
756
757/* This needs to be generated dynamically based on sequence */
758static struct snd_kcontrol_new stac922x_mixer[] = {
759 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200760 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
761 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
762 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
763
764 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
765 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
766 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
767 { } /* end */
768};
769
770
771static struct snd_kcontrol_new stac927x_mixer[] = {
772 STAC_INPUT_SOURCE(3),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100773 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200774
775 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
776 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
777 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
778
779 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
780 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
781 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
782
783 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
784 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
785 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +0200786 { } /* end */
787};
788
Takashi Iwai1697055e2007-12-18 18:05:52 +0100789static struct snd_kcontrol_new stac_dmux_mixer = {
790 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
791 .name = "Digital Input Source",
792 /* count set later */
793 .info = stac92xx_dmux_enum_info,
794 .get = stac92xx_dmux_enum_get,
795 .put = stac92xx_dmux_enum_put,
796};
797
Matt2f2f4252005-04-13 14:45:30 +0200798static int stac92xx_build_controls(struct hda_codec *codec)
799{
800 struct sigmatel_spec *spec = codec->spec;
801 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200802 int i;
Matt2f2f4252005-04-13 14:45:30 +0200803
804 err = snd_hda_add_new_ctls(codec, spec->mixer);
805 if (err < 0)
806 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200807
808 for (i = 0; i < spec->num_mixers; i++) {
809 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
810 if (err < 0)
811 return err;
812 }
Takashi Iwai1697055e2007-12-18 18:05:52 +0100813 if (spec->num_dmuxes > 0) {
814 stac_dmux_mixer.count = spec->num_dmuxes;
815 err = snd_ctl_add(codec->bus->card,
816 snd_ctl_new1(&stac_dmux_mixer, codec));
817 if (err < 0)
818 return err;
819 }
Mattc7d4b2f2005-06-27 14:59:41 +0200820
Mattdabbed62005-06-14 10:19:34 +0200821 if (spec->multiout.dig_out_nid) {
822 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
823 if (err < 0)
824 return err;
825 }
826 if (spec->dig_in_nid) {
827 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
828 if (err < 0)
829 return err;
830 }
831 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200832}
833
Matt Porter403d1942005-11-29 15:00:51 +0100834static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200835 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200836 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
837};
838
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200839/*
840 STAC 9200 pin configs for
841 102801A8
842 102801DE
843 102801E8
844*/
845static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200846 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
847 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200848};
849
850/*
851 STAC 9200 pin configs for
852 102801C0
853 102801C1
854*/
855static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200856 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
857 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200858};
859
860/*
861 STAC 9200 pin configs for
862 102801C4 (Dell Dimension E310)
863 102801C5
864 102801C7
865 102801D9
866 102801DA
867 102801E3
868*/
869static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200870 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
871 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200872};
873
874
875/*
876 STAC 9200-32 pin configs for
877 102801B5 (Dell Inspiron 630m)
878 102801D8 (Dell Inspiron 640m)
879*/
880static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200881 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
882 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200883};
884
885/*
886 STAC 9200-32 pin configs for
887 102801C2 (Dell Latitude D620)
888 102801C8
889 102801CC (Dell Latitude D820)
890 102801D4
891 102801D6
892*/
893static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200894 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
895 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200896};
897
898/*
899 STAC 9200-32 pin configs for
900 102801CE (Dell XPS M1710)
901 102801CF (Dell Precision M90)
902*/
903static unsigned int dell9200_m23_pin_configs[8] = {
904 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
905 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
906};
907
908/*
909 STAC 9200-32 pin configs for
910 102801C9
911 102801CA
912 102801CB (Dell Latitude 120L)
913 102801D3
914*/
915static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200916 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
917 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200918};
919
920/*
921 STAC 9200-32 pin configs for
922 102801BD (Dell Inspiron E1505n)
923 102801EE
924 102801EF
925*/
926static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200927 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
928 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200929};
930
931/*
932 STAC 9200-32 pin configs for
933 102801F5 (Dell Inspiron 1501)
934 102801F6
935*/
936static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200937 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
938 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200939};
940
941/*
942 STAC 9200-32
943 102801CD (Dell Inspiron E1705/9400)
944*/
945static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200946 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
947 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200948};
949
950
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100951static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
952 [STAC_REF] = ref9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200953 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
954 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
955 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
956 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
957 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
958 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
959 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
960 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
961 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
962 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100963};
964
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100965static const char *stac9200_models[STAC_9200_MODELS] = {
966 [STAC_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200967 [STAC_9200_DELL_D21] = "dell-d21",
968 [STAC_9200_DELL_D22] = "dell-d22",
969 [STAC_9200_DELL_D23] = "dell-d23",
970 [STAC_9200_DELL_M21] = "dell-m21",
971 [STAC_9200_DELL_M22] = "dell-m22",
972 [STAC_9200_DELL_M23] = "dell-m23",
973 [STAC_9200_DELL_M24] = "dell-m24",
974 [STAC_9200_DELL_M25] = "dell-m25",
975 [STAC_9200_DELL_M26] = "dell-m26",
976 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200977 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100978};
979
980static struct snd_pci_quirk stac9200_cfg_tbl[] = {
981 /* SigmaTel reference board */
982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
983 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100984 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200985 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
986 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100987 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200988 "Dell Inspiron 630m", STAC_9200_DELL_M21),
989 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
990 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
991 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
992 "unknown Dell", STAC_9200_DELL_D22),
993 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
994 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100995 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200996 "Dell Latitude D620", STAC_9200_DELL_M22),
997 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
998 "unknown Dell", STAC_9200_DELL_D23),
999 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1000 "unknown Dell", STAC_9200_DELL_D23),
1001 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1002 "unknown Dell", STAC_9200_DELL_M22),
1003 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1004 "unknown Dell", STAC_9200_DELL_M24),
1005 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1006 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001007 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001008 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001009 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001010 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001011 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001012 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001013 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001014 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001015 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001016 "Dell Precision M90", STAC_9200_DELL_M23),
1017 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1018 "unknown Dell", STAC_9200_DELL_M22),
1019 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1020 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001021 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001022 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001023 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001024 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1025 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1026 "unknown Dell", STAC_9200_DELL_D23),
1027 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1028 "unknown Dell", STAC_9200_DELL_D23),
1029 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1030 "unknown Dell", STAC_9200_DELL_D21),
1031 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1032 "unknown Dell", STAC_9200_DELL_D23),
1033 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1034 "unknown Dell", STAC_9200_DELL_D21),
1035 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1036 "unknown Dell", STAC_9200_DELL_M25),
1037 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1038 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001039 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001040 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1041 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1042 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001043 /* Panasonic */
1044 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001045 /* Gateway machines needs EAPD to be set on resume */
1046 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1047 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1048 STAC_9200_GATEWAY),
1049 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1050 STAC_9200_GATEWAY),
Matt Porter403d1942005-11-29 15:00:51 +01001051 {} /* terminator */
1052};
1053
Tobin Davis8e21c342007-01-08 11:04:17 +01001054static unsigned int ref925x_pin_configs[8] = {
1055 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1056 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
1057};
1058
1059static unsigned int stac925x_MA6_pin_configs[8] = {
1060 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1061 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
1062};
1063
Tobin Davis2c11f952007-05-17 09:36:34 +02001064static unsigned int stac925x_PA6_pin_configs[8] = {
1065 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1066 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
1067};
1068
Tobin Davis8e21c342007-01-08 11:04:17 +01001069static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +02001070 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
1071 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001072};
1073
1074static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1075 [STAC_REF] = ref925x_pin_configs,
1076 [STAC_M2_2] = stac925xM2_2_pin_configs,
1077 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +02001078 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001079};
1080
1081static const char *stac925x_models[STAC_925x_MODELS] = {
1082 [STAC_REF] = "ref",
1083 [STAC_M2_2] = "m2-2",
1084 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +02001085 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001086};
1087
1088static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1089 /* SigmaTel reference board */
1090 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001091 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +01001092 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
1093 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
1094 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +02001095 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +01001096 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
1097 {} /* terminator */
1098};
1099
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001100static unsigned int ref92hd73xx_pin_configs[12] = {
1101 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1102 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1103 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1104};
1105
1106static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1107 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1108};
1109
1110static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1111 [STAC_92HD73XX_REF] = "ref",
1112};
1113
1114static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1115 /* SigmaTel reference board */
1116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1117 "DFI LanParty", STAC_92HD73XX_REF),
1118 {} /* terminator */
1119};
1120
Matthew Ranostaye035b842007-11-06 11:53:55 +01001121static unsigned int ref92hd71bxx_pin_configs[10] = {
1122 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1123 0x0181302e, 0x01114010, 0x01a19020, 0x90a000f0,
1124 0x90a000f0, 0x01452050,
1125};
1126
1127static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1128 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1129};
1130
1131static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1132 [STAC_92HD71BXX_REF] = "ref",
1133};
1134
1135static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1136 /* SigmaTel reference board */
1137 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1138 "DFI LanParty", STAC_92HD71BXX_REF),
1139 {} /* terminator */
1140};
1141
Matt Porter403d1942005-11-29 15:00:51 +01001142static unsigned int ref922x_pin_configs[10] = {
1143 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1144 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001145 0x40000100, 0x40000100,
1146};
1147
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001148/*
1149 STAC 922X pin configs for
1150 102801A7
1151 102801AB
1152 102801A9
1153 102801D1
1154 102801D2
1155*/
1156static unsigned int dell_922x_d81_pin_configs[10] = {
1157 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1158 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1159 0x01813122, 0x400001f2,
1160};
1161
1162/*
1163 STAC 922X pin configs for
1164 102801AC
1165 102801D0
1166*/
1167static unsigned int dell_922x_d82_pin_configs[10] = {
1168 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1169 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1170 0x01813122, 0x400001f1,
1171};
1172
1173/*
1174 STAC 922X pin configs for
1175 102801BF
1176*/
1177static unsigned int dell_922x_m81_pin_configs[10] = {
1178 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1179 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1180 0x40C003f1, 0x405003f0,
1181};
1182
1183/*
1184 STAC 9221 A1 pin configs for
1185 102801D7 (Dell XPS M1210)
1186*/
1187static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001188 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1189 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001190 0x508003f3, 0x405003f4,
1191};
1192
Matt Porter403d1942005-11-29 15:00:51 +01001193static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001194 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001195 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1196 0x02a19120, 0x40000100,
1197};
1198
1199static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001200 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1201 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001202 0x02a19320, 0x40000100,
1203};
1204
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001205static unsigned int intel_mac_v1_pin_configs[10] = {
1206 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1207 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001208 0x400000fc, 0x400000fb,
1209};
1210
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001211static unsigned int intel_mac_v2_pin_configs[10] = {
1212 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1213 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001214 0x400000fc, 0x400000fb,
1215};
1216
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001217static unsigned int intel_mac_v3_pin_configs[10] = {
1218 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1219 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1220 0x400000fc, 0x400000fb,
1221};
1222
1223static unsigned int intel_mac_v4_pin_configs[10] = {
1224 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1225 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1226 0x400000fc, 0x400000fb,
1227};
1228
1229static unsigned int intel_mac_v5_pin_configs[10] = {
1230 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1231 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1232 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001233};
1234
Takashi Iwai76c08822007-06-19 12:17:42 +02001235
Takashi Iwai19039bd2006-06-28 15:52:16 +02001236static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001237 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001238 [STAC_D945GTP3] = d945gtp3_pin_configs,
1239 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001240 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1241 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1242 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1243 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1244 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001245 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001246 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1247 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1248 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1249 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1250 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1251 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001252 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1253 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1254 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1255 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001256};
1257
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001258static const char *stac922x_models[STAC_922X_MODELS] = {
1259 [STAC_D945_REF] = "ref",
1260 [STAC_D945GTP5] = "5stack",
1261 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001262 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1263 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1264 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1265 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1266 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001267 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001268 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001269 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001270 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1271 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001272 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001273 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001274 [STAC_922X_DELL_D81] = "dell-d81",
1275 [STAC_922X_DELL_D82] = "dell-d82",
1276 [STAC_922X_DELL_M81] = "dell-m81",
1277 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001278};
1279
1280static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1281 /* SigmaTel reference board */
1282 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1283 "DFI LanParty", STAC_D945_REF),
1284 /* Intel 945G based systems */
1285 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1286 "Intel D945G", STAC_D945GTP3),
1287 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1288 "Intel D945G", STAC_D945GTP3),
1289 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1290 "Intel D945G", STAC_D945GTP3),
1291 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1292 "Intel D945G", STAC_D945GTP3),
1293 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1294 "Intel D945G", STAC_D945GTP3),
1295 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1296 "Intel D945G", STAC_D945GTP3),
1297 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1298 "Intel D945G", STAC_D945GTP3),
1299 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1300 "Intel D945G", STAC_D945GTP3),
1301 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1302 "Intel D945G", STAC_D945GTP3),
1303 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1304 "Intel D945G", STAC_D945GTP3),
1305 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1306 "Intel D945G", STAC_D945GTP3),
1307 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1308 "Intel D945G", STAC_D945GTP3),
1309 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1310 "Intel D945G", STAC_D945GTP3),
1311 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1312 "Intel D945G", STAC_D945GTP3),
1313 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1314 "Intel D945G", STAC_D945GTP3),
1315 /* Intel D945G 5-stack systems */
1316 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1317 "Intel D945G", STAC_D945GTP5),
1318 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1319 "Intel D945G", STAC_D945GTP5),
1320 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1321 "Intel D945G", STAC_D945GTP5),
1322 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1323 "Intel D945G", STAC_D945GTP5),
1324 /* Intel 945P based systems */
1325 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1326 "Intel D945P", STAC_D945GTP3),
1327 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1328 "Intel D945P", STAC_D945GTP3),
1329 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1330 "Intel D945P", STAC_D945GTP3),
1331 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1332 "Intel D945P", STAC_D945GTP3),
1333 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1334 "Intel D945P", STAC_D945GTP3),
1335 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1336 "Intel D945P", STAC_D945GTP5),
1337 /* other systems */
1338 /* Apple Mac Mini (early 2006) */
1339 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001340 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001341 /* Dell systems */
1342 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1343 "unknown Dell", STAC_922X_DELL_D81),
1344 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1345 "unknown Dell", STAC_922X_DELL_D81),
1346 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1347 "unknown Dell", STAC_922X_DELL_D81),
1348 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1349 "unknown Dell", STAC_922X_DELL_D82),
1350 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1351 "unknown Dell", STAC_922X_DELL_M81),
1352 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1353 "unknown Dell", STAC_922X_DELL_D82),
1354 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1355 "unknown Dell", STAC_922X_DELL_D81),
1356 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1357 "unknown Dell", STAC_922X_DELL_D81),
1358 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1359 "Dell XPS M1210", STAC_922X_DELL_M82),
Matt Porter403d1942005-11-29 15:00:51 +01001360 {} /* terminator */
1361};
1362
Matt Porter3cc08dc2006-01-23 15:27:49 +01001363static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001364 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1365 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1366 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1367 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001368};
1369
Tobin Davis93ed1502006-09-01 21:03:12 +02001370static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001371 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1372 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1373 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1374 0x40000100, 0x40000100
1375};
1376
Tobin Davis93ed1502006-09-01 21:03:12 +02001377static unsigned int d965_5st_pin_configs[14] = {
1378 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1379 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1380 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1381 0x40000100, 0x40000100
1382};
1383
Tobin Davis4ff076e2007-08-07 11:48:12 +02001384static unsigned int dell_3st_pin_configs[14] = {
1385 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1386 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001387 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001388 0x40c003fc, 0x40000100
1389};
1390
Tobin Davis93ed1502006-09-01 21:03:12 +02001391static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001392 [STAC_D965_REF] = ref927x_pin_configs,
1393 [STAC_D965_3ST] = d965_3st_pin_configs,
1394 [STAC_D965_5ST] = d965_5st_pin_configs,
1395 [STAC_DELL_3ST] = dell_3st_pin_configs,
1396 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001397};
1398
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001399static const char *stac927x_models[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001400 [STAC_D965_REF] = "ref",
1401 [STAC_D965_3ST] = "3stack",
1402 [STAC_D965_5ST] = "5stack",
1403 [STAC_DELL_3ST] = "dell-3stack",
1404 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001405};
1406
1407static struct snd_pci_quirk stac927x_cfg_tbl[] = {
1408 /* SigmaTel reference board */
1409 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1410 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001411 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001412 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
1413 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001414 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001415 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
1416 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
1417 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
1418 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
1419 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
1420 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
1421 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
1422 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
1423 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
1424 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
1425 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
1426 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
1427 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
1428 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
1429 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
1430 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001431 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001432 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_3ST),
1433 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001434 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001435 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
1436 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001437 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_3ST),
1438 /* Dell 3 stack systems with verb table in BIOS */
1439 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell ", STAC_DELL_BIOS),
1440 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
1441 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
1442 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
1443 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
1444 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02001445 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001446 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
1447 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
1448 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
1449 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
1450 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
1451 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
1452 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
1453 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
1454 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01001455 {} /* terminator */
1456};
1457
Matt Porterf3302a52006-07-31 12:49:34 +02001458static unsigned int ref9205_pin_configs[12] = {
1459 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +02001460 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
1461 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02001462};
1463
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001464/*
1465 STAC 9205 pin configs for
1466 102801F1
1467 102801F2
1468 102801FC
1469 102801FD
1470 10280204
1471 1028021F
1472*/
1473static unsigned int dell_9205_m42_pin_configs[12] = {
1474 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1475 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1476 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1477};
1478
1479/*
1480 STAC 9205 pin configs for
1481 102801F9
1482 102801FA
1483 102801FE
1484 102801FF (Dell Precision M4300)
1485 10280206
1486 10280200
1487 10280201
1488*/
1489static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001490 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1491 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1492 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1493};
1494
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001495static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001496 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1497 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1498 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1499};
1500
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001501static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001502 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001503 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1504 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1505 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02001506};
1507
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001508static const char *stac9205_models[STAC_9205_MODELS] = {
1509 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001510 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001511 [STAC_9205_DELL_M43] = "dell-m43",
1512 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001513};
1514
1515static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1516 /* SigmaTel reference board */
1517 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1518 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001519 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1520 "unknown Dell", STAC_9205_DELL_M42),
1521 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1522 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001523 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02001524 "Dell Precision", STAC_9205_DELL_M43),
1525 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
1526 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001527 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1528 "Dell Precision", STAC_9205_DELL_M43),
Matthew Ranostaye45e4592007-09-10 23:09:42 +02001529 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
1530 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001531 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1532 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001533 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1534 "unknown Dell", STAC_9205_DELL_M42),
1535 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1536 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001537 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1538 "Dell Precision", STAC_9205_DELL_M43),
1539 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001540 "Dell Precision M4300", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001541 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1542 "Dell Precision", STAC_9205_DELL_M43),
1543 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1544 "Dell Inspiron", STAC_9205_DELL_M44),
1545 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1546 "Dell Inspiron", STAC_9205_DELL_M44),
1547 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1548 "Dell Inspiron", STAC_9205_DELL_M44),
1549 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1550 "Dell Inspiron", STAC_9205_DELL_M44),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001551 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1552 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001553 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1554 "Dell Inspiron", STAC_9205_DELL_M44),
Matt Porterf3302a52006-07-31 12:49:34 +02001555 {} /* terminator */
1556};
1557
Richard Fish11b44bb2006-08-23 18:31:34 +02001558static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1559{
1560 int i;
1561 struct sigmatel_spec *spec = codec->spec;
1562
1563 if (! spec->bios_pin_configs) {
1564 spec->bios_pin_configs = kcalloc(spec->num_pins,
1565 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1566 if (! spec->bios_pin_configs)
1567 return -ENOMEM;
1568 }
1569
1570 for (i = 0; i < spec->num_pins; i++) {
1571 hda_nid_t nid = spec->pin_nids[i];
1572 unsigned int pin_cfg;
1573
1574 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1575 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1576 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1577 nid, pin_cfg);
1578 spec->bios_pin_configs[i] = pin_cfg;
1579 }
1580
1581 return 0;
1582}
1583
Matthew Ranostay87d48362007-07-17 11:52:24 +02001584static void stac92xx_set_config_reg(struct hda_codec *codec,
1585 hda_nid_t pin_nid, unsigned int pin_config)
1586{
1587 int i;
1588 snd_hda_codec_write(codec, pin_nid, 0,
1589 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1590 pin_config & 0x000000ff);
1591 snd_hda_codec_write(codec, pin_nid, 0,
1592 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1593 (pin_config & 0x0000ff00) >> 8);
1594 snd_hda_codec_write(codec, pin_nid, 0,
1595 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1596 (pin_config & 0x00ff0000) >> 16);
1597 snd_hda_codec_write(codec, pin_nid, 0,
1598 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1599 pin_config >> 24);
1600 i = snd_hda_codec_read(codec, pin_nid, 0,
1601 AC_VERB_GET_CONFIG_DEFAULT,
1602 0x00);
1603 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1604 pin_nid, i);
1605}
1606
Matt2f2f4252005-04-13 14:45:30 +02001607static void stac92xx_set_config_regs(struct hda_codec *codec)
1608{
1609 int i;
1610 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02001611
Matthew Ranostay87d48362007-07-17 11:52:24 +02001612 if (!spec->pin_configs)
1613 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02001614
Matthew Ranostay87d48362007-07-17 11:52:24 +02001615 for (i = 0; i < spec->num_pins; i++)
1616 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1617 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02001618}
Matt2f2f4252005-04-13 14:45:30 +02001619
Takashi Iwai82599802007-07-31 15:56:24 +02001620static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001621{
Takashi Iwai82599802007-07-31 15:56:24 +02001622 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +02001623 /* Configure GPIOx as output */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001624 snd_hda_codec_write_cache(codec, codec->afg, 0,
1625 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001626 /* Configure GPIOx as CMOS */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001627 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001628 /* Assert GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001629 snd_hda_codec_write_cache(codec, codec->afg, 0,
1630 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001631 /* Enable GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001632 snd_hda_codec_write_cache(codec, codec->afg, 0,
1633 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001634}
1635
Matt2f2f4252005-04-13 14:45:30 +02001636/*
1637 * Analog playback callbacks
1638 */
1639static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1640 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001641 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001642{
1643 struct sigmatel_spec *spec = codec->spec;
1644 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1645}
1646
1647static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1648 struct hda_codec *codec,
1649 unsigned int stream_tag,
1650 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001651 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001652{
1653 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01001654 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02001655}
1656
1657static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1658 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001659 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001660{
1661 struct sigmatel_spec *spec = codec->spec;
1662 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1663}
1664
1665/*
Mattdabbed62005-06-14 10:19:34 +02001666 * Digital playback callbacks
1667 */
1668static int stac92xx_dig_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)
Mattdabbed62005-06-14 10:19:34 +02001671{
1672 struct sigmatel_spec *spec = codec->spec;
1673 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1674}
1675
1676static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1677 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001678 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001679{
1680 struct sigmatel_spec *spec = codec->spec;
1681 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1682}
1683
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001684static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1685 struct hda_codec *codec,
1686 unsigned int stream_tag,
1687 unsigned int format,
1688 struct snd_pcm_substream *substream)
1689{
1690 struct sigmatel_spec *spec = codec->spec;
1691 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1692 stream_tag, format, substream);
1693}
1694
Mattdabbed62005-06-14 10:19:34 +02001695
1696/*
Matt2f2f4252005-04-13 14:45:30 +02001697 * Analog capture callbacks
1698 */
1699static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1700 struct hda_codec *codec,
1701 unsigned int stream_tag,
1702 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001703 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001704{
1705 struct sigmatel_spec *spec = codec->spec;
1706
1707 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1708 stream_tag, 0, format);
1709 return 0;
1710}
1711
1712static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1713 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001714 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001715{
1716 struct sigmatel_spec *spec = codec->spec;
1717
1718 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1719 return 0;
1720}
1721
Mattdabbed62005-06-14 10:19:34 +02001722static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1723 .substreams = 1,
1724 .channels_min = 2,
1725 .channels_max = 2,
1726 /* NID is set in stac92xx_build_pcms */
1727 .ops = {
1728 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001729 .close = stac92xx_dig_playback_pcm_close,
1730 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02001731 },
1732};
1733
1734static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1735 .substreams = 1,
1736 .channels_min = 2,
1737 .channels_max = 2,
1738 /* NID is set in stac92xx_build_pcms */
1739};
1740
Matt2f2f4252005-04-13 14:45:30 +02001741static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1742 .substreams = 1,
1743 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02001744 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02001745 .nid = 0x02, /* NID to query formats and rates */
1746 .ops = {
1747 .open = stac92xx_playback_pcm_open,
1748 .prepare = stac92xx_playback_pcm_prepare,
1749 .cleanup = stac92xx_playback_pcm_cleanup
1750 },
1751};
1752
Matt Porter3cc08dc2006-01-23 15:27:49 +01001753static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1754 .substreams = 1,
1755 .channels_min = 2,
1756 .channels_max = 2,
1757 .nid = 0x06, /* NID to query formats and rates */
1758 .ops = {
1759 .open = stac92xx_playback_pcm_open,
1760 .prepare = stac92xx_playback_pcm_prepare,
1761 .cleanup = stac92xx_playback_pcm_cleanup
1762 },
1763};
1764
Matt2f2f4252005-04-13 14:45:30 +02001765static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02001766 .channels_min = 2,
1767 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001768 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001769 .ops = {
1770 .prepare = stac92xx_capture_pcm_prepare,
1771 .cleanup = stac92xx_capture_pcm_cleanup
1772 },
1773};
1774
1775static int stac92xx_build_pcms(struct hda_codec *codec)
1776{
1777 struct sigmatel_spec *spec = codec->spec;
1778 struct hda_pcm *info = spec->pcm_rec;
1779
1780 codec->num_pcms = 1;
1781 codec->pcm_info = info;
1782
Mattc7d4b2f2005-06-27 14:59:41 +02001783 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001784 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001785 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001786 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001787 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001788
1789 if (spec->alt_switch) {
1790 codec->num_pcms++;
1791 info++;
1792 info->name = "STAC92xx Analog Alt";
1793 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1794 }
Matt2f2f4252005-04-13 14:45:30 +02001795
Mattdabbed62005-06-14 10:19:34 +02001796 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1797 codec->num_pcms++;
1798 info++;
1799 info->name = "STAC92xx Digital";
1800 if (spec->multiout.dig_out_nid) {
1801 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1802 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1803 }
1804 if (spec->dig_in_nid) {
1805 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1806 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1807 }
1808 }
1809
Matt2f2f4252005-04-13 14:45:30 +02001810 return 0;
1811}
1812
Takashi Iwaic960a032006-03-23 17:06:28 +01001813static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1814{
1815 unsigned int pincap = snd_hda_param_read(codec, nid,
1816 AC_PAR_PIN_CAP);
1817 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1818 if (pincap & AC_PINCAP_VREF_100)
1819 return AC_PINCTL_VREF_100;
1820 if (pincap & AC_PINCAP_VREF_80)
1821 return AC_PINCTL_VREF_80;
1822 if (pincap & AC_PINCAP_VREF_50)
1823 return AC_PINCTL_VREF_50;
1824 if (pincap & AC_PINCAP_VREF_GRD)
1825 return AC_PINCTL_VREF_GRD;
1826 return 0;
1827}
1828
Matt Porter403d1942005-11-29 15:00:51 +01001829static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1830
1831{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001832 snd_hda_codec_write_cache(codec, nid, 0,
1833 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01001834}
1835
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001836#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001837
1838static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1839{
1840 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1841 struct sigmatel_spec *spec = codec->spec;
1842 int io_idx = kcontrol-> private_value & 0xff;
1843
1844 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1845 return 0;
1846}
1847
1848static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1849{
1850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1851 struct sigmatel_spec *spec = codec->spec;
1852 hda_nid_t nid = kcontrol->private_value >> 8;
1853 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001854 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01001855
1856 spec->io_switch[io_idx] = val;
1857
1858 if (val)
1859 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001860 else {
1861 unsigned int pinctl = AC_PINCTL_IN_EN;
1862 if (io_idx) /* set VREF for mic */
1863 pinctl |= stac92xx_get_vref(codec, nid);
1864 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1865 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01001866
1867 /* check the auto-mute again: we need to mute/unmute the speaker
1868 * appropriately according to the pin direction
1869 */
1870 if (spec->hp_detect)
1871 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1872
Matt Porter403d1942005-11-29 15:00:51 +01001873 return 1;
1874}
1875
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001876#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
1877
1878static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
1879 struct snd_ctl_elem_value *ucontrol)
1880{
1881 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1882 struct sigmatel_spec *spec = codec->spec;
1883
1884 ucontrol->value.integer.value[0] = spec->clfe_swap;
1885 return 0;
1886}
1887
1888static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1889 struct snd_ctl_elem_value *ucontrol)
1890{
1891 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1892 struct sigmatel_spec *spec = codec->spec;
1893 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001894 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001895
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001896 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001897 return 0;
1898
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001899 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001900
1901 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1902 spec->clfe_swap ? 0x4 : 0x0);
1903
1904 return 1;
1905}
1906
Matt Porter403d1942005-11-29 15:00:51 +01001907#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1908 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1909 .name = xname, \
1910 .index = 0, \
1911 .info = stac92xx_io_switch_info, \
1912 .get = stac92xx_io_switch_get, \
1913 .put = stac92xx_io_switch_put, \
1914 .private_value = xpval, \
1915 }
1916
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001917#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
1918 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1919 .name = xname, \
1920 .index = 0, \
1921 .info = stac92xx_clfe_switch_info, \
1922 .get = stac92xx_clfe_switch_get, \
1923 .put = stac92xx_clfe_switch_put, \
1924 .private_value = xpval, \
1925 }
Matt Porter403d1942005-11-29 15:00:51 +01001926
Mattc7d4b2f2005-06-27 14:59:41 +02001927enum {
1928 STAC_CTL_WIDGET_VOL,
1929 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001930 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001931 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02001932};
1933
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001934static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001935 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1936 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001937 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001938 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001939};
1940
1941/* add dynamic controls */
1942static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1943{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001944 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001945
1946 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1947 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1948
1949 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1950 if (! knew)
1951 return -ENOMEM;
1952 if (spec->kctl_alloc) {
1953 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1954 kfree(spec->kctl_alloc);
1955 }
1956 spec->kctl_alloc = knew;
1957 spec->num_kctl_alloc = num;
1958 }
1959
1960 knew = &spec->kctl_alloc[spec->num_kctl_used];
1961 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001962 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001963 if (! knew->name)
1964 return -ENOMEM;
1965 knew->private_value = val;
1966 spec->num_kctl_used++;
1967 return 0;
1968}
1969
Matt Porter403d1942005-11-29 15:00:51 +01001970/* flag inputs as additional dynamic lineouts */
1971static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1972{
1973 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001974 unsigned int wcaps, wtype;
1975 int i, num_dacs = 0;
1976
1977 /* use the wcaps cache to count all DACs available for line-outs */
1978 for (i = 0; i < codec->num_nodes; i++) {
1979 wcaps = codec->wcaps[i];
1980 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001981
Steve Longerbeam7b043892007-05-03 20:50:03 +02001982 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1983 num_dacs++;
1984 }
Matt Porter403d1942005-11-29 15:00:51 +01001985
Steve Longerbeam7b043892007-05-03 20:50:03 +02001986 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1987
Matt Porter403d1942005-11-29 15:00:51 +01001988 switch (cfg->line_outs) {
1989 case 3:
1990 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001991 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001992 cfg->line_out_pins[cfg->line_outs] =
1993 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001994 spec->line_switch = 1;
1995 cfg->line_outs++;
1996 }
1997 break;
1998 case 2:
1999 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002000 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002001 cfg->line_out_pins[cfg->line_outs] =
2002 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002003 spec->line_switch = 1;
2004 cfg->line_outs++;
2005 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002006 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002007 cfg->line_out_pins[cfg->line_outs] =
2008 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002009 spec->mic_switch = 1;
2010 cfg->line_outs++;
2011 }
2012 break;
2013 case 1:
2014 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002015 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002016 cfg->line_out_pins[cfg->line_outs] =
2017 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002018 spec->line_switch = 1;
2019 cfg->line_outs++;
2020 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002021 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002022 cfg->line_out_pins[cfg->line_outs] =
2023 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002024 spec->mic_switch = 1;
2025 cfg->line_outs++;
2026 }
2027 break;
2028 }
2029
2030 return 0;
2031}
2032
Steve Longerbeam7b043892007-05-03 20:50:03 +02002033
2034static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2035{
2036 int i;
2037
2038 for (i = 0; i < spec->multiout.num_dacs; i++) {
2039 if (spec->multiout.dac_nids[i] == nid)
2040 return 1;
2041 }
2042
2043 return 0;
2044}
2045
Matt Porter3cc08dc2006-01-23 15:27:49 +01002046/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002047 * Fill in the dac_nids table from the parsed pin configuration
2048 * This function only works when every pin in line_out_pins[]
2049 * contains atleast one DAC in its connection list. Some 92xx
2050 * codecs are not connected directly to a DAC, such as the 9200
2051 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002052 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002053static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02002054 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002055{
2056 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002057 int i, j, conn_len = 0;
2058 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2059 unsigned int wcaps, wtype;
2060
Mattc7d4b2f2005-06-27 14:59:41 +02002061 for (i = 0; i < cfg->line_outs; i++) {
2062 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02002063 conn_len = snd_hda_get_connections(codec, nid, conn,
2064 HDA_MAX_CONNECTIONS);
2065 for (j = 0; j < conn_len; j++) {
2066 wcaps = snd_hda_param_read(codec, conn[j],
2067 AC_PAR_AUDIO_WIDGET_CAP);
2068 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002069 if (wtype != AC_WID_AUD_OUT ||
2070 (wcaps & AC_WCAP_DIGITAL))
2071 continue;
2072 /* conn[j] is a DAC routed to this line-out */
2073 if (!is_in_dac_nids(spec, conn[j]))
2074 break;
2075 }
2076
2077 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002078 if (spec->multiout.num_dacs > 0) {
2079 /* we have already working output pins,
2080 * so let's drop the broken ones again
2081 */
2082 cfg->line_outs = spec->multiout.num_dacs;
2083 break;
2084 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002085 /* error out, no available DAC found */
2086 snd_printk(KERN_ERR
2087 "%s: No available DAC for pin 0x%x\n",
2088 __func__, nid);
2089 return -ENODEV;
2090 }
2091
2092 spec->multiout.dac_nids[i] = conn[j];
2093 spec->multiout.num_dacs++;
2094 if (conn_len > 1) {
2095 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002096 snd_hda_codec_write_cache(codec, nid, 0,
2097 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002098
2099 }
Mattc7d4b2f2005-06-27 14:59:41 +02002100 }
2101
Steve Longerbeam7b043892007-05-03 20:50:03 +02002102 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2103 spec->multiout.num_dacs,
2104 spec->multiout.dac_nids[0],
2105 spec->multiout.dac_nids[1],
2106 spec->multiout.dac_nids[2],
2107 spec->multiout.dac_nids[3],
2108 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02002109 return 0;
2110}
2111
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002112/* create volume control/switch for the given prefx type */
2113static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2114{
2115 char name[32];
2116 int err;
2117
2118 sprintf(name, "%s Playback Volume", pfx);
2119 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2120 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2121 if (err < 0)
2122 return err;
2123 sprintf(name, "%s Playback Switch", pfx);
2124 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2125 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2126 if (err < 0)
2127 return err;
2128 return 0;
2129}
2130
Mattc7d4b2f2005-06-27 14:59:41 +02002131/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002132static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002133 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002134{
Takashi Iwai19039bd2006-06-28 15:52:16 +02002135 static const char *chname[4] = {
2136 "Front", "Surround", NULL /*CLFE*/, "Side"
2137 };
Mattc7d4b2f2005-06-27 14:59:41 +02002138 hda_nid_t nid;
2139 int i, err;
2140
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002141 struct sigmatel_spec *spec = codec->spec;
2142 unsigned int wid_caps;
2143
2144
Mattc7d4b2f2005-06-27 14:59:41 +02002145 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01002146 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02002147 continue;
2148
2149 nid = spec->multiout.dac_nids[i];
2150
2151 if (i == 2) {
2152 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002153 err = create_controls(spec, "Center", nid, 1);
2154 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002155 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002156 err = create_controls(spec, "LFE", nid, 2);
2157 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002158 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002159
2160 wid_caps = get_wcaps(codec, nid);
2161
2162 if (wid_caps & AC_WCAP_LR_SWAP) {
2163 err = stac92xx_add_control(spec,
2164 STAC_CTL_WIDGET_CLFE_SWITCH,
2165 "Swap Center/LFE Playback Switch", nid);
2166
2167 if (err < 0)
2168 return err;
2169 }
2170
Mattc7d4b2f2005-06-27 14:59:41 +02002171 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002172 err = create_controls(spec, chname[i], nid, 3);
2173 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002174 return err;
2175 }
2176 }
2177
Matt Porter403d1942005-11-29 15:00:51 +01002178 if (spec->line_switch)
2179 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
2180 return err;
2181
2182 if (spec->mic_switch)
2183 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
2184 return err;
2185
Mattc7d4b2f2005-06-27 14:59:41 +02002186 return 0;
2187}
2188
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002189static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2190{
Steve Longerbeam7b043892007-05-03 20:50:03 +02002191 if (is_in_dac_nids(spec, nid))
2192 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002193 if (spec->multiout.hp_nid == nid)
2194 return 1;
2195 return 0;
2196}
2197
2198static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2199{
2200 if (!spec->multiout.hp_nid)
2201 spec->multiout.hp_nid = nid;
2202 else if (spec->multiout.num_dacs > 4) {
2203 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2204 return 1;
2205 } else {
2206 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2207 spec->multiout.num_dacs++;
2208 }
2209 return 0;
2210}
2211
2212/* add playback controls for Speaker and HP outputs */
2213static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2214 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002215{
2216 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002217 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002218 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02002219
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002220 old_num_dacs = spec->multiout.num_dacs;
2221 for (i = 0; i < cfg->hp_outs; i++) {
2222 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
2223 if (wid_caps & AC_WCAP_UNSOL_CAP)
2224 spec->hp_detect = 1;
2225 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
2226 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2227 if (check_in_dac_nids(spec, nid))
2228 nid = 0;
2229 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02002230 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002231 add_spec_dacs(spec, nid);
2232 }
2233 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02002234 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002235 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2236 if (check_in_dac_nids(spec, nid))
2237 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002238 if (! nid)
2239 continue;
2240 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02002241 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02002242 for (i = 0; i < cfg->line_outs; i++) {
2243 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
2244 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2245 if (check_in_dac_nids(spec, nid))
2246 nid = 0;
2247 if (! nid)
2248 continue;
2249 add_spec_dacs(spec, nid);
2250 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002251 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
2252 static const char *pfxs[] = {
2253 "Speaker", "External Speaker", "Speaker2",
2254 };
2255 err = create_controls(spec, pfxs[i - old_num_dacs],
2256 spec->multiout.dac_nids[i], 3);
2257 if (err < 0)
2258 return err;
2259 }
2260 if (spec->multiout.hp_nid) {
2261 const char *pfx;
Takashi Iwai6020c002007-11-19 11:56:26 +01002262 if (old_num_dacs == spec->multiout.num_dacs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002263 pfx = "Master";
2264 else
2265 pfx = "Headphone";
2266 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
2267 if (err < 0)
2268 return err;
2269 }
Mattc7d4b2f2005-06-27 14:59:41 +02002270
2271 return 0;
2272}
2273
Matt Porter8b657272006-10-26 17:12:59 +02002274/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01002275static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02002276 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
2277 "Digital Mic 3", "Digital Mic 4"
2278};
2279
2280/* create playback/capture controls for input pins on dmic capable codecs */
2281static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
2282 const struct auto_pin_cfg *cfg)
2283{
2284 struct sigmatel_spec *spec = codec->spec;
2285 struct hda_input_mux *dimux = &spec->private_dimux;
2286 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002287 int err, i, j;
2288 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02002289
2290 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
2291 dimux->items[dimux->num_items].index = 0;
2292 dimux->num_items++;
2293
2294 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002295 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02002296 int index;
2297 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002298 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02002299 unsigned int def_conf;
2300
2301 def_conf = snd_hda_codec_read(codec,
2302 spec->dmic_nids[i],
2303 0,
2304 AC_VERB_GET_CONFIG_DEFAULT,
2305 0);
2306 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
2307 continue;
2308
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002309 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02002310 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01002311 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02002312 con_lst,
2313 HDA_MAX_NUM_INPUTS);
2314 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002315 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02002316 index = j;
2317 goto found;
2318 }
2319 continue;
2320found:
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002321 wcaps = get_wcaps(codec, nid);
2322
2323 if (wcaps & AC_WCAP_OUT_AMP) {
2324 sprintf(name, "%s Capture Volume",
2325 stac92xx_dmic_labels[dimux->num_items]);
2326
2327 err = stac92xx_add_control(spec,
2328 STAC_CTL_WIDGET_VOL,
2329 name,
2330 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2331 if (err < 0)
2332 return err;
2333 }
2334
Matt Porter8b657272006-10-26 17:12:59 +02002335 dimux->items[dimux->num_items].label =
2336 stac92xx_dmic_labels[dimux->num_items];
2337 dimux->items[dimux->num_items].index = index;
2338 dimux->num_items++;
2339 }
2340
2341 return 0;
2342}
2343
Mattc7d4b2f2005-06-27 14:59:41 +02002344/* create playback/capture controls for input pins */
2345static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
2346{
2347 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002348 struct hda_input_mux *imux = &spec->private_imux;
2349 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
2350 int i, j, k;
2351
2352 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002353 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02002354
Takashi Iwai314634b2006-09-21 11:56:18 +02002355 if (!cfg->input_pins[i])
2356 continue;
2357 index = -1;
2358 for (j = 0; j < spec->num_muxes; j++) {
2359 int num_cons;
2360 num_cons = snd_hda_get_connections(codec,
2361 spec->mux_nids[j],
2362 con_lst,
2363 HDA_MAX_NUM_INPUTS);
2364 for (k = 0; k < num_cons; k++)
2365 if (con_lst[k] == cfg->input_pins[i]) {
2366 index = k;
2367 goto found;
2368 }
Mattc7d4b2f2005-06-27 14:59:41 +02002369 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002370 continue;
2371 found:
2372 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2373 imux->items[imux->num_items].index = index;
2374 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02002375 }
2376
Steve Longerbeam7b043892007-05-03 20:50:03 +02002377 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02002378 /*
2379 * Set the current input for the muxes.
2380 * The STAC9221 has two input muxes with identical source
2381 * NID lists. Hopefully this won't get confused.
2382 */
2383 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002384 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
2385 AC_VERB_SET_CONNECT_SEL,
2386 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02002387 }
2388 }
2389
Mattc7d4b2f2005-06-27 14:59:41 +02002390 return 0;
2391}
2392
Mattc7d4b2f2005-06-27 14:59:41 +02002393static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
2394{
2395 struct sigmatel_spec *spec = codec->spec;
2396 int i;
2397
2398 for (i = 0; i < spec->autocfg.line_outs; i++) {
2399 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2400 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2401 }
2402}
2403
2404static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
2405{
2406 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002407 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002408
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002409 for (i = 0; i < spec->autocfg.hp_outs; i++) {
2410 hda_nid_t pin;
2411 pin = spec->autocfg.hp_pins[i];
2412 if (pin) /* connect to front */
2413 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
2414 }
2415 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
2416 hda_nid_t pin;
2417 pin = spec->autocfg.speaker_pins[i];
2418 if (pin) /* connect to front */
2419 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
2420 }
Mattc7d4b2f2005-06-27 14:59:41 +02002421}
2422
Matt Porter3cc08dc2006-01-23 15:27:49 +01002423static 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 +02002424{
2425 struct sigmatel_spec *spec = codec->spec;
2426 int err;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002427 int hp_speaker_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002428
Matt Porter8b657272006-10-26 17:12:59 +02002429 if ((err = snd_hda_parse_pin_def_config(codec,
2430 &spec->autocfg,
2431 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002432 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002433 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01002434 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002435
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002436 /* If we have no real line-out pin and multiple hp-outs, HPs should
2437 * be set up as multi-channel outputs.
2438 */
2439 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2440 spec->autocfg.hp_outs > 1) {
2441 /* Copy hp_outs to line_outs, backup line_outs in
2442 * speaker_outs so that the following routines can handle
2443 * HP pins as primary outputs.
2444 */
2445 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
2446 sizeof(spec->autocfg.line_out_pins));
2447 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
2448 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
2449 sizeof(spec->autocfg.hp_pins));
2450 spec->autocfg.line_outs = spec->autocfg.hp_outs;
2451 hp_speaker_swap = 1;
2452 }
2453
Matt Porter403d1942005-11-29 15:00:51 +01002454 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
2455 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002456 if (spec->multiout.num_dacs == 0)
2457 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2458 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02002459
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002460 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
2461
2462 if (err < 0)
2463 return err;
2464
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002465 if (hp_speaker_swap == 1) {
2466 /* Restore the hp_outs and line_outs */
2467 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
2468 sizeof(spec->autocfg.line_out_pins));
2469 spec->autocfg.hp_outs = spec->autocfg.line_outs;
2470 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
2471 sizeof(spec->autocfg.speaker_pins));
2472 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
2473 memset(spec->autocfg.speaker_pins, 0,
2474 sizeof(spec->autocfg.speaker_pins));
2475 spec->autocfg.speaker_outs = 0;
2476 }
2477
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002478 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
2479
2480 if (err < 0)
2481 return err;
2482
2483 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
2484
2485 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002486 return err;
2487
Matt Porter8b657272006-10-26 17:12:59 +02002488 if (spec->num_dmics > 0)
2489 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
2490 &spec->autocfg)) < 0)
2491 return err;
2492
Mattc7d4b2f2005-06-27 14:59:41 +02002493 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01002494 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02002495 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002496
Takashi Iwai82bc9552006-03-21 11:24:42 +01002497 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002498 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002499 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002500 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02002501
2502 if (spec->kctl_alloc)
2503 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2504
2505 spec->input_mux = &spec->private_imux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01002506 if (!spec->dinput_mux)
2507 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002508
2509 return 1;
2510}
2511
Takashi Iwai82bc9552006-03-21 11:24:42 +01002512/* add playback controls for HP output */
2513static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
2514 struct auto_pin_cfg *cfg)
2515{
2516 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002517 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01002518 unsigned int wid_caps;
2519
2520 if (! pin)
2521 return 0;
2522
2523 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02002524 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01002525 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002526
2527 return 0;
2528}
2529
Richard Fish160ea0d2006-09-06 13:58:25 +02002530/* add playback controls for LFE output */
2531static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2532 struct auto_pin_cfg *cfg)
2533{
2534 struct sigmatel_spec *spec = codec->spec;
2535 int err;
2536 hda_nid_t lfe_pin = 0x0;
2537 int i;
2538
2539 /*
2540 * search speaker outs and line outs for a mono speaker pin
2541 * with an amp. If one is found, add LFE controls
2542 * for it.
2543 */
2544 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2545 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2546 unsigned long wcaps = get_wcaps(codec, pin);
2547 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2548 if (wcaps == AC_WCAP_OUT_AMP)
2549 /* found a mono speaker with an amp, must be lfe */
2550 lfe_pin = pin;
2551 }
2552
2553 /* if speaker_outs is 0, then speakers may be in line_outs */
2554 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2555 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2556 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2557 unsigned long cfg;
2558 cfg = snd_hda_codec_read(codec, pin, 0,
2559 AC_VERB_GET_CONFIG_DEFAULT,
2560 0x00);
2561 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
2562 unsigned long wcaps = get_wcaps(codec, pin);
2563 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2564 if (wcaps == AC_WCAP_OUT_AMP)
2565 /* found a mono speaker with an amp,
2566 must be lfe */
2567 lfe_pin = pin;
2568 }
2569 }
2570 }
2571
2572 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002573 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02002574 if (err < 0)
2575 return err;
2576 }
2577
2578 return 0;
2579}
2580
Mattc7d4b2f2005-06-27 14:59:41 +02002581static int stac9200_parse_auto_config(struct hda_codec *codec)
2582{
2583 struct sigmatel_spec *spec = codec->spec;
2584 int err;
2585
Kailang Yangdf694da2005-12-05 19:42:22 +01002586 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002587 return err;
2588
2589 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
2590 return err;
2591
Takashi Iwai82bc9552006-03-21 11:24:42 +01002592 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2593 return err;
2594
Richard Fish160ea0d2006-09-06 13:58:25 +02002595 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2596 return err;
2597
Takashi Iwai82bc9552006-03-21 11:24:42 +01002598 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002599 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002600 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002601 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02002602
2603 if (spec->kctl_alloc)
2604 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2605
2606 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002607 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002608
2609 return 1;
2610}
2611
Sam Revitch62fe78e2006-05-10 15:09:17 +02002612/*
2613 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2614 * funky external mute control using GPIO pins.
2615 */
2616
2617static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
2618{
2619 unsigned int gpiostate, gpiomask, gpiodir;
2620
2621 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2622 AC_VERB_GET_GPIO_DATA, 0);
2623
2624 if (!muted)
2625 gpiostate |= (1 << pin);
2626 else
2627 gpiostate &= ~(1 << pin);
2628
2629 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2630 AC_VERB_GET_GPIO_MASK, 0);
2631 gpiomask |= (1 << pin);
2632
2633 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2634 AC_VERB_GET_GPIO_DIRECTION, 0);
2635 gpiodir |= (1 << pin);
2636
2637 /* AppleHDA seems to do this -- WTF is this verb?? */
2638 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2639
2640 snd_hda_codec_write(codec, codec->afg, 0,
2641 AC_VERB_SET_GPIO_MASK, gpiomask);
2642 snd_hda_codec_write(codec, codec->afg, 0,
2643 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
2644
2645 msleep(1);
2646
2647 snd_hda_codec_write(codec, codec->afg, 0,
2648 AC_VERB_SET_GPIO_DATA, gpiostate);
2649}
2650
Takashi Iwai314634b2006-09-21 11:56:18 +02002651static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2652 unsigned int event)
2653{
2654 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002655 snd_hda_codec_write_cache(codec, nid, 0,
2656 AC_VERB_SET_UNSOLICITED_ENABLE,
2657 (AC_USRSP_EN | event));
Takashi Iwai314634b2006-09-21 11:56:18 +02002658}
2659
Mattc7d4b2f2005-06-27 14:59:41 +02002660static int stac92xx_init(struct hda_codec *codec)
2661{
2662 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002663 struct auto_pin_cfg *cfg = &spec->autocfg;
2664 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002665
Mattc7d4b2f2005-06-27 14:59:41 +02002666 snd_hda_sequence_write(codec, spec->init);
2667
Takashi Iwai82bc9552006-03-21 11:24:42 +01002668 /* set up pins */
2669 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02002670 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002671 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02002672 enable_pin_detect(codec, cfg->hp_pins[i],
2673 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01002674 /* force to enable the first line-out; the others are set up
2675 * in unsol_event
2676 */
2677 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2678 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02002679 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002680 /* fake event to set up pins */
2681 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2682 } else {
2683 stac92xx_auto_init_multi_out(codec);
2684 stac92xx_auto_init_hp_out(codec);
2685 }
2686 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01002687 hda_nid_t nid = cfg->input_pins[i];
2688 if (nid) {
2689 unsigned int pinctl = AC_PINCTL_IN_EN;
2690 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
2691 pinctl |= stac92xx_get_vref(codec, nid);
2692 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2693 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01002694 }
Matt Porter8b657272006-10-26 17:12:59 +02002695 if (spec->num_dmics > 0)
2696 for (i = 0; i < spec->num_dmics; i++)
2697 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
2698 AC_PINCTL_IN_EN);
2699
Takashi Iwai82bc9552006-03-21 11:24:42 +01002700 if (cfg->dig_out_pin)
2701 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2702 AC_PINCTL_OUT_EN);
2703 if (cfg->dig_in_pin)
2704 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2705 AC_PINCTL_IN_EN);
2706
Sam Revitch62fe78e2006-05-10 15:09:17 +02002707 if (spec->gpio_mute) {
2708 stac922x_gpio_mute(codec, 0, 0);
2709 stac922x_gpio_mute(codec, 1, 0);
2710 }
2711
Mattc7d4b2f2005-06-27 14:59:41 +02002712 return 0;
2713}
2714
Matt2f2f4252005-04-13 14:45:30 +02002715static void stac92xx_free(struct hda_codec *codec)
2716{
Mattc7d4b2f2005-06-27 14:59:41 +02002717 struct sigmatel_spec *spec = codec->spec;
2718 int i;
2719
2720 if (! spec)
2721 return;
2722
2723 if (spec->kctl_alloc) {
2724 for (i = 0; i < spec->num_kctl_used; i++)
2725 kfree(spec->kctl_alloc[i].name);
2726 kfree(spec->kctl_alloc);
2727 }
2728
Richard Fish11b44bb2006-08-23 18:31:34 +02002729 if (spec->bios_pin_configs)
2730 kfree(spec->bios_pin_configs);
2731
Mattc7d4b2f2005-06-27 14:59:41 +02002732 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02002733}
2734
Matt4e550962005-07-04 17:51:39 +02002735static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
2736 unsigned int flag)
2737{
2738 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2739 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002740
Takashi Iwaif9acba42007-05-29 18:01:06 +02002741 if (pin_ctl & AC_PINCTL_IN_EN) {
2742 /*
2743 * we need to check the current set-up direction of
2744 * shared input pins since they can be switched via
2745 * "xxx as Output" mixer switch
2746 */
2747 struct sigmatel_spec *spec = codec->spec;
2748 struct auto_pin_cfg *cfg = &spec->autocfg;
2749 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
2750 spec->line_switch) ||
2751 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
2752 spec->mic_switch))
2753 return;
2754 }
2755
Steve Longerbeam7b043892007-05-03 20:50:03 +02002756 /* if setting pin direction bits, clear the current
2757 direction bits first */
2758 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
2759 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
2760
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002761 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002762 AC_VERB_SET_PIN_WIDGET_CONTROL,
2763 pin_ctl | flag);
2764}
2765
2766static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
2767 unsigned int flag)
2768{
2769 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2770 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002771 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002772 AC_VERB_SET_PIN_WIDGET_CONTROL,
2773 pin_ctl & ~flag);
2774}
2775
Jiang Zhe40c1d302007-11-12 13:05:16 +01002776static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02002777{
2778 if (!nid)
2779 return 0;
2780 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Jiang Zhe40c1d302007-11-12 13:05:16 +01002781 & (1 << 31)) {
2782 unsigned int pinctl;
2783 pinctl = snd_hda_codec_read(codec, nid, 0,
2784 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2785 if (pinctl & AC_PINCTL_IN_EN)
2786 return 0; /* mic- or line-input */
2787 else
2788 return 1; /* HP-output */
2789 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002790 return 0;
2791}
2792
2793static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02002794{
2795 struct sigmatel_spec *spec = codec->spec;
2796 struct auto_pin_cfg *cfg = &spec->autocfg;
2797 int i, presence;
2798
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002799 presence = 0;
2800 for (i = 0; i < cfg->hp_outs; i++) {
Jiang Zhe40c1d302007-11-12 13:05:16 +01002801 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
Takashi Iwai314634b2006-09-21 11:56:18 +02002802 if (presence)
2803 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002804 }
Matt4e550962005-07-04 17:51:39 +02002805
2806 if (presence) {
2807 /* disable lineouts, enable hp */
2808 for (i = 0; i < cfg->line_outs; i++)
2809 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
2810 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002811 for (i = 0; i < cfg->speaker_outs; i++)
2812 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
2813 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002814 } else {
2815 /* enable lineouts, disable hp */
2816 for (i = 0; i < cfg->line_outs; i++)
2817 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
2818 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002819 for (i = 0; i < cfg->speaker_outs; i++)
2820 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
2821 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002822 }
2823}
2824
Takashi Iwai314634b2006-09-21 11:56:18 +02002825static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
2826{
2827 switch (res >> 26) {
2828 case STAC_HP_EVENT:
2829 stac92xx_hp_detect(codec, res);
2830 break;
2831 }
2832}
2833
Takashi Iwaicb53c622007-08-10 17:21:45 +02002834#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002835static int stac92xx_resume(struct hda_codec *codec)
2836{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002837 struct sigmatel_spec *spec = codec->spec;
2838
Richard Fish11b44bb2006-08-23 18:31:34 +02002839 stac92xx_set_config_regs(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002840 snd_hda_sequence_write(codec, spec->init);
2841 if (spec->gpio_mute) {
2842 stac922x_gpio_mute(codec, 0, 0);
2843 stac922x_gpio_mute(codec, 1, 0);
2844 }
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002845 snd_hda_codec_resume_amp(codec);
2846 snd_hda_codec_resume_cache(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002847 /* invoke unsolicited event to reset the HP state */
2848 if (spec->hp_detect)
2849 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Mattff6fdc32005-06-27 15:06:52 +02002850 return 0;
2851}
2852#endif
2853
Matt2f2f4252005-04-13 14:45:30 +02002854static struct hda_codec_ops stac92xx_patch_ops = {
2855 .build_controls = stac92xx_build_controls,
2856 .build_pcms = stac92xx_build_pcms,
2857 .init = stac92xx_init,
2858 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02002859 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002860#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002861 .resume = stac92xx_resume,
2862#endif
Matt2f2f4252005-04-13 14:45:30 +02002863};
2864
2865static int patch_stac9200(struct hda_codec *codec)
2866{
2867 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002868 int err;
Matt2f2f4252005-04-13 14:45:30 +02002869
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002870 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002871 if (spec == NULL)
2872 return -ENOMEM;
2873
2874 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002875 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002876 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002877 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
2878 stac9200_models,
2879 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02002880 if (spec->board_config < 0) {
2881 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
2882 err = stac92xx_save_bios_config_regs(codec);
2883 if (err < 0) {
2884 stac92xx_free(codec);
2885 return err;
2886 }
2887 spec->pin_configs = spec->bios_pin_configs;
2888 } else {
Matt Porter403d1942005-11-29 15:00:51 +01002889 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
2890 stac92xx_set_config_regs(codec);
2891 }
Matt2f2f4252005-04-13 14:45:30 +02002892
2893 spec->multiout.max_channels = 2;
2894 spec->multiout.num_dacs = 1;
2895 spec->multiout.dac_nids = stac9200_dac_nids;
2896 spec->adc_nids = stac9200_adc_nids;
2897 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02002898 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02002899 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002900 spec->num_adcs = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002901
Takashi Iwai1194b5b2007-10-10 10:04:26 +02002902 if (spec->board_config == STAC_9200_GATEWAY)
2903 spec->init = stac9200_eapd_init;
2904 else
2905 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002906 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002907
2908 err = stac9200_parse_auto_config(codec);
2909 if (err < 0) {
2910 stac92xx_free(codec);
2911 return err;
2912 }
Matt2f2f4252005-04-13 14:45:30 +02002913
2914 codec->patch_ops = stac92xx_patch_ops;
2915
2916 return 0;
2917}
2918
Tobin Davis8e21c342007-01-08 11:04:17 +01002919static int patch_stac925x(struct hda_codec *codec)
2920{
2921 struct sigmatel_spec *spec;
2922 int err;
2923
2924 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2925 if (spec == NULL)
2926 return -ENOMEM;
2927
2928 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002929 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002930 spec->pin_nids = stac925x_pin_nids;
2931 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2932 stac925x_models,
2933 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002934 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002935 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002936 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2937 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002938 err = stac92xx_save_bios_config_regs(codec);
2939 if (err < 0) {
2940 stac92xx_free(codec);
2941 return err;
2942 }
2943 spec->pin_configs = spec->bios_pin_configs;
2944 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2945 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2946 stac92xx_set_config_regs(codec);
2947 }
2948
2949 spec->multiout.max_channels = 2;
2950 spec->multiout.num_dacs = 1;
2951 spec->multiout.dac_nids = stac925x_dac_nids;
2952 spec->adc_nids = stac925x_adc_nids;
2953 spec->mux_nids = stac925x_mux_nids;
2954 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002955 spec->num_adcs = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002956 switch (codec->vendor_id) {
2957 case 0x83847632: /* STAC9202 */
2958 case 0x83847633: /* STAC9202D */
2959 case 0x83847636: /* STAC9251 */
2960 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02002961 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02002962 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01002963 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
2964 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02002965 break;
2966 default:
2967 spec->num_dmics = 0;
2968 break;
2969 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002970
2971 spec->init = stac925x_core_init;
2972 spec->mixer = stac925x_mixer;
2973
2974 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002975 if (!err) {
2976 if (spec->board_config < 0) {
2977 printk(KERN_WARNING "hda_codec: No auto-config is "
2978 "available, default to model=ref\n");
2979 spec->board_config = STAC_925x_REF;
2980 goto again;
2981 }
2982 err = -EINVAL;
2983 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002984 if (err < 0) {
2985 stac92xx_free(codec);
2986 return err;
2987 }
2988
2989 codec->patch_ops = stac92xx_patch_ops;
2990
2991 return 0;
2992}
2993
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01002994static struct hda_input_mux stac92hd73xx_dmux = {
2995 .num_items = 4,
2996 .items = {
2997 { "Analog Inputs", 0x0b },
2998 { "CD", 0x08 },
2999 { "Digital Mic 1", 0x09 },
3000 { "Digital Mic 2", 0x0a },
3001 }
3002};
3003
3004static int patch_stac92hd73xx(struct hda_codec *codec)
3005{
3006 struct sigmatel_spec *spec;
3007 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
3008 int err = 0;
3009
3010 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3011 if (spec == NULL)
3012 return -ENOMEM;
3013
3014 codec->spec = spec;
3015 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
3016 spec->pin_nids = stac92hd73xx_pin_nids;
3017 spec->board_config = snd_hda_check_board_config(codec,
3018 STAC_92HD73XX_MODELS,
3019 stac92hd73xx_models,
3020 stac92hd73xx_cfg_tbl);
3021again:
3022 if (spec->board_config < 0) {
3023 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3024 " STAC92HD73XX, using BIOS defaults\n");
3025 err = stac92xx_save_bios_config_regs(codec);
3026 if (err < 0) {
3027 stac92xx_free(codec);
3028 return err;
3029 }
3030 spec->pin_configs = spec->bios_pin_configs;
3031 } else {
3032 spec->pin_configs = stac92hd73xx_brd_tbl[spec->board_config];
3033 stac92xx_set_config_regs(codec);
3034 }
3035
3036 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
3037 conn, STAC92HD73_DAC_COUNT + 2) - 1;
3038
3039 if (spec->multiout.num_dacs < 0) {
3040 printk(KERN_WARNING "hda_codec: Could not determine "
3041 "number of channels defaulting to DAC count\n");
3042 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
3043 }
3044
3045 switch (spec->multiout.num_dacs) {
3046 case 0x3: /* 6 Channel */
3047 spec->mixer = stac92hd73xx_6ch_mixer;
3048 spec->init = stac92hd73xx_6ch_core_init;
3049 break;
3050 case 0x4: /* 8 Channel */
3051 spec->multiout.hp_nid = 0x18;
3052 spec->mixer = stac92hd73xx_8ch_mixer;
3053 spec->init = stac92hd73xx_8ch_core_init;
3054 break;
3055 case 0x5: /* 10 Channel */
3056 spec->multiout.hp_nid = 0x19;
3057 spec->mixer = stac92hd73xx_10ch_mixer;
3058 spec->init = stac92hd73xx_10ch_core_init;
3059 };
3060
3061 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
3062 spec->aloopback_mask = 0x01;
3063 spec->aloopback_shift = 8;
3064
3065 spec->mux_nids = stac92hd73xx_mux_nids;
3066 spec->adc_nids = stac92hd73xx_adc_nids;
3067 spec->dmic_nids = stac92hd73xx_dmic_nids;
3068 spec->dmux_nids = stac92hd73xx_dmux_nids;
3069
3070 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
3071 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
3072 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003073 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003074 spec->dinput_mux = &stac92hd73xx_dmux;
3075 /* GPIO0 High = Enable EAPD */
3076 spec->gpio_mask = spec->gpio_data = 0x000001;
3077 stac92xx_enable_gpio_mask(codec);
3078
3079 err = stac92xx_parse_auto_config(codec, 0x22, 0x24);
3080
3081 if (!err) {
3082 if (spec->board_config < 0) {
3083 printk(KERN_WARNING "hda_codec: No auto-config is "
3084 "available, default to model=ref\n");
3085 spec->board_config = STAC_92HD73XX_REF;
3086 goto again;
3087 }
3088 err = -EINVAL;
3089 }
3090
3091 if (err < 0) {
3092 stac92xx_free(codec);
3093 return err;
3094 }
3095
3096 codec->patch_ops = stac92xx_patch_ops;
3097
3098 return 0;
3099}
3100
Matthew Ranostaye035b842007-11-06 11:53:55 +01003101static int patch_stac92hd71bxx(struct hda_codec *codec)
3102{
3103 struct sigmatel_spec *spec;
3104 int err = 0;
3105
3106 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3107 if (spec == NULL)
3108 return -ENOMEM;
3109
3110 codec->spec = spec;
3111 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
3112 spec->pin_nids = stac92hd71bxx_pin_nids;
3113 spec->board_config = snd_hda_check_board_config(codec,
3114 STAC_92HD71BXX_MODELS,
3115 stac92hd71bxx_models,
3116 stac92hd71bxx_cfg_tbl);
3117again:
3118 if (spec->board_config < 0) {
3119 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3120 " STAC92HD71BXX, using BIOS defaults\n");
3121 err = stac92xx_save_bios_config_regs(codec);
3122 if (err < 0) {
3123 stac92xx_free(codec);
3124 return err;
3125 }
3126 spec->pin_configs = spec->bios_pin_configs;
3127 } else {
3128 spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config];
3129 stac92xx_set_config_regs(codec);
3130 }
3131
Matthew Ranostay541eee82007-12-14 12:08:04 +01003132 switch (codec->vendor_id) {
3133 case 0x111d76b6: /* 4 Port without Analog Mixer */
3134 case 0x111d76b7:
3135 case 0x111d76b4: /* 6 Port without Analog Mixer */
3136 case 0x111d76b5:
3137 spec->mixer = stac92hd71bxx_mixer;
3138 spec->init = stac92hd71bxx_core_init;
3139 break;
3140 default:
3141 spec->mixer = stac92hd71bxx_analog_mixer;
3142 spec->init = stac92hd71bxx_analog_core_init;
3143 }
3144
3145 spec->aloopback_mask = 0x20;
3146 spec->aloopback_shift = 0;
3147
Matthew Ranostaye035b842007-11-06 11:53:55 +01003148 spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */
3149 stac92xx_enable_gpio_mask(codec);
3150
Matthew Ranostaye035b842007-11-06 11:53:55 +01003151 spec->mux_nids = stac92hd71bxx_mux_nids;
3152 spec->adc_nids = stac92hd71bxx_adc_nids;
3153 spec->dmic_nids = stac92hd71bxx_dmic_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003154 spec->dmux_nids = stac92hd71bxx_dmux_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01003155
3156 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
3157 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
3158 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003159 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01003160
3161 spec->multiout.num_dacs = 2;
3162 spec->multiout.hp_nid = 0x11;
3163 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
3164
3165 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
3166 if (!err) {
3167 if (spec->board_config < 0) {
3168 printk(KERN_WARNING "hda_codec: No auto-config is "
3169 "available, default to model=ref\n");
3170 spec->board_config = STAC_92HD71BXX_REF;
3171 goto again;
3172 }
3173 err = -EINVAL;
3174 }
3175
3176 if (err < 0) {
3177 stac92xx_free(codec);
3178 return err;
3179 }
3180
3181 codec->patch_ops = stac92xx_patch_ops;
3182
3183 return 0;
3184};
3185
Matt2f2f4252005-04-13 14:45:30 +02003186static int patch_stac922x(struct hda_codec *codec)
3187{
3188 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003189 int err;
Matt2f2f4252005-04-13 14:45:30 +02003190
Takashi Iwaie560d8d2005-09-09 14:21:46 +02003191 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02003192 if (spec == NULL)
3193 return -ENOMEM;
3194
3195 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003196 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003197 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003198 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
3199 stac922x_models,
3200 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003201 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003202 spec->gpio_mute = 1;
3203 /* Intel Macs have all same PCI SSID, so we need to check
3204 * codec SSID to distinguish the exact models
3205 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01003206 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003207 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003208
3209 case 0x106b0800:
3210 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02003211 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003212 case 0x106b0600:
3213 case 0x106b0700:
3214 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01003215 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003216 case 0x106b0e00:
3217 case 0x106b0f00:
3218 case 0x106b1600:
3219 case 0x106b1700:
3220 case 0x106b0200:
3221 case 0x106b1e00:
3222 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003223 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003224 case 0x106b1a00:
3225 case 0x00000100:
3226 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02003227 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003228 case 0x106b0a00:
3229 case 0x106b2200:
3230 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02003231 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003232 }
3233 }
3234
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003235 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02003236 if (spec->board_config < 0) {
3237 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
3238 "using BIOS defaults\n");
3239 err = stac92xx_save_bios_config_regs(codec);
3240 if (err < 0) {
3241 stac92xx_free(codec);
3242 return err;
3243 }
3244 spec->pin_configs = spec->bios_pin_configs;
3245 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01003246 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
3247 stac92xx_set_config_regs(codec);
3248 }
Matt2f2f4252005-04-13 14:45:30 +02003249
Matt2f2f4252005-04-13 14:45:30 +02003250 spec->adc_nids = stac922x_adc_nids;
3251 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01003252 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003253 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02003254 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003255
3256 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02003257 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02003258
3259 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003260
Matt Porter3cc08dc2006-01-23 15:27:49 +01003261 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003262 if (!err) {
3263 if (spec->board_config < 0) {
3264 printk(KERN_WARNING "hda_codec: No auto-config is "
3265 "available, default to model=ref\n");
3266 spec->board_config = STAC_D945_REF;
3267 goto again;
3268 }
3269 err = -EINVAL;
3270 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01003271 if (err < 0) {
3272 stac92xx_free(codec);
3273 return err;
3274 }
3275
3276 codec->patch_ops = stac92xx_patch_ops;
3277
Takashi Iwai807a46362007-05-29 19:01:37 +02003278 /* Fix Mux capture level; max to 2 */
3279 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
3280 (0 << AC_AMPCAP_OFFSET_SHIFT) |
3281 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3282 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3283 (0 << AC_AMPCAP_MUTE_SHIFT));
3284
Matt Porter3cc08dc2006-01-23 15:27:49 +01003285 return 0;
3286}
3287
3288static int patch_stac927x(struct hda_codec *codec)
3289{
3290 struct sigmatel_spec *spec;
3291 int err;
3292
3293 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3294 if (spec == NULL)
3295 return -ENOMEM;
3296
3297 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003298 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003299 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003300 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
3301 stac927x_models,
3302 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003303 again:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003304 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
3305 if (spec->board_config < 0)
3306 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3307 "STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02003308 err = stac92xx_save_bios_config_regs(codec);
3309 if (err < 0) {
3310 stac92xx_free(codec);
3311 return err;
3312 }
3313 spec->pin_configs = spec->bios_pin_configs;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003314 } else {
Matt Porter3cc08dc2006-01-23 15:27:49 +01003315 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
3316 stac92xx_set_config_regs(codec);
3317 }
3318
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003319 spec->adc_nids = stac927x_adc_nids;
3320 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
3321 spec->mux_nids = stac927x_mux_nids;
3322 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
3323 spec->multiout.dac_nids = spec->dac_nids;
3324
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003325 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02003326 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003327 case STAC_D965_5ST:
3328 /* GPIO0 High = Enable EAPD */
3329 spec->gpio_mask = spec->gpio_data = 0x00000001;
3330 spec->num_dmics = 0;
3331
Tobin Davis93ed1502006-09-01 21:03:12 +02003332 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003333 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003334 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003335 case STAC_DELL_BIOS:
Matthew Ranostayc481fca2008-01-07 12:18:28 +01003336 /* correct the front input jack as a mic */
3337 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130);
3338 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003339 case STAC_DELL_3ST:
3340 /* GPIO2 High = Enable EAPD */
3341 spec->gpio_mask = spec->gpio_data = 0x00000004;
3342 spec->dmic_nids = stac927x_dmic_nids;
3343 spec->num_dmics = STAC927X_NUM_DMICS;
3344
Tobin Davis93ed1502006-09-01 21:03:12 +02003345 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003346 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003347 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003348 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003349 break;
3350 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003351 /* GPIO0 High = Enable EAPD */
3352 spec->gpio_mask = spec->gpio_data = 0x00000001;
3353 spec->num_dmics = 0;
3354
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003355 spec->init = stac927x_core_init;
3356 spec->mixer = stac927x_mixer;
3357 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01003358
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003359 spec->aloopback_mask = 0x40;
3360 spec->aloopback_shift = 0;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003361
Takashi Iwai82599802007-07-31 15:56:24 +02003362 stac92xx_enable_gpio_mask(codec);
Matt Porter3cc08dc2006-01-23 15:27:49 +01003363 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003364 if (!err) {
3365 if (spec->board_config < 0) {
3366 printk(KERN_WARNING "hda_codec: No auto-config is "
3367 "available, default to model=ref\n");
3368 spec->board_config = STAC_D965_REF;
3369 goto again;
3370 }
3371 err = -EINVAL;
3372 }
Mattc7d4b2f2005-06-27 14:59:41 +02003373 if (err < 0) {
3374 stac92xx_free(codec);
3375 return err;
3376 }
Matt2f2f4252005-04-13 14:45:30 +02003377
3378 codec->patch_ops = stac92xx_patch_ops;
3379
3380 return 0;
3381}
3382
Matt Porterf3302a52006-07-31 12:49:34 +02003383static int patch_stac9205(struct hda_codec *codec)
3384{
3385 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02003386 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02003387
3388 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3389 if (spec == NULL)
3390 return -ENOMEM;
3391
3392 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003393 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003394 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003395 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
3396 stac9205_models,
3397 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003398 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02003399 if (spec->board_config < 0) {
3400 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
3401 err = stac92xx_save_bios_config_regs(codec);
3402 if (err < 0) {
3403 stac92xx_free(codec);
3404 return err;
3405 }
3406 spec->pin_configs = spec->bios_pin_configs;
3407 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02003408 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
3409 stac92xx_set_config_regs(codec);
3410 }
3411
3412 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003413 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02003414 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01003415 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02003416 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02003417 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003418 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003419 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02003420
3421 spec->init = stac9205_core_init;
3422 spec->mixer = stac9205_mixer;
3423
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003424 spec->aloopback_mask = 0x40;
3425 spec->aloopback_shift = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02003426 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02003427
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003428 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003429 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02003430 /* Enable SPDIF in/out */
3431 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
3432 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01003433
Takashi Iwai82599802007-07-31 15:56:24 +02003434 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
Matthew Ranostay87d48362007-07-17 11:52:24 +02003435 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
3436 * GPIO2 High = Headphone Mute
3437 */
Takashi Iwai82599802007-07-31 15:56:24 +02003438 spec->gpio_data = 0x00000005;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003439 break;
3440 default:
3441 /* GPIO0 High = EAPD */
3442 spec->gpio_mask = spec->gpio_data = 0x00000001;
3443 break;
3444 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02003445
Takashi Iwai82599802007-07-31 15:56:24 +02003446 stac92xx_enable_gpio_mask(codec);
Matt Porterf3302a52006-07-31 12:49:34 +02003447 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003448 if (!err) {
3449 if (spec->board_config < 0) {
3450 printk(KERN_WARNING "hda_codec: No auto-config is "
3451 "available, default to model=ref\n");
3452 spec->board_config = STAC_9205_REF;
3453 goto again;
3454 }
3455 err = -EINVAL;
3456 }
Matt Porterf3302a52006-07-31 12:49:34 +02003457 if (err < 0) {
3458 stac92xx_free(codec);
3459 return err;
3460 }
3461
3462 codec->patch_ops = stac92xx_patch_ops;
3463
3464 return 0;
3465}
3466
Matt2f2f4252005-04-13 14:45:30 +02003467/*
Guillaume Munch6d859062006-08-22 17:15:47 +02003468 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01003469 */
3470
Guillaume Munch99ccc562006-08-16 19:35:12 +02003471/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003472static hda_nid_t vaio_dacs[] = { 0x2 };
3473#define VAIO_HP_DAC 0x5
3474static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
3475static hda_nid_t vaio_mux_nids[] = { 0x15 };
3476
3477static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02003478 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01003479 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02003480 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003481 { "Mic Jack", 0x1 },
3482 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01003483 { "PCM", 0x3 },
3484 }
3485};
3486
3487static struct hda_verb vaio_init[] = {
3488 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003489 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01003490 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3491 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3492 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3493 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003494 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003495 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3496 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3497 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3498 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3499 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3500 {}
3501};
3502
Guillaume Munch6d859062006-08-22 17:15:47 +02003503static struct hda_verb vaio_ar_init[] = {
3504 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
3505 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3506 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3507 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3508/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
3509 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003510 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02003511 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3512 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3513/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
3514 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3515 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3516 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3517 {}
3518};
3519
Takashi Iwaidb064e52006-03-16 16:04:58 +01003520/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003521static struct hda_bind_ctls vaio_bind_master_vol = {
3522 .ops = &snd_hda_bind_vol,
3523 .values = {
3524 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3525 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3526 0
3527 },
3528};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003529
3530/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003531static struct hda_bind_ctls vaio_bind_master_sw = {
3532 .ops = &snd_hda_bind_sw,
3533 .values = {
3534 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3535 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3536 0,
3537 },
3538};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003539
3540static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003541 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3542 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003543 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3544 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3545 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3546 {
3547 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3548 .name = "Capture Source",
3549 .count = 1,
3550 .info = stac92xx_mux_enum_info,
3551 .get = stac92xx_mux_enum_get,
3552 .put = stac92xx_mux_enum_put,
3553 },
3554 {}
3555};
3556
Guillaume Munch6d859062006-08-22 17:15:47 +02003557static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003558 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3559 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Guillaume Munch6d859062006-08-22 17:15:47 +02003560 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3561 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3562 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3563 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
3564 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
3565 {
3566 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3567 .name = "Capture Source",
3568 .count = 1,
3569 .info = stac92xx_mux_enum_info,
3570 .get = stac92xx_mux_enum_get,
3571 .put = stac92xx_mux_enum_put,
3572 },
3573 {}
3574};
3575
3576static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01003577 .build_controls = stac92xx_build_controls,
3578 .build_pcms = stac92xx_build_pcms,
3579 .init = stac92xx_init,
3580 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02003581#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01003582 .resume = stac92xx_resume,
3583#endif
3584};
3585
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003586static int stac9872_vaio_init(struct hda_codec *codec)
3587{
3588 int err;
3589
3590 err = stac92xx_init(codec);
3591 if (err < 0)
3592 return err;
3593 if (codec->patch_ops.unsol_event)
3594 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
3595 return 0;
3596}
3597
3598static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
3599{
Jiang Zhe40c1d302007-11-12 13:05:16 +01003600 if (get_hp_pin_presence(codec, 0x0a)) {
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003601 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3602 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3603 } else {
3604 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3605 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3606 }
3607}
3608
3609static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
3610{
3611 switch (res >> 26) {
3612 case STAC_HP_EVENT:
3613 stac9872_vaio_hp_detect(codec, res);
3614 break;
3615 }
3616}
3617
3618static struct hda_codec_ops stac9872_vaio_patch_ops = {
3619 .build_controls = stac92xx_build_controls,
3620 .build_pcms = stac92xx_build_pcms,
3621 .init = stac9872_vaio_init,
3622 .free = stac92xx_free,
3623 .unsol_event = stac9872_vaio_unsol_event,
3624#ifdef CONFIG_PM
3625 .resume = stac92xx_resume,
3626#endif
3627};
3628
Guillaume Munch6d859062006-08-22 17:15:47 +02003629enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
3630 CXD9872RD_VAIO,
3631 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
3632 STAC9872AK_VAIO,
3633 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
3634 STAC9872K_VAIO,
3635 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003636 CXD9872AKD_VAIO,
3637 STAC_9872_MODELS,
3638};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003639
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003640static const char *stac9872_models[STAC_9872_MODELS] = {
3641 [CXD9872RD_VAIO] = "vaio",
3642 [CXD9872AKD_VAIO] = "vaio-ar",
3643};
3644
3645static struct snd_pci_quirk stac9872_cfg_tbl[] = {
3646 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
3647 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
3648 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01003649 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003650 {}
3651};
3652
Guillaume Munch6d859062006-08-22 17:15:47 +02003653static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01003654{
3655 struct sigmatel_spec *spec;
3656 int board_config;
3657
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003658 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
3659 stac9872_models,
3660 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01003661 if (board_config < 0)
3662 /* unknown config, let generic-parser do its job... */
3663 return snd_hda_parse_generic_codec(codec);
3664
3665 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3666 if (spec == NULL)
3667 return -ENOMEM;
3668
3669 codec->spec = spec;
3670 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02003671 case CXD9872RD_VAIO:
3672 case STAC9872AK_VAIO:
3673 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01003674 spec->mixer = vaio_mixer;
3675 spec->init = vaio_init;
3676 spec->multiout.max_channels = 2;
3677 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3678 spec->multiout.dac_nids = vaio_dacs;
3679 spec->multiout.hp_nid = VAIO_HP_DAC;
3680 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3681 spec->adc_nids = vaio_adcs;
3682 spec->input_mux = &vaio_mux;
3683 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003684 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003685 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02003686
3687 case CXD9872AKD_VAIO:
3688 spec->mixer = vaio_ar_mixer;
3689 spec->init = vaio_ar_init;
3690 spec->multiout.max_channels = 2;
3691 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3692 spec->multiout.dac_nids = vaio_dacs;
3693 spec->multiout.hp_nid = VAIO_HP_DAC;
3694 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3695 spec->adc_nids = vaio_adcs;
3696 spec->input_mux = &vaio_mux;
3697 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003698 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02003699 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003700 }
3701
Takashi Iwaidb064e52006-03-16 16:04:58 +01003702 return 0;
3703}
3704
3705
3706/*
Matt2f2f4252005-04-13 14:45:30 +02003707 * patch entries
3708 */
3709struct hda_codec_preset snd_hda_preset_sigmatel[] = {
3710 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
3711 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
3712 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
3713 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
3714 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
3715 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
3716 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02003717 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
3718 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
3719 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
3720 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
3721 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
3722 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01003723 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
3724 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
3725 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
3726 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
3727 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
3728 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
3729 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
3730 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
3731 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
3732 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01003733 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
3734 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
3735 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
3736 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
3737 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
3738 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02003739 /* The following does not take into account .id=0x83847661 when subsys =
3740 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
3741 * currently not fully supported.
3742 */
3743 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
3744 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
3745 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02003746 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
3747 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
3748 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
3749 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
3750 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
3751 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
3752 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
3753 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostay541eee82007-12-14 12:08:04 +01003754 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
3755 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003756 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01003757 { .id = 0x111d7608, .name = "92HD71BXX", .patch = patch_stac92hd71bxx },
3758 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
3759 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
3760 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
3761 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
3762 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
3763 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
3764 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
3765 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02003766 {} /* terminator */
3767};