blob: c05d4643afd51cdbeb5729a6fea7221306cabfe8 [file] [log] [blame]
Matt2f2f4252005-04-13 14:45:30 +02001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for SigmaTel STAC92xx
5 *
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
Matt Porter403d1942005-11-29 15:00:51 +01007 * Matt Porter <mporter@embeddedalley.com>
Matt2f2f4252005-04-13 14:45:30 +02008 *
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 *
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
Matt2f2f4252005-04-13 14:45:30 +020027#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/slab.h>
30#include <linux/pci.h>
31#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020032#include <sound/asoundef.h>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040033#include <sound/jack.h>
Matt2f2f4252005-04-13 14:45:30 +020034#include "hda_codec.h"
35#include "hda_local.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020036#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020037
Takashi Iwaic6e4c662008-11-25 11:58:19 +010038enum {
39 STAC_VREF_EVENT = 1,
40 STAC_INSERT_EVENT,
41 STAC_PWR_EVENT,
42 STAC_HP_EVENT,
43};
Matt4e550962005-07-04 17:51:39 +020044
Takashi Iwaif5fcc132006-11-24 17:07:44 +010045enum {
46 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010047 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020048 STAC_9200_DELL_D21,
49 STAC_9200_DELL_D22,
50 STAC_9200_DELL_D23,
51 STAC_9200_DELL_M21,
52 STAC_9200_DELL_M22,
53 STAC_9200_DELL_M23,
54 STAC_9200_DELL_M24,
55 STAC_9200_DELL_M25,
56 STAC_9200_DELL_M26,
57 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020058 STAC_9200_M4,
59 STAC_9200_M4_2,
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,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010074 STAC_DELL_M6_AMIC,
75 STAC_DELL_M6_DMIC,
76 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050077 STAC_DELL_EQ,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010078 STAC_92HD73XX_MODELS
79};
80
81enum {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020082 STAC_92HD83XXX_REF,
83 STAC_92HD83XXX_MODELS
84};
85
86enum {
Matthew Ranostaye035b842007-11-06 11:53:55 +010087 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010088 STAC_DELL_M4_1,
89 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -050090 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -040091 STAC_HP_M4,
Matthew Ranostaye035b842007-11-06 11:53:55 +010092 STAC_92HD71BXX_MODELS
93};
94
95enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010096 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +020097 STAC_M1,
98 STAC_M1_2,
99 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100100 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200101 STAC_M3,
102 STAC_M5,
103 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100104 STAC_925x_MODELS
105};
106
107enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100108 STAC_D945_REF,
109 STAC_D945GTP3,
110 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200111 STAC_INTEL_MAC_V1,
112 STAC_INTEL_MAC_V2,
113 STAC_INTEL_MAC_V3,
114 STAC_INTEL_MAC_V4,
115 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800116 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
117 * is given, one of the above models will be
118 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200119 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100120 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100121 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100122 STAC_MACBOOK_PRO_V1,
123 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200124 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200125 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300126 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200127 STAC_922X_DELL_D81,
128 STAC_922X_DELL_D82,
129 STAC_922X_DELL_M81,
130 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100131 STAC_922X_MODELS
132};
133
134enum {
135 STAC_D965_REF,
136 STAC_D965_3ST,
137 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200138 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100139 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100140 STAC_927X_MODELS
141};
Matt Porter403d1942005-11-29 15:00:51 +0100142
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400143struct sigmatel_event {
144 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100145 unsigned char type;
146 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400147 int data;
148};
149
150struct sigmatel_jack {
151 hda_nid_t nid;
152 int type;
153 struct snd_jack *jack;
154};
155
Matt2f2f4252005-04-13 14:45:30 +0200156struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100157 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200158 unsigned int num_mixers;
159
Matt Porter403d1942005-11-29 15:00:51 +0100160 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500161 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200162 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +0100163 unsigned int line_switch: 1;
164 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100165 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100166 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400167 unsigned int spdif_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200168
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100169 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200170 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100171 unsigned int gpio_mask;
172 unsigned int gpio_dir;
173 unsigned int gpio_data;
174 unsigned int gpio_mute;
175
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200176 /* stream */
177 unsigned int stream_delay;
178
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100179 /* analog loopback */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100180 unsigned char aloopback_mask;
181 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200182
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100183 /* power management */
184 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200185 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100186 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100187 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100188
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400189 /* jack detection */
190 struct snd_array jacks;
191
192 /* events */
193 struct snd_array events;
194
Matt2f2f4252005-04-13 14:45:30 +0200195 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100196 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400197 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100198 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200199 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100200 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200201
202 /* capture */
203 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200204 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200205 hda_nid_t *mux_nids;
206 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200207 hda_nid_t *dmic_nids;
208 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100209 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100210 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200211 hda_nid_t *smux_nids;
212 unsigned int num_smuxes;
Matthew Ranostay65973632008-09-16 10:39:37 -0400213 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200214
Mattdabbed62005-06-14 10:19:34 +0200215 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100216 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200217 hda_nid_t anabeep_nid;
218 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200219
Matt2f2f4252005-04-13 14:45:30 +0200220 /* pin widgets */
221 hda_nid_t *pin_nids;
222 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200223 unsigned int *pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200224
225 /* codec specific stuff */
226 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100227 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200228
229 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200230 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100231 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200232 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100233 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200234 struct hda_input_mux *sinput_mux;
235 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400236 unsigned int cur_amux;
237 hda_nid_t *amp_nids;
238 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200239 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200240
Matt Porter403d1942005-11-29 15:00:51 +0100241 /* i/o switches */
242 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200243 unsigned int clfe_swap;
Takashi Iwaid7a89432008-11-12 09:48:04 +0100244 unsigned int hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200245 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200246
Mattc7d4b2f2005-06-27 14:59:41 +0200247 struct hda_pcm pcm_rec[2]; /* PCM information */
248
249 /* dynamic controls and input_mux */
250 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200251 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200252 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200253 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200254 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400255 struct hda_input_mux private_amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100256 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200257};
258
259static hda_nid_t stac9200_adc_nids[1] = {
260 0x03,
261};
262
263static hda_nid_t stac9200_mux_nids[1] = {
264 0x0c,
265};
266
267static hda_nid_t stac9200_dac_nids[1] = {
268 0x02,
269};
270
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100271static hda_nid_t stac92hd73xx_pwr_nids[8] = {
272 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
273 0x0f, 0x10, 0x11
274};
275
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400276static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
277 0x26, 0,
278};
279
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100280static hda_nid_t stac92hd73xx_adc_nids[2] = {
281 0x1a, 0x1b
282};
283
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400284#define DELL_M6_AMP 2
285static hda_nid_t stac92hd73xx_amp_nids[3] = {
286 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400287};
288
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100289#define STAC92HD73XX_NUM_DMICS 2
290static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
291 0x13, 0x14, 0
292};
293
294#define STAC92HD73_DAC_COUNT 5
295static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
296 0x15, 0x16, 0x17, 0x18, 0x19,
297};
298
299static hda_nid_t stac92hd73xx_mux_nids[4] = {
300 0x28, 0x29, 0x2a, 0x2b,
301};
302
303static hda_nid_t stac92hd73xx_dmux_nids[2] = {
304 0x20, 0x21,
305};
306
Matthew Ranostayd9737752008-09-07 12:03:41 +0200307static hda_nid_t stac92hd73xx_smux_nids[2] = {
308 0x22, 0x23,
309};
310
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200311#define STAC92HD83XXX_NUM_DMICS 2
312static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
313 0x11, 0x12, 0
314};
315
316#define STAC92HD81_DAC_COUNT 2
317#define STAC92HD83_DAC_COUNT 3
318static hda_nid_t stac92hd83xxx_dac_nids[STAC92HD73_DAC_COUNT] = {
319 0x13, 0x14, 0x22,
320};
321
322static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
323 0x17, 0x18,
324};
325
326static hda_nid_t stac92hd83xxx_adc_nids[2] = {
327 0x15, 0x16,
328};
329
330static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
331 0xa, 0xb, 0xd, 0xe,
332};
333
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400334static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
335 0x1e, 0,
336};
337
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200338static unsigned int stac92hd83xxx_pwr_mapping[4] = {
339 0x03, 0x0c, 0x10, 0x40,
340};
341
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100342static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
343 0x0a, 0x0d, 0x0f
344};
345
Matthew Ranostaye035b842007-11-06 11:53:55 +0100346static hda_nid_t stac92hd71bxx_adc_nids[2] = {
347 0x12, 0x13,
348};
349
350static hda_nid_t stac92hd71bxx_mux_nids[2] = {
351 0x1a, 0x1b
352};
353
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400354static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
355 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100356};
357
Matthew Ranostayd9737752008-09-07 12:03:41 +0200358static hda_nid_t stac92hd71bxx_smux_nids[2] = {
359 0x24, 0x25,
360};
361
Takashi Iwaiaea7bb02008-02-25 18:26:41 +0100362static hda_nid_t stac92hd71bxx_dac_nids[1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100363 0x10, /*0x11, */
364};
365
366#define STAC92HD71BXX_NUM_DMICS 2
367static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
368 0x18, 0x19, 0
369};
370
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400371static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
372 0x22, 0
373};
374
Tobin Davis8e21c342007-01-08 11:04:17 +0100375static hda_nid_t stac925x_adc_nids[1] = {
376 0x03,
377};
378
379static hda_nid_t stac925x_mux_nids[1] = {
380 0x0f,
381};
382
383static hda_nid_t stac925x_dac_nids[1] = {
384 0x02,
385};
386
Takashi Iwaif6e98522007-10-16 14:27:04 +0200387#define STAC925X_NUM_DMICS 1
388static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
389 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200390};
391
Takashi Iwai1697055e2007-12-18 18:05:52 +0100392static hda_nid_t stac925x_dmux_nids[1] = {
393 0x14,
394};
395
Matt2f2f4252005-04-13 14:45:30 +0200396static hda_nid_t stac922x_adc_nids[2] = {
397 0x06, 0x07,
398};
399
400static hda_nid_t stac922x_mux_nids[2] = {
401 0x12, 0x13,
402};
403
Matt Porter3cc08dc2006-01-23 15:27:49 +0100404static hda_nid_t stac927x_adc_nids[3] = {
405 0x07, 0x08, 0x09
406};
407
408static hda_nid_t stac927x_mux_nids[3] = {
409 0x15, 0x16, 0x17
410};
411
Matthew Ranostayd9737752008-09-07 12:03:41 +0200412static hda_nid_t stac927x_smux_nids[1] = {
413 0x21,
414};
415
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100416static hda_nid_t stac927x_dac_nids[6] = {
417 0x02, 0x03, 0x04, 0x05, 0x06, 0
418};
419
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100420static hda_nid_t stac927x_dmux_nids[1] = {
421 0x1b,
422};
423
Matthew Ranostay7f168592007-10-18 17:38:17 +0200424#define STAC927X_NUM_DMICS 2
425static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
426 0x13, 0x14, 0
427};
428
Matthew Ranostay65973632008-09-16 10:39:37 -0400429static const char *stac927x_spdif_labels[5] = {
430 "Digital Playback", "ADAT", "Analog Mux 1",
431 "Analog Mux 2", "Analog Mux 3"
432};
433
Matt Porterf3302a52006-07-31 12:49:34 +0200434static hda_nid_t stac9205_adc_nids[2] = {
435 0x12, 0x13
436};
437
438static hda_nid_t stac9205_mux_nids[2] = {
439 0x19, 0x1a
440};
441
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100442static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100443 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100444};
445
Matthew Ranostayd9737752008-09-07 12:03:41 +0200446static hda_nid_t stac9205_smux_nids[1] = {
447 0x21,
448};
449
Takashi Iwaif6e98522007-10-16 14:27:04 +0200450#define STAC9205_NUM_DMICS 2
451static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
452 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200453};
454
Mattc7d4b2f2005-06-27 14:59:41 +0200455static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200456 0x08, 0x09, 0x0d, 0x0e,
457 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200458};
459
Tobin Davis8e21c342007-01-08 11:04:17 +0100460static hda_nid_t stac925x_pin_nids[8] = {
461 0x07, 0x08, 0x0a, 0x0b,
462 0x0c, 0x0d, 0x10, 0x11,
463};
464
Matt2f2f4252005-04-13 14:45:30 +0200465static hda_nid_t stac922x_pin_nids[10] = {
466 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
467 0x0f, 0x10, 0x11, 0x15, 0x1b,
468};
469
Matthew Ranostaya7662642008-02-21 07:51:14 +0100470static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100471 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
472 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200473 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100474};
475
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200476static hda_nid_t stac92hd83xxx_pin_nids[14] = {
477 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
478 0x0f, 0x10, 0x11, 0x12, 0x13,
479 0x1d, 0x1e, 0x1f, 0x20
480};
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400481static hda_nid_t stac92hd71bxx_pin_nids[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100482 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
483 0x0f, 0x14, 0x18, 0x19, 0x1e,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400484 0x1f,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100485};
486
Matt Porter3cc08dc2006-01-23 15:27:49 +0100487static hda_nid_t stac927x_pin_nids[14] = {
488 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
489 0x0f, 0x10, 0x11, 0x12, 0x13,
490 0x14, 0x21, 0x22, 0x23,
491};
492
Matt Porterf3302a52006-07-31 12:49:34 +0200493static hda_nid_t stac9205_pin_nids[12] = {
494 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
495 0x0f, 0x14, 0x16, 0x17, 0x18,
496 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200497};
498
Matthew Ranostay89385032008-09-11 09:49:39 -0400499#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
500
501static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
502 struct snd_ctl_elem_value *ucontrol)
503{
504 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
505 struct sigmatel_spec *spec = codec->spec;
506 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
507
508 kcontrol->private_value ^= get_amp_nid(kcontrol);
509 kcontrol->private_value |= nid;
510
511 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
512}
513
514static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
515 struct snd_ctl_elem_value *ucontrol)
516{
517 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
518 struct sigmatel_spec *spec = codec->spec;
519 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
520
521 kcontrol->private_value ^= get_amp_nid(kcontrol);
522 kcontrol->private_value |= nid;
523
524 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
525}
526
Matt Porter8b657272006-10-26 17:12:59 +0200527static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
528 struct snd_ctl_elem_info *uinfo)
529{
530 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
531 struct sigmatel_spec *spec = codec->spec;
532 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
533}
534
535static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
536 struct snd_ctl_elem_value *ucontrol)
537{
538 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
539 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100540 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200541
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100542 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200543 return 0;
544}
545
546static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
547 struct snd_ctl_elem_value *ucontrol)
548{
549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
550 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100551 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200552
553 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100554 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200555}
556
Matthew Ranostayd9737752008-09-07 12:03:41 +0200557static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
558 struct snd_ctl_elem_info *uinfo)
559{
560 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
561 struct sigmatel_spec *spec = codec->spec;
562 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
563}
564
565static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
566 struct snd_ctl_elem_value *ucontrol)
567{
568 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
569 struct sigmatel_spec *spec = codec->spec;
570 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
571
572 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
573 return 0;
574}
575
576static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
577 struct snd_ctl_elem_value *ucontrol)
578{
579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
580 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400581 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200582 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400583 int err, val;
584 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200585
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400586 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200587 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400588 if (err < 0)
589 return err;
590
591 if (spec->spdif_mute) {
592 if (smux_idx == 0)
593 nid = spec->multiout.dig_out_nid;
594 else
595 nid = codec->slave_dig_outs[smux_idx - 1];
596 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
597 val = AMP_OUT_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400598 else
Takashi Iwaic1e99bd2008-10-29 08:03:42 +0100599 val = AMP_OUT_UNMUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400600 /* un/mute SPDIF out */
601 snd_hda_codec_write_cache(codec, nid, 0,
602 AC_VERB_SET_AMP_GAIN_MUTE, val);
603 }
604 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200605}
606
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100607static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200608{
609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
610 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200611 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200612}
613
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100614static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200615{
616 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
617 struct sigmatel_spec *spec = codec->spec;
618 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
619
620 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
621 return 0;
622}
623
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100624static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200625{
626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
627 struct sigmatel_spec *spec = codec->spec;
628 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
629
Mattc7d4b2f2005-06-27 14:59:41 +0200630 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200631 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
632}
633
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100634static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_info *uinfo)
636{
637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638 struct sigmatel_spec *spec = codec->spec;
639 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
640}
641
642static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
643 struct snd_ctl_elem_value *ucontrol)
644{
645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646 struct sigmatel_spec *spec = codec->spec;
647
648 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
649 return 0;
650}
651
652static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
653 struct snd_ctl_elem_value *ucontrol)
654{
655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
656 struct sigmatel_spec *spec = codec->spec;
657
658 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
659 spec->mono_nid, &spec->cur_mmux);
660}
661
Matthew Ranostay89385032008-09-11 09:49:39 -0400662static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
663 struct snd_ctl_elem_info *uinfo)
664{
665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
666 struct sigmatel_spec *spec = codec->spec;
667 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
668}
669
670static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
671 struct snd_ctl_elem_value *ucontrol)
672{
673 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
674 struct sigmatel_spec *spec = codec->spec;
675
676 ucontrol->value.enumerated.item[0] = spec->cur_amux;
677 return 0;
678}
679
680static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
681 struct snd_ctl_elem_value *ucontrol)
682{
683 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
684 struct sigmatel_spec *spec = codec->spec;
685 struct snd_kcontrol *ctl =
686 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
687 if (!ctl)
688 return -EINVAL;
689
690 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
691 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
692
693 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
694 0, &spec->cur_amux);
695}
696
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200697#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
698
699static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
700 struct snd_ctl_elem_value *ucontrol)
701{
702 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100703 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200704 struct sigmatel_spec *spec = codec->spec;
705
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100706 ucontrol->value.integer.value[0] = !!(spec->aloopback &
707 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200708 return 0;
709}
710
711static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
712 struct snd_ctl_elem_value *ucontrol)
713{
714 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
715 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100716 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200717 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100718 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200719
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100720 idx_val = spec->aloopback_mask << idx;
721 if (ucontrol->value.integer.value[0])
722 val = spec->aloopback | idx_val;
723 else
724 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100725 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200726 return 0;
727
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100728 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200729
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100730 /* Only return the bits defined by the shift value of the
731 * first two bytes of the mask
732 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200733 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100734 kcontrol->private_value & 0xFFFF, 0x0);
735 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200736
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100737 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200738 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100739 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200740 } else {
741 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100742 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200743 }
744
745 snd_hda_codec_write_cache(codec, codec->afg, 0,
746 kcontrol->private_value >> 16, dac_mode);
747
748 return 1;
749}
750
Mattc7d4b2f2005-06-27 14:59:41 +0200751static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200752 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200753 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200754 {}
755};
756
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200757static struct hda_verb stac9200_eapd_init[] = {
758 /* set dac0mux for dac converter */
759 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
760 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
761 {}
762};
763
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100764static struct hda_verb stac92hd73xx_6ch_core_init[] = {
765 /* set master volume and direct control */
766 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
767 /* setup audio connections */
768 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
769 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
770 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
771 /* setup adcs to point to mixer */
772 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
773 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100774 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
775 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
776 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
777 /* setup import muxs */
778 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
779 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
780 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
781 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
782 {}
783};
784
Matthew Ranostayd654a662008-03-14 08:46:51 +0100785static struct hda_verb dell_eq_core_init[] = {
786 /* set master volume to max value without distortion
787 * and direct control */
788 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
789 /* setup audio connections */
790 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
Matthew Ranostayf7cf0a72008-09-13 10:36:58 -0400791 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x02},
792 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100793 /* setup adcs to point to mixer */
794 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
795 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
796 /* setup import muxs */
797 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
798 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
799 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
800 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
801 {}
802};
803
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100804static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500805 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100806 /* setup audio connections */
Matthew Ranostay7747ecc2008-03-10 11:30:04 +0100807 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
808 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100809 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
810 /* setup adcs to point to mixer */
811 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
812 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
813 /* setup import muxs */
814 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
815 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
816 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
817 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
818 {}
819};
820
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100821static struct hda_verb stac92hd73xx_8ch_core_init[] = {
822 /* set master volume and direct control */
823 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
824 /* setup audio connections */
825 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
826 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
827 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
828 /* connect hp ports to dac3 */
829 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
830 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
831 /* setup adcs to point to mixer */
832 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
833 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100834 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
835 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
836 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
837 /* setup import muxs */
838 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
839 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
840 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
841 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
842 {}
843};
844
845static struct hda_verb stac92hd73xx_10ch_core_init[] = {
846 /* set master volume and direct control */
847 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
848 /* setup audio connections */
849 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
850 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
851 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
852 /* dac3 is connected to import3 mux */
853 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
854 /* connect hp ports to dac4 */
855 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
856 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
857 /* setup adcs to point to mixer */
858 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
859 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100860 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
861 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
862 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
863 /* setup import muxs */
864 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
865 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
866 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
867 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
868 {}
869};
870
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200871static struct hda_verb stac92hd83xxx_core_init[] = {
872 /* start of config #1 */
873 { 0xe, AC_VERB_SET_CONNECT_SEL, 0x3},
874
875 /* start of config #2 */
876 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0},
877 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0},
878 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1},
879
880 /* power state controls amps */
881 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
882};
883
Matthew Ranostaye035b842007-11-06 11:53:55 +0100884static struct hda_verb stac92hd71bxx_core_init[] = {
885 /* set master volume and direct control */
886 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
887 /* connect headphone jack to dac1 */
888 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100889 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
890 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
891 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
892 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100893};
894
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400895#define HD_DISABLE_PORTF 2
Matthew Ranostay541eee82007-12-14 12:08:04 +0100896static struct hda_verb stac92hd71bxx_analog_core_init[] = {
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200897 /* start of config #1 */
898
899 /* connect port 0f to audio mixer */
900 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200901 /* unmute right and left channels for node 0x0f */
902 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
903 /* start of config #2 */
904
Matthew Ranostay541eee82007-12-14 12:08:04 +0100905 /* set master volume and direct control */
906 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
907 /* connect headphone jack to dac1 */
908 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200909 /* unmute right and left channels for nodes 0x0a, 0xd */
Matthew Ranostaye035b842007-11-06 11:53:55 +0100910 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
911 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100912 {}
913};
914
Tobin Davis8e21c342007-01-08 11:04:17 +0100915static struct hda_verb stac925x_core_init[] = {
916 /* set dac0mux for dac converter */
917 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
918 {}
919};
920
Mattc7d4b2f2005-06-27 14:59:41 +0200921static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200922 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200923 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200924 {}
925};
926
Tobin Davis93ed1502006-09-01 21:03:12 +0200927static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200928 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200929 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200930 /* unmute node 0x1b */
931 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
932 /* select node 0x03 as DAC */
933 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
934 {}
935};
936
Matt Porter3cc08dc2006-01-23 15:27:49 +0100937static struct hda_verb stac927x_core_init[] = {
938 /* set master volume and direct control */
939 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200940 /* enable analog pc beep path */
941 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100942 {}
943};
944
Matt Porterf3302a52006-07-31 12:49:34 +0200945static struct hda_verb stac9205_core_init[] = {
946 /* set master volume and direct control */
947 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200948 /* enable analog pc beep path */
949 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200950 {}
951};
952
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100953#define STAC_MONO_MUX \
954 { \
955 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
956 .name = "Mono Mux", \
957 .count = 1, \
958 .info = stac92xx_mono_mux_enum_info, \
959 .get = stac92xx_mono_mux_enum_get, \
960 .put = stac92xx_mono_mux_enum_put, \
961 }
962
Matthew Ranostay89385032008-09-11 09:49:39 -0400963#define STAC_AMP_MUX \
964 { \
965 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
966 .name = "Amp Selector Capture Switch", \
967 .count = 1, \
968 .info = stac92xx_amp_mux_enum_info, \
969 .get = stac92xx_amp_mux_enum_get, \
970 .put = stac92xx_amp_mux_enum_put, \
971 }
972
973#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
974 { \
975 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
976 .name = xname, \
977 .index = 0, \
978 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
979 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
980 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
981 .info = stac92xx_amp_volume_info, \
982 .get = stac92xx_amp_volume_get, \
983 .put = stac92xx_amp_volume_put, \
984 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
985 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
986 }
987
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200988#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200989 { \
990 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
991 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200992 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200993 .info = stac92xx_mux_enum_info, \
994 .get = stac92xx_mux_enum_get, \
995 .put = stac92xx_mux_enum_put, \
996 }
997
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100998#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200999 { \
1000 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1001 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001002 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +02001003 .info = stac92xx_aloopback_info, \
1004 .get = stac92xx_aloopback_get, \
1005 .put = stac92xx_aloopback_put, \
1006 .private_value = verb_read | (verb_write << 16), \
1007 }
1008
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001009static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +02001010 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1011 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001012 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +02001013 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1014 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001015 { } /* end */
1016};
1017
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001018#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001019static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001020 /* start of config #1 */
1021 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1022 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1023
1024 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1025 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1026
1027 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1028 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1029
1030 /* start of config #2 */
1031 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1032 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1033
1034 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1035 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1036
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001037 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1038
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001039 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1040 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1041
1042 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1043 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1044
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001045 { } /* end */
1046};
1047
1048static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001049 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1050
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001051 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1052 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1053
1054 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1055 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1056
1057 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1058 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1059
1060 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1061 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1062
1063 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1064 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1065
1066 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1067 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1068
1069 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1070 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1071 { } /* end */
1072};
1073
1074static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001075 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1076
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001077 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1078 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1079
1080 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1081 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1082
1083 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1084 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1085
1086 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1087 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1088
1089 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1090 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1091
1092 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1093 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1094
1095 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1096 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1097 { } /* end */
1098};
1099
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001100
1101static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1102 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1103 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1104
1105 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1106 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1107
1108 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0, HDA_INPUT),
1109 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0, HDA_INPUT),
1110
1111 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x1, HDA_INPUT),
1112 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x1, HDA_INPUT),
1113
1114 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x2, HDA_INPUT),
1115 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x2, HDA_INPUT),
1116
1117 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x3, HDA_INPUT),
1118 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x3, HDA_INPUT),
1119
1120 /*
1121 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x4, HDA_INPUT),
1122 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x4, HDA_INPUT),
1123 */
1124 { } /* end */
1125};
1126
Matthew Ranostay541eee82007-12-14 12:08:04 +01001127static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001128 STAC_INPUT_SOURCE(2),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001129 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001130
Matthew Ranostay9b359472007-11-07 13:03:12 +01001131 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1132 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay9b359472007-11-07 13:03:12 +01001133
1134 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1135 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001136 /* analog pc-beep replaced with digital beep support */
1137 /*
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001138 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1139 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001140 */
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001141
Matthew Ranostay687cb982008-10-11 13:52:43 -04001142 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1143 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001144
Matthew Ranostay687cb982008-10-11 13:52:43 -04001145 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1146 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001147
1148 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1149 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1150
1151 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1152 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001153 { } /* end */
1154};
1155
Matthew Ranostay541eee82007-12-14 12:08:04 +01001156static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +01001157 STAC_INPUT_SOURCE(2),
1158 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1159
Matthew Ranostay541eee82007-12-14 12:08:04 +01001160 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1161 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001162
1163 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1164 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001165 { } /* end */
1166};
1167
Tobin Davis8e21c342007-01-08 11:04:17 +01001168static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001169 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +01001170 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
Mauro Carvalho Chehab587755f2008-05-25 18:20:06 +02001171 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
Tobin Davis8e21c342007-01-08 11:04:17 +01001172 { } /* end */
1173};
1174
Takashi Iwaid1d985f2006-11-23 19:27:12 +01001175static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001176 STAC_INPUT_SOURCE(2),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001177 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001178
1179 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1180 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001181
1182 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1183 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001184 { } /* end */
1185};
1186
1187/* This needs to be generated dynamically based on sequence */
1188static struct snd_kcontrol_new stac922x_mixer[] = {
1189 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001190 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1191 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001192
1193 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1194 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001195 { } /* end */
1196};
1197
1198
1199static struct snd_kcontrol_new stac927x_mixer[] = {
1200 STAC_INPUT_SOURCE(3),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001201 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001202
1203 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1204 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001205
1206 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1207 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001208
1209 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1210 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +02001211 { } /* end */
1212};
1213
Takashi Iwai1697055e2007-12-18 18:05:52 +01001214static struct snd_kcontrol_new stac_dmux_mixer = {
1215 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1216 .name = "Digital Input Source",
1217 /* count set later */
1218 .info = stac92xx_dmux_enum_info,
1219 .get = stac92xx_dmux_enum_get,
1220 .put = stac92xx_dmux_enum_put,
1221};
1222
Matthew Ranostayd9737752008-09-07 12:03:41 +02001223static struct snd_kcontrol_new stac_smux_mixer = {
1224 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001225 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001226 /* count set later */
1227 .info = stac92xx_smux_enum_info,
1228 .get = stac92xx_smux_enum_get,
1229 .put = stac92xx_smux_enum_put,
1230};
1231
Takashi Iwai2134ea42008-01-10 16:53:55 +01001232static const char *slave_vols[] = {
1233 "Front Playback Volume",
1234 "Surround Playback Volume",
1235 "Center Playback Volume",
1236 "LFE Playback Volume",
1237 "Side Playback Volume",
1238 "Headphone Playback Volume",
1239 "Headphone Playback Volume",
1240 "Speaker Playback Volume",
1241 "External Speaker Playback Volume",
1242 "Speaker2 Playback Volume",
1243 NULL
1244};
1245
1246static const char *slave_sws[] = {
1247 "Front Playback Switch",
1248 "Surround Playback Switch",
1249 "Center Playback Switch",
1250 "LFE Playback Switch",
1251 "Side Playback Switch",
1252 "Headphone Playback Switch",
1253 "Headphone Playback Switch",
1254 "Speaker Playback Switch",
1255 "External Speaker Playback Switch",
1256 "Speaker2 Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001257 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001258 NULL
1259};
1260
Takashi Iwai603c4012008-07-30 15:01:44 +02001261static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001262static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001263
Matt2f2f4252005-04-13 14:45:30 +02001264static int stac92xx_build_controls(struct hda_codec *codec)
1265{
1266 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001267 struct auto_pin_cfg *cfg = &spec->autocfg;
1268 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001269 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001270 int i;
Matt2f2f4252005-04-13 14:45:30 +02001271
1272 err = snd_hda_add_new_ctls(codec, spec->mixer);
1273 if (err < 0)
1274 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001275
1276 for (i = 0; i < spec->num_mixers; i++) {
1277 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1278 if (err < 0)
1279 return err;
1280 }
Takashi Iwai1697055e2007-12-18 18:05:52 +01001281 if (spec->num_dmuxes > 0) {
1282 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001283 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001284 snd_ctl_new1(&stac_dmux_mixer, codec));
1285 if (err < 0)
1286 return err;
1287 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001288 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001289 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1290 struct hda_input_mux *smux = &spec->private_smux;
1291 /* check for mute support on SPDIF out */
1292 if (wcaps & AC_WCAP_OUT_AMP) {
1293 smux->items[smux->num_items].label = "Off";
1294 smux->items[smux->num_items].index = 0;
1295 smux->num_items++;
1296 spec->spdif_mute = 1;
1297 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001298 stac_smux_mixer.count = spec->num_smuxes;
1299 err = snd_ctl_add(codec->bus->card,
1300 snd_ctl_new1(&stac_smux_mixer, codec));
1301 if (err < 0)
1302 return err;
1303 }
Mattc7d4b2f2005-06-27 14:59:41 +02001304
Mattdabbed62005-06-14 10:19:34 +02001305 if (spec->multiout.dig_out_nid) {
1306 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1307 if (err < 0)
1308 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001309 err = snd_hda_create_spdif_share_sw(codec,
1310 &spec->multiout);
1311 if (err < 0)
1312 return err;
1313 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001314 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001315 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001316 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1317 if (err < 0)
1318 return err;
1319 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001320
1321 /* if we have no master control, let's create it */
1322 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001323 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001324 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001325 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001326 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001327 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001328 if (err < 0)
1329 return err;
1330 }
1331 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1332 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1333 NULL, slave_sws);
1334 if (err < 0)
1335 return err;
1336 }
1337
Takashi Iwai603c4012008-07-30 15:01:44 +02001338 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001339
1340 /* create jack input elements */
1341 if (spec->hp_detect) {
1342 for (i = 0; i < cfg->hp_outs; i++) {
1343 int type = SND_JACK_HEADPHONE;
1344 nid = cfg->hp_pins[i];
1345 /* jack detection */
1346 if (cfg->hp_outs == i)
1347 type |= SND_JACK_LINEOUT;
1348 err = stac92xx_add_jack(codec, nid, type);
1349 if (err < 0)
1350 return err;
1351 }
1352 }
1353 for (i = 0; i < cfg->line_outs; i++) {
1354 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1355 SND_JACK_LINEOUT);
1356 if (err < 0)
1357 return err;
1358 }
1359 for (i = 0; i < AUTO_PIN_LAST; i++) {
1360 nid = cfg->input_pins[i];
1361 if (nid) {
1362 err = stac92xx_add_jack(codec, nid,
1363 SND_JACK_MICROPHONE);
1364 if (err < 0)
1365 return err;
1366 }
1367 }
1368
Mattdabbed62005-06-14 10:19:34 +02001369 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001370}
1371
Matt Porter403d1942005-11-29 15:00:51 +01001372static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001373 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001374 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1375};
1376
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001377static unsigned int gateway9200_m4_pin_configs[8] = {
1378 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1379 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1380};
1381static unsigned int gateway9200_m4_2_pin_configs[8] = {
1382 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1383 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1384};
1385
1386/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001387 STAC 9200 pin configs for
1388 102801A8
1389 102801DE
1390 102801E8
1391*/
1392static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001393 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1394 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001395};
1396
1397/*
1398 STAC 9200 pin configs for
1399 102801C0
1400 102801C1
1401*/
1402static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001403 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1404 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001405};
1406
1407/*
1408 STAC 9200 pin configs for
1409 102801C4 (Dell Dimension E310)
1410 102801C5
1411 102801C7
1412 102801D9
1413 102801DA
1414 102801E3
1415*/
1416static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001417 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1418 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001419};
1420
1421
1422/*
1423 STAC 9200-32 pin configs for
1424 102801B5 (Dell Inspiron 630m)
1425 102801D8 (Dell Inspiron 640m)
1426*/
1427static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001428 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1429 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001430};
1431
1432/*
1433 STAC 9200-32 pin configs for
1434 102801C2 (Dell Latitude D620)
1435 102801C8
1436 102801CC (Dell Latitude D820)
1437 102801D4
1438 102801D6
1439*/
1440static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001441 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1442 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001443};
1444
1445/*
1446 STAC 9200-32 pin configs for
1447 102801CE (Dell XPS M1710)
1448 102801CF (Dell Precision M90)
1449*/
1450static unsigned int dell9200_m23_pin_configs[8] = {
1451 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1452 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1453};
1454
1455/*
1456 STAC 9200-32 pin configs for
1457 102801C9
1458 102801CA
1459 102801CB (Dell Latitude 120L)
1460 102801D3
1461*/
1462static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001463 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1464 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001465};
1466
1467/*
1468 STAC 9200-32 pin configs for
1469 102801BD (Dell Inspiron E1505n)
1470 102801EE
1471 102801EF
1472*/
1473static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001474 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1475 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001476};
1477
1478/*
1479 STAC 9200-32 pin configs for
1480 102801F5 (Dell Inspiron 1501)
1481 102801F6
1482*/
1483static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001484 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1485 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001486};
1487
1488/*
1489 STAC 9200-32
1490 102801CD (Dell Inspiron E1705/9400)
1491*/
1492static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001493 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1494 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001495};
1496
Tobin Davisbf277782008-02-03 20:31:47 +01001497static unsigned int oqo9200_pin_configs[8] = {
1498 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1499 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1500};
1501
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001502
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001503static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1504 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001505 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001506 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1507 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1508 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1509 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1510 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1511 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1512 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1513 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1514 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1515 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001516 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1517 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001518 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001519};
1520
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001521static const char *stac9200_models[STAC_9200_MODELS] = {
1522 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001523 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001524 [STAC_9200_DELL_D21] = "dell-d21",
1525 [STAC_9200_DELL_D22] = "dell-d22",
1526 [STAC_9200_DELL_D23] = "dell-d23",
1527 [STAC_9200_DELL_M21] = "dell-m21",
1528 [STAC_9200_DELL_M22] = "dell-m22",
1529 [STAC_9200_DELL_M23] = "dell-m23",
1530 [STAC_9200_DELL_M24] = "dell-m24",
1531 [STAC_9200_DELL_M25] = "dell-m25",
1532 [STAC_9200_DELL_M26] = "dell-m26",
1533 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001534 [STAC_9200_M4] = "gateway-m4",
1535 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001536 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001537};
1538
1539static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1540 /* SigmaTel reference board */
1541 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1542 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001543 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001544 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1545 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001546 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001547 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1548 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1549 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1550 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1551 "unknown Dell", STAC_9200_DELL_D22),
1552 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1553 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001554 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001555 "Dell Latitude D620", STAC_9200_DELL_M22),
1556 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1557 "unknown Dell", STAC_9200_DELL_D23),
1558 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1559 "unknown Dell", STAC_9200_DELL_D23),
1560 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1561 "unknown Dell", STAC_9200_DELL_M22),
1562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1563 "unknown Dell", STAC_9200_DELL_M24),
1564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1565 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001567 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001569 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001571 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001573 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001575 "Dell Precision M90", STAC_9200_DELL_M23),
1576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1577 "unknown Dell", STAC_9200_DELL_M22),
1578 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1579 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001581 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001582 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001583 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1584 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1585 "unknown Dell", STAC_9200_DELL_D23),
1586 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1587 "unknown Dell", STAC_9200_DELL_D23),
1588 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1589 "unknown Dell", STAC_9200_DELL_D21),
1590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1591 "unknown Dell", STAC_9200_DELL_D23),
1592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1593 "unknown Dell", STAC_9200_DELL_D21),
1594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1595 "unknown Dell", STAC_9200_DELL_M25),
1596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1597 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001599 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1601 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001602 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001603 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001604 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001605 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1606 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1607 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001608 /* OQO Mobile */
1609 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001610 {} /* terminator */
1611};
1612
Tobin Davis8e21c342007-01-08 11:04:17 +01001613static unsigned int ref925x_pin_configs[8] = {
1614 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001615 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001616};
1617
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001618static unsigned int stac925xM1_pin_configs[8] = {
1619 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1620 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1621};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001622
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001623static unsigned int stac925xM1_2_pin_configs[8] = {
1624 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1625 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1626};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001627
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001628static unsigned int stac925xM2_pin_configs[8] = {
1629 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1630 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1631};
1632
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001633static unsigned int stac925xM2_2_pin_configs[8] = {
1634 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1635 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1636};
1637
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001638static unsigned int stac925xM3_pin_configs[8] = {
1639 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1640 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1641};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001642
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001643static unsigned int stac925xM5_pin_configs[8] = {
1644 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1645 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1646};
1647
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001648static unsigned int stac925xM6_pin_configs[8] = {
1649 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1650 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
1651};
1652
Tobin Davis8e21c342007-01-08 11:04:17 +01001653static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1654 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001655 [STAC_M1] = stac925xM1_pin_configs,
1656 [STAC_M1_2] = stac925xM1_2_pin_configs,
1657 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001658 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001659 [STAC_M3] = stac925xM3_pin_configs,
1660 [STAC_M5] = stac925xM5_pin_configs,
1661 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001662};
1663
1664static const char *stac925x_models[STAC_925x_MODELS] = {
1665 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001666 [STAC_M1] = "m1",
1667 [STAC_M1_2] = "m1-2",
1668 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001669 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001670 [STAC_M3] = "m3",
1671 [STAC_M5] = "m5",
1672 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001673};
1674
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001675static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001676 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1677 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1678 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1679 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001680 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001681 /* Not sure about the brand name for those */
1682 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1683 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1684 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1685 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001686 {} /* terminator */
1687};
1688
Tobin Davis8e21c342007-01-08 11:04:17 +01001689static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1690 /* SigmaTel reference board */
1691 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001692 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001693
1694 /* Default table for unknown ID */
1695 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1696
Tobin Davis8e21c342007-01-08 11:04:17 +01001697 {} /* terminator */
1698};
1699
Matthew Ranostaya7662642008-02-21 07:51:14 +01001700static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001701 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1702 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1703 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001704 0x01452050,
1705};
1706
1707static unsigned int dell_m6_pin_configs[13] = {
1708 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001709 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001710 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1711 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001712};
1713
1714static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001715 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001716 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1717 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1718 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001719 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001720};
1721
1722static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1723 [STAC_92HD73XX_REF] = "ref",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001724 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1725 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1726 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001727 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001728};
1729
1730static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1731 /* SigmaTel reference board */
1732 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001733 "DFI LanParty", STAC_92HD73XX_REF),
1734 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001735 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001736 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001737 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001738 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001739 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001740 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001741 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001742 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001743 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001744 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001745 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001746 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001747 "unknown Dell", STAC_DELL_M6_DMIC),
1748 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1749 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001750 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001751 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001752 {} /* terminator */
1753};
1754
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001755static unsigned int ref92hd83xxx_pin_configs[14] = {
1756 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1757 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1758 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1759 0x01451160, 0x98560170,
1760};
1761
1762static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1763 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1764};
1765
1766static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1767 [STAC_92HD83XXX_REF] = "ref",
1768};
1769
1770static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1771 /* SigmaTel reference board */
1772 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1773 "DFI LanParty", STAC_92HD71BXX_REF),
1774};
1775
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001776static unsigned int ref92hd71bxx_pin_configs[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001777 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001778 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001779 0x90a000f0, 0x01452050, 0x01452050,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001780};
1781
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001782static unsigned int dell_m4_1_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001783 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001784 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001785 0x40f000f0, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001786};
1787
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001788static unsigned int dell_m4_2_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001789 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1790 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001791 0x40f000f0, 0x044413b0, 0x044413b0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001792};
1793
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001794static unsigned int dell_m4_3_pin_configs[11] = {
1795 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1796 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1797 0x40f000f0, 0x044413b0, 0x044413b0,
1798};
1799
Matthew Ranostaye035b842007-11-06 11:53:55 +01001800static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1801 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001802 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1803 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001804 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001805 [STAC_HP_M4] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001806};
1807
1808static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1809 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001810 [STAC_DELL_M4_1] = "dell-m4-1",
1811 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001812 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001813 [STAC_HP_M4] = "hp-m4",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001814};
1815
1816static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1817 /* SigmaTel reference board */
1818 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1819 "DFI LanParty", STAC_92HD71BXX_REF),
Takashi Iwai80bf2722008-11-18 10:48:41 +01001820 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f2,
1821 "HP dv5", STAC_HP_M4),
1822 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4,
1823 "HP dv7", STAC_HP_M4),
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001824 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1825 "unknown HP", STAC_HP_M4),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001826 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1827 "unknown Dell", STAC_DELL_M4_1),
1828 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1829 "unknown Dell", STAC_DELL_M4_1),
1830 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1831 "unknown Dell", STAC_DELL_M4_1),
1832 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1833 "unknown Dell", STAC_DELL_M4_1),
1834 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1835 "unknown Dell", STAC_DELL_M4_1),
1836 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1837 "unknown Dell", STAC_DELL_M4_1),
1838 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1839 "unknown Dell", STAC_DELL_M4_1),
1840 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1841 "unknown Dell", STAC_DELL_M4_2),
1842 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1843 "unknown Dell", STAC_DELL_M4_2),
1844 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1845 "unknown Dell", STAC_DELL_M4_2),
1846 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1847 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001848 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1849 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001850 {} /* terminator */
1851};
1852
Matt Porter403d1942005-11-29 15:00:51 +01001853static unsigned int ref922x_pin_configs[10] = {
1854 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1855 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001856 0x40000100, 0x40000100,
1857};
1858
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001859/*
1860 STAC 922X pin configs for
1861 102801A7
1862 102801AB
1863 102801A9
1864 102801D1
1865 102801D2
1866*/
1867static unsigned int dell_922x_d81_pin_configs[10] = {
1868 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1869 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1870 0x01813122, 0x400001f2,
1871};
1872
1873/*
1874 STAC 922X pin configs for
1875 102801AC
1876 102801D0
1877*/
1878static unsigned int dell_922x_d82_pin_configs[10] = {
1879 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1880 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1881 0x01813122, 0x400001f1,
1882};
1883
1884/*
1885 STAC 922X pin configs for
1886 102801BF
1887*/
1888static unsigned int dell_922x_m81_pin_configs[10] = {
1889 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1890 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1891 0x40C003f1, 0x405003f0,
1892};
1893
1894/*
1895 STAC 9221 A1 pin configs for
1896 102801D7 (Dell XPS M1210)
1897*/
1898static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001899 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1900 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001901 0x508003f3, 0x405003f4,
1902};
1903
Matt Porter403d1942005-11-29 15:00:51 +01001904static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001905 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001906 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1907 0x02a19120, 0x40000100,
1908};
1909
1910static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001911 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1912 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001913 0x02a19320, 0x40000100,
1914};
1915
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001916static unsigned int intel_mac_v1_pin_configs[10] = {
1917 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1918 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001919 0x400000fc, 0x400000fb,
1920};
1921
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001922static unsigned int intel_mac_v2_pin_configs[10] = {
1923 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1924 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001925 0x400000fc, 0x400000fb,
1926};
1927
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001928static unsigned int intel_mac_v3_pin_configs[10] = {
1929 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1930 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1931 0x400000fc, 0x400000fb,
1932};
1933
1934static unsigned int intel_mac_v4_pin_configs[10] = {
1935 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1936 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1937 0x400000fc, 0x400000fb,
1938};
1939
1940static unsigned int intel_mac_v5_pin_configs[10] = {
1941 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1942 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1943 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001944};
1945
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001946static unsigned int ecs202_pin_configs[10] = {
1947 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1948 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1949 0x9037012e, 0x40e000f2,
1950};
Takashi Iwai76c08822007-06-19 12:17:42 +02001951
Takashi Iwai19039bd2006-06-28 15:52:16 +02001952static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001953 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001954 [STAC_D945GTP3] = d945gtp3_pin_configs,
1955 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001956 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1957 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1958 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1959 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1960 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001961 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001962 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001963 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1964 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1965 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1966 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1967 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1968 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001969 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001970 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1971 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1972 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1973 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001974};
1975
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001976static const char *stac922x_models[STAC_922X_MODELS] = {
1977 [STAC_D945_REF] = "ref",
1978 [STAC_D945GTP5] = "5stack",
1979 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001980 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1981 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1982 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1983 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1984 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001985 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001986 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001987 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001988 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001989 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1990 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001991 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001992 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001993 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001994 [STAC_922X_DELL_D81] = "dell-d81",
1995 [STAC_922X_DELL_D82] = "dell-d82",
1996 [STAC_922X_DELL_M81] = "dell-m81",
1997 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001998};
1999
2000static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2001 /* SigmaTel reference board */
2002 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2003 "DFI LanParty", STAC_D945_REF),
2004 /* Intel 945G based systems */
2005 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2006 "Intel D945G", STAC_D945GTP3),
2007 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2008 "Intel D945G", STAC_D945GTP3),
2009 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2010 "Intel D945G", STAC_D945GTP3),
2011 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2012 "Intel D945G", STAC_D945GTP3),
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2014 "Intel D945G", STAC_D945GTP3),
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2016 "Intel D945G", STAC_D945GTP3),
2017 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2018 "Intel D945G", STAC_D945GTP3),
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2020 "Intel D945G", STAC_D945GTP3),
2021 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2022 "Intel D945G", STAC_D945GTP3),
2023 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2024 "Intel D945G", STAC_D945GTP3),
2025 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2026 "Intel D945G", STAC_D945GTP3),
2027 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2028 "Intel D945G", STAC_D945GTP3),
2029 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2030 "Intel D945G", STAC_D945GTP3),
2031 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2032 "Intel D945G", STAC_D945GTP3),
2033 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2034 "Intel D945G", STAC_D945GTP3),
2035 /* Intel D945G 5-stack systems */
2036 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2037 "Intel D945G", STAC_D945GTP5),
2038 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2039 "Intel D945G", STAC_D945GTP5),
2040 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2041 "Intel D945G", STAC_D945GTP5),
2042 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2043 "Intel D945G", STAC_D945GTP5),
2044 /* Intel 945P based systems */
2045 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2046 "Intel D945P", STAC_D945GTP3),
2047 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2048 "Intel D945P", STAC_D945GTP3),
2049 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2050 "Intel D945P", STAC_D945GTP3),
2051 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2052 "Intel D945P", STAC_D945GTP3),
2053 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2054 "Intel D945P", STAC_D945GTP3),
2055 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2056 "Intel D945P", STAC_D945GTP5),
2057 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002058 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002059 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002060 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002061 /* Dell systems */
2062 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2063 "unknown Dell", STAC_922X_DELL_D81),
2064 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2065 "unknown Dell", STAC_922X_DELL_D81),
2066 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2067 "unknown Dell", STAC_922X_DELL_D81),
2068 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2069 "unknown Dell", STAC_922X_DELL_D82),
2070 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2071 "unknown Dell", STAC_922X_DELL_M81),
2072 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2073 "unknown Dell", STAC_922X_DELL_D82),
2074 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2075 "unknown Dell", STAC_922X_DELL_D81),
2076 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2077 "unknown Dell", STAC_922X_DELL_D81),
2078 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2079 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002080 /* ECS/PC Chips boards */
2081 SND_PCI_QUIRK(0x1019, 0x2144,
2082 "ECS/PC chips", STAC_ECS_202),
2083 SND_PCI_QUIRK(0x1019, 0x2608,
2084 "ECS/PC chips", STAC_ECS_202),
2085 SND_PCI_QUIRK(0x1019, 0x2633,
2086 "ECS/PC chips P17G/1333", STAC_ECS_202),
2087 SND_PCI_QUIRK(0x1019, 0x2811,
2088 "ECS/PC chips", STAC_ECS_202),
2089 SND_PCI_QUIRK(0x1019, 0x2812,
2090 "ECS/PC chips", STAC_ECS_202),
2091 SND_PCI_QUIRK(0x1019, 0x2813,
2092 "ECS/PC chips", STAC_ECS_202),
2093 SND_PCI_QUIRK(0x1019, 0x2814,
2094 "ECS/PC chips", STAC_ECS_202),
2095 SND_PCI_QUIRK(0x1019, 0x2815,
2096 "ECS/PC chips", STAC_ECS_202),
2097 SND_PCI_QUIRK(0x1019, 0x2816,
2098 "ECS/PC chips", STAC_ECS_202),
2099 SND_PCI_QUIRK(0x1019, 0x2817,
2100 "ECS/PC chips", STAC_ECS_202),
2101 SND_PCI_QUIRK(0x1019, 0x2818,
2102 "ECS/PC chips", STAC_ECS_202),
2103 SND_PCI_QUIRK(0x1019, 0x2819,
2104 "ECS/PC chips", STAC_ECS_202),
2105 SND_PCI_QUIRK(0x1019, 0x2820,
2106 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002107 {} /* terminator */
2108};
2109
Matt Porter3cc08dc2006-01-23 15:27:49 +01002110static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002111 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2112 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2113 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2114 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002115};
2116
Tobin Davis93ed1502006-09-01 21:03:12 +02002117static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002118 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2119 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2120 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2121 0x40000100, 0x40000100
2122};
2123
Tobin Davis93ed1502006-09-01 21:03:12 +02002124static unsigned int d965_5st_pin_configs[14] = {
2125 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2126 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2127 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2128 0x40000100, 0x40000100
2129};
2130
Tobin Davis4ff076e2007-08-07 11:48:12 +02002131static unsigned int dell_3st_pin_configs[14] = {
2132 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2133 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002134 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002135 0x40c003fc, 0x40000100
2136};
2137
Tobin Davis93ed1502006-09-01 21:03:12 +02002138static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002139 [STAC_D965_REF] = ref927x_pin_configs,
2140 [STAC_D965_3ST] = d965_3st_pin_configs,
2141 [STAC_D965_5ST] = d965_5st_pin_configs,
2142 [STAC_DELL_3ST] = dell_3st_pin_configs,
2143 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002144};
2145
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002146static const char *stac927x_models[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002147 [STAC_D965_REF] = "ref",
2148 [STAC_D965_3ST] = "3stack",
2149 [STAC_D965_5ST] = "5stack",
2150 [STAC_DELL_3ST] = "dell-3stack",
2151 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002152};
2153
2154static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2155 /* SigmaTel reference board */
2156 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2157 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002158 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002159 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2160 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002161 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002162 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
2163 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
2164 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
2165 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
2166 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
2167 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
2168 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
2169 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
2170 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
2171 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
2172 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
2173 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
2174 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
2175 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
2176 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
2177 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002178 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002179 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002180 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002181 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2182 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002183 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002184 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2185 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002186 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Takashi Iwai24918b62008-09-30 12:58:54 +02002187 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002188 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2189 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2190 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2191 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002192 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002193 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
2194 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
2195 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
2196 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
2197 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
2198 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
2199 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
2200 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
2201 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002202 {} /* terminator */
2203};
2204
Matt Porterf3302a52006-07-31 12:49:34 +02002205static unsigned int ref9205_pin_configs[12] = {
2206 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002207 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002208 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002209};
2210
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002211/*
2212 STAC 9205 pin configs for
2213 102801F1
2214 102801F2
2215 102801FC
2216 102801FD
2217 10280204
2218 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002219 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002220*/
2221static unsigned int dell_9205_m42_pin_configs[12] = {
2222 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2223 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2224 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2225};
2226
2227/*
2228 STAC 9205 pin configs for
2229 102801F9
2230 102801FA
2231 102801FE
2232 102801FF (Dell Precision M4300)
2233 10280206
2234 10280200
2235 10280201
2236*/
2237static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002238 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2239 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2240 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2241};
2242
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002243static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002244 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2245 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2246 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2247};
2248
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002249static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002250 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002251 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2252 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2253 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02002254};
2255
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002256static const char *stac9205_models[STAC_9205_MODELS] = {
2257 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002258 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002259 [STAC_9205_DELL_M43] = "dell-m43",
2260 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002261};
2262
2263static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2264 /* SigmaTel reference board */
2265 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2266 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002267 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2268 "unknown Dell", STAC_9205_DELL_M42),
2269 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2270 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002271 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002272 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002273 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2274 "Dell Precision", STAC_9205_DELL_M43),
2275 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2276 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002277 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2278 "unknown Dell", STAC_9205_DELL_M42),
2279 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2280 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002281 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2282 "Dell Precision", STAC_9205_DELL_M43),
2283 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002284 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002285 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2286 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002287 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2288 "Dell Precision", STAC_9205_DELL_M43),
2289 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2290 "Dell Precision", STAC_9205_DELL_M43),
2291 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2292 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002293 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2294 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002295 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2296 "Dell Vostro 1500", STAC_9205_DELL_M42),
Matt Porterf3302a52006-07-31 12:49:34 +02002297 {} /* terminator */
2298};
2299
Richard Fish11b44bb2006-08-23 18:31:34 +02002300static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2301{
2302 int i;
2303 struct sigmatel_spec *spec = codec->spec;
2304
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002305 kfree(spec->pin_configs);
2306 spec->pin_configs = kcalloc(spec->num_pins, sizeof(*spec->pin_configs),
2307 GFP_KERNEL);
2308 if (!spec->pin_configs)
2309 return -ENOMEM;
Richard Fish11b44bb2006-08-23 18:31:34 +02002310
2311 for (i = 0; i < spec->num_pins; i++) {
2312 hda_nid_t nid = spec->pin_nids[i];
2313 unsigned int pin_cfg;
2314
2315 pin_cfg = snd_hda_codec_read(codec, nid, 0,
2316 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2317 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2318 nid, pin_cfg);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002319 spec->pin_configs[i] = pin_cfg;
Richard Fish11b44bb2006-08-23 18:31:34 +02002320 }
2321
2322 return 0;
2323}
2324
Matthew Ranostay87d48362007-07-17 11:52:24 +02002325static void stac92xx_set_config_reg(struct hda_codec *codec,
2326 hda_nid_t pin_nid, unsigned int pin_config)
2327{
2328 int i;
2329 snd_hda_codec_write(codec, pin_nid, 0,
2330 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2331 pin_config & 0x000000ff);
2332 snd_hda_codec_write(codec, pin_nid, 0,
2333 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2334 (pin_config & 0x0000ff00) >> 8);
2335 snd_hda_codec_write(codec, pin_nid, 0,
2336 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2337 (pin_config & 0x00ff0000) >> 16);
2338 snd_hda_codec_write(codec, pin_nid, 0,
2339 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2340 pin_config >> 24);
2341 i = snd_hda_codec_read(codec, pin_nid, 0,
2342 AC_VERB_GET_CONFIG_DEFAULT,
2343 0x00);
2344 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
2345 pin_nid, i);
2346}
2347
Matt2f2f4252005-04-13 14:45:30 +02002348static void stac92xx_set_config_regs(struct hda_codec *codec)
2349{
2350 int i;
2351 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002352
Matthew Ranostay87d48362007-07-17 11:52:24 +02002353 if (!spec->pin_configs)
2354 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002355
Matthew Ranostay87d48362007-07-17 11:52:24 +02002356 for (i = 0; i < spec->num_pins; i++)
2357 stac92xx_set_config_reg(codec, spec->pin_nids[i],
2358 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02002359}
Matt2f2f4252005-04-13 14:45:30 +02002360
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002361static int stac_save_pin_cfgs(struct hda_codec *codec, unsigned int *pins)
2362{
2363 struct sigmatel_spec *spec = codec->spec;
2364
2365 if (!pins)
2366 return stac92xx_save_bios_config_regs(codec);
2367
2368 kfree(spec->pin_configs);
2369 spec->pin_configs = kmemdup(pins,
2370 spec->num_pins * sizeof(*pins),
2371 GFP_KERNEL);
2372 if (!spec->pin_configs)
2373 return -ENOMEM;
2374
2375 stac92xx_set_config_regs(codec);
2376 return 0;
2377}
2378
2379static void stac_change_pin_config(struct hda_codec *codec, hda_nid_t nid,
2380 unsigned int cfg)
2381{
2382 struct sigmatel_spec *spec = codec->spec;
2383 int i;
2384
2385 for (i = 0; i < spec->num_pins; i++) {
2386 if (spec->pin_nids[i] == nid) {
2387 spec->pin_configs[i] = cfg;
2388 stac92xx_set_config_reg(codec, nid, cfg);
2389 break;
2390 }
2391 }
2392}
2393
Matt2f2f4252005-04-13 14:45:30 +02002394/*
2395 * Analog playback callbacks
2396 */
2397static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2398 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002399 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002400{
2401 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002402 if (spec->stream_delay)
2403 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002404 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2405 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002406}
2407
2408static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2409 struct hda_codec *codec,
2410 unsigned int stream_tag,
2411 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002412 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002413{
2414 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002415 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002416}
2417
2418static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2419 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002420 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002421{
2422 struct sigmatel_spec *spec = codec->spec;
2423 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2424}
2425
2426/*
Mattdabbed62005-06-14 10:19:34 +02002427 * Digital playback callbacks
2428 */
2429static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2430 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002431 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002432{
2433 struct sigmatel_spec *spec = codec->spec;
2434 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2435}
2436
2437static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2438 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002439 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002440{
2441 struct sigmatel_spec *spec = codec->spec;
2442 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2443}
2444
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002445static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2446 struct hda_codec *codec,
2447 unsigned int stream_tag,
2448 unsigned int format,
2449 struct snd_pcm_substream *substream)
2450{
2451 struct sigmatel_spec *spec = codec->spec;
2452 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2453 stream_tag, format, substream);
2454}
2455
Mattdabbed62005-06-14 10:19:34 +02002456
2457/*
Matt2f2f4252005-04-13 14:45:30 +02002458 * Analog capture callbacks
2459 */
2460static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2461 struct hda_codec *codec,
2462 unsigned int stream_tag,
2463 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002464 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002465{
2466 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002467 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002468
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002469 if (spec->powerdown_adcs) {
2470 msleep(40);
2471 snd_hda_codec_write_cache(codec, nid, 0,
2472 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2473 }
2474 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002475 return 0;
2476}
2477
2478static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2479 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002480 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002481{
2482 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002483 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002484
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002485 snd_hda_codec_cleanup_stream(codec, nid);
2486 if (spec->powerdown_adcs)
2487 snd_hda_codec_write_cache(codec, nid, 0,
2488 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002489 return 0;
2490}
2491
Mattdabbed62005-06-14 10:19:34 +02002492static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2493 .substreams = 1,
2494 .channels_min = 2,
2495 .channels_max = 2,
2496 /* NID is set in stac92xx_build_pcms */
2497 .ops = {
2498 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002499 .close = stac92xx_dig_playback_pcm_close,
2500 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02002501 },
2502};
2503
2504static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2505 .substreams = 1,
2506 .channels_min = 2,
2507 .channels_max = 2,
2508 /* NID is set in stac92xx_build_pcms */
2509};
2510
Matt2f2f4252005-04-13 14:45:30 +02002511static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2512 .substreams = 1,
2513 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002514 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002515 .nid = 0x02, /* NID to query formats and rates */
2516 .ops = {
2517 .open = stac92xx_playback_pcm_open,
2518 .prepare = stac92xx_playback_pcm_prepare,
2519 .cleanup = stac92xx_playback_pcm_cleanup
2520 },
2521};
2522
Matt Porter3cc08dc2006-01-23 15:27:49 +01002523static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2524 .substreams = 1,
2525 .channels_min = 2,
2526 .channels_max = 2,
2527 .nid = 0x06, /* NID to query formats and rates */
2528 .ops = {
2529 .open = stac92xx_playback_pcm_open,
2530 .prepare = stac92xx_playback_pcm_prepare,
2531 .cleanup = stac92xx_playback_pcm_cleanup
2532 },
2533};
2534
Matt2f2f4252005-04-13 14:45:30 +02002535static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002536 .channels_min = 2,
2537 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002538 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002539 .ops = {
2540 .prepare = stac92xx_capture_pcm_prepare,
2541 .cleanup = stac92xx_capture_pcm_cleanup
2542 },
2543};
2544
2545static int stac92xx_build_pcms(struct hda_codec *codec)
2546{
2547 struct sigmatel_spec *spec = codec->spec;
2548 struct hda_pcm *info = spec->pcm_rec;
2549
2550 codec->num_pcms = 1;
2551 codec->pcm_info = info;
2552
Mattc7d4b2f2005-06-27 14:59:41 +02002553 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002554 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02002555 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002556 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002557 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002558
2559 if (spec->alt_switch) {
2560 codec->num_pcms++;
2561 info++;
2562 info->name = "STAC92xx Analog Alt";
2563 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2564 }
Matt2f2f4252005-04-13 14:45:30 +02002565
Mattdabbed62005-06-14 10:19:34 +02002566 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2567 codec->num_pcms++;
2568 info++;
2569 info->name = "STAC92xx Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01002570 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Mattdabbed62005-06-14 10:19:34 +02002571 if (spec->multiout.dig_out_nid) {
2572 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2573 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2574 }
2575 if (spec->dig_in_nid) {
2576 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2577 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2578 }
2579 }
2580
Matt2f2f4252005-04-13 14:45:30 +02002581 return 0;
2582}
2583
Takashi Iwaic960a032006-03-23 17:06:28 +01002584static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2585{
2586 unsigned int pincap = snd_hda_param_read(codec, nid,
2587 AC_PAR_PIN_CAP);
2588 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2589 if (pincap & AC_PINCAP_VREF_100)
2590 return AC_PINCTL_VREF_100;
2591 if (pincap & AC_PINCAP_VREF_80)
2592 return AC_PINCTL_VREF_80;
2593 if (pincap & AC_PINCAP_VREF_50)
2594 return AC_PINCTL_VREF_50;
2595 if (pincap & AC_PINCAP_VREF_GRD)
2596 return AC_PINCTL_VREF_GRD;
2597 return 0;
2598}
2599
Matt Porter403d1942005-11-29 15:00:51 +01002600static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2601
2602{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002603 snd_hda_codec_write_cache(codec, nid, 0,
2604 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002605}
2606
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002607#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2608
2609static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2610 struct snd_ctl_elem_value *ucontrol)
2611{
2612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2613 struct sigmatel_spec *spec = codec->spec;
2614
Takashi Iwaid7a89432008-11-12 09:48:04 +01002615 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002616 return 0;
2617}
2618
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002619static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2620 unsigned char type);
2621
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002622static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2623 struct snd_ctl_elem_value *ucontrol)
2624{
2625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2626 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002627 int nid = kcontrol->private_value;
2628
2629 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002630
2631 /* check to be sure that the ports are upto date with
2632 * switch changes
2633 */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002634 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002635
2636 return 1;
2637}
2638
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002639#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01002640
2641static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2642{
2643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2644 struct sigmatel_spec *spec = codec->spec;
2645 int io_idx = kcontrol-> private_value & 0xff;
2646
2647 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2648 return 0;
2649}
2650
2651static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2652{
2653 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2654 struct sigmatel_spec *spec = codec->spec;
2655 hda_nid_t nid = kcontrol->private_value >> 8;
2656 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002657 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01002658
2659 spec->io_switch[io_idx] = val;
2660
2661 if (val)
2662 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002663 else {
2664 unsigned int pinctl = AC_PINCTL_IN_EN;
2665 if (io_idx) /* set VREF for mic */
2666 pinctl |= stac92xx_get_vref(codec, nid);
2667 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2668 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002669
2670 /* check the auto-mute again: we need to mute/unmute the speaker
2671 * appropriately according to the pin direction
2672 */
2673 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002674 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002675
Matt Porter403d1942005-11-29 15:00:51 +01002676 return 1;
2677}
2678
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002679#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2680
2681static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2682 struct snd_ctl_elem_value *ucontrol)
2683{
2684 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2685 struct sigmatel_spec *spec = codec->spec;
2686
2687 ucontrol->value.integer.value[0] = spec->clfe_swap;
2688 return 0;
2689}
2690
2691static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2692 struct snd_ctl_elem_value *ucontrol)
2693{
2694 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2695 struct sigmatel_spec *spec = codec->spec;
2696 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002697 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002698
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002699 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002700 return 0;
2701
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002702 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002703
2704 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2705 spec->clfe_swap ? 0x4 : 0x0);
2706
2707 return 1;
2708}
2709
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002710#define STAC_CODEC_HP_SWITCH(xname) \
2711 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2712 .name = xname, \
2713 .index = 0, \
2714 .info = stac92xx_hp_switch_info, \
2715 .get = stac92xx_hp_switch_get, \
2716 .put = stac92xx_hp_switch_put, \
2717 }
2718
Matt Porter403d1942005-11-29 15:00:51 +01002719#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2720 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2721 .name = xname, \
2722 .index = 0, \
2723 .info = stac92xx_io_switch_info, \
2724 .get = stac92xx_io_switch_get, \
2725 .put = stac92xx_io_switch_put, \
2726 .private_value = xpval, \
2727 }
2728
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002729#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2730 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2731 .name = xname, \
2732 .index = 0, \
2733 .info = stac92xx_clfe_switch_info, \
2734 .get = stac92xx_clfe_switch_get, \
2735 .put = stac92xx_clfe_switch_put, \
2736 .private_value = xpval, \
2737 }
Matt Porter403d1942005-11-29 15:00:51 +01002738
Mattc7d4b2f2005-06-27 14:59:41 +02002739enum {
2740 STAC_CTL_WIDGET_VOL,
2741 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002742 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002743 STAC_CTL_WIDGET_AMP_MUX,
2744 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002745 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002746 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002747 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02002748};
2749
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002750static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002751 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2752 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002753 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002754 STAC_AMP_MUX,
2755 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002756 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002757 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002758 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002759};
2760
2761/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002762static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2763 struct snd_kcontrol_new *ktemp,
2764 int idx, const char *name,
2765 unsigned long val)
Mattc7d4b2f2005-06-27 14:59:41 +02002766{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002767 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002768
Takashi Iwai603c4012008-07-30 15:01:44 +02002769 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2770 knew = snd_array_new(&spec->kctls);
2771 if (!knew)
2772 return -ENOMEM;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002773 *knew = *ktemp;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002774 knew->index = idx;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002775 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002776 if (!knew->name)
Mattc7d4b2f2005-06-27 14:59:41 +02002777 return -ENOMEM;
2778 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002779 return 0;
2780}
2781
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002782static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2783 int type, int idx, const char *name,
2784 unsigned long val)
2785{
2786 return stac92xx_add_control_temp(spec,
2787 &stac92xx_control_templates[type],
2788 idx, name, val);
2789}
2790
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002791
2792/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002793static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2794 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002795{
2796 return stac92xx_add_control_idx(spec, type, 0, name, val);
2797}
2798
Matt Porter403d1942005-11-29 15:00:51 +01002799/* flag inputs as additional dynamic lineouts */
2800static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2801{
2802 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002803 unsigned int wcaps, wtype;
2804 int i, num_dacs = 0;
2805
2806 /* use the wcaps cache to count all DACs available for line-outs */
2807 for (i = 0; i < codec->num_nodes; i++) {
2808 wcaps = codec->wcaps[i];
2809 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002810
Steve Longerbeam7b043892007-05-03 20:50:03 +02002811 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
2812 num_dacs++;
2813 }
Matt Porter403d1942005-11-29 15:00:51 +01002814
Steve Longerbeam7b043892007-05-03 20:50:03 +02002815 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
2816
Matt Porter403d1942005-11-29 15:00:51 +01002817 switch (cfg->line_outs) {
2818 case 3:
2819 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002820 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002821 cfg->line_out_pins[cfg->line_outs] =
2822 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002823 spec->line_switch = 1;
2824 cfg->line_outs++;
2825 }
2826 break;
2827 case 2:
2828 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002829 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002830 cfg->line_out_pins[cfg->line_outs] =
2831 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002832 spec->line_switch = 1;
2833 cfg->line_outs++;
2834 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002835 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002836 cfg->line_out_pins[cfg->line_outs] =
2837 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002838 spec->mic_switch = 1;
2839 cfg->line_outs++;
2840 }
2841 break;
2842 case 1:
2843 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002844 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002845 cfg->line_out_pins[cfg->line_outs] =
2846 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002847 spec->line_switch = 1;
2848 cfg->line_outs++;
2849 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002850 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002851 cfg->line_out_pins[cfg->line_outs] =
2852 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002853 spec->mic_switch = 1;
2854 cfg->line_outs++;
2855 }
2856 break;
2857 }
2858
2859 return 0;
2860}
2861
Steve Longerbeam7b043892007-05-03 20:50:03 +02002862
2863static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2864{
2865 int i;
2866
2867 for (i = 0; i < spec->multiout.num_dacs; i++) {
2868 if (spec->multiout.dac_nids[i] == nid)
2869 return 1;
2870 }
2871
2872 return 0;
2873}
2874
Matt Porter3cc08dc2006-01-23 15:27:49 +01002875/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002876 * Fill in the dac_nids table from the parsed pin configuration
2877 * This function only works when every pin in line_out_pins[]
2878 * contains atleast one DAC in its connection list. Some 92xx
2879 * codecs are not connected directly to a DAC, such as the 9200
2880 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002881 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002882static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02002883 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002884{
2885 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002886 int i, j, conn_len = 0;
2887 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2888 unsigned int wcaps, wtype;
2889
Mattc7d4b2f2005-06-27 14:59:41 +02002890 for (i = 0; i < cfg->line_outs; i++) {
2891 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02002892 conn_len = snd_hda_get_connections(codec, nid, conn,
2893 HDA_MAX_CONNECTIONS);
2894 for (j = 0; j < conn_len; j++) {
2895 wcaps = snd_hda_param_read(codec, conn[j],
2896 AC_PAR_AUDIO_WIDGET_CAP);
2897 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002898 if (wtype != AC_WID_AUD_OUT ||
2899 (wcaps & AC_WCAP_DIGITAL))
2900 continue;
2901 /* conn[j] is a DAC routed to this line-out */
2902 if (!is_in_dac_nids(spec, conn[j]))
2903 break;
2904 }
2905
2906 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002907 if (spec->multiout.num_dacs > 0) {
2908 /* we have already working output pins,
2909 * so let's drop the broken ones again
2910 */
2911 cfg->line_outs = spec->multiout.num_dacs;
2912 break;
2913 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002914 /* error out, no available DAC found */
2915 snd_printk(KERN_ERR
2916 "%s: No available DAC for pin 0x%x\n",
2917 __func__, nid);
2918 return -ENODEV;
2919 }
2920
2921 spec->multiout.dac_nids[i] = conn[j];
2922 spec->multiout.num_dacs++;
2923 if (conn_len > 1) {
2924 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002925 snd_hda_codec_write_cache(codec, nid, 0,
2926 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002927
2928 }
Mattc7d4b2f2005-06-27 14:59:41 +02002929 }
2930
Steve Longerbeam7b043892007-05-03 20:50:03 +02002931 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2932 spec->multiout.num_dacs,
2933 spec->multiout.dac_nids[0],
2934 spec->multiout.dac_nids[1],
2935 spec->multiout.dac_nids[2],
2936 spec->multiout.dac_nids[3],
2937 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02002938 return 0;
2939}
2940
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002941/* create volume control/switch for the given prefx type */
2942static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2943{
2944 char name[32];
2945 int err;
2946
2947 sprintf(name, "%s Playback Volume", pfx);
2948 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2949 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2950 if (err < 0)
2951 return err;
2952 sprintf(name, "%s Playback Switch", pfx);
2953 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2954 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2955 if (err < 0)
2956 return err;
2957 return 0;
2958}
2959
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002960static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2961{
2962 if (!spec->multiout.hp_nid)
2963 spec->multiout.hp_nid = nid;
2964 else if (spec->multiout.num_dacs > 4) {
2965 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2966 return 1;
2967 } else {
2968 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2969 spec->multiout.num_dacs++;
2970 }
2971 return 0;
2972}
2973
2974static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2975{
2976 if (is_in_dac_nids(spec, nid))
2977 return 1;
2978 if (spec->multiout.hp_nid == nid)
2979 return 1;
2980 return 0;
2981}
2982
Mattc7d4b2f2005-06-27 14:59:41 +02002983/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002984static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002985 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002986{
Takashi Iwai19039bd2006-06-28 15:52:16 +02002987 static const char *chname[4] = {
2988 "Front", "Surround", NULL /*CLFE*/, "Side"
2989 };
Matthew Ranostayd21995e2008-10-13 13:22:45 -04002990 hda_nid_t nid = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002991 int i, err;
2992
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002993 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002994 unsigned int wid_caps, pincap;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002995
2996
Takashi Iwai40ac8c42008-02-29 14:16:17 +01002997 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01002998 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02002999 continue;
3000
3001 nid = spec->multiout.dac_nids[i];
3002
3003 if (i == 2) {
3004 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003005 err = create_controls(spec, "Center", nid, 1);
3006 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003007 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003008 err = create_controls(spec, "LFE", nid, 2);
3009 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003010 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003011
3012 wid_caps = get_wcaps(codec, nid);
3013
3014 if (wid_caps & AC_WCAP_LR_SWAP) {
3015 err = stac92xx_add_control(spec,
3016 STAC_CTL_WIDGET_CLFE_SWITCH,
3017 "Swap Center/LFE Playback Switch", nid);
3018
3019 if (err < 0)
3020 return err;
3021 }
3022
Mattc7d4b2f2005-06-27 14:59:41 +02003023 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003024 err = create_controls(spec, chname[i], nid, 3);
3025 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003026 return err;
3027 }
3028 }
3029
Matthew Ranostayfedb7562008-09-23 21:46:30 -04003030 if ((spec->multiout.num_dacs - cfg->line_outs) > 0 &&
3031 cfg->hp_outs && !spec->multiout.hp_nid)
3032 spec->multiout.hp_nid = nid;
3033
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003034 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003035 err = stac92xx_add_control(spec,
3036 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003037 "Headphone as Line Out Switch",
3038 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003039 if (err < 0)
3040 return err;
3041 }
3042
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003043 if (spec->line_switch) {
3044 nid = cfg->input_pins[AUTO_PIN_LINE];
3045 pincap = snd_hda_param_read(codec, nid,
3046 AC_PAR_PIN_CAP);
3047 if (pincap & AC_PINCAP_OUT) {
3048 err = stac92xx_add_control(spec,
3049 STAC_CTL_WIDGET_IO_SWITCH,
3050 "Line In as Output Switch", nid << 8);
3051 if (err < 0)
3052 return err;
3053 }
3054 }
Matt Porter403d1942005-11-29 15:00:51 +01003055
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003056 if (spec->mic_switch) {
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003057 unsigned int def_conf;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003058 unsigned int mic_pin = AUTO_PIN_MIC;
3059again:
3060 nid = cfg->input_pins[mic_pin];
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003061 def_conf = snd_hda_codec_read(codec, nid, 0,
3062 AC_VERB_GET_CONFIG_DEFAULT, 0);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003063 /* some laptops have an internal analog microphone
3064 * which can't be used as a output */
3065 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
3066 pincap = snd_hda_param_read(codec, nid,
3067 AC_PAR_PIN_CAP);
3068 if (pincap & AC_PINCAP_OUT) {
3069 err = stac92xx_add_control(spec,
3070 STAC_CTL_WIDGET_IO_SWITCH,
3071 "Mic as Output Switch", (nid << 8) | 1);
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003072 nid = snd_hda_codec_read(codec, nid, 0,
3073 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3074 if (!check_in_dac_nids(spec, nid))
3075 add_spec_dacs(spec, nid);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003076 if (err < 0)
3077 return err;
3078 }
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003079 } else if (mic_pin == AUTO_PIN_MIC) {
3080 mic_pin = AUTO_PIN_FRONT_MIC;
3081 goto again;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003082 }
3083 }
Matt Porter403d1942005-11-29 15:00:51 +01003084
Mattc7d4b2f2005-06-27 14:59:41 +02003085 return 0;
3086}
3087
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003088/* add playback controls for Speaker and HP outputs */
3089static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3090 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003091{
3092 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003093 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003094 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003095
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003096 old_num_dacs = spec->multiout.num_dacs;
3097 for (i = 0; i < cfg->hp_outs; i++) {
3098 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
3099 if (wid_caps & AC_WCAP_UNSOL_CAP)
3100 spec->hp_detect = 1;
3101 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
3102 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3103 if (check_in_dac_nids(spec, nid))
3104 nid = 0;
3105 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02003106 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003107 add_spec_dacs(spec, nid);
3108 }
3109 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02003110 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003111 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3112 if (check_in_dac_nids(spec, nid))
3113 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003114 if (! nid)
3115 continue;
3116 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02003117 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02003118 for (i = 0; i < cfg->line_outs; i++) {
3119 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
3120 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3121 if (check_in_dac_nids(spec, nid))
3122 nid = 0;
3123 if (! nid)
3124 continue;
3125 add_spec_dacs(spec, nid);
3126 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003127 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
3128 static const char *pfxs[] = {
3129 "Speaker", "External Speaker", "Speaker2",
3130 };
3131 err = create_controls(spec, pfxs[i - old_num_dacs],
3132 spec->multiout.dac_nids[i], 3);
3133 if (err < 0)
3134 return err;
3135 }
3136 if (spec->multiout.hp_nid) {
Takashi Iwai2626a262008-03-14 09:18:32 +01003137 err = create_controls(spec, "Headphone",
3138 spec->multiout.hp_nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003139 if (err < 0)
3140 return err;
3141 }
Mattc7d4b2f2005-06-27 14:59:41 +02003142
3143 return 0;
3144}
3145
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003146/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003147static const char *stac92xx_mono_labels[4] = {
3148 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003149};
3150
3151/* create mono mux for mono out on capable codecs */
3152static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3153{
3154 struct sigmatel_spec *spec = codec->spec;
3155 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3156 int i, num_cons;
3157 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3158
3159 num_cons = snd_hda_get_connections(codec,
3160 spec->mono_nid,
3161 con_lst,
3162 HDA_MAX_NUM_INPUTS);
3163 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3164 return -EINVAL;
3165
3166 for (i = 0; i < num_cons; i++) {
3167 mono_mux->items[mono_mux->num_items].label =
3168 stac92xx_mono_labels[i];
3169 mono_mux->items[mono_mux->num_items].index = i;
3170 mono_mux->num_items++;
3171 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003172
3173 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3174 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003175}
3176
Matthew Ranostay89385032008-09-11 09:49:39 -04003177/* labels for amp mux outputs */
3178static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003179 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003180};
3181
3182/* create amp out controls mux on capable codecs */
3183static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3184{
3185 struct sigmatel_spec *spec = codec->spec;
3186 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3187 int i, err;
3188
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003189 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003190 amp_mux->items[amp_mux->num_items].label =
3191 stac92xx_amp_labels[i];
3192 amp_mux->items[amp_mux->num_items].index = i;
3193 amp_mux->num_items++;
3194 }
3195
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003196 if (spec->num_amps > 1) {
3197 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3198 "Amp Selector Capture Switch", 0);
3199 if (err < 0)
3200 return err;
3201 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003202 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3203 "Amp Capture Volume",
3204 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3205}
3206
3207
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003208/* create PC beep volume controls */
3209static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3210 hda_nid_t nid)
3211{
3212 struct sigmatel_spec *spec = codec->spec;
3213 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3214 int err;
3215
3216 /* check for mute support for the the amp */
3217 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3218 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3219 "PC Beep Playback Switch",
3220 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3221 if (err < 0)
3222 return err;
3223 }
3224
3225 /* check to see if there is volume support for the amp */
3226 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3227 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3228 "PC Beep Playback Volume",
3229 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3230 if (err < 0)
3231 return err;
3232 }
3233 return 0;
3234}
3235
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003236#ifdef CONFIG_SND_HDA_INPUT_BEEP
3237#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3238
3239static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3240 struct snd_ctl_elem_value *ucontrol)
3241{
3242 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3243 ucontrol->value.integer.value[0] = codec->beep->enabled;
3244 return 0;
3245}
3246
3247static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3248 struct snd_ctl_elem_value *ucontrol)
3249{
3250 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3251 int enabled = !!ucontrol->value.integer.value[0];
3252 if (codec->beep->enabled != enabled) {
3253 codec->beep->enabled = enabled;
3254 return 1;
3255 }
3256 return 0;
3257}
3258
3259static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3260 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3261 .info = stac92xx_dig_beep_switch_info,
3262 .get = stac92xx_dig_beep_switch_get,
3263 .put = stac92xx_dig_beep_switch_put,
3264};
3265
3266static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3267{
3268 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3269 0, "PC Beep Playback Switch", 0);
3270}
3271#endif
3272
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003273static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3274{
3275 struct sigmatel_spec *spec = codec->spec;
3276 int wcaps, nid, i, err = 0;
3277
3278 for (i = 0; i < spec->num_muxes; i++) {
3279 nid = spec->mux_nids[i];
3280 wcaps = get_wcaps(codec, nid);
3281
3282 if (wcaps & AC_WCAP_OUT_AMP) {
3283 err = stac92xx_add_control_idx(spec,
3284 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3285 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3286 if (err < 0)
3287 return err;
3288 }
3289 }
3290 return 0;
3291};
3292
Matthew Ranostayd9737752008-09-07 12:03:41 +02003293static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003294 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003295};
3296
3297static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3298{
3299 struct sigmatel_spec *spec = codec->spec;
3300 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003301 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003302 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003303 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003304
3305 num_cons = snd_hda_get_connections(codec,
3306 spec->smux_nids[0],
3307 con_lst,
3308 HDA_MAX_NUM_INPUTS);
Matthew Ranostay65973632008-09-16 10:39:37 -04003309 if (!num_cons)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003310 return -EINVAL;
3311
Matthew Ranostay65973632008-09-16 10:39:37 -04003312 if (!labels)
3313 labels = stac92xx_spdif_labels;
3314
Matthew Ranostayd9737752008-09-07 12:03:41 +02003315 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003316 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003317 spdif_mux->items[spdif_mux->num_items].index = i;
3318 spdif_mux->num_items++;
3319 }
3320
3321 return 0;
3322}
3323
Matt Porter8b657272006-10-26 17:12:59 +02003324/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003325static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003326 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3327 "Digital Mic 3", "Digital Mic 4"
3328};
3329
3330/* create playback/capture controls for input pins on dmic capable codecs */
3331static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3332 const struct auto_pin_cfg *cfg)
3333{
3334 struct sigmatel_spec *spec = codec->spec;
3335 struct hda_input_mux *dimux = &spec->private_dimux;
3336 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003337 int err, i, j;
3338 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02003339
3340 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3341 dimux->items[dimux->num_items].index = 0;
3342 dimux->num_items++;
3343
3344 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003345 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003346 int index;
3347 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003348 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02003349 unsigned int def_conf;
3350
3351 def_conf = snd_hda_codec_read(codec,
3352 spec->dmic_nids[i],
3353 0,
3354 AC_VERB_GET_CONFIG_DEFAULT,
3355 0);
3356 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3357 continue;
3358
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003359 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02003360 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003361 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02003362 con_lst,
3363 HDA_MAX_NUM_INPUTS);
3364 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003365 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02003366 index = j;
3367 goto found;
3368 }
3369 continue;
3370found:
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003371 wcaps = get_wcaps(codec, nid) &
3372 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003373
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003374 if (wcaps) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003375 sprintf(name, "%s Capture Volume",
3376 stac92xx_dmic_labels[dimux->num_items]);
3377
3378 err = stac92xx_add_control(spec,
3379 STAC_CTL_WIDGET_VOL,
3380 name,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003381 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3382 (wcaps & AC_WCAP_OUT_AMP) ?
3383 HDA_OUTPUT : HDA_INPUT));
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003384 if (err < 0)
3385 return err;
3386 }
3387
Matt Porter8b657272006-10-26 17:12:59 +02003388 dimux->items[dimux->num_items].label =
3389 stac92xx_dmic_labels[dimux->num_items];
3390 dimux->items[dimux->num_items].index = index;
3391 dimux->num_items++;
3392 }
3393
3394 return 0;
3395}
3396
Mattc7d4b2f2005-06-27 14:59:41 +02003397/* create playback/capture controls for input pins */
3398static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3399{
3400 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003401 struct hda_input_mux *imux = &spec->private_imux;
3402 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3403 int i, j, k;
3404
3405 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003406 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02003407
Takashi Iwai314634b2006-09-21 11:56:18 +02003408 if (!cfg->input_pins[i])
3409 continue;
3410 index = -1;
3411 for (j = 0; j < spec->num_muxes; j++) {
3412 int num_cons;
3413 num_cons = snd_hda_get_connections(codec,
3414 spec->mux_nids[j],
3415 con_lst,
3416 HDA_MAX_NUM_INPUTS);
3417 for (k = 0; k < num_cons; k++)
3418 if (con_lst[k] == cfg->input_pins[i]) {
3419 index = k;
3420 goto found;
3421 }
Mattc7d4b2f2005-06-27 14:59:41 +02003422 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003423 continue;
3424 found:
3425 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3426 imux->items[imux->num_items].index = index;
3427 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003428 }
3429
Steve Longerbeam7b043892007-05-03 20:50:03 +02003430 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003431 /*
3432 * Set the current input for the muxes.
3433 * The STAC9221 has two input muxes with identical source
3434 * NID lists. Hopefully this won't get confused.
3435 */
3436 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003437 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3438 AC_VERB_SET_CONNECT_SEL,
3439 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003440 }
3441 }
3442
Mattc7d4b2f2005-06-27 14:59:41 +02003443 return 0;
3444}
3445
Mattc7d4b2f2005-06-27 14:59:41 +02003446static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3447{
3448 struct sigmatel_spec *spec = codec->spec;
3449 int i;
3450
3451 for (i = 0; i < spec->autocfg.line_outs; i++) {
3452 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3453 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3454 }
3455}
3456
3457static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3458{
3459 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003460 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003461
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003462 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3463 hda_nid_t pin;
3464 pin = spec->autocfg.hp_pins[i];
3465 if (pin) /* connect to front */
3466 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3467 }
3468 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3469 hda_nid_t pin;
3470 pin = spec->autocfg.speaker_pins[i];
3471 if (pin) /* connect to front */
3472 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3473 }
Mattc7d4b2f2005-06-27 14:59:41 +02003474}
3475
Matt Porter3cc08dc2006-01-23 15:27:49 +01003476static 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 +02003477{
3478 struct sigmatel_spec *spec = codec->spec;
3479 int err;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003480 int hp_speaker_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003481
Matt Porter8b657272006-10-26 17:12:59 +02003482 if ((err = snd_hda_parse_pin_def_config(codec,
3483 &spec->autocfg,
3484 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003485 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003486 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003487 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003488
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003489 /* If we have no real line-out pin and multiple hp-outs, HPs should
3490 * be set up as multi-channel outputs.
3491 */
3492 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3493 spec->autocfg.hp_outs > 1) {
3494 /* Copy hp_outs to line_outs, backup line_outs in
3495 * speaker_outs so that the following routines can handle
3496 * HP pins as primary outputs.
3497 */
3498 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3499 sizeof(spec->autocfg.line_out_pins));
3500 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3501 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3502 sizeof(spec->autocfg.hp_pins));
3503 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3504 hp_speaker_swap = 1;
3505 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003506 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003507 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3508 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003509 u32 caps = query_amp_caps(codec,
3510 spec->autocfg.mono_out_pin, dir);
3511 hda_nid_t conn_list[1];
3512
3513 /* get the mixer node and then the mono mux if it exists */
3514 if (snd_hda_get_connections(codec,
3515 spec->autocfg.mono_out_pin, conn_list, 1) &&
3516 snd_hda_get_connections(codec, conn_list[0],
3517 conn_list, 1)) {
3518
3519 int wcaps = get_wcaps(codec, conn_list[0]);
3520 int wid_type = (wcaps & AC_WCAP_TYPE)
3521 >> AC_WCAP_TYPE_SHIFT;
3522 /* LR swap check, some stac925x have a mux that
3523 * changes the DACs output path instead of the
3524 * mono-mux path.
3525 */
3526 if (wid_type == AC_WID_AUD_SEL &&
3527 !(wcaps & AC_WCAP_LR_SWAP))
3528 spec->mono_nid = conn_list[0];
3529 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003530 if (dir) {
3531 hda_nid_t nid = spec->autocfg.mono_out_pin;
3532
3533 /* most mono outs have a least a mute/unmute switch */
3534 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3535 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3536 "Mono Playback Switch",
3537 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003538 if (err < 0)
3539 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003540 /* check for volume support for the amp */
3541 if ((caps & AC_AMPCAP_NUM_STEPS)
3542 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3543 err = stac92xx_add_control(spec,
3544 STAC_CTL_WIDGET_VOL,
3545 "Mono Playback Volume",
3546 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3547 if (err < 0)
3548 return err;
3549 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003550 }
3551
3552 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3553 AC_PINCTL_OUT_EN);
3554 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003555
Matt Porter403d1942005-11-29 15:00:51 +01003556 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
3557 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003558 if (spec->multiout.num_dacs == 0)
3559 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3560 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003561
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003562 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
3563
3564 if (err < 0)
3565 return err;
3566
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003567 /* setup analog beep controls */
3568 if (spec->anabeep_nid > 0) {
3569 err = stac92xx_auto_create_beep_ctls(codec,
3570 spec->anabeep_nid);
3571 if (err < 0)
3572 return err;
3573 }
3574
3575 /* setup digital beep controls and input device */
3576#ifdef CONFIG_SND_HDA_INPUT_BEEP
3577 if (spec->digbeep_nid > 0) {
3578 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003579 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003580
3581 err = stac92xx_auto_create_beep_ctls(codec, nid);
3582 if (err < 0)
3583 return err;
3584 err = snd_hda_attach_beep_device(codec, nid);
3585 if (err < 0)
3586 return err;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003587 /* if no beep switch is available, make its own one */
3588 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3589 if (codec->beep &&
3590 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3591 err = stac92xx_beep_switch_ctl(codec);
3592 if (err < 0)
3593 return err;
3594 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003595 }
3596#endif
3597
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003598 if (hp_speaker_swap == 1) {
3599 /* Restore the hp_outs and line_outs */
3600 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3601 sizeof(spec->autocfg.line_out_pins));
3602 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3603 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
3604 sizeof(spec->autocfg.speaker_pins));
3605 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
3606 memset(spec->autocfg.speaker_pins, 0,
3607 sizeof(spec->autocfg.speaker_pins));
3608 spec->autocfg.speaker_outs = 0;
3609 }
3610
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003611 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3612
3613 if (err < 0)
3614 return err;
3615
3616 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3617
3618 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003619 return err;
3620
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003621 if (spec->mono_nid > 0) {
3622 err = stac92xx_auto_create_mono_output_ctls(codec);
3623 if (err < 0)
3624 return err;
3625 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003626 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003627 err = stac92xx_auto_create_amp_output_ctls(codec);
3628 if (err < 0)
3629 return err;
3630 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003631 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003632 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3633 &spec->autocfg)) < 0)
3634 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003635 if (spec->num_muxes > 0) {
3636 err = stac92xx_auto_create_mux_input_ctls(codec);
3637 if (err < 0)
3638 return err;
3639 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003640 if (spec->num_smuxes > 0) {
3641 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3642 if (err < 0)
3643 return err;
3644 }
Matt Porter8b657272006-10-26 17:12:59 +02003645
Mattc7d4b2f2005-06-27 14:59:41 +02003646 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003647 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003648 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003649
Takashi Iwai82bc9552006-03-21 11:24:42 +01003650 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003651 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003652 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003653 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003654
Takashi Iwai603c4012008-07-30 15:01:44 +02003655 if (spec->kctls.list)
3656 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003657
3658 spec->input_mux = &spec->private_imux;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003659 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003660 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003661 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04003662 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003663 return 1;
3664}
3665
Takashi Iwai82bc9552006-03-21 11:24:42 +01003666/* add playback controls for HP output */
3667static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3668 struct auto_pin_cfg *cfg)
3669{
3670 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003671 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003672 unsigned int wid_caps;
3673
3674 if (! pin)
3675 return 0;
3676
3677 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003678 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003679 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003680
3681 return 0;
3682}
3683
Richard Fish160ea0d2006-09-06 13:58:25 +02003684/* add playback controls for LFE output */
3685static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3686 struct auto_pin_cfg *cfg)
3687{
3688 struct sigmatel_spec *spec = codec->spec;
3689 int err;
3690 hda_nid_t lfe_pin = 0x0;
3691 int i;
3692
3693 /*
3694 * search speaker outs and line outs for a mono speaker pin
3695 * with an amp. If one is found, add LFE controls
3696 * for it.
3697 */
3698 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3699 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003700 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003701 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3702 if (wcaps == AC_WCAP_OUT_AMP)
3703 /* found a mono speaker with an amp, must be lfe */
3704 lfe_pin = pin;
3705 }
3706
3707 /* if speaker_outs is 0, then speakers may be in line_outs */
3708 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3709 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3710 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003711 unsigned int defcfg;
Harvey Harrison8b551782008-02-29 11:56:48 +01003712 defcfg = snd_hda_codec_read(codec, pin, 0,
Richard Fish160ea0d2006-09-06 13:58:25 +02003713 AC_VERB_GET_CONFIG_DEFAULT,
3714 0x00);
Harvey Harrison8b551782008-02-29 11:56:48 +01003715 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003716 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003717 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3718 if (wcaps == AC_WCAP_OUT_AMP)
3719 /* found a mono speaker with an amp,
3720 must be lfe */
3721 lfe_pin = pin;
3722 }
3723 }
3724 }
3725
3726 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003727 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003728 if (err < 0)
3729 return err;
3730 }
3731
3732 return 0;
3733}
3734
Mattc7d4b2f2005-06-27 14:59:41 +02003735static int stac9200_parse_auto_config(struct hda_codec *codec)
3736{
3737 struct sigmatel_spec *spec = codec->spec;
3738 int err;
3739
Kailang Yangdf694da2005-12-05 19:42:22 +01003740 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003741 return err;
3742
3743 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3744 return err;
3745
Takashi Iwai82bc9552006-03-21 11:24:42 +01003746 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3747 return err;
3748
Richard Fish160ea0d2006-09-06 13:58:25 +02003749 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3750 return err;
3751
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003752 if (spec->num_muxes > 0) {
3753 err = stac92xx_auto_create_mux_input_ctls(codec);
3754 if (err < 0)
3755 return err;
3756 }
3757
Takashi Iwai82bc9552006-03-21 11:24:42 +01003758 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003759 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003760 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003761 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003762
Takashi Iwai603c4012008-07-30 15:01:44 +02003763 if (spec->kctls.list)
3764 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003765
3766 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003767 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003768
3769 return 1;
3770}
3771
Sam Revitch62fe78e2006-05-10 15:09:17 +02003772/*
3773 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3774 * funky external mute control using GPIO pins.
3775 */
3776
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003777static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003778 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003779{
3780 unsigned int gpiostate, gpiomask, gpiodir;
3781
3782 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3783 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003784 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003785
3786 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3787 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003788 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003789
3790 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3791 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003792 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003793
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003794 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003795 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3796
3797 snd_hda_codec_write(codec, codec->afg, 0,
3798 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003799 snd_hda_codec_read(codec, codec->afg, 0,
3800 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003801
3802 msleep(1);
3803
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003804 snd_hda_codec_read(codec, codec->afg, 0,
3805 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003806}
3807
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003808static int stac92xx_add_jack(struct hda_codec *codec,
3809 hda_nid_t nid, int type)
3810{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003811#ifdef CONFIG_SND_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003812 struct sigmatel_spec *spec = codec->spec;
3813 struct sigmatel_jack *jack;
3814 int def_conf = snd_hda_codec_read(codec, nid,
3815 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
3816 int connectivity = get_defcfg_connect(def_conf);
3817 char name[32];
3818
3819 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3820 return 0;
3821
3822 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3823 jack = snd_array_new(&spec->jacks);
3824 if (!jack)
3825 return -ENOMEM;
3826 jack->nid = nid;
3827 jack->type = type;
3828
3829 sprintf(name, "%s at %s %s Jack",
3830 snd_hda_get_jack_type(def_conf),
3831 snd_hda_get_jack_connectivity(def_conf),
3832 snd_hda_get_jack_location(def_conf));
3833
3834 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003835#else
3836 return 0;
3837#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003838}
3839
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003840static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3841 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003842{
3843 struct sigmatel_event *event;
3844
3845 snd_array_init(&spec->events, sizeof(*event), 32);
3846 event = snd_array_new(&spec->events);
3847 if (!event)
3848 return -ENOMEM;
3849 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003850 event->type = type;
3851 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003852 event->data = data;
3853
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003854 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003855}
3856
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003857static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
3858 hda_nid_t nid, unsigned char type)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003859{
3860 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003861 struct sigmatel_event *event = spec->events.list;
3862 int i;
3863
3864 for (i = 0; i < spec->events.used; i++, event++) {
3865 if (event->nid == nid && event->type == type)
3866 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003867 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003868 return NULL;
3869}
3870
3871static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
3872 unsigned char tag)
3873{
3874 struct sigmatel_spec *spec = codec->spec;
3875 struct sigmatel_event *event = spec->events.list;
3876 int i;
3877
3878 for (i = 0; i < spec->events.used; i++, event++) {
3879 if (event->tag == tag)
3880 return event;
3881 }
3882 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003883}
3884
Takashi Iwai314634b2006-09-21 11:56:18 +02003885static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003886 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02003887{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003888 struct sigmatel_event *event;
3889 int tag;
3890
3891 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
3892 return;
3893 event = stac_get_event(codec, nid, type);
3894 if (event)
3895 tag = event->tag;
3896 else
3897 tag = stac_add_event(codec->spec, nid, type, 0);
3898 if (tag < 0)
3899 return;
3900 snd_hda_codec_write_cache(codec, nid, 0,
3901 AC_VERB_SET_UNSOLICITED_ENABLE,
3902 AC_USRSP_EN | tag);
Takashi Iwai314634b2006-09-21 11:56:18 +02003903}
3904
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003905static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3906{
3907 int i;
3908 for (i = 0; i < cfg->hp_outs; i++)
3909 if (cfg->hp_pins[i] == nid)
3910 return 1; /* nid is a HP-Out */
3911
3912 return 0; /* nid is not a HP-Out */
3913};
3914
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003915static void stac92xx_power_down(struct hda_codec *codec)
3916{
3917 struct sigmatel_spec *spec = codec->spec;
3918
3919 /* power down inactive DACs */
3920 hda_nid_t *dac;
3921 for (dac = spec->dac_list; *dac; dac++)
Matthew Ranostay44510892008-02-21 07:49:31 +01003922 if (!is_in_dac_nids(spec, *dac) &&
3923 spec->multiout.hp_nid != *dac)
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003924 snd_hda_codec_write_cache(codec, *dac, 0,
3925 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3926}
3927
Takashi Iwaif73d3582008-11-25 08:21:51 +01003928static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3929 int enable);
3930
Mattc7d4b2f2005-06-27 14:59:41 +02003931static int stac92xx_init(struct hda_codec *codec)
3932{
3933 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003934 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01003935 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01003936 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003937
Mattc7d4b2f2005-06-27 14:59:41 +02003938 snd_hda_sequence_write(codec, spec->init);
3939
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02003940 /* power down adcs initially */
3941 if (spec->powerdown_adcs)
3942 for (i = 0; i < spec->num_adcs; i++)
3943 snd_hda_codec_write_cache(codec,
3944 spec->adc_nids[i], 0,
3945 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003946
3947 /* set up GPIO */
3948 gpio = spec->gpio_data;
3949 /* turn on EAPD statically when spec->eapd_switch isn't set.
3950 * otherwise, unsol event will turn it on/off dynamically
3951 */
3952 if (!spec->eapd_switch)
3953 gpio |= spec->eapd_mask;
3954 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
3955
Takashi Iwai82bc9552006-03-21 11:24:42 +01003956 /* set up pins */
3957 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02003958 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003959 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003960 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003961 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003962 }
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01003963 /* force to enable the first line-out; the others are set up
3964 * in unsol_event
3965 */
3966 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003967 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003968 /* fake event to set up pins */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003969 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
3970 STAC_HP_EVENT);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003971 } else {
3972 stac92xx_auto_init_multi_out(codec);
3973 stac92xx_auto_init_hp_out(codec);
3974 }
3975 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01003976 hda_nid_t nid = cfg->input_pins[i];
3977 if (nid) {
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01003978 unsigned int pinctl;
3979 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
3980 /* for mic pins, force to initialize */
3981 pinctl = stac92xx_get_vref(codec, nid);
3982 } else {
3983 pinctl = snd_hda_codec_read(codec, nid, 0,
3984 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3985 /* if PINCTL already set then skip */
3986 if (pinctl & AC_PINCTL_IN_EN)
3987 continue;
3988 }
3989 pinctl |= AC_PINCTL_IN_EN;
Takashi Iwaic960a032006-03-23 17:06:28 +01003990 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003991 enable_pin_detect(codec, nid, STAC_INSERT_EVENT);
Takashi Iwaic960a032006-03-23 17:06:28 +01003992 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01003993 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003994 for (i = 0; i < spec->num_dmics; i++)
3995 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
3996 AC_PINCTL_IN_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003997 if (cfg->dig_out_pin)
3998 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
3999 AC_PINCTL_OUT_EN);
4000 if (cfg->dig_in_pin)
4001 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4002 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004003 for (i = 0; i < spec->num_pwrs; i++) {
4004 hda_nid_t nid = spec->pwr_nids[i];
4005 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004006
Takashi Iwaif73d3582008-11-25 08:21:51 +01004007 if (is_nid_hp_pin(cfg, nid) && spec->hp_detect)
4008 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004009
Takashi Iwaif73d3582008-11-25 08:21:51 +01004010 pinctl = snd_hda_codec_read(codec, nid, 0,
4011 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4012 /* outputs are only ports capable of power management
4013 * any attempts on powering down a input port cause the
4014 * referenced VREF to act quirky.
4015 */
4016 if (pinctl & AC_PINCTL_IN_EN)
4017 continue;
4018 def_conf = snd_hda_codec_read(codec, nid, 0,
4019 AC_VERB_GET_CONFIG_DEFAULT, 0);
4020 def_conf = get_defcfg_connect(def_conf);
4021 /* skip any ports that don't have jacks since presence
4022 * detection is useless */
4023 if (def_conf != AC_JACK_PORT_COMPLEX) {
4024 if (def_conf != AC_JACK_PORT_NONE)
4025 stac_toggle_power_map(codec, nid, 1);
4026 continue;
4027 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004028 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
4029 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004030 }
4031 if (spec->dac_list)
4032 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004033 return 0;
4034}
4035
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004036static void stac92xx_free_jacks(struct hda_codec *codec)
4037{
Takashi Iwaie4973e12008-11-18 09:32:42 +01004038#ifdef CONFIG_SND_JACK
Takashi Iwaib94d3532008-11-21 09:08:06 +01004039 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004040 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d3532008-11-21 09:08:06 +01004041 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004042 struct sigmatel_jack *jacks = spec->jacks.list;
4043 int i;
4044 for (i = 0; i < spec->jacks.used; i++)
4045 snd_device_free(codec->bus->card, &jacks[i].jack);
4046 }
4047 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004048#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004049}
4050
Takashi Iwai603c4012008-07-30 15:01:44 +02004051static void stac92xx_free_kctls(struct hda_codec *codec)
4052{
4053 struct sigmatel_spec *spec = codec->spec;
4054
4055 if (spec->kctls.list) {
4056 struct snd_kcontrol_new *kctl = spec->kctls.list;
4057 int i;
4058 for (i = 0; i < spec->kctls.used; i++)
4059 kfree(kctl[i].name);
4060 }
4061 snd_array_free(&spec->kctls);
4062}
4063
Matt2f2f4252005-04-13 14:45:30 +02004064static void stac92xx_free(struct hda_codec *codec)
4065{
Mattc7d4b2f2005-06-27 14:59:41 +02004066 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004067
4068 if (! spec)
4069 return;
4070
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004071 kfree(spec->pin_configs);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004072 stac92xx_free_jacks(codec);
4073 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004074
Mattc7d4b2f2005-06-27 14:59:41 +02004075 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004076 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004077}
4078
Matt4e550962005-07-04 17:51:39 +02004079static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4080 unsigned int flag)
4081{
4082 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4083 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004084
Takashi Iwaif9acba42007-05-29 18:01:06 +02004085 if (pin_ctl & AC_PINCTL_IN_EN) {
4086 /*
4087 * we need to check the current set-up direction of
4088 * shared input pins since they can be switched via
4089 * "xxx as Output" mixer switch
4090 */
4091 struct sigmatel_spec *spec = codec->spec;
4092 struct auto_pin_cfg *cfg = &spec->autocfg;
4093 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
4094 spec->line_switch) ||
4095 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
4096 spec->mic_switch))
4097 return;
4098 }
4099
Steve Longerbeam7b043892007-05-03 20:50:03 +02004100 /* if setting pin direction bits, clear the current
4101 direction bits first */
4102 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4103 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4104
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004105 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02004106 AC_VERB_SET_PIN_WIDGET_CONTROL,
4107 pin_ctl | flag);
4108}
4109
4110static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4111 unsigned int flag)
4112{
4113 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4114 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004115 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02004116 AC_VERB_SET_PIN_WIDGET_CONTROL,
4117 pin_ctl & ~flag);
4118}
4119
Jiang Zhe40c1d302007-11-12 13:05:16 +01004120static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004121{
4122 if (!nid)
4123 return 0;
4124 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Jiang Zhe40c1d302007-11-12 13:05:16 +01004125 & (1 << 31)) {
4126 unsigned int pinctl;
4127 pinctl = snd_hda_codec_read(codec, nid, 0,
4128 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4129 if (pinctl & AC_PINCTL_IN_EN)
4130 return 0; /* mic- or line-input */
4131 else
4132 return 1; /* HP-output */
4133 }
Takashi Iwai314634b2006-09-21 11:56:18 +02004134 return 0;
4135}
4136
Takashi Iwaid7a89432008-11-12 09:48:04 +01004137/* return non-zero if the hp-pin of the given array index isn't
4138 * a jack-detection target
4139 */
4140static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4141{
4142 struct auto_pin_cfg *cfg = &spec->autocfg;
4143
4144 /* ignore sensing of shared line and mic jacks */
4145 if (spec->line_switch &&
4146 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_LINE])
4147 return 1;
4148 if (spec->mic_switch &&
4149 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_MIC])
4150 return 1;
4151 /* ignore if the pin is set as line-out */
4152 if (cfg->hp_pins[i] == spec->hp_switch)
4153 return 1;
4154 return 0;
4155}
4156
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004157static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004158{
4159 struct sigmatel_spec *spec = codec->spec;
4160 struct auto_pin_cfg *cfg = &spec->autocfg;
4161 int i, presence;
4162
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004163 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004164 if (spec->gpio_mute)
4165 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4166 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4167
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004168 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004169 if (presence)
4170 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004171 if (no_hp_sensing(spec, i))
4172 continue;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004173 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004174 }
Matt4e550962005-07-04 17:51:39 +02004175
4176 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004177 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004178 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004179 stac92xx_reset_pinctl(codec, spec->hp_switch,
4180 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004181 for (i = 0; i < cfg->line_outs; i++)
4182 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4183 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004184 for (i = 0; i < cfg->speaker_outs; i++)
4185 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4186 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004187 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004188 stac_gpio_set(codec, spec->gpio_mask,
4189 spec->gpio_dir, spec->gpio_data &
4190 ~spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004191 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004192 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004193 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004194 stac92xx_set_pinctl(codec, spec->hp_switch,
4195 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004196 for (i = 0; i < cfg->line_outs; i++)
4197 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4198 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004199 for (i = 0; i < cfg->speaker_outs; i++)
4200 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4201 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004202 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004203 stac_gpio_set(codec, spec->gpio_mask,
4204 spec->gpio_dir, spec->gpio_data |
4205 spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004206 }
Takashi Iwaid7a89432008-11-12 09:48:04 +01004207 /* toggle hp outs */
4208 for (i = 0; i < cfg->hp_outs; i++) {
4209 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4210 if (no_hp_sensing(spec, i))
4211 continue;
4212 if (presence)
4213 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4214 else
4215 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4216 }
Matt4e550962005-07-04 17:51:39 +02004217}
4218
Takashi Iwaif73d3582008-11-25 08:21:51 +01004219static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4220 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004221{
4222 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004223 unsigned int idx, val;
4224
4225 for (idx = 0; idx < spec->num_pwrs; idx++) {
4226 if (spec->pwr_nids[idx] == nid)
4227 break;
4228 }
4229 if (idx >= spec->num_pwrs)
4230 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004231
4232 /* several codecs have two power down bits */
4233 if (spec->pwr_mapping)
4234 idx = spec->pwr_mapping[idx];
4235 else
4236 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004237
Takashi Iwaif73d3582008-11-25 08:21:51 +01004238 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4239 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004240 val &= ~idx;
4241 else
4242 val |= idx;
4243
4244 /* power down unused output ports */
4245 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004246}
4247
Takashi Iwaif73d3582008-11-25 08:21:51 +01004248static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4249{
4250 stac_toggle_power_map(codec, nid, get_hp_pin_presence(codec, nid));
4251}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004252
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004253static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4254{
4255 struct sigmatel_spec *spec = codec->spec;
4256 struct sigmatel_jack *jacks = spec->jacks.list;
4257
4258 if (jacks) {
4259 int i;
4260 for (i = 0; i < spec->jacks.used; i++) {
4261 if (jacks->nid == nid) {
4262 unsigned int pin_ctl =
4263 snd_hda_codec_read(codec, nid,
4264 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4265 0x00);
4266 int type = jacks->type;
4267 if (type == (SND_JACK_LINEOUT
4268 | SND_JACK_HEADPHONE))
4269 type = (pin_ctl & AC_PINCTL_HP_EN)
4270 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4271 snd_jack_report(jacks->jack,
4272 get_hp_pin_presence(codec, nid)
4273 ? type : 0);
4274 }
4275 jacks++;
4276 }
4277 }
4278}
Matt2f2f4252005-04-13 14:45:30 +02004279
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004280static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4281 unsigned char type)
4282{
4283 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4284 if (!event)
4285 return;
4286 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4287}
4288
Takashi Iwai314634b2006-09-21 11:56:18 +02004289static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4290{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004291 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004292 struct sigmatel_event *event;
4293 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004294
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004295 tag = (res >> 26) & 0x7f;
4296 event = stac_get_event_from_tag(codec, tag);
4297 if (!event)
4298 return;
4299
4300 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004301 case STAC_HP_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004302 stac92xx_hp_detect(codec);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004303 /* fallthru */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004304 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004305 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004306 if (spec->num_pwrs > 0)
4307 stac92xx_pin_sense(codec, event->nid);
4308 stac92xx_report_jack(codec, event->nid);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004309 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004310 case STAC_VREF_EVENT:
4311 data = snd_hda_codec_read(codec, codec->afg, 0,
4312 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004313 /* toggle VREF state based on GPIOx status */
4314 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004315 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004316 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004317 }
4318}
4319
Takashi Iwaicb53c622007-08-10 17:21:45 +02004320#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004321static int stac92xx_resume(struct hda_codec *codec)
4322{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004323 struct sigmatel_spec *spec = codec->spec;
4324
Richard Fish11b44bb2006-08-23 18:31:34 +02004325 stac92xx_set_config_regs(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004326 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004327 snd_hda_codec_resume_amp(codec);
4328 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004329 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004330 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004331 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4332 STAC_HP_EVENT);
Mattff6fdc32005-06-27 15:06:52 +02004333 return 0;
4334}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004335
4336static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4337{
4338 struct sigmatel_spec *spec = codec->spec;
4339 if (spec->eapd_mask)
4340 stac_gpio_set(codec, spec->gpio_mask,
4341 spec->gpio_dir, spec->gpio_data &
4342 ~spec->eapd_mask);
4343 return 0;
4344}
Mattff6fdc32005-06-27 15:06:52 +02004345#endif
4346
Matt2f2f4252005-04-13 14:45:30 +02004347static struct hda_codec_ops stac92xx_patch_ops = {
4348 .build_controls = stac92xx_build_controls,
4349 .build_pcms = stac92xx_build_pcms,
4350 .init = stac92xx_init,
4351 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004352 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004353#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004354 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004355 .resume = stac92xx_resume,
4356#endif
Matt2f2f4252005-04-13 14:45:30 +02004357};
4358
4359static int patch_stac9200(struct hda_codec *codec)
4360{
4361 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004362 int err;
Matt2f2f4252005-04-13 14:45:30 +02004363
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004364 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004365 if (spec == NULL)
4366 return -ENOMEM;
4367
4368 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004369 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004370 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004371 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4372 stac9200_models,
4373 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02004374 if (spec->board_config < 0) {
4375 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4376 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004377 } else
4378 err = stac_save_pin_cfgs(codec,
4379 stac9200_brd_tbl[spec->board_config]);
4380 if (err < 0) {
4381 stac92xx_free(codec);
4382 return err;
Matt Porter403d1942005-11-29 15:00:51 +01004383 }
Matt2f2f4252005-04-13 14:45:30 +02004384
4385 spec->multiout.max_channels = 2;
4386 spec->multiout.num_dacs = 1;
4387 spec->multiout.dac_nids = stac9200_dac_nids;
4388 spec->adc_nids = stac9200_adc_nids;
4389 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004390 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004391 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004392 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004393 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004394
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02004395 if (spec->board_config == STAC_9200_M4 ||
4396 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01004397 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004398 spec->init = stac9200_eapd_init;
4399 else
4400 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004401 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004402
Takashi Iwai117f2572008-03-18 09:53:23 +01004403 if (spec->board_config == STAC_9200_PANASONIC) {
4404 spec->gpio_mask = spec->gpio_dir = 0x09;
4405 spec->gpio_data = 0x00;
4406 }
4407
Mattc7d4b2f2005-06-27 14:59:41 +02004408 err = stac9200_parse_auto_config(codec);
4409 if (err < 0) {
4410 stac92xx_free(codec);
4411 return err;
4412 }
Matt2f2f4252005-04-13 14:45:30 +02004413
4414 codec->patch_ops = stac92xx_patch_ops;
4415
4416 return 0;
4417}
4418
Tobin Davis8e21c342007-01-08 11:04:17 +01004419static int patch_stac925x(struct hda_codec *codec)
4420{
4421 struct sigmatel_spec *spec;
4422 int err;
4423
4424 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4425 if (spec == NULL)
4426 return -ENOMEM;
4427
4428 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004429 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004430 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004431
4432 /* Check first for codec ID */
4433 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
4434 STAC_925x_MODELS,
4435 stac925x_models,
4436 stac925x_codec_id_cfg_tbl);
4437
4438 /* Now checks for PCI ID, if codec ID is not found */
4439 if (spec->board_config < 0)
4440 spec->board_config = snd_hda_check_board_config(codec,
4441 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01004442 stac925x_models,
4443 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004444 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01004445 if (spec->board_config < 0) {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004446 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
Tobin Davis2c11f952007-05-17 09:36:34 +02004447 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01004448 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004449 } else
4450 err = stac_save_pin_cfgs(codec,
4451 stac925x_brd_tbl[spec->board_config]);
4452 if (err < 0) {
4453 stac92xx_free(codec);
4454 return err;
Tobin Davis8e21c342007-01-08 11:04:17 +01004455 }
4456
4457 spec->multiout.max_channels = 2;
4458 spec->multiout.num_dacs = 1;
4459 spec->multiout.dac_nids = stac925x_dac_nids;
4460 spec->adc_nids = stac925x_adc_nids;
4461 spec->mux_nids = stac925x_mux_nids;
4462 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004463 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004464 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004465 switch (codec->vendor_id) {
4466 case 0x83847632: /* STAC9202 */
4467 case 0x83847633: /* STAC9202D */
4468 case 0x83847636: /* STAC9251 */
4469 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004470 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004471 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004472 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4473 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004474 break;
4475 default:
4476 spec->num_dmics = 0;
4477 break;
4478 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004479
4480 spec->init = stac925x_core_init;
4481 spec->mixer = stac925x_mixer;
4482
4483 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004484 if (!err) {
4485 if (spec->board_config < 0) {
4486 printk(KERN_WARNING "hda_codec: No auto-config is "
4487 "available, default to model=ref\n");
4488 spec->board_config = STAC_925x_REF;
4489 goto again;
4490 }
4491 err = -EINVAL;
4492 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004493 if (err < 0) {
4494 stac92xx_free(codec);
4495 return err;
4496 }
4497
4498 codec->patch_ops = stac92xx_patch_ops;
4499
4500 return 0;
4501}
4502
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004503static struct hda_input_mux stac92hd73xx_dmux = {
4504 .num_items = 4,
4505 .items = {
4506 { "Analog Inputs", 0x0b },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004507 { "Digital Mic 1", 0x09 },
4508 { "Digital Mic 2", 0x0a },
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004509 { "CD", 0x08 },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004510 }
4511};
4512
4513static int patch_stac92hd73xx(struct hda_codec *codec)
4514{
4515 struct sigmatel_spec *spec;
4516 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4517 int err = 0;
4518
4519 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4520 if (spec == NULL)
4521 return -ENOMEM;
4522
4523 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004524 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004525 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4526 spec->pin_nids = stac92hd73xx_pin_nids;
4527 spec->board_config = snd_hda_check_board_config(codec,
4528 STAC_92HD73XX_MODELS,
4529 stac92hd73xx_models,
4530 stac92hd73xx_cfg_tbl);
4531again:
4532 if (spec->board_config < 0) {
4533 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4534 " STAC92HD73XX, using BIOS defaults\n");
4535 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004536 } else
4537 err = stac_save_pin_cfgs(codec,
4538 stac92hd73xx_brd_tbl[spec->board_config]);
4539 if (err < 0) {
4540 stac92xx_free(codec);
4541 return err;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004542 }
4543
4544 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
4545 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4546
4547 if (spec->multiout.num_dacs < 0) {
4548 printk(KERN_WARNING "hda_codec: Could not determine "
4549 "number of channels defaulting to DAC count\n");
4550 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
4551 }
4552
4553 switch (spec->multiout.num_dacs) {
4554 case 0x3: /* 6 Channel */
4555 spec->mixer = stac92hd73xx_6ch_mixer;
4556 spec->init = stac92hd73xx_6ch_core_init;
4557 break;
4558 case 0x4: /* 8 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004559 spec->mixer = stac92hd73xx_8ch_mixer;
4560 spec->init = stac92hd73xx_8ch_core_init;
4561 break;
4562 case 0x5: /* 10 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004563 spec->mixer = stac92hd73xx_10ch_mixer;
4564 spec->init = stac92hd73xx_10ch_core_init;
4565 };
4566
4567 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
4568 spec->aloopback_mask = 0x01;
4569 spec->aloopback_shift = 8;
4570
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004571 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004572 spec->mux_nids = stac92hd73xx_mux_nids;
4573 spec->adc_nids = stac92hd73xx_adc_nids;
4574 spec->dmic_nids = stac92hd73xx_dmic_nids;
4575 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004576 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04004577 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004578 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004579
4580 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4581 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01004582 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004583 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4584 sizeof(stac92hd73xx_dmux));
4585
Matthew Ranostaya7662642008-02-21 07:51:14 +01004586 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004587 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004588 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004589 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004590 case STAC_DELL_M6_AMIC:
4591 case STAC_DELL_M6_DMIC:
4592 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004593 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004594 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4595 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004596 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004597 spec->num_amps = 1;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004598
4599 if (!spec->init)
4600 spec->init = dell_m6_core_init;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004601 switch (spec->board_config) {
4602 case STAC_DELL_M6_AMIC: /* Analog Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004603 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4604 spec->num_dmics = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004605 spec->private_dimux.num_items = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004606 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004607 case STAC_DELL_M6_DMIC: /* Digital Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004608 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4609 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004610 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004611 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004612 case STAC_DELL_M6_BOTH: /* Both */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004613 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4614 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4615 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004616 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004617 break;
4618 }
4619 break;
4620 default:
4621 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004622 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004623 spec->eapd_switch = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004624 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04004625 if (spec->board_config > STAC_92HD73XX_REF) {
4626 /* GPIO0 High = Enable EAPD */
4627 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4628 spec->gpio_data = 0x01;
4629 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004630 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004631
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004632 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4633 spec->pwr_nids = stac92hd73xx_pwr_nids;
4634
Matthew Ranostayd9737752008-09-07 12:03:41 +02004635 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004636
4637 if (!err) {
4638 if (spec->board_config < 0) {
4639 printk(KERN_WARNING "hda_codec: No auto-config is "
4640 "available, default to model=ref\n");
4641 spec->board_config = STAC_92HD73XX_REF;
4642 goto again;
4643 }
4644 err = -EINVAL;
4645 }
4646
4647 if (err < 0) {
4648 stac92xx_free(codec);
4649 return err;
4650 }
4651
4652 codec->patch_ops = stac92xx_patch_ops;
4653
4654 return 0;
4655}
4656
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004657static struct hda_input_mux stac92hd83xxx_dmux = {
4658 .num_items = 3,
4659 .items = {
4660 { "Analog Inputs", 0x03 },
4661 { "Digital Mic 1", 0x04 },
4662 { "Digital Mic 2", 0x05 },
4663 }
4664};
4665
4666static int patch_stac92hd83xxx(struct hda_codec *codec)
4667{
4668 struct sigmatel_spec *spec;
4669 int err;
4670
4671 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4672 if (spec == NULL)
4673 return -ENOMEM;
4674
4675 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004676 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004677 spec->mono_nid = 0x19;
4678 spec->digbeep_nid = 0x21;
4679 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4680 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4681 spec->adc_nids = stac92hd83xxx_adc_nids;
4682 spec->pwr_nids = stac92hd83xxx_pwr_nids;
4683 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4684 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
4685 spec->multiout.dac_nids = stac92hd83xxx_dac_nids;
4686
4687 spec->init = stac92hd83xxx_core_init;
4688 switch (codec->vendor_id) {
4689 case 0x111d7605:
4690 spec->multiout.num_dacs = STAC92HD81_DAC_COUNT;
4691 break;
4692 default:
4693 spec->num_pwrs--;
4694 spec->init++; /* switch to config #2 */
4695 spec->multiout.num_dacs = STAC92HD83_DAC_COUNT;
4696 }
4697
4698 spec->mixer = stac92hd83xxx_mixer;
4699 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4700 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4701 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
4702 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4703 spec->dinput_mux = &stac92hd83xxx_dmux;
4704 spec->pin_nids = stac92hd83xxx_pin_nids;
4705 spec->board_config = snd_hda_check_board_config(codec,
4706 STAC_92HD83XXX_MODELS,
4707 stac92hd83xxx_models,
4708 stac92hd83xxx_cfg_tbl);
4709again:
4710 if (spec->board_config < 0) {
4711 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4712 " STAC92HD83XXX, using BIOS defaults\n");
4713 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004714 } else
4715 err = stac_save_pin_cfgs(codec,
4716 stac92hd83xxx_brd_tbl[spec->board_config]);
4717 if (err < 0) {
4718 stac92xx_free(codec);
4719 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004720 }
4721
4722 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4723 if (!err) {
4724 if (spec->board_config < 0) {
4725 printk(KERN_WARNING "hda_codec: No auto-config is "
4726 "available, default to model=ref\n");
4727 spec->board_config = STAC_92HD83XXX_REF;
4728 goto again;
4729 }
4730 err = -EINVAL;
4731 }
4732
4733 if (err < 0) {
4734 stac92xx_free(codec);
4735 return err;
4736 }
4737
4738 codec->patch_ops = stac92xx_patch_ops;
4739
4740 return 0;
4741}
4742
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004743#ifdef SND_HDA_NEEDS_RESUME
4744static void stac92hd71xx_set_power_state(struct hda_codec *codec, int pwr)
4745{
4746 struct sigmatel_spec *spec = codec->spec;
4747 int i;
4748 snd_hda_codec_write_cache(codec, codec->afg, 0,
4749 AC_VERB_SET_POWER_STATE, pwr);
4750
4751 msleep(1);
4752 for (i = 0; i < spec->num_adcs; i++) {
4753 snd_hda_codec_write_cache(codec,
4754 spec->adc_nids[i], 0,
4755 AC_VERB_SET_POWER_STATE, pwr);
4756 }
4757};
4758
4759static int stac92hd71xx_resume(struct hda_codec *codec)
4760{
4761 stac92hd71xx_set_power_state(codec, AC_PWRST_D0);
4762 return stac92xx_resume(codec);
4763}
4764
4765static int stac92hd71xx_suspend(struct hda_codec *codec, pm_message_t state)
4766{
4767 stac92hd71xx_set_power_state(codec, AC_PWRST_D3);
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004768 return stac92xx_suspend(codec, state);
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004769};
4770
4771#endif
4772
4773static struct hda_codec_ops stac92hd71bxx_patch_ops = {
4774 .build_controls = stac92xx_build_controls,
4775 .build_pcms = stac92xx_build_pcms,
4776 .init = stac92xx_init,
4777 .free = stac92xx_free,
4778 .unsol_event = stac92xx_unsol_event,
4779#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004780 .suspend = stac92hd71xx_suspend,
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004781 .resume = stac92hd71xx_resume,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004782#endif
4783};
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004784
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004785static struct hda_input_mux stac92hd71bxx_dmux = {
4786 .num_items = 4,
4787 .items = {
4788 { "Analog Inputs", 0x00 },
4789 { "Mixer", 0x01 },
4790 { "Digital Mic 1", 0x02 },
4791 { "Digital Mic 2", 0x03 },
4792 }
4793};
4794
Matthew Ranostaye035b842007-11-06 11:53:55 +01004795static int patch_stac92hd71bxx(struct hda_codec *codec)
4796{
4797 struct sigmatel_spec *spec;
4798 int err = 0;
4799
4800 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4801 if (spec == NULL)
4802 return -ENOMEM;
4803
4804 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004805 codec->patch_ops = stac92xx_patch_ops;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004806 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004807 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004808 spec->pin_nids = stac92hd71bxx_pin_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004809 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4810 sizeof(stac92hd71bxx_dmux));
Matthew Ranostaye035b842007-11-06 11:53:55 +01004811 spec->board_config = snd_hda_check_board_config(codec,
4812 STAC_92HD71BXX_MODELS,
4813 stac92hd71bxx_models,
4814 stac92hd71bxx_cfg_tbl);
4815again:
4816 if (spec->board_config < 0) {
4817 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4818 " STAC92HD71BXX, using BIOS defaults\n");
4819 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004820 } else
4821 err = stac_save_pin_cfgs(codec,
4822 stac92hd71bxx_brd_tbl[spec->board_config]);
4823 if (err < 0) {
4824 stac92xx_free(codec);
4825 return err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004826 }
4827
Takashi Iwai41c3b642008-11-18 10:45:15 +01004828 if (spec->board_config > STAC_92HD71BXX_REF) {
4829 /* GPIO0 = EAPD */
4830 spec->gpio_mask = 0x01;
4831 spec->gpio_dir = 0x01;
4832 spec->gpio_data = 0x01;
4833 }
4834
Matthew Ranostay541eee82007-12-14 12:08:04 +01004835 switch (codec->vendor_id) {
4836 case 0x111d76b6: /* 4 Port without Analog Mixer */
4837 case 0x111d76b7:
4838 case 0x111d76b4: /* 6 Port without Analog Mixer */
4839 case 0x111d76b5:
4840 spec->mixer = stac92hd71bxx_mixer;
4841 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004842 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004843 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004844 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01004845 switch (spec->board_config) {
4846 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04004847 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004848 err = stac_add_event(spec, codec->afg,
4849 STAC_VREF_EVENT, 0x02);
4850 if (err < 0)
4851 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01004852 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04004853 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4854 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004855 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004856 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004857 spec->gpio_mask |= 0x02;
4858 break;
4859 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004860 if ((codec->revision_id & 0xf) == 0 ||
4861 (codec->revision_id & 0xf) == 1) {
4862#ifdef SND_HDA_NEEDS_RESUME
4863 codec->patch_ops = stac92hd71bxx_patch_ops;
4864#endif
4865 spec->stream_delay = 40; /* 40 milliseconds */
4866 }
4867
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004868 /* no output amps */
4869 spec->num_pwrs = 0;
4870 spec->mixer = stac92hd71bxx_analog_mixer;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004871 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004872
4873 /* disable VSW */
4874 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004875 stac_change_pin_config(codec, 0xf, 0x40f000f0);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004876 break;
4877 case 0x111d7603: /* 6 Port with Analog Mixer */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004878 if ((codec->revision_id & 0xf) == 1) {
4879#ifdef SND_HDA_NEEDS_RESUME
4880 codec->patch_ops = stac92hd71bxx_patch_ops;
4881#endif
4882 spec->stream_delay = 40; /* 40 milliseconds */
4883 }
4884
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004885 /* no output amps */
4886 spec->num_pwrs = 0;
4887 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01004888 default:
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004889 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004890 spec->mixer = stac92hd71bxx_analog_mixer;
4891 spec->init = stac92hd71bxx_analog_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004892 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004893 }
4894
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004895 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004896 spec->aloopback_shift = 0;
4897
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004898 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004899 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004900 spec->mux_nids = stac92hd71bxx_mux_nids;
4901 spec->adc_nids = stac92hd71bxx_adc_nids;
4902 spec->dmic_nids = stac92hd71bxx_dmic_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004903 spec->dmux_nids = stac92hd71bxx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004904 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004905 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004906
4907 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
4908 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004909
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004910 switch (spec->board_config) {
4911 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004912 /* enable internal microphone */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004913 stac_change_pin_config(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04004914 stac92xx_auto_set_pinctl(codec, 0x0e,
4915 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05004916 /* fallthru */
4917 case STAC_DELL_M4_2:
4918 spec->num_dmics = 0;
4919 spec->num_smuxes = 0;
4920 spec->num_dmuxes = 0;
4921 break;
4922 case STAC_DELL_M4_1:
4923 case STAC_DELL_M4_3:
4924 spec->num_dmics = 1;
4925 spec->num_smuxes = 0;
4926 spec->num_dmuxes = 0;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004927 break;
4928 default:
4929 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
4930 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
4931 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
4932 };
4933
Takashi Iwaiaea7bb02008-02-25 18:26:41 +01004934 spec->multiout.num_dacs = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004935 spec->multiout.hp_nid = 0x11;
4936 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004937 if (spec->dinput_mux)
4938 spec->private_dimux.num_items +=
4939 spec->num_dmics -
4940 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004941
4942 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
4943 if (!err) {
4944 if (spec->board_config < 0) {
4945 printk(KERN_WARNING "hda_codec: No auto-config is "
4946 "available, default to model=ref\n");
4947 spec->board_config = STAC_92HD71BXX_REF;
4948 goto again;
4949 }
4950 err = -EINVAL;
4951 }
4952
4953 if (err < 0) {
4954 stac92xx_free(codec);
4955 return err;
4956 }
4957
Matthew Ranostaye035b842007-11-06 11:53:55 +01004958 return 0;
4959};
4960
Matt2f2f4252005-04-13 14:45:30 +02004961static int patch_stac922x(struct hda_codec *codec)
4962{
4963 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004964 int err;
Matt2f2f4252005-04-13 14:45:30 +02004965
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004966 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004967 if (spec == NULL)
4968 return -ENOMEM;
4969
4970 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004971 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004972 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004973 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
4974 stac922x_models,
4975 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08004976 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004977 spec->gpio_mask = spec->gpio_dir = 0x03;
4978 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004979 /* Intel Macs have all same PCI SSID, so we need to check
4980 * codec SSID to distinguish the exact models
4981 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01004982 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004983 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004984
4985 case 0x106b0800:
4986 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02004987 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004988 case 0x106b0600:
4989 case 0x106b0700:
4990 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01004991 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004992 case 0x106b0e00:
4993 case 0x106b0f00:
4994 case 0x106b1600:
4995 case 0x106b1700:
4996 case 0x106b0200:
4997 case 0x106b1e00:
4998 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004999 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005000 case 0x106b1a00:
5001 case 0x00000100:
5002 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005003 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005004 case 0x106b0a00:
5005 case 0x106b2200:
5006 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005007 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005008 default:
5009 spec->board_config = STAC_INTEL_MAC_V3;
5010 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005011 }
5012 }
5013
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005014 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02005015 if (spec->board_config < 0) {
5016 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
5017 "using BIOS defaults\n");
5018 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005019 } else
5020 err = stac_save_pin_cfgs(codec,
5021 stac922x_brd_tbl[spec->board_config]);
5022 if (err < 0) {
5023 stac92xx_free(codec);
5024 return err;
Matt Porter403d1942005-11-29 15:00:51 +01005025 }
Matt2f2f4252005-04-13 14:45:30 +02005026
Matt2f2f4252005-04-13 14:45:30 +02005027 spec->adc_nids = stac922x_adc_nids;
5028 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005029 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005030 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005031 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005032 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005033
5034 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005035 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005036
5037 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005038
Matt Porter3cc08dc2006-01-23 15:27:49 +01005039 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005040 if (!err) {
5041 if (spec->board_config < 0) {
5042 printk(KERN_WARNING "hda_codec: No auto-config is "
5043 "available, default to model=ref\n");
5044 spec->board_config = STAC_D945_REF;
5045 goto again;
5046 }
5047 err = -EINVAL;
5048 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005049 if (err < 0) {
5050 stac92xx_free(codec);
5051 return err;
5052 }
5053
5054 codec->patch_ops = stac92xx_patch_ops;
5055
Takashi Iwai807a46362007-05-29 19:01:37 +02005056 /* Fix Mux capture level; max to 2 */
5057 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5058 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5059 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5060 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5061 (0 << AC_AMPCAP_MUTE_SHIFT));
5062
Matt Porter3cc08dc2006-01-23 15:27:49 +01005063 return 0;
5064}
5065
5066static int patch_stac927x(struct hda_codec *codec)
5067{
5068 struct sigmatel_spec *spec;
5069 int err;
5070
5071 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5072 if (spec == NULL)
5073 return -ENOMEM;
5074
5075 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005076 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005077 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005078 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5079 stac927x_models,
5080 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005081 again:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005082 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
5083 if (spec->board_config < 0)
5084 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5085 "STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02005086 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005087 } else
5088 err = stac_save_pin_cfgs(codec,
5089 stac927x_brd_tbl[spec->board_config]);
5090 if (err < 0) {
5091 stac92xx_free(codec);
5092 return err;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005093 }
5094
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005095 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005096 spec->adc_nids = stac927x_adc_nids;
5097 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5098 spec->mux_nids = stac927x_mux_nids;
5099 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005100 spec->smux_nids = stac927x_smux_nids;
5101 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005102 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005103 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005104 spec->multiout.dac_nids = spec->dac_nids;
5105
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005106 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005107 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005108 case STAC_D965_5ST:
5109 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005110 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005111 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005112 spec->num_dmics = 0;
5113
Tobin Davis93ed1502006-09-01 21:03:12 +02005114 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005115 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005116 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005117 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005118 switch (codec->subsystem_id) {
5119 case 0x10280209:
5120 case 0x1028022e:
5121 /* correct the device field to SPDIF out */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005122 stac_change_pin_config(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005123 break;
5124 };
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005125 /* configure the analog microphone on some laptops */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005126 stac_change_pin_config(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005127 /* correct the front output jack as a hp out */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005128 stac_change_pin_config(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005129 /* correct the front input jack as a mic */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005130 stac_change_pin_config(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005131 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005132 case STAC_DELL_3ST:
5133 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005134 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005135 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005136 spec->dmic_nids = stac927x_dmic_nids;
5137 spec->num_dmics = STAC927X_NUM_DMICS;
5138
Tobin Davis93ed1502006-09-01 21:03:12 +02005139 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005140 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005141 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005142 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005143 break;
5144 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005145 if (spec->board_config > STAC_D965_REF) {
5146 /* GPIO0 High = Enable EAPD */
5147 spec->eapd_mask = spec->gpio_mask = 0x01;
5148 spec->gpio_dir = spec->gpio_data = 0x01;
5149 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005150 spec->num_dmics = 0;
5151
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005152 spec->init = stac927x_core_init;
5153 spec->mixer = stac927x_mixer;
5154 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005155
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005156 spec->num_pwrs = 0;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005157 spec->aloopback_mask = 0x40;
5158 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005159 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005160
Matt Porter3cc08dc2006-01-23 15:27:49 +01005161 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005162 if (!err) {
5163 if (spec->board_config < 0) {
5164 printk(KERN_WARNING "hda_codec: No auto-config is "
5165 "available, default to model=ref\n");
5166 spec->board_config = STAC_D965_REF;
5167 goto again;
5168 }
5169 err = -EINVAL;
5170 }
Mattc7d4b2f2005-06-27 14:59:41 +02005171 if (err < 0) {
5172 stac92xx_free(codec);
5173 return err;
5174 }
Matt2f2f4252005-04-13 14:45:30 +02005175
5176 codec->patch_ops = stac92xx_patch_ops;
5177
Takashi Iwai52987652008-01-16 16:09:47 +01005178 /*
5179 * !!FIXME!!
5180 * The STAC927x seem to require fairly long delays for certain
5181 * command sequences. With too short delays (even if the answer
5182 * is set to RIRB properly), it results in the silence output
5183 * on some hardwares like Dell.
5184 *
5185 * The below flag enables the longer delay (see get_response
5186 * in hda_intel.c).
5187 */
5188 codec->bus->needs_damn_long_delay = 1;
5189
Matt2f2f4252005-04-13 14:45:30 +02005190 return 0;
5191}
5192
Matt Porterf3302a52006-07-31 12:49:34 +02005193static int patch_stac9205(struct hda_codec *codec)
5194{
5195 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005196 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005197
5198 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5199 if (spec == NULL)
5200 return -ENOMEM;
5201
5202 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005203 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005204 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005205 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5206 stac9205_models,
5207 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005208 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02005209 if (spec->board_config < 0) {
5210 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
5211 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005212 } else
5213 err = stac_save_pin_cfgs(codec,
5214 stac9205_brd_tbl[spec->board_config]);
5215 if (err < 0) {
5216 stac92xx_free(codec);
5217 return err;
Matt Porterf3302a52006-07-31 12:49:34 +02005218 }
5219
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005220 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005221 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005222 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005223 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005224 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005225 spec->smux_nids = stac9205_smux_nids;
5226 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005227 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005228 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005229 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005230 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005231 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005232
5233 spec->init = stac9205_core_init;
5234 spec->mixer = stac9205_mixer;
5235
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005236 spec->aloopback_mask = 0x40;
5237 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005238 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005239 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005240
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005241 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005242 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005243 /* Enable SPDIF in/out */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005244 stac_change_pin_config(codec, 0x1f, 0x01441030);
5245 stac_change_pin_config(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005246
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005247 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005248 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5249 if (err < 0)
5250 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005251 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005252 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5253 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005254 AC_VERB_SET_UNSOLICITED_ENABLE,
5255 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005256
5257 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005258 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005259 spec->gpio_mask = 0x1b;
5260 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005261 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005262 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005263 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005264 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005265 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005266 case STAC_9205_REF:
5267 /* SPDIF-In enabled */
5268 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005269 default:
5270 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005271 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005272 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005273 break;
5274 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005275
Matt Porterf3302a52006-07-31 12:49:34 +02005276 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005277 if (!err) {
5278 if (spec->board_config < 0) {
5279 printk(KERN_WARNING "hda_codec: No auto-config is "
5280 "available, default to model=ref\n");
5281 spec->board_config = STAC_9205_REF;
5282 goto again;
5283 }
5284 err = -EINVAL;
5285 }
Matt Porterf3302a52006-07-31 12:49:34 +02005286 if (err < 0) {
5287 stac92xx_free(codec);
5288 return err;
5289 }
5290
5291 codec->patch_ops = stac92xx_patch_ops;
5292
5293 return 0;
5294}
5295
Matt2f2f4252005-04-13 14:45:30 +02005296/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005297 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005298 */
5299
Guillaume Munch99ccc562006-08-16 19:35:12 +02005300/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005301static hda_nid_t vaio_dacs[] = { 0x2 };
5302#define VAIO_HP_DAC 0x5
5303static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
5304static hda_nid_t vaio_mux_nids[] = { 0x15 };
5305
5306static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02005307 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01005308 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02005309 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005310 { "Mic Jack", 0x1 },
5311 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01005312 { "PCM", 0x3 },
5313 }
5314};
5315
5316static struct hda_verb vaio_init[] = {
5317 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005318 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01005319 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5320 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5321 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5322 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005323 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005324 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5325 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5326 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5327 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5328 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5329 {}
5330};
5331
Guillaume Munch6d859062006-08-22 17:15:47 +02005332static struct hda_verb vaio_ar_init[] = {
5333 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5334 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5335 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5336 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5337/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
5338 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005339 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02005340 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5341 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5342/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
5343 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5344 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5345 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5346 {}
5347};
5348
Takashi Iwaidb064e52006-03-16 16:04:58 +01005349static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwai127e82e2008-11-14 14:03:33 +01005350 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5351 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5352 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5353 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
Takashi Iwaidb064e52006-03-16 16:04:58 +01005354 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5355 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5356 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5357 {
5358 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5359 .name = "Capture Source",
5360 .count = 1,
5361 .info = stac92xx_mux_enum_info,
5362 .get = stac92xx_mux_enum_get,
5363 .put = stac92xx_mux_enum_put,
5364 },
5365 {}
5366};
5367
Guillaume Munch6d859062006-08-22 17:15:47 +02005368static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwai127e82e2008-11-14 14:03:33 +01005369 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5370 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5371 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5372 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
Guillaume Munch6d859062006-08-22 17:15:47 +02005373 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5374 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5375 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5376 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
5377 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
5378 {
5379 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5380 .name = "Capture Source",
5381 .count = 1,
5382 .info = stac92xx_mux_enum_info,
5383 .get = stac92xx_mux_enum_get,
5384 .put = stac92xx_mux_enum_put,
5385 },
5386 {}
5387};
5388
5389static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01005390 .build_controls = stac92xx_build_controls,
5391 .build_pcms = stac92xx_build_pcms,
5392 .init = stac92xx_init,
5393 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02005394#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01005395 .resume = stac92xx_resume,
5396#endif
5397};
5398
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005399static int stac9872_vaio_init(struct hda_codec *codec)
5400{
5401 int err;
5402
5403 err = stac92xx_init(codec);
5404 if (err < 0)
5405 return err;
5406 if (codec->patch_ops.unsol_event)
5407 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
5408 return 0;
5409}
5410
5411static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
5412{
Jiang Zhe40c1d302007-11-12 13:05:16 +01005413 if (get_hp_pin_presence(codec, 0x0a)) {
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005414 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5415 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5416 } else {
5417 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5418 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5419 }
5420}
5421
5422static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
5423{
5424 switch (res >> 26) {
5425 case STAC_HP_EVENT:
5426 stac9872_vaio_hp_detect(codec, res);
5427 break;
5428 }
5429}
5430
5431static struct hda_codec_ops stac9872_vaio_patch_ops = {
5432 .build_controls = stac92xx_build_controls,
5433 .build_pcms = stac92xx_build_pcms,
5434 .init = stac9872_vaio_init,
5435 .free = stac92xx_free,
5436 .unsol_event = stac9872_vaio_unsol_event,
5437#ifdef CONFIG_PM
5438 .resume = stac92xx_resume,
5439#endif
5440};
5441
Guillaume Munch6d859062006-08-22 17:15:47 +02005442enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
5443 CXD9872RD_VAIO,
5444 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
5445 STAC9872AK_VAIO,
5446 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
5447 STAC9872K_VAIO,
5448 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005449 CXD9872AKD_VAIO,
5450 STAC_9872_MODELS,
5451};
Takashi Iwaidb064e52006-03-16 16:04:58 +01005452
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005453static const char *stac9872_models[STAC_9872_MODELS] = {
5454 [CXD9872RD_VAIO] = "vaio",
5455 [CXD9872AKD_VAIO] = "vaio-ar",
5456};
5457
5458static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5459 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
5460 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
5461 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01005462 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01005463 {}
5464};
5465
Guillaume Munch6d859062006-08-22 17:15:47 +02005466static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005467{
5468 struct sigmatel_spec *spec;
5469 int board_config;
5470
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005471 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5472 stac9872_models,
5473 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01005474 if (board_config < 0)
5475 /* unknown config, let generic-parser do its job... */
5476 return snd_hda_parse_generic_codec(codec);
5477
5478 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5479 if (spec == NULL)
5480 return -ENOMEM;
5481
5482 codec->spec = spec;
5483 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02005484 case CXD9872RD_VAIO:
5485 case STAC9872AK_VAIO:
5486 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01005487 spec->mixer = vaio_mixer;
5488 spec->init = vaio_init;
5489 spec->multiout.max_channels = 2;
5490 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5491 spec->multiout.dac_nids = vaio_dacs;
5492 spec->multiout.hp_nid = VAIO_HP_DAC;
5493 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5494 spec->adc_nids = vaio_adcs;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005495 spec->num_pwrs = 0;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005496 spec->input_mux = &vaio_mux;
5497 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005498 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005499 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02005500
5501 case CXD9872AKD_VAIO:
5502 spec->mixer = vaio_ar_mixer;
5503 spec->init = vaio_ar_init;
5504 spec->multiout.max_channels = 2;
5505 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5506 spec->multiout.dac_nids = vaio_dacs;
5507 spec->multiout.hp_nid = VAIO_HP_DAC;
5508 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005509 spec->num_pwrs = 0;
Guillaume Munch6d859062006-08-22 17:15:47 +02005510 spec->adc_nids = vaio_adcs;
5511 spec->input_mux = &vaio_mux;
5512 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005513 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02005514 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005515 }
5516
Takashi Iwaidb064e52006-03-16 16:04:58 +01005517 return 0;
5518}
5519
5520
5521/*
Matt2f2f4252005-04-13 14:45:30 +02005522 * patch entries
5523 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005524static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02005525 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5526 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5527 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5528 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5529 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5530 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5531 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005532 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5533 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5534 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5535 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5536 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5537 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005538 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5539 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5540 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5541 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5542 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5543 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5544 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5545 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5546 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5547 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005548 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5549 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5550 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5551 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5552 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5553 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005554 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5555 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005556 /* The following does not take into account .id=0x83847661 when subsys =
5557 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5558 * currently not fully supported.
5559 */
5560 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5561 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5562 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02005563 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5564 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5565 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5566 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5567 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5568 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5569 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5570 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005571 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005572 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5573 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005574 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005575 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5576 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005577 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005578 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5579 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5580 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5581 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5582 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5583 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5584 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5585 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005586 {} /* terminator */
5587};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005588
5589MODULE_ALIAS("snd-hda-codec-id:8384*");
5590MODULE_ALIAS("snd-hda-codec-id:111d*");
5591
5592MODULE_LICENSE("GPL");
5593MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5594
5595static struct hda_codec_preset_list sigmatel_list = {
5596 .preset = snd_hda_preset_sigmatel,
5597 .owner = THIS_MODULE,
5598};
5599
5600static int __init patch_sigmatel_init(void)
5601{
5602 return snd_hda_add_codec_preset(&sigmatel_list);
5603}
5604
5605static void __exit patch_sigmatel_exit(void)
5606{
5607 snd_hda_delete_codec_preset(&sigmatel_list);
5608}
5609
5610module_init(patch_sigmatel_init)
5611module_exit(patch_sigmatel_exit)