blob: 0817f42a7c86c14e7dbbca195bc13b2e30f9e732 [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 Ranostaye035b842007-11-06 11:53:55 +010065 STAC_92HD71BXX_REF,
66 STAC_92HD71BXX_MODELS
67};
68
69enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010070 STAC_925x_REF,
71 STAC_M2_2,
72 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020073 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +010074 STAC_925x_MODELS
75};
76
77enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +010078 STAC_D945_REF,
79 STAC_D945GTP3,
80 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +020081 STAC_INTEL_MAC_V1,
82 STAC_INTEL_MAC_V2,
83 STAC_INTEL_MAC_V3,
84 STAC_INTEL_MAC_V4,
85 STAC_INTEL_MAC_V5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020086 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +010087 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +010088 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +010089 STAC_MACBOOK_PRO_V1,
90 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +020091 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +020092 STAC_IMAC_INTEL_20,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020093 STAC_922X_DELL_D81,
94 STAC_922X_DELL_D82,
95 STAC_922X_DELL_M81,
96 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010097 STAC_922X_MODELS
98};
99
100enum {
101 STAC_D965_REF,
102 STAC_D965_3ST,
103 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200104 STAC_DELL_3ST,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100105 STAC_927X_MODELS
106};
Matt Porter403d1942005-11-29 15:00:51 +0100107
Matt2f2f4252005-04-13 14:45:30 +0200108struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100109 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200110 unsigned int num_mixers;
111
Matt Porter403d1942005-11-29 15:00:51 +0100112 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +0200113 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +0100114 unsigned int line_switch: 1;
115 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100116 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100117 unsigned int hp_detect: 1;
Sam Revitch62fe78e2006-05-10 15:09:17 +0200118 unsigned int gpio_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200119
Takashi Iwai82599802007-07-31 15:56:24 +0200120 unsigned int gpio_mask, gpio_data;
121
Matt2f2f4252005-04-13 14:45:30 +0200122 /* playback */
123 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100124 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200125
126 /* capture */
127 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200128 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200129 hda_nid_t *mux_nids;
130 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200131 hda_nid_t *dmic_nids;
132 unsigned int num_dmics;
133 hda_nid_t dmux_nid;
Mattdabbed62005-06-14 10:19:34 +0200134 hda_nid_t dig_in_nid;
Matt2f2f4252005-04-13 14:45:30 +0200135
Matt2f2f4252005-04-13 14:45:30 +0200136 /* pin widgets */
137 hda_nid_t *pin_nids;
138 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200139 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200140 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200141
142 /* codec specific stuff */
143 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100144 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200145
146 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200147 struct hda_input_mux *dinput_mux;
148 unsigned int cur_dmux;
Mattc7d4b2f2005-06-27 14:59:41 +0200149 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100150 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200151
Matt Porter403d1942005-11-29 15:00:51 +0100152 /* i/o switches */
153 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200154 unsigned int clfe_swap;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200155 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200156
Mattc7d4b2f2005-06-27 14:59:41 +0200157 struct hda_pcm pcm_rec[2]; /* PCM information */
158
159 /* dynamic controls and input_mux */
160 struct auto_pin_cfg autocfg;
161 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100162 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200163 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200164 struct hda_input_mux private_imux;
Matt2f2f4252005-04-13 14:45:30 +0200165};
166
167static hda_nid_t stac9200_adc_nids[1] = {
168 0x03,
169};
170
171static hda_nid_t stac9200_mux_nids[1] = {
172 0x0c,
173};
174
175static hda_nid_t stac9200_dac_nids[1] = {
176 0x02,
177};
178
Matthew Ranostaye035b842007-11-06 11:53:55 +0100179static hda_nid_t stac92hd71bxx_adc_nids[2] = {
180 0x12, 0x13,
181};
182
183static hda_nid_t stac92hd71bxx_mux_nids[2] = {
184 0x1a, 0x1b
185};
186
187static hda_nid_t stac92hd71bxx_dac_nids[2] = {
188 0x10, /*0x11, */
189};
190
191#define STAC92HD71BXX_NUM_DMICS 2
192static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
193 0x18, 0x19, 0
194};
195
Tobin Davis8e21c342007-01-08 11:04:17 +0100196static hda_nid_t stac925x_adc_nids[1] = {
197 0x03,
198};
199
200static hda_nid_t stac925x_mux_nids[1] = {
201 0x0f,
202};
203
204static hda_nid_t stac925x_dac_nids[1] = {
205 0x02,
206};
207
Takashi Iwaif6e98522007-10-16 14:27:04 +0200208#define STAC925X_NUM_DMICS 1
209static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
210 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200211};
212
Matt2f2f4252005-04-13 14:45:30 +0200213static hda_nid_t stac922x_adc_nids[2] = {
214 0x06, 0x07,
215};
216
217static hda_nid_t stac922x_mux_nids[2] = {
218 0x12, 0x13,
219};
220
Matt Porter3cc08dc2006-01-23 15:27:49 +0100221static hda_nid_t stac927x_adc_nids[3] = {
222 0x07, 0x08, 0x09
223};
224
225static hda_nid_t stac927x_mux_nids[3] = {
226 0x15, 0x16, 0x17
227};
228
Matthew Ranostay7f168592007-10-18 17:38:17 +0200229#define STAC927X_NUM_DMICS 2
230static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
231 0x13, 0x14, 0
232};
233
Matt Porterf3302a52006-07-31 12:49:34 +0200234static hda_nid_t stac9205_adc_nids[2] = {
235 0x12, 0x13
236};
237
238static hda_nid_t stac9205_mux_nids[2] = {
239 0x19, 0x1a
240};
241
Takashi Iwaif6e98522007-10-16 14:27:04 +0200242#define STAC9205_NUM_DMICS 2
243static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
244 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200245};
246
Mattc7d4b2f2005-06-27 14:59:41 +0200247static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200248 0x08, 0x09, 0x0d, 0x0e,
249 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200250};
251
Tobin Davis8e21c342007-01-08 11:04:17 +0100252static hda_nid_t stac925x_pin_nids[8] = {
253 0x07, 0x08, 0x0a, 0x0b,
254 0x0c, 0x0d, 0x10, 0x11,
255};
256
Matt2f2f4252005-04-13 14:45:30 +0200257static hda_nid_t stac922x_pin_nids[10] = {
258 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
259 0x0f, 0x10, 0x11, 0x15, 0x1b,
260};
261
Matthew Ranostaye035b842007-11-06 11:53:55 +0100262static hda_nid_t stac92hd71bxx_pin_nids[10] = {
263 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
264 0x0f, 0x14, 0x18, 0x19, 0x1e,
265};
266
Matt Porter3cc08dc2006-01-23 15:27:49 +0100267static hda_nid_t stac927x_pin_nids[14] = {
268 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
269 0x0f, 0x10, 0x11, 0x12, 0x13,
270 0x14, 0x21, 0x22, 0x23,
271};
272
Matt Porterf3302a52006-07-31 12:49:34 +0200273static hda_nid_t stac9205_pin_nids[12] = {
274 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
275 0x0f, 0x14, 0x16, 0x17, 0x18,
276 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200277};
278
Matt Porter8b657272006-10-26 17:12:59 +0200279static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
280 struct snd_ctl_elem_info *uinfo)
281{
282 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
283 struct sigmatel_spec *spec = codec->spec;
284 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
285}
286
287static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
288 struct snd_ctl_elem_value *ucontrol)
289{
290 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
291 struct sigmatel_spec *spec = codec->spec;
292
293 ucontrol->value.enumerated.item[0] = spec->cur_dmux;
294 return 0;
295}
296
297static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
298 struct snd_ctl_elem_value *ucontrol)
299{
300 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
301 struct sigmatel_spec *spec = codec->spec;
302
303 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
304 spec->dmux_nid, &spec->cur_dmux);
305}
306
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100307static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200308{
309 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
310 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200311 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200312}
313
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100314static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200315{
316 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
317 struct sigmatel_spec *spec = codec->spec;
318 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
319
320 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
321 return 0;
322}
323
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100324static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200325{
326 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
327 struct sigmatel_spec *spec = codec->spec;
328 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
329
Mattc7d4b2f2005-06-27 14:59:41 +0200330 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200331 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
332}
333
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200334#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
335
336static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
337 struct snd_ctl_elem_value *ucontrol)
338{
339 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
340 struct sigmatel_spec *spec = codec->spec;
341
342 ucontrol->value.integer.value[0] = spec->aloopback;
343 return 0;
344}
345
346static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
347 struct snd_ctl_elem_value *ucontrol)
348{
349 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
350 struct sigmatel_spec *spec = codec->spec;
351 unsigned int dac_mode;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100352 unsigned int val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200353
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100354 val = !!ucontrol->value.integer.value[0];
355 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200356 return 0;
357
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100358 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200359
360 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
361 kcontrol->private_value & 0xFFFF, 0x0);
362
363 if (spec->aloopback) {
364 snd_hda_power_up(codec);
365 dac_mode |= 0x40;
366 } else {
367 snd_hda_power_down(codec);
368 dac_mode &= ~0x40;
369 }
370
371 snd_hda_codec_write_cache(codec, codec->afg, 0,
372 kcontrol->private_value >> 16, dac_mode);
373
374 return 1;
375}
376
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100377static int stac92xx_volknob_info(struct snd_kcontrol *kcontrol,
378 struct snd_ctl_elem_info *uinfo)
379{
380 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
381 uinfo->count = 1;
382 uinfo->value.integer.min = 0;
383 uinfo->value.integer.max = 127;
384 return 0;
385}
386
387static int stac92xx_volknob_get(struct snd_kcontrol *kcontrol,
388 struct snd_ctl_elem_value *ucontrol)
389{
390 ucontrol->value.integer.value[0] = kcontrol->private_value & 0xff;
391 return 0;
392}
393
394static int stac92xx_volknob_put(struct snd_kcontrol *kcontrol,
395 struct snd_ctl_elem_value *ucontrol)
396{
397 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
398 unsigned int oval = kcontrol->private_value & 0xff;
399 unsigned int val;
400
401 val = ucontrol->value.integer.value[0] & 0xff;
402 if (val == oval)
403 return 0;
404
405 kcontrol->private_value &= ~0xff;
406 kcontrol->private_value |= val;
407
408 snd_hda_codec_write_cache(codec, kcontrol->private_value >> 16, 0,
409 AC_VERB_SET_VOLUME_KNOB_CONTROL, val | 0x80);
410 return 1;
411}
412
Mattc7d4b2f2005-06-27 14:59:41 +0200413static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200414 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200415 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200416 {}
417};
418
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200419static struct hda_verb stac9200_eapd_init[] = {
420 /* set dac0mux for dac converter */
421 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
422 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
423 {}
424};
425
Matthew Ranostaye035b842007-11-06 11:53:55 +0100426static struct hda_verb stac92hd71bxx_core_init[] = {
427 /* set master volume and direct control */
428 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
429 /* connect headphone jack to dac1 */
430 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay9b359472007-11-07 13:03:12 +0100431 /* connect ports 0d and 0f to audio mixer */
432 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2},
433 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
434 /* unmute dac0 input in audio mixer */
435 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100436 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
437 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
438 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
439 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
440 /* unmute mono out node */
441 { 0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
442 {}
443};
444
Tobin Davis8e21c342007-01-08 11:04:17 +0100445static struct hda_verb stac925x_core_init[] = {
446 /* set dac0mux for dac converter */
447 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
448 {}
449};
450
Mattc7d4b2f2005-06-27 14:59:41 +0200451static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200452 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200453 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200454 {}
455};
456
Tobin Davis93ed1502006-09-01 21:03:12 +0200457static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200458 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200459 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200460 /* unmute node 0x1b */
461 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
462 /* select node 0x03 as DAC */
463 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
464 {}
465};
466
Matt Porter3cc08dc2006-01-23 15:27:49 +0100467static struct hda_verb stac927x_core_init[] = {
468 /* set master volume and direct control */
469 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
470 {}
471};
472
Matt Porterf3302a52006-07-31 12:49:34 +0200473static struct hda_verb stac9205_core_init[] = {
474 /* set master volume and direct control */
475 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
476 {}
477};
478
Matthew Ranostay47744f62007-10-19 08:19:56 +0200479#define STAC_DIGITAL_INPUT_SOURCE(cnt) \
480 { \
481 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
482 .name = "Digital Input Source", \
483 .count = cnt, \
484 .info = stac92xx_dmux_enum_info, \
485 .get = stac92xx_dmux_enum_get, \
486 .put = stac92xx_dmux_enum_put,\
487 }
488
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200489#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200490 { \
491 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
492 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200493 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200494 .info = stac92xx_mux_enum_info, \
495 .get = stac92xx_mux_enum_get, \
496 .put = stac92xx_mux_enum_put, \
497 }
498
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200499#define STAC_ANALOG_LOOPBACK(verb_read,verb_write) \
500 { \
501 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
502 .name = "Analog Loopback", \
503 .count = 1, \
504 .info = stac92xx_aloopback_info, \
505 .get = stac92xx_aloopback_get, \
506 .put = stac92xx_aloopback_put, \
507 .private_value = verb_read | (verb_write << 16), \
508 }
509
Matthew Ranostay9b359472007-11-07 13:03:12 +0100510#define STAC_VOLKNOB(knob_nid) \
511 { \
512 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
513 .name = "Master Playback Volume", \
514 .count = 1, \
515 .info = stac92xx_volknob_info, \
516 .get = stac92xx_volknob_get, \
517 .put = stac92xx_volknob_put, \
518 .private_value = 127 | (knob_nid << 16), \
519 }
520
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100521static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200522 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
523 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200524 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200525 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
526 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200527 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200528 { } /* end */
529};
530
Matthew Ranostaye035b842007-11-06 11:53:55 +0100531static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
532 STAC_DIGITAL_INPUT_SOURCE(1),
533 STAC_INPUT_SOURCE(2),
534 STAC_VOLKNOB(0x28),
535
536 /* hardware gain controls */
Matthew Ranostay9b359472007-11-07 13:03:12 +0100537 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x18, 0x0, HDA_OUTPUT),
538 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x19, 0x0, HDA_OUTPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100539
Matthew Ranostay9b359472007-11-07 13:03:12 +0100540 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
541 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
542 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
543
544 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
545 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
546 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
547
548 HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT),
549 HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100550 { } /* end */
551};
552
Tobin Davis8e21c342007-01-08 11:04:17 +0100553static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200554 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +0100555 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
556 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
557 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
558 { } /* end */
559};
560
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100561static struct snd_kcontrol_new stac9205_mixer[] = {
Matthew Ranostay47744f62007-10-19 08:19:56 +0200562 STAC_DIGITAL_INPUT_SOURCE(1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200563 STAC_INPUT_SOURCE(2),
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200564 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200565
566 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
567 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
568 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
569
570 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
571 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
572 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
573
574 { } /* end */
575};
576
577/* This needs to be generated dynamically based on sequence */
578static struct snd_kcontrol_new stac922x_mixer[] = {
579 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200580 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
581 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
582 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
583
584 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
585 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
586 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
587 { } /* end */
588};
589
590
591static struct snd_kcontrol_new stac927x_mixer[] = {
Matthew Ranostay47744f62007-10-19 08:19:56 +0200592 STAC_DIGITAL_INPUT_SOURCE(1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200593 STAC_INPUT_SOURCE(3),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200594 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB),
595
596 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
597 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
598 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
599
600 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
601 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
602 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
603
604 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
605 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
606 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +0200607 { } /* end */
608};
609
Matt2f2f4252005-04-13 14:45:30 +0200610static int stac92xx_build_controls(struct hda_codec *codec)
611{
612 struct sigmatel_spec *spec = codec->spec;
613 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200614 int i;
Matt2f2f4252005-04-13 14:45:30 +0200615
616 err = snd_hda_add_new_ctls(codec, spec->mixer);
617 if (err < 0)
618 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200619
620 for (i = 0; i < spec->num_mixers; i++) {
621 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
622 if (err < 0)
623 return err;
624 }
625
Mattdabbed62005-06-14 10:19:34 +0200626 if (spec->multiout.dig_out_nid) {
627 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
628 if (err < 0)
629 return err;
630 }
631 if (spec->dig_in_nid) {
632 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
633 if (err < 0)
634 return err;
635 }
636 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200637}
638
Matt Porter403d1942005-11-29 15:00:51 +0100639static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200640 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200641 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
642};
643
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200644/*
645 STAC 9200 pin configs for
646 102801A8
647 102801DE
648 102801E8
649*/
650static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200651 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
652 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200653};
654
655/*
656 STAC 9200 pin configs for
657 102801C0
658 102801C1
659*/
660static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200661 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
662 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200663};
664
665/*
666 STAC 9200 pin configs for
667 102801C4 (Dell Dimension E310)
668 102801C5
669 102801C7
670 102801D9
671 102801DA
672 102801E3
673*/
674static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200675 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
676 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200677};
678
679
680/*
681 STAC 9200-32 pin configs for
682 102801B5 (Dell Inspiron 630m)
683 102801D8 (Dell Inspiron 640m)
684*/
685static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200686 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
687 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200688};
689
690/*
691 STAC 9200-32 pin configs for
692 102801C2 (Dell Latitude D620)
693 102801C8
694 102801CC (Dell Latitude D820)
695 102801D4
696 102801D6
697*/
698static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200699 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
700 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200701};
702
703/*
704 STAC 9200-32 pin configs for
705 102801CE (Dell XPS M1710)
706 102801CF (Dell Precision M90)
707*/
708static unsigned int dell9200_m23_pin_configs[8] = {
709 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
710 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
711};
712
713/*
714 STAC 9200-32 pin configs for
715 102801C9
716 102801CA
717 102801CB (Dell Latitude 120L)
718 102801D3
719*/
720static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200721 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
722 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200723};
724
725/*
726 STAC 9200-32 pin configs for
727 102801BD (Dell Inspiron E1505n)
728 102801EE
729 102801EF
730*/
731static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200732 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
733 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200734};
735
736/*
737 STAC 9200-32 pin configs for
738 102801F5 (Dell Inspiron 1501)
739 102801F6
740*/
741static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200742 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
743 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200744};
745
746/*
747 STAC 9200-32
748 102801CD (Dell Inspiron E1705/9400)
749*/
750static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200751 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
752 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200753};
754
755
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100756static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
757 [STAC_REF] = ref9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200758 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
759 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
760 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
761 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
762 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
763 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
764 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
765 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
766 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
767 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100768};
769
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100770static const char *stac9200_models[STAC_9200_MODELS] = {
771 [STAC_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200772 [STAC_9200_DELL_D21] = "dell-d21",
773 [STAC_9200_DELL_D22] = "dell-d22",
774 [STAC_9200_DELL_D23] = "dell-d23",
775 [STAC_9200_DELL_M21] = "dell-m21",
776 [STAC_9200_DELL_M22] = "dell-m22",
777 [STAC_9200_DELL_M23] = "dell-m23",
778 [STAC_9200_DELL_M24] = "dell-m24",
779 [STAC_9200_DELL_M25] = "dell-m25",
780 [STAC_9200_DELL_M26] = "dell-m26",
781 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200782 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100783};
784
785static struct snd_pci_quirk stac9200_cfg_tbl[] = {
786 /* SigmaTel reference board */
787 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
788 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100789 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200790 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
791 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100792 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200793 "Dell Inspiron 630m", STAC_9200_DELL_M21),
794 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
795 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
796 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
797 "unknown Dell", STAC_9200_DELL_D22),
798 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
799 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100800 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200801 "Dell Latitude D620", STAC_9200_DELL_M22),
802 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
803 "unknown Dell", STAC_9200_DELL_D23),
804 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
805 "unknown Dell", STAC_9200_DELL_D23),
806 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
807 "unknown Dell", STAC_9200_DELL_M22),
808 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
809 "unknown Dell", STAC_9200_DELL_M24),
810 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
811 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100812 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200813 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100814 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200815 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100816 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200817 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100818 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200819 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100820 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200821 "Dell Precision M90", STAC_9200_DELL_M23),
822 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
823 "unknown Dell", STAC_9200_DELL_M22),
824 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
825 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +0200826 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200827 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +0200828 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200829 "Dell Inspiron 640m", STAC_9200_DELL_M21),
830 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
831 "unknown Dell", STAC_9200_DELL_D23),
832 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
833 "unknown Dell", STAC_9200_DELL_D23),
834 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
835 "unknown Dell", STAC_9200_DELL_D21),
836 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
837 "unknown Dell", STAC_9200_DELL_D23),
838 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
839 "unknown Dell", STAC_9200_DELL_D21),
840 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
841 "unknown Dell", STAC_9200_DELL_M25),
842 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
843 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +0200844 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200845 "Dell Inspiron 1501", STAC_9200_DELL_M26),
846 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
847 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +0200848 /* Panasonic */
849 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200850 /* Gateway machines needs EAPD to be set on resume */
851 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
852 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
853 STAC_9200_GATEWAY),
854 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
855 STAC_9200_GATEWAY),
Matt Porter403d1942005-11-29 15:00:51 +0100856 {} /* terminator */
857};
858
Tobin Davis8e21c342007-01-08 11:04:17 +0100859static unsigned int ref925x_pin_configs[8] = {
860 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
861 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
862};
863
864static unsigned int stac925x_MA6_pin_configs[8] = {
865 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
866 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
867};
868
Tobin Davis2c11f952007-05-17 09:36:34 +0200869static unsigned int stac925x_PA6_pin_configs[8] = {
870 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
871 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
872};
873
Tobin Davis8e21c342007-01-08 11:04:17 +0100874static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +0200875 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
876 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +0100877};
878
879static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
880 [STAC_REF] = ref925x_pin_configs,
881 [STAC_M2_2] = stac925xM2_2_pin_configs,
882 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200883 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100884};
885
886static const char *stac925x_models[STAC_925x_MODELS] = {
887 [STAC_REF] = "ref",
888 [STAC_M2_2] = "m2-2",
889 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200890 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100891};
892
893static struct snd_pci_quirk stac925x_cfg_tbl[] = {
894 /* SigmaTel reference board */
895 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200896 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100897 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
898 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
899 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200900 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100901 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
902 {} /* terminator */
903};
904
Matthew Ranostaye035b842007-11-06 11:53:55 +0100905static unsigned int ref92hd71bxx_pin_configs[10] = {
906 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
907 0x0181302e, 0x01114010, 0x01a19020, 0x90a000f0,
908 0x90a000f0, 0x01452050,
909};
910
911static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
912 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
913};
914
915static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
916 [STAC_92HD71BXX_REF] = "ref",
917};
918
919static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
920 /* SigmaTel reference board */
921 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
922 "DFI LanParty", STAC_92HD71BXX_REF),
923 {} /* terminator */
924};
925
Matt Porter403d1942005-11-29 15:00:51 +0100926static unsigned int ref922x_pin_configs[10] = {
927 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
928 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200929 0x40000100, 0x40000100,
930};
931
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200932/*
933 STAC 922X pin configs for
934 102801A7
935 102801AB
936 102801A9
937 102801D1
938 102801D2
939*/
940static unsigned int dell_922x_d81_pin_configs[10] = {
941 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
942 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
943 0x01813122, 0x400001f2,
944};
945
946/*
947 STAC 922X pin configs for
948 102801AC
949 102801D0
950*/
951static unsigned int dell_922x_d82_pin_configs[10] = {
952 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
953 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
954 0x01813122, 0x400001f1,
955};
956
957/*
958 STAC 922X pin configs for
959 102801BF
960*/
961static unsigned int dell_922x_m81_pin_configs[10] = {
962 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
963 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
964 0x40C003f1, 0x405003f0,
965};
966
967/*
968 STAC 9221 A1 pin configs for
969 102801D7 (Dell XPS M1210)
970*/
971static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +0100972 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
973 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200974 0x508003f3, 0x405003f4,
975};
976
Matt Porter403d1942005-11-29 15:00:51 +0100977static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100978 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100979 0x40000100, 0x40000100, 0x40000100, 0x40000100,
980 0x02a19120, 0x40000100,
981};
982
983static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100984 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
985 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100986 0x02a19320, 0x40000100,
987};
988
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200989static unsigned int intel_mac_v1_pin_configs[10] = {
990 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
991 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100992 0x400000fc, 0x400000fb,
993};
994
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200995static unsigned int intel_mac_v2_pin_configs[10] = {
996 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
997 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200998 0x400000fc, 0x400000fb,
999};
1000
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001001static unsigned int intel_mac_v3_pin_configs[10] = {
1002 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1003 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1004 0x400000fc, 0x400000fb,
1005};
1006
1007static unsigned int intel_mac_v4_pin_configs[10] = {
1008 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1009 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1010 0x400000fc, 0x400000fb,
1011};
1012
1013static unsigned int intel_mac_v5_pin_configs[10] = {
1014 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1015 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1016 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001017};
1018
Takashi Iwai76c08822007-06-19 12:17:42 +02001019
Takashi Iwai19039bd2006-06-28 15:52:16 +02001020static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001021 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001022 [STAC_D945GTP3] = d945gtp3_pin_configs,
1023 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001024 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1025 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1026 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1027 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1028 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001029 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001030 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1031 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1032 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1033 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1034 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1035 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001036 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1037 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1038 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1039 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001040};
1041
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001042static const char *stac922x_models[STAC_922X_MODELS] = {
1043 [STAC_D945_REF] = "ref",
1044 [STAC_D945GTP5] = "5stack",
1045 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001046 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1047 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1048 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1049 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1050 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001051 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001052 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001053 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001054 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1055 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001056 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001057 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001058 [STAC_922X_DELL_D81] = "dell-d81",
1059 [STAC_922X_DELL_D82] = "dell-d82",
1060 [STAC_922X_DELL_M81] = "dell-m81",
1061 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001062};
1063
1064static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1065 /* SigmaTel reference board */
1066 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1067 "DFI LanParty", STAC_D945_REF),
1068 /* Intel 945G based systems */
1069 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1070 "Intel D945G", STAC_D945GTP3),
1071 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1072 "Intel D945G", STAC_D945GTP3),
1073 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1074 "Intel D945G", STAC_D945GTP3),
1075 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1076 "Intel D945G", STAC_D945GTP3),
1077 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1078 "Intel D945G", STAC_D945GTP3),
1079 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1080 "Intel D945G", STAC_D945GTP3),
1081 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1082 "Intel D945G", STAC_D945GTP3),
1083 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1084 "Intel D945G", STAC_D945GTP3),
1085 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1086 "Intel D945G", STAC_D945GTP3),
1087 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1088 "Intel D945G", STAC_D945GTP3),
1089 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1090 "Intel D945G", STAC_D945GTP3),
1091 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1092 "Intel D945G", STAC_D945GTP3),
1093 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1094 "Intel D945G", STAC_D945GTP3),
1095 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1096 "Intel D945G", STAC_D945GTP3),
1097 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1098 "Intel D945G", STAC_D945GTP3),
1099 /* Intel D945G 5-stack systems */
1100 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1101 "Intel D945G", STAC_D945GTP5),
1102 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1103 "Intel D945G", STAC_D945GTP5),
1104 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1105 "Intel D945G", STAC_D945GTP5),
1106 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1107 "Intel D945G", STAC_D945GTP5),
1108 /* Intel 945P based systems */
1109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1110 "Intel D945P", STAC_D945GTP3),
1111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1112 "Intel D945P", STAC_D945GTP3),
1113 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1114 "Intel D945P", STAC_D945GTP3),
1115 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1116 "Intel D945P", STAC_D945GTP3),
1117 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1118 "Intel D945P", STAC_D945GTP3),
1119 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1120 "Intel D945P", STAC_D945GTP5),
1121 /* other systems */
1122 /* Apple Mac Mini (early 2006) */
1123 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001124 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001125 /* Dell systems */
1126 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1127 "unknown Dell", STAC_922X_DELL_D81),
1128 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1129 "unknown Dell", STAC_922X_DELL_D81),
1130 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1131 "unknown Dell", STAC_922X_DELL_D81),
1132 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1133 "unknown Dell", STAC_922X_DELL_D82),
1134 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1135 "unknown Dell", STAC_922X_DELL_M81),
1136 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1137 "unknown Dell", STAC_922X_DELL_D82),
1138 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1139 "unknown Dell", STAC_922X_DELL_D81),
1140 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1141 "unknown Dell", STAC_922X_DELL_D81),
1142 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1143 "Dell XPS M1210", STAC_922X_DELL_M82),
Matt Porter403d1942005-11-29 15:00:51 +01001144 {} /* terminator */
1145};
1146
Matt Porter3cc08dc2006-01-23 15:27:49 +01001147static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001148 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1149 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1150 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1151 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001152};
1153
Tobin Davis93ed1502006-09-01 21:03:12 +02001154static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001155 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1156 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1157 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1158 0x40000100, 0x40000100
1159};
1160
Tobin Davis93ed1502006-09-01 21:03:12 +02001161static unsigned int d965_5st_pin_configs[14] = {
1162 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1163 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1164 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1165 0x40000100, 0x40000100
1166};
1167
Tobin Davis4ff076e2007-08-07 11:48:12 +02001168static unsigned int dell_3st_pin_configs[14] = {
1169 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1170 0x01111212, 0x01116211, 0x01813050, 0x01112214,
1171 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
1172 0x40c003fc, 0x40000100
1173};
1174
Tobin Davis93ed1502006-09-01 21:03:12 +02001175static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001176 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +02001177 [STAC_D965_3ST] = d965_3st_pin_configs,
1178 [STAC_D965_5ST] = d965_5st_pin_configs,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001179 [STAC_DELL_3ST] = dell_3st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001180};
1181
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001182static const char *stac927x_models[STAC_927X_MODELS] = {
1183 [STAC_D965_REF] = "ref",
1184 [STAC_D965_3ST] = "3stack",
1185 [STAC_D965_5ST] = "5stack",
Tobin Davis4ff076e2007-08-07 11:48:12 +02001186 [STAC_DELL_3ST] = "dell-3stack",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001187};
1188
1189static struct snd_pci_quirk stac927x_cfg_tbl[] = {
1190 /* SigmaTel reference board */
1191 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1192 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001193 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001194 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
1195 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001196 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001197 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
1198 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
1199 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
1200 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
1201 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
1202 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
1203 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
1204 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
1205 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
1206 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
1207 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
1208 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
1209 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
1210 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
1211 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
1212 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tim Gardner5e915bb2007-10-10 10:42:00 +02001213 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001214 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001215 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001216 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
1217 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001218 /* 965 based 5 stack systems */
Tim Gardner5e915bb2007-10-10 10:42:00 +02001219 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_D965_5ST),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001220 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
1221 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
1222 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
1223 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
1224 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
1225 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
1226 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
1227 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
1228 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01001229 {} /* terminator */
1230};
1231
Matt Porterf3302a52006-07-31 12:49:34 +02001232static unsigned int ref9205_pin_configs[12] = {
1233 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +02001234 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
1235 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02001236};
1237
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001238/*
1239 STAC 9205 pin configs for
1240 102801F1
1241 102801F2
1242 102801FC
1243 102801FD
1244 10280204
1245 1028021F
1246*/
1247static unsigned int dell_9205_m42_pin_configs[12] = {
1248 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1249 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1250 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1251};
1252
1253/*
1254 STAC 9205 pin configs for
1255 102801F9
1256 102801FA
1257 102801FE
1258 102801FF (Dell Precision M4300)
1259 10280206
1260 10280200
1261 10280201
1262*/
1263static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001264 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1265 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1266 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1267};
1268
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001269static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001270 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1271 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1272 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1273};
1274
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001275static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001276 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001277 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1278 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1279 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02001280};
1281
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001282static const char *stac9205_models[STAC_9205_MODELS] = {
1283 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001284 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001285 [STAC_9205_DELL_M43] = "dell-m43",
1286 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001287};
1288
1289static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1290 /* SigmaTel reference board */
1291 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1292 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001293 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1294 "unknown Dell", STAC_9205_DELL_M42),
1295 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1296 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001297 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02001298 "Dell Precision", STAC_9205_DELL_M43),
1299 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
1300 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001301 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1302 "Dell Precision", STAC_9205_DELL_M43),
Matthew Ranostaye45e4592007-09-10 23:09:42 +02001303 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
1304 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001305 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1306 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001307 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1308 "unknown Dell", STAC_9205_DELL_M42),
1309 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1310 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001311 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1312 "Dell Precision", STAC_9205_DELL_M43),
1313 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001314 "Dell Precision M4300", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001315 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1316 "Dell Precision", STAC_9205_DELL_M43),
1317 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1318 "Dell Inspiron", STAC_9205_DELL_M44),
1319 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1320 "Dell Inspiron", STAC_9205_DELL_M44),
1321 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1322 "Dell Inspiron", STAC_9205_DELL_M44),
1323 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1324 "Dell Inspiron", STAC_9205_DELL_M44),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001325 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1326 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001327 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1328 "Dell Inspiron", STAC_9205_DELL_M44),
Matt Porterf3302a52006-07-31 12:49:34 +02001329 {} /* terminator */
1330};
1331
Richard Fish11b44bb2006-08-23 18:31:34 +02001332static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1333{
1334 int i;
1335 struct sigmatel_spec *spec = codec->spec;
1336
1337 if (! spec->bios_pin_configs) {
1338 spec->bios_pin_configs = kcalloc(spec->num_pins,
1339 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1340 if (! spec->bios_pin_configs)
1341 return -ENOMEM;
1342 }
1343
1344 for (i = 0; i < spec->num_pins; i++) {
1345 hda_nid_t nid = spec->pin_nids[i];
1346 unsigned int pin_cfg;
1347
1348 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1349 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1350 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1351 nid, pin_cfg);
1352 spec->bios_pin_configs[i] = pin_cfg;
1353 }
1354
1355 return 0;
1356}
1357
Matthew Ranostay87d48362007-07-17 11:52:24 +02001358static void stac92xx_set_config_reg(struct hda_codec *codec,
1359 hda_nid_t pin_nid, unsigned int pin_config)
1360{
1361 int i;
1362 snd_hda_codec_write(codec, pin_nid, 0,
1363 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1364 pin_config & 0x000000ff);
1365 snd_hda_codec_write(codec, pin_nid, 0,
1366 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1367 (pin_config & 0x0000ff00) >> 8);
1368 snd_hda_codec_write(codec, pin_nid, 0,
1369 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1370 (pin_config & 0x00ff0000) >> 16);
1371 snd_hda_codec_write(codec, pin_nid, 0,
1372 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1373 pin_config >> 24);
1374 i = snd_hda_codec_read(codec, pin_nid, 0,
1375 AC_VERB_GET_CONFIG_DEFAULT,
1376 0x00);
1377 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1378 pin_nid, i);
1379}
1380
Matt2f2f4252005-04-13 14:45:30 +02001381static void stac92xx_set_config_regs(struct hda_codec *codec)
1382{
1383 int i;
1384 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02001385
Matthew Ranostay87d48362007-07-17 11:52:24 +02001386 if (!spec->pin_configs)
1387 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02001388
Matthew Ranostay87d48362007-07-17 11:52:24 +02001389 for (i = 0; i < spec->num_pins; i++)
1390 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1391 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02001392}
Matt2f2f4252005-04-13 14:45:30 +02001393
Takashi Iwai82599802007-07-31 15:56:24 +02001394static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001395{
Takashi Iwai82599802007-07-31 15:56:24 +02001396 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +02001397 /* Configure GPIOx as output */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001398 snd_hda_codec_write_cache(codec, codec->afg, 0,
1399 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001400 /* Configure GPIOx as CMOS */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001401 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001402 /* Assert GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001403 snd_hda_codec_write_cache(codec, codec->afg, 0,
1404 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001405 /* Enable GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001406 snd_hda_codec_write_cache(codec, codec->afg, 0,
1407 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001408}
1409
Matt2f2f4252005-04-13 14:45:30 +02001410/*
1411 * Analog playback callbacks
1412 */
1413static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1414 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001415 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001416{
1417 struct sigmatel_spec *spec = codec->spec;
1418 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1419}
1420
1421static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1422 struct hda_codec *codec,
1423 unsigned int stream_tag,
1424 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001425 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001426{
1427 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01001428 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02001429}
1430
1431static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1432 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001433 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001434{
1435 struct sigmatel_spec *spec = codec->spec;
1436 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1437}
1438
1439/*
Mattdabbed62005-06-14 10:19:34 +02001440 * Digital playback callbacks
1441 */
1442static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1443 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001444 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001445{
1446 struct sigmatel_spec *spec = codec->spec;
1447 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1448}
1449
1450static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1451 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001452 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001453{
1454 struct sigmatel_spec *spec = codec->spec;
1455 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1456}
1457
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001458static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1459 struct hda_codec *codec,
1460 unsigned int stream_tag,
1461 unsigned int format,
1462 struct snd_pcm_substream *substream)
1463{
1464 struct sigmatel_spec *spec = codec->spec;
1465 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1466 stream_tag, format, substream);
1467}
1468
Mattdabbed62005-06-14 10:19:34 +02001469
1470/*
Matt2f2f4252005-04-13 14:45:30 +02001471 * Analog capture callbacks
1472 */
1473static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1474 struct hda_codec *codec,
1475 unsigned int stream_tag,
1476 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001477 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001478{
1479 struct sigmatel_spec *spec = codec->spec;
1480
1481 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1482 stream_tag, 0, format);
1483 return 0;
1484}
1485
1486static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1487 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001488 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001489{
1490 struct sigmatel_spec *spec = codec->spec;
1491
1492 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1493 return 0;
1494}
1495
Mattdabbed62005-06-14 10:19:34 +02001496static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1497 .substreams = 1,
1498 .channels_min = 2,
1499 .channels_max = 2,
1500 /* NID is set in stac92xx_build_pcms */
1501 .ops = {
1502 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001503 .close = stac92xx_dig_playback_pcm_close,
1504 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02001505 },
1506};
1507
1508static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1509 .substreams = 1,
1510 .channels_min = 2,
1511 .channels_max = 2,
1512 /* NID is set in stac92xx_build_pcms */
1513};
1514
Matt2f2f4252005-04-13 14:45:30 +02001515static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1516 .substreams = 1,
1517 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02001518 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02001519 .nid = 0x02, /* NID to query formats and rates */
1520 .ops = {
1521 .open = stac92xx_playback_pcm_open,
1522 .prepare = stac92xx_playback_pcm_prepare,
1523 .cleanup = stac92xx_playback_pcm_cleanup
1524 },
1525};
1526
Matt Porter3cc08dc2006-01-23 15:27:49 +01001527static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1528 .substreams = 1,
1529 .channels_min = 2,
1530 .channels_max = 2,
1531 .nid = 0x06, /* NID to query formats and rates */
1532 .ops = {
1533 .open = stac92xx_playback_pcm_open,
1534 .prepare = stac92xx_playback_pcm_prepare,
1535 .cleanup = stac92xx_playback_pcm_cleanup
1536 },
1537};
1538
Matt2f2f4252005-04-13 14:45:30 +02001539static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02001540 .channels_min = 2,
1541 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001542 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001543 .ops = {
1544 .prepare = stac92xx_capture_pcm_prepare,
1545 .cleanup = stac92xx_capture_pcm_cleanup
1546 },
1547};
1548
1549static int stac92xx_build_pcms(struct hda_codec *codec)
1550{
1551 struct sigmatel_spec *spec = codec->spec;
1552 struct hda_pcm *info = spec->pcm_rec;
1553
1554 codec->num_pcms = 1;
1555 codec->pcm_info = info;
1556
Mattc7d4b2f2005-06-27 14:59:41 +02001557 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001558 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001559 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001560 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001561 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001562
1563 if (spec->alt_switch) {
1564 codec->num_pcms++;
1565 info++;
1566 info->name = "STAC92xx Analog Alt";
1567 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1568 }
Matt2f2f4252005-04-13 14:45:30 +02001569
Mattdabbed62005-06-14 10:19:34 +02001570 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1571 codec->num_pcms++;
1572 info++;
1573 info->name = "STAC92xx Digital";
1574 if (spec->multiout.dig_out_nid) {
1575 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1576 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1577 }
1578 if (spec->dig_in_nid) {
1579 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1580 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1581 }
1582 }
1583
Matt2f2f4252005-04-13 14:45:30 +02001584 return 0;
1585}
1586
Takashi Iwaic960a032006-03-23 17:06:28 +01001587static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1588{
1589 unsigned int pincap = snd_hda_param_read(codec, nid,
1590 AC_PAR_PIN_CAP);
1591 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1592 if (pincap & AC_PINCAP_VREF_100)
1593 return AC_PINCTL_VREF_100;
1594 if (pincap & AC_PINCAP_VREF_80)
1595 return AC_PINCTL_VREF_80;
1596 if (pincap & AC_PINCAP_VREF_50)
1597 return AC_PINCTL_VREF_50;
1598 if (pincap & AC_PINCAP_VREF_GRD)
1599 return AC_PINCTL_VREF_GRD;
1600 return 0;
1601}
1602
Matt Porter403d1942005-11-29 15:00:51 +01001603static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1604
1605{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001606 snd_hda_codec_write_cache(codec, nid, 0,
1607 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01001608}
1609
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001610#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001611
1612static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1613{
1614 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1615 struct sigmatel_spec *spec = codec->spec;
1616 int io_idx = kcontrol-> private_value & 0xff;
1617
1618 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1619 return 0;
1620}
1621
1622static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1623{
1624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1625 struct sigmatel_spec *spec = codec->spec;
1626 hda_nid_t nid = kcontrol->private_value >> 8;
1627 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001628 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01001629
1630 spec->io_switch[io_idx] = val;
1631
1632 if (val)
1633 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001634 else {
1635 unsigned int pinctl = AC_PINCTL_IN_EN;
1636 if (io_idx) /* set VREF for mic */
1637 pinctl |= stac92xx_get_vref(codec, nid);
1638 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1639 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01001640
1641 /* check the auto-mute again: we need to mute/unmute the speaker
1642 * appropriately according to the pin direction
1643 */
1644 if (spec->hp_detect)
1645 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1646
Matt Porter403d1942005-11-29 15:00:51 +01001647 return 1;
1648}
1649
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001650#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
1651
1652static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
1653 struct snd_ctl_elem_value *ucontrol)
1654{
1655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1656 struct sigmatel_spec *spec = codec->spec;
1657
1658 ucontrol->value.integer.value[0] = spec->clfe_swap;
1659 return 0;
1660}
1661
1662static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1663 struct snd_ctl_elem_value *ucontrol)
1664{
1665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1666 struct sigmatel_spec *spec = codec->spec;
1667 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001668 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001669
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001670 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001671 return 0;
1672
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001673 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001674
1675 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1676 spec->clfe_swap ? 0x4 : 0x0);
1677
1678 return 1;
1679}
1680
Matt Porter403d1942005-11-29 15:00:51 +01001681#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1682 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1683 .name = xname, \
1684 .index = 0, \
1685 .info = stac92xx_io_switch_info, \
1686 .get = stac92xx_io_switch_get, \
1687 .put = stac92xx_io_switch_put, \
1688 .private_value = xpval, \
1689 }
1690
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001691#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
1692 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1693 .name = xname, \
1694 .index = 0, \
1695 .info = stac92xx_clfe_switch_info, \
1696 .get = stac92xx_clfe_switch_get, \
1697 .put = stac92xx_clfe_switch_put, \
1698 .private_value = xpval, \
1699 }
Matt Porter403d1942005-11-29 15:00:51 +01001700
Mattc7d4b2f2005-06-27 14:59:41 +02001701enum {
1702 STAC_CTL_WIDGET_VOL,
1703 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001704 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001705 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02001706};
1707
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001708static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001709 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1710 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001711 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001712 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001713};
1714
1715/* add dynamic controls */
1716static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1717{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001718 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001719
1720 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1721 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1722
1723 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1724 if (! knew)
1725 return -ENOMEM;
1726 if (spec->kctl_alloc) {
1727 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1728 kfree(spec->kctl_alloc);
1729 }
1730 spec->kctl_alloc = knew;
1731 spec->num_kctl_alloc = num;
1732 }
1733
1734 knew = &spec->kctl_alloc[spec->num_kctl_used];
1735 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001736 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001737 if (! knew->name)
1738 return -ENOMEM;
1739 knew->private_value = val;
1740 spec->num_kctl_used++;
1741 return 0;
1742}
1743
Matt Porter403d1942005-11-29 15:00:51 +01001744/* flag inputs as additional dynamic lineouts */
1745static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1746{
1747 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001748 unsigned int wcaps, wtype;
1749 int i, num_dacs = 0;
1750
1751 /* use the wcaps cache to count all DACs available for line-outs */
1752 for (i = 0; i < codec->num_nodes; i++) {
1753 wcaps = codec->wcaps[i];
1754 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1755 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1756 num_dacs++;
1757 }
Matt Porter403d1942005-11-29 15:00:51 +01001758
Steve Longerbeam7b043892007-05-03 20:50:03 +02001759 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1760
Matt Porter403d1942005-11-29 15:00:51 +01001761 switch (cfg->line_outs) {
1762 case 3:
1763 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001764 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001765 cfg->line_out_pins[cfg->line_outs] =
1766 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001767 spec->line_switch = 1;
1768 cfg->line_outs++;
1769 }
1770 break;
1771 case 2:
1772 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001773 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001774 cfg->line_out_pins[cfg->line_outs] =
1775 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001776 spec->line_switch = 1;
1777 cfg->line_outs++;
1778 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001779 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001780 cfg->line_out_pins[cfg->line_outs] =
1781 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001782 spec->mic_switch = 1;
1783 cfg->line_outs++;
1784 }
1785 break;
1786 case 1:
1787 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001788 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001789 cfg->line_out_pins[cfg->line_outs] =
1790 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001791 spec->line_switch = 1;
1792 cfg->line_outs++;
1793 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001794 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001795 cfg->line_out_pins[cfg->line_outs] =
1796 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001797 spec->mic_switch = 1;
1798 cfg->line_outs++;
1799 }
1800 break;
1801 }
1802
1803 return 0;
1804}
1805
Steve Longerbeam7b043892007-05-03 20:50:03 +02001806
1807static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1808{
1809 int i;
1810
1811 for (i = 0; i < spec->multiout.num_dacs; i++) {
1812 if (spec->multiout.dac_nids[i] == nid)
1813 return 1;
1814 }
1815
1816 return 0;
1817}
1818
Matt Porter3cc08dc2006-01-23 15:27:49 +01001819/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02001820 * Fill in the dac_nids table from the parsed pin configuration
1821 * This function only works when every pin in line_out_pins[]
1822 * contains atleast one DAC in its connection list. Some 92xx
1823 * codecs are not connected directly to a DAC, such as the 9200
1824 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001825 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001826static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02001827 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001828{
1829 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001830 int i, j, conn_len = 0;
1831 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1832 unsigned int wcaps, wtype;
1833
Mattc7d4b2f2005-06-27 14:59:41 +02001834 for (i = 0; i < cfg->line_outs; i++) {
1835 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02001836 conn_len = snd_hda_get_connections(codec, nid, conn,
1837 HDA_MAX_CONNECTIONS);
1838 for (j = 0; j < conn_len; j++) {
1839 wcaps = snd_hda_param_read(codec, conn[j],
1840 AC_PAR_AUDIO_WIDGET_CAP);
1841 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1842
1843 if (wtype != AC_WID_AUD_OUT ||
1844 (wcaps & AC_WCAP_DIGITAL))
1845 continue;
1846 /* conn[j] is a DAC routed to this line-out */
1847 if (!is_in_dac_nids(spec, conn[j]))
1848 break;
1849 }
1850
1851 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02001852 if (spec->multiout.num_dacs > 0) {
1853 /* we have already working output pins,
1854 * so let's drop the broken ones again
1855 */
1856 cfg->line_outs = spec->multiout.num_dacs;
1857 break;
1858 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001859 /* error out, no available DAC found */
1860 snd_printk(KERN_ERR
1861 "%s: No available DAC for pin 0x%x\n",
1862 __func__, nid);
1863 return -ENODEV;
1864 }
1865
1866 spec->multiout.dac_nids[i] = conn[j];
1867 spec->multiout.num_dacs++;
1868 if (conn_len > 1) {
1869 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001870 snd_hda_codec_write_cache(codec, nid, 0,
1871 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02001872
1873 }
Mattc7d4b2f2005-06-27 14:59:41 +02001874 }
1875
Steve Longerbeam7b043892007-05-03 20:50:03 +02001876 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1877 spec->multiout.num_dacs,
1878 spec->multiout.dac_nids[0],
1879 spec->multiout.dac_nids[1],
1880 spec->multiout.dac_nids[2],
1881 spec->multiout.dac_nids[3],
1882 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001883 return 0;
1884}
1885
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001886/* create volume control/switch for the given prefx type */
1887static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1888{
1889 char name[32];
1890 int err;
1891
1892 sprintf(name, "%s Playback Volume", pfx);
1893 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1894 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1895 if (err < 0)
1896 return err;
1897 sprintf(name, "%s Playback Switch", pfx);
1898 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1899 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1900 if (err < 0)
1901 return err;
1902 return 0;
1903}
1904
Mattc7d4b2f2005-06-27 14:59:41 +02001905/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001906static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001907 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001908{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001909 static const char *chname[4] = {
1910 "Front", "Surround", NULL /*CLFE*/, "Side"
1911 };
Mattc7d4b2f2005-06-27 14:59:41 +02001912 hda_nid_t nid;
1913 int i, err;
1914
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001915 struct sigmatel_spec *spec = codec->spec;
1916 unsigned int wid_caps;
1917
1918
Mattc7d4b2f2005-06-27 14:59:41 +02001919 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001920 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001921 continue;
1922
1923 nid = spec->multiout.dac_nids[i];
1924
1925 if (i == 2) {
1926 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001927 err = create_controls(spec, "Center", nid, 1);
1928 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001929 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001930 err = create_controls(spec, "LFE", nid, 2);
1931 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001932 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001933
1934 wid_caps = get_wcaps(codec, nid);
1935
1936 if (wid_caps & AC_WCAP_LR_SWAP) {
1937 err = stac92xx_add_control(spec,
1938 STAC_CTL_WIDGET_CLFE_SWITCH,
1939 "Swap Center/LFE Playback Switch", nid);
1940
1941 if (err < 0)
1942 return err;
1943 }
1944
Mattc7d4b2f2005-06-27 14:59:41 +02001945 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001946 err = create_controls(spec, chname[i], nid, 3);
1947 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001948 return err;
1949 }
1950 }
1951
Matt Porter403d1942005-11-29 15:00:51 +01001952 if (spec->line_switch)
1953 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1954 return err;
1955
1956 if (spec->mic_switch)
1957 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1958 return err;
1959
Mattc7d4b2f2005-06-27 14:59:41 +02001960 return 0;
1961}
1962
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001963static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1964{
Steve Longerbeam7b043892007-05-03 20:50:03 +02001965 if (is_in_dac_nids(spec, nid))
1966 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001967 if (spec->multiout.hp_nid == nid)
1968 return 1;
1969 return 0;
1970}
1971
1972static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1973{
1974 if (!spec->multiout.hp_nid)
1975 spec->multiout.hp_nid = nid;
1976 else if (spec->multiout.num_dacs > 4) {
1977 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1978 return 1;
1979 } else {
1980 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1981 spec->multiout.num_dacs++;
1982 }
1983 return 0;
1984}
1985
1986/* add playback controls for Speaker and HP outputs */
1987static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1988 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001989{
1990 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001991 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001992 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001993
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001994 old_num_dacs = spec->multiout.num_dacs;
1995 for (i = 0; i < cfg->hp_outs; i++) {
1996 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1997 if (wid_caps & AC_WCAP_UNSOL_CAP)
1998 spec->hp_detect = 1;
1999 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
2000 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2001 if (check_in_dac_nids(spec, nid))
2002 nid = 0;
2003 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02002004 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002005 add_spec_dacs(spec, nid);
2006 }
2007 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02002008 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002009 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2010 if (check_in_dac_nids(spec, nid))
2011 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002012 if (! nid)
2013 continue;
2014 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02002015 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02002016 for (i = 0; i < cfg->line_outs; i++) {
2017 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
2018 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2019 if (check_in_dac_nids(spec, nid))
2020 nid = 0;
2021 if (! nid)
2022 continue;
2023 add_spec_dacs(spec, nid);
2024 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002025 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
2026 static const char *pfxs[] = {
2027 "Speaker", "External Speaker", "Speaker2",
2028 };
2029 err = create_controls(spec, pfxs[i - old_num_dacs],
2030 spec->multiout.dac_nids[i], 3);
2031 if (err < 0)
2032 return err;
2033 }
2034 if (spec->multiout.hp_nid) {
2035 const char *pfx;
Takashi Iwai6020c002007-11-19 11:56:26 +01002036 if (old_num_dacs == spec->multiout.num_dacs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002037 pfx = "Master";
2038 else
2039 pfx = "Headphone";
2040 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
2041 if (err < 0)
2042 return err;
2043 }
Mattc7d4b2f2005-06-27 14:59:41 +02002044
2045 return 0;
2046}
2047
Matt Porter8b657272006-10-26 17:12:59 +02002048/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01002049static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02002050 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
2051 "Digital Mic 3", "Digital Mic 4"
2052};
2053
2054/* create playback/capture controls for input pins on dmic capable codecs */
2055static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
2056 const struct auto_pin_cfg *cfg)
2057{
2058 struct sigmatel_spec *spec = codec->spec;
2059 struct hda_input_mux *dimux = &spec->private_dimux;
2060 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
2061 int i, j;
2062
2063 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
2064 dimux->items[dimux->num_items].index = 0;
2065 dimux->num_items++;
2066
2067 for (i = 0; i < spec->num_dmics; i++) {
2068 int index;
2069 int num_cons;
2070 unsigned int def_conf;
2071
2072 def_conf = snd_hda_codec_read(codec,
2073 spec->dmic_nids[i],
2074 0,
2075 AC_VERB_GET_CONFIG_DEFAULT,
2076 0);
2077 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
2078 continue;
2079
2080 num_cons = snd_hda_get_connections(codec,
2081 spec->dmux_nid,
2082 con_lst,
2083 HDA_MAX_NUM_INPUTS);
2084 for (j = 0; j < num_cons; j++)
2085 if (con_lst[j] == spec->dmic_nids[i]) {
2086 index = j;
2087 goto found;
2088 }
2089 continue;
2090found:
2091 dimux->items[dimux->num_items].label =
2092 stac92xx_dmic_labels[dimux->num_items];
2093 dimux->items[dimux->num_items].index = index;
2094 dimux->num_items++;
2095 }
2096
2097 return 0;
2098}
2099
Mattc7d4b2f2005-06-27 14:59:41 +02002100/* create playback/capture controls for input pins */
2101static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
2102{
2103 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002104 struct hda_input_mux *imux = &spec->private_imux;
2105 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
2106 int i, j, k;
2107
2108 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002109 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02002110
Takashi Iwai314634b2006-09-21 11:56:18 +02002111 if (!cfg->input_pins[i])
2112 continue;
2113 index = -1;
2114 for (j = 0; j < spec->num_muxes; j++) {
2115 int num_cons;
2116 num_cons = snd_hda_get_connections(codec,
2117 spec->mux_nids[j],
2118 con_lst,
2119 HDA_MAX_NUM_INPUTS);
2120 for (k = 0; k < num_cons; k++)
2121 if (con_lst[k] == cfg->input_pins[i]) {
2122 index = k;
2123 goto found;
2124 }
Mattc7d4b2f2005-06-27 14:59:41 +02002125 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002126 continue;
2127 found:
2128 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2129 imux->items[imux->num_items].index = index;
2130 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02002131 }
2132
Steve Longerbeam7b043892007-05-03 20:50:03 +02002133 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02002134 /*
2135 * Set the current input for the muxes.
2136 * The STAC9221 has two input muxes with identical source
2137 * NID lists. Hopefully this won't get confused.
2138 */
2139 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002140 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
2141 AC_VERB_SET_CONNECT_SEL,
2142 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02002143 }
2144 }
2145
Mattc7d4b2f2005-06-27 14:59:41 +02002146 return 0;
2147}
2148
Mattc7d4b2f2005-06-27 14:59:41 +02002149static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
2150{
2151 struct sigmatel_spec *spec = codec->spec;
2152 int i;
2153
2154 for (i = 0; i < spec->autocfg.line_outs; i++) {
2155 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2156 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2157 }
2158}
2159
2160static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
2161{
2162 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002163 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002164
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002165 for (i = 0; i < spec->autocfg.hp_outs; i++) {
2166 hda_nid_t pin;
2167 pin = spec->autocfg.hp_pins[i];
2168 if (pin) /* connect to front */
2169 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
2170 }
2171 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
2172 hda_nid_t pin;
2173 pin = spec->autocfg.speaker_pins[i];
2174 if (pin) /* connect to front */
2175 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
2176 }
Mattc7d4b2f2005-06-27 14:59:41 +02002177}
2178
Matt Porter3cc08dc2006-01-23 15:27:49 +01002179static 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 +02002180{
2181 struct sigmatel_spec *spec = codec->spec;
2182 int err;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002183 int hp_speaker_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002184
Matt Porter8b657272006-10-26 17:12:59 +02002185 if ((err = snd_hda_parse_pin_def_config(codec,
2186 &spec->autocfg,
2187 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002188 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002189 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01002190 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002191
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002192 /* If we have no real line-out pin and multiple hp-outs, HPs should
2193 * be set up as multi-channel outputs.
2194 */
2195 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2196 spec->autocfg.hp_outs > 1) {
2197 /* Copy hp_outs to line_outs, backup line_outs in
2198 * speaker_outs so that the following routines can handle
2199 * HP pins as primary outputs.
2200 */
2201 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
2202 sizeof(spec->autocfg.line_out_pins));
2203 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
2204 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
2205 sizeof(spec->autocfg.hp_pins));
2206 spec->autocfg.line_outs = spec->autocfg.hp_outs;
2207 hp_speaker_swap = 1;
2208 }
2209
Matt Porter403d1942005-11-29 15:00:51 +01002210 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
2211 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002212 if (spec->multiout.num_dacs == 0)
2213 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2214 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02002215
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002216 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
2217
2218 if (err < 0)
2219 return err;
2220
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002221 if (hp_speaker_swap == 1) {
2222 /* Restore the hp_outs and line_outs */
2223 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
2224 sizeof(spec->autocfg.line_out_pins));
2225 spec->autocfg.hp_outs = spec->autocfg.line_outs;
2226 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
2227 sizeof(spec->autocfg.speaker_pins));
2228 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
2229 memset(spec->autocfg.speaker_pins, 0,
2230 sizeof(spec->autocfg.speaker_pins));
2231 spec->autocfg.speaker_outs = 0;
2232 }
2233
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002234 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
2235
2236 if (err < 0)
2237 return err;
2238
2239 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
2240
2241 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002242 return err;
2243
Matt Porter8b657272006-10-26 17:12:59 +02002244 if (spec->num_dmics > 0)
2245 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
2246 &spec->autocfg)) < 0)
2247 return err;
2248
Mattc7d4b2f2005-06-27 14:59:41 +02002249 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01002250 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02002251 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002252
Takashi Iwai82bc9552006-03-21 11:24:42 +01002253 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002254 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002255 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002256 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02002257
2258 if (spec->kctl_alloc)
2259 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2260
2261 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002262 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002263
2264 return 1;
2265}
2266
Takashi Iwai82bc9552006-03-21 11:24:42 +01002267/* add playback controls for HP output */
2268static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
2269 struct auto_pin_cfg *cfg)
2270{
2271 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002272 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01002273 unsigned int wid_caps;
2274
2275 if (! pin)
2276 return 0;
2277
2278 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02002279 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01002280 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002281
2282 return 0;
2283}
2284
Richard Fish160ea0d2006-09-06 13:58:25 +02002285/* add playback controls for LFE output */
2286static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2287 struct auto_pin_cfg *cfg)
2288{
2289 struct sigmatel_spec *spec = codec->spec;
2290 int err;
2291 hda_nid_t lfe_pin = 0x0;
2292 int i;
2293
2294 /*
2295 * search speaker outs and line outs for a mono speaker pin
2296 * with an amp. If one is found, add LFE controls
2297 * for it.
2298 */
2299 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2300 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2301 unsigned long wcaps = get_wcaps(codec, pin);
2302 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2303 if (wcaps == AC_WCAP_OUT_AMP)
2304 /* found a mono speaker with an amp, must be lfe */
2305 lfe_pin = pin;
2306 }
2307
2308 /* if speaker_outs is 0, then speakers may be in line_outs */
2309 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2310 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2311 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2312 unsigned long cfg;
2313 cfg = snd_hda_codec_read(codec, pin, 0,
2314 AC_VERB_GET_CONFIG_DEFAULT,
2315 0x00);
2316 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
2317 unsigned long wcaps = get_wcaps(codec, pin);
2318 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2319 if (wcaps == AC_WCAP_OUT_AMP)
2320 /* found a mono speaker with an amp,
2321 must be lfe */
2322 lfe_pin = pin;
2323 }
2324 }
2325 }
2326
2327 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002328 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02002329 if (err < 0)
2330 return err;
2331 }
2332
2333 return 0;
2334}
2335
Mattc7d4b2f2005-06-27 14:59:41 +02002336static int stac9200_parse_auto_config(struct hda_codec *codec)
2337{
2338 struct sigmatel_spec *spec = codec->spec;
2339 int err;
2340
Kailang Yangdf694da2005-12-05 19:42:22 +01002341 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002342 return err;
2343
2344 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
2345 return err;
2346
Takashi Iwai82bc9552006-03-21 11:24:42 +01002347 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2348 return err;
2349
Richard Fish160ea0d2006-09-06 13:58:25 +02002350 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2351 return err;
2352
Takashi Iwai82bc9552006-03-21 11:24:42 +01002353 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002354 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002355 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002356 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02002357
2358 if (spec->kctl_alloc)
2359 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2360
2361 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002362 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002363
2364 return 1;
2365}
2366
Sam Revitch62fe78e2006-05-10 15:09:17 +02002367/*
2368 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2369 * funky external mute control using GPIO pins.
2370 */
2371
2372static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
2373{
2374 unsigned int gpiostate, gpiomask, gpiodir;
2375
2376 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2377 AC_VERB_GET_GPIO_DATA, 0);
2378
2379 if (!muted)
2380 gpiostate |= (1 << pin);
2381 else
2382 gpiostate &= ~(1 << pin);
2383
2384 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2385 AC_VERB_GET_GPIO_MASK, 0);
2386 gpiomask |= (1 << pin);
2387
2388 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2389 AC_VERB_GET_GPIO_DIRECTION, 0);
2390 gpiodir |= (1 << pin);
2391
2392 /* AppleHDA seems to do this -- WTF is this verb?? */
2393 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2394
2395 snd_hda_codec_write(codec, codec->afg, 0,
2396 AC_VERB_SET_GPIO_MASK, gpiomask);
2397 snd_hda_codec_write(codec, codec->afg, 0,
2398 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
2399
2400 msleep(1);
2401
2402 snd_hda_codec_write(codec, codec->afg, 0,
2403 AC_VERB_SET_GPIO_DATA, gpiostate);
2404}
2405
Takashi Iwai314634b2006-09-21 11:56:18 +02002406static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2407 unsigned int event)
2408{
2409 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002410 snd_hda_codec_write_cache(codec, nid, 0,
2411 AC_VERB_SET_UNSOLICITED_ENABLE,
2412 (AC_USRSP_EN | event));
Takashi Iwai314634b2006-09-21 11:56:18 +02002413}
2414
Mattc7d4b2f2005-06-27 14:59:41 +02002415static int stac92xx_init(struct hda_codec *codec)
2416{
2417 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002418 struct auto_pin_cfg *cfg = &spec->autocfg;
2419 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002420
Mattc7d4b2f2005-06-27 14:59:41 +02002421 snd_hda_sequence_write(codec, spec->init);
2422
Takashi Iwai82bc9552006-03-21 11:24:42 +01002423 /* set up pins */
2424 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02002425 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002426 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02002427 enable_pin_detect(codec, cfg->hp_pins[i],
2428 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01002429 /* force to enable the first line-out; the others are set up
2430 * in unsol_event
2431 */
2432 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2433 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02002434 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002435 /* fake event to set up pins */
2436 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2437 } else {
2438 stac92xx_auto_init_multi_out(codec);
2439 stac92xx_auto_init_hp_out(codec);
2440 }
2441 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01002442 hda_nid_t nid = cfg->input_pins[i];
2443 if (nid) {
2444 unsigned int pinctl = AC_PINCTL_IN_EN;
2445 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
2446 pinctl |= stac92xx_get_vref(codec, nid);
2447 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2448 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01002449 }
Matt Porter8b657272006-10-26 17:12:59 +02002450 if (spec->num_dmics > 0)
2451 for (i = 0; i < spec->num_dmics; i++)
2452 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
2453 AC_PINCTL_IN_EN);
2454
Takashi Iwai82bc9552006-03-21 11:24:42 +01002455 if (cfg->dig_out_pin)
2456 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2457 AC_PINCTL_OUT_EN);
2458 if (cfg->dig_in_pin)
2459 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2460 AC_PINCTL_IN_EN);
2461
Sam Revitch62fe78e2006-05-10 15:09:17 +02002462 if (spec->gpio_mute) {
2463 stac922x_gpio_mute(codec, 0, 0);
2464 stac922x_gpio_mute(codec, 1, 0);
2465 }
2466
Mattc7d4b2f2005-06-27 14:59:41 +02002467 return 0;
2468}
2469
Matt2f2f4252005-04-13 14:45:30 +02002470static void stac92xx_free(struct hda_codec *codec)
2471{
Mattc7d4b2f2005-06-27 14:59:41 +02002472 struct sigmatel_spec *spec = codec->spec;
2473 int i;
2474
2475 if (! spec)
2476 return;
2477
2478 if (spec->kctl_alloc) {
2479 for (i = 0; i < spec->num_kctl_used; i++)
2480 kfree(spec->kctl_alloc[i].name);
2481 kfree(spec->kctl_alloc);
2482 }
2483
Richard Fish11b44bb2006-08-23 18:31:34 +02002484 if (spec->bios_pin_configs)
2485 kfree(spec->bios_pin_configs);
2486
Mattc7d4b2f2005-06-27 14:59:41 +02002487 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02002488}
2489
Matt4e550962005-07-04 17:51:39 +02002490static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
2491 unsigned int flag)
2492{
2493 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2494 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002495
Takashi Iwaif9acba42007-05-29 18:01:06 +02002496 if (pin_ctl & AC_PINCTL_IN_EN) {
2497 /*
2498 * we need to check the current set-up direction of
2499 * shared input pins since they can be switched via
2500 * "xxx as Output" mixer switch
2501 */
2502 struct sigmatel_spec *spec = codec->spec;
2503 struct auto_pin_cfg *cfg = &spec->autocfg;
2504 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
2505 spec->line_switch) ||
2506 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
2507 spec->mic_switch))
2508 return;
2509 }
2510
Steve Longerbeam7b043892007-05-03 20:50:03 +02002511 /* if setting pin direction bits, clear the current
2512 direction bits first */
2513 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
2514 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
2515
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002516 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002517 AC_VERB_SET_PIN_WIDGET_CONTROL,
2518 pin_ctl | flag);
2519}
2520
2521static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
2522 unsigned int flag)
2523{
2524 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2525 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002526 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002527 AC_VERB_SET_PIN_WIDGET_CONTROL,
2528 pin_ctl & ~flag);
2529}
2530
Jiang Zhe40c1d302007-11-12 13:05:16 +01002531static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02002532{
2533 if (!nid)
2534 return 0;
2535 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Jiang Zhe40c1d302007-11-12 13:05:16 +01002536 & (1 << 31)) {
2537 unsigned int pinctl;
2538 pinctl = snd_hda_codec_read(codec, nid, 0,
2539 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2540 if (pinctl & AC_PINCTL_IN_EN)
2541 return 0; /* mic- or line-input */
2542 else
2543 return 1; /* HP-output */
2544 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002545 return 0;
2546}
2547
2548static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02002549{
2550 struct sigmatel_spec *spec = codec->spec;
2551 struct auto_pin_cfg *cfg = &spec->autocfg;
2552 int i, presence;
2553
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002554 presence = 0;
2555 for (i = 0; i < cfg->hp_outs; i++) {
Jiang Zhe40c1d302007-11-12 13:05:16 +01002556 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
Takashi Iwai314634b2006-09-21 11:56:18 +02002557 if (presence)
2558 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002559 }
Matt4e550962005-07-04 17:51:39 +02002560
2561 if (presence) {
2562 /* disable lineouts, enable hp */
2563 for (i = 0; i < cfg->line_outs; i++)
2564 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
2565 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002566 for (i = 0; i < cfg->speaker_outs; i++)
2567 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
2568 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002569 } else {
2570 /* enable lineouts, disable hp */
2571 for (i = 0; i < cfg->line_outs; i++)
2572 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
2573 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002574 for (i = 0; i < cfg->speaker_outs; i++)
2575 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
2576 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002577 }
2578}
2579
Takashi Iwai314634b2006-09-21 11:56:18 +02002580static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
2581{
2582 switch (res >> 26) {
2583 case STAC_HP_EVENT:
2584 stac92xx_hp_detect(codec, res);
2585 break;
2586 }
2587}
2588
Takashi Iwaicb53c622007-08-10 17:21:45 +02002589#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002590static int stac92xx_resume(struct hda_codec *codec)
2591{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002592 struct sigmatel_spec *spec = codec->spec;
2593
Richard Fish11b44bb2006-08-23 18:31:34 +02002594 stac92xx_set_config_regs(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002595 snd_hda_sequence_write(codec, spec->init);
2596 if (spec->gpio_mute) {
2597 stac922x_gpio_mute(codec, 0, 0);
2598 stac922x_gpio_mute(codec, 1, 0);
2599 }
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002600 snd_hda_codec_resume_amp(codec);
2601 snd_hda_codec_resume_cache(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002602 /* invoke unsolicited event to reset the HP state */
2603 if (spec->hp_detect)
2604 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Mattff6fdc32005-06-27 15:06:52 +02002605 return 0;
2606}
2607#endif
2608
Matt2f2f4252005-04-13 14:45:30 +02002609static struct hda_codec_ops stac92xx_patch_ops = {
2610 .build_controls = stac92xx_build_controls,
2611 .build_pcms = stac92xx_build_pcms,
2612 .init = stac92xx_init,
2613 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02002614 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002615#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002616 .resume = stac92xx_resume,
2617#endif
Matt2f2f4252005-04-13 14:45:30 +02002618};
2619
2620static int patch_stac9200(struct hda_codec *codec)
2621{
2622 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002623 int err;
Matt2f2f4252005-04-13 14:45:30 +02002624
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002625 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002626 if (spec == NULL)
2627 return -ENOMEM;
2628
2629 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002630 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002631 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002632 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
2633 stac9200_models,
2634 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02002635 if (spec->board_config < 0) {
2636 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
2637 err = stac92xx_save_bios_config_regs(codec);
2638 if (err < 0) {
2639 stac92xx_free(codec);
2640 return err;
2641 }
2642 spec->pin_configs = spec->bios_pin_configs;
2643 } else {
Matt Porter403d1942005-11-29 15:00:51 +01002644 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
2645 stac92xx_set_config_regs(codec);
2646 }
Matt2f2f4252005-04-13 14:45:30 +02002647
2648 spec->multiout.max_channels = 2;
2649 spec->multiout.num_dacs = 1;
2650 spec->multiout.dac_nids = stac9200_dac_nids;
2651 spec->adc_nids = stac9200_adc_nids;
2652 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02002653 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02002654 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002655 spec->num_adcs = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002656
Takashi Iwai1194b5b2007-10-10 10:04:26 +02002657 if (spec->board_config == STAC_9200_GATEWAY)
2658 spec->init = stac9200_eapd_init;
2659 else
2660 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002661 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002662
2663 err = stac9200_parse_auto_config(codec);
2664 if (err < 0) {
2665 stac92xx_free(codec);
2666 return err;
2667 }
Matt2f2f4252005-04-13 14:45:30 +02002668
2669 codec->patch_ops = stac92xx_patch_ops;
2670
2671 return 0;
2672}
2673
Tobin Davis8e21c342007-01-08 11:04:17 +01002674static int patch_stac925x(struct hda_codec *codec)
2675{
2676 struct sigmatel_spec *spec;
2677 int err;
2678
2679 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2680 if (spec == NULL)
2681 return -ENOMEM;
2682
2683 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002684 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002685 spec->pin_nids = stac925x_pin_nids;
2686 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2687 stac925x_models,
2688 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002689 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002690 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002691 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2692 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002693 err = stac92xx_save_bios_config_regs(codec);
2694 if (err < 0) {
2695 stac92xx_free(codec);
2696 return err;
2697 }
2698 spec->pin_configs = spec->bios_pin_configs;
2699 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2700 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2701 stac92xx_set_config_regs(codec);
2702 }
2703
2704 spec->multiout.max_channels = 2;
2705 spec->multiout.num_dacs = 1;
2706 spec->multiout.dac_nids = stac925x_dac_nids;
2707 spec->adc_nids = stac925x_adc_nids;
2708 spec->mux_nids = stac925x_mux_nids;
2709 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002710 spec->num_adcs = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002711 switch (codec->vendor_id) {
2712 case 0x83847632: /* STAC9202 */
2713 case 0x83847633: /* STAC9202D */
2714 case 0x83847636: /* STAC9251 */
2715 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02002716 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02002717 spec->dmic_nids = stac925x_dmic_nids;
2718 break;
2719 default:
2720 spec->num_dmics = 0;
2721 break;
2722 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002723
2724 spec->init = stac925x_core_init;
2725 spec->mixer = stac925x_mixer;
2726
2727 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002728 if (!err) {
2729 if (spec->board_config < 0) {
2730 printk(KERN_WARNING "hda_codec: No auto-config is "
2731 "available, default to model=ref\n");
2732 spec->board_config = STAC_925x_REF;
2733 goto again;
2734 }
2735 err = -EINVAL;
2736 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002737 if (err < 0) {
2738 stac92xx_free(codec);
2739 return err;
2740 }
2741
2742 codec->patch_ops = stac92xx_patch_ops;
2743
2744 return 0;
2745}
2746
Matthew Ranostaye035b842007-11-06 11:53:55 +01002747static int patch_stac92hd71bxx(struct hda_codec *codec)
2748{
2749 struct sigmatel_spec *spec;
2750 int err = 0;
2751
2752 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2753 if (spec == NULL)
2754 return -ENOMEM;
2755
2756 codec->spec = spec;
2757 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
2758 spec->pin_nids = stac92hd71bxx_pin_nids;
2759 spec->board_config = snd_hda_check_board_config(codec,
2760 STAC_92HD71BXX_MODELS,
2761 stac92hd71bxx_models,
2762 stac92hd71bxx_cfg_tbl);
2763again:
2764 if (spec->board_config < 0) {
2765 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
2766 " STAC92HD71BXX, using BIOS defaults\n");
2767 err = stac92xx_save_bios_config_regs(codec);
2768 if (err < 0) {
2769 stac92xx_free(codec);
2770 return err;
2771 }
2772 spec->pin_configs = spec->bios_pin_configs;
2773 } else {
2774 spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config];
2775 stac92xx_set_config_regs(codec);
2776 }
2777
2778 spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */
2779 stac92xx_enable_gpio_mask(codec);
2780
2781 spec->init = stac92hd71bxx_core_init;
2782 spec->mixer = stac92hd71bxx_mixer;
2783
2784 spec->mux_nids = stac92hd71bxx_mux_nids;
2785 spec->adc_nids = stac92hd71bxx_adc_nids;
2786 spec->dmic_nids = stac92hd71bxx_dmic_nids;
2787 spec->dmux_nid = 0x1c;
2788
2789 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
2790 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
2791 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
2792
2793 spec->multiout.num_dacs = 2;
2794 spec->multiout.hp_nid = 0x11;
2795 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
2796
2797 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
2798 if (!err) {
2799 if (spec->board_config < 0) {
2800 printk(KERN_WARNING "hda_codec: No auto-config is "
2801 "available, default to model=ref\n");
2802 spec->board_config = STAC_92HD71BXX_REF;
2803 goto again;
2804 }
2805 err = -EINVAL;
2806 }
2807
2808 if (err < 0) {
2809 stac92xx_free(codec);
2810 return err;
2811 }
2812
2813 codec->patch_ops = stac92xx_patch_ops;
2814
2815 return 0;
2816};
2817
Matt2f2f4252005-04-13 14:45:30 +02002818static int patch_stac922x(struct hda_codec *codec)
2819{
2820 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002821 int err;
Matt2f2f4252005-04-13 14:45:30 +02002822
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002823 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002824 if (spec == NULL)
2825 return -ENOMEM;
2826
2827 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002828 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002829 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002830 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2831 stac922x_models,
2832 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002833 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002834 spec->gpio_mute = 1;
2835 /* Intel Macs have all same PCI SSID, so we need to check
2836 * codec SSID to distinguish the exact models
2837 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002838 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002839 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002840
2841 case 0x106b0800:
2842 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002843 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002844 case 0x106b0600:
2845 case 0x106b0700:
2846 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002847 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002848 case 0x106b0e00:
2849 case 0x106b0f00:
2850 case 0x106b1600:
2851 case 0x106b1700:
2852 case 0x106b0200:
2853 case 0x106b1e00:
2854 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002855 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002856 case 0x106b1a00:
2857 case 0x00000100:
2858 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002859 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002860 case 0x106b0a00:
2861 case 0x106b2200:
2862 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002863 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002864 }
2865 }
2866
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002867 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002868 if (spec->board_config < 0) {
2869 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2870 "using BIOS defaults\n");
2871 err = stac92xx_save_bios_config_regs(codec);
2872 if (err < 0) {
2873 stac92xx_free(codec);
2874 return err;
2875 }
2876 spec->pin_configs = spec->bios_pin_configs;
2877 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002878 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2879 stac92xx_set_config_regs(codec);
2880 }
Matt2f2f4252005-04-13 14:45:30 +02002881
Matt2f2f4252005-04-13 14:45:30 +02002882 spec->adc_nids = stac922x_adc_nids;
2883 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002884 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002885 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002886 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002887
2888 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002889 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002890
2891 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002892
Matt Porter3cc08dc2006-01-23 15:27:49 +01002893 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002894 if (!err) {
2895 if (spec->board_config < 0) {
2896 printk(KERN_WARNING "hda_codec: No auto-config is "
2897 "available, default to model=ref\n");
2898 spec->board_config = STAC_D945_REF;
2899 goto again;
2900 }
2901 err = -EINVAL;
2902 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002903 if (err < 0) {
2904 stac92xx_free(codec);
2905 return err;
2906 }
2907
2908 codec->patch_ops = stac92xx_patch_ops;
2909
Takashi Iwai807a46362007-05-29 19:01:37 +02002910 /* Fix Mux capture level; max to 2 */
2911 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2912 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2913 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2914 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2915 (0 << AC_AMPCAP_MUTE_SHIFT));
2916
Matt Porter3cc08dc2006-01-23 15:27:49 +01002917 return 0;
2918}
2919
2920static int patch_stac927x(struct hda_codec *codec)
2921{
2922 struct sigmatel_spec *spec;
2923 int err;
2924
2925 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2926 if (spec == NULL)
2927 return -ENOMEM;
2928
2929 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002930 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002931 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002932 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2933 stac927x_models,
2934 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002935 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002936 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002937 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002938 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 (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002945 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2946 stac92xx_set_config_regs(codec);
2947 }
2948
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002949 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002950 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002951 spec->adc_nids = stac927x_adc_nids;
2952 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002953 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002954 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis93ed1502006-09-01 21:03:12 +02002955 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002956 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002957 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002958 case STAC_D965_5ST:
2959 spec->adc_nids = stac927x_adc_nids;
2960 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002961 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002962 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis93ed1502006-09-01 21:03:12 +02002963 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002964 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002965 break;
2966 default:
2967 spec->adc_nids = stac927x_adc_nids;
2968 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002969 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002970 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002971 spec->init = stac927x_core_init;
2972 spec->mixer = stac927x_mixer;
2973 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002974
Matthew Ranostay7f168592007-10-18 17:38:17 +02002975 switch (codec->subsystem_id) {
Matthew Ranostayb222fe52007-11-07 15:54:45 +01002976 case 0x10280242: /* STAC 9228 */
2977 case 0x102801f3:
2978 case 0x1028020A:
2979 case 0x10280209:
Matthew Ranostay7f168592007-10-18 17:38:17 +02002980 spec->dmic_nids = stac927x_dmic_nids;
2981 spec->num_dmics = STAC927X_NUM_DMICS;
Matthew Ranostay83eef752007-10-22 12:27:10 +02002982 spec->dmux_nid = 0x1b;
Matthew Ranostayf1f208d2007-11-05 15:30:13 +01002983
2984 /* Enable DMIC0 */
2985 stac92xx_set_config_reg(codec, 0x13, 0x90a60040);
2986
2987 /* GPIO2 High = Enable EAPD */
2988 spec->gpio_mask = spec->gpio_data = 0x00000004;
Matthew Ranostay7f168592007-10-18 17:38:17 +02002989 break;
2990 default:
Matthew Ranostayf1f208d2007-11-05 15:30:13 +01002991 spec->num_dmics = 0;
2992
2993 /* GPIO0 High = Enable EAPD */
2994 spec->gpio_mask = spec->gpio_data = 0x00000001;
Matthew Ranostay7f168592007-10-18 17:38:17 +02002995 }
2996
Matt Porter3cc08dc2006-01-23 15:27:49 +01002997 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai82599802007-07-31 15:56:24 +02002998 stac92xx_enable_gpio_mask(codec);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02002999
Matt Porter3cc08dc2006-01-23 15:27:49 +01003000 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003001 if (!err) {
3002 if (spec->board_config < 0) {
3003 printk(KERN_WARNING "hda_codec: No auto-config is "
3004 "available, default to model=ref\n");
3005 spec->board_config = STAC_D965_REF;
3006 goto again;
3007 }
3008 err = -EINVAL;
3009 }
Mattc7d4b2f2005-06-27 14:59:41 +02003010 if (err < 0) {
3011 stac92xx_free(codec);
3012 return err;
3013 }
Matt2f2f4252005-04-13 14:45:30 +02003014
3015 codec->patch_ops = stac92xx_patch_ops;
3016
3017 return 0;
3018}
3019
Matt Porterf3302a52006-07-31 12:49:34 +02003020static int patch_stac9205(struct hda_codec *codec)
3021{
3022 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02003023 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02003024
3025 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3026 if (spec == NULL)
3027 return -ENOMEM;
3028
3029 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003030 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003031 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003032 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
3033 stac9205_models,
3034 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003035 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02003036 if (spec->board_config < 0) {
3037 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
3038 err = stac92xx_save_bios_config_regs(codec);
3039 if (err < 0) {
3040 stac92xx_free(codec);
3041 return err;
3042 }
3043 spec->pin_configs = spec->bios_pin_configs;
3044 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02003045 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
3046 stac92xx_set_config_regs(codec);
3047 }
3048
3049 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003050 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02003051 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01003052 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02003053 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02003054 spec->num_dmics = STAC9205_NUM_DMICS;
Matt Porter8b657272006-10-26 17:12:59 +02003055 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02003056
3057 spec->init = stac9205_core_init;
3058 spec->mixer = stac9205_mixer;
3059
3060 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02003061
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003062 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003063 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02003064 /* Enable SPDIF in/out */
3065 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
3066 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01003067
Takashi Iwai82599802007-07-31 15:56:24 +02003068 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
Matthew Ranostay87d48362007-07-17 11:52:24 +02003069 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
3070 * GPIO2 High = Headphone Mute
3071 */
Takashi Iwai82599802007-07-31 15:56:24 +02003072 spec->gpio_data = 0x00000005;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003073 break;
3074 default:
3075 /* GPIO0 High = EAPD */
3076 spec->gpio_mask = spec->gpio_data = 0x00000001;
3077 break;
3078 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02003079
Takashi Iwai82599802007-07-31 15:56:24 +02003080 stac92xx_enable_gpio_mask(codec);
Matt Porterf3302a52006-07-31 12:49:34 +02003081 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003082 if (!err) {
3083 if (spec->board_config < 0) {
3084 printk(KERN_WARNING "hda_codec: No auto-config is "
3085 "available, default to model=ref\n");
3086 spec->board_config = STAC_9205_REF;
3087 goto again;
3088 }
3089 err = -EINVAL;
3090 }
Matt Porterf3302a52006-07-31 12:49:34 +02003091 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
Matt2f2f4252005-04-13 14:45:30 +02003101/*
Guillaume Munch6d859062006-08-22 17:15:47 +02003102 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01003103 */
3104
Guillaume Munch99ccc562006-08-16 19:35:12 +02003105/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003106static hda_nid_t vaio_dacs[] = { 0x2 };
3107#define VAIO_HP_DAC 0x5
3108static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
3109static hda_nid_t vaio_mux_nids[] = { 0x15 };
3110
3111static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02003112 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01003113 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02003114 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003115 { "Mic Jack", 0x1 },
3116 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01003117 { "PCM", 0x3 },
3118 }
3119};
3120
3121static struct hda_verb vaio_init[] = {
3122 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003123 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01003124 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3125 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3126 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3127 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003128 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003129 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3130 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3131 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3132 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3133 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3134 {}
3135};
3136
Guillaume Munch6d859062006-08-22 17:15:47 +02003137static struct hda_verb vaio_ar_init[] = {
3138 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
3139 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3140 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3141 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3142/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
3143 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003144 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02003145 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3146 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3147/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
3148 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3149 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3150 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3151 {}
3152};
3153
Takashi Iwaidb064e52006-03-16 16:04:58 +01003154/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003155static struct hda_bind_ctls vaio_bind_master_vol = {
3156 .ops = &snd_hda_bind_vol,
3157 .values = {
3158 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3159 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3160 0
3161 },
3162};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003163
3164/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003165static struct hda_bind_ctls vaio_bind_master_sw = {
3166 .ops = &snd_hda_bind_sw,
3167 .values = {
3168 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3169 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3170 0,
3171 },
3172};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003173
3174static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003175 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3176 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003177 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3178 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3179 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3180 {
3181 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3182 .name = "Capture Source",
3183 .count = 1,
3184 .info = stac92xx_mux_enum_info,
3185 .get = stac92xx_mux_enum_get,
3186 .put = stac92xx_mux_enum_put,
3187 },
3188 {}
3189};
3190
Guillaume Munch6d859062006-08-22 17:15:47 +02003191static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003192 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3193 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Guillaume Munch6d859062006-08-22 17:15:47 +02003194 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3195 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3196 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3197 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
3198 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
3199 {
3200 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3201 .name = "Capture Source",
3202 .count = 1,
3203 .info = stac92xx_mux_enum_info,
3204 .get = stac92xx_mux_enum_get,
3205 .put = stac92xx_mux_enum_put,
3206 },
3207 {}
3208};
3209
3210static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01003211 .build_controls = stac92xx_build_controls,
3212 .build_pcms = stac92xx_build_pcms,
3213 .init = stac92xx_init,
3214 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02003215#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01003216 .resume = stac92xx_resume,
3217#endif
3218};
3219
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003220static int stac9872_vaio_init(struct hda_codec *codec)
3221{
3222 int err;
3223
3224 err = stac92xx_init(codec);
3225 if (err < 0)
3226 return err;
3227 if (codec->patch_ops.unsol_event)
3228 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
3229 return 0;
3230}
3231
3232static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
3233{
Jiang Zhe40c1d302007-11-12 13:05:16 +01003234 if (get_hp_pin_presence(codec, 0x0a)) {
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003235 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3236 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3237 } else {
3238 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3239 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3240 }
3241}
3242
3243static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
3244{
3245 switch (res >> 26) {
3246 case STAC_HP_EVENT:
3247 stac9872_vaio_hp_detect(codec, res);
3248 break;
3249 }
3250}
3251
3252static struct hda_codec_ops stac9872_vaio_patch_ops = {
3253 .build_controls = stac92xx_build_controls,
3254 .build_pcms = stac92xx_build_pcms,
3255 .init = stac9872_vaio_init,
3256 .free = stac92xx_free,
3257 .unsol_event = stac9872_vaio_unsol_event,
3258#ifdef CONFIG_PM
3259 .resume = stac92xx_resume,
3260#endif
3261};
3262
Guillaume Munch6d859062006-08-22 17:15:47 +02003263enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
3264 CXD9872RD_VAIO,
3265 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
3266 STAC9872AK_VAIO,
3267 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
3268 STAC9872K_VAIO,
3269 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003270 CXD9872AKD_VAIO,
3271 STAC_9872_MODELS,
3272};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003273
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003274static const char *stac9872_models[STAC_9872_MODELS] = {
3275 [CXD9872RD_VAIO] = "vaio",
3276 [CXD9872AKD_VAIO] = "vaio-ar",
3277};
3278
3279static struct snd_pci_quirk stac9872_cfg_tbl[] = {
3280 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
3281 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
3282 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01003283 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003284 {}
3285};
3286
Guillaume Munch6d859062006-08-22 17:15:47 +02003287static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01003288{
3289 struct sigmatel_spec *spec;
3290 int board_config;
3291
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003292 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
3293 stac9872_models,
3294 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01003295 if (board_config < 0)
3296 /* unknown config, let generic-parser do its job... */
3297 return snd_hda_parse_generic_codec(codec);
3298
3299 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3300 if (spec == NULL)
3301 return -ENOMEM;
3302
3303 codec->spec = spec;
3304 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02003305 case CXD9872RD_VAIO:
3306 case STAC9872AK_VAIO:
3307 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01003308 spec->mixer = vaio_mixer;
3309 spec->init = vaio_init;
3310 spec->multiout.max_channels = 2;
3311 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3312 spec->multiout.dac_nids = vaio_dacs;
3313 spec->multiout.hp_nid = VAIO_HP_DAC;
3314 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3315 spec->adc_nids = vaio_adcs;
3316 spec->input_mux = &vaio_mux;
3317 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003318 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003319 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02003320
3321 case CXD9872AKD_VAIO:
3322 spec->mixer = vaio_ar_mixer;
3323 spec->init = vaio_ar_init;
3324 spec->multiout.max_channels = 2;
3325 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3326 spec->multiout.dac_nids = vaio_dacs;
3327 spec->multiout.hp_nid = VAIO_HP_DAC;
3328 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3329 spec->adc_nids = vaio_adcs;
3330 spec->input_mux = &vaio_mux;
3331 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003332 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02003333 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003334 }
3335
Takashi Iwaidb064e52006-03-16 16:04:58 +01003336 return 0;
3337}
3338
3339
3340/*
Matt2f2f4252005-04-13 14:45:30 +02003341 * patch entries
3342 */
3343struct hda_codec_preset snd_hda_preset_sigmatel[] = {
3344 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
3345 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
3346 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
3347 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
3348 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
3349 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
3350 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02003351 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
3352 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
3353 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
3354 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
3355 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
3356 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01003357 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
3358 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
3359 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
3360 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
3361 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
3362 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
3363 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
3364 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
3365 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
3366 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01003367 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
3368 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
3369 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
3370 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
3371 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
3372 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02003373 /* The following does not take into account .id=0x83847661 when subsys =
3374 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
3375 * currently not fully supported.
3376 */
3377 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
3378 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
3379 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02003380 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
3381 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
3382 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
3383 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
3384 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
3385 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
3386 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
3387 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostaye035b842007-11-06 11:53:55 +01003388 { .id = 0x111d76b0, .name = "92HD71BXX", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02003389 {} /* terminator */
3390};