blob: b7b41969180348943f95a744d71151b65a40a10f [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>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040033#include <sound/jack.h>
Matt2f2f4252005-04-13 14:45:30 +020034#include "hda_codec.h"
35#include "hda_local.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020036#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020037
Takashi Iwaic6e4c662008-11-25 11:58:19 +010038enum {
39 STAC_VREF_EVENT = 1,
40 STAC_INSERT_EVENT,
41 STAC_PWR_EVENT,
42 STAC_HP_EVENT,
43};
Matt4e550962005-07-04 17:51:39 +020044
Takashi Iwaif5fcc132006-11-24 17:07:44 +010045enum {
46 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010047 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020048 STAC_9200_DELL_D21,
49 STAC_9200_DELL_D22,
50 STAC_9200_DELL_D23,
51 STAC_9200_DELL_M21,
52 STAC_9200_DELL_M22,
53 STAC_9200_DELL_M23,
54 STAC_9200_DELL_M24,
55 STAC_9200_DELL_M25,
56 STAC_9200_DELL_M26,
57 STAC_9200_DELL_M27,
Takashi Iwai1194b5b2007-10-10 10:04:26 +020058 STAC_9200_GATEWAY,
Takashi Iwai117f2572008-03-18 09:53:23 +010059 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010060 STAC_9200_MODELS
61};
62
63enum {
64 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020065 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020066 STAC_9205_DELL_M43,
67 STAC_9205_DELL_M44,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010068 STAC_9205_MODELS
69};
70
71enum {
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010072 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010073 STAC_92HD73XX_REF,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010074 STAC_DELL_M6_AMIC,
75 STAC_DELL_M6_DMIC,
76 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050077 STAC_DELL_EQ,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010078 STAC_92HD73XX_MODELS
79};
80
81enum {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020082 STAC_92HD83XXX_REF,
83 STAC_92HD83XXX_MODELS
84};
85
86enum {
Matthew Ranostaye035b842007-11-06 11:53:55 +010087 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010088 STAC_DELL_M4_1,
89 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -050090 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -040091 STAC_HP_M4,
Matthew Ranostaye035b842007-11-06 11:53:55 +010092 STAC_92HD71BXX_MODELS
93};
94
95enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010096 STAC_925x_REF,
97 STAC_M2_2,
98 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020099 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100100 STAC_925x_MODELS
101};
102
103enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100104 STAC_D945_REF,
105 STAC_D945GTP3,
106 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200107 STAC_INTEL_MAC_V1,
108 STAC_INTEL_MAC_V2,
109 STAC_INTEL_MAC_V3,
110 STAC_INTEL_MAC_V4,
111 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800112 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
113 * is given, one of the above models will be
114 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200115 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100116 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100117 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100118 STAC_MACBOOK_PRO_V1,
119 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200120 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200121 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300122 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200123 STAC_922X_DELL_D81,
124 STAC_922X_DELL_D82,
125 STAC_922X_DELL_M81,
126 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100127 STAC_922X_MODELS
128};
129
130enum {
Takashi Iwaie28d8322008-12-17 13:48:29 +0100131 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100132 STAC_D965_REF,
133 STAC_D965_3ST,
134 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200135 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100136 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100137 STAC_927X_MODELS
138};
Matt Porter403d1942005-11-29 15:00:51 +0100139
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400140struct sigmatel_event {
141 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100142 unsigned char type;
143 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400144 int data;
145};
146
147struct sigmatel_jack {
148 hda_nid_t nid;
149 int type;
150 struct snd_jack *jack;
151};
152
Matt2f2f4252005-04-13 14:45:30 +0200153struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100154 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200155 unsigned int num_mixers;
156
Matt Porter403d1942005-11-29 15:00:51 +0100157 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500158 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200159 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +0100160 unsigned int line_switch: 1;
161 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100162 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100163 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400164 unsigned int spdif_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200165
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100166 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200167 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100168 unsigned int gpio_mask;
169 unsigned int gpio_dir;
170 unsigned int gpio_data;
171 unsigned int gpio_mute;
172
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200173 /* stream */
174 unsigned int stream_delay;
175
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100176 /* analog loopback */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100177 unsigned char aloopback_mask;
178 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200179
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100180 /* power management */
181 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200182 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100183 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100184 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100185
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400186 /* jack detection */
187 struct snd_array jacks;
188
189 /* events */
190 struct snd_array events;
191
Matt2f2f4252005-04-13 14:45:30 +0200192 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100193 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400194 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100195 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200196 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100197 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200198
199 /* capture */
200 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200201 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200202 hda_nid_t *mux_nids;
203 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200204 hda_nid_t *dmic_nids;
205 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100206 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100207 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200208 hda_nid_t *smux_nids;
209 unsigned int num_smuxes;
Matthew Ranostay65973632008-09-16 10:39:37 -0400210 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200211
Mattdabbed62005-06-14 10:19:34 +0200212 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100213 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200214 hda_nid_t anabeep_nid;
215 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200216
Matt2f2f4252005-04-13 14:45:30 +0200217 /* pin widgets */
218 hda_nid_t *pin_nids;
219 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200220 unsigned int *pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200221
222 /* codec specific stuff */
223 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100224 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200225
226 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200227 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100228 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200229 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100230 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200231 struct hda_input_mux *sinput_mux;
232 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400233 unsigned int cur_amux;
234 hda_nid_t *amp_nids;
235 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200236 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200237
Matt Porter403d1942005-11-29 15:00:51 +0100238 /* i/o switches */
239 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200240 unsigned int clfe_swap;
Takashi Iwaid7a89432008-11-12 09:48:04 +0100241 unsigned int hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200242 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200243
Mattc7d4b2f2005-06-27 14:59:41 +0200244 struct hda_pcm pcm_rec[2]; /* PCM information */
245
246 /* dynamic controls and input_mux */
247 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200248 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200249 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200250 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200251 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400252 struct hda_input_mux private_amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100253 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200254};
255
256static hda_nid_t stac9200_adc_nids[1] = {
257 0x03,
258};
259
260static hda_nid_t stac9200_mux_nids[1] = {
261 0x0c,
262};
263
264static hda_nid_t stac9200_dac_nids[1] = {
265 0x02,
266};
267
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100268static hda_nid_t stac92hd73xx_pwr_nids[8] = {
269 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
270 0x0f, 0x10, 0x11
271};
272
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400273static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
274 0x26, 0,
275};
276
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100277static hda_nid_t stac92hd73xx_adc_nids[2] = {
278 0x1a, 0x1b
279};
280
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400281#define DELL_M6_AMP 2
282static hda_nid_t stac92hd73xx_amp_nids[3] = {
283 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400284};
285
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100286#define STAC92HD73XX_NUM_DMICS 2
287static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
288 0x13, 0x14, 0
289};
290
291#define STAC92HD73_DAC_COUNT 5
292static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
293 0x15, 0x16, 0x17, 0x18, 0x19,
294};
295
296static hda_nid_t stac92hd73xx_mux_nids[4] = {
297 0x28, 0x29, 0x2a, 0x2b,
298};
299
300static hda_nid_t stac92hd73xx_dmux_nids[2] = {
301 0x20, 0x21,
302};
303
Matthew Ranostayd9737752008-09-07 12:03:41 +0200304static hda_nid_t stac92hd73xx_smux_nids[2] = {
305 0x22, 0x23,
306};
307
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200308#define STAC92HD83XXX_NUM_DMICS 2
309static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
310 0x11, 0x12, 0
311};
312
313#define STAC92HD81_DAC_COUNT 2
314#define STAC92HD83_DAC_COUNT 3
315static hda_nid_t stac92hd83xxx_dac_nids[STAC92HD73_DAC_COUNT] = {
316 0x13, 0x14, 0x22,
317};
318
319static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
320 0x17, 0x18,
321};
322
323static hda_nid_t stac92hd83xxx_adc_nids[2] = {
324 0x15, 0x16,
325};
326
327static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
328 0xa, 0xb, 0xd, 0xe,
329};
330
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400331static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
332 0x1e, 0,
333};
334
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200335static unsigned int stac92hd83xxx_pwr_mapping[4] = {
336 0x03, 0x0c, 0x10, 0x40,
337};
338
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100339static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
340 0x0a, 0x0d, 0x0f
341};
342
Matthew Ranostaye035b842007-11-06 11:53:55 +0100343static hda_nid_t stac92hd71bxx_adc_nids[2] = {
344 0x12, 0x13,
345};
346
347static hda_nid_t stac92hd71bxx_mux_nids[2] = {
348 0x1a, 0x1b
349};
350
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400351static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
352 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100353};
354
Matthew Ranostayd9737752008-09-07 12:03:41 +0200355static hda_nid_t stac92hd71bxx_smux_nids[2] = {
356 0x24, 0x25,
357};
358
Takashi Iwaiaea7bb02008-02-25 18:26:41 +0100359static hda_nid_t stac92hd71bxx_dac_nids[1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100360 0x10, /*0x11, */
361};
362
363#define STAC92HD71BXX_NUM_DMICS 2
364static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
365 0x18, 0x19, 0
366};
367
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400368static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
369 0x22, 0
370};
371
Tobin Davis8e21c342007-01-08 11:04:17 +0100372static hda_nid_t stac925x_adc_nids[1] = {
373 0x03,
374};
375
376static hda_nid_t stac925x_mux_nids[1] = {
377 0x0f,
378};
379
380static hda_nid_t stac925x_dac_nids[1] = {
381 0x02,
382};
383
Takashi Iwaif6e98522007-10-16 14:27:04 +0200384#define STAC925X_NUM_DMICS 1
385static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
386 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200387};
388
Takashi Iwai1697055e2007-12-18 18:05:52 +0100389static hda_nid_t stac925x_dmux_nids[1] = {
390 0x14,
391};
392
Matt2f2f4252005-04-13 14:45:30 +0200393static hda_nid_t stac922x_adc_nids[2] = {
394 0x06, 0x07,
395};
396
397static hda_nid_t stac922x_mux_nids[2] = {
398 0x12, 0x13,
399};
400
Matt Porter3cc08dc2006-01-23 15:27:49 +0100401static hda_nid_t stac927x_adc_nids[3] = {
402 0x07, 0x08, 0x09
403};
404
405static hda_nid_t stac927x_mux_nids[3] = {
406 0x15, 0x16, 0x17
407};
408
Matthew Ranostayd9737752008-09-07 12:03:41 +0200409static hda_nid_t stac927x_smux_nids[1] = {
410 0x21,
411};
412
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100413static hda_nid_t stac927x_dac_nids[6] = {
414 0x02, 0x03, 0x04, 0x05, 0x06, 0
415};
416
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100417static hda_nid_t stac927x_dmux_nids[1] = {
418 0x1b,
419};
420
Matthew Ranostay7f168592007-10-18 17:38:17 +0200421#define STAC927X_NUM_DMICS 2
422static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
423 0x13, 0x14, 0
424};
425
Matthew Ranostay65973632008-09-16 10:39:37 -0400426static const char *stac927x_spdif_labels[5] = {
427 "Digital Playback", "ADAT", "Analog Mux 1",
428 "Analog Mux 2", "Analog Mux 3"
429};
430
Matt Porterf3302a52006-07-31 12:49:34 +0200431static hda_nid_t stac9205_adc_nids[2] = {
432 0x12, 0x13
433};
434
435static hda_nid_t stac9205_mux_nids[2] = {
436 0x19, 0x1a
437};
438
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100439static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100440 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100441};
442
Matthew Ranostayd9737752008-09-07 12:03:41 +0200443static hda_nid_t stac9205_smux_nids[1] = {
444 0x21,
445};
446
Takashi Iwaif6e98522007-10-16 14:27:04 +0200447#define STAC9205_NUM_DMICS 2
448static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
449 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200450};
451
Mattc7d4b2f2005-06-27 14:59:41 +0200452static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200453 0x08, 0x09, 0x0d, 0x0e,
454 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200455};
456
Tobin Davis8e21c342007-01-08 11:04:17 +0100457static hda_nid_t stac925x_pin_nids[8] = {
458 0x07, 0x08, 0x0a, 0x0b,
459 0x0c, 0x0d, 0x10, 0x11,
460};
461
Matt2f2f4252005-04-13 14:45:30 +0200462static hda_nid_t stac922x_pin_nids[10] = {
463 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
464 0x0f, 0x10, 0x11, 0x15, 0x1b,
465};
466
Matthew Ranostaya7662642008-02-21 07:51:14 +0100467static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100468 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
469 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200470 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100471};
472
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200473static hda_nid_t stac92hd83xxx_pin_nids[14] = {
474 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
475 0x0f, 0x10, 0x11, 0x12, 0x13,
476 0x1d, 0x1e, 0x1f, 0x20
477};
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400478static hda_nid_t stac92hd71bxx_pin_nids[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100479 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
480 0x0f, 0x14, 0x18, 0x19, 0x1e,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400481 0x1f,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100482};
483
Matt Porter3cc08dc2006-01-23 15:27:49 +0100484static hda_nid_t stac927x_pin_nids[14] = {
485 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
486 0x0f, 0x10, 0x11, 0x12, 0x13,
487 0x14, 0x21, 0x22, 0x23,
488};
489
Matt Porterf3302a52006-07-31 12:49:34 +0200490static hda_nid_t stac9205_pin_nids[12] = {
491 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
492 0x0f, 0x14, 0x16, 0x17, 0x18,
493 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200494};
495
Matthew Ranostay89385032008-09-11 09:49:39 -0400496#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
497
498static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
499 struct snd_ctl_elem_value *ucontrol)
500{
501 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
502 struct sigmatel_spec *spec = codec->spec;
503 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
504
505 kcontrol->private_value ^= get_amp_nid(kcontrol);
506 kcontrol->private_value |= nid;
507
508 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
509}
510
511static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
512 struct snd_ctl_elem_value *ucontrol)
513{
514 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
515 struct sigmatel_spec *spec = codec->spec;
516 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
517
518 kcontrol->private_value ^= get_amp_nid(kcontrol);
519 kcontrol->private_value |= nid;
520
521 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
522}
523
Matt Porter8b657272006-10-26 17:12:59 +0200524static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
525 struct snd_ctl_elem_info *uinfo)
526{
527 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
528 struct sigmatel_spec *spec = codec->spec;
529 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
530}
531
532static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
533 struct snd_ctl_elem_value *ucontrol)
534{
535 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
536 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100537 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200538
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100539 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200540 return 0;
541}
542
543static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
544 struct snd_ctl_elem_value *ucontrol)
545{
546 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
547 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100548 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200549
550 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100551 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200552}
553
Matthew Ranostayd9737752008-09-07 12:03:41 +0200554static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
555 struct snd_ctl_elem_info *uinfo)
556{
557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
558 struct sigmatel_spec *spec = codec->spec;
559 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
560}
561
562static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
563 struct snd_ctl_elem_value *ucontrol)
564{
565 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
566 struct sigmatel_spec *spec = codec->spec;
567 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
568
569 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
570 return 0;
571}
572
573static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
574 struct snd_ctl_elem_value *ucontrol)
575{
576 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
577 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400578 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200579 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400580 int err, val;
581 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200582
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400583 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200584 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400585 if (err < 0)
586 return err;
587
588 if (spec->spdif_mute) {
589 if (smux_idx == 0)
590 nid = spec->multiout.dig_out_nid;
591 else
592 nid = codec->slave_dig_outs[smux_idx - 1];
593 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100594 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400595 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100596 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400597 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100598 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
599 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400600 }
601 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200602}
603
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100604static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200605{
606 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
607 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200608 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200609}
610
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100611static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200612{
613 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
614 struct sigmatel_spec *spec = codec->spec;
615 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
616
617 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
618 return 0;
619}
620
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100621static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200622{
623 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
624 struct sigmatel_spec *spec = codec->spec;
625 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
626
Mattc7d4b2f2005-06-27 14:59:41 +0200627 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200628 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
629}
630
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100631static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
632 struct snd_ctl_elem_info *uinfo)
633{
634 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
635 struct sigmatel_spec *spec = codec->spec;
636 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
637}
638
639static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
640 struct snd_ctl_elem_value *ucontrol)
641{
642 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
643 struct sigmatel_spec *spec = codec->spec;
644
645 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
646 return 0;
647}
648
649static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
650 struct snd_ctl_elem_value *ucontrol)
651{
652 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
653 struct sigmatel_spec *spec = codec->spec;
654
655 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
656 spec->mono_nid, &spec->cur_mmux);
657}
658
Matthew Ranostay89385032008-09-11 09:49:39 -0400659static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
660 struct snd_ctl_elem_info *uinfo)
661{
662 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
663 struct sigmatel_spec *spec = codec->spec;
664 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
665}
666
667static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
668 struct snd_ctl_elem_value *ucontrol)
669{
670 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
671 struct sigmatel_spec *spec = codec->spec;
672
673 ucontrol->value.enumerated.item[0] = spec->cur_amux;
674 return 0;
675}
676
677static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
678 struct snd_ctl_elem_value *ucontrol)
679{
680 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
681 struct sigmatel_spec *spec = codec->spec;
682 struct snd_kcontrol *ctl =
683 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
684 if (!ctl)
685 return -EINVAL;
686
687 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
688 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
689
690 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
691 0, &spec->cur_amux);
692}
693
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200694#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
695
696static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
697 struct snd_ctl_elem_value *ucontrol)
698{
699 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100700 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200701 struct sigmatel_spec *spec = codec->spec;
702
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100703 ucontrol->value.integer.value[0] = !!(spec->aloopback &
704 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200705 return 0;
706}
707
708static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
709 struct snd_ctl_elem_value *ucontrol)
710{
711 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
712 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100713 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200714 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100715 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200716
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100717 idx_val = spec->aloopback_mask << idx;
718 if (ucontrol->value.integer.value[0])
719 val = spec->aloopback | idx_val;
720 else
721 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100722 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200723 return 0;
724
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100725 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200726
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100727 /* Only return the bits defined by the shift value of the
728 * first two bytes of the mask
729 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200730 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100731 kcontrol->private_value & 0xFFFF, 0x0);
732 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200733
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100734 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200735 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100736 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200737 } else {
738 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100739 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200740 }
741
742 snd_hda_codec_write_cache(codec, codec->afg, 0,
743 kcontrol->private_value >> 16, dac_mode);
744
745 return 1;
746}
747
Mattc7d4b2f2005-06-27 14:59:41 +0200748static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200749 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200750 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200751 {}
752};
753
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200754static struct hda_verb stac9200_eapd_init[] = {
755 /* set dac0mux for dac converter */
756 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
757 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
758 {}
759};
760
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100761static struct hda_verb stac92hd73xx_6ch_core_init[] = {
762 /* set master volume and direct control */
763 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
764 /* setup audio connections */
765 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
766 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
767 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
768 /* setup adcs to point to mixer */
769 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
770 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100771 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
772 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
773 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
774 /* setup import muxs */
775 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
776 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
777 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
778 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
779 {}
780};
781
Matthew Ranostayd654a662008-03-14 08:46:51 +0100782static struct hda_verb dell_eq_core_init[] = {
783 /* set master volume to max value without distortion
784 * and direct control */
785 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
786 /* setup audio connections */
787 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
Matthew Ranostayf7cf0a72008-09-13 10:36:58 -0400788 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x02},
789 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100790 /* setup adcs to point to mixer */
791 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
792 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
793 /* setup import muxs */
794 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
795 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
796 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
797 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
798 {}
799};
800
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100801static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500802 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100803 /* setup audio connections */
Matthew Ranostay7747ecc2008-03-10 11:30:04 +0100804 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
805 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100806 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
807 /* setup adcs to point to mixer */
808 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
809 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
810 /* setup import muxs */
811 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
812 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
813 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
814 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
815 {}
816};
817
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100818static struct hda_verb stac92hd73xx_8ch_core_init[] = {
819 /* set master volume and direct control */
820 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
821 /* setup audio connections */
822 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
823 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
824 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
825 /* connect hp ports to dac3 */
826 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
827 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
828 /* setup adcs to point to mixer */
829 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
830 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100831 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
832 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
833 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
834 /* setup import muxs */
835 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
836 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
837 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
838 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
839 {}
840};
841
842static struct hda_verb stac92hd73xx_10ch_core_init[] = {
843 /* set master volume and direct control */
844 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
845 /* setup audio connections */
846 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
847 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
848 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
849 /* dac3 is connected to import3 mux */
850 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
851 /* connect hp ports to dac4 */
852 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
853 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
854 /* setup adcs to point to mixer */
855 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
856 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100857 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
858 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
859 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
860 /* setup import muxs */
861 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
862 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
863 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
864 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
865 {}
866};
867
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200868static struct hda_verb stac92hd83xxx_core_init[] = {
869 /* start of config #1 */
870 { 0xe, AC_VERB_SET_CONNECT_SEL, 0x3},
871
872 /* start of config #2 */
873 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0},
874 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0},
875 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1},
876
877 /* power state controls amps */
878 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
879};
880
Matthew Ranostaye035b842007-11-06 11:53:55 +0100881static struct hda_verb stac92hd71bxx_core_init[] = {
882 /* set master volume and direct control */
883 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
884 /* connect headphone jack to dac1 */
885 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100886 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
887 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
888 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
889 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100890};
891
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400892#define HD_DISABLE_PORTF 2
Matthew Ranostay541eee82007-12-14 12:08:04 +0100893static struct hda_verb stac92hd71bxx_analog_core_init[] = {
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200894 /* start of config #1 */
895
896 /* connect port 0f to audio mixer */
897 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200898 /* unmute right and left channels for node 0x0f */
899 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
900 /* start of config #2 */
901
Matthew Ranostay541eee82007-12-14 12:08:04 +0100902 /* set master volume and direct control */
903 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
904 /* connect headphone jack to dac1 */
905 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200906 /* unmute right and left channels for nodes 0x0a, 0xd */
Matthew Ranostaye035b842007-11-06 11:53:55 +0100907 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
908 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100909 {}
910};
911
Tobin Davis8e21c342007-01-08 11:04:17 +0100912static struct hda_verb stac925x_core_init[] = {
913 /* set dac0mux for dac converter */
914 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
915 {}
916};
917
Mattc7d4b2f2005-06-27 14:59:41 +0200918static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200919 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200920 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200921 {}
922};
923
Tobin Davis93ed1502006-09-01 21:03:12 +0200924static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200925 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200926 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200927 /* unmute node 0x1b */
928 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
929 /* select node 0x03 as DAC */
930 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
931 {}
932};
933
Matt Porter3cc08dc2006-01-23 15:27:49 +0100934static struct hda_verb stac927x_core_init[] = {
935 /* set master volume and direct control */
936 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200937 /* enable analog pc beep path */
938 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100939 {}
940};
941
Matt Porterf3302a52006-07-31 12:49:34 +0200942static struct hda_verb stac9205_core_init[] = {
943 /* set master volume and direct control */
944 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200945 /* enable analog pc beep path */
946 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200947 {}
948};
949
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100950#define STAC_MONO_MUX \
951 { \
952 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
953 .name = "Mono Mux", \
954 .count = 1, \
955 .info = stac92xx_mono_mux_enum_info, \
956 .get = stac92xx_mono_mux_enum_get, \
957 .put = stac92xx_mono_mux_enum_put, \
958 }
959
Matthew Ranostay89385032008-09-11 09:49:39 -0400960#define STAC_AMP_MUX \
961 { \
962 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
963 .name = "Amp Selector Capture Switch", \
964 .count = 1, \
965 .info = stac92xx_amp_mux_enum_info, \
966 .get = stac92xx_amp_mux_enum_get, \
967 .put = stac92xx_amp_mux_enum_put, \
968 }
969
970#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
971 { \
972 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
973 .name = xname, \
974 .index = 0, \
975 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
976 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
977 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
978 .info = stac92xx_amp_volume_info, \
979 .get = stac92xx_amp_volume_get, \
980 .put = stac92xx_amp_volume_put, \
981 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
982 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
983 }
984
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200985#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200986 { \
987 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
988 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200989 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200990 .info = stac92xx_mux_enum_info, \
991 .get = stac92xx_mux_enum_get, \
992 .put = stac92xx_mux_enum_put, \
993 }
994
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100995#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200996 { \
997 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
998 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100999 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +02001000 .info = stac92xx_aloopback_info, \
1001 .get = stac92xx_aloopback_get, \
1002 .put = stac92xx_aloopback_put, \
1003 .private_value = verb_read | (verb_write << 16), \
1004 }
1005
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001006static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +02001007 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1008 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001009 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +02001010 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1011 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001012 { } /* end */
1013};
1014
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001015#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001016static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001017 /* start of config #1 */
1018 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1019 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1020
1021 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1022 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1023
1024 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1025 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1026
1027 /* start of config #2 */
1028 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1029 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1030
1031 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1032 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1033
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001034 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1035
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001036 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1037 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1038
1039 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1040 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1041
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001042 { } /* end */
1043};
1044
1045static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001046 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1047
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001048 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1049 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1050
1051 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1052 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1053
1054 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1055 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1056
1057 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1058 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1059
1060 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1061 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1062
1063 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1064 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1065
1066 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1067 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1068 { } /* end */
1069};
1070
1071static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001072 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1073
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001074 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1075 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1076
1077 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1078 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1079
1080 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1081 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1082
1083 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1084 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1085
1086 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1087 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1088
1089 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1090 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1091
1092 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1093 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1094 { } /* end */
1095};
1096
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001097
1098static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1099 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1100 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1101
1102 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1103 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1104
1105 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0, HDA_INPUT),
1106 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0, HDA_INPUT),
1107
1108 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x1, HDA_INPUT),
1109 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x1, HDA_INPUT),
1110
1111 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x2, HDA_INPUT),
1112 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x2, HDA_INPUT),
1113
1114 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x3, HDA_INPUT),
1115 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x3, HDA_INPUT),
1116
1117 /*
1118 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x4, HDA_INPUT),
1119 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x4, HDA_INPUT),
1120 */
1121 { } /* end */
1122};
1123
Matthew Ranostay541eee82007-12-14 12:08:04 +01001124static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001125 STAC_INPUT_SOURCE(2),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001126 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001127
Matthew Ranostay9b359472007-11-07 13:03:12 +01001128 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1129 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay9b359472007-11-07 13:03:12 +01001130
1131 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1132 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001133 /* analog pc-beep replaced with digital beep support */
1134 /*
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001135 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1136 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001137 */
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001138
Matthew Ranostay687cb982008-10-11 13:52:43 -04001139 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1140 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001141
Matthew Ranostay687cb982008-10-11 13:52:43 -04001142 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1143 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001144
1145 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1146 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1147
1148 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1149 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001150 { } /* end */
1151};
1152
Matthew Ranostay541eee82007-12-14 12:08:04 +01001153static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +01001154 STAC_INPUT_SOURCE(2),
1155 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1156
Matthew Ranostay541eee82007-12-14 12:08:04 +01001157 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1158 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001159
1160 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1161 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001162 { } /* end */
1163};
1164
Tobin Davis8e21c342007-01-08 11:04:17 +01001165static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001166 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +01001167 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
Mauro Carvalho Chehab587755f2008-05-25 18:20:06 +02001168 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
Tobin Davis8e21c342007-01-08 11:04:17 +01001169 { } /* end */
1170};
1171
Takashi Iwaid1d985f2006-11-23 19:27:12 +01001172static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001173 STAC_INPUT_SOURCE(2),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001174 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001175
1176 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1177 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001178
1179 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1180 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001181 { } /* end */
1182};
1183
1184/* This needs to be generated dynamically based on sequence */
1185static struct snd_kcontrol_new stac922x_mixer[] = {
1186 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001187 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1188 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001189
1190 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1191 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001192 { } /* end */
1193};
1194
1195
1196static struct snd_kcontrol_new stac927x_mixer[] = {
1197 STAC_INPUT_SOURCE(3),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001198 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001199
1200 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1201 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001202
1203 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1204 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001205
1206 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1207 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +02001208 { } /* end */
1209};
1210
Takashi Iwai1697055e2007-12-18 18:05:52 +01001211static struct snd_kcontrol_new stac_dmux_mixer = {
1212 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1213 .name = "Digital Input Source",
1214 /* count set later */
1215 .info = stac92xx_dmux_enum_info,
1216 .get = stac92xx_dmux_enum_get,
1217 .put = stac92xx_dmux_enum_put,
1218};
1219
Matthew Ranostayd9737752008-09-07 12:03:41 +02001220static struct snd_kcontrol_new stac_smux_mixer = {
1221 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001222 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001223 /* count set later */
1224 .info = stac92xx_smux_enum_info,
1225 .get = stac92xx_smux_enum_get,
1226 .put = stac92xx_smux_enum_put,
1227};
1228
Takashi Iwai2134ea42008-01-10 16:53:55 +01001229static const char *slave_vols[] = {
1230 "Front Playback Volume",
1231 "Surround Playback Volume",
1232 "Center Playback Volume",
1233 "LFE Playback Volume",
1234 "Side Playback Volume",
1235 "Headphone Playback Volume",
1236 "Headphone Playback Volume",
1237 "Speaker Playback Volume",
1238 "External Speaker Playback Volume",
1239 "Speaker2 Playback Volume",
1240 NULL
1241};
1242
1243static const char *slave_sws[] = {
1244 "Front Playback Switch",
1245 "Surround Playback Switch",
1246 "Center Playback Switch",
1247 "LFE Playback Switch",
1248 "Side Playback Switch",
1249 "Headphone Playback Switch",
1250 "Headphone Playback Switch",
1251 "Speaker Playback Switch",
1252 "External Speaker Playback Switch",
1253 "Speaker2 Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001254 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001255 NULL
1256};
1257
Takashi Iwai603c4012008-07-30 15:01:44 +02001258static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001259static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001260
Matt2f2f4252005-04-13 14:45:30 +02001261static int stac92xx_build_controls(struct hda_codec *codec)
1262{
1263 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001264 struct auto_pin_cfg *cfg = &spec->autocfg;
1265 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001266 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001267 int i;
Matt2f2f4252005-04-13 14:45:30 +02001268
1269 err = snd_hda_add_new_ctls(codec, spec->mixer);
1270 if (err < 0)
1271 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001272
1273 for (i = 0; i < spec->num_mixers; i++) {
1274 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1275 if (err < 0)
1276 return err;
1277 }
Takashi Iwai1697055e2007-12-18 18:05:52 +01001278 if (spec->num_dmuxes > 0) {
1279 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001280 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001281 snd_ctl_new1(&stac_dmux_mixer, codec));
1282 if (err < 0)
1283 return err;
1284 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001285 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001286 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1287 struct hda_input_mux *smux = &spec->private_smux;
1288 /* check for mute support on SPDIF out */
1289 if (wcaps & AC_WCAP_OUT_AMP) {
1290 smux->items[smux->num_items].label = "Off";
1291 smux->items[smux->num_items].index = 0;
1292 smux->num_items++;
1293 spec->spdif_mute = 1;
1294 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001295 stac_smux_mixer.count = spec->num_smuxes;
Takashi Iwai4f2d23e2008-12-19 10:14:13 +01001296 err = snd_hda_ctl_add(codec,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001297 snd_ctl_new1(&stac_smux_mixer, codec));
1298 if (err < 0)
1299 return err;
1300 }
Mattc7d4b2f2005-06-27 14:59:41 +02001301
Mattdabbed62005-06-14 10:19:34 +02001302 if (spec->multiout.dig_out_nid) {
1303 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1304 if (err < 0)
1305 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001306 err = snd_hda_create_spdif_share_sw(codec,
1307 &spec->multiout);
1308 if (err < 0)
1309 return err;
1310 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001311 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001312 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001313 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1314 if (err < 0)
1315 return err;
1316 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001317
1318 /* if we have no master control, let's create it */
1319 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001320 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001321 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001322 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001323 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001324 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001325 if (err < 0)
1326 return err;
1327 }
1328 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1329 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1330 NULL, slave_sws);
1331 if (err < 0)
1332 return err;
1333 }
1334
Takashi Iwai603c4012008-07-30 15:01:44 +02001335 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001336
1337 /* create jack input elements */
1338 if (spec->hp_detect) {
1339 for (i = 0; i < cfg->hp_outs; i++) {
1340 int type = SND_JACK_HEADPHONE;
1341 nid = cfg->hp_pins[i];
1342 /* jack detection */
1343 if (cfg->hp_outs == i)
1344 type |= SND_JACK_LINEOUT;
1345 err = stac92xx_add_jack(codec, nid, type);
1346 if (err < 0)
1347 return err;
1348 }
1349 }
1350 for (i = 0; i < cfg->line_outs; i++) {
1351 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1352 SND_JACK_LINEOUT);
1353 if (err < 0)
1354 return err;
1355 }
1356 for (i = 0; i < AUTO_PIN_LAST; i++) {
1357 nid = cfg->input_pins[i];
1358 if (nid) {
1359 err = stac92xx_add_jack(codec, nid,
1360 SND_JACK_MICROPHONE);
1361 if (err < 0)
1362 return err;
1363 }
1364 }
1365
Mattdabbed62005-06-14 10:19:34 +02001366 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001367}
1368
Matt Porter403d1942005-11-29 15:00:51 +01001369static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001370 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001371 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1372};
1373
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001374/*
1375 STAC 9200 pin configs for
1376 102801A8
1377 102801DE
1378 102801E8
1379*/
1380static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001381 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1382 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001383};
1384
1385/*
1386 STAC 9200 pin configs for
1387 102801C0
1388 102801C1
1389*/
1390static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001391 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1392 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001393};
1394
1395/*
1396 STAC 9200 pin configs for
1397 102801C4 (Dell Dimension E310)
1398 102801C5
1399 102801C7
1400 102801D9
1401 102801DA
1402 102801E3
1403*/
1404static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001405 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1406 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001407};
1408
1409
1410/*
1411 STAC 9200-32 pin configs for
1412 102801B5 (Dell Inspiron 630m)
1413 102801D8 (Dell Inspiron 640m)
1414*/
1415static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001416 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1417 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001418};
1419
1420/*
1421 STAC 9200-32 pin configs for
1422 102801C2 (Dell Latitude D620)
1423 102801C8
1424 102801CC (Dell Latitude D820)
1425 102801D4
1426 102801D6
1427*/
1428static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001429 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1430 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001431};
1432
1433/*
1434 STAC 9200-32 pin configs for
1435 102801CE (Dell XPS M1710)
1436 102801CF (Dell Precision M90)
1437*/
1438static unsigned int dell9200_m23_pin_configs[8] = {
1439 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1440 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1441};
1442
1443/*
1444 STAC 9200-32 pin configs for
1445 102801C9
1446 102801CA
1447 102801CB (Dell Latitude 120L)
1448 102801D3
1449*/
1450static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001451 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1452 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001453};
1454
1455/*
1456 STAC 9200-32 pin configs for
1457 102801BD (Dell Inspiron E1505n)
1458 102801EE
1459 102801EF
1460*/
1461static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001462 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1463 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001464};
1465
1466/*
1467 STAC 9200-32 pin configs for
1468 102801F5 (Dell Inspiron 1501)
1469 102801F6
1470*/
1471static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001472 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1473 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001474};
1475
1476/*
1477 STAC 9200-32
1478 102801CD (Dell Inspiron E1705/9400)
1479*/
1480static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001481 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1482 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001483};
1484
Tobin Davisbf277782008-02-03 20:31:47 +01001485static unsigned int oqo9200_pin_configs[8] = {
1486 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1487 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1488};
1489
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001490
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001491static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1492 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001493 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001494 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1495 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1496 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1497 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1498 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1499 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1500 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1501 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1502 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1503 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001504 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001505};
1506
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001507static const char *stac9200_models[STAC_9200_MODELS] = {
1508 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001509 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001510 [STAC_9200_DELL_D21] = "dell-d21",
1511 [STAC_9200_DELL_D22] = "dell-d22",
1512 [STAC_9200_DELL_D23] = "dell-d23",
1513 [STAC_9200_DELL_M21] = "dell-m21",
1514 [STAC_9200_DELL_M22] = "dell-m22",
1515 [STAC_9200_DELL_M23] = "dell-m23",
1516 [STAC_9200_DELL_M24] = "dell-m24",
1517 [STAC_9200_DELL_M25] = "dell-m25",
1518 [STAC_9200_DELL_M26] = "dell-m26",
1519 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001520 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwai117f2572008-03-18 09:53:23 +01001521 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001522};
1523
1524static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1525 /* SigmaTel reference board */
1526 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1527 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001528 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001529 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1530 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001531 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001532 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1533 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1534 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1535 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1536 "unknown Dell", STAC_9200_DELL_D22),
1537 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1538 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001539 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001540 "Dell Latitude D620", STAC_9200_DELL_M22),
1541 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1542 "unknown Dell", STAC_9200_DELL_D23),
1543 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1544 "unknown Dell", STAC_9200_DELL_D23),
1545 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1546 "unknown Dell", STAC_9200_DELL_M22),
1547 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1548 "unknown Dell", STAC_9200_DELL_M24),
1549 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1550 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001551 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001552 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001553 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001554 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001555 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001556 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001557 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001558 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001559 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001560 "Dell Precision M90", STAC_9200_DELL_M23),
1561 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1562 "unknown Dell", STAC_9200_DELL_M22),
1563 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1564 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001565 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001566 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001567 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001568 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1569 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1570 "unknown Dell", STAC_9200_DELL_D23),
1571 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1572 "unknown Dell", STAC_9200_DELL_D23),
1573 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1574 "unknown Dell", STAC_9200_DELL_D21),
1575 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1576 "unknown Dell", STAC_9200_DELL_D23),
1577 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1578 "unknown Dell", STAC_9200_DELL_D21),
1579 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1580 "unknown Dell", STAC_9200_DELL_M25),
1581 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1582 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001583 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001584 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1585 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1586 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001587 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001588 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001589 /* Gateway machines needs EAPD to be set on resume */
1590 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1591 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1592 STAC_9200_GATEWAY),
1593 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1594 STAC_9200_GATEWAY),
Tobin Davisbf277782008-02-03 20:31:47 +01001595 /* OQO Mobile */
1596 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001597 {} /* terminator */
1598};
1599
Tobin Davis8e21c342007-01-08 11:04:17 +01001600static unsigned int ref925x_pin_configs[8] = {
1601 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001602 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001603};
1604
1605static unsigned int stac925x_MA6_pin_configs[8] = {
1606 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1607 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
1608};
1609
Tobin Davis2c11f952007-05-17 09:36:34 +02001610static unsigned int stac925x_PA6_pin_configs[8] = {
1611 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1612 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
1613};
1614
Tobin Davis8e21c342007-01-08 11:04:17 +01001615static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +02001616 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
1617 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001618};
1619
1620static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1621 [STAC_REF] = ref925x_pin_configs,
1622 [STAC_M2_2] = stac925xM2_2_pin_configs,
1623 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +02001624 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001625};
1626
1627static const char *stac925x_models[STAC_925x_MODELS] = {
1628 [STAC_REF] = "ref",
1629 [STAC_M2_2] = "m2-2",
1630 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +02001631 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001632};
1633
1634static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1635 /* SigmaTel reference board */
1636 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001637 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +01001638 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
1639 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
1640 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +02001641 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +01001642 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
1643 {} /* terminator */
1644};
1645
Matthew Ranostaya7662642008-02-21 07:51:14 +01001646static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001647 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1648 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1649 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001650 0x01452050,
1651};
1652
1653static unsigned int dell_m6_pin_configs[13] = {
1654 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001655 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001656 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1657 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001658};
1659
1660static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001661 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001662 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1663 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1664 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001665 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001666};
1667
1668static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001669 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001670 [STAC_92HD73XX_REF] = "ref",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001671 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1672 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1673 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001674 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001675};
1676
1677static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1678 /* SigmaTel reference board */
1679 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001680 "DFI LanParty", STAC_92HD73XX_REF),
1681 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001682 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001683 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001684 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001685 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001686 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001687 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001688 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001689 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001690 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001691 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001692 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001693 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001694 "unknown Dell", STAC_DELL_M6_DMIC),
1695 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1696 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001697 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001698 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001699 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1700 "Dell Studio 17", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001701 {} /* terminator */
1702};
1703
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001704static unsigned int ref92hd83xxx_pin_configs[14] = {
1705 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1706 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1707 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1708 0x01451160, 0x98560170,
1709};
1710
1711static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1712 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1713};
1714
1715static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1716 [STAC_92HD83XXX_REF] = "ref",
1717};
1718
1719static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1720 /* SigmaTel reference board */
1721 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1722 "DFI LanParty", STAC_92HD71BXX_REF),
1723};
1724
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001725static unsigned int ref92hd71bxx_pin_configs[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001726 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001727 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001728 0x90a000f0, 0x01452050, 0x01452050,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001729};
1730
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001731static unsigned int dell_m4_1_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001732 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001733 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001734 0x40f000f0, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001735};
1736
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001737static unsigned int dell_m4_2_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001738 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1739 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001740 0x40f000f0, 0x044413b0, 0x044413b0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001741};
1742
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001743static unsigned int dell_m4_3_pin_configs[11] = {
1744 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1745 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1746 0x40f000f0, 0x044413b0, 0x044413b0,
1747};
1748
Matthew Ranostaye035b842007-11-06 11:53:55 +01001749static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1750 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001751 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1752 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001753 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001754 [STAC_HP_M4] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001755};
1756
1757static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1758 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001759 [STAC_DELL_M4_1] = "dell-m4-1",
1760 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001761 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001762 [STAC_HP_M4] = "hp-m4",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001763};
1764
1765static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1766 /* SigmaTel reference board */
1767 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1768 "DFI LanParty", STAC_92HD71BXX_REF),
Takashi Iwai80bf2722008-11-18 10:48:41 +01001769 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f2,
1770 "HP dv5", STAC_HP_M4),
1771 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4,
1772 "HP dv7", STAC_HP_M4),
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001773 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1774 "unknown HP", STAC_HP_M4),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001775 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1776 "unknown Dell", STAC_DELL_M4_1),
1777 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1778 "unknown Dell", STAC_DELL_M4_1),
1779 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1780 "unknown Dell", STAC_DELL_M4_1),
1781 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1782 "unknown Dell", STAC_DELL_M4_1),
1783 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1784 "unknown Dell", STAC_DELL_M4_1),
1785 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1786 "unknown Dell", STAC_DELL_M4_1),
1787 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1788 "unknown Dell", STAC_DELL_M4_1),
1789 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1790 "unknown Dell", STAC_DELL_M4_2),
1791 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1792 "unknown Dell", STAC_DELL_M4_2),
1793 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1794 "unknown Dell", STAC_DELL_M4_2),
1795 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1796 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001797 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1798 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001799 {} /* terminator */
1800};
1801
Matt Porter403d1942005-11-29 15:00:51 +01001802static unsigned int ref922x_pin_configs[10] = {
1803 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1804 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001805 0x40000100, 0x40000100,
1806};
1807
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001808/*
1809 STAC 922X pin configs for
1810 102801A7
1811 102801AB
1812 102801A9
1813 102801D1
1814 102801D2
1815*/
1816static unsigned int dell_922x_d81_pin_configs[10] = {
1817 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1818 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1819 0x01813122, 0x400001f2,
1820};
1821
1822/*
1823 STAC 922X pin configs for
1824 102801AC
1825 102801D0
1826*/
1827static unsigned int dell_922x_d82_pin_configs[10] = {
1828 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1829 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1830 0x01813122, 0x400001f1,
1831};
1832
1833/*
1834 STAC 922X pin configs for
1835 102801BF
1836*/
1837static unsigned int dell_922x_m81_pin_configs[10] = {
1838 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1839 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1840 0x40C003f1, 0x405003f0,
1841};
1842
1843/*
1844 STAC 9221 A1 pin configs for
1845 102801D7 (Dell XPS M1210)
1846*/
1847static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001848 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1849 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001850 0x508003f3, 0x405003f4,
1851};
1852
Matt Porter403d1942005-11-29 15:00:51 +01001853static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001854 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001855 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1856 0x02a19120, 0x40000100,
1857};
1858
1859static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001860 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1861 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001862 0x02a19320, 0x40000100,
1863};
1864
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001865static unsigned int intel_mac_v1_pin_configs[10] = {
1866 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1867 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001868 0x400000fc, 0x400000fb,
1869};
1870
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001871static unsigned int intel_mac_v2_pin_configs[10] = {
1872 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1873 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001874 0x400000fc, 0x400000fb,
1875};
1876
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001877static unsigned int intel_mac_v3_pin_configs[10] = {
1878 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1879 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1880 0x400000fc, 0x400000fb,
1881};
1882
1883static unsigned int intel_mac_v4_pin_configs[10] = {
1884 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1885 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1886 0x400000fc, 0x400000fb,
1887};
1888
1889static unsigned int intel_mac_v5_pin_configs[10] = {
1890 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1891 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1892 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001893};
1894
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001895static unsigned int ecs202_pin_configs[10] = {
1896 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1897 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1898 0x9037012e, 0x40e000f2,
1899};
Takashi Iwai76c08822007-06-19 12:17:42 +02001900
Takashi Iwai19039bd2006-06-28 15:52:16 +02001901static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001902 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001903 [STAC_D945GTP3] = d945gtp3_pin_configs,
1904 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001905 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1906 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1907 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1908 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1909 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001910 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001911 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001912 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1913 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1914 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1915 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1916 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1917 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001918 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001919 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1920 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1921 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1922 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001923};
1924
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001925static const char *stac922x_models[STAC_922X_MODELS] = {
1926 [STAC_D945_REF] = "ref",
1927 [STAC_D945GTP5] = "5stack",
1928 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001929 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1930 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1931 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1932 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1933 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001934 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001935 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001936 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001937 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001938 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1939 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001940 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001941 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001942 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001943 [STAC_922X_DELL_D81] = "dell-d81",
1944 [STAC_922X_DELL_D82] = "dell-d82",
1945 [STAC_922X_DELL_M81] = "dell-m81",
1946 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001947};
1948
1949static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1950 /* SigmaTel reference board */
1951 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1952 "DFI LanParty", STAC_D945_REF),
1953 /* Intel 945G based systems */
1954 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1955 "Intel D945G", STAC_D945GTP3),
1956 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1957 "Intel D945G", STAC_D945GTP3),
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1959 "Intel D945G", STAC_D945GTP3),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1961 "Intel D945G", STAC_D945GTP3),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1963 "Intel D945G", STAC_D945GTP3),
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1965 "Intel D945G", STAC_D945GTP3),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1967 "Intel D945G", STAC_D945GTP3),
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1969 "Intel D945G", STAC_D945GTP3),
1970 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1971 "Intel D945G", STAC_D945GTP3),
1972 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1973 "Intel D945G", STAC_D945GTP3),
1974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1975 "Intel D945G", STAC_D945GTP3),
1976 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1977 "Intel D945G", STAC_D945GTP3),
1978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1979 "Intel D945G", STAC_D945GTP3),
1980 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1981 "Intel D945G", STAC_D945GTP3),
1982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1983 "Intel D945G", STAC_D945GTP3),
1984 /* Intel D945G 5-stack systems */
1985 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1986 "Intel D945G", STAC_D945GTP5),
1987 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1988 "Intel D945G", STAC_D945GTP5),
1989 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1990 "Intel D945G", STAC_D945GTP5),
1991 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1992 "Intel D945G", STAC_D945GTP5),
1993 /* Intel 945P based systems */
1994 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1995 "Intel D945P", STAC_D945GTP3),
1996 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1997 "Intel D945P", STAC_D945GTP3),
1998 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1999 "Intel D945P", STAC_D945GTP3),
2000 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2001 "Intel D945P", STAC_D945GTP3),
2002 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2003 "Intel D945P", STAC_D945GTP3),
2004 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2005 "Intel D945P", STAC_D945GTP5),
2006 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002007 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002008 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002009 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002010 /* Dell systems */
2011 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2012 "unknown Dell", STAC_922X_DELL_D81),
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2014 "unknown Dell", STAC_922X_DELL_D81),
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2016 "unknown Dell", STAC_922X_DELL_D81),
2017 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2018 "unknown Dell", STAC_922X_DELL_D82),
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2020 "unknown Dell", STAC_922X_DELL_M81),
2021 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2022 "unknown Dell", STAC_922X_DELL_D82),
2023 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2024 "unknown Dell", STAC_922X_DELL_D81),
2025 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2026 "unknown Dell", STAC_922X_DELL_D81),
2027 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2028 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002029 /* ECS/PC Chips boards */
2030 SND_PCI_QUIRK(0x1019, 0x2144,
2031 "ECS/PC chips", STAC_ECS_202),
2032 SND_PCI_QUIRK(0x1019, 0x2608,
2033 "ECS/PC chips", STAC_ECS_202),
2034 SND_PCI_QUIRK(0x1019, 0x2633,
2035 "ECS/PC chips P17G/1333", STAC_ECS_202),
2036 SND_PCI_QUIRK(0x1019, 0x2811,
2037 "ECS/PC chips", STAC_ECS_202),
2038 SND_PCI_QUIRK(0x1019, 0x2812,
2039 "ECS/PC chips", STAC_ECS_202),
2040 SND_PCI_QUIRK(0x1019, 0x2813,
2041 "ECS/PC chips", STAC_ECS_202),
2042 SND_PCI_QUIRK(0x1019, 0x2814,
2043 "ECS/PC chips", STAC_ECS_202),
2044 SND_PCI_QUIRK(0x1019, 0x2815,
2045 "ECS/PC chips", STAC_ECS_202),
2046 SND_PCI_QUIRK(0x1019, 0x2816,
2047 "ECS/PC chips", STAC_ECS_202),
2048 SND_PCI_QUIRK(0x1019, 0x2817,
2049 "ECS/PC chips", STAC_ECS_202),
2050 SND_PCI_QUIRK(0x1019, 0x2818,
2051 "ECS/PC chips", STAC_ECS_202),
2052 SND_PCI_QUIRK(0x1019, 0x2819,
2053 "ECS/PC chips", STAC_ECS_202),
2054 SND_PCI_QUIRK(0x1019, 0x2820,
2055 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002056 {} /* terminator */
2057};
2058
Matt Porter3cc08dc2006-01-23 15:27:49 +01002059static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002060 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2061 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2062 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2063 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002064};
2065
Tobin Davis93ed1502006-09-01 21:03:12 +02002066static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002067 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2068 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2069 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2070 0x40000100, 0x40000100
2071};
2072
Tobin Davis93ed1502006-09-01 21:03:12 +02002073static unsigned int d965_5st_pin_configs[14] = {
2074 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2075 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2076 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2077 0x40000100, 0x40000100
2078};
2079
Tobin Davis4ff076e2007-08-07 11:48:12 +02002080static unsigned int dell_3st_pin_configs[14] = {
2081 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2082 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002083 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002084 0x40c003fc, 0x40000100
2085};
2086
Tobin Davis93ed1502006-09-01 21:03:12 +02002087static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002088 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002089 [STAC_D965_REF] = ref927x_pin_configs,
2090 [STAC_D965_3ST] = d965_3st_pin_configs,
2091 [STAC_D965_5ST] = d965_5st_pin_configs,
2092 [STAC_DELL_3ST] = dell_3st_pin_configs,
2093 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002094};
2095
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002096static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002097 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002098 [STAC_D965_REF] = "ref",
2099 [STAC_D965_3ST] = "3stack",
2100 [STAC_D965_5ST] = "5stack",
2101 [STAC_DELL_3ST] = "dell-3stack",
2102 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002103};
2104
2105static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2106 /* SigmaTel reference board */
2107 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2108 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002109 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002110 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002112 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002113 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
2115 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
2117 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
2119 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
2121 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
2122 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
2123 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
2124 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
2125 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
2126 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
2127 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
2128 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002129 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002130 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002131 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002132 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2133 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002134 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002135 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2136 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002137 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Takashi Iwai24918b62008-09-30 12:58:54 +02002138 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002139 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2140 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2141 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2142 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002143 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002144 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
2145 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
2146 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
2147 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
2148 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
2149 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
2150 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
2151 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
2152 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002153 {} /* terminator */
2154};
2155
Matt Porterf3302a52006-07-31 12:49:34 +02002156static unsigned int ref9205_pin_configs[12] = {
2157 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002158 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002159 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002160};
2161
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002162/*
2163 STAC 9205 pin configs for
2164 102801F1
2165 102801F2
2166 102801FC
2167 102801FD
2168 10280204
2169 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002170 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002171*/
2172static unsigned int dell_9205_m42_pin_configs[12] = {
2173 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2174 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2175 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2176};
2177
2178/*
2179 STAC 9205 pin configs for
2180 102801F9
2181 102801FA
2182 102801FE
2183 102801FF (Dell Precision M4300)
2184 10280206
2185 10280200
2186 10280201
2187*/
2188static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002189 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2190 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2191 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2192};
2193
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002194static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002195 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2196 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2197 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2198};
2199
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002200static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002201 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002202 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2203 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2204 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02002205};
2206
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002207static const char *stac9205_models[STAC_9205_MODELS] = {
2208 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002209 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002210 [STAC_9205_DELL_M43] = "dell-m43",
2211 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002212};
2213
2214static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2215 /* SigmaTel reference board */
2216 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2217 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002218 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2219 "unknown Dell", STAC_9205_DELL_M42),
2220 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2221 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002222 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002223 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002224 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2225 "Dell Precision", STAC_9205_DELL_M43),
2226 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2227 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002228 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2229 "unknown Dell", STAC_9205_DELL_M42),
2230 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2231 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002232 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2233 "Dell Precision", STAC_9205_DELL_M43),
2234 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002235 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002236 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2237 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002238 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2239 "Dell Precision", STAC_9205_DELL_M43),
2240 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2241 "Dell Precision", STAC_9205_DELL_M43),
2242 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2243 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002244 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2245 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002246 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2247 "Dell Vostro 1500", STAC_9205_DELL_M42),
Matt Porterf3302a52006-07-31 12:49:34 +02002248 {} /* terminator */
2249};
2250
Richard Fish11b44bb2006-08-23 18:31:34 +02002251static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2252{
2253 int i;
2254 struct sigmatel_spec *spec = codec->spec;
2255
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002256 kfree(spec->pin_configs);
2257 spec->pin_configs = kcalloc(spec->num_pins, sizeof(*spec->pin_configs),
2258 GFP_KERNEL);
2259 if (!spec->pin_configs)
2260 return -ENOMEM;
Richard Fish11b44bb2006-08-23 18:31:34 +02002261
2262 for (i = 0; i < spec->num_pins; i++) {
2263 hda_nid_t nid = spec->pin_nids[i];
2264 unsigned int pin_cfg;
2265
2266 pin_cfg = snd_hda_codec_read(codec, nid, 0,
2267 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2268 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2269 nid, pin_cfg);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002270 spec->pin_configs[i] = pin_cfg;
Richard Fish11b44bb2006-08-23 18:31:34 +02002271 }
2272
2273 return 0;
2274}
2275
Matthew Ranostay87d48362007-07-17 11:52:24 +02002276static void stac92xx_set_config_reg(struct hda_codec *codec,
2277 hda_nid_t pin_nid, unsigned int pin_config)
2278{
2279 int i;
2280 snd_hda_codec_write(codec, pin_nid, 0,
2281 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2282 pin_config & 0x000000ff);
2283 snd_hda_codec_write(codec, pin_nid, 0,
2284 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2285 (pin_config & 0x0000ff00) >> 8);
2286 snd_hda_codec_write(codec, pin_nid, 0,
2287 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2288 (pin_config & 0x00ff0000) >> 16);
2289 snd_hda_codec_write(codec, pin_nid, 0,
2290 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2291 pin_config >> 24);
2292 i = snd_hda_codec_read(codec, pin_nid, 0,
2293 AC_VERB_GET_CONFIG_DEFAULT,
2294 0x00);
2295 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
2296 pin_nid, i);
2297}
2298
Matt2f2f4252005-04-13 14:45:30 +02002299static void stac92xx_set_config_regs(struct hda_codec *codec)
2300{
2301 int i;
2302 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002303
Matthew Ranostay87d48362007-07-17 11:52:24 +02002304 if (!spec->pin_configs)
2305 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002306
Matthew Ranostay87d48362007-07-17 11:52:24 +02002307 for (i = 0; i < spec->num_pins; i++)
2308 stac92xx_set_config_reg(codec, spec->pin_nids[i],
2309 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02002310}
Matt2f2f4252005-04-13 14:45:30 +02002311
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002312static int stac_save_pin_cfgs(struct hda_codec *codec, unsigned int *pins)
2313{
2314 struct sigmatel_spec *spec = codec->spec;
2315
2316 if (!pins)
2317 return stac92xx_save_bios_config_regs(codec);
2318
2319 kfree(spec->pin_configs);
2320 spec->pin_configs = kmemdup(pins,
2321 spec->num_pins * sizeof(*pins),
2322 GFP_KERNEL);
2323 if (!spec->pin_configs)
2324 return -ENOMEM;
2325
2326 stac92xx_set_config_regs(codec);
2327 return 0;
2328}
2329
2330static void stac_change_pin_config(struct hda_codec *codec, hda_nid_t nid,
2331 unsigned int cfg)
2332{
2333 struct sigmatel_spec *spec = codec->spec;
2334 int i;
2335
2336 for (i = 0; i < spec->num_pins; i++) {
2337 if (spec->pin_nids[i] == nid) {
2338 spec->pin_configs[i] = cfg;
2339 stac92xx_set_config_reg(codec, nid, cfg);
2340 break;
2341 }
2342 }
2343}
2344
Matt2f2f4252005-04-13 14:45:30 +02002345/*
2346 * Analog playback callbacks
2347 */
2348static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2349 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002350 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002351{
2352 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002353 if (spec->stream_delay)
2354 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002355 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2356 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002357}
2358
2359static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2360 struct hda_codec *codec,
2361 unsigned int stream_tag,
2362 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002363 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002364{
2365 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002366 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002367}
2368
2369static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2370 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002371 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002372{
2373 struct sigmatel_spec *spec = codec->spec;
2374 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2375}
2376
2377/*
Mattdabbed62005-06-14 10:19:34 +02002378 * Digital playback callbacks
2379 */
2380static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2381 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002382 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002383{
2384 struct sigmatel_spec *spec = codec->spec;
2385 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2386}
2387
2388static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2389 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002390 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002391{
2392 struct sigmatel_spec *spec = codec->spec;
2393 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2394}
2395
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002396static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2397 struct hda_codec *codec,
2398 unsigned int stream_tag,
2399 unsigned int format,
2400 struct snd_pcm_substream *substream)
2401{
2402 struct sigmatel_spec *spec = codec->spec;
2403 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2404 stream_tag, format, substream);
2405}
2406
Mattdabbed62005-06-14 10:19:34 +02002407
2408/*
Matt2f2f4252005-04-13 14:45:30 +02002409 * Analog capture callbacks
2410 */
2411static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2412 struct hda_codec *codec,
2413 unsigned int stream_tag,
2414 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002415 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002416{
2417 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002418 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002419
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002420 if (spec->powerdown_adcs) {
2421 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002422 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002423 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2424 }
2425 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002426 return 0;
2427}
2428
2429static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2430 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002431 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002432{
2433 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002434 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002435
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002436 snd_hda_codec_cleanup_stream(codec, nid);
2437 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002438 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002439 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002440 return 0;
2441}
2442
Mattdabbed62005-06-14 10:19:34 +02002443static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2444 .substreams = 1,
2445 .channels_min = 2,
2446 .channels_max = 2,
2447 /* NID is set in stac92xx_build_pcms */
2448 .ops = {
2449 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002450 .close = stac92xx_dig_playback_pcm_close,
2451 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02002452 },
2453};
2454
2455static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2456 .substreams = 1,
2457 .channels_min = 2,
2458 .channels_max = 2,
2459 /* NID is set in stac92xx_build_pcms */
2460};
2461
Matt2f2f4252005-04-13 14:45:30 +02002462static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2463 .substreams = 1,
2464 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002465 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002466 .nid = 0x02, /* NID to query formats and rates */
2467 .ops = {
2468 .open = stac92xx_playback_pcm_open,
2469 .prepare = stac92xx_playback_pcm_prepare,
2470 .cleanup = stac92xx_playback_pcm_cleanup
2471 },
2472};
2473
Matt Porter3cc08dc2006-01-23 15:27:49 +01002474static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2475 .substreams = 1,
2476 .channels_min = 2,
2477 .channels_max = 2,
2478 .nid = 0x06, /* NID to query formats and rates */
2479 .ops = {
2480 .open = stac92xx_playback_pcm_open,
2481 .prepare = stac92xx_playback_pcm_prepare,
2482 .cleanup = stac92xx_playback_pcm_cleanup
2483 },
2484};
2485
Matt2f2f4252005-04-13 14:45:30 +02002486static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002487 .channels_min = 2,
2488 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002489 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002490 .ops = {
2491 .prepare = stac92xx_capture_pcm_prepare,
2492 .cleanup = stac92xx_capture_pcm_cleanup
2493 },
2494};
2495
2496static int stac92xx_build_pcms(struct hda_codec *codec)
2497{
2498 struct sigmatel_spec *spec = codec->spec;
2499 struct hda_pcm *info = spec->pcm_rec;
2500
2501 codec->num_pcms = 1;
2502 codec->pcm_info = info;
2503
Mattc7d4b2f2005-06-27 14:59:41 +02002504 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002505 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02002506 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002507 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002508 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002509
2510 if (spec->alt_switch) {
2511 codec->num_pcms++;
2512 info++;
2513 info->name = "STAC92xx Analog Alt";
2514 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2515 }
Matt2f2f4252005-04-13 14:45:30 +02002516
Mattdabbed62005-06-14 10:19:34 +02002517 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2518 codec->num_pcms++;
2519 info++;
2520 info->name = "STAC92xx Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01002521 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Mattdabbed62005-06-14 10:19:34 +02002522 if (spec->multiout.dig_out_nid) {
2523 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2524 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2525 }
2526 if (spec->dig_in_nid) {
2527 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2528 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2529 }
2530 }
2531
Matt2f2f4252005-04-13 14:45:30 +02002532 return 0;
2533}
2534
Takashi Iwaic960a032006-03-23 17:06:28 +01002535static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2536{
2537 unsigned int pincap = snd_hda_param_read(codec, nid,
2538 AC_PAR_PIN_CAP);
2539 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2540 if (pincap & AC_PINCAP_VREF_100)
2541 return AC_PINCTL_VREF_100;
2542 if (pincap & AC_PINCAP_VREF_80)
2543 return AC_PINCTL_VREF_80;
2544 if (pincap & AC_PINCAP_VREF_50)
2545 return AC_PINCTL_VREF_50;
2546 if (pincap & AC_PINCAP_VREF_GRD)
2547 return AC_PINCTL_VREF_GRD;
2548 return 0;
2549}
2550
Matt Porter403d1942005-11-29 15:00:51 +01002551static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2552
2553{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002554 snd_hda_codec_write_cache(codec, nid, 0,
2555 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002556}
2557
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002558#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2559
2560static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2561 struct snd_ctl_elem_value *ucontrol)
2562{
2563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2564 struct sigmatel_spec *spec = codec->spec;
2565
Takashi Iwaid7a89432008-11-12 09:48:04 +01002566 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002567 return 0;
2568}
2569
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002570static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2571 unsigned char type);
2572
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002573static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2574 struct snd_ctl_elem_value *ucontrol)
2575{
2576 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2577 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002578 int nid = kcontrol->private_value;
2579
2580 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002581
2582 /* check to be sure that the ports are upto date with
2583 * switch changes
2584 */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002585 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002586
2587 return 1;
2588}
2589
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002590#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01002591
2592static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2593{
2594 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2595 struct sigmatel_spec *spec = codec->spec;
2596 int io_idx = kcontrol-> private_value & 0xff;
2597
2598 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2599 return 0;
2600}
2601
2602static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2603{
2604 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2605 struct sigmatel_spec *spec = codec->spec;
2606 hda_nid_t nid = kcontrol->private_value >> 8;
2607 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002608 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01002609
2610 spec->io_switch[io_idx] = val;
2611
2612 if (val)
2613 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002614 else {
2615 unsigned int pinctl = AC_PINCTL_IN_EN;
2616 if (io_idx) /* set VREF for mic */
2617 pinctl |= stac92xx_get_vref(codec, nid);
2618 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2619 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002620
2621 /* check the auto-mute again: we need to mute/unmute the speaker
2622 * appropriately according to the pin direction
2623 */
2624 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002625 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002626
Matt Porter403d1942005-11-29 15:00:51 +01002627 return 1;
2628}
2629
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002630#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2631
2632static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2633 struct snd_ctl_elem_value *ucontrol)
2634{
2635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2636 struct sigmatel_spec *spec = codec->spec;
2637
2638 ucontrol->value.integer.value[0] = spec->clfe_swap;
2639 return 0;
2640}
2641
2642static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2643 struct snd_ctl_elem_value *ucontrol)
2644{
2645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2646 struct sigmatel_spec *spec = codec->spec;
2647 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002648 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002649
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002650 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002651 return 0;
2652
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002653 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002654
2655 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2656 spec->clfe_swap ? 0x4 : 0x0);
2657
2658 return 1;
2659}
2660
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002661#define STAC_CODEC_HP_SWITCH(xname) \
2662 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2663 .name = xname, \
2664 .index = 0, \
2665 .info = stac92xx_hp_switch_info, \
2666 .get = stac92xx_hp_switch_get, \
2667 .put = stac92xx_hp_switch_put, \
2668 }
2669
Matt Porter403d1942005-11-29 15:00:51 +01002670#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2671 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2672 .name = xname, \
2673 .index = 0, \
2674 .info = stac92xx_io_switch_info, \
2675 .get = stac92xx_io_switch_get, \
2676 .put = stac92xx_io_switch_put, \
2677 .private_value = xpval, \
2678 }
2679
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002680#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2681 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2682 .name = xname, \
2683 .index = 0, \
2684 .info = stac92xx_clfe_switch_info, \
2685 .get = stac92xx_clfe_switch_get, \
2686 .put = stac92xx_clfe_switch_put, \
2687 .private_value = xpval, \
2688 }
Matt Porter403d1942005-11-29 15:00:51 +01002689
Mattc7d4b2f2005-06-27 14:59:41 +02002690enum {
2691 STAC_CTL_WIDGET_VOL,
2692 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002693 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002694 STAC_CTL_WIDGET_AMP_MUX,
2695 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002696 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002697 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002698 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02002699};
2700
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002701static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002702 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2703 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002704 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002705 STAC_AMP_MUX,
2706 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002707 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002708 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002709 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002710};
2711
2712/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002713static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2714 struct snd_kcontrol_new *ktemp,
2715 int idx, const char *name,
2716 unsigned long val)
Mattc7d4b2f2005-06-27 14:59:41 +02002717{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002718 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002719
Takashi Iwai603c4012008-07-30 15:01:44 +02002720 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2721 knew = snd_array_new(&spec->kctls);
2722 if (!knew)
2723 return -ENOMEM;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002724 *knew = *ktemp;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002725 knew->index = idx;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002726 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002727 if (!knew->name)
Mattc7d4b2f2005-06-27 14:59:41 +02002728 return -ENOMEM;
2729 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002730 return 0;
2731}
2732
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002733static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2734 int type, int idx, const char *name,
2735 unsigned long val)
2736{
2737 return stac92xx_add_control_temp(spec,
2738 &stac92xx_control_templates[type],
2739 idx, name, val);
2740}
2741
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002742
2743/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002744static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2745 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002746{
2747 return stac92xx_add_control_idx(spec, type, 0, name, val);
2748}
2749
Matt Porter403d1942005-11-29 15:00:51 +01002750/* flag inputs as additional dynamic lineouts */
2751static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2752{
2753 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002754 unsigned int wcaps, wtype;
2755 int i, num_dacs = 0;
2756
2757 /* use the wcaps cache to count all DACs available for line-outs */
2758 for (i = 0; i < codec->num_nodes; i++) {
2759 wcaps = codec->wcaps[i];
2760 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002761
Steve Longerbeam7b043892007-05-03 20:50:03 +02002762 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
2763 num_dacs++;
2764 }
Matt Porter403d1942005-11-29 15:00:51 +01002765
Steve Longerbeam7b043892007-05-03 20:50:03 +02002766 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
2767
Matt Porter403d1942005-11-29 15:00:51 +01002768 switch (cfg->line_outs) {
2769 case 3:
2770 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002771 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002772 cfg->line_out_pins[cfg->line_outs] =
2773 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002774 spec->line_switch = 1;
2775 cfg->line_outs++;
2776 }
2777 break;
2778 case 2:
2779 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002780 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002781 cfg->line_out_pins[cfg->line_outs] =
2782 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002783 spec->line_switch = 1;
2784 cfg->line_outs++;
2785 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002786 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002787 cfg->line_out_pins[cfg->line_outs] =
2788 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002789 spec->mic_switch = 1;
2790 cfg->line_outs++;
2791 }
2792 break;
2793 case 1:
2794 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002795 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002796 cfg->line_out_pins[cfg->line_outs] =
2797 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002798 spec->line_switch = 1;
2799 cfg->line_outs++;
2800 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002801 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002802 cfg->line_out_pins[cfg->line_outs] =
2803 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002804 spec->mic_switch = 1;
2805 cfg->line_outs++;
2806 }
2807 break;
2808 }
2809
2810 return 0;
2811}
2812
Steve Longerbeam7b043892007-05-03 20:50:03 +02002813
2814static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2815{
2816 int i;
2817
2818 for (i = 0; i < spec->multiout.num_dacs; i++) {
2819 if (spec->multiout.dac_nids[i] == nid)
2820 return 1;
2821 }
2822
2823 return 0;
2824}
2825
Matt Porter3cc08dc2006-01-23 15:27:49 +01002826/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002827 * Fill in the dac_nids table from the parsed pin configuration
2828 * This function only works when every pin in line_out_pins[]
2829 * contains atleast one DAC in its connection list. Some 92xx
2830 * codecs are not connected directly to a DAC, such as the 9200
2831 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002832 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002833static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02002834 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002835{
2836 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002837 int i, j, conn_len = 0;
2838 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2839 unsigned int wcaps, wtype;
2840
Mattc7d4b2f2005-06-27 14:59:41 +02002841 for (i = 0; i < cfg->line_outs; i++) {
2842 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02002843 conn_len = snd_hda_get_connections(codec, nid, conn,
2844 HDA_MAX_CONNECTIONS);
2845 for (j = 0; j < conn_len; j++) {
2846 wcaps = snd_hda_param_read(codec, conn[j],
2847 AC_PAR_AUDIO_WIDGET_CAP);
2848 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002849 if (wtype != AC_WID_AUD_OUT ||
2850 (wcaps & AC_WCAP_DIGITAL))
2851 continue;
2852 /* conn[j] is a DAC routed to this line-out */
2853 if (!is_in_dac_nids(spec, conn[j]))
2854 break;
2855 }
2856
2857 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002858 if (spec->multiout.num_dacs > 0) {
2859 /* we have already working output pins,
2860 * so let's drop the broken ones again
2861 */
2862 cfg->line_outs = spec->multiout.num_dacs;
2863 break;
2864 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002865 /* error out, no available DAC found */
2866 snd_printk(KERN_ERR
2867 "%s: No available DAC for pin 0x%x\n",
2868 __func__, nid);
2869 return -ENODEV;
2870 }
2871
2872 spec->multiout.dac_nids[i] = conn[j];
2873 spec->multiout.num_dacs++;
2874 if (conn_len > 1) {
2875 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002876 snd_hda_codec_write_cache(codec, nid, 0,
2877 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002878
2879 }
Mattc7d4b2f2005-06-27 14:59:41 +02002880 }
2881
Steve Longerbeam7b043892007-05-03 20:50:03 +02002882 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2883 spec->multiout.num_dacs,
2884 spec->multiout.dac_nids[0],
2885 spec->multiout.dac_nids[1],
2886 spec->multiout.dac_nids[2],
2887 spec->multiout.dac_nids[3],
2888 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02002889 return 0;
2890}
2891
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002892/* create volume control/switch for the given prefx type */
2893static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2894{
2895 char name[32];
2896 int err;
2897
2898 sprintf(name, "%s Playback Volume", pfx);
2899 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2900 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2901 if (err < 0)
2902 return err;
2903 sprintf(name, "%s Playback Switch", pfx);
2904 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2905 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2906 if (err < 0)
2907 return err;
2908 return 0;
2909}
2910
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002911static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2912{
2913 if (!spec->multiout.hp_nid)
2914 spec->multiout.hp_nid = nid;
2915 else if (spec->multiout.num_dacs > 4) {
2916 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2917 return 1;
2918 } else {
2919 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2920 spec->multiout.num_dacs++;
2921 }
2922 return 0;
2923}
2924
2925static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2926{
2927 if (is_in_dac_nids(spec, nid))
2928 return 1;
2929 if (spec->multiout.hp_nid == nid)
2930 return 1;
2931 return 0;
2932}
2933
Mattc7d4b2f2005-06-27 14:59:41 +02002934/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002935static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002936 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002937{
Takashi Iwai19039bd2006-06-28 15:52:16 +02002938 static const char *chname[4] = {
2939 "Front", "Surround", NULL /*CLFE*/, "Side"
2940 };
Matthew Ranostayd21995e2008-10-13 13:22:45 -04002941 hda_nid_t nid = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002942 int i, err;
2943
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002944 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002945 unsigned int wid_caps, pincap;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002946
2947
Takashi Iwai40ac8c42008-02-29 14:16:17 +01002948 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01002949 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02002950 continue;
2951
2952 nid = spec->multiout.dac_nids[i];
2953
2954 if (i == 2) {
2955 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002956 err = create_controls(spec, "Center", nid, 1);
2957 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002958 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002959 err = create_controls(spec, "LFE", nid, 2);
2960 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002961 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002962
2963 wid_caps = get_wcaps(codec, nid);
2964
2965 if (wid_caps & AC_WCAP_LR_SWAP) {
2966 err = stac92xx_add_control(spec,
2967 STAC_CTL_WIDGET_CLFE_SWITCH,
2968 "Swap Center/LFE Playback Switch", nid);
2969
2970 if (err < 0)
2971 return err;
2972 }
2973
Mattc7d4b2f2005-06-27 14:59:41 +02002974 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002975 err = create_controls(spec, chname[i], nid, 3);
2976 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002977 return err;
2978 }
2979 }
2980
Matthew Ranostayfedb7562008-09-23 21:46:30 -04002981 if ((spec->multiout.num_dacs - cfg->line_outs) > 0 &&
Takashi Iwai8f55c1e2008-12-19 14:02:32 +01002982 cfg->hp_outs == 1 && !spec->multiout.hp_nid)
Matthew Ranostayfedb7562008-09-23 21:46:30 -04002983 spec->multiout.hp_nid = nid;
2984
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01002985 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002986 err = stac92xx_add_control(spec,
2987 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01002988 "Headphone as Line Out Switch",
2989 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002990 if (err < 0)
2991 return err;
2992 }
2993
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002994 if (spec->line_switch) {
2995 nid = cfg->input_pins[AUTO_PIN_LINE];
2996 pincap = snd_hda_param_read(codec, nid,
2997 AC_PAR_PIN_CAP);
2998 if (pincap & AC_PINCAP_OUT) {
2999 err = stac92xx_add_control(spec,
3000 STAC_CTL_WIDGET_IO_SWITCH,
3001 "Line In as Output Switch", nid << 8);
3002 if (err < 0)
3003 return err;
3004 }
3005 }
Matt Porter403d1942005-11-29 15:00:51 +01003006
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003007 if (spec->mic_switch) {
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003008 unsigned int def_conf;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003009 unsigned int mic_pin = AUTO_PIN_MIC;
3010again:
3011 nid = cfg->input_pins[mic_pin];
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003012 def_conf = snd_hda_codec_read(codec, nid, 0,
3013 AC_VERB_GET_CONFIG_DEFAULT, 0);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003014 /* some laptops have an internal analog microphone
3015 * which can't be used as a output */
3016 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
3017 pincap = snd_hda_param_read(codec, nid,
3018 AC_PAR_PIN_CAP);
3019 if (pincap & AC_PINCAP_OUT) {
3020 err = stac92xx_add_control(spec,
3021 STAC_CTL_WIDGET_IO_SWITCH,
3022 "Mic as Output Switch", (nid << 8) | 1);
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003023 nid = snd_hda_codec_read(codec, nid, 0,
3024 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3025 if (!check_in_dac_nids(spec, nid))
3026 add_spec_dacs(spec, nid);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003027 if (err < 0)
3028 return err;
3029 }
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003030 } else if (mic_pin == AUTO_PIN_MIC) {
3031 mic_pin = AUTO_PIN_FRONT_MIC;
3032 goto again;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003033 }
3034 }
Matt Porter403d1942005-11-29 15:00:51 +01003035
Mattc7d4b2f2005-06-27 14:59:41 +02003036 return 0;
3037}
3038
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003039/* add playback controls for Speaker and HP outputs */
3040static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3041 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003042{
3043 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003044 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003045 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003046
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003047 old_num_dacs = spec->multiout.num_dacs;
3048 for (i = 0; i < cfg->hp_outs; i++) {
3049 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
3050 if (wid_caps & AC_WCAP_UNSOL_CAP)
3051 spec->hp_detect = 1;
3052 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
3053 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3054 if (check_in_dac_nids(spec, nid))
3055 nid = 0;
3056 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02003057 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003058 add_spec_dacs(spec, nid);
3059 }
3060 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02003061 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003062 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3063 if (check_in_dac_nids(spec, nid))
3064 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003065 if (! nid)
3066 continue;
3067 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02003068 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02003069 for (i = 0; i < cfg->line_outs; i++) {
3070 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
3071 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3072 if (check_in_dac_nids(spec, nid))
3073 nid = 0;
3074 if (! nid)
3075 continue;
3076 add_spec_dacs(spec, nid);
3077 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003078 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
3079 static const char *pfxs[] = {
3080 "Speaker", "External Speaker", "Speaker2",
3081 };
3082 err = create_controls(spec, pfxs[i - old_num_dacs],
3083 spec->multiout.dac_nids[i], 3);
3084 if (err < 0)
3085 return err;
3086 }
3087 if (spec->multiout.hp_nid) {
Takashi Iwai2626a262008-03-14 09:18:32 +01003088 err = create_controls(spec, "Headphone",
3089 spec->multiout.hp_nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003090 if (err < 0)
3091 return err;
3092 }
Mattc7d4b2f2005-06-27 14:59:41 +02003093
3094 return 0;
3095}
3096
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003097/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003098static const char *stac92xx_mono_labels[4] = {
3099 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003100};
3101
3102/* create mono mux for mono out on capable codecs */
3103static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3104{
3105 struct sigmatel_spec *spec = codec->spec;
3106 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3107 int i, num_cons;
3108 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3109
3110 num_cons = snd_hda_get_connections(codec,
3111 spec->mono_nid,
3112 con_lst,
3113 HDA_MAX_NUM_INPUTS);
3114 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3115 return -EINVAL;
3116
3117 for (i = 0; i < num_cons; i++) {
3118 mono_mux->items[mono_mux->num_items].label =
3119 stac92xx_mono_labels[i];
3120 mono_mux->items[mono_mux->num_items].index = i;
3121 mono_mux->num_items++;
3122 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003123
3124 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3125 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003126}
3127
Matthew Ranostay89385032008-09-11 09:49:39 -04003128/* labels for amp mux outputs */
3129static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003130 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003131};
3132
3133/* create amp out controls mux on capable codecs */
3134static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3135{
3136 struct sigmatel_spec *spec = codec->spec;
3137 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3138 int i, err;
3139
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003140 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003141 amp_mux->items[amp_mux->num_items].label =
3142 stac92xx_amp_labels[i];
3143 amp_mux->items[amp_mux->num_items].index = i;
3144 amp_mux->num_items++;
3145 }
3146
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003147 if (spec->num_amps > 1) {
3148 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3149 "Amp Selector Capture Switch", 0);
3150 if (err < 0)
3151 return err;
3152 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003153 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3154 "Amp Capture Volume",
3155 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3156}
3157
3158
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003159/* create PC beep volume controls */
3160static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3161 hda_nid_t nid)
3162{
3163 struct sigmatel_spec *spec = codec->spec;
3164 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3165 int err;
3166
3167 /* check for mute support for the the amp */
3168 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3169 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3170 "PC Beep Playback Switch",
3171 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3172 if (err < 0)
3173 return err;
3174 }
3175
3176 /* check to see if there is volume support for the amp */
3177 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3178 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3179 "PC Beep Playback Volume",
3180 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3181 if (err < 0)
3182 return err;
3183 }
3184 return 0;
3185}
3186
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003187#ifdef CONFIG_SND_HDA_INPUT_BEEP
3188#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3189
3190static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3191 struct snd_ctl_elem_value *ucontrol)
3192{
3193 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3194 ucontrol->value.integer.value[0] = codec->beep->enabled;
3195 return 0;
3196}
3197
3198static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3199 struct snd_ctl_elem_value *ucontrol)
3200{
3201 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3202 int enabled = !!ucontrol->value.integer.value[0];
3203 if (codec->beep->enabled != enabled) {
3204 codec->beep->enabled = enabled;
3205 return 1;
3206 }
3207 return 0;
3208}
3209
3210static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3211 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3212 .info = stac92xx_dig_beep_switch_info,
3213 .get = stac92xx_dig_beep_switch_get,
3214 .put = stac92xx_dig_beep_switch_put,
3215};
3216
3217static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3218{
3219 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3220 0, "PC Beep Playback Switch", 0);
3221}
3222#endif
3223
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003224static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3225{
3226 struct sigmatel_spec *spec = codec->spec;
3227 int wcaps, nid, i, err = 0;
3228
3229 for (i = 0; i < spec->num_muxes; i++) {
3230 nid = spec->mux_nids[i];
3231 wcaps = get_wcaps(codec, nid);
3232
3233 if (wcaps & AC_WCAP_OUT_AMP) {
3234 err = stac92xx_add_control_idx(spec,
3235 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3236 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3237 if (err < 0)
3238 return err;
3239 }
3240 }
3241 return 0;
3242};
3243
Matthew Ranostayd9737752008-09-07 12:03:41 +02003244static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003245 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003246};
3247
3248static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3249{
3250 struct sigmatel_spec *spec = codec->spec;
3251 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003252 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003253 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003254 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003255
3256 num_cons = snd_hda_get_connections(codec,
3257 spec->smux_nids[0],
3258 con_lst,
3259 HDA_MAX_NUM_INPUTS);
Matthew Ranostay65973632008-09-16 10:39:37 -04003260 if (!num_cons)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003261 return -EINVAL;
3262
Matthew Ranostay65973632008-09-16 10:39:37 -04003263 if (!labels)
3264 labels = stac92xx_spdif_labels;
3265
Matthew Ranostayd9737752008-09-07 12:03:41 +02003266 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003267 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003268 spdif_mux->items[spdif_mux->num_items].index = i;
3269 spdif_mux->num_items++;
3270 }
3271
3272 return 0;
3273}
3274
Matt Porter8b657272006-10-26 17:12:59 +02003275/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003276static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003277 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3278 "Digital Mic 3", "Digital Mic 4"
3279};
3280
3281/* create playback/capture controls for input pins on dmic capable codecs */
3282static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3283 const struct auto_pin_cfg *cfg)
3284{
3285 struct sigmatel_spec *spec = codec->spec;
3286 struct hda_input_mux *dimux = &spec->private_dimux;
3287 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003288 int err, i, j;
3289 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02003290
3291 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3292 dimux->items[dimux->num_items].index = 0;
3293 dimux->num_items++;
3294
3295 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003296 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003297 int index;
3298 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003299 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02003300 unsigned int def_conf;
3301
3302 def_conf = snd_hda_codec_read(codec,
3303 spec->dmic_nids[i],
3304 0,
3305 AC_VERB_GET_CONFIG_DEFAULT,
3306 0);
3307 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3308 continue;
3309
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003310 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02003311 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003312 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02003313 con_lst,
3314 HDA_MAX_NUM_INPUTS);
3315 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003316 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02003317 index = j;
3318 goto found;
3319 }
3320 continue;
3321found:
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003322 wcaps = get_wcaps(codec, nid) &
3323 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003324
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003325 if (wcaps) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003326 sprintf(name, "%s Capture Volume",
3327 stac92xx_dmic_labels[dimux->num_items]);
3328
3329 err = stac92xx_add_control(spec,
3330 STAC_CTL_WIDGET_VOL,
3331 name,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003332 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3333 (wcaps & AC_WCAP_OUT_AMP) ?
3334 HDA_OUTPUT : HDA_INPUT));
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003335 if (err < 0)
3336 return err;
3337 }
3338
Matt Porter8b657272006-10-26 17:12:59 +02003339 dimux->items[dimux->num_items].label =
3340 stac92xx_dmic_labels[dimux->num_items];
3341 dimux->items[dimux->num_items].index = index;
3342 dimux->num_items++;
3343 }
3344
3345 return 0;
3346}
3347
Mattc7d4b2f2005-06-27 14:59:41 +02003348/* create playback/capture controls for input pins */
3349static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3350{
3351 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003352 struct hda_input_mux *imux = &spec->private_imux;
3353 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3354 int i, j, k;
3355
3356 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003357 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02003358
Takashi Iwai314634b2006-09-21 11:56:18 +02003359 if (!cfg->input_pins[i])
3360 continue;
3361 index = -1;
3362 for (j = 0; j < spec->num_muxes; j++) {
3363 int num_cons;
3364 num_cons = snd_hda_get_connections(codec,
3365 spec->mux_nids[j],
3366 con_lst,
3367 HDA_MAX_NUM_INPUTS);
3368 for (k = 0; k < num_cons; k++)
3369 if (con_lst[k] == cfg->input_pins[i]) {
3370 index = k;
3371 goto found;
3372 }
Mattc7d4b2f2005-06-27 14:59:41 +02003373 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003374 continue;
3375 found:
3376 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3377 imux->items[imux->num_items].index = index;
3378 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003379 }
3380
Steve Longerbeam7b043892007-05-03 20:50:03 +02003381 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003382 /*
3383 * Set the current input for the muxes.
3384 * The STAC9221 has two input muxes with identical source
3385 * NID lists. Hopefully this won't get confused.
3386 */
3387 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003388 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3389 AC_VERB_SET_CONNECT_SEL,
3390 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003391 }
3392 }
3393
Mattc7d4b2f2005-06-27 14:59:41 +02003394 return 0;
3395}
3396
Mattc7d4b2f2005-06-27 14:59:41 +02003397static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3398{
3399 struct sigmatel_spec *spec = codec->spec;
3400 int i;
3401
3402 for (i = 0; i < spec->autocfg.line_outs; i++) {
3403 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3404 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3405 }
3406}
3407
3408static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3409{
3410 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003411 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003412
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003413 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3414 hda_nid_t pin;
3415 pin = spec->autocfg.hp_pins[i];
3416 if (pin) /* connect to front */
3417 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3418 }
3419 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3420 hda_nid_t pin;
3421 pin = spec->autocfg.speaker_pins[i];
3422 if (pin) /* connect to front */
3423 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3424 }
Mattc7d4b2f2005-06-27 14:59:41 +02003425}
3426
Matt Porter3cc08dc2006-01-23 15:27:49 +01003427static 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 +02003428{
3429 struct sigmatel_spec *spec = codec->spec;
3430 int err;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003431 int hp_speaker_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003432
Matt Porter8b657272006-10-26 17:12:59 +02003433 if ((err = snd_hda_parse_pin_def_config(codec,
3434 &spec->autocfg,
3435 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003436 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003437 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003438 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003439
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003440 /* If we have no real line-out pin and multiple hp-outs, HPs should
3441 * be set up as multi-channel outputs.
3442 */
3443 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3444 spec->autocfg.hp_outs > 1) {
3445 /* Copy hp_outs to line_outs, backup line_outs in
3446 * speaker_outs so that the following routines can handle
3447 * HP pins as primary outputs.
3448 */
3449 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3450 sizeof(spec->autocfg.line_out_pins));
3451 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3452 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3453 sizeof(spec->autocfg.hp_pins));
3454 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3455 hp_speaker_swap = 1;
3456 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003457 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003458 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3459 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003460 u32 caps = query_amp_caps(codec,
3461 spec->autocfg.mono_out_pin, dir);
3462 hda_nid_t conn_list[1];
3463
3464 /* get the mixer node and then the mono mux if it exists */
3465 if (snd_hda_get_connections(codec,
3466 spec->autocfg.mono_out_pin, conn_list, 1) &&
3467 snd_hda_get_connections(codec, conn_list[0],
3468 conn_list, 1)) {
3469
3470 int wcaps = get_wcaps(codec, conn_list[0]);
3471 int wid_type = (wcaps & AC_WCAP_TYPE)
3472 >> AC_WCAP_TYPE_SHIFT;
3473 /* LR swap check, some stac925x have a mux that
3474 * changes the DACs output path instead of the
3475 * mono-mux path.
3476 */
3477 if (wid_type == AC_WID_AUD_SEL &&
3478 !(wcaps & AC_WCAP_LR_SWAP))
3479 spec->mono_nid = conn_list[0];
3480 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003481 if (dir) {
3482 hda_nid_t nid = spec->autocfg.mono_out_pin;
3483
3484 /* most mono outs have a least a mute/unmute switch */
3485 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3486 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3487 "Mono Playback Switch",
3488 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003489 if (err < 0)
3490 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003491 /* check for volume support for the amp */
3492 if ((caps & AC_AMPCAP_NUM_STEPS)
3493 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3494 err = stac92xx_add_control(spec,
3495 STAC_CTL_WIDGET_VOL,
3496 "Mono Playback Volume",
3497 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3498 if (err < 0)
3499 return err;
3500 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003501 }
3502
3503 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3504 AC_PINCTL_OUT_EN);
3505 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003506
Matt Porter403d1942005-11-29 15:00:51 +01003507 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
3508 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003509 if (spec->multiout.num_dacs == 0)
3510 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3511 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003512
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003513 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
3514
3515 if (err < 0)
3516 return err;
3517
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003518 /* setup analog beep controls */
3519 if (spec->anabeep_nid > 0) {
3520 err = stac92xx_auto_create_beep_ctls(codec,
3521 spec->anabeep_nid);
3522 if (err < 0)
3523 return err;
3524 }
3525
3526 /* setup digital beep controls and input device */
3527#ifdef CONFIG_SND_HDA_INPUT_BEEP
3528 if (spec->digbeep_nid > 0) {
3529 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003530 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003531
3532 err = stac92xx_auto_create_beep_ctls(codec, nid);
3533 if (err < 0)
3534 return err;
3535 err = snd_hda_attach_beep_device(codec, nid);
3536 if (err < 0)
3537 return err;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003538 /* if no beep switch is available, make its own one */
3539 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3540 if (codec->beep &&
3541 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3542 err = stac92xx_beep_switch_ctl(codec);
3543 if (err < 0)
3544 return err;
3545 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003546 }
3547#endif
3548
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003549 if (hp_speaker_swap == 1) {
3550 /* Restore the hp_outs and line_outs */
3551 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3552 sizeof(spec->autocfg.line_out_pins));
3553 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3554 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
3555 sizeof(spec->autocfg.speaker_pins));
3556 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
3557 memset(spec->autocfg.speaker_pins, 0,
3558 sizeof(spec->autocfg.speaker_pins));
3559 spec->autocfg.speaker_outs = 0;
3560 }
3561
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003562 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3563
3564 if (err < 0)
3565 return err;
3566
3567 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3568
3569 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003570 return err;
3571
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003572 if (spec->mono_nid > 0) {
3573 err = stac92xx_auto_create_mono_output_ctls(codec);
3574 if (err < 0)
3575 return err;
3576 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003577 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003578 err = stac92xx_auto_create_amp_output_ctls(codec);
3579 if (err < 0)
3580 return err;
3581 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003582 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003583 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3584 &spec->autocfg)) < 0)
3585 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003586 if (spec->num_muxes > 0) {
3587 err = stac92xx_auto_create_mux_input_ctls(codec);
3588 if (err < 0)
3589 return err;
3590 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003591 if (spec->num_smuxes > 0) {
3592 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3593 if (err < 0)
3594 return err;
3595 }
Matt Porter8b657272006-10-26 17:12:59 +02003596
Mattc7d4b2f2005-06-27 14:59:41 +02003597 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003598 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003599 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003600
Takashi Iwai82bc9552006-03-21 11:24:42 +01003601 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003602 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003603 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003604 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003605
Takashi Iwai603c4012008-07-30 15:01:44 +02003606 if (spec->kctls.list)
3607 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003608
3609 spec->input_mux = &spec->private_imux;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003610 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003611 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003612 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04003613 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003614 return 1;
3615}
3616
Takashi Iwai82bc9552006-03-21 11:24:42 +01003617/* add playback controls for HP output */
3618static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3619 struct auto_pin_cfg *cfg)
3620{
3621 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003622 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003623 unsigned int wid_caps;
3624
3625 if (! pin)
3626 return 0;
3627
3628 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003629 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003630 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003631
3632 return 0;
3633}
3634
Richard Fish160ea0d2006-09-06 13:58:25 +02003635/* add playback controls for LFE output */
3636static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3637 struct auto_pin_cfg *cfg)
3638{
3639 struct sigmatel_spec *spec = codec->spec;
3640 int err;
3641 hda_nid_t lfe_pin = 0x0;
3642 int i;
3643
3644 /*
3645 * search speaker outs and line outs for a mono speaker pin
3646 * with an amp. If one is found, add LFE controls
3647 * for it.
3648 */
3649 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3650 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003651 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003652 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3653 if (wcaps == AC_WCAP_OUT_AMP)
3654 /* found a mono speaker with an amp, must be lfe */
3655 lfe_pin = pin;
3656 }
3657
3658 /* if speaker_outs is 0, then speakers may be in line_outs */
3659 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3660 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3661 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003662 unsigned int defcfg;
Harvey Harrison8b551782008-02-29 11:56:48 +01003663 defcfg = snd_hda_codec_read(codec, pin, 0,
Richard Fish160ea0d2006-09-06 13:58:25 +02003664 AC_VERB_GET_CONFIG_DEFAULT,
3665 0x00);
Harvey Harrison8b551782008-02-29 11:56:48 +01003666 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003667 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003668 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3669 if (wcaps == AC_WCAP_OUT_AMP)
3670 /* found a mono speaker with an amp,
3671 must be lfe */
3672 lfe_pin = pin;
3673 }
3674 }
3675 }
3676
3677 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003678 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003679 if (err < 0)
3680 return err;
3681 }
3682
3683 return 0;
3684}
3685
Mattc7d4b2f2005-06-27 14:59:41 +02003686static int stac9200_parse_auto_config(struct hda_codec *codec)
3687{
3688 struct sigmatel_spec *spec = codec->spec;
3689 int err;
3690
Kailang Yangdf694da2005-12-05 19:42:22 +01003691 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003692 return err;
3693
3694 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3695 return err;
3696
Takashi Iwai82bc9552006-03-21 11:24:42 +01003697 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3698 return err;
3699
Richard Fish160ea0d2006-09-06 13:58:25 +02003700 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3701 return err;
3702
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003703 if (spec->num_muxes > 0) {
3704 err = stac92xx_auto_create_mux_input_ctls(codec);
3705 if (err < 0)
3706 return err;
3707 }
3708
Takashi Iwai82bc9552006-03-21 11:24:42 +01003709 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003710 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003711 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003712 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003713
Takashi Iwai603c4012008-07-30 15:01:44 +02003714 if (spec->kctls.list)
3715 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003716
3717 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003718 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003719
3720 return 1;
3721}
3722
Sam Revitch62fe78e2006-05-10 15:09:17 +02003723/*
3724 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3725 * funky external mute control using GPIO pins.
3726 */
3727
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003728static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003729 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003730{
3731 unsigned int gpiostate, gpiomask, gpiodir;
3732
3733 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3734 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003735 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003736
3737 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3738 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003739 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003740
3741 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3742 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003743 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003744
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003745 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003746 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3747
3748 snd_hda_codec_write(codec, codec->afg, 0,
3749 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003750 snd_hda_codec_read(codec, codec->afg, 0,
3751 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003752
3753 msleep(1);
3754
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003755 snd_hda_codec_read(codec, codec->afg, 0,
3756 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003757}
3758
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003759static int stac92xx_add_jack(struct hda_codec *codec,
3760 hda_nid_t nid, int type)
3761{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003762#ifdef CONFIG_SND_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003763 struct sigmatel_spec *spec = codec->spec;
3764 struct sigmatel_jack *jack;
3765 int def_conf = snd_hda_codec_read(codec, nid,
3766 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
3767 int connectivity = get_defcfg_connect(def_conf);
3768 char name[32];
3769
3770 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3771 return 0;
3772
3773 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3774 jack = snd_array_new(&spec->jacks);
3775 if (!jack)
3776 return -ENOMEM;
3777 jack->nid = nid;
3778 jack->type = type;
3779
3780 sprintf(name, "%s at %s %s Jack",
3781 snd_hda_get_jack_type(def_conf),
3782 snd_hda_get_jack_connectivity(def_conf),
3783 snd_hda_get_jack_location(def_conf));
3784
3785 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003786#else
3787 return 0;
3788#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003789}
3790
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003791static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3792 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003793{
3794 struct sigmatel_event *event;
3795
3796 snd_array_init(&spec->events, sizeof(*event), 32);
3797 event = snd_array_new(&spec->events);
3798 if (!event)
3799 return -ENOMEM;
3800 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003801 event->type = type;
3802 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003803 event->data = data;
3804
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003805 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003806}
3807
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003808static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
3809 hda_nid_t nid, unsigned char type)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003810{
3811 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003812 struct sigmatel_event *event = spec->events.list;
3813 int i;
3814
3815 for (i = 0; i < spec->events.used; i++, event++) {
3816 if (event->nid == nid && event->type == type)
3817 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003818 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003819 return NULL;
3820}
3821
3822static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
3823 unsigned char tag)
3824{
3825 struct sigmatel_spec *spec = codec->spec;
3826 struct sigmatel_event *event = spec->events.list;
3827 int i;
3828
3829 for (i = 0; i < spec->events.used; i++, event++) {
3830 if (event->tag == tag)
3831 return event;
3832 }
3833 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003834}
3835
Takashi Iwai314634b2006-09-21 11:56:18 +02003836static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003837 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02003838{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003839 struct sigmatel_event *event;
3840 int tag;
3841
3842 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
3843 return;
3844 event = stac_get_event(codec, nid, type);
3845 if (event)
3846 tag = event->tag;
3847 else
3848 tag = stac_add_event(codec->spec, nid, type, 0);
3849 if (tag < 0)
3850 return;
3851 snd_hda_codec_write_cache(codec, nid, 0,
3852 AC_VERB_SET_UNSOLICITED_ENABLE,
3853 AC_USRSP_EN | tag);
Takashi Iwai314634b2006-09-21 11:56:18 +02003854}
3855
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003856static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3857{
3858 int i;
3859 for (i = 0; i < cfg->hp_outs; i++)
3860 if (cfg->hp_pins[i] == nid)
3861 return 1; /* nid is a HP-Out */
3862
3863 return 0; /* nid is not a HP-Out */
3864};
3865
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003866static void stac92xx_power_down(struct hda_codec *codec)
3867{
3868 struct sigmatel_spec *spec = codec->spec;
3869
3870 /* power down inactive DACs */
3871 hda_nid_t *dac;
3872 for (dac = spec->dac_list; *dac; dac++)
Matthew Ranostay44510892008-02-21 07:49:31 +01003873 if (!is_in_dac_nids(spec, *dac) &&
3874 spec->multiout.hp_nid != *dac)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01003875 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003876 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3877}
3878
Takashi Iwaif73d3582008-11-25 08:21:51 +01003879static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3880 int enable);
3881
Mattc7d4b2f2005-06-27 14:59:41 +02003882static int stac92xx_init(struct hda_codec *codec)
3883{
3884 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003885 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01003886 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01003887 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003888
Mattc7d4b2f2005-06-27 14:59:41 +02003889 snd_hda_sequence_write(codec, spec->init);
3890
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02003891 /* power down adcs initially */
3892 if (spec->powerdown_adcs)
3893 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01003894 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02003895 spec->adc_nids[i], 0,
3896 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003897
3898 /* set up GPIO */
3899 gpio = spec->gpio_data;
3900 /* turn on EAPD statically when spec->eapd_switch isn't set.
3901 * otherwise, unsol event will turn it on/off dynamically
3902 */
3903 if (!spec->eapd_switch)
3904 gpio |= spec->eapd_mask;
3905 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
3906
Takashi Iwai82bc9552006-03-21 11:24:42 +01003907 /* set up pins */
3908 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02003909 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003910 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003911 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003912 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003913 }
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01003914 /* force to enable the first line-out; the others are set up
3915 * in unsol_event
3916 */
3917 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003918 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003919 /* fake event to set up pins */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003920 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
3921 STAC_HP_EVENT);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003922 } else {
3923 stac92xx_auto_init_multi_out(codec);
3924 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01003925 for (i = 0; i < cfg->hp_outs; i++)
3926 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003927 }
3928 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01003929 hda_nid_t nid = cfg->input_pins[i];
3930 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01003931 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01003932 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
3933 /* for mic pins, force to initialize */
3934 pinctl = stac92xx_get_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01003935 pinctl |= AC_PINCTL_IN_EN;
3936 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01003937 } else {
3938 pinctl = snd_hda_codec_read(codec, nid, 0,
3939 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3940 /* if PINCTL already set then skip */
Takashi Iwai12dde4c2008-12-05 13:09:27 +01003941 if (!(pinctl & AC_PINCTL_IN_EN)) {
3942 pinctl |= AC_PINCTL_IN_EN;
3943 stac92xx_auto_set_pinctl(codec, nid,
3944 pinctl);
3945 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01003946 }
Takashi Iwai12dde4c2008-12-05 13:09:27 +01003947 conf = snd_hda_codec_read(codec, nid, 0,
3948 AC_VERB_GET_CONFIG_DEFAULT, 0);
3949 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
3950 enable_pin_detect(codec, nid,
3951 STAC_INSERT_EVENT);
3952 stac_issue_unsol_event(codec, nid,
3953 STAC_INSERT_EVENT);
3954 }
Takashi Iwaic960a032006-03-23 17:06:28 +01003955 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01003956 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003957 for (i = 0; i < spec->num_dmics; i++)
3958 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
3959 AC_PINCTL_IN_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003960 if (cfg->dig_out_pin)
3961 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
3962 AC_PINCTL_OUT_EN);
3963 if (cfg->dig_in_pin)
3964 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
3965 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003966 for (i = 0; i < spec->num_pwrs; i++) {
3967 hda_nid_t nid = spec->pwr_nids[i];
3968 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003969
Takashi Iwaif73d3582008-11-25 08:21:51 +01003970 if (is_nid_hp_pin(cfg, nid) && spec->hp_detect)
3971 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003972
Takashi Iwaif73d3582008-11-25 08:21:51 +01003973 pinctl = snd_hda_codec_read(codec, nid, 0,
3974 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3975 /* outputs are only ports capable of power management
3976 * any attempts on powering down a input port cause the
3977 * referenced VREF to act quirky.
3978 */
3979 if (pinctl & AC_PINCTL_IN_EN)
3980 continue;
3981 def_conf = snd_hda_codec_read(codec, nid, 0,
3982 AC_VERB_GET_CONFIG_DEFAULT, 0);
3983 def_conf = get_defcfg_connect(def_conf);
3984 /* skip any ports that don't have jacks since presence
3985 * detection is useless */
3986 if (def_conf != AC_JACK_PORT_COMPLEX) {
3987 if (def_conf != AC_JACK_PORT_NONE)
3988 stac_toggle_power_map(codec, nid, 1);
3989 continue;
3990 }
Takashi Iwai12dde4c2008-12-05 13:09:27 +01003991 if (!stac_get_event(codec, nid, STAC_INSERT_EVENT)) {
3992 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
3993 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
3994 }
Takashi Iwaif73d3582008-11-25 08:21:51 +01003995 }
3996 if (spec->dac_list)
3997 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02003998 return 0;
3999}
4000
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004001static void stac92xx_free_jacks(struct hda_codec *codec)
4002{
Takashi Iwaie4973e12008-11-18 09:32:42 +01004003#ifdef CONFIG_SND_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01004004 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004005 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01004006 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004007 struct sigmatel_jack *jacks = spec->jacks.list;
4008 int i;
4009 for (i = 0; i < spec->jacks.used; i++)
4010 snd_device_free(codec->bus->card, &jacks[i].jack);
4011 }
4012 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004013#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004014}
4015
Takashi Iwai603c4012008-07-30 15:01:44 +02004016static void stac92xx_free_kctls(struct hda_codec *codec)
4017{
4018 struct sigmatel_spec *spec = codec->spec;
4019
4020 if (spec->kctls.list) {
4021 struct snd_kcontrol_new *kctl = spec->kctls.list;
4022 int i;
4023 for (i = 0; i < spec->kctls.used; i++)
4024 kfree(kctl[i].name);
4025 }
4026 snd_array_free(&spec->kctls);
4027}
4028
Matt2f2f4252005-04-13 14:45:30 +02004029static void stac92xx_free(struct hda_codec *codec)
4030{
Mattc7d4b2f2005-06-27 14:59:41 +02004031 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004032
4033 if (! spec)
4034 return;
4035
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004036 kfree(spec->pin_configs);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004037 stac92xx_free_jacks(codec);
4038 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004039
Mattc7d4b2f2005-06-27 14:59:41 +02004040 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004041 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004042}
4043
Matt4e550962005-07-04 17:51:39 +02004044static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4045 unsigned int flag)
4046{
4047 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4048 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004049
Takashi Iwaif9acba42007-05-29 18:01:06 +02004050 if (pin_ctl & AC_PINCTL_IN_EN) {
4051 /*
4052 * we need to check the current set-up direction of
4053 * shared input pins since they can be switched via
4054 * "xxx as Output" mixer switch
4055 */
4056 struct sigmatel_spec *spec = codec->spec;
4057 struct auto_pin_cfg *cfg = &spec->autocfg;
4058 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
4059 spec->line_switch) ||
4060 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
4061 spec->mic_switch))
4062 return;
4063 }
4064
Steve Longerbeam7b043892007-05-03 20:50:03 +02004065 /* if setting pin direction bits, clear the current
4066 direction bits first */
4067 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4068 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4069
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004070 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02004071 AC_VERB_SET_PIN_WIDGET_CONTROL,
4072 pin_ctl | flag);
4073}
4074
4075static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4076 unsigned int flag)
4077{
4078 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4079 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004080 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02004081 AC_VERB_SET_PIN_WIDGET_CONTROL,
4082 pin_ctl & ~flag);
4083}
4084
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004085static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004086{
4087 if (!nid)
4088 return 0;
4089 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004090 & (1 << 31))
4091 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004092 return 0;
4093}
4094
Takashi Iwaid7a89432008-11-12 09:48:04 +01004095/* return non-zero if the hp-pin of the given array index isn't
4096 * a jack-detection target
4097 */
4098static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4099{
4100 struct auto_pin_cfg *cfg = &spec->autocfg;
4101
4102 /* ignore sensing of shared line and mic jacks */
4103 if (spec->line_switch &&
4104 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_LINE])
4105 return 1;
4106 if (spec->mic_switch &&
4107 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_MIC])
4108 return 1;
4109 /* ignore if the pin is set as line-out */
4110 if (cfg->hp_pins[i] == spec->hp_switch)
4111 return 1;
4112 return 0;
4113}
4114
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004115static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004116{
4117 struct sigmatel_spec *spec = codec->spec;
4118 struct auto_pin_cfg *cfg = &spec->autocfg;
4119 int i, presence;
4120
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004121 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004122 if (spec->gpio_mute)
4123 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4124 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4125
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004126 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004127 if (presence)
4128 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004129 if (no_hp_sensing(spec, i))
4130 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004131 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4132 if (presence) {
4133 unsigned int pinctl;
4134 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4135 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4136 if (pinctl & AC_PINCTL_IN_EN)
4137 presence = 0; /* mic- or line-input */
4138 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004139 }
Matt4e550962005-07-04 17:51:39 +02004140
4141 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004142 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004143 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004144 stac92xx_reset_pinctl(codec, spec->hp_switch,
4145 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004146 for (i = 0; i < cfg->line_outs; i++)
4147 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4148 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004149 for (i = 0; i < cfg->speaker_outs; i++)
4150 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4151 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004152 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004153 stac_gpio_set(codec, spec->gpio_mask,
4154 spec->gpio_dir, spec->gpio_data &
4155 ~spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004156 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004157 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004158 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004159 stac92xx_set_pinctl(codec, spec->hp_switch,
4160 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004161 for (i = 0; i < cfg->line_outs; i++)
4162 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4163 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004164 for (i = 0; i < cfg->speaker_outs; i++)
4165 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4166 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004167 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004168 stac_gpio_set(codec, spec->gpio_mask,
4169 spec->gpio_dir, spec->gpio_data |
4170 spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004171 }
Takashi Iwaid7a89432008-11-12 09:48:04 +01004172 /* toggle hp outs */
4173 for (i = 0; i < cfg->hp_outs; i++) {
4174 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4175 if (no_hp_sensing(spec, i))
4176 continue;
4177 if (presence)
4178 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4179 else
4180 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4181 }
Matt4e550962005-07-04 17:51:39 +02004182}
4183
Takashi Iwaif73d3582008-11-25 08:21:51 +01004184static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4185 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004186{
4187 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004188 unsigned int idx, val;
4189
4190 for (idx = 0; idx < spec->num_pwrs; idx++) {
4191 if (spec->pwr_nids[idx] == nid)
4192 break;
4193 }
4194 if (idx >= spec->num_pwrs)
4195 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004196
4197 /* several codecs have two power down bits */
4198 if (spec->pwr_mapping)
4199 idx = spec->pwr_mapping[idx];
4200 else
4201 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004202
Takashi Iwaif73d3582008-11-25 08:21:51 +01004203 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4204 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004205 val &= ~idx;
4206 else
4207 val |= idx;
4208
4209 /* power down unused output ports */
4210 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004211}
4212
Takashi Iwaif73d3582008-11-25 08:21:51 +01004213static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4214{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004215 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004216}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004217
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004218static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4219{
4220 struct sigmatel_spec *spec = codec->spec;
4221 struct sigmatel_jack *jacks = spec->jacks.list;
4222
4223 if (jacks) {
4224 int i;
4225 for (i = 0; i < spec->jacks.used; i++) {
4226 if (jacks->nid == nid) {
4227 unsigned int pin_ctl =
4228 snd_hda_codec_read(codec, nid,
4229 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4230 0x00);
4231 int type = jacks->type;
4232 if (type == (SND_JACK_LINEOUT
4233 | SND_JACK_HEADPHONE))
4234 type = (pin_ctl & AC_PINCTL_HP_EN)
4235 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4236 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004237 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004238 ? type : 0);
4239 }
4240 jacks++;
4241 }
4242 }
4243}
Matt2f2f4252005-04-13 14:45:30 +02004244
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004245static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4246 unsigned char type)
4247{
4248 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4249 if (!event)
4250 return;
4251 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4252}
4253
Takashi Iwai314634b2006-09-21 11:56:18 +02004254static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4255{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004256 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004257 struct sigmatel_event *event;
4258 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004259
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004260 tag = (res >> 26) & 0x7f;
4261 event = stac_get_event_from_tag(codec, tag);
4262 if (!event)
4263 return;
4264
4265 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004266 case STAC_HP_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004267 stac92xx_hp_detect(codec);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004268 /* fallthru */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004269 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004270 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004271 if (spec->num_pwrs > 0)
4272 stac92xx_pin_sense(codec, event->nid);
4273 stac92xx_report_jack(codec, event->nid);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004274 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004275 case STAC_VREF_EVENT:
4276 data = snd_hda_codec_read(codec, codec->afg, 0,
4277 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004278 /* toggle VREF state based on GPIOx status */
4279 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004280 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004281 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004282 }
4283}
4284
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004285#ifdef CONFIG_PROC_FS
4286static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4287 struct hda_codec *codec, hda_nid_t nid)
4288{
4289 if (nid == codec->afg)
4290 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4291 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4292}
4293
4294static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4295 struct hda_codec *codec,
4296 unsigned int verb)
4297{
4298 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4299 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4300}
4301
4302/* stac92hd71bxx, stac92hd73xx */
4303static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4304 struct hda_codec *codec, hda_nid_t nid)
4305{
4306 stac92hd_proc_hook(buffer, codec, nid);
4307 if (nid == codec->afg)
4308 analog_loop_proc_hook(buffer, codec, 0xfa0);
4309}
4310
4311static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4312 struct hda_codec *codec, hda_nid_t nid)
4313{
4314 if (nid == codec->afg)
4315 analog_loop_proc_hook(buffer, codec, 0xfe0);
4316}
4317
4318static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4319 struct hda_codec *codec, hda_nid_t nid)
4320{
4321 if (nid == codec->afg)
4322 analog_loop_proc_hook(buffer, codec, 0xfeb);
4323}
4324#else
4325#define stac92hd_proc_hook NULL
4326#define stac92hd7x_proc_hook NULL
4327#define stac9205_proc_hook NULL
4328#define stac927x_proc_hook NULL
4329#endif
4330
Takashi Iwaicb53c622007-08-10 17:21:45 +02004331#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004332static int stac92xx_resume(struct hda_codec *codec)
4333{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004334 struct sigmatel_spec *spec = codec->spec;
4335
Richard Fish11b44bb2006-08-23 18:31:34 +02004336 stac92xx_set_config_regs(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004337 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004338 snd_hda_codec_resume_amp(codec);
4339 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004340 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004341 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004342 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4343 STAC_HP_EVENT);
Mattff6fdc32005-06-27 15:06:52 +02004344 return 0;
4345}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004346
4347static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4348{
4349 struct sigmatel_spec *spec = codec->spec;
4350 if (spec->eapd_mask)
4351 stac_gpio_set(codec, spec->gpio_mask,
4352 spec->gpio_dir, spec->gpio_data &
4353 ~spec->eapd_mask);
4354 return 0;
4355}
Mattff6fdc32005-06-27 15:06:52 +02004356#endif
4357
Matt2f2f4252005-04-13 14:45:30 +02004358static struct hda_codec_ops stac92xx_patch_ops = {
4359 .build_controls = stac92xx_build_controls,
4360 .build_pcms = stac92xx_build_pcms,
4361 .init = stac92xx_init,
4362 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004363 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004364#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004365 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004366 .resume = stac92xx_resume,
4367#endif
Matt2f2f4252005-04-13 14:45:30 +02004368};
4369
4370static int patch_stac9200(struct hda_codec *codec)
4371{
4372 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004373 int err;
Matt2f2f4252005-04-13 14:45:30 +02004374
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004375 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004376 if (spec == NULL)
4377 return -ENOMEM;
4378
4379 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004380 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004381 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004382 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4383 stac9200_models,
4384 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02004385 if (spec->board_config < 0) {
4386 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4387 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004388 } else
4389 err = stac_save_pin_cfgs(codec,
4390 stac9200_brd_tbl[spec->board_config]);
4391 if (err < 0) {
4392 stac92xx_free(codec);
4393 return err;
Matt Porter403d1942005-11-29 15:00:51 +01004394 }
Matt2f2f4252005-04-13 14:45:30 +02004395
4396 spec->multiout.max_channels = 2;
4397 spec->multiout.num_dacs = 1;
4398 spec->multiout.dac_nids = stac9200_dac_nids;
4399 spec->adc_nids = stac9200_adc_nids;
4400 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004401 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004402 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004403 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004404 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004405
Tobin Davisbf277782008-02-03 20:31:47 +01004406 if (spec->board_config == STAC_9200_GATEWAY ||
4407 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004408 spec->init = stac9200_eapd_init;
4409 else
4410 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004411 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004412
Takashi Iwai117f2572008-03-18 09:53:23 +01004413 if (spec->board_config == STAC_9200_PANASONIC) {
4414 spec->gpio_mask = spec->gpio_dir = 0x09;
4415 spec->gpio_data = 0x00;
4416 }
4417
Mattc7d4b2f2005-06-27 14:59:41 +02004418 err = stac9200_parse_auto_config(codec);
4419 if (err < 0) {
4420 stac92xx_free(codec);
4421 return err;
4422 }
Matt2f2f4252005-04-13 14:45:30 +02004423
4424 codec->patch_ops = stac92xx_patch_ops;
4425
4426 return 0;
4427}
4428
Tobin Davis8e21c342007-01-08 11:04:17 +01004429static int patch_stac925x(struct hda_codec *codec)
4430{
4431 struct sigmatel_spec *spec;
4432 int err;
4433
4434 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4435 if (spec == NULL)
4436 return -ENOMEM;
4437
4438 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004439 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004440 spec->pin_nids = stac925x_pin_nids;
4441 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
4442 stac925x_models,
4443 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004444 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01004445 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02004446 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
4447 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01004448 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004449 } else
4450 err = stac_save_pin_cfgs(codec,
4451 stac925x_brd_tbl[spec->board_config]);
4452 if (err < 0) {
4453 stac92xx_free(codec);
4454 return err;
Tobin Davis8e21c342007-01-08 11:04:17 +01004455 }
4456
4457 spec->multiout.max_channels = 2;
4458 spec->multiout.num_dacs = 1;
4459 spec->multiout.dac_nids = stac925x_dac_nids;
4460 spec->adc_nids = stac925x_adc_nids;
4461 spec->mux_nids = stac925x_mux_nids;
4462 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004463 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004464 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004465 switch (codec->vendor_id) {
4466 case 0x83847632: /* STAC9202 */
4467 case 0x83847633: /* STAC9202D */
4468 case 0x83847636: /* STAC9251 */
4469 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004470 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004471 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004472 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4473 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004474 break;
4475 default:
4476 spec->num_dmics = 0;
4477 break;
4478 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004479
4480 spec->init = stac925x_core_init;
4481 spec->mixer = stac925x_mixer;
4482
4483 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004484 if (!err) {
4485 if (spec->board_config < 0) {
4486 printk(KERN_WARNING "hda_codec: No auto-config is "
4487 "available, default to model=ref\n");
4488 spec->board_config = STAC_925x_REF;
4489 goto again;
4490 }
4491 err = -EINVAL;
4492 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004493 if (err < 0) {
4494 stac92xx_free(codec);
4495 return err;
4496 }
4497
4498 codec->patch_ops = stac92xx_patch_ops;
4499
4500 return 0;
4501}
4502
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004503static struct hda_input_mux stac92hd73xx_dmux = {
4504 .num_items = 4,
4505 .items = {
4506 { "Analog Inputs", 0x0b },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004507 { "Digital Mic 1", 0x09 },
4508 { "Digital Mic 2", 0x0a },
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004509 { "CD", 0x08 },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004510 }
4511};
4512
4513static int patch_stac92hd73xx(struct hda_codec *codec)
4514{
4515 struct sigmatel_spec *spec;
4516 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4517 int err = 0;
4518
4519 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4520 if (spec == NULL)
4521 return -ENOMEM;
4522
4523 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004524 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004525 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4526 spec->pin_nids = stac92hd73xx_pin_nids;
4527 spec->board_config = snd_hda_check_board_config(codec,
4528 STAC_92HD73XX_MODELS,
4529 stac92hd73xx_models,
4530 stac92hd73xx_cfg_tbl);
4531again:
4532 if (spec->board_config < 0) {
4533 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4534 " STAC92HD73XX, using BIOS defaults\n");
4535 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004536 } else
4537 err = stac_save_pin_cfgs(codec,
4538 stac92hd73xx_brd_tbl[spec->board_config]);
4539 if (err < 0) {
4540 stac92xx_free(codec);
4541 return err;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004542 }
4543
4544 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
4545 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4546
4547 if (spec->multiout.num_dacs < 0) {
4548 printk(KERN_WARNING "hda_codec: Could not determine "
4549 "number of channels defaulting to DAC count\n");
4550 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
4551 }
4552
4553 switch (spec->multiout.num_dacs) {
4554 case 0x3: /* 6 Channel */
Takashi Iwai85f13b62008-12-19 08:20:38 +01004555 spec->multiout.hp_nid = 0x17;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004556 spec->mixer = stac92hd73xx_6ch_mixer;
4557 spec->init = stac92hd73xx_6ch_core_init;
4558 break;
4559 case 0x4: /* 8 Channel */
Takashi Iwai85f13b62008-12-19 08:20:38 +01004560 spec->multiout.hp_nid = 0x18;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004561 spec->mixer = stac92hd73xx_8ch_mixer;
4562 spec->init = stac92hd73xx_8ch_core_init;
4563 break;
4564 case 0x5: /* 10 Channel */
Takashi Iwai85f13b62008-12-19 08:20:38 +01004565 spec->multiout.hp_nid = 0x19;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004566 spec->mixer = stac92hd73xx_10ch_mixer;
4567 spec->init = stac92hd73xx_10ch_core_init;
4568 };
4569
4570 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
4571 spec->aloopback_mask = 0x01;
4572 spec->aloopback_shift = 8;
4573
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004574 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004575 spec->mux_nids = stac92hd73xx_mux_nids;
4576 spec->adc_nids = stac92hd73xx_adc_nids;
4577 spec->dmic_nids = stac92hd73xx_dmic_nids;
4578 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004579 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04004580 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004581 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004582
4583 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4584 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01004585 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004586 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4587 sizeof(stac92hd73xx_dmux));
4588
Matthew Ranostaya7662642008-02-21 07:51:14 +01004589 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004590 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004591 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004592 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004593 case STAC_DELL_M6_AMIC:
4594 case STAC_DELL_M6_DMIC:
4595 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004596 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004597 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4598 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004599 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004600 spec->num_amps = 1;
Takashi Iwai8f55c1e2008-12-19 14:02:32 +01004601 spec->multiout.hp_nid = 0; /* dual HPs */
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004602
4603 if (!spec->init)
4604 spec->init = dell_m6_core_init;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004605 switch (spec->board_config) {
4606 case STAC_DELL_M6_AMIC: /* Analog Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004607 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4608 spec->num_dmics = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004609 spec->private_dimux.num_items = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004610 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004611 case STAC_DELL_M6_DMIC: /* Digital Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004612 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4613 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004614 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004615 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004616 case STAC_DELL_M6_BOTH: /* Both */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004617 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4618 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4619 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004620 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004621 break;
4622 }
4623 break;
4624 default:
4625 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004626 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004627 spec->eapd_switch = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004628 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04004629 if (spec->board_config > STAC_92HD73XX_REF) {
4630 /* GPIO0 High = Enable EAPD */
4631 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4632 spec->gpio_data = 0x01;
4633 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004634 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004635
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004636 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4637 spec->pwr_nids = stac92hd73xx_pwr_nids;
4638
Matthew Ranostayd9737752008-09-07 12:03:41 +02004639 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004640
4641 if (!err) {
4642 if (spec->board_config < 0) {
4643 printk(KERN_WARNING "hda_codec: No auto-config is "
4644 "available, default to model=ref\n");
4645 spec->board_config = STAC_92HD73XX_REF;
4646 goto again;
4647 }
4648 err = -EINVAL;
4649 }
4650
4651 if (err < 0) {
4652 stac92xx_free(codec);
4653 return err;
4654 }
4655
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01004656 if (spec->board_config == STAC_92HD73XX_NO_JD)
4657 spec->hp_detect = 0;
4658
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004659 codec->patch_ops = stac92xx_patch_ops;
4660
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004661 codec->proc_widget_hook = stac92hd7x_proc_hook;
4662
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004663 return 0;
4664}
4665
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004666static struct hda_input_mux stac92hd83xxx_dmux = {
4667 .num_items = 3,
4668 .items = {
4669 { "Analog Inputs", 0x03 },
4670 { "Digital Mic 1", 0x04 },
4671 { "Digital Mic 2", 0x05 },
4672 }
4673};
4674
4675static int patch_stac92hd83xxx(struct hda_codec *codec)
4676{
4677 struct sigmatel_spec *spec;
4678 int err;
4679
4680 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4681 if (spec == NULL)
4682 return -ENOMEM;
4683
4684 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004685 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004686 spec->mono_nid = 0x19;
4687 spec->digbeep_nid = 0x21;
4688 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4689 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4690 spec->adc_nids = stac92hd83xxx_adc_nids;
4691 spec->pwr_nids = stac92hd83xxx_pwr_nids;
4692 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4693 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
4694 spec->multiout.dac_nids = stac92hd83xxx_dac_nids;
4695
4696 spec->init = stac92hd83xxx_core_init;
4697 switch (codec->vendor_id) {
4698 case 0x111d7605:
4699 spec->multiout.num_dacs = STAC92HD81_DAC_COUNT;
4700 break;
4701 default:
4702 spec->num_pwrs--;
4703 spec->init++; /* switch to config #2 */
4704 spec->multiout.num_dacs = STAC92HD83_DAC_COUNT;
4705 }
4706
4707 spec->mixer = stac92hd83xxx_mixer;
4708 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4709 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4710 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
4711 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4712 spec->dinput_mux = &stac92hd83xxx_dmux;
4713 spec->pin_nids = stac92hd83xxx_pin_nids;
4714 spec->board_config = snd_hda_check_board_config(codec,
4715 STAC_92HD83XXX_MODELS,
4716 stac92hd83xxx_models,
4717 stac92hd83xxx_cfg_tbl);
4718again:
4719 if (spec->board_config < 0) {
4720 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4721 " STAC92HD83XXX, using BIOS defaults\n");
4722 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004723 } else
4724 err = stac_save_pin_cfgs(codec,
4725 stac92hd83xxx_brd_tbl[spec->board_config]);
4726 if (err < 0) {
4727 stac92xx_free(codec);
4728 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004729 }
4730
4731 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4732 if (!err) {
4733 if (spec->board_config < 0) {
4734 printk(KERN_WARNING "hda_codec: No auto-config is "
4735 "available, default to model=ref\n");
4736 spec->board_config = STAC_92HD83XXX_REF;
4737 goto again;
4738 }
4739 err = -EINVAL;
4740 }
4741
4742 if (err < 0) {
4743 stac92xx_free(codec);
4744 return err;
4745 }
4746
4747 codec->patch_ops = stac92xx_patch_ops;
4748
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004749 codec->proc_widget_hook = stac92hd_proc_hook;
4750
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004751 return 0;
4752}
4753
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004754static struct hda_input_mux stac92hd71bxx_dmux = {
4755 .num_items = 4,
4756 .items = {
4757 { "Analog Inputs", 0x00 },
4758 { "Mixer", 0x01 },
4759 { "Digital Mic 1", 0x02 },
4760 { "Digital Mic 2", 0x03 },
4761 }
4762};
4763
Matthew Ranostaye035b842007-11-06 11:53:55 +01004764static int patch_stac92hd71bxx(struct hda_codec *codec)
4765{
4766 struct sigmatel_spec *spec;
4767 int err = 0;
4768
4769 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4770 if (spec == NULL)
4771 return -ENOMEM;
4772
4773 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004774 codec->patch_ops = stac92xx_patch_ops;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004775 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004776 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004777 spec->pin_nids = stac92hd71bxx_pin_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004778 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4779 sizeof(stac92hd71bxx_dmux));
Matthew Ranostaye035b842007-11-06 11:53:55 +01004780 spec->board_config = snd_hda_check_board_config(codec,
4781 STAC_92HD71BXX_MODELS,
4782 stac92hd71bxx_models,
4783 stac92hd71bxx_cfg_tbl);
4784again:
4785 if (spec->board_config < 0) {
4786 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4787 " STAC92HD71BXX, using BIOS defaults\n");
4788 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004789 } else
4790 err = stac_save_pin_cfgs(codec,
4791 stac92hd71bxx_brd_tbl[spec->board_config]);
4792 if (err < 0) {
4793 stac92xx_free(codec);
4794 return err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004795 }
4796
Takashi Iwai41c3b642008-11-18 10:45:15 +01004797 if (spec->board_config > STAC_92HD71BXX_REF) {
4798 /* GPIO0 = EAPD */
4799 spec->gpio_mask = 0x01;
4800 spec->gpio_dir = 0x01;
4801 spec->gpio_data = 0x01;
4802 }
4803
Matthew Ranostay541eee82007-12-14 12:08:04 +01004804 switch (codec->vendor_id) {
4805 case 0x111d76b6: /* 4 Port without Analog Mixer */
4806 case 0x111d76b7:
4807 case 0x111d76b4: /* 6 Port without Analog Mixer */
4808 case 0x111d76b5:
4809 spec->mixer = stac92hd71bxx_mixer;
4810 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004811 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004812 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004813 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01004814 switch (spec->board_config) {
4815 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04004816 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004817 err = stac_add_event(spec, codec->afg,
4818 STAC_VREF_EVENT, 0x02);
4819 if (err < 0)
4820 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01004821 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04004822 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4823 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004824 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004825 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004826 spec->gpio_mask |= 0x02;
4827 break;
4828 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004829 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004830 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004831 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004832
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004833 /* no output amps */
4834 spec->num_pwrs = 0;
4835 spec->mixer = stac92hd71bxx_analog_mixer;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004836 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004837
4838 /* disable VSW */
4839 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004840 stac_change_pin_config(codec, 0xf, 0x40f000f0);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004841 break;
4842 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004843 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004844 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004845
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004846 /* no output amps */
4847 spec->num_pwrs = 0;
4848 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01004849 default:
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004850 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004851 spec->mixer = stac92hd71bxx_analog_mixer;
4852 spec->init = stac92hd71bxx_analog_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004853 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004854 }
4855
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004856 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004857 spec->aloopback_shift = 0;
4858
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004859 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004860 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004861 spec->mux_nids = stac92hd71bxx_mux_nids;
4862 spec->adc_nids = stac92hd71bxx_adc_nids;
4863 spec->dmic_nids = stac92hd71bxx_dmic_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004864 spec->dmux_nids = stac92hd71bxx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004865 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004866 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004867
4868 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
4869 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004870
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004871 switch (spec->board_config) {
4872 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004873 /* enable internal microphone */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004874 stac_change_pin_config(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04004875 stac92xx_auto_set_pinctl(codec, 0x0e,
4876 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05004877 /* fallthru */
4878 case STAC_DELL_M4_2:
4879 spec->num_dmics = 0;
4880 spec->num_smuxes = 0;
4881 spec->num_dmuxes = 0;
4882 break;
4883 case STAC_DELL_M4_1:
4884 case STAC_DELL_M4_3:
4885 spec->num_dmics = 1;
4886 spec->num_smuxes = 0;
4887 spec->num_dmuxes = 0;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004888 break;
4889 default:
4890 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
4891 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
4892 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
4893 };
4894
Takashi Iwaiaea7bb02008-02-25 18:26:41 +01004895 spec->multiout.num_dacs = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004896 spec->multiout.hp_nid = 0x11;
4897 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004898 if (spec->dinput_mux)
4899 spec->private_dimux.num_items +=
4900 spec->num_dmics -
4901 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004902
4903 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
4904 if (!err) {
4905 if (spec->board_config < 0) {
4906 printk(KERN_WARNING "hda_codec: No auto-config is "
4907 "available, default to model=ref\n");
4908 spec->board_config = STAC_92HD71BXX_REF;
4909 goto again;
4910 }
4911 err = -EINVAL;
4912 }
4913
4914 if (err < 0) {
4915 stac92xx_free(codec);
4916 return err;
4917 }
4918
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004919 codec->proc_widget_hook = stac92hd7x_proc_hook;
4920
Matthew Ranostaye035b842007-11-06 11:53:55 +01004921 return 0;
4922};
4923
Matt2f2f4252005-04-13 14:45:30 +02004924static int patch_stac922x(struct hda_codec *codec)
4925{
4926 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004927 int err;
Matt2f2f4252005-04-13 14:45:30 +02004928
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004929 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004930 if (spec == NULL)
4931 return -ENOMEM;
4932
4933 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004934 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004935 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004936 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
4937 stac922x_models,
4938 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08004939 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004940 spec->gpio_mask = spec->gpio_dir = 0x03;
4941 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004942 /* Intel Macs have all same PCI SSID, so we need to check
4943 * codec SSID to distinguish the exact models
4944 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01004945 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004946 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004947
4948 case 0x106b0800:
4949 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02004950 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004951 case 0x106b0600:
4952 case 0x106b0700:
4953 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01004954 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004955 case 0x106b0e00:
4956 case 0x106b0f00:
4957 case 0x106b1600:
4958 case 0x106b1700:
4959 case 0x106b0200:
4960 case 0x106b1e00:
4961 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004962 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004963 case 0x106b1a00:
4964 case 0x00000100:
4965 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02004966 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004967 case 0x106b0a00:
4968 case 0x106b2200:
4969 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02004970 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08004971 default:
4972 spec->board_config = STAC_INTEL_MAC_V3;
4973 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004974 }
4975 }
4976
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004977 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02004978 if (spec->board_config < 0) {
4979 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
4980 "using BIOS defaults\n");
4981 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004982 } else
4983 err = stac_save_pin_cfgs(codec,
4984 stac922x_brd_tbl[spec->board_config]);
4985 if (err < 0) {
4986 stac92xx_free(codec);
4987 return err;
Matt Porter403d1942005-11-29 15:00:51 +01004988 }
Matt2f2f4252005-04-13 14:45:30 +02004989
Matt2f2f4252005-04-13 14:45:30 +02004990 spec->adc_nids = stac922x_adc_nids;
4991 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01004992 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004993 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02004994 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004995 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004996
4997 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004998 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004999
5000 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005001
Matt Porter3cc08dc2006-01-23 15:27:49 +01005002 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005003 if (!err) {
5004 if (spec->board_config < 0) {
5005 printk(KERN_WARNING "hda_codec: No auto-config is "
5006 "available, default to model=ref\n");
5007 spec->board_config = STAC_D945_REF;
5008 goto again;
5009 }
5010 err = -EINVAL;
5011 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005012 if (err < 0) {
5013 stac92xx_free(codec);
5014 return err;
5015 }
5016
5017 codec->patch_ops = stac92xx_patch_ops;
5018
Takashi Iwai807a46362007-05-29 19:01:37 +02005019 /* Fix Mux capture level; max to 2 */
5020 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5021 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5022 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5023 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5024 (0 << AC_AMPCAP_MUTE_SHIFT));
5025
Matt Porter3cc08dc2006-01-23 15:27:49 +01005026 return 0;
5027}
5028
5029static int patch_stac927x(struct hda_codec *codec)
5030{
5031 struct sigmatel_spec *spec;
5032 int err;
5033
5034 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5035 if (spec == NULL)
5036 return -ENOMEM;
5037
5038 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005039 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005040 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005041 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5042 stac927x_models,
5043 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005044 again:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005045 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
5046 if (spec->board_config < 0)
5047 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5048 "STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02005049 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005050 } else
5051 err = stac_save_pin_cfgs(codec,
5052 stac927x_brd_tbl[spec->board_config]);
5053 if (err < 0) {
5054 stac92xx_free(codec);
5055 return err;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005056 }
5057
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005058 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005059 spec->adc_nids = stac927x_adc_nids;
5060 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5061 spec->mux_nids = stac927x_mux_nids;
5062 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005063 spec->smux_nids = stac927x_smux_nids;
5064 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005065 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005066 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005067 spec->multiout.dac_nids = spec->dac_nids;
5068
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005069 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005070 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005071 case STAC_D965_5ST:
5072 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005073 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005074 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005075 spec->num_dmics = 0;
5076
Tobin Davis93ed1502006-09-01 21:03:12 +02005077 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005078 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005079 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005080 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005081 switch (codec->subsystem_id) {
5082 case 0x10280209:
5083 case 0x1028022e:
5084 /* correct the device field to SPDIF out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005085 stac_change_pin_config(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005086 break;
5087 };
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005088 /* configure the analog microphone on some laptops */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005089 stac_change_pin_config(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005090 /* correct the front output jack as a hp out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005091 stac_change_pin_config(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005092 /* correct the front input jack as a mic */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005093 stac_change_pin_config(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005094 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005095 case STAC_DELL_3ST:
5096 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005097 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005098 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005099 spec->dmic_nids = stac927x_dmic_nids;
5100 spec->num_dmics = STAC927X_NUM_DMICS;
5101
Tobin Davis93ed1502006-09-01 21:03:12 +02005102 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005103 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005104 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005105 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005106 break;
5107 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005108 if (spec->board_config > STAC_D965_REF) {
5109 /* GPIO0 High = Enable EAPD */
5110 spec->eapd_mask = spec->gpio_mask = 0x01;
5111 spec->gpio_dir = spec->gpio_data = 0x01;
5112 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005113 spec->num_dmics = 0;
5114
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005115 spec->init = stac927x_core_init;
5116 spec->mixer = stac927x_mixer;
5117 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005118
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005119 spec->num_pwrs = 0;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005120 spec->aloopback_mask = 0x40;
5121 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005122 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005123
Matt Porter3cc08dc2006-01-23 15:27:49 +01005124 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005125 if (!err) {
5126 if (spec->board_config < 0) {
5127 printk(KERN_WARNING "hda_codec: No auto-config is "
5128 "available, default to model=ref\n");
5129 spec->board_config = STAC_D965_REF;
5130 goto again;
5131 }
5132 err = -EINVAL;
5133 }
Mattc7d4b2f2005-06-27 14:59:41 +02005134 if (err < 0) {
5135 stac92xx_free(codec);
5136 return err;
5137 }
Matt2f2f4252005-04-13 14:45:30 +02005138
5139 codec->patch_ops = stac92xx_patch_ops;
5140
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005141 codec->proc_widget_hook = stac927x_proc_hook;
5142
Takashi Iwai52987652008-01-16 16:09:47 +01005143 /*
5144 * !!FIXME!!
5145 * The STAC927x seem to require fairly long delays for certain
5146 * command sequences. With too short delays (even if the answer
5147 * is set to RIRB properly), it results in the silence output
5148 * on some hardwares like Dell.
5149 *
5150 * The below flag enables the longer delay (see get_response
5151 * in hda_intel.c).
5152 */
5153 codec->bus->needs_damn_long_delay = 1;
5154
Takashi Iwaie28d8322008-12-17 13:48:29 +01005155 /* no jack detecion for ref-no-jd model */
5156 if (spec->board_config == STAC_D965_REF_NO_JD)
5157 spec->hp_detect = 0;
5158
Matt2f2f4252005-04-13 14:45:30 +02005159 return 0;
5160}
5161
Matt Porterf3302a52006-07-31 12:49:34 +02005162static int patch_stac9205(struct hda_codec *codec)
5163{
5164 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005165 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005166
5167 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5168 if (spec == NULL)
5169 return -ENOMEM;
5170
5171 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005172 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005173 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005174 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5175 stac9205_models,
5176 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005177 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02005178 if (spec->board_config < 0) {
5179 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
5180 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005181 } else
5182 err = stac_save_pin_cfgs(codec,
5183 stac9205_brd_tbl[spec->board_config]);
5184 if (err < 0) {
5185 stac92xx_free(codec);
5186 return err;
Matt Porterf3302a52006-07-31 12:49:34 +02005187 }
5188
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005189 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005190 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005191 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005192 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005193 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005194 spec->smux_nids = stac9205_smux_nids;
5195 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005196 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005197 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005198 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005199 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005200 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005201
5202 spec->init = stac9205_core_init;
5203 spec->mixer = stac9205_mixer;
5204
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005205 spec->aloopback_mask = 0x40;
5206 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005207 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005208 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005209
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005210 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005211 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005212 /* Enable SPDIF in/out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005213 stac_change_pin_config(codec, 0x1f, 0x01441030);
5214 stac_change_pin_config(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005215
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005216 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005217 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5218 if (err < 0)
5219 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005220 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005221 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5222 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005223 AC_VERB_SET_UNSOLICITED_ENABLE,
5224 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005225
5226 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005227 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005228 spec->gpio_mask = 0x1b;
5229 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005230 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005231 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005232 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005233 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005234 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005235 case STAC_9205_REF:
5236 /* SPDIF-In enabled */
5237 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005238 default:
5239 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005240 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005241 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005242 break;
5243 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005244
Matt Porterf3302a52006-07-31 12:49:34 +02005245 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005246 if (!err) {
5247 if (spec->board_config < 0) {
5248 printk(KERN_WARNING "hda_codec: No auto-config is "
5249 "available, default to model=ref\n");
5250 spec->board_config = STAC_9205_REF;
5251 goto again;
5252 }
5253 err = -EINVAL;
5254 }
Matt Porterf3302a52006-07-31 12:49:34 +02005255 if (err < 0) {
5256 stac92xx_free(codec);
5257 return err;
5258 }
5259
5260 codec->patch_ops = stac92xx_patch_ops;
5261
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005262 codec->proc_widget_hook = stac9205_proc_hook;
5263
Matt Porterf3302a52006-07-31 12:49:34 +02005264 return 0;
5265}
5266
Matt2f2f4252005-04-13 14:45:30 +02005267/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005268 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005269 */
5270
Guillaume Munch99ccc562006-08-16 19:35:12 +02005271/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005272static hda_nid_t vaio_dacs[] = { 0x2 };
5273#define VAIO_HP_DAC 0x5
5274static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
5275static hda_nid_t vaio_mux_nids[] = { 0x15 };
5276
5277static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02005278 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01005279 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02005280 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005281 { "Mic Jack", 0x1 },
5282 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01005283 { "PCM", 0x3 },
5284 }
5285};
5286
5287static struct hda_verb vaio_init[] = {
5288 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005289 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01005290 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5291 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5292 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5293 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005294 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005295 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5296 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5297 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5298 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5299 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5300 {}
5301};
5302
Guillaume Munch6d859062006-08-22 17:15:47 +02005303static struct hda_verb vaio_ar_init[] = {
5304 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5305 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5306 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5307 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5308/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
5309 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005310 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02005311 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5312 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5313/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
5314 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5315 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5316 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5317 {}
5318};
5319
Takashi Iwaidb064e52006-03-16 16:04:58 +01005320static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwai127e82e2008-11-14 14:03:33 +01005321 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5322 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5323 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5324 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
Takashi Iwaidb064e52006-03-16 16:04:58 +01005325 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5326 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5327 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5328 {
5329 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5330 .name = "Capture Source",
5331 .count = 1,
5332 .info = stac92xx_mux_enum_info,
5333 .get = stac92xx_mux_enum_get,
5334 .put = stac92xx_mux_enum_put,
5335 },
5336 {}
5337};
5338
Guillaume Munch6d859062006-08-22 17:15:47 +02005339static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwai127e82e2008-11-14 14:03:33 +01005340 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5341 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5342 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5343 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
Guillaume Munch6d859062006-08-22 17:15:47 +02005344 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5345 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5346 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5347 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
5348 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
5349 {
5350 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5351 .name = "Capture Source",
5352 .count = 1,
5353 .info = stac92xx_mux_enum_info,
5354 .get = stac92xx_mux_enum_get,
5355 .put = stac92xx_mux_enum_put,
5356 },
5357 {}
5358};
5359
5360static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01005361 .build_controls = stac92xx_build_controls,
5362 .build_pcms = stac92xx_build_pcms,
5363 .init = stac92xx_init,
5364 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02005365#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01005366 .resume = stac92xx_resume,
5367#endif
5368};
5369
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005370static int stac9872_vaio_init(struct hda_codec *codec)
5371{
5372 int err;
5373
5374 err = stac92xx_init(codec);
5375 if (err < 0)
5376 return err;
5377 if (codec->patch_ops.unsol_event)
5378 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
5379 return 0;
5380}
5381
5382static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
5383{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01005384 if (get_pin_presence(codec, 0x0a)) {
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005385 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5386 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5387 } else {
5388 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5389 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5390 }
5391}
5392
5393static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
5394{
5395 switch (res >> 26) {
5396 case STAC_HP_EVENT:
5397 stac9872_vaio_hp_detect(codec, res);
5398 break;
5399 }
5400}
5401
5402static struct hda_codec_ops stac9872_vaio_patch_ops = {
5403 .build_controls = stac92xx_build_controls,
5404 .build_pcms = stac92xx_build_pcms,
5405 .init = stac9872_vaio_init,
5406 .free = stac92xx_free,
5407 .unsol_event = stac9872_vaio_unsol_event,
5408#ifdef CONFIG_PM
5409 .resume = stac92xx_resume,
5410#endif
5411};
5412
Guillaume Munch6d859062006-08-22 17:15:47 +02005413enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
5414 CXD9872RD_VAIO,
5415 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
5416 STAC9872AK_VAIO,
5417 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
5418 STAC9872K_VAIO,
5419 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005420 CXD9872AKD_VAIO,
5421 STAC_9872_MODELS,
5422};
Takashi Iwaidb064e52006-03-16 16:04:58 +01005423
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005424static const char *stac9872_models[STAC_9872_MODELS] = {
5425 [CXD9872RD_VAIO] = "vaio",
5426 [CXD9872AKD_VAIO] = "vaio-ar",
5427};
5428
5429static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5430 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
5431 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
5432 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01005433 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01005434 {}
5435};
5436
Guillaume Munch6d859062006-08-22 17:15:47 +02005437static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005438{
5439 struct sigmatel_spec *spec;
5440 int board_config;
5441
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005442 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5443 stac9872_models,
5444 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01005445 if (board_config < 0)
5446 /* unknown config, let generic-parser do its job... */
5447 return snd_hda_parse_generic_codec(codec);
5448
5449 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5450 if (spec == NULL)
5451 return -ENOMEM;
5452
5453 codec->spec = spec;
5454 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02005455 case CXD9872RD_VAIO:
5456 case STAC9872AK_VAIO:
5457 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01005458 spec->mixer = vaio_mixer;
5459 spec->init = vaio_init;
5460 spec->multiout.max_channels = 2;
5461 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5462 spec->multiout.dac_nids = vaio_dacs;
5463 spec->multiout.hp_nid = VAIO_HP_DAC;
5464 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5465 spec->adc_nids = vaio_adcs;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005466 spec->num_pwrs = 0;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005467 spec->input_mux = &vaio_mux;
5468 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005469 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005470 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02005471
5472 case CXD9872AKD_VAIO:
5473 spec->mixer = vaio_ar_mixer;
5474 spec->init = vaio_ar_init;
5475 spec->multiout.max_channels = 2;
5476 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5477 spec->multiout.dac_nids = vaio_dacs;
5478 spec->multiout.hp_nid = VAIO_HP_DAC;
5479 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005480 spec->num_pwrs = 0;
Guillaume Munch6d859062006-08-22 17:15:47 +02005481 spec->adc_nids = vaio_adcs;
5482 spec->input_mux = &vaio_mux;
5483 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005484 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02005485 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005486 }
5487
Takashi Iwaidb064e52006-03-16 16:04:58 +01005488 return 0;
5489}
5490
5491
5492/*
Matt2f2f4252005-04-13 14:45:30 +02005493 * patch entries
5494 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005495static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02005496 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5497 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5498 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5499 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5500 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5501 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5502 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005503 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5504 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5505 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5506 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5507 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5508 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005509 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5510 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5511 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5512 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5513 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5514 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5515 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5516 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5517 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5518 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005519 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5520 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5521 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5522 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5523 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5524 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005525 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5526 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005527 /* The following does not take into account .id=0x83847661 when subsys =
5528 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5529 * currently not fully supported.
5530 */
5531 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5532 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5533 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02005534 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5535 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5536 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5537 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5538 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5539 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5540 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5541 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005542 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005543 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5544 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005545 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005546 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5547 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005548 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005549 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5550 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5551 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5552 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5553 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5554 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5555 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5556 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005557 {} /* terminator */
5558};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005559
5560MODULE_ALIAS("snd-hda-codec-id:8384*");
5561MODULE_ALIAS("snd-hda-codec-id:111d*");
5562
5563MODULE_LICENSE("GPL");
5564MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5565
5566static struct hda_codec_preset_list sigmatel_list = {
5567 .preset = snd_hda_preset_sigmatel,
5568 .owner = THIS_MODULE,
5569};
5570
5571static int __init patch_sigmatel_init(void)
5572{
5573 return snd_hda_add_codec_preset(&sigmatel_list);
5574}
5575
5576static void __exit patch_sigmatel_exit(void)
5577{
5578 snd_hda_delete_codec_preset(&sigmatel_list);
5579}
5580
5581module_init(patch_sigmatel_init)
5582module_exit(patch_sigmatel_exit)