blob: c4447b160a5a1bfbd1ae7a34a4527f8f03fff89e [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;
352
353 if (spec->aloopback == ucontrol->value.integer.value[0])
354 return 0;
355
356 spec->aloopback = ucontrol->value.integer.value[0];
357
358
359 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
360 kcontrol->private_value & 0xFFFF, 0x0);
361
362 if (spec->aloopback) {
363 snd_hda_power_up(codec);
364 dac_mode |= 0x40;
365 } else {
366 snd_hda_power_down(codec);
367 dac_mode &= ~0x40;
368 }
369
370 snd_hda_codec_write_cache(codec, codec->afg, 0,
371 kcontrol->private_value >> 16, dac_mode);
372
373 return 1;
374}
375
Mattc7d4b2f2005-06-27 14:59:41 +0200376static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200377 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200378 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200379 {}
380};
381
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200382static struct hda_verb stac9200_eapd_init[] = {
383 /* set dac0mux for dac converter */
384 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
385 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
386 {}
387};
388
Matthew Ranostaye035b842007-11-06 11:53:55 +0100389static struct hda_verb stac92hd71bxx_core_init[] = {
390 /* set master volume and direct control */
391 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
392 /* connect headphone jack to dac1 */
393 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay9b359472007-11-07 13:03:12 +0100394 /* connect ports 0d and 0f to audio mixer */
395 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2},
396 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
397 /* unmute dac0 input in audio mixer */
398 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100399 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
400 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
401 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
402 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
403 /* unmute mono out node */
404 { 0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
405 {}
406};
407
Tobin Davis8e21c342007-01-08 11:04:17 +0100408static struct hda_verb stac925x_core_init[] = {
409 /* set dac0mux for dac converter */
410 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
411 {}
412};
413
Mattc7d4b2f2005-06-27 14:59:41 +0200414static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200415 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200416 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200417 {}
418};
419
Tobin Davis93ed1502006-09-01 21:03:12 +0200420static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200421 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200422 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200423 /* unmute node 0x1b */
424 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
425 /* select node 0x03 as DAC */
426 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
427 {}
428};
429
Matt Porter3cc08dc2006-01-23 15:27:49 +0100430static struct hda_verb stac927x_core_init[] = {
431 /* set master volume and direct control */
432 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
433 {}
434};
435
Matt Porterf3302a52006-07-31 12:49:34 +0200436static struct hda_verb stac9205_core_init[] = {
437 /* set master volume and direct control */
438 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
439 {}
440};
441
Matthew Ranostay47744f62007-10-19 08:19:56 +0200442#define STAC_DIGITAL_INPUT_SOURCE(cnt) \
443 { \
444 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
445 .name = "Digital Input Source", \
446 .count = cnt, \
447 .info = stac92xx_dmux_enum_info, \
448 .get = stac92xx_dmux_enum_get, \
449 .put = stac92xx_dmux_enum_put,\
450 }
451
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200452#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200453 { \
454 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
455 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200456 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200457 .info = stac92xx_mux_enum_info, \
458 .get = stac92xx_mux_enum_get, \
459 .put = stac92xx_mux_enum_put, \
460 }
461
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200462#define STAC_ANALOG_LOOPBACK(verb_read,verb_write) \
463 { \
464 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
465 .name = "Analog Loopback", \
466 .count = 1, \
467 .info = stac92xx_aloopback_info, \
468 .get = stac92xx_aloopback_get, \
469 .put = stac92xx_aloopback_put, \
470 .private_value = verb_read | (verb_write << 16), \
471 }
472
Matthew Ranostay9b359472007-11-07 13:03:12 +0100473#define STAC_VOLKNOB(knob_nid) \
474 { \
475 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
476 .name = "Master Playback Volume", \
477 .count = 1, \
478 .info = stac92xx_volknob_info, \
479 .get = stac92xx_volknob_get, \
480 .put = stac92xx_volknob_put, \
481 .private_value = 127 | (knob_nid << 16), \
482 }
483
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100484static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200485 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
486 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200487 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200488 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
489 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200490 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200491 { } /* end */
492};
493
Matthew Ranostaye035b842007-11-06 11:53:55 +0100494static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
495 STAC_DIGITAL_INPUT_SOURCE(1),
496 STAC_INPUT_SOURCE(2),
497 STAC_VOLKNOB(0x28),
498
499 /* hardware gain controls */
Matthew Ranostay9b359472007-11-07 13:03:12 +0100500 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x0, 0x18, 0x0, HDA_OUTPUT),
501 HDA_CODEC_VOLUME_IDX("Digital Mic Volume", 0x1, 0x19, 0x0, HDA_OUTPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100502
Matthew Ranostay9b359472007-11-07 13:03:12 +0100503 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
504 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
505 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
506
507 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
508 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
509 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
510
511 HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT),
512 HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100513 { } /* end */
514};
515
Tobin Davis8e21c342007-01-08 11:04:17 +0100516static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200517 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +0100518 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
519 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
520 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
521 { } /* end */
522};
523
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100524static struct snd_kcontrol_new stac9205_mixer[] = {
Matthew Ranostay47744f62007-10-19 08:19:56 +0200525 STAC_DIGITAL_INPUT_SOURCE(1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200526 STAC_INPUT_SOURCE(2),
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200527 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200528
529 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
530 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
531 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
532
533 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
534 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
535 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
536
537 { } /* end */
538};
539
540/* This needs to be generated dynamically based on sequence */
541static struct snd_kcontrol_new stac922x_mixer[] = {
542 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200543 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
544 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
545 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
546
547 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
548 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
549 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
550 { } /* end */
551};
552
553
554static struct snd_kcontrol_new stac927x_mixer[] = {
Matthew Ranostay47744f62007-10-19 08:19:56 +0200555 STAC_DIGITAL_INPUT_SOURCE(1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200556 STAC_INPUT_SOURCE(3),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200557 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB),
558
559 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
560 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
561 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
562
563 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
564 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
565 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
566
567 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
568 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
569 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +0200570 { } /* end */
571};
572
Matt2f2f4252005-04-13 14:45:30 +0200573static int stac92xx_build_controls(struct hda_codec *codec)
574{
575 struct sigmatel_spec *spec = codec->spec;
576 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200577 int i;
Matt2f2f4252005-04-13 14:45:30 +0200578
579 err = snd_hda_add_new_ctls(codec, spec->mixer);
580 if (err < 0)
581 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200582
583 for (i = 0; i < spec->num_mixers; i++) {
584 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
585 if (err < 0)
586 return err;
587 }
588
Mattdabbed62005-06-14 10:19:34 +0200589 if (spec->multiout.dig_out_nid) {
590 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
591 if (err < 0)
592 return err;
593 }
594 if (spec->dig_in_nid) {
595 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
596 if (err < 0)
597 return err;
598 }
599 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200600}
601
Matt Porter403d1942005-11-29 15:00:51 +0100602static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200603 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200604 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
605};
606
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200607/*
608 STAC 9200 pin configs for
609 102801A8
610 102801DE
611 102801E8
612*/
613static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200614 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
615 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200616};
617
618/*
619 STAC 9200 pin configs for
620 102801C0
621 102801C1
622*/
623static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200624 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
625 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200626};
627
628/*
629 STAC 9200 pin configs for
630 102801C4 (Dell Dimension E310)
631 102801C5
632 102801C7
633 102801D9
634 102801DA
635 102801E3
636*/
637static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200638 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
639 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200640};
641
642
643/*
644 STAC 9200-32 pin configs for
645 102801B5 (Dell Inspiron 630m)
646 102801D8 (Dell Inspiron 640m)
647*/
648static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200649 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
650 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200651};
652
653/*
654 STAC 9200-32 pin configs for
655 102801C2 (Dell Latitude D620)
656 102801C8
657 102801CC (Dell Latitude D820)
658 102801D4
659 102801D6
660*/
661static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200662 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
663 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200664};
665
666/*
667 STAC 9200-32 pin configs for
668 102801CE (Dell XPS M1710)
669 102801CF (Dell Precision M90)
670*/
671static unsigned int dell9200_m23_pin_configs[8] = {
672 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
673 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
674};
675
676/*
677 STAC 9200-32 pin configs for
678 102801C9
679 102801CA
680 102801CB (Dell Latitude 120L)
681 102801D3
682*/
683static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200684 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
685 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200686};
687
688/*
689 STAC 9200-32 pin configs for
690 102801BD (Dell Inspiron E1505n)
691 102801EE
692 102801EF
693*/
694static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200695 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
696 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200697};
698
699/*
700 STAC 9200-32 pin configs for
701 102801F5 (Dell Inspiron 1501)
702 102801F6
703*/
704static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200705 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
706 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200707};
708
709/*
710 STAC 9200-32
711 102801CD (Dell Inspiron E1705/9400)
712*/
713static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200714 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
715 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200716};
717
718
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100719static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
720 [STAC_REF] = ref9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200721 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
722 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
723 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
724 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
725 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
726 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
727 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
728 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
729 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
730 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +0100731};
732
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100733static const char *stac9200_models[STAC_9200_MODELS] = {
734 [STAC_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200735 [STAC_9200_DELL_D21] = "dell-d21",
736 [STAC_9200_DELL_D22] = "dell-d22",
737 [STAC_9200_DELL_D23] = "dell-d23",
738 [STAC_9200_DELL_M21] = "dell-m21",
739 [STAC_9200_DELL_M22] = "dell-m22",
740 [STAC_9200_DELL_M23] = "dell-m23",
741 [STAC_9200_DELL_M24] = "dell-m24",
742 [STAC_9200_DELL_M25] = "dell-m25",
743 [STAC_9200_DELL_M26] = "dell-m26",
744 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200745 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100746};
747
748static struct snd_pci_quirk stac9200_cfg_tbl[] = {
749 /* SigmaTel reference board */
750 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
751 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +0100752 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200753 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
754 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100755 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200756 "Dell Inspiron 630m", STAC_9200_DELL_M21),
757 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
758 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
759 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
760 "unknown Dell", STAC_9200_DELL_D22),
761 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
762 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100763 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200764 "Dell Latitude D620", STAC_9200_DELL_M22),
765 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
766 "unknown Dell", STAC_9200_DELL_D23),
767 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
768 "unknown Dell", STAC_9200_DELL_D23),
769 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
770 "unknown Dell", STAC_9200_DELL_M22),
771 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
772 "unknown Dell", STAC_9200_DELL_M24),
773 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
774 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100775 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200776 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +0100777 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200778 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100779 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200780 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +0100781 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200782 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +0100783 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200784 "Dell Precision M90", STAC_9200_DELL_M23),
785 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
786 "unknown Dell", STAC_9200_DELL_M22),
787 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
788 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +0200789 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200790 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +0200791 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200792 "Dell Inspiron 640m", STAC_9200_DELL_M21),
793 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
794 "unknown Dell", STAC_9200_DELL_D23),
795 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
796 "unknown Dell", STAC_9200_DELL_D23),
797 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
798 "unknown Dell", STAC_9200_DELL_D21),
799 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
800 "unknown Dell", STAC_9200_DELL_D23),
801 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
802 "unknown Dell", STAC_9200_DELL_D21),
803 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
804 "unknown Dell", STAC_9200_DELL_M25),
805 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
806 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +0200807 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200808 "Dell Inspiron 1501", STAC_9200_DELL_M26),
809 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
810 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +0200811 /* Panasonic */
812 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200813 /* Gateway machines needs EAPD to be set on resume */
814 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
815 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
816 STAC_9200_GATEWAY),
817 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
818 STAC_9200_GATEWAY),
Matt Porter403d1942005-11-29 15:00:51 +0100819 {} /* terminator */
820};
821
Tobin Davis8e21c342007-01-08 11:04:17 +0100822static unsigned int ref925x_pin_configs[8] = {
823 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
824 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
825};
826
827static unsigned int stac925x_MA6_pin_configs[8] = {
828 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
829 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
830};
831
Tobin Davis2c11f952007-05-17 09:36:34 +0200832static unsigned int stac925x_PA6_pin_configs[8] = {
833 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
834 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
835};
836
Tobin Davis8e21c342007-01-08 11:04:17 +0100837static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +0200838 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
839 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +0100840};
841
842static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
843 [STAC_REF] = ref925x_pin_configs,
844 [STAC_M2_2] = stac925xM2_2_pin_configs,
845 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +0200846 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +0100847};
848
849static const char *stac925x_models[STAC_925x_MODELS] = {
850 [STAC_REF] = "ref",
851 [STAC_M2_2] = "m2-2",
852 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +0200853 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +0100854};
855
856static struct snd_pci_quirk stac925x_cfg_tbl[] = {
857 /* SigmaTel reference board */
858 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +0200859 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +0100860 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
861 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
862 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +0200863 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +0100864 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
865 {} /* terminator */
866};
867
Matthew Ranostaye035b842007-11-06 11:53:55 +0100868static unsigned int ref92hd71bxx_pin_configs[10] = {
869 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
870 0x0181302e, 0x01114010, 0x01a19020, 0x90a000f0,
871 0x90a000f0, 0x01452050,
872};
873
874static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
875 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
876};
877
878static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
879 [STAC_92HD71BXX_REF] = "ref",
880};
881
882static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
883 /* SigmaTel reference board */
884 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
885 "DFI LanParty", STAC_92HD71BXX_REF),
886 {} /* terminator */
887};
888
Matt Porter403d1942005-11-29 15:00:51 +0100889static unsigned int ref922x_pin_configs[10] = {
890 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
891 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +0200892 0x40000100, 0x40000100,
893};
894
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200895/*
896 STAC 922X pin configs for
897 102801A7
898 102801AB
899 102801A9
900 102801D1
901 102801D2
902*/
903static unsigned int dell_922x_d81_pin_configs[10] = {
904 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
905 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
906 0x01813122, 0x400001f2,
907};
908
909/*
910 STAC 922X pin configs for
911 102801AC
912 102801D0
913*/
914static unsigned int dell_922x_d82_pin_configs[10] = {
915 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
916 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
917 0x01813122, 0x400001f1,
918};
919
920/*
921 STAC 922X pin configs for
922 102801BF
923*/
924static unsigned int dell_922x_m81_pin_configs[10] = {
925 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
926 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
927 0x40C003f1, 0x405003f0,
928};
929
930/*
931 STAC 9221 A1 pin configs for
932 102801D7 (Dell XPS M1210)
933*/
934static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +0100935 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
936 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200937 0x508003f3, 0x405003f4,
938};
939
Matt Porter403d1942005-11-29 15:00:51 +0100940static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100941 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +0100942 0x40000100, 0x40000100, 0x40000100, 0x40000100,
943 0x02a19120, 0x40000100,
944};
945
946static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +0100947 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
948 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +0100949 0x02a19320, 0x40000100,
950};
951
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200952static unsigned int intel_mac_v1_pin_configs[10] = {
953 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
954 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100955 0x400000fc, 0x400000fb,
956};
957
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200958static unsigned int intel_mac_v2_pin_configs[10] = {
959 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
960 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200961 0x400000fc, 0x400000fb,
962};
963
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200964static unsigned int intel_mac_v3_pin_configs[10] = {
965 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
966 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
967 0x400000fc, 0x400000fb,
968};
969
970static unsigned int intel_mac_v4_pin_configs[10] = {
971 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
972 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
973 0x400000fc, 0x400000fb,
974};
975
976static unsigned int intel_mac_v5_pin_configs[10] = {
977 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
978 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
979 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200980};
981
Takashi Iwai76c08822007-06-19 12:17:42 +0200982
Takashi Iwai19039bd2006-06-28 15:52:16 +0200983static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100984 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +0200985 [STAC_D945GTP3] = d945gtp3_pin_configs,
986 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200987 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
988 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
989 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
990 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
991 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200992 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200993 [STAC_MACMINI] = intel_mac_v3_pin_configs,
994 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
995 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
996 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
997 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
998 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200999 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1000 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1001 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1002 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001003};
1004
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001005static const char *stac922x_models[STAC_922X_MODELS] = {
1006 [STAC_D945_REF] = "ref",
1007 [STAC_D945GTP5] = "5stack",
1008 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001009 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1010 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1011 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1012 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1013 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001014 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001015 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001016 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001017 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1018 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001019 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001020 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001021 [STAC_922X_DELL_D81] = "dell-d81",
1022 [STAC_922X_DELL_D82] = "dell-d82",
1023 [STAC_922X_DELL_M81] = "dell-m81",
1024 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001025};
1026
1027static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1028 /* SigmaTel reference board */
1029 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1030 "DFI LanParty", STAC_D945_REF),
1031 /* Intel 945G based systems */
1032 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1033 "Intel D945G", STAC_D945GTP3),
1034 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1035 "Intel D945G", STAC_D945GTP3),
1036 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1037 "Intel D945G", STAC_D945GTP3),
1038 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1039 "Intel D945G", STAC_D945GTP3),
1040 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1041 "Intel D945G", STAC_D945GTP3),
1042 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1043 "Intel D945G", STAC_D945GTP3),
1044 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1045 "Intel D945G", STAC_D945GTP3),
1046 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1047 "Intel D945G", STAC_D945GTP3),
1048 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1049 "Intel D945G", STAC_D945GTP3),
1050 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1051 "Intel D945G", STAC_D945GTP3),
1052 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1053 "Intel D945G", STAC_D945GTP3),
1054 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1055 "Intel D945G", STAC_D945GTP3),
1056 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1057 "Intel D945G", STAC_D945GTP3),
1058 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1059 "Intel D945G", STAC_D945GTP3),
1060 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1061 "Intel D945G", STAC_D945GTP3),
1062 /* Intel D945G 5-stack systems */
1063 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1064 "Intel D945G", STAC_D945GTP5),
1065 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1066 "Intel D945G", STAC_D945GTP5),
1067 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1068 "Intel D945G", STAC_D945GTP5),
1069 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1070 "Intel D945G", STAC_D945GTP5),
1071 /* Intel 945P based systems */
1072 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1073 "Intel D945P", STAC_D945GTP3),
1074 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1075 "Intel D945P", STAC_D945GTP3),
1076 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1077 "Intel D945P", STAC_D945GTP3),
1078 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1079 "Intel D945P", STAC_D945GTP3),
1080 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1081 "Intel D945P", STAC_D945GTP3),
1082 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1083 "Intel D945P", STAC_D945GTP5),
1084 /* other systems */
1085 /* Apple Mac Mini (early 2006) */
1086 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001087 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001088 /* Dell systems */
1089 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1090 "unknown Dell", STAC_922X_DELL_D81),
1091 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1092 "unknown Dell", STAC_922X_DELL_D81),
1093 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1094 "unknown Dell", STAC_922X_DELL_D81),
1095 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1096 "unknown Dell", STAC_922X_DELL_D82),
1097 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1098 "unknown Dell", STAC_922X_DELL_M81),
1099 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1100 "unknown Dell", STAC_922X_DELL_D82),
1101 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1102 "unknown Dell", STAC_922X_DELL_D81),
1103 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1104 "unknown Dell", STAC_922X_DELL_D81),
1105 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1106 "Dell XPS M1210", STAC_922X_DELL_M82),
Matt Porter403d1942005-11-29 15:00:51 +01001107 {} /* terminator */
1108};
1109
Matt Porter3cc08dc2006-01-23 15:27:49 +01001110static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001111 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1112 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1113 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1114 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001115};
1116
Tobin Davis93ed1502006-09-01 21:03:12 +02001117static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001118 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1119 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1120 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1121 0x40000100, 0x40000100
1122};
1123
Tobin Davis93ed1502006-09-01 21:03:12 +02001124static unsigned int d965_5st_pin_configs[14] = {
1125 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1126 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1127 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1128 0x40000100, 0x40000100
1129};
1130
Tobin Davis4ff076e2007-08-07 11:48:12 +02001131static unsigned int dell_3st_pin_configs[14] = {
1132 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1133 0x01111212, 0x01116211, 0x01813050, 0x01112214,
1134 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
1135 0x40c003fc, 0x40000100
1136};
1137
Tobin Davis93ed1502006-09-01 21:03:12 +02001138static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001139 [STAC_D965_REF] = ref927x_pin_configs,
Tobin Davis93ed1502006-09-01 21:03:12 +02001140 [STAC_D965_3ST] = d965_3st_pin_configs,
1141 [STAC_D965_5ST] = d965_5st_pin_configs,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001142 [STAC_DELL_3ST] = dell_3st_pin_configs,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001143};
1144
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001145static const char *stac927x_models[STAC_927X_MODELS] = {
1146 [STAC_D965_REF] = "ref",
1147 [STAC_D965_3ST] = "3stack",
1148 [STAC_D965_5ST] = "5stack",
Tobin Davis4ff076e2007-08-07 11:48:12 +02001149 [STAC_DELL_3ST] = "dell-3stack",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001150};
1151
1152static struct snd_pci_quirk stac927x_cfg_tbl[] = {
1153 /* SigmaTel reference board */
1154 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1155 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001156 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001157 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
1158 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001159 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001160 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
1161 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
1162 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
1163 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
1164 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
1165 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
1166 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
1167 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
1168 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
1169 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
1170 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
1171 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
1172 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
1173 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
1174 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
1175 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tim Gardner5e915bb2007-10-10 10:42:00 +02001176 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001177 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001178 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001179 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
1180 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001181 /* 965 based 5 stack systems */
Tim Gardner5e915bb2007-10-10 10:42:00 +02001182 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_D965_5ST),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001183 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
1184 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
1185 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
1186 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
1187 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
1188 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
1189 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
1190 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
1191 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01001192 {} /* terminator */
1193};
1194
Matt Porterf3302a52006-07-31 12:49:34 +02001195static unsigned int ref9205_pin_configs[12] = {
1196 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matt Porter8b657272006-10-26 17:12:59 +02001197 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
1198 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02001199};
1200
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001201/*
1202 STAC 9205 pin configs for
1203 102801F1
1204 102801F2
1205 102801FC
1206 102801FD
1207 10280204
1208 1028021F
1209*/
1210static unsigned int dell_9205_m42_pin_configs[12] = {
1211 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1212 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1213 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1214};
1215
1216/*
1217 STAC 9205 pin configs for
1218 102801F9
1219 102801FA
1220 102801FE
1221 102801FF (Dell Precision M4300)
1222 10280206
1223 10280200
1224 10280201
1225*/
1226static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001227 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1228 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1229 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1230};
1231
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001232static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001233 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1234 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1235 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1236};
1237
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001238static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001239 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001240 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1241 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1242 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02001243};
1244
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001245static const char *stac9205_models[STAC_9205_MODELS] = {
1246 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001247 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001248 [STAC_9205_DELL_M43] = "dell-m43",
1249 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001250};
1251
1252static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1253 /* SigmaTel reference board */
1254 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1255 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001256 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1257 "unknown Dell", STAC_9205_DELL_M42),
1258 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1259 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001260 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02001261 "Dell Precision", STAC_9205_DELL_M43),
1262 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
1263 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001264 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1265 "Dell Precision", STAC_9205_DELL_M43),
Matthew Ranostaye45e4592007-09-10 23:09:42 +02001266 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
1267 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001268 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1269 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001270 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1271 "unknown Dell", STAC_9205_DELL_M42),
1272 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1273 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001274 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1275 "Dell Precision", STAC_9205_DELL_M43),
1276 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001277 "Dell Precision M4300", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001278 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1279 "Dell Precision", STAC_9205_DELL_M43),
1280 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1281 "Dell Inspiron", STAC_9205_DELL_M44),
1282 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1283 "Dell Inspiron", STAC_9205_DELL_M44),
1284 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1285 "Dell Inspiron", STAC_9205_DELL_M44),
1286 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1287 "Dell Inspiron", STAC_9205_DELL_M44),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001288 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1289 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001290 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1291 "Dell Inspiron", STAC_9205_DELL_M44),
Matt Porterf3302a52006-07-31 12:49:34 +02001292 {} /* terminator */
1293};
1294
Richard Fish11b44bb2006-08-23 18:31:34 +02001295static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1296{
1297 int i;
1298 struct sigmatel_spec *spec = codec->spec;
1299
1300 if (! spec->bios_pin_configs) {
1301 spec->bios_pin_configs = kcalloc(spec->num_pins,
1302 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1303 if (! spec->bios_pin_configs)
1304 return -ENOMEM;
1305 }
1306
1307 for (i = 0; i < spec->num_pins; i++) {
1308 hda_nid_t nid = spec->pin_nids[i];
1309 unsigned int pin_cfg;
1310
1311 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1312 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1313 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1314 nid, pin_cfg);
1315 spec->bios_pin_configs[i] = pin_cfg;
1316 }
1317
1318 return 0;
1319}
1320
Matthew Ranostay87d48362007-07-17 11:52:24 +02001321static void stac92xx_set_config_reg(struct hda_codec *codec,
1322 hda_nid_t pin_nid, unsigned int pin_config)
1323{
1324 int i;
1325 snd_hda_codec_write(codec, pin_nid, 0,
1326 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1327 pin_config & 0x000000ff);
1328 snd_hda_codec_write(codec, pin_nid, 0,
1329 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1330 (pin_config & 0x0000ff00) >> 8);
1331 snd_hda_codec_write(codec, pin_nid, 0,
1332 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1333 (pin_config & 0x00ff0000) >> 16);
1334 snd_hda_codec_write(codec, pin_nid, 0,
1335 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1336 pin_config >> 24);
1337 i = snd_hda_codec_read(codec, pin_nid, 0,
1338 AC_VERB_GET_CONFIG_DEFAULT,
1339 0x00);
1340 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1341 pin_nid, i);
1342}
1343
Matt2f2f4252005-04-13 14:45:30 +02001344static void stac92xx_set_config_regs(struct hda_codec *codec)
1345{
1346 int i;
1347 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02001348
Matthew Ranostay87d48362007-07-17 11:52:24 +02001349 if (!spec->pin_configs)
1350 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02001351
Matthew Ranostay87d48362007-07-17 11:52:24 +02001352 for (i = 0; i < spec->num_pins; i++)
1353 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1354 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02001355}
Matt2f2f4252005-04-13 14:45:30 +02001356
Takashi Iwai82599802007-07-31 15:56:24 +02001357static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001358{
Takashi Iwai82599802007-07-31 15:56:24 +02001359 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay87d48362007-07-17 11:52:24 +02001360 /* Configure GPIOx as output */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001361 snd_hda_codec_write_cache(codec, codec->afg, 0,
1362 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001363 /* Configure GPIOx as CMOS */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001364 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001365 /* Assert GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001366 snd_hda_codec_write_cache(codec, codec->afg, 0,
1367 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
Matthew Ranostay87d48362007-07-17 11:52:24 +02001368 /* Enable GPIOx */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001369 snd_hda_codec_write_cache(codec, codec->afg, 0,
1370 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02001371}
1372
Matt2f2f4252005-04-13 14:45:30 +02001373/*
1374 * Analog playback callbacks
1375 */
1376static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1377 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001378 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001379{
1380 struct sigmatel_spec *spec = codec->spec;
1381 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1382}
1383
1384static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1385 struct hda_codec *codec,
1386 unsigned int stream_tag,
1387 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001388 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001389{
1390 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01001391 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02001392}
1393
1394static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1395 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001396 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001397{
1398 struct sigmatel_spec *spec = codec->spec;
1399 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1400}
1401
1402/*
Mattdabbed62005-06-14 10:19:34 +02001403 * Digital playback callbacks
1404 */
1405static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1406 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001407 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001408{
1409 struct sigmatel_spec *spec = codec->spec;
1410 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1411}
1412
1413static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1414 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001415 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001416{
1417 struct sigmatel_spec *spec = codec->spec;
1418 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1419}
1420
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001421static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1422 struct hda_codec *codec,
1423 unsigned int stream_tag,
1424 unsigned int format,
1425 struct snd_pcm_substream *substream)
1426{
1427 struct sigmatel_spec *spec = codec->spec;
1428 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1429 stream_tag, format, substream);
1430}
1431
Mattdabbed62005-06-14 10:19:34 +02001432
1433/*
Matt2f2f4252005-04-13 14:45:30 +02001434 * Analog capture callbacks
1435 */
1436static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1437 struct hda_codec *codec,
1438 unsigned int stream_tag,
1439 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001440 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001441{
1442 struct sigmatel_spec *spec = codec->spec;
1443
1444 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1445 stream_tag, 0, format);
1446 return 0;
1447}
1448
1449static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1450 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001451 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001452{
1453 struct sigmatel_spec *spec = codec->spec;
1454
1455 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1456 return 0;
1457}
1458
Mattdabbed62005-06-14 10:19:34 +02001459static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1460 .substreams = 1,
1461 .channels_min = 2,
1462 .channels_max = 2,
1463 /* NID is set in stac92xx_build_pcms */
1464 .ops = {
1465 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001466 .close = stac92xx_dig_playback_pcm_close,
1467 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02001468 },
1469};
1470
1471static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1472 .substreams = 1,
1473 .channels_min = 2,
1474 .channels_max = 2,
1475 /* NID is set in stac92xx_build_pcms */
1476};
1477
Matt2f2f4252005-04-13 14:45:30 +02001478static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1479 .substreams = 1,
1480 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02001481 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02001482 .nid = 0x02, /* NID to query formats and rates */
1483 .ops = {
1484 .open = stac92xx_playback_pcm_open,
1485 .prepare = stac92xx_playback_pcm_prepare,
1486 .cleanup = stac92xx_playback_pcm_cleanup
1487 },
1488};
1489
Matt Porter3cc08dc2006-01-23 15:27:49 +01001490static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1491 .substreams = 1,
1492 .channels_min = 2,
1493 .channels_max = 2,
1494 .nid = 0x06, /* NID to query formats and rates */
1495 .ops = {
1496 .open = stac92xx_playback_pcm_open,
1497 .prepare = stac92xx_playback_pcm_prepare,
1498 .cleanup = stac92xx_playback_pcm_cleanup
1499 },
1500};
1501
Matt2f2f4252005-04-13 14:45:30 +02001502static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02001503 .channels_min = 2,
1504 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001505 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001506 .ops = {
1507 .prepare = stac92xx_capture_pcm_prepare,
1508 .cleanup = stac92xx_capture_pcm_cleanup
1509 },
1510};
1511
1512static int stac92xx_build_pcms(struct hda_codec *codec)
1513{
1514 struct sigmatel_spec *spec = codec->spec;
1515 struct hda_pcm *info = spec->pcm_rec;
1516
1517 codec->num_pcms = 1;
1518 codec->pcm_info = info;
1519
Mattc7d4b2f2005-06-27 14:59:41 +02001520 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001521 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001522 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001523 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001524 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001525
1526 if (spec->alt_switch) {
1527 codec->num_pcms++;
1528 info++;
1529 info->name = "STAC92xx Analog Alt";
1530 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1531 }
Matt2f2f4252005-04-13 14:45:30 +02001532
Mattdabbed62005-06-14 10:19:34 +02001533 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1534 codec->num_pcms++;
1535 info++;
1536 info->name = "STAC92xx Digital";
1537 if (spec->multiout.dig_out_nid) {
1538 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1539 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1540 }
1541 if (spec->dig_in_nid) {
1542 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1543 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1544 }
1545 }
1546
Matt2f2f4252005-04-13 14:45:30 +02001547 return 0;
1548}
1549
Takashi Iwaic960a032006-03-23 17:06:28 +01001550static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1551{
1552 unsigned int pincap = snd_hda_param_read(codec, nid,
1553 AC_PAR_PIN_CAP);
1554 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1555 if (pincap & AC_PINCAP_VREF_100)
1556 return AC_PINCTL_VREF_100;
1557 if (pincap & AC_PINCAP_VREF_80)
1558 return AC_PINCTL_VREF_80;
1559 if (pincap & AC_PINCAP_VREF_50)
1560 return AC_PINCTL_VREF_50;
1561 if (pincap & AC_PINCAP_VREF_GRD)
1562 return AC_PINCTL_VREF_GRD;
1563 return 0;
1564}
1565
Matt Porter403d1942005-11-29 15:00:51 +01001566static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1567
1568{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001569 snd_hda_codec_write_cache(codec, nid, 0,
1570 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01001571}
1572
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001573#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001574
1575static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1576{
1577 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1578 struct sigmatel_spec *spec = codec->spec;
1579 int io_idx = kcontrol-> private_value & 0xff;
1580
1581 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1582 return 0;
1583}
1584
1585static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1586{
1587 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1588 struct sigmatel_spec *spec = codec->spec;
1589 hda_nid_t nid = kcontrol->private_value >> 8;
1590 int io_idx = kcontrol-> private_value & 0xff;
1591 unsigned short val = ucontrol->value.integer.value[0];
1592
1593 spec->io_switch[io_idx] = val;
1594
1595 if (val)
1596 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001597 else {
1598 unsigned int pinctl = AC_PINCTL_IN_EN;
1599 if (io_idx) /* set VREF for mic */
1600 pinctl |= stac92xx_get_vref(codec, nid);
1601 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1602 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01001603
1604 /* check the auto-mute again: we need to mute/unmute the speaker
1605 * appropriately according to the pin direction
1606 */
1607 if (spec->hp_detect)
1608 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1609
Matt Porter403d1942005-11-29 15:00:51 +01001610 return 1;
1611}
1612
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001613#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
1614
1615static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
1616 struct snd_ctl_elem_value *ucontrol)
1617{
1618 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1619 struct sigmatel_spec *spec = codec->spec;
1620
1621 ucontrol->value.integer.value[0] = spec->clfe_swap;
1622 return 0;
1623}
1624
1625static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1626 struct snd_ctl_elem_value *ucontrol)
1627{
1628 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1629 struct sigmatel_spec *spec = codec->spec;
1630 hda_nid_t nid = kcontrol->private_value & 0xff;
1631
1632 if (spec->clfe_swap == ucontrol->value.integer.value[0])
1633 return 0;
1634
1635 spec->clfe_swap = ucontrol->value.integer.value[0];
1636
1637 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1638 spec->clfe_swap ? 0x4 : 0x0);
1639
1640 return 1;
1641}
1642
Matt Porter403d1942005-11-29 15:00:51 +01001643#define STAC_CODEC_IO_SWITCH(xname, xpval) \
1644 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1645 .name = xname, \
1646 .index = 0, \
1647 .info = stac92xx_io_switch_info, \
1648 .get = stac92xx_io_switch_get, \
1649 .put = stac92xx_io_switch_put, \
1650 .private_value = xpval, \
1651 }
1652
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001653#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
1654 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1655 .name = xname, \
1656 .index = 0, \
1657 .info = stac92xx_clfe_switch_info, \
1658 .get = stac92xx_clfe_switch_get, \
1659 .put = stac92xx_clfe_switch_put, \
1660 .private_value = xpval, \
1661 }
Matt Porter403d1942005-11-29 15:00:51 +01001662
Mattc7d4b2f2005-06-27 14:59:41 +02001663enum {
1664 STAC_CTL_WIDGET_VOL,
1665 STAC_CTL_WIDGET_MUTE,
Matt Porter403d1942005-11-29 15:00:51 +01001666 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001667 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02001668};
1669
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001670static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02001671 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
1672 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matt Porter403d1942005-11-29 15:00:51 +01001673 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001674 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02001675};
1676
1677/* add dynamic controls */
1678static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
1679{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001680 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02001681
1682 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
1683 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
1684
1685 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
1686 if (! knew)
1687 return -ENOMEM;
1688 if (spec->kctl_alloc) {
1689 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
1690 kfree(spec->kctl_alloc);
1691 }
1692 spec->kctl_alloc = knew;
1693 spec->num_kctl_alloc = num;
1694 }
1695
1696 knew = &spec->kctl_alloc[spec->num_kctl_used];
1697 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02001698 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02001699 if (! knew->name)
1700 return -ENOMEM;
1701 knew->private_value = val;
1702 spec->num_kctl_used++;
1703 return 0;
1704}
1705
Matt Porter403d1942005-11-29 15:00:51 +01001706/* flag inputs as additional dynamic lineouts */
1707static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
1708{
1709 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001710 unsigned int wcaps, wtype;
1711 int i, num_dacs = 0;
1712
1713 /* use the wcaps cache to count all DACs available for line-outs */
1714 for (i = 0; i < codec->num_nodes; i++) {
1715 wcaps = codec->wcaps[i];
1716 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1717 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
1718 num_dacs++;
1719 }
Matt Porter403d1942005-11-29 15:00:51 +01001720
Steve Longerbeam7b043892007-05-03 20:50:03 +02001721 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
1722
Matt Porter403d1942005-11-29 15:00:51 +01001723 switch (cfg->line_outs) {
1724 case 3:
1725 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001726 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001727 cfg->line_out_pins[cfg->line_outs] =
1728 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001729 spec->line_switch = 1;
1730 cfg->line_outs++;
1731 }
1732 break;
1733 case 2:
1734 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001735 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001736 cfg->line_out_pins[cfg->line_outs] =
1737 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001738 spec->line_switch = 1;
1739 cfg->line_outs++;
1740 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001741 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001742 cfg->line_out_pins[cfg->line_outs] =
1743 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001744 spec->mic_switch = 1;
1745 cfg->line_outs++;
1746 }
1747 break;
1748 case 1:
1749 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02001750 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001751 cfg->line_out_pins[cfg->line_outs] =
1752 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01001753 spec->line_switch = 1;
1754 cfg->line_outs++;
1755 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001756 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02001757 cfg->line_out_pins[cfg->line_outs] =
1758 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01001759 spec->mic_switch = 1;
1760 cfg->line_outs++;
1761 }
1762 break;
1763 }
1764
1765 return 0;
1766}
1767
Steve Longerbeam7b043892007-05-03 20:50:03 +02001768
1769static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1770{
1771 int i;
1772
1773 for (i = 0; i < spec->multiout.num_dacs; i++) {
1774 if (spec->multiout.dac_nids[i] == nid)
1775 return 1;
1776 }
1777
1778 return 0;
1779}
1780
Matt Porter3cc08dc2006-01-23 15:27:49 +01001781/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02001782 * Fill in the dac_nids table from the parsed pin configuration
1783 * This function only works when every pin in line_out_pins[]
1784 * contains atleast one DAC in its connection list. Some 92xx
1785 * codecs are not connected directly to a DAC, such as the 9200
1786 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01001787 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02001788static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02001789 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001790{
1791 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02001792 int i, j, conn_len = 0;
1793 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
1794 unsigned int wcaps, wtype;
1795
Mattc7d4b2f2005-06-27 14:59:41 +02001796 for (i = 0; i < cfg->line_outs; i++) {
1797 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02001798 conn_len = snd_hda_get_connections(codec, nid, conn,
1799 HDA_MAX_CONNECTIONS);
1800 for (j = 0; j < conn_len; j++) {
1801 wcaps = snd_hda_param_read(codec, conn[j],
1802 AC_PAR_AUDIO_WIDGET_CAP);
1803 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
1804
1805 if (wtype != AC_WID_AUD_OUT ||
1806 (wcaps & AC_WCAP_DIGITAL))
1807 continue;
1808 /* conn[j] is a DAC routed to this line-out */
1809 if (!is_in_dac_nids(spec, conn[j]))
1810 break;
1811 }
1812
1813 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02001814 if (spec->multiout.num_dacs > 0) {
1815 /* we have already working output pins,
1816 * so let's drop the broken ones again
1817 */
1818 cfg->line_outs = spec->multiout.num_dacs;
1819 break;
1820 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02001821 /* error out, no available DAC found */
1822 snd_printk(KERN_ERR
1823 "%s: No available DAC for pin 0x%x\n",
1824 __func__, nid);
1825 return -ENODEV;
1826 }
1827
1828 spec->multiout.dac_nids[i] = conn[j];
1829 spec->multiout.num_dacs++;
1830 if (conn_len > 1) {
1831 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001832 snd_hda_codec_write_cache(codec, nid, 0,
1833 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02001834
1835 }
Mattc7d4b2f2005-06-27 14:59:41 +02001836 }
1837
Steve Longerbeam7b043892007-05-03 20:50:03 +02001838 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
1839 spec->multiout.num_dacs,
1840 spec->multiout.dac_nids[0],
1841 spec->multiout.dac_nids[1],
1842 spec->multiout.dac_nids[2],
1843 spec->multiout.dac_nids[3],
1844 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02001845 return 0;
1846}
1847
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001848/* create volume control/switch for the given prefx type */
1849static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
1850{
1851 char name[32];
1852 int err;
1853
1854 sprintf(name, "%s Playback Volume", pfx);
1855 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
1856 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1857 if (err < 0)
1858 return err;
1859 sprintf(name, "%s Playback Switch", pfx);
1860 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
1861 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
1862 if (err < 0)
1863 return err;
1864 return 0;
1865}
1866
Mattc7d4b2f2005-06-27 14:59:41 +02001867/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001868static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001869 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001870{
Takashi Iwai19039bd2006-06-28 15:52:16 +02001871 static const char *chname[4] = {
1872 "Front", "Surround", NULL /*CLFE*/, "Side"
1873 };
Mattc7d4b2f2005-06-27 14:59:41 +02001874 hda_nid_t nid;
1875 int i, err;
1876
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001877 struct sigmatel_spec *spec = codec->spec;
1878 unsigned int wid_caps;
1879
1880
Mattc7d4b2f2005-06-27 14:59:41 +02001881 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01001882 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02001883 continue;
1884
1885 nid = spec->multiout.dac_nids[i];
1886
1887 if (i == 2) {
1888 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001889 err = create_controls(spec, "Center", nid, 1);
1890 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001891 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001892 err = create_controls(spec, "LFE", nid, 2);
1893 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001894 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001895
1896 wid_caps = get_wcaps(codec, nid);
1897
1898 if (wid_caps & AC_WCAP_LR_SWAP) {
1899 err = stac92xx_add_control(spec,
1900 STAC_CTL_WIDGET_CLFE_SWITCH,
1901 "Swap Center/LFE Playback Switch", nid);
1902
1903 if (err < 0)
1904 return err;
1905 }
1906
Mattc7d4b2f2005-06-27 14:59:41 +02001907 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001908 err = create_controls(spec, chname[i], nid, 3);
1909 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02001910 return err;
1911 }
1912 }
1913
Matt Porter403d1942005-11-29 15:00:51 +01001914 if (spec->line_switch)
1915 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
1916 return err;
1917
1918 if (spec->mic_switch)
1919 if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
1920 return err;
1921
Mattc7d4b2f2005-06-27 14:59:41 +02001922 return 0;
1923}
1924
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001925static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
1926{
Steve Longerbeam7b043892007-05-03 20:50:03 +02001927 if (is_in_dac_nids(spec, nid))
1928 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001929 if (spec->multiout.hp_nid == nid)
1930 return 1;
1931 return 0;
1932}
1933
1934static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
1935{
1936 if (!spec->multiout.hp_nid)
1937 spec->multiout.hp_nid = nid;
1938 else if (spec->multiout.num_dacs > 4) {
1939 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
1940 return 1;
1941 } else {
1942 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
1943 spec->multiout.num_dacs++;
1944 }
1945 return 0;
1946}
1947
1948/* add playback controls for Speaker and HP outputs */
1949static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
1950 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02001951{
1952 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02001953 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001954 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02001955
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001956 old_num_dacs = spec->multiout.num_dacs;
1957 for (i = 0; i < cfg->hp_outs; i++) {
1958 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
1959 if (wid_caps & AC_WCAP_UNSOL_CAP)
1960 spec->hp_detect = 1;
1961 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
1962 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1963 if (check_in_dac_nids(spec, nid))
1964 nid = 0;
1965 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02001966 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001967 add_spec_dacs(spec, nid);
1968 }
1969 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02001970 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001971 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1972 if (check_in_dac_nids(spec, nid))
1973 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001974 if (! nid)
1975 continue;
1976 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02001977 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02001978 for (i = 0; i < cfg->line_outs; i++) {
1979 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
1980 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
1981 if (check_in_dac_nids(spec, nid))
1982 nid = 0;
1983 if (! nid)
1984 continue;
1985 add_spec_dacs(spec, nid);
1986 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001987 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
1988 static const char *pfxs[] = {
1989 "Speaker", "External Speaker", "Speaker2",
1990 };
1991 err = create_controls(spec, pfxs[i - old_num_dacs],
1992 spec->multiout.dac_nids[i], 3);
1993 if (err < 0)
1994 return err;
1995 }
1996 if (spec->multiout.hp_nid) {
1997 const char *pfx;
Takashi Iwai6020c002007-11-19 11:56:26 +01001998 if (old_num_dacs == spec->multiout.num_dacs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02001999 pfx = "Master";
2000 else
2001 pfx = "Headphone";
2002 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
2003 if (err < 0)
2004 return err;
2005 }
Mattc7d4b2f2005-06-27 14:59:41 +02002006
2007 return 0;
2008}
2009
Matt Porter8b657272006-10-26 17:12:59 +02002010/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01002011static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02002012 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
2013 "Digital Mic 3", "Digital Mic 4"
2014};
2015
2016/* create playback/capture controls for input pins on dmic capable codecs */
2017static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
2018 const struct auto_pin_cfg *cfg)
2019{
2020 struct sigmatel_spec *spec = codec->spec;
2021 struct hda_input_mux *dimux = &spec->private_dimux;
2022 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
2023 int i, j;
2024
2025 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
2026 dimux->items[dimux->num_items].index = 0;
2027 dimux->num_items++;
2028
2029 for (i = 0; i < spec->num_dmics; i++) {
2030 int index;
2031 int num_cons;
2032 unsigned int def_conf;
2033
2034 def_conf = snd_hda_codec_read(codec,
2035 spec->dmic_nids[i],
2036 0,
2037 AC_VERB_GET_CONFIG_DEFAULT,
2038 0);
2039 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
2040 continue;
2041
2042 num_cons = snd_hda_get_connections(codec,
2043 spec->dmux_nid,
2044 con_lst,
2045 HDA_MAX_NUM_INPUTS);
2046 for (j = 0; j < num_cons; j++)
2047 if (con_lst[j] == spec->dmic_nids[i]) {
2048 index = j;
2049 goto found;
2050 }
2051 continue;
2052found:
2053 dimux->items[dimux->num_items].label =
2054 stac92xx_dmic_labels[dimux->num_items];
2055 dimux->items[dimux->num_items].index = index;
2056 dimux->num_items++;
2057 }
2058
2059 return 0;
2060}
2061
Mattc7d4b2f2005-06-27 14:59:41 +02002062/* create playback/capture controls for input pins */
2063static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
2064{
2065 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002066 struct hda_input_mux *imux = &spec->private_imux;
2067 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
2068 int i, j, k;
2069
2070 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002071 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02002072
Takashi Iwai314634b2006-09-21 11:56:18 +02002073 if (!cfg->input_pins[i])
2074 continue;
2075 index = -1;
2076 for (j = 0; j < spec->num_muxes; j++) {
2077 int num_cons;
2078 num_cons = snd_hda_get_connections(codec,
2079 spec->mux_nids[j],
2080 con_lst,
2081 HDA_MAX_NUM_INPUTS);
2082 for (k = 0; k < num_cons; k++)
2083 if (con_lst[k] == cfg->input_pins[i]) {
2084 index = k;
2085 goto found;
2086 }
Mattc7d4b2f2005-06-27 14:59:41 +02002087 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002088 continue;
2089 found:
2090 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2091 imux->items[imux->num_items].index = index;
2092 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02002093 }
2094
Steve Longerbeam7b043892007-05-03 20:50:03 +02002095 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02002096 /*
2097 * Set the current input for the muxes.
2098 * The STAC9221 has two input muxes with identical source
2099 * NID lists. Hopefully this won't get confused.
2100 */
2101 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002102 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
2103 AC_VERB_SET_CONNECT_SEL,
2104 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02002105 }
2106 }
2107
Mattc7d4b2f2005-06-27 14:59:41 +02002108 return 0;
2109}
2110
Mattc7d4b2f2005-06-27 14:59:41 +02002111static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
2112{
2113 struct sigmatel_spec *spec = codec->spec;
2114 int i;
2115
2116 for (i = 0; i < spec->autocfg.line_outs; i++) {
2117 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2118 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2119 }
2120}
2121
2122static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
2123{
2124 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002125 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002126
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002127 for (i = 0; i < spec->autocfg.hp_outs; i++) {
2128 hda_nid_t pin;
2129 pin = spec->autocfg.hp_pins[i];
2130 if (pin) /* connect to front */
2131 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
2132 }
2133 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
2134 hda_nid_t pin;
2135 pin = spec->autocfg.speaker_pins[i];
2136 if (pin) /* connect to front */
2137 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
2138 }
Mattc7d4b2f2005-06-27 14:59:41 +02002139}
2140
Matt Porter3cc08dc2006-01-23 15:27:49 +01002141static 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 +02002142{
2143 struct sigmatel_spec *spec = codec->spec;
2144 int err;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002145 int hp_speaker_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002146
Matt Porter8b657272006-10-26 17:12:59 +02002147 if ((err = snd_hda_parse_pin_def_config(codec,
2148 &spec->autocfg,
2149 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002150 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002151 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01002152 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002153
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002154 /* If we have no real line-out pin and multiple hp-outs, HPs should
2155 * be set up as multi-channel outputs.
2156 */
2157 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2158 spec->autocfg.hp_outs > 1) {
2159 /* Copy hp_outs to line_outs, backup line_outs in
2160 * speaker_outs so that the following routines can handle
2161 * HP pins as primary outputs.
2162 */
2163 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
2164 sizeof(spec->autocfg.line_out_pins));
2165 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
2166 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
2167 sizeof(spec->autocfg.hp_pins));
2168 spec->autocfg.line_outs = spec->autocfg.hp_outs;
2169 hp_speaker_swap = 1;
2170 }
2171
Matt Porter403d1942005-11-29 15:00:51 +01002172 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
2173 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002174 if (spec->multiout.num_dacs == 0)
2175 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2176 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02002177
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002178 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
2179
2180 if (err < 0)
2181 return err;
2182
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002183 if (hp_speaker_swap == 1) {
2184 /* Restore the hp_outs and line_outs */
2185 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
2186 sizeof(spec->autocfg.line_out_pins));
2187 spec->autocfg.hp_outs = spec->autocfg.line_outs;
2188 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
2189 sizeof(spec->autocfg.speaker_pins));
2190 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
2191 memset(spec->autocfg.speaker_pins, 0,
2192 sizeof(spec->autocfg.speaker_pins));
2193 spec->autocfg.speaker_outs = 0;
2194 }
2195
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002196 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
2197
2198 if (err < 0)
2199 return err;
2200
2201 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
2202
2203 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002204 return err;
2205
Matt Porter8b657272006-10-26 17:12:59 +02002206 if (spec->num_dmics > 0)
2207 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
2208 &spec->autocfg)) < 0)
2209 return err;
2210
Mattc7d4b2f2005-06-27 14:59:41 +02002211 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01002212 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02002213 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002214
Takashi Iwai82bc9552006-03-21 11:24:42 +01002215 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002216 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002217 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002218 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02002219
2220 if (spec->kctl_alloc)
2221 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2222
2223 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002224 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002225
2226 return 1;
2227}
2228
Takashi Iwai82bc9552006-03-21 11:24:42 +01002229/* add playback controls for HP output */
2230static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
2231 struct auto_pin_cfg *cfg)
2232{
2233 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002234 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01002235 unsigned int wid_caps;
2236
2237 if (! pin)
2238 return 0;
2239
2240 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02002241 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01002242 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002243
2244 return 0;
2245}
2246
Richard Fish160ea0d2006-09-06 13:58:25 +02002247/* add playback controls for LFE output */
2248static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2249 struct auto_pin_cfg *cfg)
2250{
2251 struct sigmatel_spec *spec = codec->spec;
2252 int err;
2253 hda_nid_t lfe_pin = 0x0;
2254 int i;
2255
2256 /*
2257 * search speaker outs and line outs for a mono speaker pin
2258 * with an amp. If one is found, add LFE controls
2259 * for it.
2260 */
2261 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2262 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2263 unsigned long wcaps = get_wcaps(codec, pin);
2264 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2265 if (wcaps == AC_WCAP_OUT_AMP)
2266 /* found a mono speaker with an amp, must be lfe */
2267 lfe_pin = pin;
2268 }
2269
2270 /* if speaker_outs is 0, then speakers may be in line_outs */
2271 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2272 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2273 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2274 unsigned long cfg;
2275 cfg = snd_hda_codec_read(codec, pin, 0,
2276 AC_VERB_GET_CONFIG_DEFAULT,
2277 0x00);
2278 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
2279 unsigned long wcaps = get_wcaps(codec, pin);
2280 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2281 if (wcaps == AC_WCAP_OUT_AMP)
2282 /* found a mono speaker with an amp,
2283 must be lfe */
2284 lfe_pin = pin;
2285 }
2286 }
2287 }
2288
2289 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002290 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02002291 if (err < 0)
2292 return err;
2293 }
2294
2295 return 0;
2296}
2297
Mattc7d4b2f2005-06-27 14:59:41 +02002298static int stac9200_parse_auto_config(struct hda_codec *codec)
2299{
2300 struct sigmatel_spec *spec = codec->spec;
2301 int err;
2302
Kailang Yangdf694da2005-12-05 19:42:22 +01002303 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002304 return err;
2305
2306 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
2307 return err;
2308
Takashi Iwai82bc9552006-03-21 11:24:42 +01002309 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2310 return err;
2311
Richard Fish160ea0d2006-09-06 13:58:25 +02002312 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2313 return err;
2314
Takashi Iwai82bc9552006-03-21 11:24:42 +01002315 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002316 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002317 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002318 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02002319
2320 if (spec->kctl_alloc)
2321 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2322
2323 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002324 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002325
2326 return 1;
2327}
2328
Sam Revitch62fe78e2006-05-10 15:09:17 +02002329/*
2330 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2331 * funky external mute control using GPIO pins.
2332 */
2333
2334static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
2335{
2336 unsigned int gpiostate, gpiomask, gpiodir;
2337
2338 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2339 AC_VERB_GET_GPIO_DATA, 0);
2340
2341 if (!muted)
2342 gpiostate |= (1 << pin);
2343 else
2344 gpiostate &= ~(1 << pin);
2345
2346 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2347 AC_VERB_GET_GPIO_MASK, 0);
2348 gpiomask |= (1 << pin);
2349
2350 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2351 AC_VERB_GET_GPIO_DIRECTION, 0);
2352 gpiodir |= (1 << pin);
2353
2354 /* AppleHDA seems to do this -- WTF is this verb?? */
2355 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2356
2357 snd_hda_codec_write(codec, codec->afg, 0,
2358 AC_VERB_SET_GPIO_MASK, gpiomask);
2359 snd_hda_codec_write(codec, codec->afg, 0,
2360 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
2361
2362 msleep(1);
2363
2364 snd_hda_codec_write(codec, codec->afg, 0,
2365 AC_VERB_SET_GPIO_DATA, gpiostate);
2366}
2367
Takashi Iwai314634b2006-09-21 11:56:18 +02002368static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2369 unsigned int event)
2370{
2371 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002372 snd_hda_codec_write_cache(codec, nid, 0,
2373 AC_VERB_SET_UNSOLICITED_ENABLE,
2374 (AC_USRSP_EN | event));
Takashi Iwai314634b2006-09-21 11:56:18 +02002375}
2376
Mattc7d4b2f2005-06-27 14:59:41 +02002377static int stac92xx_init(struct hda_codec *codec)
2378{
2379 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002380 struct auto_pin_cfg *cfg = &spec->autocfg;
2381 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002382
Mattc7d4b2f2005-06-27 14:59:41 +02002383 snd_hda_sequence_write(codec, spec->init);
2384
Takashi Iwai82bc9552006-03-21 11:24:42 +01002385 /* set up pins */
2386 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02002387 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002388 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02002389 enable_pin_detect(codec, cfg->hp_pins[i],
2390 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01002391 /* force to enable the first line-out; the others are set up
2392 * in unsol_event
2393 */
2394 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2395 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02002396 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002397 /* fake event to set up pins */
2398 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2399 } else {
2400 stac92xx_auto_init_multi_out(codec);
2401 stac92xx_auto_init_hp_out(codec);
2402 }
2403 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01002404 hda_nid_t nid = cfg->input_pins[i];
2405 if (nid) {
2406 unsigned int pinctl = AC_PINCTL_IN_EN;
2407 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
2408 pinctl |= stac92xx_get_vref(codec, nid);
2409 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2410 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01002411 }
Matt Porter8b657272006-10-26 17:12:59 +02002412 if (spec->num_dmics > 0)
2413 for (i = 0; i < spec->num_dmics; i++)
2414 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
2415 AC_PINCTL_IN_EN);
2416
Takashi Iwai82bc9552006-03-21 11:24:42 +01002417 if (cfg->dig_out_pin)
2418 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2419 AC_PINCTL_OUT_EN);
2420 if (cfg->dig_in_pin)
2421 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2422 AC_PINCTL_IN_EN);
2423
Sam Revitch62fe78e2006-05-10 15:09:17 +02002424 if (spec->gpio_mute) {
2425 stac922x_gpio_mute(codec, 0, 0);
2426 stac922x_gpio_mute(codec, 1, 0);
2427 }
2428
Mattc7d4b2f2005-06-27 14:59:41 +02002429 return 0;
2430}
2431
Matt2f2f4252005-04-13 14:45:30 +02002432static void stac92xx_free(struct hda_codec *codec)
2433{
Mattc7d4b2f2005-06-27 14:59:41 +02002434 struct sigmatel_spec *spec = codec->spec;
2435 int i;
2436
2437 if (! spec)
2438 return;
2439
2440 if (spec->kctl_alloc) {
2441 for (i = 0; i < spec->num_kctl_used; i++)
2442 kfree(spec->kctl_alloc[i].name);
2443 kfree(spec->kctl_alloc);
2444 }
2445
Richard Fish11b44bb2006-08-23 18:31:34 +02002446 if (spec->bios_pin_configs)
2447 kfree(spec->bios_pin_configs);
2448
Mattc7d4b2f2005-06-27 14:59:41 +02002449 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02002450}
2451
Matt4e550962005-07-04 17:51:39 +02002452static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
2453 unsigned int flag)
2454{
2455 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2456 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002457
Takashi Iwaif9acba42007-05-29 18:01:06 +02002458 if (pin_ctl & AC_PINCTL_IN_EN) {
2459 /*
2460 * we need to check the current set-up direction of
2461 * shared input pins since they can be switched via
2462 * "xxx as Output" mixer switch
2463 */
2464 struct sigmatel_spec *spec = codec->spec;
2465 struct auto_pin_cfg *cfg = &spec->autocfg;
2466 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
2467 spec->line_switch) ||
2468 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
2469 spec->mic_switch))
2470 return;
2471 }
2472
Steve Longerbeam7b043892007-05-03 20:50:03 +02002473 /* if setting pin direction bits, clear the current
2474 direction bits first */
2475 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
2476 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
2477
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002478 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002479 AC_VERB_SET_PIN_WIDGET_CONTROL,
2480 pin_ctl | flag);
2481}
2482
2483static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
2484 unsigned int flag)
2485{
2486 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2487 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002488 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002489 AC_VERB_SET_PIN_WIDGET_CONTROL,
2490 pin_ctl & ~flag);
2491}
2492
Jiang Zhe40c1d302007-11-12 13:05:16 +01002493static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02002494{
2495 if (!nid)
2496 return 0;
2497 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Jiang Zhe40c1d302007-11-12 13:05:16 +01002498 & (1 << 31)) {
2499 unsigned int pinctl;
2500 pinctl = snd_hda_codec_read(codec, nid, 0,
2501 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2502 if (pinctl & AC_PINCTL_IN_EN)
2503 return 0; /* mic- or line-input */
2504 else
2505 return 1; /* HP-output */
2506 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002507 return 0;
2508}
2509
2510static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02002511{
2512 struct sigmatel_spec *spec = codec->spec;
2513 struct auto_pin_cfg *cfg = &spec->autocfg;
2514 int i, presence;
2515
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002516 presence = 0;
2517 for (i = 0; i < cfg->hp_outs; i++) {
Jiang Zhe40c1d302007-11-12 13:05:16 +01002518 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
Takashi Iwai314634b2006-09-21 11:56:18 +02002519 if (presence)
2520 break;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002521 }
Matt4e550962005-07-04 17:51:39 +02002522
2523 if (presence) {
2524 /* disable lineouts, enable hp */
2525 for (i = 0; i < cfg->line_outs; i++)
2526 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
2527 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002528 for (i = 0; i < cfg->speaker_outs; i++)
2529 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
2530 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002531 } else {
2532 /* enable lineouts, disable hp */
2533 for (i = 0; i < cfg->line_outs; i++)
2534 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
2535 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002536 for (i = 0; i < cfg->speaker_outs; i++)
2537 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
2538 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02002539 }
2540}
2541
Takashi Iwai314634b2006-09-21 11:56:18 +02002542static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
2543{
2544 switch (res >> 26) {
2545 case STAC_HP_EVENT:
2546 stac92xx_hp_detect(codec, res);
2547 break;
2548 }
2549}
2550
Takashi Iwaicb53c622007-08-10 17:21:45 +02002551#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002552static int stac92xx_resume(struct hda_codec *codec)
2553{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002554 struct sigmatel_spec *spec = codec->spec;
2555
Richard Fish11b44bb2006-08-23 18:31:34 +02002556 stac92xx_set_config_regs(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002557 snd_hda_sequence_write(codec, spec->init);
2558 if (spec->gpio_mute) {
2559 stac922x_gpio_mute(codec, 0, 0);
2560 stac922x_gpio_mute(codec, 1, 0);
2561 }
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002562 snd_hda_codec_resume_amp(codec);
2563 snd_hda_codec_resume_cache(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002564 /* invoke unsolicited event to reset the HP state */
2565 if (spec->hp_detect)
2566 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Mattff6fdc32005-06-27 15:06:52 +02002567 return 0;
2568}
2569#endif
2570
Matt2f2f4252005-04-13 14:45:30 +02002571static struct hda_codec_ops stac92xx_patch_ops = {
2572 .build_controls = stac92xx_build_controls,
2573 .build_pcms = stac92xx_build_pcms,
2574 .init = stac92xx_init,
2575 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02002576 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002577#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02002578 .resume = stac92xx_resume,
2579#endif
Matt2f2f4252005-04-13 14:45:30 +02002580};
2581
2582static int patch_stac9200(struct hda_codec *codec)
2583{
2584 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002585 int err;
Matt2f2f4252005-04-13 14:45:30 +02002586
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002587 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002588 if (spec == NULL)
2589 return -ENOMEM;
2590
2591 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002592 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002593 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002594 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
2595 stac9200_models,
2596 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02002597 if (spec->board_config < 0) {
2598 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
2599 err = stac92xx_save_bios_config_regs(codec);
2600 if (err < 0) {
2601 stac92xx_free(codec);
2602 return err;
2603 }
2604 spec->pin_configs = spec->bios_pin_configs;
2605 } else {
Matt Porter403d1942005-11-29 15:00:51 +01002606 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
2607 stac92xx_set_config_regs(codec);
2608 }
Matt2f2f4252005-04-13 14:45:30 +02002609
2610 spec->multiout.max_channels = 2;
2611 spec->multiout.num_dacs = 1;
2612 spec->multiout.dac_nids = stac9200_dac_nids;
2613 spec->adc_nids = stac9200_adc_nids;
2614 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02002615 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02002616 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002617 spec->num_adcs = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002618
Takashi Iwai1194b5b2007-10-10 10:04:26 +02002619 if (spec->board_config == STAC_9200_GATEWAY)
2620 spec->init = stac9200_eapd_init;
2621 else
2622 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002623 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002624
2625 err = stac9200_parse_auto_config(codec);
2626 if (err < 0) {
2627 stac92xx_free(codec);
2628 return err;
2629 }
Matt2f2f4252005-04-13 14:45:30 +02002630
2631 codec->patch_ops = stac92xx_patch_ops;
2632
2633 return 0;
2634}
2635
Tobin Davis8e21c342007-01-08 11:04:17 +01002636static int patch_stac925x(struct hda_codec *codec)
2637{
2638 struct sigmatel_spec *spec;
2639 int err;
2640
2641 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2642 if (spec == NULL)
2643 return -ENOMEM;
2644
2645 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002646 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01002647 spec->pin_nids = stac925x_pin_nids;
2648 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
2649 stac925x_models,
2650 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002651 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01002652 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02002653 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
2654 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01002655 err = stac92xx_save_bios_config_regs(codec);
2656 if (err < 0) {
2657 stac92xx_free(codec);
2658 return err;
2659 }
2660 spec->pin_configs = spec->bios_pin_configs;
2661 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
2662 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
2663 stac92xx_set_config_regs(codec);
2664 }
2665
2666 spec->multiout.max_channels = 2;
2667 spec->multiout.num_dacs = 1;
2668 spec->multiout.dac_nids = stac925x_dac_nids;
2669 spec->adc_nids = stac925x_adc_nids;
2670 spec->mux_nids = stac925x_mux_nids;
2671 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002672 spec->num_adcs = 1;
Tobin Davis2c11f952007-05-17 09:36:34 +02002673 switch (codec->vendor_id) {
2674 case 0x83847632: /* STAC9202 */
2675 case 0x83847633: /* STAC9202D */
2676 case 0x83847636: /* STAC9251 */
2677 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02002678 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02002679 spec->dmic_nids = stac925x_dmic_nids;
2680 break;
2681 default:
2682 spec->num_dmics = 0;
2683 break;
2684 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002685
2686 spec->init = stac925x_core_init;
2687 spec->mixer = stac925x_mixer;
2688
2689 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002690 if (!err) {
2691 if (spec->board_config < 0) {
2692 printk(KERN_WARNING "hda_codec: No auto-config is "
2693 "available, default to model=ref\n");
2694 spec->board_config = STAC_925x_REF;
2695 goto again;
2696 }
2697 err = -EINVAL;
2698 }
Tobin Davis8e21c342007-01-08 11:04:17 +01002699 if (err < 0) {
2700 stac92xx_free(codec);
2701 return err;
2702 }
2703
2704 codec->patch_ops = stac92xx_patch_ops;
2705
2706 return 0;
2707}
2708
Matthew Ranostaye035b842007-11-06 11:53:55 +01002709static int patch_stac92hd71bxx(struct hda_codec *codec)
2710{
2711 struct sigmatel_spec *spec;
2712 int err = 0;
2713
2714 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2715 if (spec == NULL)
2716 return -ENOMEM;
2717
2718 codec->spec = spec;
2719 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
2720 spec->pin_nids = stac92hd71bxx_pin_nids;
2721 spec->board_config = snd_hda_check_board_config(codec,
2722 STAC_92HD71BXX_MODELS,
2723 stac92hd71bxx_models,
2724 stac92hd71bxx_cfg_tbl);
2725again:
2726 if (spec->board_config < 0) {
2727 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
2728 " STAC92HD71BXX, using BIOS defaults\n");
2729 err = stac92xx_save_bios_config_regs(codec);
2730 if (err < 0) {
2731 stac92xx_free(codec);
2732 return err;
2733 }
2734 spec->pin_configs = spec->bios_pin_configs;
2735 } else {
2736 spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config];
2737 stac92xx_set_config_regs(codec);
2738 }
2739
2740 spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */
2741 stac92xx_enable_gpio_mask(codec);
2742
2743 spec->init = stac92hd71bxx_core_init;
2744 spec->mixer = stac92hd71bxx_mixer;
2745
2746 spec->mux_nids = stac92hd71bxx_mux_nids;
2747 spec->adc_nids = stac92hd71bxx_adc_nids;
2748 spec->dmic_nids = stac92hd71bxx_dmic_nids;
2749 spec->dmux_nid = 0x1c;
2750
2751 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
2752 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
2753 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
2754
2755 spec->multiout.num_dacs = 2;
2756 spec->multiout.hp_nid = 0x11;
2757 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
2758
2759 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
2760 if (!err) {
2761 if (spec->board_config < 0) {
2762 printk(KERN_WARNING "hda_codec: No auto-config is "
2763 "available, default to model=ref\n");
2764 spec->board_config = STAC_92HD71BXX_REF;
2765 goto again;
2766 }
2767 err = -EINVAL;
2768 }
2769
2770 if (err < 0) {
2771 stac92xx_free(codec);
2772 return err;
2773 }
2774
2775 codec->patch_ops = stac92xx_patch_ops;
2776
2777 return 0;
2778};
2779
Matt2f2f4252005-04-13 14:45:30 +02002780static int patch_stac922x(struct hda_codec *codec)
2781{
2782 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002783 int err;
Matt2f2f4252005-04-13 14:45:30 +02002784
Takashi Iwaie560d8d2005-09-09 14:21:46 +02002785 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02002786 if (spec == NULL)
2787 return -ENOMEM;
2788
2789 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002790 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002791 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002792 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
2793 stac922x_models,
2794 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002795 if (spec->board_config == STAC_INTEL_MAC_V3) {
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002796 spec->gpio_mute = 1;
2797 /* Intel Macs have all same PCI SSID, so we need to check
2798 * codec SSID to distinguish the exact models
2799 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002800 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002801 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002802
2803 case 0x106b0800:
2804 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02002805 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002806 case 0x106b0600:
2807 case 0x106b0700:
2808 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002809 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002810 case 0x106b0e00:
2811 case 0x106b0f00:
2812 case 0x106b1600:
2813 case 0x106b1700:
2814 case 0x106b0200:
2815 case 0x106b1e00:
2816 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002817 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002818 case 0x106b1a00:
2819 case 0x00000100:
2820 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02002821 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002822 case 0x106b0a00:
2823 case 0x106b2200:
2824 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002825 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002826 }
2827 }
2828
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002829 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002830 if (spec->board_config < 0) {
2831 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
2832 "using BIOS defaults\n");
2833 err = stac92xx_save_bios_config_regs(codec);
2834 if (err < 0) {
2835 stac92xx_free(codec);
2836 return err;
2837 }
2838 spec->pin_configs = spec->bios_pin_configs;
2839 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01002840 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
2841 stac92xx_set_config_regs(codec);
2842 }
Matt2f2f4252005-04-13 14:45:30 +02002843
Matt2f2f4252005-04-13 14:45:30 +02002844 spec->adc_nids = stac922x_adc_nids;
2845 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002846 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002847 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02002848 spec->num_dmics = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002849
2850 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02002851 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02002852
2853 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002854
Matt Porter3cc08dc2006-01-23 15:27:49 +01002855 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002856 if (!err) {
2857 if (spec->board_config < 0) {
2858 printk(KERN_WARNING "hda_codec: No auto-config is "
2859 "available, default to model=ref\n");
2860 spec->board_config = STAC_D945_REF;
2861 goto again;
2862 }
2863 err = -EINVAL;
2864 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002865 if (err < 0) {
2866 stac92xx_free(codec);
2867 return err;
2868 }
2869
2870 codec->patch_ops = stac92xx_patch_ops;
2871
Takashi Iwai807a46362007-05-29 19:01:37 +02002872 /* Fix Mux capture level; max to 2 */
2873 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
2874 (0 << AC_AMPCAP_OFFSET_SHIFT) |
2875 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
2876 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
2877 (0 << AC_AMPCAP_MUTE_SHIFT));
2878
Matt Porter3cc08dc2006-01-23 15:27:49 +01002879 return 0;
2880}
2881
2882static int patch_stac927x(struct hda_codec *codec)
2883{
2884 struct sigmatel_spec *spec;
2885 int err;
2886
2887 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2888 if (spec == NULL)
2889 return -ENOMEM;
2890
2891 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002892 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002893 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002894 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
2895 stac927x_models,
2896 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002897 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002898 if (spec->board_config < 0) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002899 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02002900 err = stac92xx_save_bios_config_regs(codec);
2901 if (err < 0) {
2902 stac92xx_free(codec);
2903 return err;
2904 }
2905 spec->pin_configs = spec->bios_pin_configs;
2906 } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002907 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
2908 stac92xx_set_config_regs(codec);
2909 }
2910
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002911 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02002912 case STAC_D965_3ST:
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002913 spec->adc_nids = stac927x_adc_nids;
2914 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002915 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002916 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis93ed1502006-09-01 21:03:12 +02002917 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002918 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002919 break;
Tobin Davis93ed1502006-09-01 21:03:12 +02002920 case STAC_D965_5ST:
2921 spec->adc_nids = stac927x_adc_nids;
2922 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002923 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002924 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis93ed1502006-09-01 21:03:12 +02002925 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002926 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002927 break;
2928 default:
2929 spec->adc_nids = stac927x_adc_nids;
2930 spec->mux_nids = stac927x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01002931 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002932 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002933 spec->init = stac927x_core_init;
2934 spec->mixer = stac927x_mixer;
2935 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01002936
Matthew Ranostay7f168592007-10-18 17:38:17 +02002937 switch (codec->subsystem_id) {
Matthew Ranostayb222fe52007-11-07 15:54:45 +01002938 case 0x10280242: /* STAC 9228 */
2939 case 0x102801f3:
2940 case 0x1028020A:
2941 case 0x10280209:
Matthew Ranostay7f168592007-10-18 17:38:17 +02002942 spec->dmic_nids = stac927x_dmic_nids;
2943 spec->num_dmics = STAC927X_NUM_DMICS;
Matthew Ranostay83eef752007-10-22 12:27:10 +02002944 spec->dmux_nid = 0x1b;
Matthew Ranostayf1f208d2007-11-05 15:30:13 +01002945
2946 /* Enable DMIC0 */
2947 stac92xx_set_config_reg(codec, 0x13, 0x90a60040);
2948
2949 /* GPIO2 High = Enable EAPD */
2950 spec->gpio_mask = spec->gpio_data = 0x00000004;
Matthew Ranostay7f168592007-10-18 17:38:17 +02002951 break;
2952 default:
Matthew Ranostayf1f208d2007-11-05 15:30:13 +01002953 spec->num_dmics = 0;
2954
2955 /* GPIO0 High = Enable EAPD */
2956 spec->gpio_mask = spec->gpio_data = 0x00000001;
Matthew Ranostay7f168592007-10-18 17:38:17 +02002957 }
2958
Matt Porter3cc08dc2006-01-23 15:27:49 +01002959 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai82599802007-07-31 15:56:24 +02002960 stac92xx_enable_gpio_mask(codec);
Matthew Ranostay92a22be2007-06-19 16:48:28 +02002961
Matt Porter3cc08dc2006-01-23 15:27:49 +01002962 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002963 if (!err) {
2964 if (spec->board_config < 0) {
2965 printk(KERN_WARNING "hda_codec: No auto-config is "
2966 "available, default to model=ref\n");
2967 spec->board_config = STAC_D965_REF;
2968 goto again;
2969 }
2970 err = -EINVAL;
2971 }
Mattc7d4b2f2005-06-27 14:59:41 +02002972 if (err < 0) {
2973 stac92xx_free(codec);
2974 return err;
2975 }
Matt2f2f4252005-04-13 14:45:30 +02002976
2977 codec->patch_ops = stac92xx_patch_ops;
2978
2979 return 0;
2980}
2981
Matt Porterf3302a52006-07-31 12:49:34 +02002982static int patch_stac9205(struct hda_codec *codec)
2983{
2984 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02002985 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02002986
2987 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2988 if (spec == NULL)
2989 return -ENOMEM;
2990
2991 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02002992 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02002993 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002994 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
2995 stac9205_models,
2996 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01002997 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02002998 if (spec->board_config < 0) {
2999 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
3000 err = stac92xx_save_bios_config_regs(codec);
3001 if (err < 0) {
3002 stac92xx_free(codec);
3003 return err;
3004 }
3005 spec->pin_configs = spec->bios_pin_configs;
3006 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02003007 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
3008 stac92xx_set_config_regs(codec);
3009 }
3010
3011 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003012 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02003013 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01003014 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02003015 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02003016 spec->num_dmics = STAC9205_NUM_DMICS;
Matt Porter8b657272006-10-26 17:12:59 +02003017 spec->dmux_nid = 0x1d;
Matt Porterf3302a52006-07-31 12:49:34 +02003018
3019 spec->init = stac9205_core_init;
3020 spec->mixer = stac9205_mixer;
3021
3022 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02003023
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003024 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003025 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02003026 /* Enable SPDIF in/out */
3027 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
3028 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01003029
Takashi Iwai82599802007-07-31 15:56:24 +02003030 spec->gpio_mask = 0x00000007; /* GPIO0-2 */
Matthew Ranostay87d48362007-07-17 11:52:24 +02003031 /* GPIO0 High = EAPD, GPIO1 Low = DRM,
3032 * GPIO2 High = Headphone Mute
3033 */
Takashi Iwai82599802007-07-31 15:56:24 +02003034 spec->gpio_data = 0x00000005;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003035 break;
3036 default:
3037 /* GPIO0 High = EAPD */
3038 spec->gpio_mask = spec->gpio_data = 0x00000001;
3039 break;
3040 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02003041
Takashi Iwai82599802007-07-31 15:56:24 +02003042 stac92xx_enable_gpio_mask(codec);
Matt Porterf3302a52006-07-31 12:49:34 +02003043 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003044 if (!err) {
3045 if (spec->board_config < 0) {
3046 printk(KERN_WARNING "hda_codec: No auto-config is "
3047 "available, default to model=ref\n");
3048 spec->board_config = STAC_9205_REF;
3049 goto again;
3050 }
3051 err = -EINVAL;
3052 }
Matt Porterf3302a52006-07-31 12:49:34 +02003053 if (err < 0) {
3054 stac92xx_free(codec);
3055 return err;
3056 }
3057
3058 codec->patch_ops = stac92xx_patch_ops;
3059
3060 return 0;
3061}
3062
Matt2f2f4252005-04-13 14:45:30 +02003063/*
Guillaume Munch6d859062006-08-22 17:15:47 +02003064 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01003065 */
3066
Guillaume Munch99ccc562006-08-16 19:35:12 +02003067/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003068static hda_nid_t vaio_dacs[] = { 0x2 };
3069#define VAIO_HP_DAC 0x5
3070static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
3071static hda_nid_t vaio_mux_nids[] = { 0x15 };
3072
3073static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02003074 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01003075 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02003076 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003077 { "Mic Jack", 0x1 },
3078 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01003079 { "PCM", 0x3 },
3080 }
3081};
3082
3083static struct hda_verb vaio_init[] = {
3084 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003085 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01003086 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3087 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3088 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3089 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003090 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003091 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3092 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3093 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3094 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3095 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3096 {}
3097};
3098
Guillaume Munch6d859062006-08-22 17:15:47 +02003099static struct hda_verb vaio_ar_init[] = {
3100 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
3101 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3102 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3103 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3104/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
3105 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003106 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02003107 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3108 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3109/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
3110 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3111 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3112 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3113 {}
3114};
3115
Takashi Iwaidb064e52006-03-16 16:04:58 +01003116/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003117static struct hda_bind_ctls vaio_bind_master_vol = {
3118 .ops = &snd_hda_bind_vol,
3119 .values = {
3120 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3121 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3122 0
3123 },
3124};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003125
3126/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003127static struct hda_bind_ctls vaio_bind_master_sw = {
3128 .ops = &snd_hda_bind_sw,
3129 .values = {
3130 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3131 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3132 0,
3133 },
3134};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003135
3136static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003137 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3138 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003139 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3140 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3141 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3142 {
3143 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3144 .name = "Capture Source",
3145 .count = 1,
3146 .info = stac92xx_mux_enum_info,
3147 .get = stac92xx_mux_enum_get,
3148 .put = stac92xx_mux_enum_put,
3149 },
3150 {}
3151};
3152
Guillaume Munch6d859062006-08-22 17:15:47 +02003153static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003154 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3155 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Guillaume Munch6d859062006-08-22 17:15:47 +02003156 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3157 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3158 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3159 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
3160 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
3161 {
3162 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3163 .name = "Capture Source",
3164 .count = 1,
3165 .info = stac92xx_mux_enum_info,
3166 .get = stac92xx_mux_enum_get,
3167 .put = stac92xx_mux_enum_put,
3168 },
3169 {}
3170};
3171
3172static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01003173 .build_controls = stac92xx_build_controls,
3174 .build_pcms = stac92xx_build_pcms,
3175 .init = stac92xx_init,
3176 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02003177#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01003178 .resume = stac92xx_resume,
3179#endif
3180};
3181
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003182static int stac9872_vaio_init(struct hda_codec *codec)
3183{
3184 int err;
3185
3186 err = stac92xx_init(codec);
3187 if (err < 0)
3188 return err;
3189 if (codec->patch_ops.unsol_event)
3190 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
3191 return 0;
3192}
3193
3194static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
3195{
Jiang Zhe40c1d302007-11-12 13:05:16 +01003196 if (get_hp_pin_presence(codec, 0x0a)) {
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003197 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3198 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3199 } else {
3200 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3201 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3202 }
3203}
3204
3205static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
3206{
3207 switch (res >> 26) {
3208 case STAC_HP_EVENT:
3209 stac9872_vaio_hp_detect(codec, res);
3210 break;
3211 }
3212}
3213
3214static struct hda_codec_ops stac9872_vaio_patch_ops = {
3215 .build_controls = stac92xx_build_controls,
3216 .build_pcms = stac92xx_build_pcms,
3217 .init = stac9872_vaio_init,
3218 .free = stac92xx_free,
3219 .unsol_event = stac9872_vaio_unsol_event,
3220#ifdef CONFIG_PM
3221 .resume = stac92xx_resume,
3222#endif
3223};
3224
Guillaume Munch6d859062006-08-22 17:15:47 +02003225enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
3226 CXD9872RD_VAIO,
3227 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
3228 STAC9872AK_VAIO,
3229 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
3230 STAC9872K_VAIO,
3231 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003232 CXD9872AKD_VAIO,
3233 STAC_9872_MODELS,
3234};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003235
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003236static const char *stac9872_models[STAC_9872_MODELS] = {
3237 [CXD9872RD_VAIO] = "vaio",
3238 [CXD9872AKD_VAIO] = "vaio-ar",
3239};
3240
3241static struct snd_pci_quirk stac9872_cfg_tbl[] = {
3242 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
3243 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
3244 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01003245 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003246 {}
3247};
3248
Guillaume Munch6d859062006-08-22 17:15:47 +02003249static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01003250{
3251 struct sigmatel_spec *spec;
3252 int board_config;
3253
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003254 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
3255 stac9872_models,
3256 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01003257 if (board_config < 0)
3258 /* unknown config, let generic-parser do its job... */
3259 return snd_hda_parse_generic_codec(codec);
3260
3261 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3262 if (spec == NULL)
3263 return -ENOMEM;
3264
3265 codec->spec = spec;
3266 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02003267 case CXD9872RD_VAIO:
3268 case STAC9872AK_VAIO:
3269 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01003270 spec->mixer = vaio_mixer;
3271 spec->init = vaio_init;
3272 spec->multiout.max_channels = 2;
3273 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3274 spec->multiout.dac_nids = vaio_dacs;
3275 spec->multiout.hp_nid = VAIO_HP_DAC;
3276 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3277 spec->adc_nids = vaio_adcs;
3278 spec->input_mux = &vaio_mux;
3279 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003280 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003281 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02003282
3283 case CXD9872AKD_VAIO:
3284 spec->mixer = vaio_ar_mixer;
3285 spec->init = vaio_ar_init;
3286 spec->multiout.max_channels = 2;
3287 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3288 spec->multiout.dac_nids = vaio_dacs;
3289 spec->multiout.hp_nid = VAIO_HP_DAC;
3290 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3291 spec->adc_nids = vaio_adcs;
3292 spec->input_mux = &vaio_mux;
3293 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003294 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02003295 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003296 }
3297
Takashi Iwaidb064e52006-03-16 16:04:58 +01003298 return 0;
3299}
3300
3301
3302/*
Matt2f2f4252005-04-13 14:45:30 +02003303 * patch entries
3304 */
3305struct hda_codec_preset snd_hda_preset_sigmatel[] = {
3306 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
3307 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
3308 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
3309 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
3310 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
3311 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
3312 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02003313 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
3314 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
3315 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
3316 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
3317 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
3318 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01003319 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
3320 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
3321 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
3322 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
3323 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
3324 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
3325 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
3326 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
3327 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
3328 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01003329 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
3330 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
3331 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
3332 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
3333 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
3334 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02003335 /* The following does not take into account .id=0x83847661 when subsys =
3336 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
3337 * currently not fully supported.
3338 */
3339 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
3340 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
3341 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02003342 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
3343 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
3344 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
3345 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
3346 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
3347 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
3348 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
3349 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostaye035b842007-11-06 11:53:55 +01003350 { .id = 0x111d76b0, .name = "92HD71BXX", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02003351 {} /* terminator */
3352};