blob: caf48edaa921f629870b5e39bc4e83a94d56c52d [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
Matt2f2f4252005-04-13 14:45:30 +020027#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/slab.h>
30#include <linux/pci.h>
31#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020032#include <sound/asoundef.h>
Matt2f2f4252005-04-13 14:45:30 +020033#include "hda_codec.h"
34#include "hda_local.h"
35
Matt4e550962005-07-04 17:51:39 +020036#define NUM_CONTROL_ALLOC 32
Matthew Ranostaya64135a2008-01-10 16:55:06 +010037#define STAC_PWR_EVENT 0x20
38#define STAC_HP_EVENT 0x30
Matt4e550962005-07-04 17:51:39 +020039
Takashi Iwaif5fcc132006-11-24 17:07:44 +010040enum {
41 STAC_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020042 STAC_9200_DELL_D21,
43 STAC_9200_DELL_D22,
44 STAC_9200_DELL_D23,
45 STAC_9200_DELL_M21,
46 STAC_9200_DELL_M22,
47 STAC_9200_DELL_M23,
48 STAC_9200_DELL_M24,
49 STAC_9200_DELL_M25,
50 STAC_9200_DELL_M26,
51 STAC_9200_DELL_M27,
Takashi Iwai1194b5b2007-10-10 10:04:26 +020052 STAC_9200_GATEWAY,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010053 STAC_9200_MODELS
54};
55
56enum {
57 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020058 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020059 STAC_9205_DELL_M43,
60 STAC_9205_DELL_M44,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010061 STAC_9205_MODELS
62};
63
64enum {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010065 STAC_92HD73XX_REF,
66 STAC_92HD73XX_MODELS
67};
68
69enum {
Matthew Ranostaye035b842007-11-06 11:53:55 +010070 STAC_92HD71BXX_REF,
71 STAC_92HD71BXX_MODELS
72};
73
74enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010075 STAC_925x_REF,
76 STAC_M2_2,
77 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020078 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +010079 STAC_925x_MODELS
80};
81
82enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +010083 STAC_D945_REF,
84 STAC_D945GTP3,
85 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +020086 STAC_INTEL_MAC_V1,
87 STAC_INTEL_MAC_V2,
88 STAC_INTEL_MAC_V3,
89 STAC_INTEL_MAC_V4,
90 STAC_INTEL_MAC_V5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020091 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +010092 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +010093 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +010094 STAC_MACBOOK_PRO_V1,
95 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +020096 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +020097 STAC_IMAC_INTEL_20,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020098 STAC_922X_DELL_D81,
99 STAC_922X_DELL_D82,
100 STAC_922X_DELL_M81,
101 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100102 STAC_922X_MODELS
103};
104
105enum {
106 STAC_D965_REF,
107 STAC_D965_3ST,
108 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200109 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100110 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100111 STAC_927X_MODELS
112};
Matt Porter403d1942005-11-29 15:00:51 +0100113
Matt2f2f4252005-04-13 14:45:30 +0200114struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100115 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200116 unsigned int num_mixers;
117
Matt Porter403d1942005-11-29 15:00:51 +0100118 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +0200119 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +0100120 unsigned int line_switch: 1;
121 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100122 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100123 unsigned int hp_detect: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200124
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100125 /* gpio lines */
126 unsigned int gpio_mask;
127 unsigned int gpio_dir;
128 unsigned int gpio_data;
129 unsigned int gpio_mute;
130
131 /* analog loopback */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100132 unsigned char aloopback_mask;
133 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200134
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100135 /* power management */
136 unsigned int num_pwrs;
137 hda_nid_t *pwr_nids;
138
Matt2f2f4252005-04-13 14:45:30 +0200139 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100140 struct hda_input_mux *mono_mux;
141 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200142 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100143 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200144
145 /* capture */
146 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200147 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200148 hda_nid_t *mux_nids;
149 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200150 hda_nid_t *dmic_nids;
151 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100152 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100153 unsigned int num_dmuxes;
Mattdabbed62005-06-14 10:19:34 +0200154 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100155 hda_nid_t mono_nid;
Matt2f2f4252005-04-13 14:45:30 +0200156
Matt2f2f4252005-04-13 14:45:30 +0200157 /* pin widgets */
158 hda_nid_t *pin_nids;
159 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200160 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200161 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200162
163 /* codec specific stuff */
164 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100165 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200166
167 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200168 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100169 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200170 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100171 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200172
Matt Porter403d1942005-11-29 15:00:51 +0100173 /* i/o switches */
174 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200175 unsigned int clfe_swap;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200176 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200177
Mattc7d4b2f2005-06-27 14:59:41 +0200178 struct hda_pcm pcm_rec[2]; /* PCM information */
179
180 /* dynamic controls and input_mux */
181 struct auto_pin_cfg autocfg;
182 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100183 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200184 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200185 struct hda_input_mux private_imux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100186 struct hda_input_mux private_mono_mux;
Takashi Iwai2134ea42008-01-10 16:53:55 +0100187
188 /* virtual master */
189 unsigned int vmaster_tlv[4];
Matt2f2f4252005-04-13 14:45:30 +0200190};
191
192static hda_nid_t stac9200_adc_nids[1] = {
193 0x03,
194};
195
196static hda_nid_t stac9200_mux_nids[1] = {
197 0x0c,
198};
199
200static hda_nid_t stac9200_dac_nids[1] = {
201 0x02,
202};
203
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100204static hda_nid_t stac92hd73xx_pwr_nids[8] = {
205 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
206 0x0f, 0x10, 0x11
207};
208
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100209static hda_nid_t stac92hd73xx_adc_nids[2] = {
210 0x1a, 0x1b
211};
212
213#define STAC92HD73XX_NUM_DMICS 2
214static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
215 0x13, 0x14, 0
216};
217
218#define STAC92HD73_DAC_COUNT 5
219static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
220 0x15, 0x16, 0x17, 0x18, 0x19,
221};
222
223static hda_nid_t stac92hd73xx_mux_nids[4] = {
224 0x28, 0x29, 0x2a, 0x2b,
225};
226
227static hda_nid_t stac92hd73xx_dmux_nids[2] = {
228 0x20, 0x21,
229};
230
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100231static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
232 0x0a, 0x0d, 0x0f
233};
234
Matthew Ranostaye035b842007-11-06 11:53:55 +0100235static hda_nid_t stac92hd71bxx_adc_nids[2] = {
236 0x12, 0x13,
237};
238
239static hda_nid_t stac92hd71bxx_mux_nids[2] = {
240 0x1a, 0x1b
241};
242
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100243static hda_nid_t stac92hd71bxx_dmux_nids[1] = {
244 0x1c,
245};
246
Matthew Ranostaye035b842007-11-06 11:53:55 +0100247static hda_nid_t stac92hd71bxx_dac_nids[2] = {
248 0x10, /*0x11, */
249};
250
251#define STAC92HD71BXX_NUM_DMICS 2
252static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
253 0x18, 0x19, 0
254};
255
Tobin Davis8e21c342007-01-08 11:04:17 +0100256static hda_nid_t stac925x_adc_nids[1] = {
257 0x03,
258};
259
260static hda_nid_t stac925x_mux_nids[1] = {
261 0x0f,
262};
263
264static hda_nid_t stac925x_dac_nids[1] = {
265 0x02,
266};
267
Takashi Iwaif6e98522007-10-16 14:27:04 +0200268#define STAC925X_NUM_DMICS 1
269static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
270 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200271};
272
Takashi Iwai1697055e2007-12-18 18:05:52 +0100273static hda_nid_t stac925x_dmux_nids[1] = {
274 0x14,
275};
276
Matt2f2f4252005-04-13 14:45:30 +0200277static hda_nid_t stac922x_adc_nids[2] = {
278 0x06, 0x07,
279};
280
281static hda_nid_t stac922x_mux_nids[2] = {
282 0x12, 0x13,
283};
284
Matt Porter3cc08dc2006-01-23 15:27:49 +0100285static hda_nid_t stac927x_adc_nids[3] = {
286 0x07, 0x08, 0x09
287};
288
289static hda_nid_t stac927x_mux_nids[3] = {
290 0x15, 0x16, 0x17
291};
292
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100293static hda_nid_t stac927x_dmux_nids[1] = {
294 0x1b,
295};
296
Matthew Ranostay7f168592007-10-18 17:38:17 +0200297#define STAC927X_NUM_DMICS 2
298static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
299 0x13, 0x14, 0
300};
301
Matt Porterf3302a52006-07-31 12:49:34 +0200302static hda_nid_t stac9205_adc_nids[2] = {
303 0x12, 0x13
304};
305
306static hda_nid_t stac9205_mux_nids[2] = {
307 0x19, 0x1a
308};
309
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100310static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100311 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100312};
313
Takashi Iwaif6e98522007-10-16 14:27:04 +0200314#define STAC9205_NUM_DMICS 2
315static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
316 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200317};
318
Mattc7d4b2f2005-06-27 14:59:41 +0200319static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200320 0x08, 0x09, 0x0d, 0x0e,
321 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200322};
323
Tobin Davis8e21c342007-01-08 11:04:17 +0100324static hda_nid_t stac925x_pin_nids[8] = {
325 0x07, 0x08, 0x0a, 0x0b,
326 0x0c, 0x0d, 0x10, 0x11,
327};
328
Matt2f2f4252005-04-13 14:45:30 +0200329static hda_nid_t stac922x_pin_nids[10] = {
330 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
331 0x0f, 0x10, 0x11, 0x15, 0x1b,
332};
333
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100334static hda_nid_t stac92hd73xx_pin_nids[12] = {
335 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
336 0x0f, 0x10, 0x11, 0x12, 0x13,
337 0x14, 0x22
338};
339
Matthew Ranostaye035b842007-11-06 11:53:55 +0100340static hda_nid_t stac92hd71bxx_pin_nids[10] = {
341 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
342 0x0f, 0x14, 0x18, 0x19, 0x1e,
343};
344
Matt Porter3cc08dc2006-01-23 15:27:49 +0100345static hda_nid_t stac927x_pin_nids[14] = {
346 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
347 0x0f, 0x10, 0x11, 0x12, 0x13,
348 0x14, 0x21, 0x22, 0x23,
349};
350
Matt Porterf3302a52006-07-31 12:49:34 +0200351static hda_nid_t stac9205_pin_nids[12] = {
352 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
353 0x0f, 0x14, 0x16, 0x17, 0x18,
354 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200355};
356
Matt Porter8b657272006-10-26 17:12:59 +0200357static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
358 struct snd_ctl_elem_info *uinfo)
359{
360 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
361 struct sigmatel_spec *spec = codec->spec;
362 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
363}
364
365static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
366 struct snd_ctl_elem_value *ucontrol)
367{
368 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
369 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100370 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200371
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100372 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200373 return 0;
374}
375
376static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
377 struct snd_ctl_elem_value *ucontrol)
378{
379 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
380 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100381 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200382
383 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100384 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200385}
386
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100387static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200388{
389 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
390 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200391 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200392}
393
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100394static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200395{
396 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
397 struct sigmatel_spec *spec = codec->spec;
398 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
399
400 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
401 return 0;
402}
403
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100404static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200405{
406 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
407 struct sigmatel_spec *spec = codec->spec;
408 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
409
Mattc7d4b2f2005-06-27 14:59:41 +0200410 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200411 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
412}
413
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100414static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
415 struct snd_ctl_elem_info *uinfo)
416{
417 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
418 struct sigmatel_spec *spec = codec->spec;
419 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
420}
421
422static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
423 struct snd_ctl_elem_value *ucontrol)
424{
425 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
426 struct sigmatel_spec *spec = codec->spec;
427
428 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
429 return 0;
430}
431
432static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
433 struct snd_ctl_elem_value *ucontrol)
434{
435 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
436 struct sigmatel_spec *spec = codec->spec;
437
438 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
439 spec->mono_nid, &spec->cur_mmux);
440}
441
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200442#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
443
444static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
445 struct snd_ctl_elem_value *ucontrol)
446{
447 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100448 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200449 struct sigmatel_spec *spec = codec->spec;
450
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100451 ucontrol->value.integer.value[0] = !!(spec->aloopback &
452 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200453 return 0;
454}
455
456static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
457 struct snd_ctl_elem_value *ucontrol)
458{
459 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
460 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100461 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200462 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100463 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200464
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100465 idx_val = spec->aloopback_mask << idx;
466 if (ucontrol->value.integer.value[0])
467 val = spec->aloopback | idx_val;
468 else
469 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100470 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200471 return 0;
472
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100473 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200474
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100475 /* Only return the bits defined by the shift value of the
476 * first two bytes of the mask
477 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200478 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100479 kcontrol->private_value & 0xFFFF, 0x0);
480 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200481
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100482 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200483 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100484 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200485 } else {
486 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100487 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200488 }
489
490 snd_hda_codec_write_cache(codec, codec->afg, 0,
491 kcontrol->private_value >> 16, dac_mode);
492
493 return 1;
494}
495
Mattc7d4b2f2005-06-27 14:59:41 +0200496static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200497 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200498 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200499 {}
500};
501
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200502static struct hda_verb stac9200_eapd_init[] = {
503 /* set dac0mux for dac converter */
504 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
505 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
506 {}
507};
508
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100509static struct hda_verb stac92hd73xx_6ch_core_init[] = {
510 /* set master volume and direct control */
511 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
512 /* setup audio connections */
513 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
514 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
515 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
516 /* setup adcs to point to mixer */
517 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
518 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100519 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
520 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
521 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
522 /* setup import muxs */
523 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
524 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
525 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
526 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
527 {}
528};
529
530static struct hda_verb stac92hd73xx_8ch_core_init[] = {
531 /* set master volume and direct control */
532 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
533 /* setup audio connections */
534 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
535 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
536 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
537 /* connect hp ports to dac3 */
538 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
539 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
540 /* setup adcs to point to mixer */
541 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
542 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100543 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
544 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
545 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
546 /* setup import muxs */
547 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
548 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
549 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
550 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
551 {}
552};
553
554static struct hda_verb stac92hd73xx_10ch_core_init[] = {
555 /* set master volume and direct control */
556 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
557 /* setup audio connections */
558 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
559 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
560 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
561 /* dac3 is connected to import3 mux */
562 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
563 /* connect hp ports to dac4 */
564 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
565 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
566 /* setup adcs to point to mixer */
567 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
568 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100569 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
570 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
571 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
572 /* setup import muxs */
573 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
574 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
575 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
576 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
577 {}
578};
579
Matthew Ranostaye035b842007-11-06 11:53:55 +0100580static struct hda_verb stac92hd71bxx_core_init[] = {
581 /* set master volume and direct control */
582 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
583 /* connect headphone jack to dac1 */
584 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100585 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
586 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
587 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
588 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
589 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100590};
591
592static struct hda_verb stac92hd71bxx_analog_core_init[] = {
593 /* set master volume and direct control */
594 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
595 /* connect headphone jack to dac1 */
596 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay9b359472007-11-07 13:03:12 +0100597 /* connect ports 0d and 0f to audio mixer */
598 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2},
599 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100600 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
Matthew Ranostay9b359472007-11-07 13:03:12 +0100601 /* unmute dac0 input in audio mixer */
602 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100603 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
604 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
605 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
606 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100607 {}
608};
609
Tobin Davis8e21c342007-01-08 11:04:17 +0100610static struct hda_verb stac925x_core_init[] = {
611 /* set dac0mux for dac converter */
612 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
613 {}
614};
615
Mattc7d4b2f2005-06-27 14:59:41 +0200616static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200617 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200618 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200619 {}
620};
621
Tobin Davis93ed1502006-09-01 21:03:12 +0200622static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200623 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200624 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200625 /* unmute node 0x1b */
626 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
627 /* select node 0x03 as DAC */
628 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
629 {}
630};
631
Matt Porter3cc08dc2006-01-23 15:27:49 +0100632static struct hda_verb stac927x_core_init[] = {
633 /* set master volume and direct control */
634 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
635 {}
636};
637
Matt Porterf3302a52006-07-31 12:49:34 +0200638static struct hda_verb stac9205_core_init[] = {
639 /* set master volume and direct control */
640 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
641 {}
642};
643
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100644#define STAC_MONO_MUX \
645 { \
646 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
647 .name = "Mono Mux", \
648 .count = 1, \
649 .info = stac92xx_mono_mux_enum_info, \
650 .get = stac92xx_mono_mux_enum_get, \
651 .put = stac92xx_mono_mux_enum_put, \
652 }
653
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200654#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200655 { \
656 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
657 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200658 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200659 .info = stac92xx_mux_enum_info, \
660 .get = stac92xx_mux_enum_get, \
661 .put = stac92xx_mux_enum_put, \
662 }
663
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100664#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200665 { \
666 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
667 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100668 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200669 .info = stac92xx_aloopback_info, \
670 .get = stac92xx_aloopback_get, \
671 .put = stac92xx_aloopback_put, \
672 .private_value = verb_read | (verb_write << 16), \
673 }
674
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100675static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200676 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
677 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200678 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200679 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
680 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200681 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200682 { } /* end */
683};
684
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100685static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100686 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
687
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100688 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
689 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
690
691 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
692 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
693
694 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
695 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
696
697 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
698 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
699
700 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
701 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
702
703 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
704 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
705
706 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
707 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
708 { } /* end */
709};
710
711static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100712 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
713
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100714 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
715 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
716
717 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
718 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
719
720 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
721 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
722
723 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
724 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
725
726 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
727 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
728
729 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
730 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
731
732 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
733 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
734 { } /* end */
735};
736
737static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100738 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
739
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100740 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
741 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
742
743 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
744 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
745
746 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
747 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
748
749 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
750 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
751
752 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
753 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
754
755 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
756 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
757
758 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
759 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
760 { } /* end */
761};
762
Matthew Ranostay541eee82007-12-14 12:08:04 +0100763static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100764 STAC_INPUT_SOURCE(2),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100765
Matthew Ranostay9b359472007-11-07 13:03:12 +0100766 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
767 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
768 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
769
770 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
771 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
772 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
773
774 HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT),
775 HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100776 { } /* end */
777};
778
Matthew Ranostay541eee82007-12-14 12:08:04 +0100779static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +0100780 STAC_INPUT_SOURCE(2),
781 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
782
Matthew Ranostay541eee82007-12-14 12:08:04 +0100783 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
784 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
785 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
786
787 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
788 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
789 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
790 { } /* end */
791};
792
Tobin Davis8e21c342007-01-08 11:04:17 +0100793static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200794 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +0100795 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
796 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
797 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
798 { } /* end */
799};
800
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100801static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200802 STAC_INPUT_SOURCE(2),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100803 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200804
805 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
806 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
807 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
808
809 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
810 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
811 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
812
813 { } /* end */
814};
815
816/* This needs to be generated dynamically based on sequence */
817static struct snd_kcontrol_new stac922x_mixer[] = {
818 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200819 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
820 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
821 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
822
823 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
824 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
825 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
826 { } /* end */
827};
828
829
830static struct snd_kcontrol_new stac927x_mixer[] = {
831 STAC_INPUT_SOURCE(3),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100832 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200833
834 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
835 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
836 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
837
838 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
839 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
840 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
841
842 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
843 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
844 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +0200845 { } /* end */
846};
847
Takashi Iwai1697055e2007-12-18 18:05:52 +0100848static struct snd_kcontrol_new stac_dmux_mixer = {
849 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
850 .name = "Digital Input Source",
851 /* count set later */
852 .info = stac92xx_dmux_enum_info,
853 .get = stac92xx_dmux_enum_get,
854 .put = stac92xx_dmux_enum_put,
855};
856
Takashi Iwai2134ea42008-01-10 16:53:55 +0100857static const char *slave_vols[] = {
858 "Front Playback Volume",
859 "Surround Playback Volume",
860 "Center Playback Volume",
861 "LFE Playback Volume",
862 "Side Playback Volume",
863 "Headphone Playback Volume",
864 "Headphone Playback Volume",
865 "Speaker Playback Volume",
866 "External Speaker Playback Volume",
867 "Speaker2 Playback Volume",
868 NULL
869};
870
871static const char *slave_sws[] = {
872 "Front Playback Switch",
873 "Surround Playback Switch",
874 "Center Playback Switch",
875 "LFE Playback Switch",
876 "Side Playback Switch",
877 "Headphone Playback Switch",
878 "Headphone Playback Switch",
879 "Speaker Playback Switch",
880 "External Speaker Playback Switch",
881 "Speaker2 Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +0100882 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100883 NULL
884};
885
Matt2f2f4252005-04-13 14:45:30 +0200886static int stac92xx_build_controls(struct hda_codec *codec)
887{
888 struct sigmatel_spec *spec = codec->spec;
889 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200890 int i;
Matt2f2f4252005-04-13 14:45:30 +0200891
892 err = snd_hda_add_new_ctls(codec, spec->mixer);
893 if (err < 0)
894 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200895
896 for (i = 0; i < spec->num_mixers; i++) {
897 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
898 if (err < 0)
899 return err;
900 }
Takashi Iwai1697055e2007-12-18 18:05:52 +0100901 if (spec->num_dmuxes > 0) {
902 stac_dmux_mixer.count = spec->num_dmuxes;
903 err = snd_ctl_add(codec->bus->card,
904 snd_ctl_new1(&stac_dmux_mixer, codec));
905 if (err < 0)
906 return err;
907 }
Mattc7d4b2f2005-06-27 14:59:41 +0200908
Mattdabbed62005-06-14 10:19:34 +0200909 if (spec->multiout.dig_out_nid) {
910 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
911 if (err < 0)
912 return err;
913 }
914 if (spec->dig_in_nid) {
915 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
916 if (err < 0)
917 return err;
918 }
Takashi Iwai2134ea42008-01-10 16:53:55 +0100919
920 /* if we have no master control, let's create it */
921 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
922 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
923 HDA_OUTPUT, spec->vmaster_tlv);
924 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
925 spec->vmaster_tlv, slave_vols);
926 if (err < 0)
927 return err;
928 }
929 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
930 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
931 NULL, slave_sws);
932 if (err < 0)
933 return err;
934 }
935
Mattdabbed62005-06-14 10:19:34 +0200936 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200937}
938
Matt Porter403d1942005-11-29 15:00:51 +0100939static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200940 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200941 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
942};
943
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200944/*
945 STAC 9200 pin configs for
946 102801A8
947 102801DE
948 102801E8
949*/
950static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200951 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
952 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200953};
954
955/*
956 STAC 9200 pin configs for
957 102801C0
958 102801C1
959*/
960static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200961 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
962 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200963};
964
965/*
966 STAC 9200 pin configs for
967 102801C4 (Dell Dimension E310)
968 102801C5
969 102801C7
970 102801D9
971 102801DA
972 102801E3
973*/
974static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200975 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
976 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200977};
978
979
980/*
981 STAC 9200-32 pin configs for
982 102801B5 (Dell Inspiron 630m)
983 102801D8 (Dell Inspiron 640m)
984*/
985static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200986 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
987 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200988};
989
990/*
991 STAC 9200-32 pin configs for
992 102801C2 (Dell Latitude D620)
993 102801C8
994 102801CC (Dell Latitude D820)
995 102801D4
996 102801D6
997*/
998static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200999 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1000 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001001};
1002
1003/*
1004 STAC 9200-32 pin configs for
1005 102801CE (Dell XPS M1710)
1006 102801CF (Dell Precision M90)
1007*/
1008static unsigned int dell9200_m23_pin_configs[8] = {
1009 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1010 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1011};
1012
1013/*
1014 STAC 9200-32 pin configs for
1015 102801C9
1016 102801CA
1017 102801CB (Dell Latitude 120L)
1018 102801D3
1019*/
1020static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001021 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1022 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001023};
1024
1025/*
1026 STAC 9200-32 pin configs for
1027 102801BD (Dell Inspiron E1505n)
1028 102801EE
1029 102801EF
1030*/
1031static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001032 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1033 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001034};
1035
1036/*
1037 STAC 9200-32 pin configs for
1038 102801F5 (Dell Inspiron 1501)
1039 102801F6
1040*/
1041static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001042 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1043 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001044};
1045
1046/*
1047 STAC 9200-32
1048 102801CD (Dell Inspiron E1705/9400)
1049*/
1050static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001051 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1052 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001053};
1054
1055
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001056static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1057 [STAC_REF] = ref9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001058 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1059 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1060 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1061 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1062 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1063 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1064 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1065 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1066 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1067 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001068};
1069
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001070static const char *stac9200_models[STAC_9200_MODELS] = {
1071 [STAC_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001072 [STAC_9200_DELL_D21] = "dell-d21",
1073 [STAC_9200_DELL_D22] = "dell-d22",
1074 [STAC_9200_DELL_D23] = "dell-d23",
1075 [STAC_9200_DELL_M21] = "dell-m21",
1076 [STAC_9200_DELL_M22] = "dell-m22",
1077 [STAC_9200_DELL_M23] = "dell-m23",
1078 [STAC_9200_DELL_M24] = "dell-m24",
1079 [STAC_9200_DELL_M25] = "dell-m25",
1080 [STAC_9200_DELL_M26] = "dell-m26",
1081 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001082 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001083};
1084
1085static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1086 /* SigmaTel reference board */
1087 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1088 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001089 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001090 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1091 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001092 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001093 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1094 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1095 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1096 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1097 "unknown Dell", STAC_9200_DELL_D22),
1098 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1099 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001100 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001101 "Dell Latitude D620", STAC_9200_DELL_M22),
1102 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1103 "unknown Dell", STAC_9200_DELL_D23),
1104 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1105 "unknown Dell", STAC_9200_DELL_D23),
1106 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1107 "unknown Dell", STAC_9200_DELL_M22),
1108 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1109 "unknown Dell", STAC_9200_DELL_M24),
1110 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1111 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001112 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001113 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001114 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001115 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001116 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001117 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001118 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001119 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001120 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001121 "Dell Precision M90", STAC_9200_DELL_M23),
1122 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1123 "unknown Dell", STAC_9200_DELL_M22),
1124 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1125 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001126 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001127 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001128 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001129 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1130 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1131 "unknown Dell", STAC_9200_DELL_D23),
1132 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1133 "unknown Dell", STAC_9200_DELL_D23),
1134 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1135 "unknown Dell", STAC_9200_DELL_D21),
1136 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1137 "unknown Dell", STAC_9200_DELL_D23),
1138 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1139 "unknown Dell", STAC_9200_DELL_D21),
1140 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1141 "unknown Dell", STAC_9200_DELL_M25),
1142 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1143 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001144 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001145 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1146 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1147 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001148 /* Panasonic */
1149 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001150 /* Gateway machines needs EAPD to be set on resume */
1151 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1152 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1153 STAC_9200_GATEWAY),
1154 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1155 STAC_9200_GATEWAY),
Matt Porter403d1942005-11-29 15:00:51 +01001156 {} /* terminator */
1157};
1158
Tobin Davis8e21c342007-01-08 11:04:17 +01001159static unsigned int ref925x_pin_configs[8] = {
1160 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001161 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001162};
1163
1164static unsigned int stac925x_MA6_pin_configs[8] = {
1165 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1166 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
1167};
1168
Tobin Davis2c11f952007-05-17 09:36:34 +02001169static unsigned int stac925x_PA6_pin_configs[8] = {
1170 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1171 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
1172};
1173
Tobin Davis8e21c342007-01-08 11:04:17 +01001174static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +02001175 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
1176 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001177};
1178
1179static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1180 [STAC_REF] = ref925x_pin_configs,
1181 [STAC_M2_2] = stac925xM2_2_pin_configs,
1182 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +02001183 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001184};
1185
1186static const char *stac925x_models[STAC_925x_MODELS] = {
1187 [STAC_REF] = "ref",
1188 [STAC_M2_2] = "m2-2",
1189 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +02001190 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001191};
1192
1193static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1194 /* SigmaTel reference board */
1195 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001196 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +01001197 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
1198 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
1199 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +02001200 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +01001201 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
1202 {} /* terminator */
1203};
1204
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001205static unsigned int ref92hd73xx_pin_configs[12] = {
1206 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1207 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1208 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1209};
1210
1211static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1212 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1213};
1214
1215static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1216 [STAC_92HD73XX_REF] = "ref",
1217};
1218
1219static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1220 /* SigmaTel reference board */
1221 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1222 "DFI LanParty", STAC_92HD73XX_REF),
1223 {} /* terminator */
1224};
1225
Matthew Ranostaye035b842007-11-06 11:53:55 +01001226static unsigned int ref92hd71bxx_pin_configs[10] = {
1227 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostayb22b4822008-01-22 12:32:30 +01001228 0x0181302e, 0x01114010, 0x01019020, 0x90a000f0,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001229 0x90a000f0, 0x01452050,
1230};
1231
1232static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1233 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1234};
1235
1236static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1237 [STAC_92HD71BXX_REF] = "ref",
1238};
1239
1240static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1241 /* SigmaTel reference board */
1242 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1243 "DFI LanParty", STAC_92HD71BXX_REF),
1244 {} /* terminator */
1245};
1246
Matt Porter403d1942005-11-29 15:00:51 +01001247static unsigned int ref922x_pin_configs[10] = {
1248 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1249 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001250 0x40000100, 0x40000100,
1251};
1252
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001253/*
1254 STAC 922X pin configs for
1255 102801A7
1256 102801AB
1257 102801A9
1258 102801D1
1259 102801D2
1260*/
1261static unsigned int dell_922x_d81_pin_configs[10] = {
1262 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1263 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1264 0x01813122, 0x400001f2,
1265};
1266
1267/*
1268 STAC 922X pin configs for
1269 102801AC
1270 102801D0
1271*/
1272static unsigned int dell_922x_d82_pin_configs[10] = {
1273 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1274 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1275 0x01813122, 0x400001f1,
1276};
1277
1278/*
1279 STAC 922X pin configs for
1280 102801BF
1281*/
1282static unsigned int dell_922x_m81_pin_configs[10] = {
1283 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1284 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1285 0x40C003f1, 0x405003f0,
1286};
1287
1288/*
1289 STAC 9221 A1 pin configs for
1290 102801D7 (Dell XPS M1210)
1291*/
1292static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001293 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1294 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001295 0x508003f3, 0x405003f4,
1296};
1297
Matt Porter403d1942005-11-29 15:00:51 +01001298static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001299 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001300 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1301 0x02a19120, 0x40000100,
1302};
1303
1304static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001305 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1306 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001307 0x02a19320, 0x40000100,
1308};
1309
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001310static unsigned int intel_mac_v1_pin_configs[10] = {
1311 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1312 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001313 0x400000fc, 0x400000fb,
1314};
1315
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001316static unsigned int intel_mac_v2_pin_configs[10] = {
1317 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1318 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001319 0x400000fc, 0x400000fb,
1320};
1321
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001322static unsigned int intel_mac_v3_pin_configs[10] = {
1323 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1324 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1325 0x400000fc, 0x400000fb,
1326};
1327
1328static unsigned int intel_mac_v4_pin_configs[10] = {
1329 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1330 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1331 0x400000fc, 0x400000fb,
1332};
1333
1334static unsigned int intel_mac_v5_pin_configs[10] = {
1335 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1336 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1337 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001338};
1339
Takashi Iwai76c08822007-06-19 12:17:42 +02001340
Takashi Iwai19039bd2006-06-28 15:52:16 +02001341static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001342 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001343 [STAC_D945GTP3] = d945gtp3_pin_configs,
1344 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001345 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1346 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1347 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1348 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1349 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001350 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001351 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1352 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1353 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1354 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1355 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1356 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001357 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1358 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1359 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1360 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001361};
1362
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001363static const char *stac922x_models[STAC_922X_MODELS] = {
1364 [STAC_D945_REF] = "ref",
1365 [STAC_D945GTP5] = "5stack",
1366 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001367 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1368 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1369 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1370 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1371 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001372 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001373 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001374 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001375 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1376 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001377 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001378 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001379 [STAC_922X_DELL_D81] = "dell-d81",
1380 [STAC_922X_DELL_D82] = "dell-d82",
1381 [STAC_922X_DELL_M81] = "dell-m81",
1382 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001383};
1384
1385static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1386 /* SigmaTel reference board */
1387 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1388 "DFI LanParty", STAC_D945_REF),
1389 /* Intel 945G based systems */
1390 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1391 "Intel D945G", STAC_D945GTP3),
1392 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1393 "Intel D945G", STAC_D945GTP3),
1394 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1395 "Intel D945G", STAC_D945GTP3),
1396 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1397 "Intel D945G", STAC_D945GTP3),
1398 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1399 "Intel D945G", STAC_D945GTP3),
1400 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1401 "Intel D945G", STAC_D945GTP3),
1402 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1403 "Intel D945G", STAC_D945GTP3),
1404 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1405 "Intel D945G", STAC_D945GTP3),
1406 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1407 "Intel D945G", STAC_D945GTP3),
1408 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1409 "Intel D945G", STAC_D945GTP3),
1410 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1411 "Intel D945G", STAC_D945GTP3),
1412 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1413 "Intel D945G", STAC_D945GTP3),
1414 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1415 "Intel D945G", STAC_D945GTP3),
1416 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1417 "Intel D945G", STAC_D945GTP3),
1418 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1419 "Intel D945G", STAC_D945GTP3),
1420 /* Intel D945G 5-stack systems */
1421 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1422 "Intel D945G", STAC_D945GTP5),
1423 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1424 "Intel D945G", STAC_D945GTP5),
1425 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1426 "Intel D945G", STAC_D945GTP5),
1427 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1428 "Intel D945G", STAC_D945GTP5),
1429 /* Intel 945P based systems */
1430 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1431 "Intel D945P", STAC_D945GTP3),
1432 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1433 "Intel D945P", STAC_D945GTP3),
1434 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1435 "Intel D945P", STAC_D945GTP3),
1436 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1437 "Intel D945P", STAC_D945GTP3),
1438 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1439 "Intel D945P", STAC_D945GTP3),
1440 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1441 "Intel D945P", STAC_D945GTP5),
1442 /* other systems */
1443 /* Apple Mac Mini (early 2006) */
1444 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001445 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001446 /* Dell systems */
1447 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1448 "unknown Dell", STAC_922X_DELL_D81),
1449 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1450 "unknown Dell", STAC_922X_DELL_D81),
1451 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1452 "unknown Dell", STAC_922X_DELL_D81),
1453 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1454 "unknown Dell", STAC_922X_DELL_D82),
1455 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1456 "unknown Dell", STAC_922X_DELL_M81),
1457 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1458 "unknown Dell", STAC_922X_DELL_D82),
1459 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1460 "unknown Dell", STAC_922X_DELL_D81),
1461 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1462 "unknown Dell", STAC_922X_DELL_D81),
1463 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1464 "Dell XPS M1210", STAC_922X_DELL_M82),
Matt Porter403d1942005-11-29 15:00:51 +01001465 {} /* terminator */
1466};
1467
Matt Porter3cc08dc2006-01-23 15:27:49 +01001468static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001469 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1470 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1471 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1472 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001473};
1474
Tobin Davis93ed1502006-09-01 21:03:12 +02001475static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001476 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1477 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1478 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1479 0x40000100, 0x40000100
1480};
1481
Tobin Davis93ed1502006-09-01 21:03:12 +02001482static unsigned int d965_5st_pin_configs[14] = {
1483 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1484 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1485 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1486 0x40000100, 0x40000100
1487};
1488
Tobin Davis4ff076e2007-08-07 11:48:12 +02001489static unsigned int dell_3st_pin_configs[14] = {
1490 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1491 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001492 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001493 0x40c003fc, 0x40000100
1494};
1495
Tobin Davis93ed1502006-09-01 21:03:12 +02001496static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001497 [STAC_D965_REF] = ref927x_pin_configs,
1498 [STAC_D965_3ST] = d965_3st_pin_configs,
1499 [STAC_D965_5ST] = d965_5st_pin_configs,
1500 [STAC_DELL_3ST] = dell_3st_pin_configs,
1501 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001502};
1503
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001504static const char *stac927x_models[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001505 [STAC_D965_REF] = "ref",
1506 [STAC_D965_3ST] = "3stack",
1507 [STAC_D965_5ST] = "5stack",
1508 [STAC_DELL_3ST] = "dell-3stack",
1509 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001510};
1511
1512static struct snd_pci_quirk stac927x_cfg_tbl[] = {
1513 /* SigmaTel reference board */
1514 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1515 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001516 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001517 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
1518 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001519 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001520 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
1521 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
1522 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
1523 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
1524 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
1525 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
1526 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
1527 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
1528 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
1529 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
1530 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
1531 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
1532 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
1533 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
1534 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
1535 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001536 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001537 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001538 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001539 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
1540 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001541 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01001542 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
1543 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001544 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell ", STAC_DELL_BIOS),
1545 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
1546 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
1547 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
1548 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
1549 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02001550 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001551 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
1552 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
1553 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
1554 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
1555 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
1556 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
1557 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
1558 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
1559 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01001560 {} /* terminator */
1561};
1562
Matt Porterf3302a52006-07-31 12:49:34 +02001563static unsigned int ref9205_pin_configs[12] = {
1564 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001565 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02001566 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02001567};
1568
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001569/*
1570 STAC 9205 pin configs for
1571 102801F1
1572 102801F2
1573 102801FC
1574 102801FD
1575 10280204
1576 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01001577 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001578*/
1579static unsigned int dell_9205_m42_pin_configs[12] = {
1580 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1581 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1582 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1583};
1584
1585/*
1586 STAC 9205 pin configs for
1587 102801F9
1588 102801FA
1589 102801FE
1590 102801FF (Dell Precision M4300)
1591 10280206
1592 10280200
1593 10280201
1594*/
1595static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001596 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1597 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1598 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1599};
1600
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001601static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001602 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1603 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1604 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1605};
1606
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001607static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001608 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001609 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1610 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1611 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02001612};
1613
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001614static const char *stac9205_models[STAC_9205_MODELS] = {
1615 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001616 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001617 [STAC_9205_DELL_M43] = "dell-m43",
1618 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001619};
1620
1621static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1622 /* SigmaTel reference board */
1623 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1624 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001625 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1626 "unknown Dell", STAC_9205_DELL_M42),
1627 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1628 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001629 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02001630 "Dell Precision", STAC_9205_DELL_M43),
1631 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
1632 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001633 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1634 "Dell Precision", STAC_9205_DELL_M43),
Matthew Ranostaye45e4592007-09-10 23:09:42 +02001635 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
1636 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001637 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1638 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001639 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1640 "unknown Dell", STAC_9205_DELL_M42),
1641 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1642 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001643 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1644 "Dell Precision", STAC_9205_DELL_M43),
1645 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001646 "Dell Precision M4300", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001647 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1648 "Dell Precision", STAC_9205_DELL_M43),
1649 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1650 "Dell Inspiron", STAC_9205_DELL_M44),
1651 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1652 "Dell Inspiron", STAC_9205_DELL_M44),
1653 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1654 "Dell Inspiron", STAC_9205_DELL_M44),
1655 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1656 "Dell Inspiron", STAC_9205_DELL_M44),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001657 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1658 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001659 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1660 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01001661 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
1662 "Dell Vostro 1500", STAC_9205_DELL_M42),
Matt Porterf3302a52006-07-31 12:49:34 +02001663 {} /* terminator */
1664};
1665
Richard Fish11b44bb2006-08-23 18:31:34 +02001666static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1667{
1668 int i;
1669 struct sigmatel_spec *spec = codec->spec;
1670
1671 if (! spec->bios_pin_configs) {
1672 spec->bios_pin_configs = kcalloc(spec->num_pins,
1673 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1674 if (! spec->bios_pin_configs)
1675 return -ENOMEM;
1676 }
1677
1678 for (i = 0; i < spec->num_pins; i++) {
1679 hda_nid_t nid = spec->pin_nids[i];
1680 unsigned int pin_cfg;
1681
1682 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1683 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1684 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1685 nid, pin_cfg);
1686 spec->bios_pin_configs[i] = pin_cfg;
1687 }
1688
1689 return 0;
1690}
1691
Matthew Ranostay87d48362007-07-17 11:52:24 +02001692static void stac92xx_set_config_reg(struct hda_codec *codec,
1693 hda_nid_t pin_nid, unsigned int pin_config)
1694{
1695 int i;
1696 snd_hda_codec_write(codec, pin_nid, 0,
1697 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1698 pin_config & 0x000000ff);
1699 snd_hda_codec_write(codec, pin_nid, 0,
1700 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1701 (pin_config & 0x0000ff00) >> 8);
1702 snd_hda_codec_write(codec, pin_nid, 0,
1703 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1704 (pin_config & 0x00ff0000) >> 16);
1705 snd_hda_codec_write(codec, pin_nid, 0,
1706 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1707 pin_config >> 24);
1708 i = snd_hda_codec_read(codec, pin_nid, 0,
1709 AC_VERB_GET_CONFIG_DEFAULT,
1710 0x00);
1711 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1712 pin_nid, i);
1713}
1714
Matt2f2f4252005-04-13 14:45:30 +02001715static void stac92xx_set_config_regs(struct hda_codec *codec)
1716{
1717 int i;
1718 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02001719
Matthew Ranostay87d48362007-07-17 11:52:24 +02001720 if (!spec->pin_configs)
1721 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02001722
Matthew Ranostay87d48362007-07-17 11:52:24 +02001723 for (i = 0; i < spec->num_pins; i++)
1724 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1725 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02001726}
Matt2f2f4252005-04-13 14:45:30 +02001727
Matt2f2f4252005-04-13 14:45:30 +02001728/*
1729 * Analog playback callbacks
1730 */
1731static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1732 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001733 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001734{
1735 struct sigmatel_spec *spec = codec->spec;
1736 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
1737}
1738
1739static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1740 struct hda_codec *codec,
1741 unsigned int stream_tag,
1742 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001743 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001744{
1745 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01001746 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02001747}
1748
1749static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1750 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001751 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001752{
1753 struct sigmatel_spec *spec = codec->spec;
1754 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1755}
1756
1757/*
Mattdabbed62005-06-14 10:19:34 +02001758 * Digital playback callbacks
1759 */
1760static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1761 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001762 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001763{
1764 struct sigmatel_spec *spec = codec->spec;
1765 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1766}
1767
1768static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1769 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001770 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001771{
1772 struct sigmatel_spec *spec = codec->spec;
1773 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1774}
1775
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001776static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1777 struct hda_codec *codec,
1778 unsigned int stream_tag,
1779 unsigned int format,
1780 struct snd_pcm_substream *substream)
1781{
1782 struct sigmatel_spec *spec = codec->spec;
1783 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1784 stream_tag, format, substream);
1785}
1786
Mattdabbed62005-06-14 10:19:34 +02001787
1788/*
Matt2f2f4252005-04-13 14:45:30 +02001789 * Analog capture callbacks
1790 */
1791static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1792 struct hda_codec *codec,
1793 unsigned int stream_tag,
1794 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001795 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001796{
1797 struct sigmatel_spec *spec = codec->spec;
1798
1799 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1800 stream_tag, 0, format);
1801 return 0;
1802}
1803
1804static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1805 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001806 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001807{
1808 struct sigmatel_spec *spec = codec->spec;
1809
1810 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1811 return 0;
1812}
1813
Mattdabbed62005-06-14 10:19:34 +02001814static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1815 .substreams = 1,
1816 .channels_min = 2,
1817 .channels_max = 2,
1818 /* NID is set in stac92xx_build_pcms */
1819 .ops = {
1820 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001821 .close = stac92xx_dig_playback_pcm_close,
1822 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02001823 },
1824};
1825
1826static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1827 .substreams = 1,
1828 .channels_min = 2,
1829 .channels_max = 2,
1830 /* NID is set in stac92xx_build_pcms */
1831};
1832
Matt2f2f4252005-04-13 14:45:30 +02001833static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1834 .substreams = 1,
1835 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02001836 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02001837 .nid = 0x02, /* NID to query formats and rates */
1838 .ops = {
1839 .open = stac92xx_playback_pcm_open,
1840 .prepare = stac92xx_playback_pcm_prepare,
1841 .cleanup = stac92xx_playback_pcm_cleanup
1842 },
1843};
1844
Matt Porter3cc08dc2006-01-23 15:27:49 +01001845static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1846 .substreams = 1,
1847 .channels_min = 2,
1848 .channels_max = 2,
1849 .nid = 0x06, /* NID to query formats and rates */
1850 .ops = {
1851 .open = stac92xx_playback_pcm_open,
1852 .prepare = stac92xx_playback_pcm_prepare,
1853 .cleanup = stac92xx_playback_pcm_cleanup
1854 },
1855};
1856
Matt2f2f4252005-04-13 14:45:30 +02001857static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02001858 .channels_min = 2,
1859 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001860 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001861 .ops = {
1862 .prepare = stac92xx_capture_pcm_prepare,
1863 .cleanup = stac92xx_capture_pcm_cleanup
1864 },
1865};
1866
1867static int stac92xx_build_pcms(struct hda_codec *codec)
1868{
1869 struct sigmatel_spec *spec = codec->spec;
1870 struct hda_pcm *info = spec->pcm_rec;
1871
1872 codec->num_pcms = 1;
1873 codec->pcm_info = info;
1874
Mattc7d4b2f2005-06-27 14:59:41 +02001875 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001876 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001877 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001878 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001879 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001880
1881 if (spec->alt_switch) {
1882 codec->num_pcms++;
1883 info++;
1884 info->name = "STAC92xx Analog Alt";
1885 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1886 }
Matt2f2f4252005-04-13 14:45:30 +02001887
Mattdabbed62005-06-14 10:19:34 +02001888 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1889 codec->num_pcms++;
1890 info++;
1891 info->name = "STAC92xx Digital";
1892 if (spec->multiout.dig_out_nid) {
1893 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1894 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1895 }
1896 if (spec->dig_in_nid) {
1897 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1898 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1899 }
1900 }
1901
Matt2f2f4252005-04-13 14:45:30 +02001902 return 0;
1903}
1904
Takashi Iwaic960a032006-03-23 17:06:28 +01001905static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1906{
1907 unsigned int pincap = snd_hda_param_read(codec, nid,
1908 AC_PAR_PIN_CAP);
1909 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1910 if (pincap & AC_PINCAP_VREF_100)
1911 return AC_PINCTL_VREF_100;
1912 if (pincap & AC_PINCAP_VREF_80)
1913 return AC_PINCTL_VREF_80;
1914 if (pincap & AC_PINCAP_VREF_50)
1915 return AC_PINCTL_VREF_50;
1916 if (pincap & AC_PINCAP_VREF_GRD)
1917 return AC_PINCTL_VREF_GRD;
1918 return 0;
1919}
1920
Matt Porter403d1942005-11-29 15:00:51 +01001921static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
1922
1923{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02001924 snd_hda_codec_write_cache(codec, nid, 0,
1925 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01001926}
1927
Takashi Iwaia5ce8892007-07-23 15:42:26 +02001928#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01001929
1930static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1931{
1932 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1933 struct sigmatel_spec *spec = codec->spec;
1934 int io_idx = kcontrol-> private_value & 0xff;
1935
1936 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
1937 return 0;
1938}
1939
1940static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1941{
1942 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1943 struct sigmatel_spec *spec = codec->spec;
1944 hda_nid_t nid = kcontrol->private_value >> 8;
1945 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001946 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01001947
1948 spec->io_switch[io_idx] = val;
1949
1950 if (val)
1951 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01001952 else {
1953 unsigned int pinctl = AC_PINCTL_IN_EN;
1954 if (io_idx) /* set VREF for mic */
1955 pinctl |= stac92xx_get_vref(codec, nid);
1956 stac92xx_auto_set_pinctl(codec, nid, pinctl);
1957 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01001958
1959 /* check the auto-mute again: we need to mute/unmute the speaker
1960 * appropriately according to the pin direction
1961 */
1962 if (spec->hp_detect)
1963 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
1964
Matt Porter403d1942005-11-29 15:00:51 +01001965 return 1;
1966}
1967
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001968#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
1969
1970static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
1971 struct snd_ctl_elem_value *ucontrol)
1972{
1973 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1974 struct sigmatel_spec *spec = codec->spec;
1975
1976 ucontrol->value.integer.value[0] = spec->clfe_swap;
1977 return 0;
1978}
1979
1980static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1981 struct snd_ctl_elem_value *ucontrol)
1982{
1983 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1984 struct sigmatel_spec *spec = codec->spec;
1985 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001986 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001987
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001988 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001989 return 0;
1990
Takashi Iwai68ea7b22007-11-15 15:54:38 +01001991 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02001992
1993 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
1994 spec->clfe_swap ? 0x4 : 0x0);
1995
1996 return 1;
1997}
1998
Matt Porter403d1942005-11-29 15:00:51 +01001999#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2000 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2001 .name = xname, \
2002 .index = 0, \
2003 .info = stac92xx_io_switch_info, \
2004 .get = stac92xx_io_switch_get, \
2005 .put = stac92xx_io_switch_put, \
2006 .private_value = xpval, \
2007 }
2008
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002009#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2010 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2011 .name = xname, \
2012 .index = 0, \
2013 .info = stac92xx_clfe_switch_info, \
2014 .get = stac92xx_clfe_switch_get, \
2015 .put = stac92xx_clfe_switch_put, \
2016 .private_value = xpval, \
2017 }
Matt Porter403d1942005-11-29 15:00:51 +01002018
Mattc7d4b2f2005-06-27 14:59:41 +02002019enum {
2020 STAC_CTL_WIDGET_VOL,
2021 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002022 STAC_CTL_WIDGET_MONO_MUX,
Matt Porter403d1942005-11-29 15:00:51 +01002023 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002024 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02002025};
2026
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002027static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002028 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2029 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002030 STAC_MONO_MUX,
Matt Porter403d1942005-11-29 15:00:51 +01002031 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002032 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002033};
2034
2035/* add dynamic controls */
2036static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
2037{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002038 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002039
2040 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2041 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2042
2043 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2044 if (! knew)
2045 return -ENOMEM;
2046 if (spec->kctl_alloc) {
2047 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2048 kfree(spec->kctl_alloc);
2049 }
2050 spec->kctl_alloc = knew;
2051 spec->num_kctl_alloc = num;
2052 }
2053
2054 knew = &spec->kctl_alloc[spec->num_kctl_used];
2055 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002056 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02002057 if (! knew->name)
2058 return -ENOMEM;
2059 knew->private_value = val;
2060 spec->num_kctl_used++;
2061 return 0;
2062}
2063
Matt Porter403d1942005-11-29 15:00:51 +01002064/* flag inputs as additional dynamic lineouts */
2065static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2066{
2067 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002068 unsigned int wcaps, wtype;
2069 int i, num_dacs = 0;
2070
2071 /* use the wcaps cache to count all DACs available for line-outs */
2072 for (i = 0; i < codec->num_nodes; i++) {
2073 wcaps = codec->wcaps[i];
2074 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002075
Steve Longerbeam7b043892007-05-03 20:50:03 +02002076 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
2077 num_dacs++;
2078 }
Matt Porter403d1942005-11-29 15:00:51 +01002079
Steve Longerbeam7b043892007-05-03 20:50:03 +02002080 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
2081
Matt Porter403d1942005-11-29 15:00:51 +01002082 switch (cfg->line_outs) {
2083 case 3:
2084 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002085 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002086 cfg->line_out_pins[cfg->line_outs] =
2087 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002088 spec->line_switch = 1;
2089 cfg->line_outs++;
2090 }
2091 break;
2092 case 2:
2093 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002094 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002095 cfg->line_out_pins[cfg->line_outs] =
2096 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002097 spec->line_switch = 1;
2098 cfg->line_outs++;
2099 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002100 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002101 cfg->line_out_pins[cfg->line_outs] =
2102 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002103 spec->mic_switch = 1;
2104 cfg->line_outs++;
2105 }
2106 break;
2107 case 1:
2108 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002109 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002110 cfg->line_out_pins[cfg->line_outs] =
2111 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002112 spec->line_switch = 1;
2113 cfg->line_outs++;
2114 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002115 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002116 cfg->line_out_pins[cfg->line_outs] =
2117 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002118 spec->mic_switch = 1;
2119 cfg->line_outs++;
2120 }
2121 break;
2122 }
2123
2124 return 0;
2125}
2126
Steve Longerbeam7b043892007-05-03 20:50:03 +02002127
2128static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2129{
2130 int i;
2131
2132 for (i = 0; i < spec->multiout.num_dacs; i++) {
2133 if (spec->multiout.dac_nids[i] == nid)
2134 return 1;
2135 }
2136
2137 return 0;
2138}
2139
Matt Porter3cc08dc2006-01-23 15:27:49 +01002140/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002141 * Fill in the dac_nids table from the parsed pin configuration
2142 * This function only works when every pin in line_out_pins[]
2143 * contains atleast one DAC in its connection list. Some 92xx
2144 * codecs are not connected directly to a DAC, such as the 9200
2145 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002146 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002147static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02002148 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002149{
2150 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002151 int i, j, conn_len = 0;
2152 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2153 unsigned int wcaps, wtype;
2154
Mattc7d4b2f2005-06-27 14:59:41 +02002155 for (i = 0; i < cfg->line_outs; i++) {
2156 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02002157 conn_len = snd_hda_get_connections(codec, nid, conn,
2158 HDA_MAX_CONNECTIONS);
2159 for (j = 0; j < conn_len; j++) {
2160 wcaps = snd_hda_param_read(codec, conn[j],
2161 AC_PAR_AUDIO_WIDGET_CAP);
2162 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002163 if (wtype != AC_WID_AUD_OUT ||
2164 (wcaps & AC_WCAP_DIGITAL))
2165 continue;
2166 /* conn[j] is a DAC routed to this line-out */
2167 if (!is_in_dac_nids(spec, conn[j]))
2168 break;
2169 }
2170
2171 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002172 if (spec->multiout.num_dacs > 0) {
2173 /* we have already working output pins,
2174 * so let's drop the broken ones again
2175 */
2176 cfg->line_outs = spec->multiout.num_dacs;
2177 break;
2178 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002179 /* error out, no available DAC found */
2180 snd_printk(KERN_ERR
2181 "%s: No available DAC for pin 0x%x\n",
2182 __func__, nid);
2183 return -ENODEV;
2184 }
2185
2186 spec->multiout.dac_nids[i] = conn[j];
2187 spec->multiout.num_dacs++;
2188 if (conn_len > 1) {
2189 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002190 snd_hda_codec_write_cache(codec, nid, 0,
2191 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002192
2193 }
Mattc7d4b2f2005-06-27 14:59:41 +02002194 }
2195
Steve Longerbeam7b043892007-05-03 20:50:03 +02002196 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2197 spec->multiout.num_dacs,
2198 spec->multiout.dac_nids[0],
2199 spec->multiout.dac_nids[1],
2200 spec->multiout.dac_nids[2],
2201 spec->multiout.dac_nids[3],
2202 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02002203 return 0;
2204}
2205
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002206/* create volume control/switch for the given prefx type */
2207static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2208{
2209 char name[32];
2210 int err;
2211
2212 sprintf(name, "%s Playback Volume", pfx);
2213 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2214 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2215 if (err < 0)
2216 return err;
2217 sprintf(name, "%s Playback Switch", pfx);
2218 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2219 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2220 if (err < 0)
2221 return err;
2222 return 0;
2223}
2224
Mattc7d4b2f2005-06-27 14:59:41 +02002225/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002226static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002227 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002228{
Takashi Iwai19039bd2006-06-28 15:52:16 +02002229 static const char *chname[4] = {
2230 "Front", "Surround", NULL /*CLFE*/, "Side"
2231 };
Mattc7d4b2f2005-06-27 14:59:41 +02002232 hda_nid_t nid;
2233 int i, err;
2234
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002235 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002236 unsigned int wid_caps, pincap;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002237
2238
Mattc7d4b2f2005-06-27 14:59:41 +02002239 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01002240 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02002241 continue;
2242
2243 nid = spec->multiout.dac_nids[i];
2244
2245 if (i == 2) {
2246 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002247 err = create_controls(spec, "Center", nid, 1);
2248 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002249 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002250 err = create_controls(spec, "LFE", nid, 2);
2251 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002252 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002253
2254 wid_caps = get_wcaps(codec, nid);
2255
2256 if (wid_caps & AC_WCAP_LR_SWAP) {
2257 err = stac92xx_add_control(spec,
2258 STAC_CTL_WIDGET_CLFE_SWITCH,
2259 "Swap Center/LFE Playback Switch", nid);
2260
2261 if (err < 0)
2262 return err;
2263 }
2264
Mattc7d4b2f2005-06-27 14:59:41 +02002265 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002266 err = create_controls(spec, chname[i], nid, 3);
2267 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002268 return err;
2269 }
2270 }
2271
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002272 if (spec->line_switch) {
2273 nid = cfg->input_pins[AUTO_PIN_LINE];
2274 pincap = snd_hda_param_read(codec, nid,
2275 AC_PAR_PIN_CAP);
2276 if (pincap & AC_PINCAP_OUT) {
2277 err = stac92xx_add_control(spec,
2278 STAC_CTL_WIDGET_IO_SWITCH,
2279 "Line In as Output Switch", nid << 8);
2280 if (err < 0)
2281 return err;
2282 }
2283 }
Matt Porter403d1942005-11-29 15:00:51 +01002284
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002285 if (spec->mic_switch) {
Matthew Ranostaycace16f2008-01-30 14:58:38 +01002286 unsigned int def_conf;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002287 nid = cfg->input_pins[AUTO_PIN_MIC];
Matthew Ranostaycace16f2008-01-30 14:58:38 +01002288 def_conf = snd_hda_codec_read(codec, nid, 0,
2289 AC_VERB_GET_CONFIG_DEFAULT, 0);
2290
2291 /* some laptops have an internal analog microphone
2292 * which can't be used as a output */
2293 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2294 pincap = snd_hda_param_read(codec, nid,
2295 AC_PAR_PIN_CAP);
2296 if (pincap & AC_PINCAP_OUT) {
2297 err = stac92xx_add_control(spec,
2298 STAC_CTL_WIDGET_IO_SWITCH,
2299 "Mic as Output Switch", (nid << 8) | 1);
2300 if (err < 0)
2301 return err;
2302 }
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002303 }
2304 }
Matt Porter403d1942005-11-29 15:00:51 +01002305
Mattc7d4b2f2005-06-27 14:59:41 +02002306 return 0;
2307}
2308
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002309static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2310{
Steve Longerbeam7b043892007-05-03 20:50:03 +02002311 if (is_in_dac_nids(spec, nid))
2312 return 1;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002313 if (spec->multiout.hp_nid == nid)
2314 return 1;
2315 return 0;
2316}
2317
2318static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2319{
2320 if (!spec->multiout.hp_nid)
2321 spec->multiout.hp_nid = nid;
2322 else if (spec->multiout.num_dacs > 4) {
2323 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2324 return 1;
2325 } else {
2326 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2327 spec->multiout.num_dacs++;
2328 }
2329 return 0;
2330}
2331
2332/* add playback controls for Speaker and HP outputs */
2333static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2334 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002335{
2336 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002337 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002338 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02002339
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002340 old_num_dacs = spec->multiout.num_dacs;
2341 for (i = 0; i < cfg->hp_outs; i++) {
2342 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
2343 if (wid_caps & AC_WCAP_UNSOL_CAP)
2344 spec->hp_detect = 1;
2345 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
2346 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2347 if (check_in_dac_nids(spec, nid))
2348 nid = 0;
2349 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02002350 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002351 add_spec_dacs(spec, nid);
2352 }
2353 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02002354 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002355 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2356 if (check_in_dac_nids(spec, nid))
2357 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002358 if (! nid)
2359 continue;
2360 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02002361 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02002362 for (i = 0; i < cfg->line_outs; i++) {
2363 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
2364 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2365 if (check_in_dac_nids(spec, nid))
2366 nid = 0;
2367 if (! nid)
2368 continue;
2369 add_spec_dacs(spec, nid);
2370 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002371 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
2372 static const char *pfxs[] = {
2373 "Speaker", "External Speaker", "Speaker2",
2374 };
2375 err = create_controls(spec, pfxs[i - old_num_dacs],
2376 spec->multiout.dac_nids[i], 3);
2377 if (err < 0)
2378 return err;
2379 }
2380 if (spec->multiout.hp_nid) {
2381 const char *pfx;
Takashi Iwai6020c002007-11-19 11:56:26 +01002382 if (old_num_dacs == spec->multiout.num_dacs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002383 pfx = "Master";
2384 else
2385 pfx = "Headphone";
2386 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
2387 if (err < 0)
2388 return err;
2389 }
Mattc7d4b2f2005-06-27 14:59:41 +02002390
2391 return 0;
2392}
2393
Matthew Ranostayb22b4822008-01-22 12:32:30 +01002394/* labels for mono mux outputs */
2395static const char *stac92xx_mono_labels[3] = {
2396 "DAC0", "DAC1", "Mixer"
2397};
2398
2399/* create mono mux for mono out on capable codecs */
2400static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
2401{
2402 struct sigmatel_spec *spec = codec->spec;
2403 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
2404 int i, num_cons;
2405 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
2406
2407 num_cons = snd_hda_get_connections(codec,
2408 spec->mono_nid,
2409 con_lst,
2410 HDA_MAX_NUM_INPUTS);
2411 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
2412 return -EINVAL;
2413
2414 for (i = 0; i < num_cons; i++) {
2415 mono_mux->items[mono_mux->num_items].label =
2416 stac92xx_mono_labels[i];
2417 mono_mux->items[mono_mux->num_items].index = i;
2418 mono_mux->num_items++;
2419 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01002420
2421 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
2422 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01002423}
2424
Matt Porter8b657272006-10-26 17:12:59 +02002425/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01002426static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02002427 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
2428 "Digital Mic 3", "Digital Mic 4"
2429};
2430
2431/* create playback/capture controls for input pins on dmic capable codecs */
2432static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
2433 const struct auto_pin_cfg *cfg)
2434{
2435 struct sigmatel_spec *spec = codec->spec;
2436 struct hda_input_mux *dimux = &spec->private_dimux;
2437 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002438 int err, i, j;
2439 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02002440
2441 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
2442 dimux->items[dimux->num_items].index = 0;
2443 dimux->num_items++;
2444
2445 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002446 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02002447 int index;
2448 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002449 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02002450 unsigned int def_conf;
2451
2452 def_conf = snd_hda_codec_read(codec,
2453 spec->dmic_nids[i],
2454 0,
2455 AC_VERB_GET_CONFIG_DEFAULT,
2456 0);
2457 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
2458 continue;
2459
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002460 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02002461 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01002462 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02002463 con_lst,
2464 HDA_MAX_NUM_INPUTS);
2465 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002466 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02002467 index = j;
2468 goto found;
2469 }
2470 continue;
2471found:
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002472 wcaps = get_wcaps(codec, nid);
2473
2474 if (wcaps & AC_WCAP_OUT_AMP) {
2475 sprintf(name, "%s Capture Volume",
2476 stac92xx_dmic_labels[dimux->num_items]);
2477
2478 err = stac92xx_add_control(spec,
2479 STAC_CTL_WIDGET_VOL,
2480 name,
2481 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2482 if (err < 0)
2483 return err;
2484 }
2485
Matt Porter8b657272006-10-26 17:12:59 +02002486 dimux->items[dimux->num_items].label =
2487 stac92xx_dmic_labels[dimux->num_items];
2488 dimux->items[dimux->num_items].index = index;
2489 dimux->num_items++;
2490 }
2491
2492 return 0;
2493}
2494
Mattc7d4b2f2005-06-27 14:59:41 +02002495/* create playback/capture controls for input pins */
2496static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
2497{
2498 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002499 struct hda_input_mux *imux = &spec->private_imux;
2500 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
2501 int i, j, k;
2502
2503 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002504 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02002505
Takashi Iwai314634b2006-09-21 11:56:18 +02002506 if (!cfg->input_pins[i])
2507 continue;
2508 index = -1;
2509 for (j = 0; j < spec->num_muxes; j++) {
2510 int num_cons;
2511 num_cons = snd_hda_get_connections(codec,
2512 spec->mux_nids[j],
2513 con_lst,
2514 HDA_MAX_NUM_INPUTS);
2515 for (k = 0; k < num_cons; k++)
2516 if (con_lst[k] == cfg->input_pins[i]) {
2517 index = k;
2518 goto found;
2519 }
Mattc7d4b2f2005-06-27 14:59:41 +02002520 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002521 continue;
2522 found:
2523 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2524 imux->items[imux->num_items].index = index;
2525 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02002526 }
2527
Steve Longerbeam7b043892007-05-03 20:50:03 +02002528 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02002529 /*
2530 * Set the current input for the muxes.
2531 * The STAC9221 has two input muxes with identical source
2532 * NID lists. Hopefully this won't get confused.
2533 */
2534 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002535 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
2536 AC_VERB_SET_CONNECT_SEL,
2537 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02002538 }
2539 }
2540
Mattc7d4b2f2005-06-27 14:59:41 +02002541 return 0;
2542}
2543
Mattc7d4b2f2005-06-27 14:59:41 +02002544static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
2545{
2546 struct sigmatel_spec *spec = codec->spec;
2547 int i;
2548
2549 for (i = 0; i < spec->autocfg.line_outs; i++) {
2550 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2551 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2552 }
2553}
2554
2555static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
2556{
2557 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002558 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002559
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002560 for (i = 0; i < spec->autocfg.hp_outs; i++) {
2561 hda_nid_t pin;
2562 pin = spec->autocfg.hp_pins[i];
2563 if (pin) /* connect to front */
2564 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
2565 }
2566 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
2567 hda_nid_t pin;
2568 pin = spec->autocfg.speaker_pins[i];
2569 if (pin) /* connect to front */
2570 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
2571 }
Mattc7d4b2f2005-06-27 14:59:41 +02002572}
2573
Matt Porter3cc08dc2006-01-23 15:27:49 +01002574static 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 +02002575{
2576 struct sigmatel_spec *spec = codec->spec;
2577 int err;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002578 int hp_speaker_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002579
Matt Porter8b657272006-10-26 17:12:59 +02002580 if ((err = snd_hda_parse_pin_def_config(codec,
2581 &spec->autocfg,
2582 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002583 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002584 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01002585 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002586
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002587 /* If we have no real line-out pin and multiple hp-outs, HPs should
2588 * be set up as multi-channel outputs.
2589 */
2590 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2591 spec->autocfg.hp_outs > 1) {
2592 /* Copy hp_outs to line_outs, backup line_outs in
2593 * speaker_outs so that the following routines can handle
2594 * HP pins as primary outputs.
2595 */
2596 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
2597 sizeof(spec->autocfg.line_out_pins));
2598 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
2599 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
2600 sizeof(spec->autocfg.hp_pins));
2601 spec->autocfg.line_outs = spec->autocfg.hp_outs;
2602 hp_speaker_swap = 1;
2603 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01002604 if (spec->autocfg.mono_out_pin) {
2605 int dir = (get_wcaps(codec, spec->autocfg.mono_out_pin)
2606 & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
2607 u32 caps = query_amp_caps(codec,
2608 spec->autocfg.mono_out_pin, dir);
2609 hda_nid_t conn_list[1];
2610
2611 /* get the mixer node and then the mono mux if it exists */
2612 if (snd_hda_get_connections(codec,
2613 spec->autocfg.mono_out_pin, conn_list, 1) &&
2614 snd_hda_get_connections(codec, conn_list[0],
2615 conn_list, 1)) {
2616
2617 int wcaps = get_wcaps(codec, conn_list[0]);
2618 int wid_type = (wcaps & AC_WCAP_TYPE)
2619 >> AC_WCAP_TYPE_SHIFT;
2620 /* LR swap check, some stac925x have a mux that
2621 * changes the DACs output path instead of the
2622 * mono-mux path.
2623 */
2624 if (wid_type == AC_WID_AUD_SEL &&
2625 !(wcaps & AC_WCAP_LR_SWAP))
2626 spec->mono_nid = conn_list[0];
2627 }
2628 /* all mono outs have a least a mute/unmute switch */
2629 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
2630 "Mono Playback Switch",
2631 HDA_COMPOSE_AMP_VAL(spec->autocfg.mono_out_pin,
2632 1, 0, dir));
2633 if (err < 0)
2634 return err;
2635 /* check to see if there is volume support for the amp */
2636 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
2637 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
2638 "Mono Playback Volume",
2639 HDA_COMPOSE_AMP_VAL(spec->autocfg.mono_out_pin,
2640 1, 0, dir));
2641 if (err < 0)
2642 return err;
2643 }
2644
2645 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
2646 AC_PINCTL_OUT_EN);
2647 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002648
Matt Porter403d1942005-11-29 15:00:51 +01002649 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
2650 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002651 if (spec->multiout.num_dacs == 0)
2652 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2653 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02002654
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002655 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
2656
2657 if (err < 0)
2658 return err;
2659
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002660 if (hp_speaker_swap == 1) {
2661 /* Restore the hp_outs and line_outs */
2662 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
2663 sizeof(spec->autocfg.line_out_pins));
2664 spec->autocfg.hp_outs = spec->autocfg.line_outs;
2665 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
2666 sizeof(spec->autocfg.speaker_pins));
2667 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
2668 memset(spec->autocfg.speaker_pins, 0,
2669 sizeof(spec->autocfg.speaker_pins));
2670 spec->autocfg.speaker_outs = 0;
2671 }
2672
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002673 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
2674
2675 if (err < 0)
2676 return err;
2677
2678 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
2679
2680 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002681 return err;
2682
Matthew Ranostayb22b4822008-01-22 12:32:30 +01002683 if (spec->mono_nid > 0) {
2684 err = stac92xx_auto_create_mono_output_ctls(codec);
2685 if (err < 0)
2686 return err;
2687 }
2688
Matt Porter8b657272006-10-26 17:12:59 +02002689 if (spec->num_dmics > 0)
2690 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
2691 &spec->autocfg)) < 0)
2692 return err;
2693
Mattc7d4b2f2005-06-27 14:59:41 +02002694 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01002695 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02002696 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002697
Takashi Iwai82bc9552006-03-21 11:24:42 +01002698 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002699 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002700 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002701 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02002702
2703 if (spec->kctl_alloc)
2704 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2705
2706 spec->input_mux = &spec->private_imux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01002707 if (!spec->dinput_mux)
2708 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01002709 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02002710
2711 return 1;
2712}
2713
Takashi Iwai82bc9552006-03-21 11:24:42 +01002714/* add playback controls for HP output */
2715static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
2716 struct auto_pin_cfg *cfg)
2717{
2718 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002719 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01002720 unsigned int wid_caps;
2721
2722 if (! pin)
2723 return 0;
2724
2725 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02002726 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01002727 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002728
2729 return 0;
2730}
2731
Richard Fish160ea0d2006-09-06 13:58:25 +02002732/* add playback controls for LFE output */
2733static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2734 struct auto_pin_cfg *cfg)
2735{
2736 struct sigmatel_spec *spec = codec->spec;
2737 int err;
2738 hda_nid_t lfe_pin = 0x0;
2739 int i;
2740
2741 /*
2742 * search speaker outs and line outs for a mono speaker pin
2743 * with an amp. If one is found, add LFE controls
2744 * for it.
2745 */
2746 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2747 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2748 unsigned long wcaps = get_wcaps(codec, pin);
2749 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2750 if (wcaps == AC_WCAP_OUT_AMP)
2751 /* found a mono speaker with an amp, must be lfe */
2752 lfe_pin = pin;
2753 }
2754
2755 /* if speaker_outs is 0, then speakers may be in line_outs */
2756 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2757 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2758 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2759 unsigned long cfg;
2760 cfg = snd_hda_codec_read(codec, pin, 0,
2761 AC_VERB_GET_CONFIG_DEFAULT,
2762 0x00);
2763 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
2764 unsigned long wcaps = get_wcaps(codec, pin);
2765 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2766 if (wcaps == AC_WCAP_OUT_AMP)
2767 /* found a mono speaker with an amp,
2768 must be lfe */
2769 lfe_pin = pin;
2770 }
2771 }
2772 }
2773
2774 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002775 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02002776 if (err < 0)
2777 return err;
2778 }
2779
2780 return 0;
2781}
2782
Mattc7d4b2f2005-06-27 14:59:41 +02002783static int stac9200_parse_auto_config(struct hda_codec *codec)
2784{
2785 struct sigmatel_spec *spec = codec->spec;
2786 int err;
2787
Kailang Yangdf694da2005-12-05 19:42:22 +01002788 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002789 return err;
2790
2791 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
2792 return err;
2793
Takashi Iwai82bc9552006-03-21 11:24:42 +01002794 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2795 return err;
2796
Richard Fish160ea0d2006-09-06 13:58:25 +02002797 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2798 return err;
2799
Takashi Iwai82bc9552006-03-21 11:24:42 +01002800 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002801 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002802 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002803 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02002804
2805 if (spec->kctl_alloc)
2806 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2807
2808 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002809 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002810
2811 return 1;
2812}
2813
Sam Revitch62fe78e2006-05-10 15:09:17 +02002814/*
2815 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2816 * funky external mute control using GPIO pins.
2817 */
2818
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01002819static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01002820 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02002821{
2822 unsigned int gpiostate, gpiomask, gpiodir;
2823
2824 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2825 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01002826 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02002827
2828 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2829 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01002830 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02002831
2832 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2833 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01002834 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02002835
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01002836 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02002837 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2838
2839 snd_hda_codec_write(codec, codec->afg, 0,
2840 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01002841 snd_hda_codec_read(codec, codec->afg, 0,
2842 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02002843
2844 msleep(1);
2845
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01002846 snd_hda_codec_read(codec, codec->afg, 0,
2847 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02002848}
2849
Takashi Iwai314634b2006-09-21 11:56:18 +02002850static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2851 unsigned int event)
2852{
2853 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002854 snd_hda_codec_write_cache(codec, nid, 0,
2855 AC_VERB_SET_UNSOLICITED_ENABLE,
2856 (AC_USRSP_EN | event));
Takashi Iwai314634b2006-09-21 11:56:18 +02002857}
2858
Matthew Ranostaya64135a2008-01-10 16:55:06 +01002859static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
2860{
2861 int i;
2862 for (i = 0; i < cfg->hp_outs; i++)
2863 if (cfg->hp_pins[i] == nid)
2864 return 1; /* nid is a HP-Out */
2865
2866 return 0; /* nid is not a HP-Out */
2867};
2868
Mattc7d4b2f2005-06-27 14:59:41 +02002869static int stac92xx_init(struct hda_codec *codec)
2870{
2871 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002872 struct auto_pin_cfg *cfg = &spec->autocfg;
2873 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002874
Mattc7d4b2f2005-06-27 14:59:41 +02002875 snd_hda_sequence_write(codec, spec->init);
2876
Takashi Iwai82bc9552006-03-21 11:24:42 +01002877 /* set up pins */
2878 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02002879 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002880 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02002881 enable_pin_detect(codec, cfg->hp_pins[i],
2882 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01002883 /* force to enable the first line-out; the others are set up
2884 * in unsol_event
2885 */
2886 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2887 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02002888 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002889 /* fake event to set up pins */
2890 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2891 } else {
2892 stac92xx_auto_init_multi_out(codec);
2893 stac92xx_auto_init_hp_out(codec);
2894 }
2895 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01002896 hda_nid_t nid = cfg->input_pins[i];
2897 if (nid) {
2898 unsigned int pinctl = AC_PINCTL_IN_EN;
2899 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
2900 pinctl |= stac92xx_get_vref(codec, nid);
2901 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2902 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01002903 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01002904 for (i = 0; i < spec->num_dmics; i++)
2905 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
2906 AC_PINCTL_IN_EN);
2907 for (i = 0; i < spec->num_pwrs; i++) {
2908 int event = is_nid_hp_pin(cfg, spec->pwr_nids[i])
2909 ? STAC_HP_EVENT : STAC_PWR_EVENT;
2910 int pinctl = snd_hda_codec_read(codec, spec->pwr_nids[i],
2911 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
2912 /* outputs are only ports capable of power management
2913 * any attempts on powering down a input port cause the
2914 * referenced VREF to act quirky.
2915 */
2916 if (pinctl & AC_PINCTL_IN_EN)
2917 continue;
2918 enable_pin_detect(codec, spec->pwr_nids[i], event | i);
2919 codec->patch_ops.unsol_event(codec, (event | i) << 26);
2920 }
Matt Porter8b657272006-10-26 17:12:59 +02002921
Takashi Iwai82bc9552006-03-21 11:24:42 +01002922 if (cfg->dig_out_pin)
2923 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2924 AC_PINCTL_OUT_EN);
2925 if (cfg->dig_in_pin)
2926 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2927 AC_PINCTL_IN_EN);
2928
Matthew Ranostay4fe51952008-01-29 15:28:44 +01002929 stac_gpio_set(codec, spec->gpio_mask,
2930 spec->gpio_dir, spec->gpio_data);
Sam Revitch62fe78e2006-05-10 15:09:17 +02002931
Mattc7d4b2f2005-06-27 14:59:41 +02002932 return 0;
2933}
2934
Matt2f2f4252005-04-13 14:45:30 +02002935static void stac92xx_free(struct hda_codec *codec)
2936{
Mattc7d4b2f2005-06-27 14:59:41 +02002937 struct sigmatel_spec *spec = codec->spec;
2938 int i;
2939
2940 if (! spec)
2941 return;
2942
2943 if (spec->kctl_alloc) {
2944 for (i = 0; i < spec->num_kctl_used; i++)
2945 kfree(spec->kctl_alloc[i].name);
2946 kfree(spec->kctl_alloc);
2947 }
2948
Richard Fish11b44bb2006-08-23 18:31:34 +02002949 if (spec->bios_pin_configs)
2950 kfree(spec->bios_pin_configs);
2951
Mattc7d4b2f2005-06-27 14:59:41 +02002952 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02002953}
2954
Matt4e550962005-07-04 17:51:39 +02002955static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
2956 unsigned int flag)
2957{
2958 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2959 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002960
Takashi Iwaif9acba42007-05-29 18:01:06 +02002961 if (pin_ctl & AC_PINCTL_IN_EN) {
2962 /*
2963 * we need to check the current set-up direction of
2964 * shared input pins since they can be switched via
2965 * "xxx as Output" mixer switch
2966 */
2967 struct sigmatel_spec *spec = codec->spec;
2968 struct auto_pin_cfg *cfg = &spec->autocfg;
2969 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
2970 spec->line_switch) ||
2971 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
2972 spec->mic_switch))
2973 return;
2974 }
2975
Steve Longerbeam7b043892007-05-03 20:50:03 +02002976 /* if setting pin direction bits, clear the current
2977 direction bits first */
2978 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
2979 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
2980
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002981 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002982 AC_VERB_SET_PIN_WIDGET_CONTROL,
2983 pin_ctl | flag);
2984}
2985
2986static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
2987 unsigned int flag)
2988{
2989 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
2990 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002991 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02002992 AC_VERB_SET_PIN_WIDGET_CONTROL,
2993 pin_ctl & ~flag);
2994}
2995
Jiang Zhe40c1d302007-11-12 13:05:16 +01002996static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02002997{
2998 if (!nid)
2999 return 0;
3000 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Jiang Zhe40c1d302007-11-12 13:05:16 +01003001 & (1 << 31)) {
3002 unsigned int pinctl;
3003 pinctl = snd_hda_codec_read(codec, nid, 0,
3004 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3005 if (pinctl & AC_PINCTL_IN_EN)
3006 return 0; /* mic- or line-input */
3007 else
3008 return 1; /* HP-output */
3009 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003010 return 0;
3011}
3012
3013static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02003014{
3015 struct sigmatel_spec *spec = codec->spec;
3016 struct auto_pin_cfg *cfg = &spec->autocfg;
3017 int i, presence;
3018
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003019 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003020 if (spec->gpio_mute)
3021 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
3022 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
3023
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003024 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003025 if (presence)
3026 break;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003027 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003028 }
Matt4e550962005-07-04 17:51:39 +02003029
3030 if (presence) {
3031 /* disable lineouts, enable hp */
3032 for (i = 0; i < cfg->line_outs; i++)
3033 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
3034 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003035 for (i = 0; i < cfg->speaker_outs; i++)
3036 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
3037 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02003038 } else {
3039 /* enable lineouts, disable hp */
3040 for (i = 0; i < cfg->line_outs; i++)
3041 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
3042 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003043 for (i = 0; i < cfg->speaker_outs; i++)
3044 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
3045 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02003046 }
3047}
3048
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003049static void stac92xx_pin_sense(struct hda_codec *codec, int idx)
3050{
3051 struct sigmatel_spec *spec = codec->spec;
3052 hda_nid_t nid = spec->pwr_nids[idx];
3053 int presence, val;
3054 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0)
3055 & 0x000000ff;
3056 presence = get_hp_pin_presence(codec, nid);
3057 idx = 1 << idx;
3058
3059 if (presence)
3060 val &= ~idx;
3061 else
3062 val |= idx;
3063
3064 /* power down unused output ports */
3065 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
3066};
3067
Takashi Iwai314634b2006-09-21 11:56:18 +02003068static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
3069{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003070 struct sigmatel_spec *spec = codec->spec;
3071 int idx = res >> 26 & 0x0f;
3072
3073 switch ((res >> 26) & 0x30) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003074 case STAC_HP_EVENT:
3075 stac92xx_hp_detect(codec, res);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003076 /* fallthru */
3077 case STAC_PWR_EVENT:
3078 if (spec->num_pwrs > 0)
3079 stac92xx_pin_sense(codec, idx);
Takashi Iwai314634b2006-09-21 11:56:18 +02003080 }
3081}
3082
Takashi Iwaicb53c622007-08-10 17:21:45 +02003083#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02003084static int stac92xx_resume(struct hda_codec *codec)
3085{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02003086 struct sigmatel_spec *spec = codec->spec;
3087
Richard Fish11b44bb2006-08-23 18:31:34 +02003088 stac92xx_set_config_regs(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02003089 snd_hda_sequence_write(codec, spec->init);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003090 stac_gpio_set(codec, spec->gpio_mask,
3091 spec->gpio_dir, spec->gpio_data);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003092 snd_hda_codec_resume_amp(codec);
3093 snd_hda_codec_resume_cache(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02003094 /* invoke unsolicited event to reset the HP state */
3095 if (spec->hp_detect)
3096 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Mattff6fdc32005-06-27 15:06:52 +02003097 return 0;
3098}
3099#endif
3100
Matt2f2f4252005-04-13 14:45:30 +02003101static struct hda_codec_ops stac92xx_patch_ops = {
3102 .build_controls = stac92xx_build_controls,
3103 .build_pcms = stac92xx_build_pcms,
3104 .init = stac92xx_init,
3105 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02003106 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02003107#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02003108 .resume = stac92xx_resume,
3109#endif
Matt2f2f4252005-04-13 14:45:30 +02003110};
3111
3112static int patch_stac9200(struct hda_codec *codec)
3113{
3114 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003115 int err;
Matt2f2f4252005-04-13 14:45:30 +02003116
Takashi Iwaie560d8d2005-09-09 14:21:46 +02003117 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02003118 if (spec == NULL)
3119 return -ENOMEM;
3120
3121 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003122 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003123 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003124 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
3125 stac9200_models,
3126 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02003127 if (spec->board_config < 0) {
3128 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
3129 err = stac92xx_save_bios_config_regs(codec);
3130 if (err < 0) {
3131 stac92xx_free(codec);
3132 return err;
3133 }
3134 spec->pin_configs = spec->bios_pin_configs;
3135 } else {
Matt Porter403d1942005-11-29 15:00:51 +01003136 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
3137 stac92xx_set_config_regs(codec);
3138 }
Matt2f2f4252005-04-13 14:45:30 +02003139
3140 spec->multiout.max_channels = 2;
3141 spec->multiout.num_dacs = 1;
3142 spec->multiout.dac_nids = stac9200_dac_nids;
3143 spec->adc_nids = stac9200_adc_nids;
3144 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02003145 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02003146 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003147 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003148 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003149
Takashi Iwai1194b5b2007-10-10 10:04:26 +02003150 if (spec->board_config == STAC_9200_GATEWAY)
3151 spec->init = stac9200_eapd_init;
3152 else
3153 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02003154 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02003155
3156 err = stac9200_parse_auto_config(codec);
3157 if (err < 0) {
3158 stac92xx_free(codec);
3159 return err;
3160 }
Matt2f2f4252005-04-13 14:45:30 +02003161
3162 codec->patch_ops = stac92xx_patch_ops;
3163
3164 return 0;
3165}
3166
Tobin Davis8e21c342007-01-08 11:04:17 +01003167static int patch_stac925x(struct hda_codec *codec)
3168{
3169 struct sigmatel_spec *spec;
3170 int err;
3171
3172 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3173 if (spec == NULL)
3174 return -ENOMEM;
3175
3176 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003177 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01003178 spec->pin_nids = stac925x_pin_nids;
3179 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
3180 stac925x_models,
3181 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003182 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01003183 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02003184 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
3185 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01003186 err = stac92xx_save_bios_config_regs(codec);
3187 if (err < 0) {
3188 stac92xx_free(codec);
3189 return err;
3190 }
3191 spec->pin_configs = spec->bios_pin_configs;
3192 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
3193 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
3194 stac92xx_set_config_regs(codec);
3195 }
3196
3197 spec->multiout.max_channels = 2;
3198 spec->multiout.num_dacs = 1;
3199 spec->multiout.dac_nids = stac925x_dac_nids;
3200 spec->adc_nids = stac925x_adc_nids;
3201 spec->mux_nids = stac925x_mux_nids;
3202 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003203 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003204 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02003205 switch (codec->vendor_id) {
3206 case 0x83847632: /* STAC9202 */
3207 case 0x83847633: /* STAC9202D */
3208 case 0x83847636: /* STAC9251 */
3209 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02003210 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02003211 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003212 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
3213 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02003214 break;
3215 default:
3216 spec->num_dmics = 0;
3217 break;
3218 }
Tobin Davis8e21c342007-01-08 11:04:17 +01003219
3220 spec->init = stac925x_core_init;
3221 spec->mixer = stac925x_mixer;
3222
3223 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003224 if (!err) {
3225 if (spec->board_config < 0) {
3226 printk(KERN_WARNING "hda_codec: No auto-config is "
3227 "available, default to model=ref\n");
3228 spec->board_config = STAC_925x_REF;
3229 goto again;
3230 }
3231 err = -EINVAL;
3232 }
Tobin Davis8e21c342007-01-08 11:04:17 +01003233 if (err < 0) {
3234 stac92xx_free(codec);
3235 return err;
3236 }
3237
3238 codec->patch_ops = stac92xx_patch_ops;
3239
3240 return 0;
3241}
3242
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003243static struct hda_input_mux stac92hd73xx_dmux = {
3244 .num_items = 4,
3245 .items = {
3246 { "Analog Inputs", 0x0b },
3247 { "CD", 0x08 },
3248 { "Digital Mic 1", 0x09 },
3249 { "Digital Mic 2", 0x0a },
3250 }
3251};
3252
3253static int patch_stac92hd73xx(struct hda_codec *codec)
3254{
3255 struct sigmatel_spec *spec;
3256 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
3257 int err = 0;
3258
3259 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3260 if (spec == NULL)
3261 return -ENOMEM;
3262
3263 codec->spec = spec;
3264 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
3265 spec->pin_nids = stac92hd73xx_pin_nids;
3266 spec->board_config = snd_hda_check_board_config(codec,
3267 STAC_92HD73XX_MODELS,
3268 stac92hd73xx_models,
3269 stac92hd73xx_cfg_tbl);
3270again:
3271 if (spec->board_config < 0) {
3272 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3273 " STAC92HD73XX, using BIOS defaults\n");
3274 err = stac92xx_save_bios_config_regs(codec);
3275 if (err < 0) {
3276 stac92xx_free(codec);
3277 return err;
3278 }
3279 spec->pin_configs = spec->bios_pin_configs;
3280 } else {
3281 spec->pin_configs = stac92hd73xx_brd_tbl[spec->board_config];
3282 stac92xx_set_config_regs(codec);
3283 }
3284
3285 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
3286 conn, STAC92HD73_DAC_COUNT + 2) - 1;
3287
3288 if (spec->multiout.num_dacs < 0) {
3289 printk(KERN_WARNING "hda_codec: Could not determine "
3290 "number of channels defaulting to DAC count\n");
3291 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
3292 }
3293
3294 switch (spec->multiout.num_dacs) {
3295 case 0x3: /* 6 Channel */
3296 spec->mixer = stac92hd73xx_6ch_mixer;
3297 spec->init = stac92hd73xx_6ch_core_init;
3298 break;
3299 case 0x4: /* 8 Channel */
3300 spec->multiout.hp_nid = 0x18;
3301 spec->mixer = stac92hd73xx_8ch_mixer;
3302 spec->init = stac92hd73xx_8ch_core_init;
3303 break;
3304 case 0x5: /* 10 Channel */
3305 spec->multiout.hp_nid = 0x19;
3306 spec->mixer = stac92hd73xx_10ch_mixer;
3307 spec->init = stac92hd73xx_10ch_core_init;
3308 };
3309
3310 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
3311 spec->aloopback_mask = 0x01;
3312 spec->aloopback_shift = 8;
3313
3314 spec->mux_nids = stac92hd73xx_mux_nids;
3315 spec->adc_nids = stac92hd73xx_adc_nids;
3316 spec->dmic_nids = stac92hd73xx_dmic_nids;
3317 spec->dmux_nids = stac92hd73xx_dmux_nids;
3318
3319 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
3320 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
3321 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003322 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003323 spec->dinput_mux = &stac92hd73xx_dmux;
3324 /* GPIO0 High = Enable EAPD */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003325 spec->gpio_mask = spec->gpio_dir = 0x1;
3326 spec->gpio_data = 0x01;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003327
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003328 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
3329 spec->pwr_nids = stac92hd73xx_pwr_nids;
3330
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003331 err = stac92xx_parse_auto_config(codec, 0x22, 0x24);
3332
3333 if (!err) {
3334 if (spec->board_config < 0) {
3335 printk(KERN_WARNING "hda_codec: No auto-config is "
3336 "available, default to model=ref\n");
3337 spec->board_config = STAC_92HD73XX_REF;
3338 goto again;
3339 }
3340 err = -EINVAL;
3341 }
3342
3343 if (err < 0) {
3344 stac92xx_free(codec);
3345 return err;
3346 }
3347
3348 codec->patch_ops = stac92xx_patch_ops;
3349
3350 return 0;
3351}
3352
Matthew Ranostaye035b842007-11-06 11:53:55 +01003353static int patch_stac92hd71bxx(struct hda_codec *codec)
3354{
3355 struct sigmatel_spec *spec;
3356 int err = 0;
3357
3358 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3359 if (spec == NULL)
3360 return -ENOMEM;
3361
3362 codec->spec = spec;
3363 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
3364 spec->pin_nids = stac92hd71bxx_pin_nids;
3365 spec->board_config = snd_hda_check_board_config(codec,
3366 STAC_92HD71BXX_MODELS,
3367 stac92hd71bxx_models,
3368 stac92hd71bxx_cfg_tbl);
3369again:
3370 if (spec->board_config < 0) {
3371 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3372 " STAC92HD71BXX, using BIOS defaults\n");
3373 err = stac92xx_save_bios_config_regs(codec);
3374 if (err < 0) {
3375 stac92xx_free(codec);
3376 return err;
3377 }
3378 spec->pin_configs = spec->bios_pin_configs;
3379 } else {
3380 spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config];
3381 stac92xx_set_config_regs(codec);
3382 }
3383
Matthew Ranostay541eee82007-12-14 12:08:04 +01003384 switch (codec->vendor_id) {
3385 case 0x111d76b6: /* 4 Port without Analog Mixer */
3386 case 0x111d76b7:
3387 case 0x111d76b4: /* 6 Port without Analog Mixer */
3388 case 0x111d76b5:
3389 spec->mixer = stac92hd71bxx_mixer;
3390 spec->init = stac92hd71bxx_core_init;
3391 break;
3392 default:
3393 spec->mixer = stac92hd71bxx_analog_mixer;
3394 spec->init = stac92hd71bxx_analog_core_init;
3395 }
3396
3397 spec->aloopback_mask = 0x20;
3398 spec->aloopback_shift = 0;
3399
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003400 /* GPIO0 High = EAPD */
3401 spec->gpio_mask = spec->gpio_dir = spec->gpio_data = 0x1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01003402
Matthew Ranostaye035b842007-11-06 11:53:55 +01003403 spec->mux_nids = stac92hd71bxx_mux_nids;
3404 spec->adc_nids = stac92hd71bxx_adc_nids;
3405 spec->dmic_nids = stac92hd71bxx_dmic_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003406 spec->dmux_nids = stac92hd71bxx_dmux_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01003407
3408 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
3409 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
3410 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003411 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01003412
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003413 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
3414 spec->pwr_nids = stac92hd71bxx_pwr_nids;
3415
Matthew Ranostaye035b842007-11-06 11:53:55 +01003416 spec->multiout.num_dacs = 2;
3417 spec->multiout.hp_nid = 0x11;
3418 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
3419
3420 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
3421 if (!err) {
3422 if (spec->board_config < 0) {
3423 printk(KERN_WARNING "hda_codec: No auto-config is "
3424 "available, default to model=ref\n");
3425 spec->board_config = STAC_92HD71BXX_REF;
3426 goto again;
3427 }
3428 err = -EINVAL;
3429 }
3430
3431 if (err < 0) {
3432 stac92xx_free(codec);
3433 return err;
3434 }
3435
3436 codec->patch_ops = stac92xx_patch_ops;
3437
3438 return 0;
3439};
3440
Matt2f2f4252005-04-13 14:45:30 +02003441static int patch_stac922x(struct hda_codec *codec)
3442{
3443 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003444 int err;
Matt2f2f4252005-04-13 14:45:30 +02003445
Takashi Iwaie560d8d2005-09-09 14:21:46 +02003446 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02003447 if (spec == NULL)
3448 return -ENOMEM;
3449
3450 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003451 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003452 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003453 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
3454 stac922x_models,
3455 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003456 if (spec->board_config == STAC_INTEL_MAC_V3) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003457 spec->gpio_mask = spec->gpio_dir = 0x03;
3458 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003459 /* Intel Macs have all same PCI SSID, so we need to check
3460 * codec SSID to distinguish the exact models
3461 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01003462 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003463 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003464
3465 case 0x106b0800:
3466 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02003467 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003468 case 0x106b0600:
3469 case 0x106b0700:
3470 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01003471 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003472 case 0x106b0e00:
3473 case 0x106b0f00:
3474 case 0x106b1600:
3475 case 0x106b1700:
3476 case 0x106b0200:
3477 case 0x106b1e00:
3478 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003479 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003480 case 0x106b1a00:
3481 case 0x00000100:
3482 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02003483 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003484 case 0x106b0a00:
3485 case 0x106b2200:
3486 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02003487 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003488 }
3489 }
3490
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003491 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02003492 if (spec->board_config < 0) {
3493 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
3494 "using BIOS defaults\n");
3495 err = stac92xx_save_bios_config_regs(codec);
3496 if (err < 0) {
3497 stac92xx_free(codec);
3498 return err;
3499 }
3500 spec->pin_configs = spec->bios_pin_configs;
3501 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01003502 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
3503 stac92xx_set_config_regs(codec);
3504 }
Matt2f2f4252005-04-13 14:45:30 +02003505
Matt2f2f4252005-04-13 14:45:30 +02003506 spec->adc_nids = stac922x_adc_nids;
3507 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01003508 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003509 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02003510 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003511 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003512
3513 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02003514 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02003515
3516 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003517
Matt Porter3cc08dc2006-01-23 15:27:49 +01003518 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003519 if (!err) {
3520 if (spec->board_config < 0) {
3521 printk(KERN_WARNING "hda_codec: No auto-config is "
3522 "available, default to model=ref\n");
3523 spec->board_config = STAC_D945_REF;
3524 goto again;
3525 }
3526 err = -EINVAL;
3527 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01003528 if (err < 0) {
3529 stac92xx_free(codec);
3530 return err;
3531 }
3532
3533 codec->patch_ops = stac92xx_patch_ops;
3534
Takashi Iwai807a46362007-05-29 19:01:37 +02003535 /* Fix Mux capture level; max to 2 */
3536 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
3537 (0 << AC_AMPCAP_OFFSET_SHIFT) |
3538 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3539 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3540 (0 << AC_AMPCAP_MUTE_SHIFT));
3541
Matt Porter3cc08dc2006-01-23 15:27:49 +01003542 return 0;
3543}
3544
3545static int patch_stac927x(struct hda_codec *codec)
3546{
3547 struct sigmatel_spec *spec;
3548 int err;
3549
3550 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3551 if (spec == NULL)
3552 return -ENOMEM;
3553
3554 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003555 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003556 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003557 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
3558 stac927x_models,
3559 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003560 again:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003561 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
3562 if (spec->board_config < 0)
3563 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3564 "STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02003565 err = stac92xx_save_bios_config_regs(codec);
3566 if (err < 0) {
3567 stac92xx_free(codec);
3568 return err;
3569 }
3570 spec->pin_configs = spec->bios_pin_configs;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003571 } else {
Matt Porter3cc08dc2006-01-23 15:27:49 +01003572 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
3573 stac92xx_set_config_regs(codec);
3574 }
3575
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003576 spec->adc_nids = stac927x_adc_nids;
3577 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
3578 spec->mux_nids = stac927x_mux_nids;
3579 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
3580 spec->multiout.dac_nids = spec->dac_nids;
3581
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003582 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02003583 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003584 case STAC_D965_5ST:
3585 /* GPIO0 High = Enable EAPD */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003586 spec->gpio_mask = spec->gpio_dir = 0x01;
3587 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003588 spec->num_dmics = 0;
3589
Tobin Davis93ed1502006-09-01 21:03:12 +02003590 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003591 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003592 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003593 case STAC_DELL_BIOS:
Matthew Ranostay2f32d902008-01-10 13:06:26 +01003594 /* correct the front output jack as a hp out */
3595 stac92xx_set_config_reg(codec, 0x0f, 0x02270110);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01003596 /* correct the front input jack as a mic */
3597 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130);
3598 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003599 case STAC_DELL_3ST:
3600 /* GPIO2 High = Enable EAPD */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003601 spec->gpio_mask = spec->gpio_dir = 0x04;
3602 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003603 spec->dmic_nids = stac927x_dmic_nids;
3604 spec->num_dmics = STAC927X_NUM_DMICS;
3605
Tobin Davis93ed1502006-09-01 21:03:12 +02003606 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003607 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003608 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003609 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003610 break;
3611 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003612 /* GPIO0 High = Enable EAPD */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003613 spec->gpio_mask = spec->gpio_dir = 0x1;
3614 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003615 spec->num_dmics = 0;
3616
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003617 spec->init = stac927x_core_init;
3618 spec->mixer = stac927x_mixer;
3619 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01003620
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003621 spec->num_pwrs = 0;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003622 spec->aloopback_mask = 0x40;
3623 spec->aloopback_shift = 0;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003624
Matt Porter3cc08dc2006-01-23 15:27:49 +01003625 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003626 if (!err) {
3627 if (spec->board_config < 0) {
3628 printk(KERN_WARNING "hda_codec: No auto-config is "
3629 "available, default to model=ref\n");
3630 spec->board_config = STAC_D965_REF;
3631 goto again;
3632 }
3633 err = -EINVAL;
3634 }
Mattc7d4b2f2005-06-27 14:59:41 +02003635 if (err < 0) {
3636 stac92xx_free(codec);
3637 return err;
3638 }
Matt2f2f4252005-04-13 14:45:30 +02003639
3640 codec->patch_ops = stac92xx_patch_ops;
3641
Takashi Iwai52987652008-01-16 16:09:47 +01003642 /*
3643 * !!FIXME!!
3644 * The STAC927x seem to require fairly long delays for certain
3645 * command sequences. With too short delays (even if the answer
3646 * is set to RIRB properly), it results in the silence output
3647 * on some hardwares like Dell.
3648 *
3649 * The below flag enables the longer delay (see get_response
3650 * in hda_intel.c).
3651 */
3652 codec->bus->needs_damn_long_delay = 1;
3653
Matt2f2f4252005-04-13 14:45:30 +02003654 return 0;
3655}
3656
Matt Porterf3302a52006-07-31 12:49:34 +02003657static int patch_stac9205(struct hda_codec *codec)
3658{
3659 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02003660 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02003661
3662 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3663 if (spec == NULL)
3664 return -ENOMEM;
3665
3666 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003667 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003668 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003669 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
3670 stac9205_models,
3671 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003672 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02003673 if (spec->board_config < 0) {
3674 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
3675 err = stac92xx_save_bios_config_regs(codec);
3676 if (err < 0) {
3677 stac92xx_free(codec);
3678 return err;
3679 }
3680 spec->pin_configs = spec->bios_pin_configs;
3681 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02003682 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
3683 stac92xx_set_config_regs(codec);
3684 }
3685
3686 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003687 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02003688 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01003689 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02003690 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02003691 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003692 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003693 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003694 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02003695
3696 spec->init = stac9205_core_init;
3697 spec->mixer = stac9205_mixer;
3698
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003699 spec->aloopback_mask = 0x40;
3700 spec->aloopback_shift = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02003701 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02003702
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003703 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003704 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02003705 /* Enable SPDIF in/out */
3706 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
3707 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01003708
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003709 /* Enable unsol response for GPIO4/Dock HP connection */
3710 snd_hda_codec_write(codec, codec->afg, 0,
3711 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
3712 snd_hda_codec_write_cache(codec, codec->afg, 0,
3713 AC_VERB_SET_UNSOLICITED_ENABLE,
3714 (AC_USRSP_EN | STAC_HP_EVENT));
3715
3716 spec->gpio_dir = 0x0b;
3717 spec->gpio_mask = 0x1b;
3718 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01003719 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003720 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02003721 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003722 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003723 break;
3724 default:
3725 /* GPIO0 High = EAPD */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003726 spec->gpio_mask = spec->gpio_dir = 0x1;
3727 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003728 break;
3729 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02003730
Matt Porterf3302a52006-07-31 12:49:34 +02003731 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003732 if (!err) {
3733 if (spec->board_config < 0) {
3734 printk(KERN_WARNING "hda_codec: No auto-config is "
3735 "available, default to model=ref\n");
3736 spec->board_config = STAC_9205_REF;
3737 goto again;
3738 }
3739 err = -EINVAL;
3740 }
Matt Porterf3302a52006-07-31 12:49:34 +02003741 if (err < 0) {
3742 stac92xx_free(codec);
3743 return err;
3744 }
3745
3746 codec->patch_ops = stac92xx_patch_ops;
3747
3748 return 0;
3749}
3750
Matt2f2f4252005-04-13 14:45:30 +02003751/*
Guillaume Munch6d859062006-08-22 17:15:47 +02003752 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01003753 */
3754
Guillaume Munch99ccc562006-08-16 19:35:12 +02003755/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003756static hda_nid_t vaio_dacs[] = { 0x2 };
3757#define VAIO_HP_DAC 0x5
3758static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
3759static hda_nid_t vaio_mux_nids[] = { 0x15 };
3760
3761static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02003762 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01003763 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02003764 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003765 { "Mic Jack", 0x1 },
3766 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01003767 { "PCM", 0x3 },
3768 }
3769};
3770
3771static struct hda_verb vaio_init[] = {
3772 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003773 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01003774 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3775 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3776 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3777 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003778 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003779 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3780 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3781 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3782 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3783 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3784 {}
3785};
3786
Guillaume Munch6d859062006-08-22 17:15:47 +02003787static struct hda_verb vaio_ar_init[] = {
3788 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
3789 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3790 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3791 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3792/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
3793 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003794 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02003795 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3796 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3797/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
3798 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3799 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3800 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3801 {}
3802};
3803
Takashi Iwaidb064e52006-03-16 16:04:58 +01003804/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003805static struct hda_bind_ctls vaio_bind_master_vol = {
3806 .ops = &snd_hda_bind_vol,
3807 .values = {
3808 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3809 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3810 0
3811 },
3812};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003813
3814/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003815static struct hda_bind_ctls vaio_bind_master_sw = {
3816 .ops = &snd_hda_bind_sw,
3817 .values = {
3818 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3819 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3820 0,
3821 },
3822};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003823
3824static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003825 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3826 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003827 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3828 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3829 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3830 {
3831 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3832 .name = "Capture Source",
3833 .count = 1,
3834 .info = stac92xx_mux_enum_info,
3835 .get = stac92xx_mux_enum_get,
3836 .put = stac92xx_mux_enum_put,
3837 },
3838 {}
3839};
3840
Guillaume Munch6d859062006-08-22 17:15:47 +02003841static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003842 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3843 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Guillaume Munch6d859062006-08-22 17:15:47 +02003844 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3845 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3846 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3847 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
3848 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
3849 {
3850 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3851 .name = "Capture Source",
3852 .count = 1,
3853 .info = stac92xx_mux_enum_info,
3854 .get = stac92xx_mux_enum_get,
3855 .put = stac92xx_mux_enum_put,
3856 },
3857 {}
3858};
3859
3860static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01003861 .build_controls = stac92xx_build_controls,
3862 .build_pcms = stac92xx_build_pcms,
3863 .init = stac92xx_init,
3864 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02003865#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01003866 .resume = stac92xx_resume,
3867#endif
3868};
3869
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003870static int stac9872_vaio_init(struct hda_codec *codec)
3871{
3872 int err;
3873
3874 err = stac92xx_init(codec);
3875 if (err < 0)
3876 return err;
3877 if (codec->patch_ops.unsol_event)
3878 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
3879 return 0;
3880}
3881
3882static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
3883{
Jiang Zhe40c1d302007-11-12 13:05:16 +01003884 if (get_hp_pin_presence(codec, 0x0a)) {
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003885 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3886 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3887 } else {
3888 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
3889 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
3890 }
3891}
3892
3893static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
3894{
3895 switch (res >> 26) {
3896 case STAC_HP_EVENT:
3897 stac9872_vaio_hp_detect(codec, res);
3898 break;
3899 }
3900}
3901
3902static struct hda_codec_ops stac9872_vaio_patch_ops = {
3903 .build_controls = stac92xx_build_controls,
3904 .build_pcms = stac92xx_build_pcms,
3905 .init = stac9872_vaio_init,
3906 .free = stac92xx_free,
3907 .unsol_event = stac9872_vaio_unsol_event,
3908#ifdef CONFIG_PM
3909 .resume = stac92xx_resume,
3910#endif
3911};
3912
Guillaume Munch6d859062006-08-22 17:15:47 +02003913enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
3914 CXD9872RD_VAIO,
3915 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
3916 STAC9872AK_VAIO,
3917 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
3918 STAC9872K_VAIO,
3919 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003920 CXD9872AKD_VAIO,
3921 STAC_9872_MODELS,
3922};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003923
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003924static const char *stac9872_models[STAC_9872_MODELS] = {
3925 [CXD9872RD_VAIO] = "vaio",
3926 [CXD9872AKD_VAIO] = "vaio-ar",
3927};
3928
3929static struct snd_pci_quirk stac9872_cfg_tbl[] = {
3930 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
3931 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
3932 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01003933 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003934 {}
3935};
3936
Guillaume Munch6d859062006-08-22 17:15:47 +02003937static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01003938{
3939 struct sigmatel_spec *spec;
3940 int board_config;
3941
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003942 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
3943 stac9872_models,
3944 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01003945 if (board_config < 0)
3946 /* unknown config, let generic-parser do its job... */
3947 return snd_hda_parse_generic_codec(codec);
3948
3949 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3950 if (spec == NULL)
3951 return -ENOMEM;
3952
3953 codec->spec = spec;
3954 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02003955 case CXD9872RD_VAIO:
3956 case STAC9872AK_VAIO:
3957 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01003958 spec->mixer = vaio_mixer;
3959 spec->init = vaio_init;
3960 spec->multiout.max_channels = 2;
3961 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3962 spec->multiout.dac_nids = vaio_dacs;
3963 spec->multiout.hp_nid = VAIO_HP_DAC;
3964 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
3965 spec->adc_nids = vaio_adcs;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003966 spec->num_pwrs = 0;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003967 spec->input_mux = &vaio_mux;
3968 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003969 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003970 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02003971
3972 case CXD9872AKD_VAIO:
3973 spec->mixer = vaio_ar_mixer;
3974 spec->init = vaio_ar_init;
3975 spec->multiout.max_channels = 2;
3976 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
3977 spec->multiout.dac_nids = vaio_dacs;
3978 spec->multiout.hp_nid = VAIO_HP_DAC;
3979 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003980 spec->num_pwrs = 0;
Guillaume Munch6d859062006-08-22 17:15:47 +02003981 spec->adc_nids = vaio_adcs;
3982 spec->input_mux = &vaio_mux;
3983 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003984 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02003985 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01003986 }
3987
Takashi Iwaidb064e52006-03-16 16:04:58 +01003988 return 0;
3989}
3990
3991
3992/*
Matt2f2f4252005-04-13 14:45:30 +02003993 * patch entries
3994 */
3995struct hda_codec_preset snd_hda_preset_sigmatel[] = {
3996 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
3997 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
3998 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
3999 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
4000 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
4001 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
4002 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02004003 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
4004 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
4005 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
4006 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
4007 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
4008 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01004009 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
4010 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
4011 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
4012 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
4013 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
4014 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
4015 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
4016 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
4017 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
4018 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01004019 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
4020 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
4021 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
4022 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
4023 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
4024 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02004025 /* The following does not take into account .id=0x83847661 when subsys =
4026 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
4027 * currently not fully supported.
4028 */
4029 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
4030 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
4031 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02004032 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
4033 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
4034 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
4035 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
4036 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
4037 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
4038 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
4039 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostay541eee82007-12-14 12:08:04 +01004040 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
4041 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004042 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01004043 { .id = 0x111d7608, .name = "92HD71BXX", .patch = patch_stac92hd71bxx },
4044 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
4045 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
4046 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
4047 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
4048 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
4049 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
4050 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
4051 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02004052 {} /* terminator */
4053};