blob: 4b7dda57c0e9302c73f0d860719376dd141cd34c [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"
Harvey Harrison3c9a3202008-02-29 11:59:26 +010036#include "hda_patch.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020037#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020038
Takashi Iwaic6e4c662008-11-25 11:58:19 +010039enum {
40 STAC_VREF_EVENT = 1,
41 STAC_INSERT_EVENT,
42 STAC_PWR_EVENT,
43 STAC_HP_EVENT,
44};
Matt4e550962005-07-04 17:51:39 +020045
Takashi Iwaif5fcc132006-11-24 17:07:44 +010046enum {
47 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010048 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020049 STAC_9200_DELL_D21,
50 STAC_9200_DELL_D22,
51 STAC_9200_DELL_D23,
52 STAC_9200_DELL_M21,
53 STAC_9200_DELL_M22,
54 STAC_9200_DELL_M23,
55 STAC_9200_DELL_M24,
56 STAC_9200_DELL_M25,
57 STAC_9200_DELL_M26,
58 STAC_9200_DELL_M27,
Takashi Iwai1194b5b2007-10-10 10:04:26 +020059 STAC_9200_GATEWAY,
Takashi Iwai117f2572008-03-18 09:53:23 +010060 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010061 STAC_9200_MODELS
62};
63
64enum {
65 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020066 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020067 STAC_9205_DELL_M43,
68 STAC_9205_DELL_M44,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010069 STAC_9205_MODELS
70};
71
72enum {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010073 STAC_92HD73XX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010074 STAC_DELL_M6,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050075 STAC_DELL_EQ,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010076 STAC_92HD73XX_MODELS
77};
78
79enum {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020080 STAC_92HD83XXX_REF,
81 STAC_92HD83XXX_MODELS
82};
83
84enum {
Matthew Ranostaye035b842007-11-06 11:53:55 +010085 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010086 STAC_DELL_M4_1,
87 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -050088 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -040089 STAC_HP_M4,
Matthew Ranostaye035b842007-11-06 11:53:55 +010090 STAC_92HD71BXX_MODELS
91};
92
93enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010094 STAC_925x_REF,
95 STAC_M2_2,
96 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020097 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +010098 STAC_925x_MODELS
99};
100
101enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100102 STAC_D945_REF,
103 STAC_D945GTP3,
104 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200105 STAC_INTEL_MAC_V1,
106 STAC_INTEL_MAC_V2,
107 STAC_INTEL_MAC_V3,
108 STAC_INTEL_MAC_V4,
109 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800110 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
111 * is given, one of the above models will be
112 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200113 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100114 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100115 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100116 STAC_MACBOOK_PRO_V1,
117 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200118 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200119 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300120 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200121 STAC_922X_DELL_D81,
122 STAC_922X_DELL_D82,
123 STAC_922X_DELL_M81,
124 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100125 STAC_922X_MODELS
126};
127
128enum {
129 STAC_D965_REF,
130 STAC_D965_3ST,
131 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200132 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100133 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100134 STAC_927X_MODELS
135};
Matt Porter403d1942005-11-29 15:00:51 +0100136
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400137struct sigmatel_event {
138 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100139 unsigned char type;
140 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400141 int data;
142};
143
144struct sigmatel_jack {
145 hda_nid_t nid;
146 int type;
147 struct snd_jack *jack;
148};
149
Matt2f2f4252005-04-13 14:45:30 +0200150struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100151 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200152 unsigned int num_mixers;
153
Matt Porter403d1942005-11-29 15:00:51 +0100154 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500155 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200156 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +0100157 unsigned int line_switch: 1;
158 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100159 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100160 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400161 unsigned int spdif_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200162
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100163 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200164 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100165 unsigned int gpio_mask;
166 unsigned int gpio_dir;
167 unsigned int gpio_data;
168 unsigned int gpio_mute;
169
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200170 /* stream */
171 unsigned int stream_delay;
172
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100173 /* analog loopback */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100174 unsigned char aloopback_mask;
175 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200176
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100177 /* power management */
178 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200179 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100180 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100181 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100182
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400183 /* jack detection */
184 struct snd_array jacks;
185
186 /* events */
187 struct snd_array events;
188
Matt2f2f4252005-04-13 14:45:30 +0200189 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100190 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400191 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100192 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200193 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100194 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200195
196 /* capture */
197 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200198 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200199 hda_nid_t *mux_nids;
200 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200201 hda_nid_t *dmic_nids;
202 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100203 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100204 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200205 hda_nid_t *smux_nids;
206 unsigned int num_smuxes;
Matthew Ranostay65973632008-09-16 10:39:37 -0400207 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200208
Mattdabbed62005-06-14 10:19:34 +0200209 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100210 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200211 hda_nid_t anabeep_nid;
212 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200213
Matt2f2f4252005-04-13 14:45:30 +0200214 /* pin widgets */
215 hda_nid_t *pin_nids;
216 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200217 unsigned int *pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200218
219 /* codec specific stuff */
220 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100221 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200222
223 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200224 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100225 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200226 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100227 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200228 struct hda_input_mux *sinput_mux;
229 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400230 unsigned int cur_amux;
231 hda_nid_t *amp_nids;
232 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200233 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200234
Matt Porter403d1942005-11-29 15:00:51 +0100235 /* i/o switches */
236 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200237 unsigned int clfe_swap;
Takashi Iwaid7a89432008-11-12 09:48:04 +0100238 unsigned int hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200239 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200240
Mattc7d4b2f2005-06-27 14:59:41 +0200241 struct hda_pcm pcm_rec[2]; /* PCM information */
242
243 /* dynamic controls and input_mux */
244 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200245 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200246 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200247 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200248 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400249 struct hda_input_mux private_amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100250 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200251};
252
253static hda_nid_t stac9200_adc_nids[1] = {
254 0x03,
255};
256
257static hda_nid_t stac9200_mux_nids[1] = {
258 0x0c,
259};
260
261static hda_nid_t stac9200_dac_nids[1] = {
262 0x02,
263};
264
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100265static hda_nid_t stac92hd73xx_pwr_nids[8] = {
266 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
267 0x0f, 0x10, 0x11
268};
269
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400270static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
271 0x26, 0,
272};
273
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100274static hda_nid_t stac92hd73xx_adc_nids[2] = {
275 0x1a, 0x1b
276};
277
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400278#define DELL_M6_AMP 2
279static hda_nid_t stac92hd73xx_amp_nids[3] = {
280 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400281};
282
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100283#define STAC92HD73XX_NUM_DMICS 2
284static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
285 0x13, 0x14, 0
286};
287
288#define STAC92HD73_DAC_COUNT 5
289static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
290 0x15, 0x16, 0x17, 0x18, 0x19,
291};
292
293static hda_nid_t stac92hd73xx_mux_nids[4] = {
294 0x28, 0x29, 0x2a, 0x2b,
295};
296
297static hda_nid_t stac92hd73xx_dmux_nids[2] = {
298 0x20, 0x21,
299};
300
Matthew Ranostayd9737752008-09-07 12:03:41 +0200301static hda_nid_t stac92hd73xx_smux_nids[2] = {
302 0x22, 0x23,
303};
304
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200305#define STAC92HD83XXX_NUM_DMICS 2
306static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
307 0x11, 0x12, 0
308};
309
310#define STAC92HD81_DAC_COUNT 2
311#define STAC92HD83_DAC_COUNT 3
312static hda_nid_t stac92hd83xxx_dac_nids[STAC92HD73_DAC_COUNT] = {
313 0x13, 0x14, 0x22,
314};
315
316static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
317 0x17, 0x18,
318};
319
320static hda_nid_t stac92hd83xxx_adc_nids[2] = {
321 0x15, 0x16,
322};
323
324static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
325 0xa, 0xb, 0xd, 0xe,
326};
327
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400328static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
329 0x1e, 0,
330};
331
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200332static unsigned int stac92hd83xxx_pwr_mapping[4] = {
333 0x03, 0x0c, 0x10, 0x40,
334};
335
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100336static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
337 0x0a, 0x0d, 0x0f
338};
339
Matthew Ranostaye035b842007-11-06 11:53:55 +0100340static hda_nid_t stac92hd71bxx_adc_nids[2] = {
341 0x12, 0x13,
342};
343
344static hda_nid_t stac92hd71bxx_mux_nids[2] = {
345 0x1a, 0x1b
346};
347
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400348static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
349 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100350};
351
Matthew Ranostayd9737752008-09-07 12:03:41 +0200352static hda_nid_t stac92hd71bxx_smux_nids[2] = {
353 0x24, 0x25,
354};
355
Takashi Iwaiaea7bb02008-02-25 18:26:41 +0100356static hda_nid_t stac92hd71bxx_dac_nids[1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100357 0x10, /*0x11, */
358};
359
360#define STAC92HD71BXX_NUM_DMICS 2
361static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
362 0x18, 0x19, 0
363};
364
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400365static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
366 0x22, 0
367};
368
Tobin Davis8e21c342007-01-08 11:04:17 +0100369static hda_nid_t stac925x_adc_nids[1] = {
370 0x03,
371};
372
373static hda_nid_t stac925x_mux_nids[1] = {
374 0x0f,
375};
376
377static hda_nid_t stac925x_dac_nids[1] = {
378 0x02,
379};
380
Takashi Iwaif6e98522007-10-16 14:27:04 +0200381#define STAC925X_NUM_DMICS 1
382static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
383 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200384};
385
Takashi Iwai1697055e2007-12-18 18:05:52 +0100386static hda_nid_t stac925x_dmux_nids[1] = {
387 0x14,
388};
389
Matt2f2f4252005-04-13 14:45:30 +0200390static hda_nid_t stac922x_adc_nids[2] = {
391 0x06, 0x07,
392};
393
394static hda_nid_t stac922x_mux_nids[2] = {
395 0x12, 0x13,
396};
397
Matt Porter3cc08dc2006-01-23 15:27:49 +0100398static hda_nid_t stac927x_adc_nids[3] = {
399 0x07, 0x08, 0x09
400};
401
402static hda_nid_t stac927x_mux_nids[3] = {
403 0x15, 0x16, 0x17
404};
405
Matthew Ranostayd9737752008-09-07 12:03:41 +0200406static hda_nid_t stac927x_smux_nids[1] = {
407 0x21,
408};
409
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100410static hda_nid_t stac927x_dac_nids[6] = {
411 0x02, 0x03, 0x04, 0x05, 0x06, 0
412};
413
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100414static hda_nid_t stac927x_dmux_nids[1] = {
415 0x1b,
416};
417
Matthew Ranostay7f168592007-10-18 17:38:17 +0200418#define STAC927X_NUM_DMICS 2
419static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
420 0x13, 0x14, 0
421};
422
Matthew Ranostay65973632008-09-16 10:39:37 -0400423static const char *stac927x_spdif_labels[5] = {
424 "Digital Playback", "ADAT", "Analog Mux 1",
425 "Analog Mux 2", "Analog Mux 3"
426};
427
Matt Porterf3302a52006-07-31 12:49:34 +0200428static hda_nid_t stac9205_adc_nids[2] = {
429 0x12, 0x13
430};
431
432static hda_nid_t stac9205_mux_nids[2] = {
433 0x19, 0x1a
434};
435
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100436static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100437 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100438};
439
Matthew Ranostayd9737752008-09-07 12:03:41 +0200440static hda_nid_t stac9205_smux_nids[1] = {
441 0x21,
442};
443
Takashi Iwaif6e98522007-10-16 14:27:04 +0200444#define STAC9205_NUM_DMICS 2
445static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
446 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200447};
448
Mattc7d4b2f2005-06-27 14:59:41 +0200449static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200450 0x08, 0x09, 0x0d, 0x0e,
451 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200452};
453
Tobin Davis8e21c342007-01-08 11:04:17 +0100454static hda_nid_t stac925x_pin_nids[8] = {
455 0x07, 0x08, 0x0a, 0x0b,
456 0x0c, 0x0d, 0x10, 0x11,
457};
458
Matt2f2f4252005-04-13 14:45:30 +0200459static hda_nid_t stac922x_pin_nids[10] = {
460 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
461 0x0f, 0x10, 0x11, 0x15, 0x1b,
462};
463
Matthew Ranostaya7662642008-02-21 07:51:14 +0100464static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100465 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
466 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200467 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100468};
469
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200470static hda_nid_t stac92hd83xxx_pin_nids[14] = {
471 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
472 0x0f, 0x10, 0x11, 0x12, 0x13,
473 0x1d, 0x1e, 0x1f, 0x20
474};
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400475static hda_nid_t stac92hd71bxx_pin_nids[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100476 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
477 0x0f, 0x14, 0x18, 0x19, 0x1e,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400478 0x1f,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100479};
480
Matt Porter3cc08dc2006-01-23 15:27:49 +0100481static hda_nid_t stac927x_pin_nids[14] = {
482 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
483 0x0f, 0x10, 0x11, 0x12, 0x13,
484 0x14, 0x21, 0x22, 0x23,
485};
486
Matt Porterf3302a52006-07-31 12:49:34 +0200487static hda_nid_t stac9205_pin_nids[12] = {
488 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
489 0x0f, 0x14, 0x16, 0x17, 0x18,
490 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200491};
492
Matthew Ranostay89385032008-09-11 09:49:39 -0400493#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
494
495static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
496 struct snd_ctl_elem_value *ucontrol)
497{
498 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
499 struct sigmatel_spec *spec = codec->spec;
500 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
501
502 kcontrol->private_value ^= get_amp_nid(kcontrol);
503 kcontrol->private_value |= nid;
504
505 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
506}
507
508static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
509 struct snd_ctl_elem_value *ucontrol)
510{
511 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
512 struct sigmatel_spec *spec = codec->spec;
513 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
514
515 kcontrol->private_value ^= get_amp_nid(kcontrol);
516 kcontrol->private_value |= nid;
517
518 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
519}
520
Matt Porter8b657272006-10-26 17:12:59 +0200521static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
522 struct snd_ctl_elem_info *uinfo)
523{
524 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
525 struct sigmatel_spec *spec = codec->spec;
526 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
527}
528
529static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
530 struct snd_ctl_elem_value *ucontrol)
531{
532 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
533 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100534 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200535
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100536 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200537 return 0;
538}
539
540static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
541 struct snd_ctl_elem_value *ucontrol)
542{
543 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
544 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100545 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200546
547 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100548 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200549}
550
Matthew Ranostayd9737752008-09-07 12:03:41 +0200551static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
552 struct snd_ctl_elem_info *uinfo)
553{
554 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
555 struct sigmatel_spec *spec = codec->spec;
556 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
557}
558
559static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
560 struct snd_ctl_elem_value *ucontrol)
561{
562 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
563 struct sigmatel_spec *spec = codec->spec;
564 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
565
566 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
567 return 0;
568}
569
570static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
571 struct snd_ctl_elem_value *ucontrol)
572{
573 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
574 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400575 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200576 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400577 int err, val;
578 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200579
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400580 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200581 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400582 if (err < 0)
583 return err;
584
585 if (spec->spdif_mute) {
586 if (smux_idx == 0)
587 nid = spec->multiout.dig_out_nid;
588 else
589 nid = codec->slave_dig_outs[smux_idx - 1];
590 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
591 val = AMP_OUT_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400592 else
Takashi Iwaic1e99bd2008-10-29 08:03:42 +0100593 val = AMP_OUT_UNMUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400594 /* un/mute SPDIF out */
595 snd_hda_codec_write_cache(codec, nid, 0,
596 AC_VERB_SET_AMP_GAIN_MUTE, val);
597 }
598 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200599}
600
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100601static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200602{
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200605 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200606}
607
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100608static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200609{
610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
611 struct sigmatel_spec *spec = codec->spec;
612 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
613
614 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
615 return 0;
616}
617
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100618static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200619{
620 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
621 struct sigmatel_spec *spec = codec->spec;
622 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
623
Mattc7d4b2f2005-06-27 14:59:41 +0200624 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200625 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
626}
627
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100628static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
629 struct snd_ctl_elem_info *uinfo)
630{
631 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
632 struct sigmatel_spec *spec = codec->spec;
633 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
634}
635
636static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
637 struct snd_ctl_elem_value *ucontrol)
638{
639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
640 struct sigmatel_spec *spec = codec->spec;
641
642 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
643 return 0;
644}
645
646static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
647 struct snd_ctl_elem_value *ucontrol)
648{
649 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
650 struct sigmatel_spec *spec = codec->spec;
651
652 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
653 spec->mono_nid, &spec->cur_mmux);
654}
655
Matthew Ranostay89385032008-09-11 09:49:39 -0400656static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
657 struct snd_ctl_elem_info *uinfo)
658{
659 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660 struct sigmatel_spec *spec = codec->spec;
661 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
662}
663
664static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
665 struct snd_ctl_elem_value *ucontrol)
666{
667 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
668 struct sigmatel_spec *spec = codec->spec;
669
670 ucontrol->value.enumerated.item[0] = spec->cur_amux;
671 return 0;
672}
673
674static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
675 struct snd_ctl_elem_value *ucontrol)
676{
677 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
678 struct sigmatel_spec *spec = codec->spec;
679 struct snd_kcontrol *ctl =
680 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
681 if (!ctl)
682 return -EINVAL;
683
684 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
685 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
686
687 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
688 0, &spec->cur_amux);
689}
690
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200691#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
692
693static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
694 struct snd_ctl_elem_value *ucontrol)
695{
696 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100697 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200698 struct sigmatel_spec *spec = codec->spec;
699
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100700 ucontrol->value.integer.value[0] = !!(spec->aloopback &
701 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200702 return 0;
703}
704
705static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
706 struct snd_ctl_elem_value *ucontrol)
707{
708 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
709 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100710 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200711 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100712 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200713
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100714 idx_val = spec->aloopback_mask << idx;
715 if (ucontrol->value.integer.value[0])
716 val = spec->aloopback | idx_val;
717 else
718 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100719 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200720 return 0;
721
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100722 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200723
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100724 /* Only return the bits defined by the shift value of the
725 * first two bytes of the mask
726 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200727 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100728 kcontrol->private_value & 0xFFFF, 0x0);
729 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200730
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100731 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200732 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100733 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200734 } else {
735 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100736 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200737 }
738
739 snd_hda_codec_write_cache(codec, codec->afg, 0,
740 kcontrol->private_value >> 16, dac_mode);
741
742 return 1;
743}
744
Mattc7d4b2f2005-06-27 14:59:41 +0200745static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200746 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200747 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200748 {}
749};
750
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200751static struct hda_verb stac9200_eapd_init[] = {
752 /* set dac0mux for dac converter */
753 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
754 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
755 {}
756};
757
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100758static struct hda_verb stac92hd73xx_6ch_core_init[] = {
759 /* set master volume and direct control */
760 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
761 /* setup audio connections */
762 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
763 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
764 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
765 /* setup adcs to point to mixer */
766 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
767 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100768 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
769 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
770 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
771 /* setup import muxs */
772 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
773 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
774 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
775 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
776 {}
777};
778
Matthew Ranostayd654a662008-03-14 08:46:51 +0100779static struct hda_verb dell_eq_core_init[] = {
780 /* set master volume to max value without distortion
781 * and direct control */
782 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
783 /* setup audio connections */
784 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
Matthew Ranostayf7cf0a72008-09-13 10:36:58 -0400785 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x02},
786 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100787 /* setup adcs to point to mixer */
788 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
789 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
790 /* setup import muxs */
791 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
792 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
793 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
794 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
795 {}
796};
797
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100798static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500799 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100800 /* setup audio connections */
Matthew Ranostay7747ecc2008-03-10 11:30:04 +0100801 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
802 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100803 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
804 /* setup adcs to point to mixer */
805 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
806 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
807 /* setup import muxs */
808 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
809 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
810 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
811 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
812 {}
813};
814
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100815static struct hda_verb stac92hd73xx_8ch_core_init[] = {
816 /* set master volume and direct control */
817 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
818 /* setup audio connections */
819 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
820 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
821 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
822 /* connect hp ports to dac3 */
823 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
824 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
825 /* setup adcs to point to mixer */
826 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
827 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100828 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
829 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
830 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
831 /* setup import muxs */
832 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
833 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
834 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
835 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
836 {}
837};
838
839static struct hda_verb stac92hd73xx_10ch_core_init[] = {
840 /* set master volume and direct control */
841 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
842 /* setup audio connections */
843 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
844 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
845 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
846 /* dac3 is connected to import3 mux */
847 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
848 /* connect hp ports to dac4 */
849 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
850 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
851 /* setup adcs to point to mixer */
852 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
853 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100854 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
855 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
856 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
857 /* setup import muxs */
858 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
859 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
860 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
861 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
862 {}
863};
864
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200865static struct hda_verb stac92hd83xxx_core_init[] = {
866 /* start of config #1 */
867 { 0xe, AC_VERB_SET_CONNECT_SEL, 0x3},
868
869 /* start of config #2 */
870 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0},
871 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0},
872 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1},
873
874 /* power state controls amps */
875 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
876};
877
Matthew Ranostaye035b842007-11-06 11:53:55 +0100878static struct hda_verb stac92hd71bxx_core_init[] = {
879 /* set master volume and direct control */
880 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
881 /* connect headphone jack to dac1 */
882 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100883 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
884 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
885 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
886 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100887};
888
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400889#define HD_DISABLE_PORTF 2
Matthew Ranostay541eee82007-12-14 12:08:04 +0100890static struct hda_verb stac92hd71bxx_analog_core_init[] = {
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200891 /* start of config #1 */
892
893 /* connect port 0f to audio mixer */
894 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200895 /* unmute right and left channels for node 0x0f */
896 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
897 /* start of config #2 */
898
Matthew Ranostay541eee82007-12-14 12:08:04 +0100899 /* set master volume and direct control */
900 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
901 /* connect headphone jack to dac1 */
902 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200903 /* unmute right and left channels for nodes 0x0a, 0xd */
Matthew Ranostaye035b842007-11-06 11:53:55 +0100904 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
905 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100906 {}
907};
908
Tobin Davis8e21c342007-01-08 11:04:17 +0100909static struct hda_verb stac925x_core_init[] = {
910 /* set dac0mux for dac converter */
911 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
912 {}
913};
914
Mattc7d4b2f2005-06-27 14:59:41 +0200915static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200916 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200917 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200918 {}
919};
920
Tobin Davis93ed1502006-09-01 21:03:12 +0200921static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200922 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200923 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200924 /* unmute node 0x1b */
925 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
926 /* select node 0x03 as DAC */
927 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
928 {}
929};
930
Matt Porter3cc08dc2006-01-23 15:27:49 +0100931static struct hda_verb stac927x_core_init[] = {
932 /* set master volume and direct control */
933 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200934 /* enable analog pc beep path */
935 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100936 {}
937};
938
Matt Porterf3302a52006-07-31 12:49:34 +0200939static struct hda_verb stac9205_core_init[] = {
940 /* set master volume and direct control */
941 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200942 /* enable analog pc beep path */
943 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200944 {}
945};
946
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100947#define STAC_MONO_MUX \
948 { \
949 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
950 .name = "Mono Mux", \
951 .count = 1, \
952 .info = stac92xx_mono_mux_enum_info, \
953 .get = stac92xx_mono_mux_enum_get, \
954 .put = stac92xx_mono_mux_enum_put, \
955 }
956
Matthew Ranostay89385032008-09-11 09:49:39 -0400957#define STAC_AMP_MUX \
958 { \
959 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
960 .name = "Amp Selector Capture Switch", \
961 .count = 1, \
962 .info = stac92xx_amp_mux_enum_info, \
963 .get = stac92xx_amp_mux_enum_get, \
964 .put = stac92xx_amp_mux_enum_put, \
965 }
966
967#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
968 { \
969 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
970 .name = xname, \
971 .index = 0, \
972 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
973 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
974 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
975 .info = stac92xx_amp_volume_info, \
976 .get = stac92xx_amp_volume_get, \
977 .put = stac92xx_amp_volume_put, \
978 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
979 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
980 }
981
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200982#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200983 { \
984 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
985 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200986 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200987 .info = stac92xx_mux_enum_info, \
988 .get = stac92xx_mux_enum_get, \
989 .put = stac92xx_mux_enum_put, \
990 }
991
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100992#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200993 { \
994 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
995 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100996 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200997 .info = stac92xx_aloopback_info, \
998 .get = stac92xx_aloopback_get, \
999 .put = stac92xx_aloopback_put, \
1000 .private_value = verb_read | (verb_write << 16), \
1001 }
1002
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001003static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +02001004 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1005 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001006 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +02001007 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1008 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001009 { } /* end */
1010};
1011
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001012#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001013static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001014 /* start of config #1 */
1015 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1016 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1017
1018 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1019 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1020
1021 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1022 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1023
1024 /* start of config #2 */
1025 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1026 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1027
1028 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1029 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1030
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001031 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1032
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001033 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1034 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1035
1036 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1037 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1038
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001039 { } /* end */
1040};
1041
1042static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001043 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1044
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001045 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1046 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1047
1048 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1049 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1050
1051 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1052 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1053
1054 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1055 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1056
1057 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1058 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1059
1060 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1061 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1062
1063 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1064 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1065 { } /* end */
1066};
1067
1068static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001069 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1070
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001071 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1072 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1073
1074 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1075 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1076
1077 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1078 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1079
1080 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1081 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1082
1083 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1084 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1085
1086 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1087 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1088
1089 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1090 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1091 { } /* end */
1092};
1093
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001094
1095static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1096 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1097 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1098
1099 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1100 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1101
1102 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0, HDA_INPUT),
1103 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0, HDA_INPUT),
1104
1105 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x1, HDA_INPUT),
1106 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x1, HDA_INPUT),
1107
1108 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x2, HDA_INPUT),
1109 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x2, HDA_INPUT),
1110
1111 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x3, HDA_INPUT),
1112 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x3, HDA_INPUT),
1113
1114 /*
1115 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x4, HDA_INPUT),
1116 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x4, HDA_INPUT),
1117 */
1118 { } /* end */
1119};
1120
Matthew Ranostay541eee82007-12-14 12:08:04 +01001121static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001122 STAC_INPUT_SOURCE(2),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001123 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001124
Matthew Ranostay9b359472007-11-07 13:03:12 +01001125 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1126 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay9b359472007-11-07 13:03:12 +01001127
1128 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1129 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001130 /* analog pc-beep replaced with digital beep support */
1131 /*
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001132 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1133 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001134 */
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001135
Matthew Ranostay687cb982008-10-11 13:52:43 -04001136 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1137 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001138
Matthew Ranostay687cb982008-10-11 13:52:43 -04001139 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1140 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001141
1142 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1143 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1144
1145 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1146 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001147 { } /* end */
1148};
1149
Matthew Ranostay541eee82007-12-14 12:08:04 +01001150static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +01001151 STAC_INPUT_SOURCE(2),
1152 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1153
Matthew Ranostay541eee82007-12-14 12:08:04 +01001154 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1155 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001156
1157 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1158 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001159 { } /* end */
1160};
1161
Tobin Davis8e21c342007-01-08 11:04:17 +01001162static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001163 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +01001164 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
Mauro Carvalho Chehab587755f2008-05-25 18:20:06 +02001165 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
Tobin Davis8e21c342007-01-08 11:04:17 +01001166 { } /* end */
1167};
1168
Takashi Iwaid1d985f2006-11-23 19:27:12 +01001169static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001170 STAC_INPUT_SOURCE(2),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001171 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001172
1173 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1174 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001175
1176 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1177 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001178 { } /* end */
1179};
1180
1181/* This needs to be generated dynamically based on sequence */
1182static struct snd_kcontrol_new stac922x_mixer[] = {
1183 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001184 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1185 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001186
1187 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1188 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001189 { } /* end */
1190};
1191
1192
1193static struct snd_kcontrol_new stac927x_mixer[] = {
1194 STAC_INPUT_SOURCE(3),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001195 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001196
1197 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1198 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001199
1200 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1201 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001202
1203 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1204 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +02001205 { } /* end */
1206};
1207
Takashi Iwai1697055e2007-12-18 18:05:52 +01001208static struct snd_kcontrol_new stac_dmux_mixer = {
1209 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1210 .name = "Digital Input Source",
1211 /* count set later */
1212 .info = stac92xx_dmux_enum_info,
1213 .get = stac92xx_dmux_enum_get,
1214 .put = stac92xx_dmux_enum_put,
1215};
1216
Matthew Ranostayd9737752008-09-07 12:03:41 +02001217static struct snd_kcontrol_new stac_smux_mixer = {
1218 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001219 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001220 /* count set later */
1221 .info = stac92xx_smux_enum_info,
1222 .get = stac92xx_smux_enum_get,
1223 .put = stac92xx_smux_enum_put,
1224};
1225
Takashi Iwai2134ea42008-01-10 16:53:55 +01001226static const char *slave_vols[] = {
1227 "Front Playback Volume",
1228 "Surround Playback Volume",
1229 "Center Playback Volume",
1230 "LFE Playback Volume",
1231 "Side Playback Volume",
1232 "Headphone Playback Volume",
1233 "Headphone Playback Volume",
1234 "Speaker Playback Volume",
1235 "External Speaker Playback Volume",
1236 "Speaker2 Playback Volume",
1237 NULL
1238};
1239
1240static const char *slave_sws[] = {
1241 "Front Playback Switch",
1242 "Surround Playback Switch",
1243 "Center Playback Switch",
1244 "LFE Playback Switch",
1245 "Side Playback Switch",
1246 "Headphone Playback Switch",
1247 "Headphone Playback Switch",
1248 "Speaker Playback Switch",
1249 "External Speaker Playback Switch",
1250 "Speaker2 Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001251 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001252 NULL
1253};
1254
Takashi Iwai603c4012008-07-30 15:01:44 +02001255static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001256static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001257
Matt2f2f4252005-04-13 14:45:30 +02001258static int stac92xx_build_controls(struct hda_codec *codec)
1259{
1260 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001261 struct auto_pin_cfg *cfg = &spec->autocfg;
1262 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001263 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001264 int i;
Matt2f2f4252005-04-13 14:45:30 +02001265
1266 err = snd_hda_add_new_ctls(codec, spec->mixer);
1267 if (err < 0)
1268 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001269
1270 for (i = 0; i < spec->num_mixers; i++) {
1271 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1272 if (err < 0)
1273 return err;
1274 }
Takashi Iwai1697055e2007-12-18 18:05:52 +01001275 if (spec->num_dmuxes > 0) {
1276 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001277 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001278 snd_ctl_new1(&stac_dmux_mixer, codec));
1279 if (err < 0)
1280 return err;
1281 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001282 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001283 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1284 struct hda_input_mux *smux = &spec->private_smux;
1285 /* check for mute support on SPDIF out */
1286 if (wcaps & AC_WCAP_OUT_AMP) {
1287 smux->items[smux->num_items].label = "Off";
1288 smux->items[smux->num_items].index = 0;
1289 smux->num_items++;
1290 spec->spdif_mute = 1;
1291 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001292 stac_smux_mixer.count = spec->num_smuxes;
1293 err = snd_ctl_add(codec->bus->card,
1294 snd_ctl_new1(&stac_smux_mixer, codec));
1295 if (err < 0)
1296 return err;
1297 }
Mattc7d4b2f2005-06-27 14:59:41 +02001298
Mattdabbed62005-06-14 10:19:34 +02001299 if (spec->multiout.dig_out_nid) {
1300 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1301 if (err < 0)
1302 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001303 err = snd_hda_create_spdif_share_sw(codec,
1304 &spec->multiout);
1305 if (err < 0)
1306 return err;
1307 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001308 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001309 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001310 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1311 if (err < 0)
1312 return err;
1313 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001314
1315 /* if we have no master control, let's create it */
1316 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001317 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001318 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001319 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001320 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001321 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001322 if (err < 0)
1323 return err;
1324 }
1325 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1326 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1327 NULL, slave_sws);
1328 if (err < 0)
1329 return err;
1330 }
1331
Takashi Iwai603c4012008-07-30 15:01:44 +02001332 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001333
1334 /* create jack input elements */
1335 if (spec->hp_detect) {
1336 for (i = 0; i < cfg->hp_outs; i++) {
1337 int type = SND_JACK_HEADPHONE;
1338 nid = cfg->hp_pins[i];
1339 /* jack detection */
1340 if (cfg->hp_outs == i)
1341 type |= SND_JACK_LINEOUT;
1342 err = stac92xx_add_jack(codec, nid, type);
1343 if (err < 0)
1344 return err;
1345 }
1346 }
1347 for (i = 0; i < cfg->line_outs; i++) {
1348 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1349 SND_JACK_LINEOUT);
1350 if (err < 0)
1351 return err;
1352 }
1353 for (i = 0; i < AUTO_PIN_LAST; i++) {
1354 nid = cfg->input_pins[i];
1355 if (nid) {
1356 err = stac92xx_add_jack(codec, nid,
1357 SND_JACK_MICROPHONE);
1358 if (err < 0)
1359 return err;
1360 }
1361 }
1362
Mattdabbed62005-06-14 10:19:34 +02001363 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001364}
1365
Matt Porter403d1942005-11-29 15:00:51 +01001366static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001367 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001368 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1369};
1370
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001371/*
1372 STAC 9200 pin configs for
1373 102801A8
1374 102801DE
1375 102801E8
1376*/
1377static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001378 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1379 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001380};
1381
1382/*
1383 STAC 9200 pin configs for
1384 102801C0
1385 102801C1
1386*/
1387static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001388 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1389 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001390};
1391
1392/*
1393 STAC 9200 pin configs for
1394 102801C4 (Dell Dimension E310)
1395 102801C5
1396 102801C7
1397 102801D9
1398 102801DA
1399 102801E3
1400*/
1401static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001402 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1403 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001404};
1405
1406
1407/*
1408 STAC 9200-32 pin configs for
1409 102801B5 (Dell Inspiron 630m)
1410 102801D8 (Dell Inspiron 640m)
1411*/
1412static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001413 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1414 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001415};
1416
1417/*
1418 STAC 9200-32 pin configs for
1419 102801C2 (Dell Latitude D620)
1420 102801C8
1421 102801CC (Dell Latitude D820)
1422 102801D4
1423 102801D6
1424*/
1425static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001426 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1427 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001428};
1429
1430/*
1431 STAC 9200-32 pin configs for
1432 102801CE (Dell XPS M1710)
1433 102801CF (Dell Precision M90)
1434*/
1435static unsigned int dell9200_m23_pin_configs[8] = {
1436 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1437 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1438};
1439
1440/*
1441 STAC 9200-32 pin configs for
1442 102801C9
1443 102801CA
1444 102801CB (Dell Latitude 120L)
1445 102801D3
1446*/
1447static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001448 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1449 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001450};
1451
1452/*
1453 STAC 9200-32 pin configs for
1454 102801BD (Dell Inspiron E1505n)
1455 102801EE
1456 102801EF
1457*/
1458static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001459 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1460 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001461};
1462
1463/*
1464 STAC 9200-32 pin configs for
1465 102801F5 (Dell Inspiron 1501)
1466 102801F6
1467*/
1468static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001469 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1470 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001471};
1472
1473/*
1474 STAC 9200-32
1475 102801CD (Dell Inspiron E1705/9400)
1476*/
1477static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001478 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1479 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001480};
1481
Tobin Davisbf277782008-02-03 20:31:47 +01001482static unsigned int oqo9200_pin_configs[8] = {
1483 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1484 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1485};
1486
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001487
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001488static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1489 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001490 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001491 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1492 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1493 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1494 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1495 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1496 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1497 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1498 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1499 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1500 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001501 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001502};
1503
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001504static const char *stac9200_models[STAC_9200_MODELS] = {
1505 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001506 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001507 [STAC_9200_DELL_D21] = "dell-d21",
1508 [STAC_9200_DELL_D22] = "dell-d22",
1509 [STAC_9200_DELL_D23] = "dell-d23",
1510 [STAC_9200_DELL_M21] = "dell-m21",
1511 [STAC_9200_DELL_M22] = "dell-m22",
1512 [STAC_9200_DELL_M23] = "dell-m23",
1513 [STAC_9200_DELL_M24] = "dell-m24",
1514 [STAC_9200_DELL_M25] = "dell-m25",
1515 [STAC_9200_DELL_M26] = "dell-m26",
1516 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001517 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwai117f2572008-03-18 09:53:23 +01001518 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001519};
1520
1521static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1522 /* SigmaTel reference board */
1523 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1524 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001525 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001526 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1527 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001528 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001529 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1530 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1531 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1532 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1533 "unknown Dell", STAC_9200_DELL_D22),
1534 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1535 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001536 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001537 "Dell Latitude D620", STAC_9200_DELL_M22),
1538 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1539 "unknown Dell", STAC_9200_DELL_D23),
1540 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1541 "unknown Dell", STAC_9200_DELL_D23),
1542 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1543 "unknown Dell", STAC_9200_DELL_M22),
1544 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1545 "unknown Dell", STAC_9200_DELL_M24),
1546 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1547 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001548 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001549 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001550 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001551 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001552 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001553 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001554 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001555 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001556 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001557 "Dell Precision M90", STAC_9200_DELL_M23),
1558 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1559 "unknown Dell", STAC_9200_DELL_M22),
1560 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1561 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001563 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001565 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1567 "unknown Dell", STAC_9200_DELL_D23),
1568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1569 "unknown Dell", STAC_9200_DELL_D23),
1570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1571 "unknown Dell", STAC_9200_DELL_D21),
1572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1573 "unknown Dell", STAC_9200_DELL_D23),
1574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1575 "unknown Dell", STAC_9200_DELL_D21),
1576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1577 "unknown Dell", STAC_9200_DELL_M25),
1578 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1579 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001581 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1582 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1583 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001584 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001585 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001586 /* Gateway machines needs EAPD to be set on resume */
1587 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1588 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1589 STAC_9200_GATEWAY),
1590 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1591 STAC_9200_GATEWAY),
Tobin Davisbf277782008-02-03 20:31:47 +01001592 /* OQO Mobile */
1593 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001594 {} /* terminator */
1595};
1596
Tobin Davis8e21c342007-01-08 11:04:17 +01001597static unsigned int ref925x_pin_configs[8] = {
1598 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001599 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001600};
1601
1602static unsigned int stac925x_MA6_pin_configs[8] = {
1603 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1604 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
1605};
1606
Tobin Davis2c11f952007-05-17 09:36:34 +02001607static unsigned int stac925x_PA6_pin_configs[8] = {
1608 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1609 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
1610};
1611
Tobin Davis8e21c342007-01-08 11:04:17 +01001612static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +02001613 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
1614 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001615};
1616
1617static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1618 [STAC_REF] = ref925x_pin_configs,
1619 [STAC_M2_2] = stac925xM2_2_pin_configs,
1620 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +02001621 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001622};
1623
1624static const char *stac925x_models[STAC_925x_MODELS] = {
1625 [STAC_REF] = "ref",
1626 [STAC_M2_2] = "m2-2",
1627 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +02001628 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001629};
1630
1631static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1632 /* SigmaTel reference board */
1633 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001634 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +01001635 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
1636 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
1637 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +02001638 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +01001639 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
1640 {} /* terminator */
1641};
1642
Matthew Ranostaya7662642008-02-21 07:51:14 +01001643static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001644 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1645 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1646 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001647 0x01452050,
1648};
1649
1650static unsigned int dell_m6_pin_configs[13] = {
1651 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001652 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001653 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1654 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001655};
1656
1657static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001658 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1659 [STAC_DELL_M6] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001660 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001661};
1662
1663static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1664 [STAC_92HD73XX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001665 [STAC_DELL_M6] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001666 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001667};
1668
1669static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1670 /* SigmaTel reference board */
1671 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001672 "DFI LanParty", STAC_92HD73XX_REF),
1673 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwaid6752a52008-11-21 18:01:44 +01001674 "Dell Studio 1535", STAC_DELL_M6),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001675 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1676 "unknown Dell", STAC_DELL_M6),
1677 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1678 "unknown Dell", STAC_DELL_M6),
1679 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1680 "unknown Dell", STAC_DELL_M6),
1681 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1682 "unknown Dell", STAC_DELL_M6),
1683 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1684 "unknown Dell", STAC_DELL_M6),
1685 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1686 "unknown Dell", STAC_DELL_M6),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001687 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
1688 "Dell Studio 15", STAC_DELL_M6),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001689 {} /* terminator */
1690};
1691
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001692static unsigned int ref92hd83xxx_pin_configs[14] = {
1693 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1694 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1695 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1696 0x01451160, 0x98560170,
1697};
1698
1699static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1700 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1701};
1702
1703static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1704 [STAC_92HD83XXX_REF] = "ref",
1705};
1706
1707static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1708 /* SigmaTel reference board */
1709 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1710 "DFI LanParty", STAC_92HD71BXX_REF),
1711};
1712
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001713static unsigned int ref92hd71bxx_pin_configs[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001714 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001715 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001716 0x90a000f0, 0x01452050, 0x01452050,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001717};
1718
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001719static unsigned int dell_m4_1_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001720 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001721 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001722 0x40f000f0, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001723};
1724
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001725static unsigned int dell_m4_2_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001726 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1727 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001728 0x40f000f0, 0x044413b0, 0x044413b0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001729};
1730
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001731static unsigned int dell_m4_3_pin_configs[11] = {
1732 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1733 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1734 0x40f000f0, 0x044413b0, 0x044413b0,
1735};
1736
Matthew Ranostaye035b842007-11-06 11:53:55 +01001737static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1738 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001739 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1740 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001741 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001742 [STAC_HP_M4] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001743};
1744
1745static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1746 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001747 [STAC_DELL_M4_1] = "dell-m4-1",
1748 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001749 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001750 [STAC_HP_M4] = "hp-m4",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001751};
1752
1753static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1754 /* SigmaTel reference board */
1755 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1756 "DFI LanParty", STAC_92HD71BXX_REF),
Takashi Iwai80bf2722008-11-18 10:48:41 +01001757 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f2,
1758 "HP dv5", STAC_HP_M4),
1759 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4,
1760 "HP dv7", STAC_HP_M4),
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001761 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1762 "unknown HP", STAC_HP_M4),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001763 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1764 "unknown Dell", STAC_DELL_M4_1),
1765 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1766 "unknown Dell", STAC_DELL_M4_1),
1767 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1768 "unknown Dell", STAC_DELL_M4_1),
1769 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1770 "unknown Dell", STAC_DELL_M4_1),
1771 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1772 "unknown Dell", STAC_DELL_M4_1),
1773 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1774 "unknown Dell", STAC_DELL_M4_1),
1775 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1776 "unknown Dell", STAC_DELL_M4_1),
1777 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1778 "unknown Dell", STAC_DELL_M4_2),
1779 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1780 "unknown Dell", STAC_DELL_M4_2),
1781 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1782 "unknown Dell", STAC_DELL_M4_2),
1783 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1784 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001785 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1786 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001787 {} /* terminator */
1788};
1789
Matt Porter403d1942005-11-29 15:00:51 +01001790static unsigned int ref922x_pin_configs[10] = {
1791 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1792 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001793 0x40000100, 0x40000100,
1794};
1795
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001796/*
1797 STAC 922X pin configs for
1798 102801A7
1799 102801AB
1800 102801A9
1801 102801D1
1802 102801D2
1803*/
1804static unsigned int dell_922x_d81_pin_configs[10] = {
1805 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1806 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1807 0x01813122, 0x400001f2,
1808};
1809
1810/*
1811 STAC 922X pin configs for
1812 102801AC
1813 102801D0
1814*/
1815static unsigned int dell_922x_d82_pin_configs[10] = {
1816 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1817 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1818 0x01813122, 0x400001f1,
1819};
1820
1821/*
1822 STAC 922X pin configs for
1823 102801BF
1824*/
1825static unsigned int dell_922x_m81_pin_configs[10] = {
1826 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1827 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1828 0x40C003f1, 0x405003f0,
1829};
1830
1831/*
1832 STAC 9221 A1 pin configs for
1833 102801D7 (Dell XPS M1210)
1834*/
1835static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001836 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1837 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001838 0x508003f3, 0x405003f4,
1839};
1840
Matt Porter403d1942005-11-29 15:00:51 +01001841static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001842 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001843 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1844 0x02a19120, 0x40000100,
1845};
1846
1847static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001848 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1849 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001850 0x02a19320, 0x40000100,
1851};
1852
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001853static unsigned int intel_mac_v1_pin_configs[10] = {
1854 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1855 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001856 0x400000fc, 0x400000fb,
1857};
1858
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001859static unsigned int intel_mac_v2_pin_configs[10] = {
1860 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1861 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001862 0x400000fc, 0x400000fb,
1863};
1864
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001865static unsigned int intel_mac_v3_pin_configs[10] = {
1866 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1867 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1868 0x400000fc, 0x400000fb,
1869};
1870
1871static unsigned int intel_mac_v4_pin_configs[10] = {
1872 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1873 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1874 0x400000fc, 0x400000fb,
1875};
1876
1877static unsigned int intel_mac_v5_pin_configs[10] = {
1878 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1879 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1880 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001881};
1882
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001883static unsigned int ecs202_pin_configs[10] = {
1884 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1885 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1886 0x9037012e, 0x40e000f2,
1887};
Takashi Iwai76c08822007-06-19 12:17:42 +02001888
Takashi Iwai19039bd2006-06-28 15:52:16 +02001889static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001890 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001891 [STAC_D945GTP3] = d945gtp3_pin_configs,
1892 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001893 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1894 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1895 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1896 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1897 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001898 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001899 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001900 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1901 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1902 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1903 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1904 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1905 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001906 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001907 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1908 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1909 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1910 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001911};
1912
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001913static const char *stac922x_models[STAC_922X_MODELS] = {
1914 [STAC_D945_REF] = "ref",
1915 [STAC_D945GTP5] = "5stack",
1916 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001917 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1918 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1919 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1920 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1921 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001922 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001923 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001924 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001925 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001926 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1927 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001928 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001929 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001930 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001931 [STAC_922X_DELL_D81] = "dell-d81",
1932 [STAC_922X_DELL_D82] = "dell-d82",
1933 [STAC_922X_DELL_M81] = "dell-m81",
1934 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001935};
1936
1937static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1938 /* SigmaTel reference board */
1939 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1940 "DFI LanParty", STAC_D945_REF),
1941 /* Intel 945G based systems */
1942 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1943 "Intel D945G", STAC_D945GTP3),
1944 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1945 "Intel D945G", STAC_D945GTP3),
1946 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1947 "Intel D945G", STAC_D945GTP3),
1948 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1949 "Intel D945G", STAC_D945GTP3),
1950 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1951 "Intel D945G", STAC_D945GTP3),
1952 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1953 "Intel D945G", STAC_D945GTP3),
1954 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1955 "Intel D945G", STAC_D945GTP3),
1956 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1957 "Intel D945G", STAC_D945GTP3),
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1959 "Intel D945G", STAC_D945GTP3),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1961 "Intel D945G", STAC_D945GTP3),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1963 "Intel D945G", STAC_D945GTP3),
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1965 "Intel D945G", STAC_D945GTP3),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1967 "Intel D945G", STAC_D945GTP3),
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1969 "Intel D945G", STAC_D945GTP3),
1970 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1971 "Intel D945G", STAC_D945GTP3),
1972 /* Intel D945G 5-stack systems */
1973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1974 "Intel D945G", STAC_D945GTP5),
1975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1976 "Intel D945G", STAC_D945GTP5),
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1978 "Intel D945G", STAC_D945GTP5),
1979 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1980 "Intel D945G", STAC_D945GTP5),
1981 /* Intel 945P based systems */
1982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1983 "Intel D945P", STAC_D945GTP3),
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1985 "Intel D945P", STAC_D945GTP3),
1986 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1987 "Intel D945P", STAC_D945GTP3),
1988 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1989 "Intel D945P", STAC_D945GTP3),
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1991 "Intel D945P", STAC_D945GTP3),
1992 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1993 "Intel D945P", STAC_D945GTP5),
1994 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08001995 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001996 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001997 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001998 /* Dell systems */
1999 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2000 "unknown Dell", STAC_922X_DELL_D81),
2001 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2002 "unknown Dell", STAC_922X_DELL_D81),
2003 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2004 "unknown Dell", STAC_922X_DELL_D81),
2005 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2006 "unknown Dell", STAC_922X_DELL_D82),
2007 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2008 "unknown Dell", STAC_922X_DELL_M81),
2009 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2010 "unknown Dell", STAC_922X_DELL_D82),
2011 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2012 "unknown Dell", STAC_922X_DELL_D81),
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2014 "unknown Dell", STAC_922X_DELL_D81),
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2016 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002017 /* ECS/PC Chips boards */
2018 SND_PCI_QUIRK(0x1019, 0x2144,
2019 "ECS/PC chips", STAC_ECS_202),
2020 SND_PCI_QUIRK(0x1019, 0x2608,
2021 "ECS/PC chips", STAC_ECS_202),
2022 SND_PCI_QUIRK(0x1019, 0x2633,
2023 "ECS/PC chips P17G/1333", STAC_ECS_202),
2024 SND_PCI_QUIRK(0x1019, 0x2811,
2025 "ECS/PC chips", STAC_ECS_202),
2026 SND_PCI_QUIRK(0x1019, 0x2812,
2027 "ECS/PC chips", STAC_ECS_202),
2028 SND_PCI_QUIRK(0x1019, 0x2813,
2029 "ECS/PC chips", STAC_ECS_202),
2030 SND_PCI_QUIRK(0x1019, 0x2814,
2031 "ECS/PC chips", STAC_ECS_202),
2032 SND_PCI_QUIRK(0x1019, 0x2815,
2033 "ECS/PC chips", STAC_ECS_202),
2034 SND_PCI_QUIRK(0x1019, 0x2816,
2035 "ECS/PC chips", STAC_ECS_202),
2036 SND_PCI_QUIRK(0x1019, 0x2817,
2037 "ECS/PC chips", STAC_ECS_202),
2038 SND_PCI_QUIRK(0x1019, 0x2818,
2039 "ECS/PC chips", STAC_ECS_202),
2040 SND_PCI_QUIRK(0x1019, 0x2819,
2041 "ECS/PC chips", STAC_ECS_202),
2042 SND_PCI_QUIRK(0x1019, 0x2820,
2043 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002044 {} /* terminator */
2045};
2046
Matt Porter3cc08dc2006-01-23 15:27:49 +01002047static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002048 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2049 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2050 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2051 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002052};
2053
Tobin Davis93ed1502006-09-01 21:03:12 +02002054static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002055 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2056 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2057 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2058 0x40000100, 0x40000100
2059};
2060
Tobin Davis93ed1502006-09-01 21:03:12 +02002061static unsigned int d965_5st_pin_configs[14] = {
2062 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2063 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2064 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2065 0x40000100, 0x40000100
2066};
2067
Tobin Davis4ff076e2007-08-07 11:48:12 +02002068static unsigned int dell_3st_pin_configs[14] = {
2069 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2070 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002071 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002072 0x40c003fc, 0x40000100
2073};
2074
Tobin Davis93ed1502006-09-01 21:03:12 +02002075static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002076 [STAC_D965_REF] = ref927x_pin_configs,
2077 [STAC_D965_3ST] = d965_3st_pin_configs,
2078 [STAC_D965_5ST] = d965_5st_pin_configs,
2079 [STAC_DELL_3ST] = dell_3st_pin_configs,
2080 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002081};
2082
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002083static const char *stac927x_models[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002084 [STAC_D965_REF] = "ref",
2085 [STAC_D965_3ST] = "3stack",
2086 [STAC_D965_5ST] = "5stack",
2087 [STAC_DELL_3ST] = "dell-3stack",
2088 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002089};
2090
2091static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2092 /* SigmaTel reference board */
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2094 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002095 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002096 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2097 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002098 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002099 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
2100 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
2101 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
2102 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
2103 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
2104 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
2106 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
2107 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
2108 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
2109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
2110 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
2111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
2112 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
2113 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002115 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002116 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002117 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002118 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2119 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002120 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002121 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2122 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002123 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Takashi Iwai24918b62008-09-30 12:58:54 +02002124 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002125 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2126 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2127 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2128 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002129 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002130 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
2131 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
2132 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
2133 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
2134 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
2135 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
2136 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
2137 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
2138 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002139 {} /* terminator */
2140};
2141
Matt Porterf3302a52006-07-31 12:49:34 +02002142static unsigned int ref9205_pin_configs[12] = {
2143 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002144 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002145 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002146};
2147
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002148/*
2149 STAC 9205 pin configs for
2150 102801F1
2151 102801F2
2152 102801FC
2153 102801FD
2154 10280204
2155 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002156 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002157*/
2158static unsigned int dell_9205_m42_pin_configs[12] = {
2159 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2160 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2161 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2162};
2163
2164/*
2165 STAC 9205 pin configs for
2166 102801F9
2167 102801FA
2168 102801FE
2169 102801FF (Dell Precision M4300)
2170 10280206
2171 10280200
2172 10280201
2173*/
2174static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002175 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2176 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2177 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2178};
2179
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002180static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002181 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2182 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2183 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2184};
2185
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002186static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002187 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002188 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2189 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2190 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02002191};
2192
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002193static const char *stac9205_models[STAC_9205_MODELS] = {
2194 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002195 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002196 [STAC_9205_DELL_M43] = "dell-m43",
2197 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002198};
2199
2200static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2201 /* SigmaTel reference board */
2202 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2203 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002204 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2205 "unknown Dell", STAC_9205_DELL_M42),
2206 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2207 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002209 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002210 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2211 "Dell Precision", STAC_9205_DELL_M43),
2212 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2213 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002214 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2215 "unknown Dell", STAC_9205_DELL_M42),
2216 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2217 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002218 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2219 "Dell Precision", STAC_9205_DELL_M43),
2220 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002221 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002222 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2223 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002224 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2225 "Dell Precision", STAC_9205_DELL_M43),
2226 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2227 "Dell Precision", STAC_9205_DELL_M43),
2228 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2229 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002230 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2231 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002232 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2233 "Dell Vostro 1500", STAC_9205_DELL_M42),
Matt Porterf3302a52006-07-31 12:49:34 +02002234 {} /* terminator */
2235};
2236
Richard Fish11b44bb2006-08-23 18:31:34 +02002237static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2238{
2239 int i;
2240 struct sigmatel_spec *spec = codec->spec;
2241
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002242 kfree(spec->pin_configs);
2243 spec->pin_configs = kcalloc(spec->num_pins, sizeof(*spec->pin_configs),
2244 GFP_KERNEL);
2245 if (!spec->pin_configs)
2246 return -ENOMEM;
Richard Fish11b44bb2006-08-23 18:31:34 +02002247
2248 for (i = 0; i < spec->num_pins; i++) {
2249 hda_nid_t nid = spec->pin_nids[i];
2250 unsigned int pin_cfg;
2251
2252 pin_cfg = snd_hda_codec_read(codec, nid, 0,
2253 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2254 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2255 nid, pin_cfg);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002256 spec->pin_configs[i] = pin_cfg;
Richard Fish11b44bb2006-08-23 18:31:34 +02002257 }
2258
2259 return 0;
2260}
2261
Matthew Ranostay87d48362007-07-17 11:52:24 +02002262static void stac92xx_set_config_reg(struct hda_codec *codec,
2263 hda_nid_t pin_nid, unsigned int pin_config)
2264{
2265 int i;
2266 snd_hda_codec_write(codec, pin_nid, 0,
2267 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2268 pin_config & 0x000000ff);
2269 snd_hda_codec_write(codec, pin_nid, 0,
2270 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2271 (pin_config & 0x0000ff00) >> 8);
2272 snd_hda_codec_write(codec, pin_nid, 0,
2273 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2274 (pin_config & 0x00ff0000) >> 16);
2275 snd_hda_codec_write(codec, pin_nid, 0,
2276 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2277 pin_config >> 24);
2278 i = snd_hda_codec_read(codec, pin_nid, 0,
2279 AC_VERB_GET_CONFIG_DEFAULT,
2280 0x00);
2281 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
2282 pin_nid, i);
2283}
2284
Matt2f2f4252005-04-13 14:45:30 +02002285static void stac92xx_set_config_regs(struct hda_codec *codec)
2286{
2287 int i;
2288 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002289
Matthew Ranostay87d48362007-07-17 11:52:24 +02002290 if (!spec->pin_configs)
2291 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002292
Matthew Ranostay87d48362007-07-17 11:52:24 +02002293 for (i = 0; i < spec->num_pins; i++)
2294 stac92xx_set_config_reg(codec, spec->pin_nids[i],
2295 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02002296}
Matt2f2f4252005-04-13 14:45:30 +02002297
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002298static int stac_save_pin_cfgs(struct hda_codec *codec, unsigned int *pins)
2299{
2300 struct sigmatel_spec *spec = codec->spec;
2301
2302 if (!pins)
2303 return stac92xx_save_bios_config_regs(codec);
2304
2305 kfree(spec->pin_configs);
2306 spec->pin_configs = kmemdup(pins,
2307 spec->num_pins * sizeof(*pins),
2308 GFP_KERNEL);
2309 if (!spec->pin_configs)
2310 return -ENOMEM;
2311
2312 stac92xx_set_config_regs(codec);
2313 return 0;
2314}
2315
2316static void stac_change_pin_config(struct hda_codec *codec, hda_nid_t nid,
2317 unsigned int cfg)
2318{
2319 struct sigmatel_spec *spec = codec->spec;
2320 int i;
2321
2322 for (i = 0; i < spec->num_pins; i++) {
2323 if (spec->pin_nids[i] == nid) {
2324 spec->pin_configs[i] = cfg;
2325 stac92xx_set_config_reg(codec, nid, cfg);
2326 break;
2327 }
2328 }
2329}
2330
Matt2f2f4252005-04-13 14:45:30 +02002331/*
2332 * Analog playback callbacks
2333 */
2334static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2335 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002336 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002337{
2338 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002339 if (spec->stream_delay)
2340 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002341 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2342 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002343}
2344
2345static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2346 struct hda_codec *codec,
2347 unsigned int stream_tag,
2348 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002349 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002350{
2351 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002352 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002353}
2354
2355static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2356 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002357 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002358{
2359 struct sigmatel_spec *spec = codec->spec;
2360 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2361}
2362
2363/*
Mattdabbed62005-06-14 10:19:34 +02002364 * Digital playback callbacks
2365 */
2366static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2367 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002368 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002369{
2370 struct sigmatel_spec *spec = codec->spec;
2371 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2372}
2373
2374static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2375 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002376 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002377{
2378 struct sigmatel_spec *spec = codec->spec;
2379 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2380}
2381
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002382static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2383 struct hda_codec *codec,
2384 unsigned int stream_tag,
2385 unsigned int format,
2386 struct snd_pcm_substream *substream)
2387{
2388 struct sigmatel_spec *spec = codec->spec;
2389 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2390 stream_tag, format, substream);
2391}
2392
Mattdabbed62005-06-14 10:19:34 +02002393
2394/*
Matt2f2f4252005-04-13 14:45:30 +02002395 * Analog capture callbacks
2396 */
2397static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2398 struct hda_codec *codec,
2399 unsigned int stream_tag,
2400 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002401 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002402{
2403 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002404 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002405
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002406 if (spec->powerdown_adcs) {
2407 msleep(40);
2408 snd_hda_codec_write_cache(codec, nid, 0,
2409 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2410 }
2411 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002412 return 0;
2413}
2414
2415static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2416 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002417 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002418{
2419 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002420 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002421
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002422 snd_hda_codec_cleanup_stream(codec, nid);
2423 if (spec->powerdown_adcs)
2424 snd_hda_codec_write_cache(codec, nid, 0,
2425 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002426 return 0;
2427}
2428
Mattdabbed62005-06-14 10:19:34 +02002429static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2430 .substreams = 1,
2431 .channels_min = 2,
2432 .channels_max = 2,
2433 /* NID is set in stac92xx_build_pcms */
2434 .ops = {
2435 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002436 .close = stac92xx_dig_playback_pcm_close,
2437 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02002438 },
2439};
2440
2441static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2442 .substreams = 1,
2443 .channels_min = 2,
2444 .channels_max = 2,
2445 /* NID is set in stac92xx_build_pcms */
2446};
2447
Matt2f2f4252005-04-13 14:45:30 +02002448static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2449 .substreams = 1,
2450 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002451 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002452 .nid = 0x02, /* NID to query formats and rates */
2453 .ops = {
2454 .open = stac92xx_playback_pcm_open,
2455 .prepare = stac92xx_playback_pcm_prepare,
2456 .cleanup = stac92xx_playback_pcm_cleanup
2457 },
2458};
2459
Matt Porter3cc08dc2006-01-23 15:27:49 +01002460static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2461 .substreams = 1,
2462 .channels_min = 2,
2463 .channels_max = 2,
2464 .nid = 0x06, /* NID to query formats and rates */
2465 .ops = {
2466 .open = stac92xx_playback_pcm_open,
2467 .prepare = stac92xx_playback_pcm_prepare,
2468 .cleanup = stac92xx_playback_pcm_cleanup
2469 },
2470};
2471
Matt2f2f4252005-04-13 14:45:30 +02002472static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002473 .channels_min = 2,
2474 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002475 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002476 .ops = {
2477 .prepare = stac92xx_capture_pcm_prepare,
2478 .cleanup = stac92xx_capture_pcm_cleanup
2479 },
2480};
2481
2482static int stac92xx_build_pcms(struct hda_codec *codec)
2483{
2484 struct sigmatel_spec *spec = codec->spec;
2485 struct hda_pcm *info = spec->pcm_rec;
2486
2487 codec->num_pcms = 1;
2488 codec->pcm_info = info;
2489
Mattc7d4b2f2005-06-27 14:59:41 +02002490 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002491 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02002492 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002493 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002494 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002495
2496 if (spec->alt_switch) {
2497 codec->num_pcms++;
2498 info++;
2499 info->name = "STAC92xx Analog Alt";
2500 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2501 }
Matt2f2f4252005-04-13 14:45:30 +02002502
Mattdabbed62005-06-14 10:19:34 +02002503 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2504 codec->num_pcms++;
2505 info++;
2506 info->name = "STAC92xx Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01002507 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Mattdabbed62005-06-14 10:19:34 +02002508 if (spec->multiout.dig_out_nid) {
2509 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2510 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2511 }
2512 if (spec->dig_in_nid) {
2513 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2514 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2515 }
2516 }
2517
Matt2f2f4252005-04-13 14:45:30 +02002518 return 0;
2519}
2520
Takashi Iwaic960a032006-03-23 17:06:28 +01002521static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2522{
2523 unsigned int pincap = snd_hda_param_read(codec, nid,
2524 AC_PAR_PIN_CAP);
2525 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2526 if (pincap & AC_PINCAP_VREF_100)
2527 return AC_PINCTL_VREF_100;
2528 if (pincap & AC_PINCAP_VREF_80)
2529 return AC_PINCTL_VREF_80;
2530 if (pincap & AC_PINCAP_VREF_50)
2531 return AC_PINCTL_VREF_50;
2532 if (pincap & AC_PINCAP_VREF_GRD)
2533 return AC_PINCTL_VREF_GRD;
2534 return 0;
2535}
2536
Matt Porter403d1942005-11-29 15:00:51 +01002537static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2538
2539{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002540 snd_hda_codec_write_cache(codec, nid, 0,
2541 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002542}
2543
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002544#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2545
2546static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2547 struct snd_ctl_elem_value *ucontrol)
2548{
2549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2550 struct sigmatel_spec *spec = codec->spec;
2551
Takashi Iwaid7a89432008-11-12 09:48:04 +01002552 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002553 return 0;
2554}
2555
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002556static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2557 unsigned char type);
2558
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002559static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2560 struct snd_ctl_elem_value *ucontrol)
2561{
2562 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2563 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002564 int nid = kcontrol->private_value;
2565
2566 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002567
2568 /* check to be sure that the ports are upto date with
2569 * switch changes
2570 */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002571 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002572
2573 return 1;
2574}
2575
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002576#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01002577
2578static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2579{
2580 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2581 struct sigmatel_spec *spec = codec->spec;
2582 int io_idx = kcontrol-> private_value & 0xff;
2583
2584 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2585 return 0;
2586}
2587
2588static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2589{
2590 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2591 struct sigmatel_spec *spec = codec->spec;
2592 hda_nid_t nid = kcontrol->private_value >> 8;
2593 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002594 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01002595
2596 spec->io_switch[io_idx] = val;
2597
2598 if (val)
2599 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002600 else {
2601 unsigned int pinctl = AC_PINCTL_IN_EN;
2602 if (io_idx) /* set VREF for mic */
2603 pinctl |= stac92xx_get_vref(codec, nid);
2604 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2605 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002606
2607 /* check the auto-mute again: we need to mute/unmute the speaker
2608 * appropriately according to the pin direction
2609 */
2610 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002611 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002612
Matt Porter403d1942005-11-29 15:00:51 +01002613 return 1;
2614}
2615
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002616#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2617
2618static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2619 struct snd_ctl_elem_value *ucontrol)
2620{
2621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2622 struct sigmatel_spec *spec = codec->spec;
2623
2624 ucontrol->value.integer.value[0] = spec->clfe_swap;
2625 return 0;
2626}
2627
2628static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2629 struct snd_ctl_elem_value *ucontrol)
2630{
2631 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2632 struct sigmatel_spec *spec = codec->spec;
2633 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002634 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002635
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002636 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002637 return 0;
2638
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002639 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002640
2641 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2642 spec->clfe_swap ? 0x4 : 0x0);
2643
2644 return 1;
2645}
2646
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002647#define STAC_CODEC_HP_SWITCH(xname) \
2648 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2649 .name = xname, \
2650 .index = 0, \
2651 .info = stac92xx_hp_switch_info, \
2652 .get = stac92xx_hp_switch_get, \
2653 .put = stac92xx_hp_switch_put, \
2654 }
2655
Matt Porter403d1942005-11-29 15:00:51 +01002656#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2657 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2658 .name = xname, \
2659 .index = 0, \
2660 .info = stac92xx_io_switch_info, \
2661 .get = stac92xx_io_switch_get, \
2662 .put = stac92xx_io_switch_put, \
2663 .private_value = xpval, \
2664 }
2665
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002666#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2667 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2668 .name = xname, \
2669 .index = 0, \
2670 .info = stac92xx_clfe_switch_info, \
2671 .get = stac92xx_clfe_switch_get, \
2672 .put = stac92xx_clfe_switch_put, \
2673 .private_value = xpval, \
2674 }
Matt Porter403d1942005-11-29 15:00:51 +01002675
Mattc7d4b2f2005-06-27 14:59:41 +02002676enum {
2677 STAC_CTL_WIDGET_VOL,
2678 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002679 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002680 STAC_CTL_WIDGET_AMP_MUX,
2681 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002682 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002683 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002684 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02002685};
2686
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002687static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002688 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2689 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002690 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002691 STAC_AMP_MUX,
2692 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002693 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002694 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002695 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002696};
2697
2698/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002699static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2700 struct snd_kcontrol_new *ktemp,
2701 int idx, const char *name,
2702 unsigned long val)
Mattc7d4b2f2005-06-27 14:59:41 +02002703{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002704 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002705
Takashi Iwai603c4012008-07-30 15:01:44 +02002706 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2707 knew = snd_array_new(&spec->kctls);
2708 if (!knew)
2709 return -ENOMEM;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002710 *knew = *ktemp;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002711 knew->index = idx;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002712 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002713 if (!knew->name)
Mattc7d4b2f2005-06-27 14:59:41 +02002714 return -ENOMEM;
2715 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002716 return 0;
2717}
2718
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002719static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2720 int type, int idx, const char *name,
2721 unsigned long val)
2722{
2723 return stac92xx_add_control_temp(spec,
2724 &stac92xx_control_templates[type],
2725 idx, name, val);
2726}
2727
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002728
2729/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002730static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2731 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002732{
2733 return stac92xx_add_control_idx(spec, type, 0, name, val);
2734}
2735
Matt Porter403d1942005-11-29 15:00:51 +01002736/* flag inputs as additional dynamic lineouts */
2737static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2738{
2739 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002740 unsigned int wcaps, wtype;
2741 int i, num_dacs = 0;
2742
2743 /* use the wcaps cache to count all DACs available for line-outs */
2744 for (i = 0; i < codec->num_nodes; i++) {
2745 wcaps = codec->wcaps[i];
2746 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002747
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002748 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
2749 num_dacs++;
2750 }
Matt Porter403d1942005-11-29 15:00:51 +01002751
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002752 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
2753
Matt Porter403d1942005-11-29 15:00:51 +01002754 switch (cfg->line_outs) {
2755 case 3:
2756 /* add line-in as side */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002757 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002758 cfg->line_out_pins[cfg->line_outs] =
2759 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002760 spec->line_switch = 1;
2761 cfg->line_outs++;
2762 }
2763 break;
2764 case 2:
2765 /* add line-in as clfe and mic as side */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002766 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002767 cfg->line_out_pins[cfg->line_outs] =
2768 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002769 spec->line_switch = 1;
2770 cfg->line_outs++;
2771 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002772 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002773 cfg->line_out_pins[cfg->line_outs] =
2774 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002775 spec->mic_switch = 1;
2776 cfg->line_outs++;
2777 }
2778 break;
2779 case 1:
2780 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002781 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002782 cfg->line_out_pins[cfg->line_outs] =
2783 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002784 spec->line_switch = 1;
2785 cfg->line_outs++;
2786 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002787 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002788 cfg->line_out_pins[cfg->line_outs] =
2789 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002790 spec->mic_switch = 1;
2791 cfg->line_outs++;
2792 }
2793 break;
2794 }
2795
2796 return 0;
2797}
2798
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002799
2800static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2801{
2802 int i;
2803
2804 for (i = 0; i < spec->multiout.num_dacs; i++) {
2805 if (spec->multiout.dac_nids[i] == nid)
2806 return 1;
2807 }
2808
2809 return 0;
2810}
2811
Matt Porter3cc08dc2006-01-23 15:27:49 +01002812/*
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002813 * Fill in the dac_nids table from the parsed pin configuration
2814 * This function only works when every pin in line_out_pins[]
2815 * contains atleast one DAC in its connection list. Some 92xx
2816 * codecs are not connected directly to a DAC, such as the 9200
2817 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002818 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002819static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02002820 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002821{
2822 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002823 int i, j, conn_len = 0;
2824 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2825 unsigned int wcaps, wtype;
2826
Mattc7d4b2f2005-06-27 14:59:41 +02002827 for (i = 0; i < cfg->line_outs; i++) {
2828 nid = cfg->line_out_pins[i];
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002829 conn_len = snd_hda_get_connections(codec, nid, conn,
2830 HDA_MAX_CONNECTIONS);
2831 for (j = 0; j < conn_len; j++) {
2832 wcaps = snd_hda_param_read(codec, conn[j],
2833 AC_PAR_AUDIO_WIDGET_CAP);
2834 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002835 if (wtype != AC_WID_AUD_OUT ||
2836 (wcaps & AC_WCAP_DIGITAL))
2837 continue;
2838 /* conn[j] is a DAC routed to this line-out */
2839 if (!is_in_dac_nids(spec, conn[j]))
2840 break;
2841 }
2842
2843 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002844 if (spec->multiout.num_dacs > 0) {
2845 /* we have already working output pins,
2846 * so let's drop the broken ones again
2847 */
2848 cfg->line_outs = spec->multiout.num_dacs;
2849 break;
2850 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002851 /* error out, no available DAC found */
2852 snd_printk(KERN_ERR
2853 "%s: No available DAC for pin 0x%x\n",
2854 __func__, nid);
2855 return -ENODEV;
2856 }
2857
2858 spec->multiout.dac_nids[i] = conn[j];
2859 spec->multiout.num_dacs++;
2860 if (conn_len > 1) {
2861 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002862 snd_hda_codec_write_cache(codec, nid, 0,
2863 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002864
2865 }
Mattc7d4b2f2005-06-27 14:59:41 +02002866 }
2867
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002868 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2869 spec->multiout.num_dacs,
2870 spec->multiout.dac_nids[0],
2871 spec->multiout.dac_nids[1],
2872 spec->multiout.dac_nids[2],
2873 spec->multiout.dac_nids[3],
2874 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02002875 return 0;
2876}
2877
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002878/* create volume control/switch for the given prefx type */
2879static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2880{
2881 char name[32];
2882 int err;
2883
2884 sprintf(name, "%s Playback Volume", pfx);
2885 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2886 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2887 if (err < 0)
2888 return err;
2889 sprintf(name, "%s Playback Switch", pfx);
2890 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2891 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2892 if (err < 0)
2893 return err;
2894 return 0;
2895}
2896
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002897static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2898{
2899 if (!spec->multiout.hp_nid)
2900 spec->multiout.hp_nid = nid;
2901 else if (spec->multiout.num_dacs > 4) {
2902 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2903 return 1;
2904 } else {
2905 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2906 spec->multiout.num_dacs++;
2907 }
2908 return 0;
2909}
2910
2911static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2912{
2913 if (is_in_dac_nids(spec, nid))
2914 return 1;
2915 if (spec->multiout.hp_nid == nid)
2916 return 1;
2917 return 0;
2918}
2919
Mattc7d4b2f2005-06-27 14:59:41 +02002920/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002921static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002922 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002923{
Takashi Iwai19039bd2006-06-28 15:52:16 +02002924 static const char *chname[4] = {
2925 "Front", "Surround", NULL /*CLFE*/, "Side"
2926 };
Matthew Ranostayd21995e2008-10-13 13:22:45 -04002927 hda_nid_t nid = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002928 int i, err;
2929
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002930 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002931 unsigned int wid_caps, pincap;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002932
2933
Takashi Iwai40ac8c42008-02-29 14:16:17 +01002934 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01002935 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02002936 continue;
2937
2938 nid = spec->multiout.dac_nids[i];
2939
2940 if (i == 2) {
2941 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002942 err = create_controls(spec, "Center", nid, 1);
2943 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002944 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002945 err = create_controls(spec, "LFE", nid, 2);
2946 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002947 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002948
2949 wid_caps = get_wcaps(codec, nid);
2950
2951 if (wid_caps & AC_WCAP_LR_SWAP) {
2952 err = stac92xx_add_control(spec,
2953 STAC_CTL_WIDGET_CLFE_SWITCH,
2954 "Swap Center/LFE Playback Switch", nid);
2955
2956 if (err < 0)
2957 return err;
2958 }
2959
Mattc7d4b2f2005-06-27 14:59:41 +02002960 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002961 err = create_controls(spec, chname[i], nid, 3);
2962 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002963 return err;
2964 }
2965 }
2966
Matthew Ranostayfedb7562008-09-23 21:46:30 -04002967 if ((spec->multiout.num_dacs - cfg->line_outs) > 0 &&
2968 cfg->hp_outs && !spec->multiout.hp_nid)
2969 spec->multiout.hp_nid = nid;
2970
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01002971 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002972 err = stac92xx_add_control(spec,
2973 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01002974 "Headphone as Line Out Switch",
2975 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002976 if (err < 0)
2977 return err;
2978 }
2979
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002980 if (spec->line_switch) {
2981 nid = cfg->input_pins[AUTO_PIN_LINE];
2982 pincap = snd_hda_param_read(codec, nid,
2983 AC_PAR_PIN_CAP);
2984 if (pincap & AC_PINCAP_OUT) {
2985 err = stac92xx_add_control(spec,
2986 STAC_CTL_WIDGET_IO_SWITCH,
2987 "Line In as Output Switch", nid << 8);
2988 if (err < 0)
2989 return err;
2990 }
2991 }
Matt Porter403d1942005-11-29 15:00:51 +01002992
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002993 if (spec->mic_switch) {
Matthew Ranostaycace16f2008-01-30 14:58:38 +01002994 unsigned int def_conf;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002995 unsigned int mic_pin = AUTO_PIN_MIC;
2996again:
2997 nid = cfg->input_pins[mic_pin];
Matthew Ranostaycace16f2008-01-30 14:58:38 +01002998 def_conf = snd_hda_codec_read(codec, nid, 0,
2999 AC_VERB_GET_CONFIG_DEFAULT, 0);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003000 /* some laptops have an internal analog microphone
3001 * which can't be used as a output */
3002 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
3003 pincap = snd_hda_param_read(codec, nid,
3004 AC_PAR_PIN_CAP);
3005 if (pincap & AC_PINCAP_OUT) {
3006 err = stac92xx_add_control(spec,
3007 STAC_CTL_WIDGET_IO_SWITCH,
3008 "Mic as Output Switch", (nid << 8) | 1);
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003009 nid = snd_hda_codec_read(codec, nid, 0,
3010 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3011 if (!check_in_dac_nids(spec, nid))
3012 add_spec_dacs(spec, nid);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003013 if (err < 0)
3014 return err;
3015 }
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003016 } else if (mic_pin == AUTO_PIN_MIC) {
3017 mic_pin = AUTO_PIN_FRONT_MIC;
3018 goto again;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003019 }
3020 }
Matt Porter403d1942005-11-29 15:00:51 +01003021
Mattc7d4b2f2005-06-27 14:59:41 +02003022 return 0;
3023}
3024
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003025/* add playback controls for Speaker and HP outputs */
3026static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3027 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003028{
3029 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003030 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003031 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003032
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003033 old_num_dacs = spec->multiout.num_dacs;
3034 for (i = 0; i < cfg->hp_outs; i++) {
3035 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
3036 if (wid_caps & AC_WCAP_UNSOL_CAP)
3037 spec->hp_detect = 1;
3038 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
3039 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3040 if (check_in_dac_nids(spec, nid))
3041 nid = 0;
3042 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02003043 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003044 add_spec_dacs(spec, nid);
3045 }
3046 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003047 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003048 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3049 if (check_in_dac_nids(spec, nid))
3050 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003051 if (! nid)
3052 continue;
3053 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02003054 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02003055 for (i = 0; i < cfg->line_outs; i++) {
3056 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
3057 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3058 if (check_in_dac_nids(spec, nid))
3059 nid = 0;
3060 if (! nid)
3061 continue;
3062 add_spec_dacs(spec, nid);
3063 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003064 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
3065 static const char *pfxs[] = {
3066 "Speaker", "External Speaker", "Speaker2",
3067 };
3068 err = create_controls(spec, pfxs[i - old_num_dacs],
3069 spec->multiout.dac_nids[i], 3);
3070 if (err < 0)
3071 return err;
3072 }
3073 if (spec->multiout.hp_nid) {
Takashi Iwai2626a262008-03-14 09:18:32 +01003074 err = create_controls(spec, "Headphone",
3075 spec->multiout.hp_nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003076 if (err < 0)
3077 return err;
3078 }
Mattc7d4b2f2005-06-27 14:59:41 +02003079
3080 return 0;
3081}
3082
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003083/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003084static const char *stac92xx_mono_labels[4] = {
3085 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003086};
3087
3088/* create mono mux for mono out on capable codecs */
3089static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3090{
3091 struct sigmatel_spec *spec = codec->spec;
3092 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3093 int i, num_cons;
3094 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3095
3096 num_cons = snd_hda_get_connections(codec,
3097 spec->mono_nid,
3098 con_lst,
3099 HDA_MAX_NUM_INPUTS);
3100 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3101 return -EINVAL;
3102
3103 for (i = 0; i < num_cons; i++) {
3104 mono_mux->items[mono_mux->num_items].label =
3105 stac92xx_mono_labels[i];
3106 mono_mux->items[mono_mux->num_items].index = i;
3107 mono_mux->num_items++;
3108 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003109
3110 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3111 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003112}
3113
Matthew Ranostay89385032008-09-11 09:49:39 -04003114/* labels for amp mux outputs */
3115static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003116 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003117};
3118
3119/* create amp out controls mux on capable codecs */
3120static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3121{
3122 struct sigmatel_spec *spec = codec->spec;
3123 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3124 int i, err;
3125
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003126 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003127 amp_mux->items[amp_mux->num_items].label =
3128 stac92xx_amp_labels[i];
3129 amp_mux->items[amp_mux->num_items].index = i;
3130 amp_mux->num_items++;
3131 }
3132
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003133 if (spec->num_amps > 1) {
3134 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3135 "Amp Selector Capture Switch", 0);
3136 if (err < 0)
3137 return err;
3138 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003139 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3140 "Amp Capture Volume",
3141 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3142}
3143
3144
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003145/* create PC beep volume controls */
3146static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3147 hda_nid_t nid)
3148{
3149 struct sigmatel_spec *spec = codec->spec;
3150 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3151 int err;
3152
3153 /* check for mute support for the the amp */
3154 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3155 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3156 "PC Beep Playback Switch",
3157 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3158 if (err < 0)
3159 return err;
3160 }
3161
3162 /* check to see if there is volume support for the amp */
3163 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3164 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3165 "PC Beep Playback Volume",
3166 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3167 if (err < 0)
3168 return err;
3169 }
3170 return 0;
3171}
3172
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003173#ifdef CONFIG_SND_HDA_INPUT_BEEP
3174#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3175
3176static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3177 struct snd_ctl_elem_value *ucontrol)
3178{
3179 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3180 ucontrol->value.integer.value[0] = codec->beep->enabled;
3181 return 0;
3182}
3183
3184static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3185 struct snd_ctl_elem_value *ucontrol)
3186{
3187 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3188 int enabled = !!ucontrol->value.integer.value[0];
3189 if (codec->beep->enabled != enabled) {
3190 codec->beep->enabled = enabled;
3191 return 1;
3192 }
3193 return 0;
3194}
3195
3196static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3197 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3198 .info = stac92xx_dig_beep_switch_info,
3199 .get = stac92xx_dig_beep_switch_get,
3200 .put = stac92xx_dig_beep_switch_put,
3201};
3202
3203static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3204{
3205 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3206 0, "PC Beep Playback Switch", 0);
3207}
3208#endif
3209
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003210static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3211{
3212 struct sigmatel_spec *spec = codec->spec;
3213 int wcaps, nid, i, err = 0;
3214
3215 for (i = 0; i < spec->num_muxes; i++) {
3216 nid = spec->mux_nids[i];
3217 wcaps = get_wcaps(codec, nid);
3218
3219 if (wcaps & AC_WCAP_OUT_AMP) {
3220 err = stac92xx_add_control_idx(spec,
3221 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3222 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3223 if (err < 0)
3224 return err;
3225 }
3226 }
3227 return 0;
3228};
3229
Matthew Ranostayd9737752008-09-07 12:03:41 +02003230static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003231 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003232};
3233
3234static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3235{
3236 struct sigmatel_spec *spec = codec->spec;
3237 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003238 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003239 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003240 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003241
3242 num_cons = snd_hda_get_connections(codec,
3243 spec->smux_nids[0],
3244 con_lst,
3245 HDA_MAX_NUM_INPUTS);
Matthew Ranostay65973632008-09-16 10:39:37 -04003246 if (!num_cons)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003247 return -EINVAL;
3248
Matthew Ranostay65973632008-09-16 10:39:37 -04003249 if (!labels)
3250 labels = stac92xx_spdif_labels;
3251
Matthew Ranostayd9737752008-09-07 12:03:41 +02003252 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003253 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003254 spdif_mux->items[spdif_mux->num_items].index = i;
3255 spdif_mux->num_items++;
3256 }
3257
3258 return 0;
3259}
3260
Matt Porter8b657272006-10-26 17:12:59 +02003261/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003262static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003263 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3264 "Digital Mic 3", "Digital Mic 4"
3265};
3266
3267/* create playback/capture controls for input pins on dmic capable codecs */
3268static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3269 const struct auto_pin_cfg *cfg)
3270{
3271 struct sigmatel_spec *spec = codec->spec;
3272 struct hda_input_mux *dimux = &spec->private_dimux;
3273 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003274 int err, i, j;
3275 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02003276
3277 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3278 dimux->items[dimux->num_items].index = 0;
3279 dimux->num_items++;
3280
3281 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003282 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003283 int index;
3284 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003285 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02003286 unsigned int def_conf;
3287
3288 def_conf = snd_hda_codec_read(codec,
3289 spec->dmic_nids[i],
3290 0,
3291 AC_VERB_GET_CONFIG_DEFAULT,
3292 0);
3293 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3294 continue;
3295
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003296 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02003297 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003298 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02003299 con_lst,
3300 HDA_MAX_NUM_INPUTS);
3301 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003302 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02003303 index = j;
3304 goto found;
3305 }
3306 continue;
3307found:
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003308 wcaps = get_wcaps(codec, nid) &
3309 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003310
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003311 if (wcaps) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003312 sprintf(name, "%s Capture Volume",
3313 stac92xx_dmic_labels[dimux->num_items]);
3314
3315 err = stac92xx_add_control(spec,
3316 STAC_CTL_WIDGET_VOL,
3317 name,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003318 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3319 (wcaps & AC_WCAP_OUT_AMP) ?
3320 HDA_OUTPUT : HDA_INPUT));
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003321 if (err < 0)
3322 return err;
3323 }
3324
Matt Porter8b657272006-10-26 17:12:59 +02003325 dimux->items[dimux->num_items].label =
3326 stac92xx_dmic_labels[dimux->num_items];
3327 dimux->items[dimux->num_items].index = index;
3328 dimux->num_items++;
3329 }
3330
3331 return 0;
3332}
3333
Mattc7d4b2f2005-06-27 14:59:41 +02003334/* create playback/capture controls for input pins */
3335static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3336{
3337 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003338 struct hda_input_mux *imux = &spec->private_imux;
3339 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3340 int i, j, k;
3341
3342 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003343 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02003344
Takashi Iwai314634b2006-09-21 11:56:18 +02003345 if (!cfg->input_pins[i])
3346 continue;
3347 index = -1;
3348 for (j = 0; j < spec->num_muxes; j++) {
3349 int num_cons;
3350 num_cons = snd_hda_get_connections(codec,
3351 spec->mux_nids[j],
3352 con_lst,
3353 HDA_MAX_NUM_INPUTS);
3354 for (k = 0; k < num_cons; k++)
3355 if (con_lst[k] == cfg->input_pins[i]) {
3356 index = k;
3357 goto found;
3358 }
Mattc7d4b2f2005-06-27 14:59:41 +02003359 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003360 continue;
3361 found:
3362 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3363 imux->items[imux->num_items].index = index;
3364 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003365 }
3366
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003367 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003368 /*
3369 * Set the current input for the muxes.
3370 * The STAC9221 has two input muxes with identical source
3371 * NID lists. Hopefully this won't get confused.
3372 */
3373 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003374 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3375 AC_VERB_SET_CONNECT_SEL,
3376 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003377 }
3378 }
3379
Mattc7d4b2f2005-06-27 14:59:41 +02003380 return 0;
3381}
3382
Mattc7d4b2f2005-06-27 14:59:41 +02003383static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3384{
3385 struct sigmatel_spec *spec = codec->spec;
3386 int i;
3387
3388 for (i = 0; i < spec->autocfg.line_outs; i++) {
3389 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3390 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3391 }
3392}
3393
3394static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3395{
3396 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003397 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003398
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003399 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3400 hda_nid_t pin;
3401 pin = spec->autocfg.hp_pins[i];
3402 if (pin) /* connect to front */
3403 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3404 }
3405 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3406 hda_nid_t pin;
3407 pin = spec->autocfg.speaker_pins[i];
3408 if (pin) /* connect to front */
3409 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3410 }
Mattc7d4b2f2005-06-27 14:59:41 +02003411}
3412
Matt Porter3cc08dc2006-01-23 15:27:49 +01003413static 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 +02003414{
3415 struct sigmatel_spec *spec = codec->spec;
3416 int err;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003417 int hp_speaker_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003418
Matt Porter8b657272006-10-26 17:12:59 +02003419 if ((err = snd_hda_parse_pin_def_config(codec,
3420 &spec->autocfg,
3421 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003422 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003423 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003424 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003425
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003426 /* If we have no real line-out pin and multiple hp-outs, HPs should
3427 * be set up as multi-channel outputs.
3428 */
3429 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3430 spec->autocfg.hp_outs > 1) {
3431 /* Copy hp_outs to line_outs, backup line_outs in
3432 * speaker_outs so that the following routines can handle
3433 * HP pins as primary outputs.
3434 */
3435 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3436 sizeof(spec->autocfg.line_out_pins));
3437 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3438 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3439 sizeof(spec->autocfg.hp_pins));
3440 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3441 hp_speaker_swap = 1;
3442 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003443 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003444 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3445 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003446 u32 caps = query_amp_caps(codec,
3447 spec->autocfg.mono_out_pin, dir);
3448 hda_nid_t conn_list[1];
3449
3450 /* get the mixer node and then the mono mux if it exists */
3451 if (snd_hda_get_connections(codec,
3452 spec->autocfg.mono_out_pin, conn_list, 1) &&
3453 snd_hda_get_connections(codec, conn_list[0],
3454 conn_list, 1)) {
3455
3456 int wcaps = get_wcaps(codec, conn_list[0]);
3457 int wid_type = (wcaps & AC_WCAP_TYPE)
3458 >> AC_WCAP_TYPE_SHIFT;
3459 /* LR swap check, some stac925x have a mux that
3460 * changes the DACs output path instead of the
3461 * mono-mux path.
3462 */
3463 if (wid_type == AC_WID_AUD_SEL &&
3464 !(wcaps & AC_WCAP_LR_SWAP))
3465 spec->mono_nid = conn_list[0];
3466 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003467 if (dir) {
3468 hda_nid_t nid = spec->autocfg.mono_out_pin;
3469
3470 /* most mono outs have a least a mute/unmute switch */
3471 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3472 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3473 "Mono Playback Switch",
3474 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003475 if (err < 0)
3476 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003477 /* check for volume support for the amp */
3478 if ((caps & AC_AMPCAP_NUM_STEPS)
3479 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3480 err = stac92xx_add_control(spec,
3481 STAC_CTL_WIDGET_VOL,
3482 "Mono Playback Volume",
3483 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3484 if (err < 0)
3485 return err;
3486 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003487 }
3488
3489 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3490 AC_PINCTL_OUT_EN);
3491 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003492
Matt Porter403d1942005-11-29 15:00:51 +01003493 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
3494 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003495 if (spec->multiout.num_dacs == 0)
3496 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3497 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003498
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003499 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
3500
3501 if (err < 0)
3502 return err;
3503
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003504 /* setup analog beep controls */
3505 if (spec->anabeep_nid > 0) {
3506 err = stac92xx_auto_create_beep_ctls(codec,
3507 spec->anabeep_nid);
3508 if (err < 0)
3509 return err;
3510 }
3511
3512 /* setup digital beep controls and input device */
3513#ifdef CONFIG_SND_HDA_INPUT_BEEP
3514 if (spec->digbeep_nid > 0) {
3515 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003516 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003517
3518 err = stac92xx_auto_create_beep_ctls(codec, nid);
3519 if (err < 0)
3520 return err;
3521 err = snd_hda_attach_beep_device(codec, nid);
3522 if (err < 0)
3523 return err;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003524 /* if no beep switch is available, make its own one */
3525 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3526 if (codec->beep &&
3527 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3528 err = stac92xx_beep_switch_ctl(codec);
3529 if (err < 0)
3530 return err;
3531 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003532 }
3533#endif
3534
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003535 if (hp_speaker_swap == 1) {
3536 /* Restore the hp_outs and line_outs */
3537 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3538 sizeof(spec->autocfg.line_out_pins));
3539 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3540 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
3541 sizeof(spec->autocfg.speaker_pins));
3542 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
3543 memset(spec->autocfg.speaker_pins, 0,
3544 sizeof(spec->autocfg.speaker_pins));
3545 spec->autocfg.speaker_outs = 0;
3546 }
3547
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003548 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3549
3550 if (err < 0)
3551 return err;
3552
3553 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3554
3555 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003556 return err;
3557
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003558 if (spec->mono_nid > 0) {
3559 err = stac92xx_auto_create_mono_output_ctls(codec);
3560 if (err < 0)
3561 return err;
3562 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003563 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003564 err = stac92xx_auto_create_amp_output_ctls(codec);
3565 if (err < 0)
3566 return err;
3567 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003568 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003569 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3570 &spec->autocfg)) < 0)
3571 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003572 if (spec->num_muxes > 0) {
3573 err = stac92xx_auto_create_mux_input_ctls(codec);
3574 if (err < 0)
3575 return err;
3576 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003577 if (spec->num_smuxes > 0) {
3578 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3579 if (err < 0)
3580 return err;
3581 }
Matt Porter8b657272006-10-26 17:12:59 +02003582
Mattc7d4b2f2005-06-27 14:59:41 +02003583 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003584 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003585 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003586
Takashi Iwai82bc9552006-03-21 11:24:42 +01003587 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003588 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003589 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003590 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003591
Takashi Iwai603c4012008-07-30 15:01:44 +02003592 if (spec->kctls.list)
3593 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003594
3595 spec->input_mux = &spec->private_imux;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003596 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003597 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003598 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04003599 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003600 return 1;
3601}
3602
Takashi Iwai82bc9552006-03-21 11:24:42 +01003603/* add playback controls for HP output */
3604static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3605 struct auto_pin_cfg *cfg)
3606{
3607 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003608 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003609 unsigned int wid_caps;
3610
3611 if (! pin)
3612 return 0;
3613
3614 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003615 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003616 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003617
3618 return 0;
3619}
3620
Richard Fish160ea0d2006-09-06 13:58:25 +02003621/* add playback controls for LFE output */
3622static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3623 struct auto_pin_cfg *cfg)
3624{
3625 struct sigmatel_spec *spec = codec->spec;
3626 int err;
3627 hda_nid_t lfe_pin = 0x0;
3628 int i;
3629
3630 /*
3631 * search speaker outs and line outs for a mono speaker pin
3632 * with an amp. If one is found, add LFE controls
3633 * for it.
3634 */
3635 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3636 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003637 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003638 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3639 if (wcaps == AC_WCAP_OUT_AMP)
3640 /* found a mono speaker with an amp, must be lfe */
3641 lfe_pin = pin;
3642 }
3643
3644 /* if speaker_outs is 0, then speakers may be in line_outs */
3645 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3646 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3647 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003648 unsigned int defcfg;
Harvey Harrison8b551782008-02-29 11:56:48 +01003649 defcfg = snd_hda_codec_read(codec, pin, 0,
Richard Fish160ea0d2006-09-06 13:58:25 +02003650 AC_VERB_GET_CONFIG_DEFAULT,
3651 0x00);
Harvey Harrison8b551782008-02-29 11:56:48 +01003652 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003653 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003654 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3655 if (wcaps == AC_WCAP_OUT_AMP)
3656 /* found a mono speaker with an amp,
3657 must be lfe */
3658 lfe_pin = pin;
3659 }
3660 }
3661 }
3662
3663 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003664 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003665 if (err < 0)
3666 return err;
3667 }
3668
3669 return 0;
3670}
3671
Mattc7d4b2f2005-06-27 14:59:41 +02003672static int stac9200_parse_auto_config(struct hda_codec *codec)
3673{
3674 struct sigmatel_spec *spec = codec->spec;
3675 int err;
3676
Kailang Yangdf694da2005-12-05 19:42:22 +01003677 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003678 return err;
3679
3680 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3681 return err;
3682
Takashi Iwai82bc9552006-03-21 11:24:42 +01003683 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3684 return err;
3685
Richard Fish160ea0d2006-09-06 13:58:25 +02003686 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3687 return err;
3688
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003689 if (spec->num_muxes > 0) {
3690 err = stac92xx_auto_create_mux_input_ctls(codec);
3691 if (err < 0)
3692 return err;
3693 }
3694
Takashi Iwai82bc9552006-03-21 11:24:42 +01003695 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003696 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003697 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003698 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003699
Takashi Iwai603c4012008-07-30 15:01:44 +02003700 if (spec->kctls.list)
3701 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003702
3703 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003704 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003705
3706 return 1;
3707}
3708
Sam Revitch62fe78e2006-05-10 15:09:17 +02003709/*
3710 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3711 * funky external mute control using GPIO pins.
3712 */
3713
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003714static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003715 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003716{
3717 unsigned int gpiostate, gpiomask, gpiodir;
3718
3719 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3720 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003721 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003722
3723 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3724 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003725 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003726
3727 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3728 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003729 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003730
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003731 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003732 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3733
3734 snd_hda_codec_write(codec, codec->afg, 0,
3735 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003736 snd_hda_codec_read(codec, codec->afg, 0,
3737 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003738
3739 msleep(1);
3740
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003741 snd_hda_codec_read(codec, codec->afg, 0,
3742 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003743}
3744
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003745static int stac92xx_add_jack(struct hda_codec *codec,
3746 hda_nid_t nid, int type)
3747{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003748#ifdef CONFIG_SND_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003749 struct sigmatel_spec *spec = codec->spec;
3750 struct sigmatel_jack *jack;
3751 int def_conf = snd_hda_codec_read(codec, nid,
3752 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
3753 int connectivity = get_defcfg_connect(def_conf);
3754 char name[32];
3755
3756 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3757 return 0;
3758
3759 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3760 jack = snd_array_new(&spec->jacks);
3761 if (!jack)
3762 return -ENOMEM;
3763 jack->nid = nid;
3764 jack->type = type;
3765
3766 sprintf(name, "%s at %s %s Jack",
3767 snd_hda_get_jack_type(def_conf),
3768 snd_hda_get_jack_connectivity(def_conf),
3769 snd_hda_get_jack_location(def_conf));
3770
3771 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003772#else
3773 return 0;
3774#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003775}
3776
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003777static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3778 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003779{
3780 struct sigmatel_event *event;
3781
3782 snd_array_init(&spec->events, sizeof(*event), 32);
3783 event = snd_array_new(&spec->events);
3784 if (!event)
3785 return -ENOMEM;
3786 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003787 event->type = type;
3788 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003789 event->data = data;
3790
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003791 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003792}
3793
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003794static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
3795 hda_nid_t nid, unsigned char type)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003796{
3797 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003798 struct sigmatel_event *event = spec->events.list;
3799 int i;
3800
3801 for (i = 0; i < spec->events.used; i++, event++) {
3802 if (event->nid == nid && event->type == type)
3803 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003804 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003805 return NULL;
3806}
3807
3808static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
3809 unsigned char tag)
3810{
3811 struct sigmatel_spec *spec = codec->spec;
3812 struct sigmatel_event *event = spec->events.list;
3813 int i;
3814
3815 for (i = 0; i < spec->events.used; i++, event++) {
3816 if (event->tag == tag)
3817 return event;
3818 }
3819 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003820}
3821
Takashi Iwai314634b2006-09-21 11:56:18 +02003822static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003823 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02003824{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003825 struct sigmatel_event *event;
3826 int tag;
3827
3828 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
3829 return;
3830 event = stac_get_event(codec, nid, type);
3831 if (event)
3832 tag = event->tag;
3833 else
3834 tag = stac_add_event(codec->spec, nid, type, 0);
3835 if (tag < 0)
3836 return;
3837 snd_hda_codec_write_cache(codec, nid, 0,
3838 AC_VERB_SET_UNSOLICITED_ENABLE,
3839 AC_USRSP_EN | tag);
Takashi Iwai314634b2006-09-21 11:56:18 +02003840}
3841
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003842static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3843{
3844 int i;
3845 for (i = 0; i < cfg->hp_outs; i++)
3846 if (cfg->hp_pins[i] == nid)
3847 return 1; /* nid is a HP-Out */
3848
3849 return 0; /* nid is not a HP-Out */
3850};
3851
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003852static void stac92xx_power_down(struct hda_codec *codec)
3853{
3854 struct sigmatel_spec *spec = codec->spec;
3855
3856 /* power down inactive DACs */
3857 hda_nid_t *dac;
3858 for (dac = spec->dac_list; *dac; dac++)
Matthew Ranostay44510892008-02-21 07:49:31 +01003859 if (!is_in_dac_nids(spec, *dac) &&
3860 spec->multiout.hp_nid != *dac)
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003861 snd_hda_codec_write_cache(codec, *dac, 0,
3862 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3863}
3864
Takashi Iwaif73d3582008-11-25 08:21:51 +01003865static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3866 int enable);
3867
Mattc7d4b2f2005-06-27 14:59:41 +02003868static int stac92xx_init(struct hda_codec *codec)
3869{
3870 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003871 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01003872 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01003873 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003874
Mattc7d4b2f2005-06-27 14:59:41 +02003875 snd_hda_sequence_write(codec, spec->init);
3876
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02003877 /* power down adcs initially */
3878 if (spec->powerdown_adcs)
3879 for (i = 0; i < spec->num_adcs; i++)
3880 snd_hda_codec_write_cache(codec,
3881 spec->adc_nids[i], 0,
3882 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003883
3884 /* set up GPIO */
3885 gpio = spec->gpio_data;
3886 /* turn on EAPD statically when spec->eapd_switch isn't set.
3887 * otherwise, unsol event will turn it on/off dynamically
3888 */
3889 if (!spec->eapd_switch)
3890 gpio |= spec->eapd_mask;
3891 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
3892
Takashi Iwai82bc9552006-03-21 11:24:42 +01003893 /* set up pins */
3894 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02003895 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003896 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003897 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003898 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003899 }
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01003900 /* force to enable the first line-out; the others are set up
3901 * in unsol_event
3902 */
3903 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003904 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003905 /* fake event to set up pins */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003906 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
3907 STAC_HP_EVENT);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003908 } else {
3909 stac92xx_auto_init_multi_out(codec);
3910 stac92xx_auto_init_hp_out(codec);
3911 }
3912 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01003913 hda_nid_t nid = cfg->input_pins[i];
3914 if (nid) {
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01003915 unsigned int pinctl;
3916 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
3917 /* for mic pins, force to initialize */
3918 pinctl = stac92xx_get_vref(codec, nid);
3919 } else {
3920 pinctl = snd_hda_codec_read(codec, nid, 0,
3921 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3922 /* if PINCTL already set then skip */
3923 if (pinctl & AC_PINCTL_IN_EN)
3924 continue;
3925 }
3926 pinctl |= AC_PINCTL_IN_EN;
Takashi Iwaic960a032006-03-23 17:06:28 +01003927 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003928 enable_pin_detect(codec, nid, STAC_INSERT_EVENT);
Takashi Iwaic960a032006-03-23 17:06:28 +01003929 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01003930 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003931 for (i = 0; i < spec->num_dmics; i++)
3932 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
3933 AC_PINCTL_IN_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003934 if (cfg->dig_out_pin)
3935 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
3936 AC_PINCTL_OUT_EN);
3937 if (cfg->dig_in_pin)
3938 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
3939 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003940 for (i = 0; i < spec->num_pwrs; i++) {
3941 hda_nid_t nid = spec->pwr_nids[i];
3942 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003943
Takashi Iwaif73d3582008-11-25 08:21:51 +01003944 if (is_nid_hp_pin(cfg, nid) && spec->hp_detect)
3945 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003946
Takashi Iwaif73d3582008-11-25 08:21:51 +01003947 pinctl = snd_hda_codec_read(codec, nid, 0,
3948 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3949 /* outputs are only ports capable of power management
3950 * any attempts on powering down a input port cause the
3951 * referenced VREF to act quirky.
3952 */
3953 if (pinctl & AC_PINCTL_IN_EN)
3954 continue;
3955 def_conf = snd_hda_codec_read(codec, nid, 0,
3956 AC_VERB_GET_CONFIG_DEFAULT, 0);
3957 def_conf = get_defcfg_connect(def_conf);
3958 /* skip any ports that don't have jacks since presence
3959 * detection is useless */
3960 if (def_conf != AC_JACK_PORT_COMPLEX) {
3961 if (def_conf != AC_JACK_PORT_NONE)
3962 stac_toggle_power_map(codec, nid, 1);
3963 continue;
3964 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003965 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
3966 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003967 }
3968 if (spec->dac_list)
3969 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02003970 return 0;
3971}
3972
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003973static void stac92xx_free_jacks(struct hda_codec *codec)
3974{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003975#ifdef CONFIG_SND_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01003976 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003977 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01003978 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003979 struct sigmatel_jack *jacks = spec->jacks.list;
3980 int i;
3981 for (i = 0; i < spec->jacks.used; i++)
3982 snd_device_free(codec->bus->card, &jacks[i].jack);
3983 }
3984 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003985#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003986}
3987
Takashi Iwai603c4012008-07-30 15:01:44 +02003988static void stac92xx_free_kctls(struct hda_codec *codec)
3989{
3990 struct sigmatel_spec *spec = codec->spec;
3991
3992 if (spec->kctls.list) {
3993 struct snd_kcontrol_new *kctl = spec->kctls.list;
3994 int i;
3995 for (i = 0; i < spec->kctls.used; i++)
3996 kfree(kctl[i].name);
3997 }
3998 snd_array_free(&spec->kctls);
3999}
4000
Matt2f2f4252005-04-13 14:45:30 +02004001static void stac92xx_free(struct hda_codec *codec)
4002{
Mattc7d4b2f2005-06-27 14:59:41 +02004003 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004004
4005 if (! spec)
4006 return;
4007
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004008 kfree(spec->pin_configs);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004009 stac92xx_free_jacks(codec);
4010 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004011
Mattc7d4b2f2005-06-27 14:59:41 +02004012 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004013 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004014}
4015
Matt4e550962005-07-04 17:51:39 +02004016static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4017 unsigned int flag)
4018{
4019 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4020 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004021
Takashi Iwaif9acba42007-05-29 18:01:06 +02004022 if (pin_ctl & AC_PINCTL_IN_EN) {
4023 /*
4024 * we need to check the current set-up direction of
4025 * shared input pins since they can be switched via
4026 * "xxx as Output" mixer switch
4027 */
4028 struct sigmatel_spec *spec = codec->spec;
4029 struct auto_pin_cfg *cfg = &spec->autocfg;
4030 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
4031 spec->line_switch) ||
4032 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
4033 spec->mic_switch))
4034 return;
4035 }
4036
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004037 /* if setting pin direction bits, clear the current
4038 direction bits first */
4039 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4040 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4041
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004042 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02004043 AC_VERB_SET_PIN_WIDGET_CONTROL,
4044 pin_ctl | flag);
4045}
4046
4047static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4048 unsigned int flag)
4049{
4050 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4051 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004052 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02004053 AC_VERB_SET_PIN_WIDGET_CONTROL,
4054 pin_ctl & ~flag);
4055}
4056
Jiang Zhe40c1d302007-11-12 13:05:16 +01004057static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004058{
4059 if (!nid)
4060 return 0;
4061 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Jiang Zhe40c1d302007-11-12 13:05:16 +01004062 & (1 << 31)) {
4063 unsigned int pinctl;
4064 pinctl = snd_hda_codec_read(codec, nid, 0,
4065 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4066 if (pinctl & AC_PINCTL_IN_EN)
4067 return 0; /* mic- or line-input */
4068 else
4069 return 1; /* HP-output */
4070 }
Takashi Iwai314634b2006-09-21 11:56:18 +02004071 return 0;
4072}
4073
Takashi Iwaid7a89432008-11-12 09:48:04 +01004074/* return non-zero if the hp-pin of the given array index isn't
4075 * a jack-detection target
4076 */
4077static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4078{
4079 struct auto_pin_cfg *cfg = &spec->autocfg;
4080
4081 /* ignore sensing of shared line and mic jacks */
4082 if (spec->line_switch &&
4083 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_LINE])
4084 return 1;
4085 if (spec->mic_switch &&
4086 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_MIC])
4087 return 1;
4088 /* ignore if the pin is set as line-out */
4089 if (cfg->hp_pins[i] == spec->hp_switch)
4090 return 1;
4091 return 0;
4092}
4093
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004094static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004095{
4096 struct sigmatel_spec *spec = codec->spec;
4097 struct auto_pin_cfg *cfg = &spec->autocfg;
4098 int i, presence;
4099
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004100 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004101 if (spec->gpio_mute)
4102 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4103 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4104
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004105 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004106 if (presence)
4107 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004108 if (no_hp_sensing(spec, i))
4109 continue;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004110 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004111 }
Matt4e550962005-07-04 17:51:39 +02004112
4113 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004114 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004115 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004116 stac92xx_reset_pinctl(codec, spec->hp_switch,
4117 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004118 for (i = 0; i < cfg->line_outs; i++)
4119 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4120 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004121 for (i = 0; i < cfg->speaker_outs; i++)
4122 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4123 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004124 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004125 stac_gpio_set(codec, spec->gpio_mask,
4126 spec->gpio_dir, spec->gpio_data &
4127 ~spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004128 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004129 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004130 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004131 stac92xx_set_pinctl(codec, spec->hp_switch,
4132 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004133 for (i = 0; i < cfg->line_outs; i++)
4134 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4135 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004136 for (i = 0; i < cfg->speaker_outs; i++)
4137 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4138 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004139 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004140 stac_gpio_set(codec, spec->gpio_mask,
4141 spec->gpio_dir, spec->gpio_data |
4142 spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004143 }
Takashi Iwaid7a89432008-11-12 09:48:04 +01004144 /* toggle hp outs */
4145 for (i = 0; i < cfg->hp_outs; i++) {
4146 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4147 if (no_hp_sensing(spec, i))
4148 continue;
4149 if (presence)
4150 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4151 else
4152 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4153 }
Matt4e550962005-07-04 17:51:39 +02004154}
4155
Takashi Iwaif73d3582008-11-25 08:21:51 +01004156static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4157 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004158{
4159 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004160 unsigned int idx, val;
4161
4162 for (idx = 0; idx < spec->num_pwrs; idx++) {
4163 if (spec->pwr_nids[idx] == nid)
4164 break;
4165 }
4166 if (idx >= spec->num_pwrs)
4167 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004168
4169 /* several codecs have two power down bits */
4170 if (spec->pwr_mapping)
4171 idx = spec->pwr_mapping[idx];
4172 else
4173 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004174
Takashi Iwaif73d3582008-11-25 08:21:51 +01004175 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4176 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004177 val &= ~idx;
4178 else
4179 val |= idx;
4180
4181 /* power down unused output ports */
4182 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004183}
4184
Takashi Iwaif73d3582008-11-25 08:21:51 +01004185static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4186{
4187 stac_toggle_power_map(codec, nid, get_hp_pin_presence(codec, nid));
4188}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004189
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004190static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4191{
4192 struct sigmatel_spec *spec = codec->spec;
4193 struct sigmatel_jack *jacks = spec->jacks.list;
4194
4195 if (jacks) {
4196 int i;
4197 for (i = 0; i < spec->jacks.used; i++) {
4198 if (jacks->nid == nid) {
4199 unsigned int pin_ctl =
4200 snd_hda_codec_read(codec, nid,
4201 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4202 0x00);
4203 int type = jacks->type;
4204 if (type == (SND_JACK_LINEOUT
4205 | SND_JACK_HEADPHONE))
4206 type = (pin_ctl & AC_PINCTL_HP_EN)
4207 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4208 snd_jack_report(jacks->jack,
4209 get_hp_pin_presence(codec, nid)
4210 ? type : 0);
4211 }
4212 jacks++;
4213 }
4214 }
4215}
Matt2f2f4252005-04-13 14:45:30 +02004216
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004217static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4218 unsigned char type)
4219{
4220 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4221 if (!event)
4222 return;
4223 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4224}
4225
Takashi Iwai314634b2006-09-21 11:56:18 +02004226static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4227{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004228 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004229 struct sigmatel_event *event;
4230 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004231
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004232 tag = (res >> 26) & 0x7f;
4233 event = stac_get_event_from_tag(codec, tag);
4234 if (!event)
4235 return;
4236
4237 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004238 case STAC_HP_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004239 stac92xx_hp_detect(codec);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004240 /* fallthru */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004241 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004242 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004243 if (spec->num_pwrs > 0)
4244 stac92xx_pin_sense(codec, event->nid);
4245 stac92xx_report_jack(codec, event->nid);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004246 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004247 case STAC_VREF_EVENT:
4248 data = snd_hda_codec_read(codec, codec->afg, 0,
4249 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004250 /* toggle VREF state based on GPIOx status */
4251 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004252 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004253 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004254 }
4255}
4256
Takashi Iwaicb53c622007-08-10 17:21:45 +02004257#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004258static int stac92xx_resume(struct hda_codec *codec)
4259{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004260 struct sigmatel_spec *spec = codec->spec;
4261
Richard Fish11b44bb2006-08-23 18:31:34 +02004262 stac92xx_set_config_regs(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004263 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004264 snd_hda_codec_resume_amp(codec);
4265 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004266 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004267 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004268 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4269 STAC_HP_EVENT);
Mattff6fdc32005-06-27 15:06:52 +02004270 return 0;
4271}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004272
4273static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4274{
4275 struct sigmatel_spec *spec = codec->spec;
4276 if (spec->eapd_mask)
4277 stac_gpio_set(codec, spec->gpio_mask,
4278 spec->gpio_dir, spec->gpio_data &
4279 ~spec->eapd_mask);
4280 return 0;
4281}
Mattff6fdc32005-06-27 15:06:52 +02004282#endif
4283
Matt2f2f4252005-04-13 14:45:30 +02004284static struct hda_codec_ops stac92xx_patch_ops = {
4285 .build_controls = stac92xx_build_controls,
4286 .build_pcms = stac92xx_build_pcms,
4287 .init = stac92xx_init,
4288 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004289 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004290#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004291 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004292 .resume = stac92xx_resume,
4293#endif
Matt2f2f4252005-04-13 14:45:30 +02004294};
4295
4296static int patch_stac9200(struct hda_codec *codec)
4297{
4298 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004299 int err;
Matt2f2f4252005-04-13 14:45:30 +02004300
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004301 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004302 if (spec == NULL)
4303 return -ENOMEM;
4304
4305 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004306 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004307 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004308 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4309 stac9200_models,
4310 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02004311 if (spec->board_config < 0) {
4312 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4313 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004314 } else
4315 err = stac_save_pin_cfgs(codec,
4316 stac9200_brd_tbl[spec->board_config]);
4317 if (err < 0) {
4318 stac92xx_free(codec);
4319 return err;
Matt Porter403d1942005-11-29 15:00:51 +01004320 }
Matt2f2f4252005-04-13 14:45:30 +02004321
4322 spec->multiout.max_channels = 2;
4323 spec->multiout.num_dacs = 1;
4324 spec->multiout.dac_nids = stac9200_dac_nids;
4325 spec->adc_nids = stac9200_adc_nids;
4326 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004327 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004328 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004329 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004330 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004331
Tobin Davisbf277782008-02-03 20:31:47 +01004332 if (spec->board_config == STAC_9200_GATEWAY ||
4333 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004334 spec->init = stac9200_eapd_init;
4335 else
4336 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004337 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004338
Takashi Iwai117f2572008-03-18 09:53:23 +01004339 if (spec->board_config == STAC_9200_PANASONIC) {
4340 spec->gpio_mask = spec->gpio_dir = 0x09;
4341 spec->gpio_data = 0x00;
4342 }
4343
Mattc7d4b2f2005-06-27 14:59:41 +02004344 err = stac9200_parse_auto_config(codec);
4345 if (err < 0) {
4346 stac92xx_free(codec);
4347 return err;
4348 }
Matt2f2f4252005-04-13 14:45:30 +02004349
4350 codec->patch_ops = stac92xx_patch_ops;
4351
4352 return 0;
4353}
4354
Tobin Davis8e21c342007-01-08 11:04:17 +01004355static int patch_stac925x(struct hda_codec *codec)
4356{
4357 struct sigmatel_spec *spec;
4358 int err;
4359
4360 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4361 if (spec == NULL)
4362 return -ENOMEM;
4363
4364 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004365 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004366 spec->pin_nids = stac925x_pin_nids;
4367 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
4368 stac925x_models,
4369 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004370 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01004371 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02004372 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
4373 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01004374 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004375 } else
4376 err = stac_save_pin_cfgs(codec,
4377 stac925x_brd_tbl[spec->board_config]);
4378 if (err < 0) {
4379 stac92xx_free(codec);
4380 return err;
Tobin Davis8e21c342007-01-08 11:04:17 +01004381 }
4382
4383 spec->multiout.max_channels = 2;
4384 spec->multiout.num_dacs = 1;
4385 spec->multiout.dac_nids = stac925x_dac_nids;
4386 spec->adc_nids = stac925x_adc_nids;
4387 spec->mux_nids = stac925x_mux_nids;
4388 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004389 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004390 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004391 switch (codec->vendor_id) {
4392 case 0x83847632: /* STAC9202 */
4393 case 0x83847633: /* STAC9202D */
4394 case 0x83847636: /* STAC9251 */
4395 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004396 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004397 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004398 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4399 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004400 break;
4401 default:
4402 spec->num_dmics = 0;
4403 break;
4404 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004405
4406 spec->init = stac925x_core_init;
4407 spec->mixer = stac925x_mixer;
4408
4409 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004410 if (!err) {
4411 if (spec->board_config < 0) {
4412 printk(KERN_WARNING "hda_codec: No auto-config is "
4413 "available, default to model=ref\n");
4414 spec->board_config = STAC_925x_REF;
4415 goto again;
4416 }
4417 err = -EINVAL;
4418 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004419 if (err < 0) {
4420 stac92xx_free(codec);
4421 return err;
4422 }
4423
4424 codec->patch_ops = stac92xx_patch_ops;
4425
4426 return 0;
4427}
4428
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004429static struct hda_input_mux stac92hd73xx_dmux = {
4430 .num_items = 4,
4431 .items = {
4432 { "Analog Inputs", 0x0b },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004433 { "Digital Mic 1", 0x09 },
4434 { "Digital Mic 2", 0x0a },
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004435 { "CD", 0x08 },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004436 }
4437};
4438
4439static int patch_stac92hd73xx(struct hda_codec *codec)
4440{
4441 struct sigmatel_spec *spec;
4442 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4443 int err = 0;
4444
4445 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4446 if (spec == NULL)
4447 return -ENOMEM;
4448
4449 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004450 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004451 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4452 spec->pin_nids = stac92hd73xx_pin_nids;
4453 spec->board_config = snd_hda_check_board_config(codec,
4454 STAC_92HD73XX_MODELS,
4455 stac92hd73xx_models,
4456 stac92hd73xx_cfg_tbl);
4457again:
4458 if (spec->board_config < 0) {
4459 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4460 " STAC92HD73XX, using BIOS defaults\n");
4461 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004462 } else
4463 err = stac_save_pin_cfgs(codec,
4464 stac92hd73xx_brd_tbl[spec->board_config]);
4465 if (err < 0) {
4466 stac92xx_free(codec);
4467 return err;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004468 }
4469
4470 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
4471 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4472
4473 if (spec->multiout.num_dacs < 0) {
4474 printk(KERN_WARNING "hda_codec: Could not determine "
4475 "number of channels defaulting to DAC count\n");
4476 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
4477 }
4478
4479 switch (spec->multiout.num_dacs) {
4480 case 0x3: /* 6 Channel */
4481 spec->mixer = stac92hd73xx_6ch_mixer;
4482 spec->init = stac92hd73xx_6ch_core_init;
4483 break;
4484 case 0x4: /* 8 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004485 spec->mixer = stac92hd73xx_8ch_mixer;
4486 spec->init = stac92hd73xx_8ch_core_init;
4487 break;
4488 case 0x5: /* 10 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004489 spec->mixer = stac92hd73xx_10ch_mixer;
4490 spec->init = stac92hd73xx_10ch_core_init;
4491 };
4492
4493 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
4494 spec->aloopback_mask = 0x01;
4495 spec->aloopback_shift = 8;
4496
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004497 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004498 spec->mux_nids = stac92hd73xx_mux_nids;
4499 spec->adc_nids = stac92hd73xx_adc_nids;
4500 spec->dmic_nids = stac92hd73xx_dmic_nids;
4501 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004502 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04004503 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004504 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004505
4506 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4507 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01004508 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004509 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4510 sizeof(stac92hd73xx_dmux));
4511
Matthew Ranostaya7662642008-02-21 07:51:14 +01004512 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004513 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004514 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004515 /* fallthru */
4516 case STAC_DELL_M6:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004517 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004518 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4519 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004520 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004521 spec->num_amps = 1;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004522
4523 if (!spec->init)
4524 spec->init = dell_m6_core_init;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004525 switch (codec->subsystem_id) {
4526 case 0x1028025e: /* Analog Mics */
4527 case 0x1028025f:
4528 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4529 spec->num_dmics = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004530 spec->private_dimux.num_items = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004531 break;
Matthew Ranostayd654a662008-03-14 08:46:51 +01004532 case 0x10280271: /* Digital Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004533 case 0x10280272:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004534 case 0x10280254:
4535 case 0x10280255:
Matthew Ranostaya7662642008-02-21 07:51:14 +01004536 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4537 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004538 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004539 break;
4540 case 0x10280256: /* Both */
4541 case 0x10280057:
4542 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4543 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4544 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004545 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004546 break;
4547 }
4548 break;
4549 default:
4550 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004551 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004552 spec->eapd_switch = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004553 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04004554 if (spec->board_config > STAC_92HD73XX_REF) {
4555 /* GPIO0 High = Enable EAPD */
4556 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4557 spec->gpio_data = 0x01;
4558 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004559 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004560
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004561 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4562 spec->pwr_nids = stac92hd73xx_pwr_nids;
4563
Matthew Ranostayd9737752008-09-07 12:03:41 +02004564 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004565
4566 if (!err) {
4567 if (spec->board_config < 0) {
4568 printk(KERN_WARNING "hda_codec: No auto-config is "
4569 "available, default to model=ref\n");
4570 spec->board_config = STAC_92HD73XX_REF;
4571 goto again;
4572 }
4573 err = -EINVAL;
4574 }
4575
4576 if (err < 0) {
4577 stac92xx_free(codec);
4578 return err;
4579 }
4580
4581 codec->patch_ops = stac92xx_patch_ops;
4582
4583 return 0;
4584}
4585
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004586static struct hda_input_mux stac92hd83xxx_dmux = {
4587 .num_items = 3,
4588 .items = {
4589 { "Analog Inputs", 0x03 },
4590 { "Digital Mic 1", 0x04 },
4591 { "Digital Mic 2", 0x05 },
4592 }
4593};
4594
4595static int patch_stac92hd83xxx(struct hda_codec *codec)
4596{
4597 struct sigmatel_spec *spec;
4598 int err;
4599
4600 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4601 if (spec == NULL)
4602 return -ENOMEM;
4603
4604 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004605 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004606 spec->mono_nid = 0x19;
4607 spec->digbeep_nid = 0x21;
4608 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4609 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4610 spec->adc_nids = stac92hd83xxx_adc_nids;
4611 spec->pwr_nids = stac92hd83xxx_pwr_nids;
4612 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4613 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
4614 spec->multiout.dac_nids = stac92hd83xxx_dac_nids;
4615
4616 spec->init = stac92hd83xxx_core_init;
4617 switch (codec->vendor_id) {
4618 case 0x111d7605:
4619 spec->multiout.num_dacs = STAC92HD81_DAC_COUNT;
4620 break;
4621 default:
4622 spec->num_pwrs--;
4623 spec->init++; /* switch to config #2 */
4624 spec->multiout.num_dacs = STAC92HD83_DAC_COUNT;
4625 }
4626
4627 spec->mixer = stac92hd83xxx_mixer;
4628 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4629 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4630 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
4631 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4632 spec->dinput_mux = &stac92hd83xxx_dmux;
4633 spec->pin_nids = stac92hd83xxx_pin_nids;
4634 spec->board_config = snd_hda_check_board_config(codec,
4635 STAC_92HD83XXX_MODELS,
4636 stac92hd83xxx_models,
4637 stac92hd83xxx_cfg_tbl);
4638again:
4639 if (spec->board_config < 0) {
4640 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4641 " STAC92HD83XXX, using BIOS defaults\n");
4642 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004643 } else
4644 err = stac_save_pin_cfgs(codec,
4645 stac92hd83xxx_brd_tbl[spec->board_config]);
4646 if (err < 0) {
4647 stac92xx_free(codec);
4648 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004649 }
4650
4651 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4652 if (!err) {
4653 if (spec->board_config < 0) {
4654 printk(KERN_WARNING "hda_codec: No auto-config is "
4655 "available, default to model=ref\n");
4656 spec->board_config = STAC_92HD83XXX_REF;
4657 goto again;
4658 }
4659 err = -EINVAL;
4660 }
4661
4662 if (err < 0) {
4663 stac92xx_free(codec);
4664 return err;
4665 }
4666
4667 codec->patch_ops = stac92xx_patch_ops;
4668
4669 return 0;
4670}
4671
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004672#ifdef SND_HDA_NEEDS_RESUME
4673static void stac92hd71xx_set_power_state(struct hda_codec *codec, int pwr)
4674{
4675 struct sigmatel_spec *spec = codec->spec;
4676 int i;
4677 snd_hda_codec_write_cache(codec, codec->afg, 0,
4678 AC_VERB_SET_POWER_STATE, pwr);
4679
4680 msleep(1);
4681 for (i = 0; i < spec->num_adcs; i++) {
4682 snd_hda_codec_write_cache(codec,
4683 spec->adc_nids[i], 0,
4684 AC_VERB_SET_POWER_STATE, pwr);
4685 }
4686};
4687
4688static int stac92hd71xx_resume(struct hda_codec *codec)
4689{
4690 stac92hd71xx_set_power_state(codec, AC_PWRST_D0);
4691 return stac92xx_resume(codec);
4692}
4693
4694static int stac92hd71xx_suspend(struct hda_codec *codec, pm_message_t state)
4695{
4696 stac92hd71xx_set_power_state(codec, AC_PWRST_D3);
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004697 return stac92xx_suspend(codec, state);
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004698};
4699
4700#endif
4701
4702static struct hda_codec_ops stac92hd71bxx_patch_ops = {
4703 .build_controls = stac92xx_build_controls,
4704 .build_pcms = stac92xx_build_pcms,
4705 .init = stac92xx_init,
4706 .free = stac92xx_free,
4707 .unsol_event = stac92xx_unsol_event,
4708#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004709 .suspend = stac92hd71xx_suspend,
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004710 .resume = stac92hd71xx_resume,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004711#endif
4712};
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004713
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004714static struct hda_input_mux stac92hd71bxx_dmux = {
4715 .num_items = 4,
4716 .items = {
4717 { "Analog Inputs", 0x00 },
4718 { "Mixer", 0x01 },
4719 { "Digital Mic 1", 0x02 },
4720 { "Digital Mic 2", 0x03 },
4721 }
4722};
4723
Matthew Ranostaye035b842007-11-06 11:53:55 +01004724static int patch_stac92hd71bxx(struct hda_codec *codec)
4725{
4726 struct sigmatel_spec *spec;
4727 int err = 0;
4728
4729 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4730 if (spec == NULL)
4731 return -ENOMEM;
4732
4733 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004734 codec->patch_ops = stac92xx_patch_ops;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004735 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004736 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004737 spec->pin_nids = stac92hd71bxx_pin_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004738 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4739 sizeof(stac92hd71bxx_dmux));
Matthew Ranostaye035b842007-11-06 11:53:55 +01004740 spec->board_config = snd_hda_check_board_config(codec,
4741 STAC_92HD71BXX_MODELS,
4742 stac92hd71bxx_models,
4743 stac92hd71bxx_cfg_tbl);
4744again:
4745 if (spec->board_config < 0) {
4746 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4747 " STAC92HD71BXX, using BIOS defaults\n");
4748 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004749 } else
4750 err = stac_save_pin_cfgs(codec,
4751 stac92hd71bxx_brd_tbl[spec->board_config]);
4752 if (err < 0) {
4753 stac92xx_free(codec);
4754 return err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004755 }
4756
Takashi Iwai41c3b642008-11-18 10:45:15 +01004757 if (spec->board_config > STAC_92HD71BXX_REF) {
4758 /* GPIO0 = EAPD */
4759 spec->gpio_mask = 0x01;
4760 spec->gpio_dir = 0x01;
4761 spec->gpio_data = 0x01;
4762 }
4763
Matthew Ranostay541eee82007-12-14 12:08:04 +01004764 switch (codec->vendor_id) {
4765 case 0x111d76b6: /* 4 Port without Analog Mixer */
4766 case 0x111d76b7:
4767 case 0x111d76b4: /* 6 Port without Analog Mixer */
4768 case 0x111d76b5:
4769 spec->mixer = stac92hd71bxx_mixer;
4770 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004771 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004772 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004773 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01004774 switch (spec->board_config) {
4775 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04004776 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004777 err = stac_add_event(spec, codec->afg,
4778 STAC_VREF_EVENT, 0x02);
4779 if (err < 0)
4780 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01004781 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04004782 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4783 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004784 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004785 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004786 spec->gpio_mask |= 0x02;
4787 break;
4788 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004789 if ((codec->revision_id & 0xf) == 0 ||
4790 (codec->revision_id & 0xf) == 1) {
4791#ifdef SND_HDA_NEEDS_RESUME
4792 codec->patch_ops = stac92hd71bxx_patch_ops;
4793#endif
4794 spec->stream_delay = 40; /* 40 milliseconds */
4795 }
4796
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004797 /* no output amps */
4798 spec->num_pwrs = 0;
4799 spec->mixer = stac92hd71bxx_analog_mixer;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004800 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004801
4802 /* disable VSW */
4803 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004804 stac_change_pin_config(codec, 0xf, 0x40f000f0);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004805 break;
4806 case 0x111d7603: /* 6 Port with Analog Mixer */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004807 if ((codec->revision_id & 0xf) == 1) {
4808#ifdef SND_HDA_NEEDS_RESUME
4809 codec->patch_ops = stac92hd71bxx_patch_ops;
4810#endif
4811 spec->stream_delay = 40; /* 40 milliseconds */
4812 }
4813
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004814 /* no output amps */
4815 spec->num_pwrs = 0;
4816 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01004817 default:
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004818 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004819 spec->mixer = stac92hd71bxx_analog_mixer;
4820 spec->init = stac92hd71bxx_analog_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004821 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004822 }
4823
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004824 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004825 spec->aloopback_shift = 0;
4826
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004827 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004828 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004829 spec->mux_nids = stac92hd71bxx_mux_nids;
4830 spec->adc_nids = stac92hd71bxx_adc_nids;
4831 spec->dmic_nids = stac92hd71bxx_dmic_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004832 spec->dmux_nids = stac92hd71bxx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004833 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004834 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004835
4836 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
4837 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004838
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004839 switch (spec->board_config) {
4840 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004841 /* enable internal microphone */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004842 stac_change_pin_config(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04004843 stac92xx_auto_set_pinctl(codec, 0x0e,
4844 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05004845 /* fallthru */
4846 case STAC_DELL_M4_2:
4847 spec->num_dmics = 0;
4848 spec->num_smuxes = 0;
4849 spec->num_dmuxes = 0;
4850 break;
4851 case STAC_DELL_M4_1:
4852 case STAC_DELL_M4_3:
4853 spec->num_dmics = 1;
4854 spec->num_smuxes = 0;
4855 spec->num_dmuxes = 0;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004856 break;
4857 default:
4858 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
4859 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
4860 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
4861 };
4862
Takashi Iwaiaea7bb02008-02-25 18:26:41 +01004863 spec->multiout.num_dacs = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004864 spec->multiout.hp_nid = 0x11;
4865 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004866 if (spec->dinput_mux)
4867 spec->private_dimux.num_items +=
4868 spec->num_dmics -
4869 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004870
4871 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
4872 if (!err) {
4873 if (spec->board_config < 0) {
4874 printk(KERN_WARNING "hda_codec: No auto-config is "
4875 "available, default to model=ref\n");
4876 spec->board_config = STAC_92HD71BXX_REF;
4877 goto again;
4878 }
4879 err = -EINVAL;
4880 }
4881
4882 if (err < 0) {
4883 stac92xx_free(codec);
4884 return err;
4885 }
4886
Matthew Ranostaye035b842007-11-06 11:53:55 +01004887 return 0;
4888};
4889
Matt2f2f4252005-04-13 14:45:30 +02004890static int patch_stac922x(struct hda_codec *codec)
4891{
4892 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004893 int err;
Matt2f2f4252005-04-13 14:45:30 +02004894
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004895 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004896 if (spec == NULL)
4897 return -ENOMEM;
4898
4899 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004900 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004901 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004902 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
4903 stac922x_models,
4904 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08004905 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004906 spec->gpio_mask = spec->gpio_dir = 0x03;
4907 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004908 /* Intel Macs have all same PCI SSID, so we need to check
4909 * codec SSID to distinguish the exact models
4910 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01004911 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004912 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004913
4914 case 0x106b0800:
4915 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02004916 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004917 case 0x106b0600:
4918 case 0x106b0700:
4919 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01004920 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004921 case 0x106b0e00:
4922 case 0x106b0f00:
4923 case 0x106b1600:
4924 case 0x106b1700:
4925 case 0x106b0200:
4926 case 0x106b1e00:
4927 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004928 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004929 case 0x106b1a00:
4930 case 0x00000100:
4931 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02004932 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004933 case 0x106b0a00:
4934 case 0x106b2200:
4935 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02004936 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08004937 default:
4938 spec->board_config = STAC_INTEL_MAC_V3;
4939 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004940 }
4941 }
4942
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004943 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02004944 if (spec->board_config < 0) {
4945 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
4946 "using BIOS defaults\n");
4947 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004948 } else
4949 err = stac_save_pin_cfgs(codec,
4950 stac922x_brd_tbl[spec->board_config]);
4951 if (err < 0) {
4952 stac92xx_free(codec);
4953 return err;
Matt Porter403d1942005-11-29 15:00:51 +01004954 }
Matt2f2f4252005-04-13 14:45:30 +02004955
Matt2f2f4252005-04-13 14:45:30 +02004956 spec->adc_nids = stac922x_adc_nids;
4957 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01004958 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004959 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02004960 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004961 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004962
4963 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004964 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004965
4966 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02004967
Matt Porter3cc08dc2006-01-23 15:27:49 +01004968 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004969 if (!err) {
4970 if (spec->board_config < 0) {
4971 printk(KERN_WARNING "hda_codec: No auto-config is "
4972 "available, default to model=ref\n");
4973 spec->board_config = STAC_D945_REF;
4974 goto again;
4975 }
4976 err = -EINVAL;
4977 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01004978 if (err < 0) {
4979 stac92xx_free(codec);
4980 return err;
4981 }
4982
4983 codec->patch_ops = stac92xx_patch_ops;
4984
Takashi Iwai807a46362007-05-29 19:01:37 +02004985 /* Fix Mux capture level; max to 2 */
4986 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
4987 (0 << AC_AMPCAP_OFFSET_SHIFT) |
4988 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4989 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4990 (0 << AC_AMPCAP_MUTE_SHIFT));
4991
Matt Porter3cc08dc2006-01-23 15:27:49 +01004992 return 0;
4993}
4994
4995static int patch_stac927x(struct hda_codec *codec)
4996{
4997 struct sigmatel_spec *spec;
4998 int err;
4999
5000 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5001 if (spec == NULL)
5002 return -ENOMEM;
5003
5004 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005005 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005006 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005007 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5008 stac927x_models,
5009 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005010 again:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005011 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
5012 if (spec->board_config < 0)
5013 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5014 "STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02005015 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005016 } else
5017 err = stac_save_pin_cfgs(codec,
5018 stac927x_brd_tbl[spec->board_config]);
5019 if (err < 0) {
5020 stac92xx_free(codec);
5021 return err;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005022 }
5023
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005024 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005025 spec->adc_nids = stac927x_adc_nids;
5026 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5027 spec->mux_nids = stac927x_mux_nids;
5028 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005029 spec->smux_nids = stac927x_smux_nids;
5030 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005031 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005032 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005033 spec->multiout.dac_nids = spec->dac_nids;
5034
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005035 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005036 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005037 case STAC_D965_5ST:
5038 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005039 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005040 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005041 spec->num_dmics = 0;
5042
Tobin Davis93ed1502006-09-01 21:03:12 +02005043 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005044 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005045 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005046 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005047 switch (codec->subsystem_id) {
5048 case 0x10280209:
5049 case 0x1028022e:
5050 /* correct the device field to SPDIF out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005051 stac_change_pin_config(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005052 break;
5053 };
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005054 /* configure the analog microphone on some laptops */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005055 stac_change_pin_config(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005056 /* correct the front output jack as a hp out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005057 stac_change_pin_config(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005058 /* correct the front input jack as a mic */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005059 stac_change_pin_config(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005060 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005061 case STAC_DELL_3ST:
5062 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005063 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005064 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005065 spec->dmic_nids = stac927x_dmic_nids;
5066 spec->num_dmics = STAC927X_NUM_DMICS;
5067
Tobin Davis93ed1502006-09-01 21:03:12 +02005068 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005069 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005070 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005071 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005072 break;
5073 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005074 if (spec->board_config > STAC_D965_REF) {
5075 /* GPIO0 High = Enable EAPD */
5076 spec->eapd_mask = spec->gpio_mask = 0x01;
5077 spec->gpio_dir = spec->gpio_data = 0x01;
5078 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005079 spec->num_dmics = 0;
5080
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005081 spec->init = stac927x_core_init;
5082 spec->mixer = stac927x_mixer;
5083 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005084
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005085 spec->num_pwrs = 0;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005086 spec->aloopback_mask = 0x40;
5087 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005088 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005089
Matt Porter3cc08dc2006-01-23 15:27:49 +01005090 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005091 if (!err) {
5092 if (spec->board_config < 0) {
5093 printk(KERN_WARNING "hda_codec: No auto-config is "
5094 "available, default to model=ref\n");
5095 spec->board_config = STAC_D965_REF;
5096 goto again;
5097 }
5098 err = -EINVAL;
5099 }
Mattc7d4b2f2005-06-27 14:59:41 +02005100 if (err < 0) {
5101 stac92xx_free(codec);
5102 return err;
5103 }
Matt2f2f4252005-04-13 14:45:30 +02005104
5105 codec->patch_ops = stac92xx_patch_ops;
5106
Takashi Iwai52987652008-01-16 16:09:47 +01005107 /*
5108 * !!FIXME!!
5109 * The STAC927x seem to require fairly long delays for certain
5110 * command sequences. With too short delays (even if the answer
5111 * is set to RIRB properly), it results in the silence output
5112 * on some hardwares like Dell.
5113 *
5114 * The below flag enables the longer delay (see get_response
5115 * in hda_intel.c).
5116 */
5117 codec->bus->needs_damn_long_delay = 1;
5118
Matt2f2f4252005-04-13 14:45:30 +02005119 return 0;
5120}
5121
Matt Porterf3302a52006-07-31 12:49:34 +02005122static int patch_stac9205(struct hda_codec *codec)
5123{
5124 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005125 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005126
5127 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5128 if (spec == NULL)
5129 return -ENOMEM;
5130
5131 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005132 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005133 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005134 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5135 stac9205_models,
5136 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005137 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02005138 if (spec->board_config < 0) {
5139 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
5140 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005141 } else
5142 err = stac_save_pin_cfgs(codec,
5143 stac9205_brd_tbl[spec->board_config]);
5144 if (err < 0) {
5145 stac92xx_free(codec);
5146 return err;
Matt Porterf3302a52006-07-31 12:49:34 +02005147 }
5148
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005149 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005150 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005151 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005152 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005153 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005154 spec->smux_nids = stac9205_smux_nids;
5155 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005156 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005157 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005158 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005159 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005160 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005161
5162 spec->init = stac9205_core_init;
5163 spec->mixer = stac9205_mixer;
5164
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005165 spec->aloopback_mask = 0x40;
5166 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005167 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005168 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005169
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005170 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005171 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005172 /* Enable SPDIF in/out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005173 stac_change_pin_config(codec, 0x1f, 0x01441030);
5174 stac_change_pin_config(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005175
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005176 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005177 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5178 if (err < 0)
5179 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005180 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005181 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5182 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005183 AC_VERB_SET_UNSOLICITED_ENABLE,
5184 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005185
5186 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005187 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005188 spec->gpio_mask = 0x1b;
5189 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005190 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005191 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005192 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005193 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005194 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005195 case STAC_9205_REF:
5196 /* SPDIF-In enabled */
5197 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005198 default:
5199 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005200 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005201 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005202 break;
5203 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005204
Matt Porterf3302a52006-07-31 12:49:34 +02005205 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005206 if (!err) {
5207 if (spec->board_config < 0) {
5208 printk(KERN_WARNING "hda_codec: No auto-config is "
5209 "available, default to model=ref\n");
5210 spec->board_config = STAC_9205_REF;
5211 goto again;
5212 }
5213 err = -EINVAL;
5214 }
Matt Porterf3302a52006-07-31 12:49:34 +02005215 if (err < 0) {
5216 stac92xx_free(codec);
5217 return err;
5218 }
5219
5220 codec->patch_ops = stac92xx_patch_ops;
5221
5222 return 0;
5223}
5224
Matt2f2f4252005-04-13 14:45:30 +02005225/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005226 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005227 */
5228
Guillaume Munch99ccc562006-08-16 19:35:12 +02005229/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005230static hda_nid_t vaio_dacs[] = { 0x2 };
5231#define VAIO_HP_DAC 0x5
5232static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
5233static hda_nid_t vaio_mux_nids[] = { 0x15 };
5234
5235static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02005236 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01005237 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02005238 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005239 { "Mic Jack", 0x1 },
5240 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01005241 { "PCM", 0x3 },
5242 }
5243};
5244
5245static struct hda_verb vaio_init[] = {
5246 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005247 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01005248 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5249 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5250 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5251 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005252 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005253 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5254 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5255 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5256 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5257 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5258 {}
5259};
5260
Guillaume Munch6d859062006-08-22 17:15:47 +02005261static struct hda_verb vaio_ar_init[] = {
5262 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5263 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5264 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5265 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5266/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
5267 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005268 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02005269 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5270 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5271/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
5272 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5273 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5274 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5275 {}
5276};
5277
Takashi Iwaidb064e52006-03-16 16:04:58 +01005278static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwai127e82e2008-11-14 14:03:33 +01005279 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5280 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5281 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5282 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
Takashi Iwaidb064e52006-03-16 16:04:58 +01005283 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5284 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5285 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5286 {
5287 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5288 .name = "Capture Source",
5289 .count = 1,
5290 .info = stac92xx_mux_enum_info,
5291 .get = stac92xx_mux_enum_get,
5292 .put = stac92xx_mux_enum_put,
5293 },
5294 {}
5295};
5296
Guillaume Munch6d859062006-08-22 17:15:47 +02005297static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwai127e82e2008-11-14 14:03:33 +01005298 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5299 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5300 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5301 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
Guillaume Munch6d859062006-08-22 17:15:47 +02005302 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5303 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5304 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5305 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
5306 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
5307 {
5308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5309 .name = "Capture Source",
5310 .count = 1,
5311 .info = stac92xx_mux_enum_info,
5312 .get = stac92xx_mux_enum_get,
5313 .put = stac92xx_mux_enum_put,
5314 },
5315 {}
5316};
5317
5318static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01005319 .build_controls = stac92xx_build_controls,
5320 .build_pcms = stac92xx_build_pcms,
5321 .init = stac92xx_init,
5322 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02005323#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01005324 .resume = stac92xx_resume,
5325#endif
5326};
5327
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005328static int stac9872_vaio_init(struct hda_codec *codec)
5329{
5330 int err;
5331
5332 err = stac92xx_init(codec);
5333 if (err < 0)
5334 return err;
5335 if (codec->patch_ops.unsol_event)
5336 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
5337 return 0;
5338}
5339
5340static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
5341{
Jiang Zhe40c1d302007-11-12 13:05:16 +01005342 if (get_hp_pin_presence(codec, 0x0a)) {
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005343 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5344 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5345 } else {
5346 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5347 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5348 }
5349}
5350
5351static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
5352{
5353 switch (res >> 26) {
5354 case STAC_HP_EVENT:
5355 stac9872_vaio_hp_detect(codec, res);
5356 break;
5357 }
5358}
5359
5360static struct hda_codec_ops stac9872_vaio_patch_ops = {
5361 .build_controls = stac92xx_build_controls,
5362 .build_pcms = stac92xx_build_pcms,
5363 .init = stac9872_vaio_init,
5364 .free = stac92xx_free,
5365 .unsol_event = stac9872_vaio_unsol_event,
5366#ifdef CONFIG_PM
5367 .resume = stac92xx_resume,
5368#endif
5369};
5370
Guillaume Munch6d859062006-08-22 17:15:47 +02005371enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
5372 CXD9872RD_VAIO,
5373 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
5374 STAC9872AK_VAIO,
5375 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
5376 STAC9872K_VAIO,
5377 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005378 CXD9872AKD_VAIO,
5379 STAC_9872_MODELS,
5380};
Takashi Iwaidb064e52006-03-16 16:04:58 +01005381
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005382static const char *stac9872_models[STAC_9872_MODELS] = {
5383 [CXD9872RD_VAIO] = "vaio",
5384 [CXD9872AKD_VAIO] = "vaio-ar",
5385};
5386
5387static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5388 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
5389 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
5390 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01005391 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01005392 {}
5393};
5394
Guillaume Munch6d859062006-08-22 17:15:47 +02005395static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005396{
5397 struct sigmatel_spec *spec;
5398 int board_config;
5399
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005400 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5401 stac9872_models,
5402 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01005403 if (board_config < 0)
5404 /* unknown config, let generic-parser do its job... */
5405 return snd_hda_parse_generic_codec(codec);
5406
5407 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5408 if (spec == NULL)
5409 return -ENOMEM;
5410
5411 codec->spec = spec;
5412 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02005413 case CXD9872RD_VAIO:
5414 case STAC9872AK_VAIO:
5415 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01005416 spec->mixer = vaio_mixer;
5417 spec->init = vaio_init;
5418 spec->multiout.max_channels = 2;
5419 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5420 spec->multiout.dac_nids = vaio_dacs;
5421 spec->multiout.hp_nid = VAIO_HP_DAC;
5422 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5423 spec->adc_nids = vaio_adcs;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005424 spec->num_pwrs = 0;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005425 spec->input_mux = &vaio_mux;
5426 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005427 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005428 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02005429
5430 case CXD9872AKD_VAIO:
5431 spec->mixer = vaio_ar_mixer;
5432 spec->init = vaio_ar_init;
5433 spec->multiout.max_channels = 2;
5434 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5435 spec->multiout.dac_nids = vaio_dacs;
5436 spec->multiout.hp_nid = VAIO_HP_DAC;
5437 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005438 spec->num_pwrs = 0;
Guillaume Munch6d859062006-08-22 17:15:47 +02005439 spec->adc_nids = vaio_adcs;
5440 spec->input_mux = &vaio_mux;
5441 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005442 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02005443 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005444 }
5445
Takashi Iwaidb064e52006-03-16 16:04:58 +01005446 return 0;
5447}
5448
5449
5450/*
Matt2f2f4252005-04-13 14:45:30 +02005451 * patch entries
5452 */
5453struct hda_codec_preset snd_hda_preset_sigmatel[] = {
5454 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5455 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5456 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5457 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5458 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5459 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5460 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005461 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5462 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5463 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5464 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5465 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5466 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005467 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5468 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5469 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5470 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5471 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5472 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5473 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5474 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5475 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5476 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005477 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5478 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5479 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5480 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5481 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5482 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005483 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5484 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005485 /* The following does not take into account .id=0x83847661 when subsys =
5486 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5487 * currently not fully supported.
5488 */
5489 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5490 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5491 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02005492 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5493 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5494 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5495 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5496 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5497 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5498 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5499 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005500 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005501 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5502 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005503 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005504 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5505 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005506 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005507 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5508 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5509 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5510 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5511 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5512 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5513 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5514 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005515 {} /* terminator */
5516};