blob: 068a77ae459e36994ca17be68a0e2644c0e474d5 [file] [log] [blame]
Matt2f2f4252005-04-13 14:45:30 +02001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for SigmaTel STAC92xx
5 *
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
Matt Porter403d1942005-11-29 15:00:51 +01007 * Matt Porter <mporter@embeddedalley.com>
Matt2f2f4252005-04-13 14:45:30 +02008 *
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 *
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
Matt2f2f4252005-04-13 14:45:30 +020027#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/slab.h>
30#include <linux/pci.h>
31#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020032#include <sound/asoundef.h>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040033#include <sound/jack.h>
Matt2f2f4252005-04-13 14:45:30 +020034#include "hda_codec.h"
35#include "hda_local.h"
Harvey Harrison3c9a3202008-02-29 11:59:26 +010036#include "hda_patch.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020037#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020038
Takashi Iwaic6e4c662008-11-25 11:58:19 +010039enum {
40 STAC_VREF_EVENT = 1,
41 STAC_INSERT_EVENT,
42 STAC_PWR_EVENT,
43 STAC_HP_EVENT,
44};
Matt4e550962005-07-04 17:51:39 +020045
Takashi Iwaif5fcc132006-11-24 17:07:44 +010046enum {
47 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010048 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020049 STAC_9200_DELL_D21,
50 STAC_9200_DELL_D22,
51 STAC_9200_DELL_D23,
52 STAC_9200_DELL_M21,
53 STAC_9200_DELL_M22,
54 STAC_9200_DELL_M23,
55 STAC_9200_DELL_M24,
56 STAC_9200_DELL_M25,
57 STAC_9200_DELL_M26,
58 STAC_9200_DELL_M27,
Takashi Iwai1194b5b2007-10-10 10:04:26 +020059 STAC_9200_GATEWAY,
Takashi Iwai117f2572008-03-18 09:53:23 +010060 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010061 STAC_9200_MODELS
62};
63
64enum {
65 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020066 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020067 STAC_9205_DELL_M43,
68 STAC_9205_DELL_M44,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010069 STAC_9205_MODELS
70};
71
72enum {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010073 STAC_92HD73XX_REF,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010074 STAC_DELL_M6_AMIC,
75 STAC_DELL_M6_DMIC,
76 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050077 STAC_DELL_EQ,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010078 STAC_92HD73XX_MODELS
79};
80
81enum {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020082 STAC_92HD83XXX_REF,
83 STAC_92HD83XXX_MODELS
84};
85
86enum {
Matthew Ranostaye035b842007-11-06 11:53:55 +010087 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010088 STAC_DELL_M4_1,
89 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -050090 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -040091 STAC_HP_M4,
Matthew Ranostaye035b842007-11-06 11:53:55 +010092 STAC_92HD71BXX_MODELS
93};
94
95enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010096 STAC_925x_REF,
97 STAC_M2_2,
98 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020099 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100100 STAC_925x_MODELS
101};
102
103enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100104 STAC_D945_REF,
105 STAC_D945GTP3,
106 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200107 STAC_INTEL_MAC_V1,
108 STAC_INTEL_MAC_V2,
109 STAC_INTEL_MAC_V3,
110 STAC_INTEL_MAC_V4,
111 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800112 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
113 * is given, one of the above models will be
114 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200115 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100116 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100117 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100118 STAC_MACBOOK_PRO_V1,
119 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200120 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200121 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300122 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200123 STAC_922X_DELL_D81,
124 STAC_922X_DELL_D82,
125 STAC_922X_DELL_M81,
126 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100127 STAC_922X_MODELS
128};
129
130enum {
131 STAC_D965_REF,
132 STAC_D965_3ST,
133 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200134 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100135 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100136 STAC_927X_MODELS
137};
Matt Porter403d1942005-11-29 15:00:51 +0100138
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400139struct sigmatel_event {
140 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100141 unsigned char type;
142 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400143 int data;
144};
145
146struct sigmatel_jack {
147 hda_nid_t nid;
148 int type;
149 struct snd_jack *jack;
150};
151
Matt2f2f4252005-04-13 14:45:30 +0200152struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100153 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200154 unsigned int num_mixers;
155
Matt Porter403d1942005-11-29 15:00:51 +0100156 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500157 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200158 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +0100159 unsigned int line_switch: 1;
160 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100161 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100162 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400163 unsigned int spdif_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200164
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100165 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200166 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100167 unsigned int gpio_mask;
168 unsigned int gpio_dir;
169 unsigned int gpio_data;
170 unsigned int gpio_mute;
171
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200172 /* stream */
173 unsigned int stream_delay;
174
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100175 /* analog loopback */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100176 unsigned char aloopback_mask;
177 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200178
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100179 /* power management */
180 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200181 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100182 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100183 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100184
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400185 /* jack detection */
186 struct snd_array jacks;
187
188 /* events */
189 struct snd_array events;
190
Matt2f2f4252005-04-13 14:45:30 +0200191 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100192 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400193 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100194 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200195 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100196 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200197
198 /* capture */
199 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200200 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200201 hda_nid_t *mux_nids;
202 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200203 hda_nid_t *dmic_nids;
204 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100205 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100206 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200207 hda_nid_t *smux_nids;
208 unsigned int num_smuxes;
Matthew Ranostay65973632008-09-16 10:39:37 -0400209 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200210
Mattdabbed62005-06-14 10:19:34 +0200211 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100212 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200213 hda_nid_t anabeep_nid;
214 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200215
Matt2f2f4252005-04-13 14:45:30 +0200216 /* pin widgets */
217 hda_nid_t *pin_nids;
218 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200219 unsigned int *pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200220
221 /* codec specific stuff */
222 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100223 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200224
225 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200226 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100227 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200228 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100229 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200230 struct hda_input_mux *sinput_mux;
231 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400232 unsigned int cur_amux;
233 hda_nid_t *amp_nids;
234 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200235 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200236
Matt Porter403d1942005-11-29 15:00:51 +0100237 /* i/o switches */
238 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200239 unsigned int clfe_swap;
Takashi Iwaid7a89432008-11-12 09:48:04 +0100240 unsigned int hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200241 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200242
Mattc7d4b2f2005-06-27 14:59:41 +0200243 struct hda_pcm pcm_rec[2]; /* PCM information */
244
245 /* dynamic controls and input_mux */
246 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200247 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200248 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200249 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200250 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400251 struct hda_input_mux private_amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100252 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200253};
254
255static hda_nid_t stac9200_adc_nids[1] = {
256 0x03,
257};
258
259static hda_nid_t stac9200_mux_nids[1] = {
260 0x0c,
261};
262
263static hda_nid_t stac9200_dac_nids[1] = {
264 0x02,
265};
266
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100267static hda_nid_t stac92hd73xx_pwr_nids[8] = {
268 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
269 0x0f, 0x10, 0x11
270};
271
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400272static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
273 0x26, 0,
274};
275
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100276static hda_nid_t stac92hd73xx_adc_nids[2] = {
277 0x1a, 0x1b
278};
279
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400280#define DELL_M6_AMP 2
281static hda_nid_t stac92hd73xx_amp_nids[3] = {
282 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400283};
284
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100285#define STAC92HD73XX_NUM_DMICS 2
286static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
287 0x13, 0x14, 0
288};
289
290#define STAC92HD73_DAC_COUNT 5
291static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
292 0x15, 0x16, 0x17, 0x18, 0x19,
293};
294
295static hda_nid_t stac92hd73xx_mux_nids[4] = {
296 0x28, 0x29, 0x2a, 0x2b,
297};
298
299static hda_nid_t stac92hd73xx_dmux_nids[2] = {
300 0x20, 0x21,
301};
302
Matthew Ranostayd9737752008-09-07 12:03:41 +0200303static hda_nid_t stac92hd73xx_smux_nids[2] = {
304 0x22, 0x23,
305};
306
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200307#define STAC92HD83XXX_NUM_DMICS 2
308static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
309 0x11, 0x12, 0
310};
311
312#define STAC92HD81_DAC_COUNT 2
313#define STAC92HD83_DAC_COUNT 3
314static hda_nid_t stac92hd83xxx_dac_nids[STAC92HD73_DAC_COUNT] = {
315 0x13, 0x14, 0x22,
316};
317
318static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
319 0x17, 0x18,
320};
321
322static hda_nid_t stac92hd83xxx_adc_nids[2] = {
323 0x15, 0x16,
324};
325
326static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
327 0xa, 0xb, 0xd, 0xe,
328};
329
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400330static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
331 0x1e, 0,
332};
333
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200334static unsigned int stac92hd83xxx_pwr_mapping[4] = {
335 0x03, 0x0c, 0x10, 0x40,
336};
337
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100338static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
339 0x0a, 0x0d, 0x0f
340};
341
Matthew Ranostaye035b842007-11-06 11:53:55 +0100342static hda_nid_t stac92hd71bxx_adc_nids[2] = {
343 0x12, 0x13,
344};
345
346static hda_nid_t stac92hd71bxx_mux_nids[2] = {
347 0x1a, 0x1b
348};
349
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400350static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
351 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100352};
353
Matthew Ranostayd9737752008-09-07 12:03:41 +0200354static hda_nid_t stac92hd71bxx_smux_nids[2] = {
355 0x24, 0x25,
356};
357
Takashi Iwaiaea7bb02008-02-25 18:26:41 +0100358static hda_nid_t stac92hd71bxx_dac_nids[1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100359 0x10, /*0x11, */
360};
361
362#define STAC92HD71BXX_NUM_DMICS 2
363static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
364 0x18, 0x19, 0
365};
366
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400367static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
368 0x22, 0
369};
370
Tobin Davis8e21c342007-01-08 11:04:17 +0100371static hda_nid_t stac925x_adc_nids[1] = {
372 0x03,
373};
374
375static hda_nid_t stac925x_mux_nids[1] = {
376 0x0f,
377};
378
379static hda_nid_t stac925x_dac_nids[1] = {
380 0x02,
381};
382
Takashi Iwaif6e98522007-10-16 14:27:04 +0200383#define STAC925X_NUM_DMICS 1
384static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
385 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200386};
387
Takashi Iwai1697055e2007-12-18 18:05:52 +0100388static hda_nid_t stac925x_dmux_nids[1] = {
389 0x14,
390};
391
Matt2f2f4252005-04-13 14:45:30 +0200392static hda_nid_t stac922x_adc_nids[2] = {
393 0x06, 0x07,
394};
395
396static hda_nid_t stac922x_mux_nids[2] = {
397 0x12, 0x13,
398};
399
Matt Porter3cc08dc2006-01-23 15:27:49 +0100400static hda_nid_t stac927x_adc_nids[3] = {
401 0x07, 0x08, 0x09
402};
403
404static hda_nid_t stac927x_mux_nids[3] = {
405 0x15, 0x16, 0x17
406};
407
Matthew Ranostayd9737752008-09-07 12:03:41 +0200408static hda_nid_t stac927x_smux_nids[1] = {
409 0x21,
410};
411
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100412static hda_nid_t stac927x_dac_nids[6] = {
413 0x02, 0x03, 0x04, 0x05, 0x06, 0
414};
415
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100416static hda_nid_t stac927x_dmux_nids[1] = {
417 0x1b,
418};
419
Matthew Ranostay7f168592007-10-18 17:38:17 +0200420#define STAC927X_NUM_DMICS 2
421static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
422 0x13, 0x14, 0
423};
424
Matthew Ranostay65973632008-09-16 10:39:37 -0400425static const char *stac927x_spdif_labels[5] = {
426 "Digital Playback", "ADAT", "Analog Mux 1",
427 "Analog Mux 2", "Analog Mux 3"
428};
429
Matt Porterf3302a52006-07-31 12:49:34 +0200430static hda_nid_t stac9205_adc_nids[2] = {
431 0x12, 0x13
432};
433
434static hda_nid_t stac9205_mux_nids[2] = {
435 0x19, 0x1a
436};
437
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100438static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100439 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100440};
441
Matthew Ranostayd9737752008-09-07 12:03:41 +0200442static hda_nid_t stac9205_smux_nids[1] = {
443 0x21,
444};
445
Takashi Iwaif6e98522007-10-16 14:27:04 +0200446#define STAC9205_NUM_DMICS 2
447static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
448 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200449};
450
Mattc7d4b2f2005-06-27 14:59:41 +0200451static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200452 0x08, 0x09, 0x0d, 0x0e,
453 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200454};
455
Tobin Davis8e21c342007-01-08 11:04:17 +0100456static hda_nid_t stac925x_pin_nids[8] = {
457 0x07, 0x08, 0x0a, 0x0b,
458 0x0c, 0x0d, 0x10, 0x11,
459};
460
Matt2f2f4252005-04-13 14:45:30 +0200461static hda_nid_t stac922x_pin_nids[10] = {
462 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
463 0x0f, 0x10, 0x11, 0x15, 0x1b,
464};
465
Matthew Ranostaya7662642008-02-21 07:51:14 +0100466static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100467 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
468 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200469 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100470};
471
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200472static hda_nid_t stac92hd83xxx_pin_nids[14] = {
473 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
474 0x0f, 0x10, 0x11, 0x12, 0x13,
475 0x1d, 0x1e, 0x1f, 0x20
476};
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400477static hda_nid_t stac92hd71bxx_pin_nids[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100478 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
479 0x0f, 0x14, 0x18, 0x19, 0x1e,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400480 0x1f,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100481};
482
Matt Porter3cc08dc2006-01-23 15:27:49 +0100483static hda_nid_t stac927x_pin_nids[14] = {
484 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
485 0x0f, 0x10, 0x11, 0x12, 0x13,
486 0x14, 0x21, 0x22, 0x23,
487};
488
Matt Porterf3302a52006-07-31 12:49:34 +0200489static hda_nid_t stac9205_pin_nids[12] = {
490 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
491 0x0f, 0x14, 0x16, 0x17, 0x18,
492 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200493};
494
Matthew Ranostay89385032008-09-11 09:49:39 -0400495#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
496
497static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
498 struct snd_ctl_elem_value *ucontrol)
499{
500 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
501 struct sigmatel_spec *spec = codec->spec;
502 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
503
504 kcontrol->private_value ^= get_amp_nid(kcontrol);
505 kcontrol->private_value |= nid;
506
507 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
508}
509
510static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
511 struct snd_ctl_elem_value *ucontrol)
512{
513 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
514 struct sigmatel_spec *spec = codec->spec;
515 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
516
517 kcontrol->private_value ^= get_amp_nid(kcontrol);
518 kcontrol->private_value |= nid;
519
520 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
521}
522
Matt Porter8b657272006-10-26 17:12:59 +0200523static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
524 struct snd_ctl_elem_info *uinfo)
525{
526 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
527 struct sigmatel_spec *spec = codec->spec;
528 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
529}
530
531static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
532 struct snd_ctl_elem_value *ucontrol)
533{
534 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
535 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100536 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200537
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100538 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200539 return 0;
540}
541
542static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
543 struct snd_ctl_elem_value *ucontrol)
544{
545 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
546 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100547 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200548
549 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100550 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200551}
552
Matthew Ranostayd9737752008-09-07 12:03:41 +0200553static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
554 struct snd_ctl_elem_info *uinfo)
555{
556 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
557 struct sigmatel_spec *spec = codec->spec;
558 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
559}
560
561static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
562 struct snd_ctl_elem_value *ucontrol)
563{
564 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
565 struct sigmatel_spec *spec = codec->spec;
566 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
567
568 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
569 return 0;
570}
571
572static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
573 struct snd_ctl_elem_value *ucontrol)
574{
575 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
576 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400577 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200578 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400579 int err, val;
580 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200581
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400582 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200583 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400584 if (err < 0)
585 return err;
586
587 if (spec->spdif_mute) {
588 if (smux_idx == 0)
589 nid = spec->multiout.dig_out_nid;
590 else
591 nid = codec->slave_dig_outs[smux_idx - 1];
592 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100593 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400594 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100595 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400596 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100597 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
598 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400599 }
600 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200601}
602
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100603static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200604{
605 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200607 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200608}
609
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100610static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200611{
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 struct sigmatel_spec *spec = codec->spec;
614 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
615
616 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
617 return 0;
618}
619
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100620static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200621{
622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
623 struct sigmatel_spec *spec = codec->spec;
624 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
625
Mattc7d4b2f2005-06-27 14:59:41 +0200626 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200627 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
628}
629
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100630static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
631 struct snd_ctl_elem_info *uinfo)
632{
633 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
634 struct sigmatel_spec *spec = codec->spec;
635 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
636}
637
638static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
639 struct snd_ctl_elem_value *ucontrol)
640{
641 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
642 struct sigmatel_spec *spec = codec->spec;
643
644 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
645 return 0;
646}
647
648static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
650{
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct sigmatel_spec *spec = codec->spec;
653
654 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
655 spec->mono_nid, &spec->cur_mmux);
656}
657
Matthew Ranostay89385032008-09-11 09:49:39 -0400658static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
659 struct snd_ctl_elem_info *uinfo)
660{
661 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
662 struct sigmatel_spec *spec = codec->spec;
663 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
664}
665
666static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
667 struct snd_ctl_elem_value *ucontrol)
668{
669 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
670 struct sigmatel_spec *spec = codec->spec;
671
672 ucontrol->value.enumerated.item[0] = spec->cur_amux;
673 return 0;
674}
675
676static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
677 struct snd_ctl_elem_value *ucontrol)
678{
679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
680 struct sigmatel_spec *spec = codec->spec;
681 struct snd_kcontrol *ctl =
682 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
683 if (!ctl)
684 return -EINVAL;
685
686 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
687 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
688
689 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
690 0, &spec->cur_amux);
691}
692
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200693#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
694
695static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
696 struct snd_ctl_elem_value *ucontrol)
697{
698 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100699 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200700 struct sigmatel_spec *spec = codec->spec;
701
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100702 ucontrol->value.integer.value[0] = !!(spec->aloopback &
703 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200704 return 0;
705}
706
707static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
708 struct snd_ctl_elem_value *ucontrol)
709{
710 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
711 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100712 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200713 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100714 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200715
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100716 idx_val = spec->aloopback_mask << idx;
717 if (ucontrol->value.integer.value[0])
718 val = spec->aloopback | idx_val;
719 else
720 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100721 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200722 return 0;
723
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100724 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200725
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100726 /* Only return the bits defined by the shift value of the
727 * first two bytes of the mask
728 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200729 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100730 kcontrol->private_value & 0xFFFF, 0x0);
731 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200732
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100733 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200734 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100735 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200736 } else {
737 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100738 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200739 }
740
741 snd_hda_codec_write_cache(codec, codec->afg, 0,
742 kcontrol->private_value >> 16, dac_mode);
743
744 return 1;
745}
746
Mattc7d4b2f2005-06-27 14:59:41 +0200747static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200748 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200749 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200750 {}
751};
752
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200753static struct hda_verb stac9200_eapd_init[] = {
754 /* set dac0mux for dac converter */
755 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
756 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
757 {}
758};
759
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100760static struct hda_verb stac92hd73xx_6ch_core_init[] = {
761 /* set master volume and direct control */
762 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
763 /* setup audio connections */
764 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
765 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
766 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
767 /* setup adcs to point to mixer */
768 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
769 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100770 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
771 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
772 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
773 /* setup import muxs */
774 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
775 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
776 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
777 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
778 {}
779};
780
Matthew Ranostayd654a662008-03-14 08:46:51 +0100781static struct hda_verb dell_eq_core_init[] = {
782 /* set master volume to max value without distortion
783 * and direct control */
784 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
785 /* setup audio connections */
786 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
Matthew Ranostayf7cf0a72008-09-13 10:36:58 -0400787 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x02},
788 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100789 /* setup adcs to point to mixer */
790 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
791 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
792 /* setup import muxs */
793 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
794 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
795 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
796 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
797 {}
798};
799
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100800static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500801 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100802 /* setup audio connections */
Matthew Ranostay7747ecc2008-03-10 11:30:04 +0100803 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
804 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100805 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
806 /* setup adcs to point to mixer */
807 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
808 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
809 /* setup import muxs */
810 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
811 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
812 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
813 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
814 {}
815};
816
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100817static struct hda_verb stac92hd73xx_8ch_core_init[] = {
818 /* set master volume and direct control */
819 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
820 /* setup audio connections */
821 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
822 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
823 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
824 /* connect hp ports to dac3 */
825 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
826 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
827 /* setup adcs to point to mixer */
828 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
829 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100830 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
831 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
832 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
833 /* setup import muxs */
834 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
835 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
836 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
837 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
838 {}
839};
840
841static struct hda_verb stac92hd73xx_10ch_core_init[] = {
842 /* set master volume and direct control */
843 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
844 /* setup audio connections */
845 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
846 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
847 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
848 /* dac3 is connected to import3 mux */
849 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
850 /* connect hp ports to dac4 */
851 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
852 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
853 /* setup adcs to point to mixer */
854 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
855 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100856 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
857 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
858 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
859 /* setup import muxs */
860 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
861 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
862 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
863 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
864 {}
865};
866
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200867static struct hda_verb stac92hd83xxx_core_init[] = {
868 /* start of config #1 */
869 { 0xe, AC_VERB_SET_CONNECT_SEL, 0x3},
870
871 /* start of config #2 */
872 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0},
873 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0},
874 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1},
875
876 /* power state controls amps */
877 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
878};
879
Matthew Ranostaye035b842007-11-06 11:53:55 +0100880static struct hda_verb stac92hd71bxx_core_init[] = {
881 /* set master volume and direct control */
882 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
883 /* connect headphone jack to dac1 */
884 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100885 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
886 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
887 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
888 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100889};
890
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400891#define HD_DISABLE_PORTF 2
Matthew Ranostay541eee82007-12-14 12:08:04 +0100892static struct hda_verb stac92hd71bxx_analog_core_init[] = {
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200893 /* start of config #1 */
894
895 /* connect port 0f to audio mixer */
896 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200897 /* unmute right and left channels for node 0x0f */
898 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
899 /* start of config #2 */
900
Matthew Ranostay541eee82007-12-14 12:08:04 +0100901 /* set master volume and direct control */
902 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
903 /* connect headphone jack to dac1 */
904 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200905 /* unmute right and left channels for nodes 0x0a, 0xd */
Matthew Ranostaye035b842007-11-06 11:53:55 +0100906 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
907 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100908 {}
909};
910
Tobin Davis8e21c342007-01-08 11:04:17 +0100911static struct hda_verb stac925x_core_init[] = {
912 /* set dac0mux for dac converter */
913 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
914 {}
915};
916
Mattc7d4b2f2005-06-27 14:59:41 +0200917static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200918 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200919 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200920 {}
921};
922
Tobin Davis93ed1502006-09-01 21:03:12 +0200923static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200924 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200925 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200926 /* unmute node 0x1b */
927 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
928 /* select node 0x03 as DAC */
929 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
930 {}
931};
932
Matt Porter3cc08dc2006-01-23 15:27:49 +0100933static struct hda_verb stac927x_core_init[] = {
934 /* set master volume and direct control */
935 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200936 /* enable analog pc beep path */
937 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100938 {}
939};
940
Matt Porterf3302a52006-07-31 12:49:34 +0200941static struct hda_verb stac9205_core_init[] = {
942 /* set master volume and direct control */
943 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200944 /* enable analog pc beep path */
945 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200946 {}
947};
948
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100949#define STAC_MONO_MUX \
950 { \
951 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
952 .name = "Mono Mux", \
953 .count = 1, \
954 .info = stac92xx_mono_mux_enum_info, \
955 .get = stac92xx_mono_mux_enum_get, \
956 .put = stac92xx_mono_mux_enum_put, \
957 }
958
Matthew Ranostay89385032008-09-11 09:49:39 -0400959#define STAC_AMP_MUX \
960 { \
961 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
962 .name = "Amp Selector Capture Switch", \
963 .count = 1, \
964 .info = stac92xx_amp_mux_enum_info, \
965 .get = stac92xx_amp_mux_enum_get, \
966 .put = stac92xx_amp_mux_enum_put, \
967 }
968
969#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
970 { \
971 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
972 .name = xname, \
973 .index = 0, \
974 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
975 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
976 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
977 .info = stac92xx_amp_volume_info, \
978 .get = stac92xx_amp_volume_get, \
979 .put = stac92xx_amp_volume_put, \
980 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
981 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
982 }
983
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200984#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200985 { \
986 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
987 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200988 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200989 .info = stac92xx_mux_enum_info, \
990 .get = stac92xx_mux_enum_get, \
991 .put = stac92xx_mux_enum_put, \
992 }
993
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100994#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200995 { \
996 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
997 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100998 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200999 .info = stac92xx_aloopback_info, \
1000 .get = stac92xx_aloopback_get, \
1001 .put = stac92xx_aloopback_put, \
1002 .private_value = verb_read | (verb_write << 16), \
1003 }
1004
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001005static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +02001006 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1007 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001008 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +02001009 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1010 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001011 { } /* end */
1012};
1013
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001014#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001015static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001016 /* start of config #1 */
1017 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1018 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1019
1020 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1021 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1022
1023 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1024 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1025
1026 /* start of config #2 */
1027 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1028 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1029
1030 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1031 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1032
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001033 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1034
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001035 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1036 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1037
1038 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1039 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1040
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001041 { } /* end */
1042};
1043
1044static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001045 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1046
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001047 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1048 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1049
1050 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1051 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1052
1053 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1054 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1055
1056 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1057 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1058
1059 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1060 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1061
1062 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1063 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1064
1065 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1066 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1067 { } /* end */
1068};
1069
1070static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001071 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1072
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001073 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1074 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1075
1076 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1077 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1078
1079 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1080 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1081
1082 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1083 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1084
1085 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1086 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1087
1088 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1089 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1090
1091 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1092 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1093 { } /* end */
1094};
1095
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001096
1097static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1098 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1099 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1100
1101 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1102 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1103
1104 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0, HDA_INPUT),
1105 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0, HDA_INPUT),
1106
1107 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x1, HDA_INPUT),
1108 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x1, HDA_INPUT),
1109
1110 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x2, HDA_INPUT),
1111 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x2, HDA_INPUT),
1112
1113 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x3, HDA_INPUT),
1114 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x3, HDA_INPUT),
1115
1116 /*
1117 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x4, HDA_INPUT),
1118 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x4, HDA_INPUT),
1119 */
1120 { } /* end */
1121};
1122
Matthew Ranostay541eee82007-12-14 12:08:04 +01001123static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001124 STAC_INPUT_SOURCE(2),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001125 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001126
Matthew Ranostay9b359472007-11-07 13:03:12 +01001127 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1128 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay9b359472007-11-07 13:03:12 +01001129
1130 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1131 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001132 /* analog pc-beep replaced with digital beep support */
1133 /*
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001134 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1135 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001136 */
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001137
Matthew Ranostay687cb982008-10-11 13:52:43 -04001138 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1139 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001140
Matthew Ranostay687cb982008-10-11 13:52:43 -04001141 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1142 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001143
1144 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1145 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1146
1147 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1148 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001149 { } /* end */
1150};
1151
Matthew Ranostay541eee82007-12-14 12:08:04 +01001152static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +01001153 STAC_INPUT_SOURCE(2),
1154 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1155
Matthew Ranostay541eee82007-12-14 12:08:04 +01001156 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1157 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001158
1159 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1160 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001161 { } /* end */
1162};
1163
Tobin Davis8e21c342007-01-08 11:04:17 +01001164static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001165 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +01001166 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
Mauro Carvalho Chehab587755f2008-05-25 18:20:06 +02001167 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
Tobin Davis8e21c342007-01-08 11:04:17 +01001168 { } /* end */
1169};
1170
Takashi Iwaid1d985f2006-11-23 19:27:12 +01001171static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001172 STAC_INPUT_SOURCE(2),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001173 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001174
1175 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1176 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001177
1178 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1179 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001180 { } /* end */
1181};
1182
1183/* This needs to be generated dynamically based on sequence */
1184static struct snd_kcontrol_new stac922x_mixer[] = {
1185 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001186 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1187 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001188
1189 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1190 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001191 { } /* end */
1192};
1193
1194
1195static struct snd_kcontrol_new stac927x_mixer[] = {
1196 STAC_INPUT_SOURCE(3),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001197 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001198
1199 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1200 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001201
1202 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1203 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001204
1205 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1206 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +02001207 { } /* end */
1208};
1209
Takashi Iwai1697055e2007-12-18 18:05:52 +01001210static struct snd_kcontrol_new stac_dmux_mixer = {
1211 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1212 .name = "Digital Input Source",
1213 /* count set later */
1214 .info = stac92xx_dmux_enum_info,
1215 .get = stac92xx_dmux_enum_get,
1216 .put = stac92xx_dmux_enum_put,
1217};
1218
Matthew Ranostayd9737752008-09-07 12:03:41 +02001219static struct snd_kcontrol_new stac_smux_mixer = {
1220 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001221 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001222 /* count set later */
1223 .info = stac92xx_smux_enum_info,
1224 .get = stac92xx_smux_enum_get,
1225 .put = stac92xx_smux_enum_put,
1226};
1227
Takashi Iwai2134ea42008-01-10 16:53:55 +01001228static const char *slave_vols[] = {
1229 "Front Playback Volume",
1230 "Surround Playback Volume",
1231 "Center Playback Volume",
1232 "LFE Playback Volume",
1233 "Side Playback Volume",
1234 "Headphone Playback Volume",
1235 "Headphone Playback Volume",
1236 "Speaker Playback Volume",
1237 "External Speaker Playback Volume",
1238 "Speaker2 Playback Volume",
1239 NULL
1240};
1241
1242static const char *slave_sws[] = {
1243 "Front Playback Switch",
1244 "Surround Playback Switch",
1245 "Center Playback Switch",
1246 "LFE Playback Switch",
1247 "Side Playback Switch",
1248 "Headphone Playback Switch",
1249 "Headphone Playback Switch",
1250 "Speaker Playback Switch",
1251 "External Speaker Playback Switch",
1252 "Speaker2 Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001253 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001254 NULL
1255};
1256
Takashi Iwai603c4012008-07-30 15:01:44 +02001257static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001258static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001259
Matt2f2f4252005-04-13 14:45:30 +02001260static int stac92xx_build_controls(struct hda_codec *codec)
1261{
1262 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001263 struct auto_pin_cfg *cfg = &spec->autocfg;
1264 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001265 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001266 int i;
Matt2f2f4252005-04-13 14:45:30 +02001267
1268 err = snd_hda_add_new_ctls(codec, spec->mixer);
1269 if (err < 0)
1270 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001271
1272 for (i = 0; i < spec->num_mixers; i++) {
1273 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1274 if (err < 0)
1275 return err;
1276 }
Takashi Iwai1697055e2007-12-18 18:05:52 +01001277 if (spec->num_dmuxes > 0) {
1278 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001279 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001280 snd_ctl_new1(&stac_dmux_mixer, codec));
1281 if (err < 0)
1282 return err;
1283 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001284 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001285 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1286 struct hda_input_mux *smux = &spec->private_smux;
1287 /* check for mute support on SPDIF out */
1288 if (wcaps & AC_WCAP_OUT_AMP) {
1289 smux->items[smux->num_items].label = "Off";
1290 smux->items[smux->num_items].index = 0;
1291 smux->num_items++;
1292 spec->spdif_mute = 1;
1293 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001294 stac_smux_mixer.count = spec->num_smuxes;
1295 err = snd_ctl_add(codec->bus->card,
1296 snd_ctl_new1(&stac_smux_mixer, codec));
1297 if (err < 0)
1298 return err;
1299 }
Mattc7d4b2f2005-06-27 14:59:41 +02001300
Mattdabbed62005-06-14 10:19:34 +02001301 if (spec->multiout.dig_out_nid) {
1302 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1303 if (err < 0)
1304 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001305 err = snd_hda_create_spdif_share_sw(codec,
1306 &spec->multiout);
1307 if (err < 0)
1308 return err;
1309 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001310 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001311 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001312 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1313 if (err < 0)
1314 return err;
1315 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001316
1317 /* if we have no master control, let's create it */
1318 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001319 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001320 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001321 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001322 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001323 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001324 if (err < 0)
1325 return err;
1326 }
1327 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1328 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1329 NULL, slave_sws);
1330 if (err < 0)
1331 return err;
1332 }
1333
Takashi Iwai603c4012008-07-30 15:01:44 +02001334 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001335
1336 /* create jack input elements */
1337 if (spec->hp_detect) {
1338 for (i = 0; i < cfg->hp_outs; i++) {
1339 int type = SND_JACK_HEADPHONE;
1340 nid = cfg->hp_pins[i];
1341 /* jack detection */
1342 if (cfg->hp_outs == i)
1343 type |= SND_JACK_LINEOUT;
1344 err = stac92xx_add_jack(codec, nid, type);
1345 if (err < 0)
1346 return err;
1347 }
1348 }
1349 for (i = 0; i < cfg->line_outs; i++) {
1350 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1351 SND_JACK_LINEOUT);
1352 if (err < 0)
1353 return err;
1354 }
1355 for (i = 0; i < AUTO_PIN_LAST; i++) {
1356 nid = cfg->input_pins[i];
1357 if (nid) {
1358 err = stac92xx_add_jack(codec, nid,
1359 SND_JACK_MICROPHONE);
1360 if (err < 0)
1361 return err;
1362 }
1363 }
1364
Mattdabbed62005-06-14 10:19:34 +02001365 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001366}
1367
Matt Porter403d1942005-11-29 15:00:51 +01001368static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001369 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001370 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1371};
1372
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001373/*
1374 STAC 9200 pin configs for
1375 102801A8
1376 102801DE
1377 102801E8
1378*/
1379static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001380 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1381 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001382};
1383
1384/*
1385 STAC 9200 pin configs for
1386 102801C0
1387 102801C1
1388*/
1389static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001390 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1391 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001392};
1393
1394/*
1395 STAC 9200 pin configs for
1396 102801C4 (Dell Dimension E310)
1397 102801C5
1398 102801C7
1399 102801D9
1400 102801DA
1401 102801E3
1402*/
1403static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001404 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1405 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001406};
1407
1408
1409/*
1410 STAC 9200-32 pin configs for
1411 102801B5 (Dell Inspiron 630m)
1412 102801D8 (Dell Inspiron 640m)
1413*/
1414static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001415 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1416 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001417};
1418
1419/*
1420 STAC 9200-32 pin configs for
1421 102801C2 (Dell Latitude D620)
1422 102801C8
1423 102801CC (Dell Latitude D820)
1424 102801D4
1425 102801D6
1426*/
1427static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001428 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1429 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001430};
1431
1432/*
1433 STAC 9200-32 pin configs for
1434 102801CE (Dell XPS M1710)
1435 102801CF (Dell Precision M90)
1436*/
1437static unsigned int dell9200_m23_pin_configs[8] = {
1438 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1439 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1440};
1441
1442/*
1443 STAC 9200-32 pin configs for
1444 102801C9
1445 102801CA
1446 102801CB (Dell Latitude 120L)
1447 102801D3
1448*/
1449static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001450 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1451 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001452};
1453
1454/*
1455 STAC 9200-32 pin configs for
1456 102801BD (Dell Inspiron E1505n)
1457 102801EE
1458 102801EF
1459*/
1460static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001461 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1462 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001463};
1464
1465/*
1466 STAC 9200-32 pin configs for
1467 102801F5 (Dell Inspiron 1501)
1468 102801F6
1469*/
1470static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001471 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1472 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001473};
1474
1475/*
1476 STAC 9200-32
1477 102801CD (Dell Inspiron E1705/9400)
1478*/
1479static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001480 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1481 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001482};
1483
Tobin Davisbf277782008-02-03 20:31:47 +01001484static unsigned int oqo9200_pin_configs[8] = {
1485 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1486 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1487};
1488
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001489
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001490static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1491 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001492 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001493 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1494 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1495 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1496 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1497 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1498 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1499 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1500 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1501 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1502 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001503 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001504};
1505
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001506static const char *stac9200_models[STAC_9200_MODELS] = {
1507 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001508 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001509 [STAC_9200_DELL_D21] = "dell-d21",
1510 [STAC_9200_DELL_D22] = "dell-d22",
1511 [STAC_9200_DELL_D23] = "dell-d23",
1512 [STAC_9200_DELL_M21] = "dell-m21",
1513 [STAC_9200_DELL_M22] = "dell-m22",
1514 [STAC_9200_DELL_M23] = "dell-m23",
1515 [STAC_9200_DELL_M24] = "dell-m24",
1516 [STAC_9200_DELL_M25] = "dell-m25",
1517 [STAC_9200_DELL_M26] = "dell-m26",
1518 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001519 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwai117f2572008-03-18 09:53:23 +01001520 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001521};
1522
1523static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1524 /* SigmaTel reference board */
1525 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1526 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001527 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001528 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1529 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001530 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001531 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1532 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1533 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1534 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1535 "unknown Dell", STAC_9200_DELL_D22),
1536 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1537 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001538 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001539 "Dell Latitude D620", STAC_9200_DELL_M22),
1540 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1541 "unknown Dell", STAC_9200_DELL_D23),
1542 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1543 "unknown Dell", STAC_9200_DELL_D23),
1544 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1545 "unknown Dell", STAC_9200_DELL_M22),
1546 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1547 "unknown Dell", STAC_9200_DELL_M24),
1548 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1549 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001550 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001551 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001552 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001553 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001554 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001555 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001556 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001557 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001558 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001559 "Dell Precision M90", STAC_9200_DELL_M23),
1560 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1561 "unknown Dell", STAC_9200_DELL_M22),
1562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1563 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001565 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001567 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1569 "unknown Dell", STAC_9200_DELL_D23),
1570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1571 "unknown Dell", STAC_9200_DELL_D23),
1572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1573 "unknown Dell", STAC_9200_DELL_D21),
1574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1575 "unknown Dell", STAC_9200_DELL_D23),
1576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1577 "unknown Dell", STAC_9200_DELL_D21),
1578 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1579 "unknown Dell", STAC_9200_DELL_M25),
1580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1581 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001582 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001583 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1584 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1585 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001586 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001587 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001588 /* Gateway machines needs EAPD to be set on resume */
1589 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1590 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1591 STAC_9200_GATEWAY),
1592 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1593 STAC_9200_GATEWAY),
Tobin Davisbf277782008-02-03 20:31:47 +01001594 /* OQO Mobile */
1595 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001596 {} /* terminator */
1597};
1598
Tobin Davis8e21c342007-01-08 11:04:17 +01001599static unsigned int ref925x_pin_configs[8] = {
1600 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001601 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001602};
1603
1604static unsigned int stac925x_MA6_pin_configs[8] = {
1605 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1606 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
1607};
1608
Tobin Davis2c11f952007-05-17 09:36:34 +02001609static unsigned int stac925x_PA6_pin_configs[8] = {
1610 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1611 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
1612};
1613
Tobin Davis8e21c342007-01-08 11:04:17 +01001614static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +02001615 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
1616 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001617};
1618
1619static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1620 [STAC_REF] = ref925x_pin_configs,
1621 [STAC_M2_2] = stac925xM2_2_pin_configs,
1622 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +02001623 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001624};
1625
1626static const char *stac925x_models[STAC_925x_MODELS] = {
1627 [STAC_REF] = "ref",
1628 [STAC_M2_2] = "m2-2",
1629 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +02001630 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001631};
1632
1633static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1634 /* SigmaTel reference board */
1635 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001636 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +01001637 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
1638 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
1639 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +02001640 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +01001641 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
1642 {} /* terminator */
1643};
1644
Matthew Ranostaya7662642008-02-21 07:51:14 +01001645static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001646 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1647 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1648 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001649 0x01452050,
1650};
1651
1652static unsigned int dell_m6_pin_configs[13] = {
1653 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001654 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001655 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1656 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001657};
1658
1659static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001660 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001661 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1662 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1663 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001664 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001665};
1666
1667static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1668 [STAC_92HD73XX_REF] = "ref",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001669 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1670 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1671 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001672 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001673};
1674
1675static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1676 /* SigmaTel reference board */
1677 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001678 "DFI LanParty", STAC_92HD73XX_REF),
1679 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001680 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001681 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001682 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001683 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001684 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001685 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001686 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001687 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001688 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001689 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001690 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001691 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001692 "unknown Dell", STAC_DELL_M6_DMIC),
1693 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1694 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001695 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001696 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001697 {} /* terminator */
1698};
1699
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001700static unsigned int ref92hd83xxx_pin_configs[14] = {
1701 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1702 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1703 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1704 0x01451160, 0x98560170,
1705};
1706
1707static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1708 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1709};
1710
1711static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1712 [STAC_92HD83XXX_REF] = "ref",
1713};
1714
1715static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1716 /* SigmaTel reference board */
1717 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1718 "DFI LanParty", STAC_92HD71BXX_REF),
1719};
1720
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001721static unsigned int ref92hd71bxx_pin_configs[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001722 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001723 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001724 0x90a000f0, 0x01452050, 0x01452050,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001725};
1726
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001727static unsigned int dell_m4_1_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001728 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001729 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001730 0x40f000f0, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001731};
1732
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001733static unsigned int dell_m4_2_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001734 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1735 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001736 0x40f000f0, 0x044413b0, 0x044413b0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001737};
1738
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001739static unsigned int dell_m4_3_pin_configs[11] = {
1740 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1741 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1742 0x40f000f0, 0x044413b0, 0x044413b0,
1743};
1744
Matthew Ranostaye035b842007-11-06 11:53:55 +01001745static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1746 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001747 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1748 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001749 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001750 [STAC_HP_M4] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001751};
1752
1753static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1754 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001755 [STAC_DELL_M4_1] = "dell-m4-1",
1756 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001757 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001758 [STAC_HP_M4] = "hp-m4",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001759};
1760
1761static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1762 /* SigmaTel reference board */
1763 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1764 "DFI LanParty", STAC_92HD71BXX_REF),
Takashi Iwai80bf2722008-11-18 10:48:41 +01001765 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f2,
1766 "HP dv5", STAC_HP_M4),
1767 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4,
1768 "HP dv7", STAC_HP_M4),
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001769 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1770 "unknown HP", STAC_HP_M4),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001771 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1772 "unknown Dell", STAC_DELL_M4_1),
1773 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1774 "unknown Dell", STAC_DELL_M4_1),
1775 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1776 "unknown Dell", STAC_DELL_M4_1),
1777 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1778 "unknown Dell", STAC_DELL_M4_1),
1779 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1780 "unknown Dell", STAC_DELL_M4_1),
1781 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1782 "unknown Dell", STAC_DELL_M4_1),
1783 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1784 "unknown Dell", STAC_DELL_M4_1),
1785 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1786 "unknown Dell", STAC_DELL_M4_2),
1787 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1788 "unknown Dell", STAC_DELL_M4_2),
1789 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1790 "unknown Dell", STAC_DELL_M4_2),
1791 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1792 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001793 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1794 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001795 {} /* terminator */
1796};
1797
Matt Porter403d1942005-11-29 15:00:51 +01001798static unsigned int ref922x_pin_configs[10] = {
1799 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1800 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001801 0x40000100, 0x40000100,
1802};
1803
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001804/*
1805 STAC 922X pin configs for
1806 102801A7
1807 102801AB
1808 102801A9
1809 102801D1
1810 102801D2
1811*/
1812static unsigned int dell_922x_d81_pin_configs[10] = {
1813 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1814 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1815 0x01813122, 0x400001f2,
1816};
1817
1818/*
1819 STAC 922X pin configs for
1820 102801AC
1821 102801D0
1822*/
1823static unsigned int dell_922x_d82_pin_configs[10] = {
1824 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1825 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1826 0x01813122, 0x400001f1,
1827};
1828
1829/*
1830 STAC 922X pin configs for
1831 102801BF
1832*/
1833static unsigned int dell_922x_m81_pin_configs[10] = {
1834 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1835 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1836 0x40C003f1, 0x405003f0,
1837};
1838
1839/*
1840 STAC 9221 A1 pin configs for
1841 102801D7 (Dell XPS M1210)
1842*/
1843static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001844 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1845 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001846 0x508003f3, 0x405003f4,
1847};
1848
Matt Porter403d1942005-11-29 15:00:51 +01001849static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001850 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001851 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1852 0x02a19120, 0x40000100,
1853};
1854
1855static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001856 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1857 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001858 0x02a19320, 0x40000100,
1859};
1860
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001861static unsigned int intel_mac_v1_pin_configs[10] = {
1862 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1863 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001864 0x400000fc, 0x400000fb,
1865};
1866
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001867static unsigned int intel_mac_v2_pin_configs[10] = {
1868 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1869 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001870 0x400000fc, 0x400000fb,
1871};
1872
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001873static unsigned int intel_mac_v3_pin_configs[10] = {
1874 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1875 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1876 0x400000fc, 0x400000fb,
1877};
1878
1879static unsigned int intel_mac_v4_pin_configs[10] = {
1880 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1881 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1882 0x400000fc, 0x400000fb,
1883};
1884
1885static unsigned int intel_mac_v5_pin_configs[10] = {
1886 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1887 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1888 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001889};
1890
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001891static unsigned int ecs202_pin_configs[10] = {
1892 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1893 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1894 0x9037012e, 0x40e000f2,
1895};
Takashi Iwai76c08822007-06-19 12:17:42 +02001896
Takashi Iwai19039bd2006-06-28 15:52:16 +02001897static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001898 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001899 [STAC_D945GTP3] = d945gtp3_pin_configs,
1900 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001901 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1902 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1903 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1904 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1905 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001906 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001907 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001908 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1909 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1910 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1911 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1912 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1913 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001914 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001915 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1916 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1917 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1918 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001919};
1920
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001921static const char *stac922x_models[STAC_922X_MODELS] = {
1922 [STAC_D945_REF] = "ref",
1923 [STAC_D945GTP5] = "5stack",
1924 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001925 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1926 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1927 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1928 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1929 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001930 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001931 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001932 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001933 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001934 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1935 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001936 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001937 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001938 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001939 [STAC_922X_DELL_D81] = "dell-d81",
1940 [STAC_922X_DELL_D82] = "dell-d82",
1941 [STAC_922X_DELL_M81] = "dell-m81",
1942 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001943};
1944
1945static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1946 /* SigmaTel reference board */
1947 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1948 "DFI LanParty", STAC_D945_REF),
1949 /* Intel 945G based systems */
1950 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1951 "Intel D945G", STAC_D945GTP3),
1952 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1953 "Intel D945G", STAC_D945GTP3),
1954 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1955 "Intel D945G", STAC_D945GTP3),
1956 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1957 "Intel D945G", STAC_D945GTP3),
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1959 "Intel D945G", STAC_D945GTP3),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1961 "Intel D945G", STAC_D945GTP3),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1963 "Intel D945G", STAC_D945GTP3),
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1965 "Intel D945G", STAC_D945GTP3),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1967 "Intel D945G", STAC_D945GTP3),
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1969 "Intel D945G", STAC_D945GTP3),
1970 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1971 "Intel D945G", STAC_D945GTP3),
1972 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1973 "Intel D945G", STAC_D945GTP3),
1974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1975 "Intel D945G", STAC_D945GTP3),
1976 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1977 "Intel D945G", STAC_D945GTP3),
1978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1979 "Intel D945G", STAC_D945GTP3),
1980 /* Intel D945G 5-stack systems */
1981 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1982 "Intel D945G", STAC_D945GTP5),
1983 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1984 "Intel D945G", STAC_D945GTP5),
1985 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1986 "Intel D945G", STAC_D945GTP5),
1987 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1988 "Intel D945G", STAC_D945GTP5),
1989 /* Intel 945P based systems */
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1991 "Intel D945P", STAC_D945GTP3),
1992 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1993 "Intel D945P", STAC_D945GTP3),
1994 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1995 "Intel D945P", STAC_D945GTP3),
1996 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1997 "Intel D945P", STAC_D945GTP3),
1998 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1999 "Intel D945P", STAC_D945GTP3),
2000 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2001 "Intel D945P", STAC_D945GTP5),
2002 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002003 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002004 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002005 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002006 /* Dell systems */
2007 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2008 "unknown Dell", STAC_922X_DELL_D81),
2009 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2010 "unknown Dell", STAC_922X_DELL_D81),
2011 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2012 "unknown Dell", STAC_922X_DELL_D81),
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2014 "unknown Dell", STAC_922X_DELL_D82),
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2016 "unknown Dell", STAC_922X_DELL_M81),
2017 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2018 "unknown Dell", STAC_922X_DELL_D82),
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2020 "unknown Dell", STAC_922X_DELL_D81),
2021 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2022 "unknown Dell", STAC_922X_DELL_D81),
2023 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2024 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002025 /* ECS/PC Chips boards */
2026 SND_PCI_QUIRK(0x1019, 0x2144,
2027 "ECS/PC chips", STAC_ECS_202),
2028 SND_PCI_QUIRK(0x1019, 0x2608,
2029 "ECS/PC chips", STAC_ECS_202),
2030 SND_PCI_QUIRK(0x1019, 0x2633,
2031 "ECS/PC chips P17G/1333", STAC_ECS_202),
2032 SND_PCI_QUIRK(0x1019, 0x2811,
2033 "ECS/PC chips", STAC_ECS_202),
2034 SND_PCI_QUIRK(0x1019, 0x2812,
2035 "ECS/PC chips", STAC_ECS_202),
2036 SND_PCI_QUIRK(0x1019, 0x2813,
2037 "ECS/PC chips", STAC_ECS_202),
2038 SND_PCI_QUIRK(0x1019, 0x2814,
2039 "ECS/PC chips", STAC_ECS_202),
2040 SND_PCI_QUIRK(0x1019, 0x2815,
2041 "ECS/PC chips", STAC_ECS_202),
2042 SND_PCI_QUIRK(0x1019, 0x2816,
2043 "ECS/PC chips", STAC_ECS_202),
2044 SND_PCI_QUIRK(0x1019, 0x2817,
2045 "ECS/PC chips", STAC_ECS_202),
2046 SND_PCI_QUIRK(0x1019, 0x2818,
2047 "ECS/PC chips", STAC_ECS_202),
2048 SND_PCI_QUIRK(0x1019, 0x2819,
2049 "ECS/PC chips", STAC_ECS_202),
2050 SND_PCI_QUIRK(0x1019, 0x2820,
2051 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002052 {} /* terminator */
2053};
2054
Matt Porter3cc08dc2006-01-23 15:27:49 +01002055static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002056 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2057 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2058 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2059 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002060};
2061
Tobin Davis93ed1502006-09-01 21:03:12 +02002062static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002063 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2064 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2065 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2066 0x40000100, 0x40000100
2067};
2068
Tobin Davis93ed1502006-09-01 21:03:12 +02002069static unsigned int d965_5st_pin_configs[14] = {
2070 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2071 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2072 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2073 0x40000100, 0x40000100
2074};
2075
Tobin Davis4ff076e2007-08-07 11:48:12 +02002076static unsigned int dell_3st_pin_configs[14] = {
2077 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2078 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002079 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002080 0x40c003fc, 0x40000100
2081};
2082
Tobin Davis93ed1502006-09-01 21:03:12 +02002083static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002084 [STAC_D965_REF] = ref927x_pin_configs,
2085 [STAC_D965_3ST] = d965_3st_pin_configs,
2086 [STAC_D965_5ST] = d965_5st_pin_configs,
2087 [STAC_DELL_3ST] = dell_3st_pin_configs,
2088 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002089};
2090
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002091static const char *stac927x_models[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002092 [STAC_D965_REF] = "ref",
2093 [STAC_D965_3ST] = "3stack",
2094 [STAC_D965_5ST] = "5stack",
2095 [STAC_DELL_3ST] = "dell-3stack",
2096 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002097};
2098
2099static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2100 /* SigmaTel reference board */
2101 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2102 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002103 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002104 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002106 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002107 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
2108 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
2109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
2110 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
2111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
2112 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
2113 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
2115 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
2117 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
2119 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
2121 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
2122 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002123 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002124 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002125 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002126 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2127 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002128 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002129 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2130 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002131 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Takashi Iwai24918b62008-09-30 12:58:54 +02002132 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002133 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2134 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2135 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2136 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002137 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002138 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
2139 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
2140 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
2141 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
2142 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
2143 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
2144 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
2145 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
2146 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002147 {} /* terminator */
2148};
2149
Matt Porterf3302a52006-07-31 12:49:34 +02002150static unsigned int ref9205_pin_configs[12] = {
2151 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002152 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002153 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002154};
2155
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002156/*
2157 STAC 9205 pin configs for
2158 102801F1
2159 102801F2
2160 102801FC
2161 102801FD
2162 10280204
2163 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002164 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002165*/
2166static unsigned int dell_9205_m42_pin_configs[12] = {
2167 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2168 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2169 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2170};
2171
2172/*
2173 STAC 9205 pin configs for
2174 102801F9
2175 102801FA
2176 102801FE
2177 102801FF (Dell Precision M4300)
2178 10280206
2179 10280200
2180 10280201
2181*/
2182static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002183 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2184 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2185 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2186};
2187
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002188static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002189 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2190 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2191 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2192};
2193
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002194static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002195 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002196 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2197 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2198 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02002199};
2200
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002201static const char *stac9205_models[STAC_9205_MODELS] = {
2202 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002203 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002204 [STAC_9205_DELL_M43] = "dell-m43",
2205 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002206};
2207
2208static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2209 /* SigmaTel reference board */
2210 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2211 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002212 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2213 "unknown Dell", STAC_9205_DELL_M42),
2214 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2215 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002216 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002217 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002218 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2219 "Dell Precision", STAC_9205_DELL_M43),
2220 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2221 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002222 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2223 "unknown Dell", STAC_9205_DELL_M42),
2224 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2225 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002226 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2227 "Dell Precision", STAC_9205_DELL_M43),
2228 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002229 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002230 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2231 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002232 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2233 "Dell Precision", STAC_9205_DELL_M43),
2234 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2235 "Dell Precision", STAC_9205_DELL_M43),
2236 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2237 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002238 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2239 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002240 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2241 "Dell Vostro 1500", STAC_9205_DELL_M42),
Matt Porterf3302a52006-07-31 12:49:34 +02002242 {} /* terminator */
2243};
2244
Richard Fish11b44bb2006-08-23 18:31:34 +02002245static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2246{
2247 int i;
2248 struct sigmatel_spec *spec = codec->spec;
2249
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002250 kfree(spec->pin_configs);
2251 spec->pin_configs = kcalloc(spec->num_pins, sizeof(*spec->pin_configs),
2252 GFP_KERNEL);
2253 if (!spec->pin_configs)
2254 return -ENOMEM;
Richard Fish11b44bb2006-08-23 18:31:34 +02002255
2256 for (i = 0; i < spec->num_pins; i++) {
2257 hda_nid_t nid = spec->pin_nids[i];
2258 unsigned int pin_cfg;
2259
2260 pin_cfg = snd_hda_codec_read(codec, nid, 0,
2261 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2262 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2263 nid, pin_cfg);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002264 spec->pin_configs[i] = pin_cfg;
Richard Fish11b44bb2006-08-23 18:31:34 +02002265 }
2266
2267 return 0;
2268}
2269
Matthew Ranostay87d48362007-07-17 11:52:24 +02002270static void stac92xx_set_config_reg(struct hda_codec *codec,
2271 hda_nid_t pin_nid, unsigned int pin_config)
2272{
2273 int i;
2274 snd_hda_codec_write(codec, pin_nid, 0,
2275 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2276 pin_config & 0x000000ff);
2277 snd_hda_codec_write(codec, pin_nid, 0,
2278 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2279 (pin_config & 0x0000ff00) >> 8);
2280 snd_hda_codec_write(codec, pin_nid, 0,
2281 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2282 (pin_config & 0x00ff0000) >> 16);
2283 snd_hda_codec_write(codec, pin_nid, 0,
2284 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2285 pin_config >> 24);
2286 i = snd_hda_codec_read(codec, pin_nid, 0,
2287 AC_VERB_GET_CONFIG_DEFAULT,
2288 0x00);
2289 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
2290 pin_nid, i);
2291}
2292
Matt2f2f4252005-04-13 14:45:30 +02002293static void stac92xx_set_config_regs(struct hda_codec *codec)
2294{
2295 int i;
2296 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002297
Matthew Ranostay87d48362007-07-17 11:52:24 +02002298 if (!spec->pin_configs)
2299 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002300
Matthew Ranostay87d48362007-07-17 11:52:24 +02002301 for (i = 0; i < spec->num_pins; i++)
2302 stac92xx_set_config_reg(codec, spec->pin_nids[i],
2303 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02002304}
Matt2f2f4252005-04-13 14:45:30 +02002305
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002306static int stac_save_pin_cfgs(struct hda_codec *codec, unsigned int *pins)
2307{
2308 struct sigmatel_spec *spec = codec->spec;
2309
2310 if (!pins)
2311 return stac92xx_save_bios_config_regs(codec);
2312
2313 kfree(spec->pin_configs);
2314 spec->pin_configs = kmemdup(pins,
2315 spec->num_pins * sizeof(*pins),
2316 GFP_KERNEL);
2317 if (!spec->pin_configs)
2318 return -ENOMEM;
2319
2320 stac92xx_set_config_regs(codec);
2321 return 0;
2322}
2323
2324static void stac_change_pin_config(struct hda_codec *codec, hda_nid_t nid,
2325 unsigned int cfg)
2326{
2327 struct sigmatel_spec *spec = codec->spec;
2328 int i;
2329
2330 for (i = 0; i < spec->num_pins; i++) {
2331 if (spec->pin_nids[i] == nid) {
2332 spec->pin_configs[i] = cfg;
2333 stac92xx_set_config_reg(codec, nid, cfg);
2334 break;
2335 }
2336 }
2337}
2338
Matt2f2f4252005-04-13 14:45:30 +02002339/*
2340 * Analog playback callbacks
2341 */
2342static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2343 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002344 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002345{
2346 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002347 if (spec->stream_delay)
2348 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002349 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2350 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002351}
2352
2353static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2354 struct hda_codec *codec,
2355 unsigned int stream_tag,
2356 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002357 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002358{
2359 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002360 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002361}
2362
2363static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2364 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002365 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002366{
2367 struct sigmatel_spec *spec = codec->spec;
2368 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2369}
2370
2371/*
Mattdabbed62005-06-14 10:19:34 +02002372 * Digital playback callbacks
2373 */
2374static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2375 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002376 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002377{
2378 struct sigmatel_spec *spec = codec->spec;
2379 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2380}
2381
2382static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2383 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002384 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002385{
2386 struct sigmatel_spec *spec = codec->spec;
2387 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2388}
2389
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002390static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2391 struct hda_codec *codec,
2392 unsigned int stream_tag,
2393 unsigned int format,
2394 struct snd_pcm_substream *substream)
2395{
2396 struct sigmatel_spec *spec = codec->spec;
2397 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2398 stream_tag, format, substream);
2399}
2400
Mattdabbed62005-06-14 10:19:34 +02002401
2402/*
Matt2f2f4252005-04-13 14:45:30 +02002403 * Analog capture callbacks
2404 */
2405static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2406 struct hda_codec *codec,
2407 unsigned int stream_tag,
2408 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002409 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002410{
2411 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002412 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002413
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002414 if (spec->powerdown_adcs) {
2415 msleep(40);
2416 snd_hda_codec_write_cache(codec, nid, 0,
2417 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2418 }
2419 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002420 return 0;
2421}
2422
2423static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2424 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002425 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002426{
2427 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002428 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002429
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002430 snd_hda_codec_cleanup_stream(codec, nid);
2431 if (spec->powerdown_adcs)
2432 snd_hda_codec_write_cache(codec, nid, 0,
2433 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002434 return 0;
2435}
2436
Mattdabbed62005-06-14 10:19:34 +02002437static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2438 .substreams = 1,
2439 .channels_min = 2,
2440 .channels_max = 2,
2441 /* NID is set in stac92xx_build_pcms */
2442 .ops = {
2443 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002444 .close = stac92xx_dig_playback_pcm_close,
2445 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02002446 },
2447};
2448
2449static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2450 .substreams = 1,
2451 .channels_min = 2,
2452 .channels_max = 2,
2453 /* NID is set in stac92xx_build_pcms */
2454};
2455
Matt2f2f4252005-04-13 14:45:30 +02002456static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2457 .substreams = 1,
2458 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002459 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002460 .nid = 0x02, /* NID to query formats and rates */
2461 .ops = {
2462 .open = stac92xx_playback_pcm_open,
2463 .prepare = stac92xx_playback_pcm_prepare,
2464 .cleanup = stac92xx_playback_pcm_cleanup
2465 },
2466};
2467
Matt Porter3cc08dc2006-01-23 15:27:49 +01002468static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2469 .substreams = 1,
2470 .channels_min = 2,
2471 .channels_max = 2,
2472 .nid = 0x06, /* NID to query formats and rates */
2473 .ops = {
2474 .open = stac92xx_playback_pcm_open,
2475 .prepare = stac92xx_playback_pcm_prepare,
2476 .cleanup = stac92xx_playback_pcm_cleanup
2477 },
2478};
2479
Matt2f2f4252005-04-13 14:45:30 +02002480static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002481 .channels_min = 2,
2482 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002483 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002484 .ops = {
2485 .prepare = stac92xx_capture_pcm_prepare,
2486 .cleanup = stac92xx_capture_pcm_cleanup
2487 },
2488};
2489
2490static int stac92xx_build_pcms(struct hda_codec *codec)
2491{
2492 struct sigmatel_spec *spec = codec->spec;
2493 struct hda_pcm *info = spec->pcm_rec;
2494
2495 codec->num_pcms = 1;
2496 codec->pcm_info = info;
2497
Mattc7d4b2f2005-06-27 14:59:41 +02002498 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002499 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02002500 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002501 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002502 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002503
2504 if (spec->alt_switch) {
2505 codec->num_pcms++;
2506 info++;
2507 info->name = "STAC92xx Analog Alt";
2508 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2509 }
Matt2f2f4252005-04-13 14:45:30 +02002510
Mattdabbed62005-06-14 10:19:34 +02002511 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2512 codec->num_pcms++;
2513 info++;
2514 info->name = "STAC92xx Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01002515 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Mattdabbed62005-06-14 10:19:34 +02002516 if (spec->multiout.dig_out_nid) {
2517 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2518 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2519 }
2520 if (spec->dig_in_nid) {
2521 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2522 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2523 }
2524 }
2525
Matt2f2f4252005-04-13 14:45:30 +02002526 return 0;
2527}
2528
Takashi Iwaic960a032006-03-23 17:06:28 +01002529static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2530{
2531 unsigned int pincap = snd_hda_param_read(codec, nid,
2532 AC_PAR_PIN_CAP);
2533 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2534 if (pincap & AC_PINCAP_VREF_100)
2535 return AC_PINCTL_VREF_100;
2536 if (pincap & AC_PINCAP_VREF_80)
2537 return AC_PINCTL_VREF_80;
2538 if (pincap & AC_PINCAP_VREF_50)
2539 return AC_PINCTL_VREF_50;
2540 if (pincap & AC_PINCAP_VREF_GRD)
2541 return AC_PINCTL_VREF_GRD;
2542 return 0;
2543}
2544
Matt Porter403d1942005-11-29 15:00:51 +01002545static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2546
2547{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002548 snd_hda_codec_write_cache(codec, nid, 0,
2549 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002550}
2551
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002552#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2553
2554static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2555 struct snd_ctl_elem_value *ucontrol)
2556{
2557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2558 struct sigmatel_spec *spec = codec->spec;
2559
Takashi Iwaid7a89432008-11-12 09:48:04 +01002560 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002561 return 0;
2562}
2563
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002564static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2565 unsigned char type);
2566
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002567static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2568 struct snd_ctl_elem_value *ucontrol)
2569{
2570 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2571 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002572 int nid = kcontrol->private_value;
2573
2574 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002575
2576 /* check to be sure that the ports are upto date with
2577 * switch changes
2578 */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002579 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002580
2581 return 1;
2582}
2583
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002584#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01002585
2586static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2587{
2588 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2589 struct sigmatel_spec *spec = codec->spec;
2590 int io_idx = kcontrol-> private_value & 0xff;
2591
2592 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2593 return 0;
2594}
2595
2596static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2597{
2598 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2599 struct sigmatel_spec *spec = codec->spec;
2600 hda_nid_t nid = kcontrol->private_value >> 8;
2601 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002602 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01002603
2604 spec->io_switch[io_idx] = val;
2605
2606 if (val)
2607 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002608 else {
2609 unsigned int pinctl = AC_PINCTL_IN_EN;
2610 if (io_idx) /* set VREF for mic */
2611 pinctl |= stac92xx_get_vref(codec, nid);
2612 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2613 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002614
2615 /* check the auto-mute again: we need to mute/unmute the speaker
2616 * appropriately according to the pin direction
2617 */
2618 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002619 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002620
Matt Porter403d1942005-11-29 15:00:51 +01002621 return 1;
2622}
2623
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002624#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2625
2626static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2627 struct snd_ctl_elem_value *ucontrol)
2628{
2629 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2630 struct sigmatel_spec *spec = codec->spec;
2631
2632 ucontrol->value.integer.value[0] = spec->clfe_swap;
2633 return 0;
2634}
2635
2636static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2637 struct snd_ctl_elem_value *ucontrol)
2638{
2639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2640 struct sigmatel_spec *spec = codec->spec;
2641 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002642 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002643
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002644 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002645 return 0;
2646
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002647 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002648
2649 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2650 spec->clfe_swap ? 0x4 : 0x0);
2651
2652 return 1;
2653}
2654
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002655#define STAC_CODEC_HP_SWITCH(xname) \
2656 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2657 .name = xname, \
2658 .index = 0, \
2659 .info = stac92xx_hp_switch_info, \
2660 .get = stac92xx_hp_switch_get, \
2661 .put = stac92xx_hp_switch_put, \
2662 }
2663
Matt Porter403d1942005-11-29 15:00:51 +01002664#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2665 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2666 .name = xname, \
2667 .index = 0, \
2668 .info = stac92xx_io_switch_info, \
2669 .get = stac92xx_io_switch_get, \
2670 .put = stac92xx_io_switch_put, \
2671 .private_value = xpval, \
2672 }
2673
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002674#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2675 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2676 .name = xname, \
2677 .index = 0, \
2678 .info = stac92xx_clfe_switch_info, \
2679 .get = stac92xx_clfe_switch_get, \
2680 .put = stac92xx_clfe_switch_put, \
2681 .private_value = xpval, \
2682 }
Matt Porter403d1942005-11-29 15:00:51 +01002683
Mattc7d4b2f2005-06-27 14:59:41 +02002684enum {
2685 STAC_CTL_WIDGET_VOL,
2686 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002687 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002688 STAC_CTL_WIDGET_AMP_MUX,
2689 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002690 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002691 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002692 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02002693};
2694
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002695static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002696 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2697 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002698 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002699 STAC_AMP_MUX,
2700 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002701 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002702 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002703 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002704};
2705
2706/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002707static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2708 struct snd_kcontrol_new *ktemp,
2709 int idx, const char *name,
2710 unsigned long val)
Mattc7d4b2f2005-06-27 14:59:41 +02002711{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002712 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002713
Takashi Iwai603c4012008-07-30 15:01:44 +02002714 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2715 knew = snd_array_new(&spec->kctls);
2716 if (!knew)
2717 return -ENOMEM;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002718 *knew = *ktemp;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002719 knew->index = idx;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002720 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002721 if (!knew->name)
Mattc7d4b2f2005-06-27 14:59:41 +02002722 return -ENOMEM;
2723 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002724 return 0;
2725}
2726
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002727static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2728 int type, int idx, const char *name,
2729 unsigned long val)
2730{
2731 return stac92xx_add_control_temp(spec,
2732 &stac92xx_control_templates[type],
2733 idx, name, val);
2734}
2735
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002736
2737/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002738static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2739 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002740{
2741 return stac92xx_add_control_idx(spec, type, 0, name, val);
2742}
2743
Matt Porter403d1942005-11-29 15:00:51 +01002744/* flag inputs as additional dynamic lineouts */
2745static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2746{
2747 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002748 unsigned int wcaps, wtype;
2749 int i, num_dacs = 0;
2750
2751 /* use the wcaps cache to count all DACs available for line-outs */
2752 for (i = 0; i < codec->num_nodes; i++) {
2753 wcaps = codec->wcaps[i];
2754 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002755
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002756 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
2757 num_dacs++;
2758 }
Matt Porter403d1942005-11-29 15:00:51 +01002759
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002760 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
2761
Matt Porter403d1942005-11-29 15:00:51 +01002762 switch (cfg->line_outs) {
2763 case 3:
2764 /* add line-in as side */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002765 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002766 cfg->line_out_pins[cfg->line_outs] =
2767 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002768 spec->line_switch = 1;
2769 cfg->line_outs++;
2770 }
2771 break;
2772 case 2:
2773 /* add line-in as clfe and mic as side */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002774 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002775 cfg->line_out_pins[cfg->line_outs] =
2776 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002777 spec->line_switch = 1;
2778 cfg->line_outs++;
2779 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002780 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002781 cfg->line_out_pins[cfg->line_outs] =
2782 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002783 spec->mic_switch = 1;
2784 cfg->line_outs++;
2785 }
2786 break;
2787 case 1:
2788 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002789 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002790 cfg->line_out_pins[cfg->line_outs] =
2791 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002792 spec->line_switch = 1;
2793 cfg->line_outs++;
2794 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002795 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002796 cfg->line_out_pins[cfg->line_outs] =
2797 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002798 spec->mic_switch = 1;
2799 cfg->line_outs++;
2800 }
2801 break;
2802 }
2803
2804 return 0;
2805}
2806
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002807
2808static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2809{
2810 int i;
2811
2812 for (i = 0; i < spec->multiout.num_dacs; i++) {
2813 if (spec->multiout.dac_nids[i] == nid)
2814 return 1;
2815 }
2816
2817 return 0;
2818}
2819
Matt Porter3cc08dc2006-01-23 15:27:49 +01002820/*
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002821 * Fill in the dac_nids table from the parsed pin configuration
2822 * This function only works when every pin in line_out_pins[]
2823 * contains atleast one DAC in its connection list. Some 92xx
2824 * codecs are not connected directly to a DAC, such as the 9200
2825 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002826 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002827static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02002828 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002829{
2830 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002831 int i, j, conn_len = 0;
2832 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2833 unsigned int wcaps, wtype;
2834
Mattc7d4b2f2005-06-27 14:59:41 +02002835 for (i = 0; i < cfg->line_outs; i++) {
2836 nid = cfg->line_out_pins[i];
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002837 conn_len = snd_hda_get_connections(codec, nid, conn,
2838 HDA_MAX_CONNECTIONS);
2839 for (j = 0; j < conn_len; j++) {
2840 wcaps = snd_hda_param_read(codec, conn[j],
2841 AC_PAR_AUDIO_WIDGET_CAP);
2842 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002843 if (wtype != AC_WID_AUD_OUT ||
2844 (wcaps & AC_WCAP_DIGITAL))
2845 continue;
2846 /* conn[j] is a DAC routed to this line-out */
2847 if (!is_in_dac_nids(spec, conn[j]))
2848 break;
2849 }
2850
2851 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002852 if (spec->multiout.num_dacs > 0) {
2853 /* we have already working output pins,
2854 * so let's drop the broken ones again
2855 */
2856 cfg->line_outs = spec->multiout.num_dacs;
2857 break;
2858 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002859 /* error out, no available DAC found */
2860 snd_printk(KERN_ERR
2861 "%s: No available DAC for pin 0x%x\n",
2862 __func__, nid);
2863 return -ENODEV;
2864 }
2865
2866 spec->multiout.dac_nids[i] = conn[j];
2867 spec->multiout.num_dacs++;
2868 if (conn_len > 1) {
2869 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002870 snd_hda_codec_write_cache(codec, nid, 0,
2871 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002872
2873 }
Mattc7d4b2f2005-06-27 14:59:41 +02002874 }
2875
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002876 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2877 spec->multiout.num_dacs,
2878 spec->multiout.dac_nids[0],
2879 spec->multiout.dac_nids[1],
2880 spec->multiout.dac_nids[2],
2881 spec->multiout.dac_nids[3],
2882 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02002883 return 0;
2884}
2885
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002886/* create volume control/switch for the given prefx type */
2887static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2888{
2889 char name[32];
2890 int err;
2891
2892 sprintf(name, "%s Playback Volume", pfx);
2893 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2894 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2895 if (err < 0)
2896 return err;
2897 sprintf(name, "%s Playback Switch", pfx);
2898 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2899 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2900 if (err < 0)
2901 return err;
2902 return 0;
2903}
2904
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002905static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2906{
2907 if (!spec->multiout.hp_nid)
2908 spec->multiout.hp_nid = nid;
2909 else if (spec->multiout.num_dacs > 4) {
2910 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2911 return 1;
2912 } else {
2913 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2914 spec->multiout.num_dacs++;
2915 }
2916 return 0;
2917}
2918
2919static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2920{
2921 if (is_in_dac_nids(spec, nid))
2922 return 1;
2923 if (spec->multiout.hp_nid == nid)
2924 return 1;
2925 return 0;
2926}
2927
Mattc7d4b2f2005-06-27 14:59:41 +02002928/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002929static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002930 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002931{
Takashi Iwai19039bd2006-06-28 15:52:16 +02002932 static const char *chname[4] = {
2933 "Front", "Surround", NULL /*CLFE*/, "Side"
2934 };
Matthew Ranostayd21995e2008-10-13 13:22:45 -04002935 hda_nid_t nid = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002936 int i, err;
2937
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002938 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002939 unsigned int wid_caps, pincap;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002940
2941
Takashi Iwai40ac8c42008-02-29 14:16:17 +01002942 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01002943 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02002944 continue;
2945
2946 nid = spec->multiout.dac_nids[i];
2947
2948 if (i == 2) {
2949 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002950 err = create_controls(spec, "Center", nid, 1);
2951 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002952 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002953 err = create_controls(spec, "LFE", nid, 2);
2954 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002955 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002956
2957 wid_caps = get_wcaps(codec, nid);
2958
2959 if (wid_caps & AC_WCAP_LR_SWAP) {
2960 err = stac92xx_add_control(spec,
2961 STAC_CTL_WIDGET_CLFE_SWITCH,
2962 "Swap Center/LFE Playback Switch", nid);
2963
2964 if (err < 0)
2965 return err;
2966 }
2967
Mattc7d4b2f2005-06-27 14:59:41 +02002968 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002969 err = create_controls(spec, chname[i], nid, 3);
2970 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002971 return err;
2972 }
2973 }
2974
Matthew Ranostayfedb7562008-09-23 21:46:30 -04002975 if ((spec->multiout.num_dacs - cfg->line_outs) > 0 &&
2976 cfg->hp_outs && !spec->multiout.hp_nid)
2977 spec->multiout.hp_nid = nid;
2978
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01002979 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002980 err = stac92xx_add_control(spec,
2981 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01002982 "Headphone as Line Out Switch",
2983 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002984 if (err < 0)
2985 return err;
2986 }
2987
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002988 if (spec->line_switch) {
2989 nid = cfg->input_pins[AUTO_PIN_LINE];
2990 pincap = snd_hda_param_read(codec, nid,
2991 AC_PAR_PIN_CAP);
2992 if (pincap & AC_PINCAP_OUT) {
2993 err = stac92xx_add_control(spec,
2994 STAC_CTL_WIDGET_IO_SWITCH,
2995 "Line In as Output Switch", nid << 8);
2996 if (err < 0)
2997 return err;
2998 }
2999 }
Matt Porter403d1942005-11-29 15:00:51 +01003000
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003001 if (spec->mic_switch) {
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003002 unsigned int def_conf;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003003 unsigned int mic_pin = AUTO_PIN_MIC;
3004again:
3005 nid = cfg->input_pins[mic_pin];
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003006 def_conf = snd_hda_codec_read(codec, nid, 0,
3007 AC_VERB_GET_CONFIG_DEFAULT, 0);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003008 /* some laptops have an internal analog microphone
3009 * which can't be used as a output */
3010 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
3011 pincap = snd_hda_param_read(codec, nid,
3012 AC_PAR_PIN_CAP);
3013 if (pincap & AC_PINCAP_OUT) {
3014 err = stac92xx_add_control(spec,
3015 STAC_CTL_WIDGET_IO_SWITCH,
3016 "Mic as Output Switch", (nid << 8) | 1);
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003017 nid = snd_hda_codec_read(codec, nid, 0,
3018 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3019 if (!check_in_dac_nids(spec, nid))
3020 add_spec_dacs(spec, nid);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003021 if (err < 0)
3022 return err;
3023 }
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003024 } else if (mic_pin == AUTO_PIN_MIC) {
3025 mic_pin = AUTO_PIN_FRONT_MIC;
3026 goto again;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003027 }
3028 }
Matt Porter403d1942005-11-29 15:00:51 +01003029
Mattc7d4b2f2005-06-27 14:59:41 +02003030 return 0;
3031}
3032
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003033/* add playback controls for Speaker and HP outputs */
3034static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3035 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003036{
3037 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003038 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003039 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003040
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003041 old_num_dacs = spec->multiout.num_dacs;
3042 for (i = 0; i < cfg->hp_outs; i++) {
3043 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
3044 if (wid_caps & AC_WCAP_UNSOL_CAP)
3045 spec->hp_detect = 1;
3046 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
3047 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3048 if (check_in_dac_nids(spec, nid))
3049 nid = 0;
3050 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02003051 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003052 add_spec_dacs(spec, nid);
3053 }
3054 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003055 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003056 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3057 if (check_in_dac_nids(spec, nid))
3058 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003059 if (! nid)
3060 continue;
3061 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02003062 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02003063 for (i = 0; i < cfg->line_outs; i++) {
3064 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
3065 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3066 if (check_in_dac_nids(spec, nid))
3067 nid = 0;
3068 if (! nid)
3069 continue;
3070 add_spec_dacs(spec, nid);
3071 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003072 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
3073 static const char *pfxs[] = {
3074 "Speaker", "External Speaker", "Speaker2",
3075 };
3076 err = create_controls(spec, pfxs[i - old_num_dacs],
3077 spec->multiout.dac_nids[i], 3);
3078 if (err < 0)
3079 return err;
3080 }
3081 if (spec->multiout.hp_nid) {
Takashi Iwai2626a262008-03-14 09:18:32 +01003082 err = create_controls(spec, "Headphone",
3083 spec->multiout.hp_nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003084 if (err < 0)
3085 return err;
3086 }
Mattc7d4b2f2005-06-27 14:59:41 +02003087
3088 return 0;
3089}
3090
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003091/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003092static const char *stac92xx_mono_labels[4] = {
3093 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003094};
3095
3096/* create mono mux for mono out on capable codecs */
3097static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3098{
3099 struct sigmatel_spec *spec = codec->spec;
3100 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3101 int i, num_cons;
3102 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3103
3104 num_cons = snd_hda_get_connections(codec,
3105 spec->mono_nid,
3106 con_lst,
3107 HDA_MAX_NUM_INPUTS);
3108 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3109 return -EINVAL;
3110
3111 for (i = 0; i < num_cons; i++) {
3112 mono_mux->items[mono_mux->num_items].label =
3113 stac92xx_mono_labels[i];
3114 mono_mux->items[mono_mux->num_items].index = i;
3115 mono_mux->num_items++;
3116 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003117
3118 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3119 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003120}
3121
Matthew Ranostay89385032008-09-11 09:49:39 -04003122/* labels for amp mux outputs */
3123static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003124 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003125};
3126
3127/* create amp out controls mux on capable codecs */
3128static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3129{
3130 struct sigmatel_spec *spec = codec->spec;
3131 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3132 int i, err;
3133
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003134 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003135 amp_mux->items[amp_mux->num_items].label =
3136 stac92xx_amp_labels[i];
3137 amp_mux->items[amp_mux->num_items].index = i;
3138 amp_mux->num_items++;
3139 }
3140
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003141 if (spec->num_amps > 1) {
3142 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3143 "Amp Selector Capture Switch", 0);
3144 if (err < 0)
3145 return err;
3146 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003147 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3148 "Amp Capture Volume",
3149 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3150}
3151
3152
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003153/* create PC beep volume controls */
3154static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3155 hda_nid_t nid)
3156{
3157 struct sigmatel_spec *spec = codec->spec;
3158 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3159 int err;
3160
3161 /* check for mute support for the the amp */
3162 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3163 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3164 "PC Beep Playback Switch",
3165 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3166 if (err < 0)
3167 return err;
3168 }
3169
3170 /* check to see if there is volume support for the amp */
3171 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3172 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3173 "PC Beep Playback Volume",
3174 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3175 if (err < 0)
3176 return err;
3177 }
3178 return 0;
3179}
3180
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003181#ifdef CONFIG_SND_HDA_INPUT_BEEP
3182#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3183
3184static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3185 struct snd_ctl_elem_value *ucontrol)
3186{
3187 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3188 ucontrol->value.integer.value[0] = codec->beep->enabled;
3189 return 0;
3190}
3191
3192static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3193 struct snd_ctl_elem_value *ucontrol)
3194{
3195 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3196 int enabled = !!ucontrol->value.integer.value[0];
3197 if (codec->beep->enabled != enabled) {
3198 codec->beep->enabled = enabled;
3199 return 1;
3200 }
3201 return 0;
3202}
3203
3204static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3205 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3206 .info = stac92xx_dig_beep_switch_info,
3207 .get = stac92xx_dig_beep_switch_get,
3208 .put = stac92xx_dig_beep_switch_put,
3209};
3210
3211static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3212{
3213 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3214 0, "PC Beep Playback Switch", 0);
3215}
3216#endif
3217
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003218static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3219{
3220 struct sigmatel_spec *spec = codec->spec;
3221 int wcaps, nid, i, err = 0;
3222
3223 for (i = 0; i < spec->num_muxes; i++) {
3224 nid = spec->mux_nids[i];
3225 wcaps = get_wcaps(codec, nid);
3226
3227 if (wcaps & AC_WCAP_OUT_AMP) {
3228 err = stac92xx_add_control_idx(spec,
3229 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3230 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3231 if (err < 0)
3232 return err;
3233 }
3234 }
3235 return 0;
3236};
3237
Matthew Ranostayd9737752008-09-07 12:03:41 +02003238static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003239 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003240};
3241
3242static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3243{
3244 struct sigmatel_spec *spec = codec->spec;
3245 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003246 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003247 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003248 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003249
3250 num_cons = snd_hda_get_connections(codec,
3251 spec->smux_nids[0],
3252 con_lst,
3253 HDA_MAX_NUM_INPUTS);
Matthew Ranostay65973632008-09-16 10:39:37 -04003254 if (!num_cons)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003255 return -EINVAL;
3256
Matthew Ranostay65973632008-09-16 10:39:37 -04003257 if (!labels)
3258 labels = stac92xx_spdif_labels;
3259
Matthew Ranostayd9737752008-09-07 12:03:41 +02003260 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003261 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003262 spdif_mux->items[spdif_mux->num_items].index = i;
3263 spdif_mux->num_items++;
3264 }
3265
3266 return 0;
3267}
3268
Matt Porter8b657272006-10-26 17:12:59 +02003269/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003270static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003271 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3272 "Digital Mic 3", "Digital Mic 4"
3273};
3274
3275/* create playback/capture controls for input pins on dmic capable codecs */
3276static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3277 const struct auto_pin_cfg *cfg)
3278{
3279 struct sigmatel_spec *spec = codec->spec;
3280 struct hda_input_mux *dimux = &spec->private_dimux;
3281 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003282 int err, i, j;
3283 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02003284
3285 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3286 dimux->items[dimux->num_items].index = 0;
3287 dimux->num_items++;
3288
3289 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003290 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003291 int index;
3292 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003293 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02003294 unsigned int def_conf;
3295
3296 def_conf = snd_hda_codec_read(codec,
3297 spec->dmic_nids[i],
3298 0,
3299 AC_VERB_GET_CONFIG_DEFAULT,
3300 0);
3301 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3302 continue;
3303
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003304 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02003305 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003306 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02003307 con_lst,
3308 HDA_MAX_NUM_INPUTS);
3309 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003310 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02003311 index = j;
3312 goto found;
3313 }
3314 continue;
3315found:
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003316 wcaps = get_wcaps(codec, nid) &
3317 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003318
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003319 if (wcaps) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003320 sprintf(name, "%s Capture Volume",
3321 stac92xx_dmic_labels[dimux->num_items]);
3322
3323 err = stac92xx_add_control(spec,
3324 STAC_CTL_WIDGET_VOL,
3325 name,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003326 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3327 (wcaps & AC_WCAP_OUT_AMP) ?
3328 HDA_OUTPUT : HDA_INPUT));
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003329 if (err < 0)
3330 return err;
3331 }
3332
Matt Porter8b657272006-10-26 17:12:59 +02003333 dimux->items[dimux->num_items].label =
3334 stac92xx_dmic_labels[dimux->num_items];
3335 dimux->items[dimux->num_items].index = index;
3336 dimux->num_items++;
3337 }
3338
3339 return 0;
3340}
3341
Mattc7d4b2f2005-06-27 14:59:41 +02003342/* create playback/capture controls for input pins */
3343static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3344{
3345 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003346 struct hda_input_mux *imux = &spec->private_imux;
3347 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3348 int i, j, k;
3349
3350 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003351 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02003352
Takashi Iwai314634b2006-09-21 11:56:18 +02003353 if (!cfg->input_pins[i])
3354 continue;
3355 index = -1;
3356 for (j = 0; j < spec->num_muxes; j++) {
3357 int num_cons;
3358 num_cons = snd_hda_get_connections(codec,
3359 spec->mux_nids[j],
3360 con_lst,
3361 HDA_MAX_NUM_INPUTS);
3362 for (k = 0; k < num_cons; k++)
3363 if (con_lst[k] == cfg->input_pins[i]) {
3364 index = k;
3365 goto found;
3366 }
Mattc7d4b2f2005-06-27 14:59:41 +02003367 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003368 continue;
3369 found:
3370 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3371 imux->items[imux->num_items].index = index;
3372 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003373 }
3374
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003375 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003376 /*
3377 * Set the current input for the muxes.
3378 * The STAC9221 has two input muxes with identical source
3379 * NID lists. Hopefully this won't get confused.
3380 */
3381 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003382 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3383 AC_VERB_SET_CONNECT_SEL,
3384 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003385 }
3386 }
3387
Mattc7d4b2f2005-06-27 14:59:41 +02003388 return 0;
3389}
3390
Mattc7d4b2f2005-06-27 14:59:41 +02003391static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3392{
3393 struct sigmatel_spec *spec = codec->spec;
3394 int i;
3395
3396 for (i = 0; i < spec->autocfg.line_outs; i++) {
3397 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3398 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3399 }
3400}
3401
3402static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3403{
3404 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003405 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003406
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003407 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3408 hda_nid_t pin;
3409 pin = spec->autocfg.hp_pins[i];
3410 if (pin) /* connect to front */
3411 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3412 }
3413 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3414 hda_nid_t pin;
3415 pin = spec->autocfg.speaker_pins[i];
3416 if (pin) /* connect to front */
3417 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3418 }
Mattc7d4b2f2005-06-27 14:59:41 +02003419}
3420
Matt Porter3cc08dc2006-01-23 15:27:49 +01003421static 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 +02003422{
3423 struct sigmatel_spec *spec = codec->spec;
3424 int err;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003425 int hp_speaker_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003426
Matt Porter8b657272006-10-26 17:12:59 +02003427 if ((err = snd_hda_parse_pin_def_config(codec,
3428 &spec->autocfg,
3429 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003430 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003431 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003432 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003433
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003434 /* If we have no real line-out pin and multiple hp-outs, HPs should
3435 * be set up as multi-channel outputs.
3436 */
3437 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3438 spec->autocfg.hp_outs > 1) {
3439 /* Copy hp_outs to line_outs, backup line_outs in
3440 * speaker_outs so that the following routines can handle
3441 * HP pins as primary outputs.
3442 */
3443 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3444 sizeof(spec->autocfg.line_out_pins));
3445 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3446 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3447 sizeof(spec->autocfg.hp_pins));
3448 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3449 hp_speaker_swap = 1;
3450 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003451 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003452 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3453 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003454 u32 caps = query_amp_caps(codec,
3455 spec->autocfg.mono_out_pin, dir);
3456 hda_nid_t conn_list[1];
3457
3458 /* get the mixer node and then the mono mux if it exists */
3459 if (snd_hda_get_connections(codec,
3460 spec->autocfg.mono_out_pin, conn_list, 1) &&
3461 snd_hda_get_connections(codec, conn_list[0],
3462 conn_list, 1)) {
3463
3464 int wcaps = get_wcaps(codec, conn_list[0]);
3465 int wid_type = (wcaps & AC_WCAP_TYPE)
3466 >> AC_WCAP_TYPE_SHIFT;
3467 /* LR swap check, some stac925x have a mux that
3468 * changes the DACs output path instead of the
3469 * mono-mux path.
3470 */
3471 if (wid_type == AC_WID_AUD_SEL &&
3472 !(wcaps & AC_WCAP_LR_SWAP))
3473 spec->mono_nid = conn_list[0];
3474 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003475 if (dir) {
3476 hda_nid_t nid = spec->autocfg.mono_out_pin;
3477
3478 /* most mono outs have a least a mute/unmute switch */
3479 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3480 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3481 "Mono Playback Switch",
3482 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003483 if (err < 0)
3484 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003485 /* check for volume support for the amp */
3486 if ((caps & AC_AMPCAP_NUM_STEPS)
3487 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3488 err = stac92xx_add_control(spec,
3489 STAC_CTL_WIDGET_VOL,
3490 "Mono Playback Volume",
3491 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3492 if (err < 0)
3493 return err;
3494 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003495 }
3496
3497 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3498 AC_PINCTL_OUT_EN);
3499 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003500
Matt Porter403d1942005-11-29 15:00:51 +01003501 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
3502 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003503 if (spec->multiout.num_dacs == 0)
3504 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3505 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003506
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003507 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
3508
3509 if (err < 0)
3510 return err;
3511
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003512 /* setup analog beep controls */
3513 if (spec->anabeep_nid > 0) {
3514 err = stac92xx_auto_create_beep_ctls(codec,
3515 spec->anabeep_nid);
3516 if (err < 0)
3517 return err;
3518 }
3519
3520 /* setup digital beep controls and input device */
3521#ifdef CONFIG_SND_HDA_INPUT_BEEP
3522 if (spec->digbeep_nid > 0) {
3523 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003524 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003525
3526 err = stac92xx_auto_create_beep_ctls(codec, nid);
3527 if (err < 0)
3528 return err;
3529 err = snd_hda_attach_beep_device(codec, nid);
3530 if (err < 0)
3531 return err;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003532 /* if no beep switch is available, make its own one */
3533 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3534 if (codec->beep &&
3535 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3536 err = stac92xx_beep_switch_ctl(codec);
3537 if (err < 0)
3538 return err;
3539 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003540 }
3541#endif
3542
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003543 if (hp_speaker_swap == 1) {
3544 /* Restore the hp_outs and line_outs */
3545 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3546 sizeof(spec->autocfg.line_out_pins));
3547 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3548 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
3549 sizeof(spec->autocfg.speaker_pins));
3550 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
3551 memset(spec->autocfg.speaker_pins, 0,
3552 sizeof(spec->autocfg.speaker_pins));
3553 spec->autocfg.speaker_outs = 0;
3554 }
3555
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003556 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3557
3558 if (err < 0)
3559 return err;
3560
3561 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3562
3563 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003564 return err;
3565
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003566 if (spec->mono_nid > 0) {
3567 err = stac92xx_auto_create_mono_output_ctls(codec);
3568 if (err < 0)
3569 return err;
3570 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003571 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003572 err = stac92xx_auto_create_amp_output_ctls(codec);
3573 if (err < 0)
3574 return err;
3575 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003576 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003577 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3578 &spec->autocfg)) < 0)
3579 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003580 if (spec->num_muxes > 0) {
3581 err = stac92xx_auto_create_mux_input_ctls(codec);
3582 if (err < 0)
3583 return err;
3584 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003585 if (spec->num_smuxes > 0) {
3586 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3587 if (err < 0)
3588 return err;
3589 }
Matt Porter8b657272006-10-26 17:12:59 +02003590
Mattc7d4b2f2005-06-27 14:59:41 +02003591 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003592 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003593 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003594
Takashi Iwai82bc9552006-03-21 11:24:42 +01003595 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003596 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003597 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003598 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003599
Takashi Iwai603c4012008-07-30 15:01:44 +02003600 if (spec->kctls.list)
3601 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003602
3603 spec->input_mux = &spec->private_imux;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003604 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003605 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003606 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04003607 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003608 return 1;
3609}
3610
Takashi Iwai82bc9552006-03-21 11:24:42 +01003611/* add playback controls for HP output */
3612static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3613 struct auto_pin_cfg *cfg)
3614{
3615 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003616 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003617 unsigned int wid_caps;
3618
3619 if (! pin)
3620 return 0;
3621
3622 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003623 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003624 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003625
3626 return 0;
3627}
3628
Richard Fish160ea0d2006-09-06 13:58:25 +02003629/* add playback controls for LFE output */
3630static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3631 struct auto_pin_cfg *cfg)
3632{
3633 struct sigmatel_spec *spec = codec->spec;
3634 int err;
3635 hda_nid_t lfe_pin = 0x0;
3636 int i;
3637
3638 /*
3639 * search speaker outs and line outs for a mono speaker pin
3640 * with an amp. If one is found, add LFE controls
3641 * for it.
3642 */
3643 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3644 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003645 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003646 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3647 if (wcaps == AC_WCAP_OUT_AMP)
3648 /* found a mono speaker with an amp, must be lfe */
3649 lfe_pin = pin;
3650 }
3651
3652 /* if speaker_outs is 0, then speakers may be in line_outs */
3653 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3654 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3655 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003656 unsigned int defcfg;
Harvey Harrison8b551782008-02-29 11:56:48 +01003657 defcfg = snd_hda_codec_read(codec, pin, 0,
Richard Fish160ea0d2006-09-06 13:58:25 +02003658 AC_VERB_GET_CONFIG_DEFAULT,
3659 0x00);
Harvey Harrison8b551782008-02-29 11:56:48 +01003660 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003661 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003662 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3663 if (wcaps == AC_WCAP_OUT_AMP)
3664 /* found a mono speaker with an amp,
3665 must be lfe */
3666 lfe_pin = pin;
3667 }
3668 }
3669 }
3670
3671 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003672 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003673 if (err < 0)
3674 return err;
3675 }
3676
3677 return 0;
3678}
3679
Mattc7d4b2f2005-06-27 14:59:41 +02003680static int stac9200_parse_auto_config(struct hda_codec *codec)
3681{
3682 struct sigmatel_spec *spec = codec->spec;
3683 int err;
3684
Kailang Yangdf694da2005-12-05 19:42:22 +01003685 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003686 return err;
3687
3688 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3689 return err;
3690
Takashi Iwai82bc9552006-03-21 11:24:42 +01003691 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3692 return err;
3693
Richard Fish160ea0d2006-09-06 13:58:25 +02003694 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3695 return err;
3696
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003697 if (spec->num_muxes > 0) {
3698 err = stac92xx_auto_create_mux_input_ctls(codec);
3699 if (err < 0)
3700 return err;
3701 }
3702
Takashi Iwai82bc9552006-03-21 11:24:42 +01003703 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003704 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003705 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003706 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003707
Takashi Iwai603c4012008-07-30 15:01:44 +02003708 if (spec->kctls.list)
3709 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003710
3711 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003712 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003713
3714 return 1;
3715}
3716
Sam Revitch62fe78e2006-05-10 15:09:17 +02003717/*
3718 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3719 * funky external mute control using GPIO pins.
3720 */
3721
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003722static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003723 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003724{
3725 unsigned int gpiostate, gpiomask, gpiodir;
3726
3727 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3728 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003729 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003730
3731 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3732 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003733 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003734
3735 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3736 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003737 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003738
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003739 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003740 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3741
3742 snd_hda_codec_write(codec, codec->afg, 0,
3743 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003744 snd_hda_codec_read(codec, codec->afg, 0,
3745 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003746
3747 msleep(1);
3748
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003749 snd_hda_codec_read(codec, codec->afg, 0,
3750 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003751}
3752
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003753static int stac92xx_add_jack(struct hda_codec *codec,
3754 hda_nid_t nid, int type)
3755{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003756#ifdef CONFIG_SND_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003757 struct sigmatel_spec *spec = codec->spec;
3758 struct sigmatel_jack *jack;
3759 int def_conf = snd_hda_codec_read(codec, nid,
3760 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
3761 int connectivity = get_defcfg_connect(def_conf);
3762 char name[32];
3763
3764 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3765 return 0;
3766
3767 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3768 jack = snd_array_new(&spec->jacks);
3769 if (!jack)
3770 return -ENOMEM;
3771 jack->nid = nid;
3772 jack->type = type;
3773
3774 sprintf(name, "%s at %s %s Jack",
3775 snd_hda_get_jack_type(def_conf),
3776 snd_hda_get_jack_connectivity(def_conf),
3777 snd_hda_get_jack_location(def_conf));
3778
3779 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003780#else
3781 return 0;
3782#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003783}
3784
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003785static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3786 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003787{
3788 struct sigmatel_event *event;
3789
3790 snd_array_init(&spec->events, sizeof(*event), 32);
3791 event = snd_array_new(&spec->events);
3792 if (!event)
3793 return -ENOMEM;
3794 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003795 event->type = type;
3796 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003797 event->data = data;
3798
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003799 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003800}
3801
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003802static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
3803 hda_nid_t nid, unsigned char type)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003804{
3805 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003806 struct sigmatel_event *event = spec->events.list;
3807 int i;
3808
3809 for (i = 0; i < spec->events.used; i++, event++) {
3810 if (event->nid == nid && event->type == type)
3811 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003812 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003813 return NULL;
3814}
3815
3816static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
3817 unsigned char tag)
3818{
3819 struct sigmatel_spec *spec = codec->spec;
3820 struct sigmatel_event *event = spec->events.list;
3821 int i;
3822
3823 for (i = 0; i < spec->events.used; i++, event++) {
3824 if (event->tag == tag)
3825 return event;
3826 }
3827 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003828}
3829
Takashi Iwai314634b2006-09-21 11:56:18 +02003830static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003831 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02003832{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003833 struct sigmatel_event *event;
3834 int tag;
3835
3836 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
3837 return;
3838 event = stac_get_event(codec, nid, type);
3839 if (event)
3840 tag = event->tag;
3841 else
3842 tag = stac_add_event(codec->spec, nid, type, 0);
3843 if (tag < 0)
3844 return;
3845 snd_hda_codec_write_cache(codec, nid, 0,
3846 AC_VERB_SET_UNSOLICITED_ENABLE,
3847 AC_USRSP_EN | tag);
Takashi Iwai314634b2006-09-21 11:56:18 +02003848}
3849
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003850static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3851{
3852 int i;
3853 for (i = 0; i < cfg->hp_outs; i++)
3854 if (cfg->hp_pins[i] == nid)
3855 return 1; /* nid is a HP-Out */
3856
3857 return 0; /* nid is not a HP-Out */
3858};
3859
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003860static void stac92xx_power_down(struct hda_codec *codec)
3861{
3862 struct sigmatel_spec *spec = codec->spec;
3863
3864 /* power down inactive DACs */
3865 hda_nid_t *dac;
3866 for (dac = spec->dac_list; *dac; dac++)
Matthew Ranostay44510892008-02-21 07:49:31 +01003867 if (!is_in_dac_nids(spec, *dac) &&
3868 spec->multiout.hp_nid != *dac)
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003869 snd_hda_codec_write_cache(codec, *dac, 0,
3870 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3871}
3872
Takashi Iwaif73d3582008-11-25 08:21:51 +01003873static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3874 int enable);
3875
Mattc7d4b2f2005-06-27 14:59:41 +02003876static int stac92xx_init(struct hda_codec *codec)
3877{
3878 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003879 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01003880 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01003881 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003882
Mattc7d4b2f2005-06-27 14:59:41 +02003883 snd_hda_sequence_write(codec, spec->init);
3884
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02003885 /* power down adcs initially */
3886 if (spec->powerdown_adcs)
3887 for (i = 0; i < spec->num_adcs; i++)
3888 snd_hda_codec_write_cache(codec,
3889 spec->adc_nids[i], 0,
3890 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003891
3892 /* set up GPIO */
3893 gpio = spec->gpio_data;
3894 /* turn on EAPD statically when spec->eapd_switch isn't set.
3895 * otherwise, unsol event will turn it on/off dynamically
3896 */
3897 if (!spec->eapd_switch)
3898 gpio |= spec->eapd_mask;
3899 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
3900
Takashi Iwai82bc9552006-03-21 11:24:42 +01003901 /* set up pins */
3902 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02003903 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003904 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003905 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003906 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003907 }
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01003908 /* force to enable the first line-out; the others are set up
3909 * in unsol_event
3910 */
3911 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003912 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003913 /* fake event to set up pins */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003914 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
3915 STAC_HP_EVENT);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003916 } else {
3917 stac92xx_auto_init_multi_out(codec);
3918 stac92xx_auto_init_hp_out(codec);
3919 }
3920 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01003921 hda_nid_t nid = cfg->input_pins[i];
3922 if (nid) {
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01003923 unsigned int pinctl;
3924 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
3925 /* for mic pins, force to initialize */
3926 pinctl = stac92xx_get_vref(codec, nid);
3927 } else {
3928 pinctl = snd_hda_codec_read(codec, nid, 0,
3929 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3930 /* if PINCTL already set then skip */
3931 if (pinctl & AC_PINCTL_IN_EN)
3932 continue;
3933 }
3934 pinctl |= AC_PINCTL_IN_EN;
Takashi Iwaic960a032006-03-23 17:06:28 +01003935 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003936 enable_pin_detect(codec, nid, STAC_INSERT_EVENT);
Takashi Iwaic960a032006-03-23 17:06:28 +01003937 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01003938 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003939 for (i = 0; i < spec->num_dmics; i++)
3940 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
3941 AC_PINCTL_IN_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003942 if (cfg->dig_out_pin)
3943 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
3944 AC_PINCTL_OUT_EN);
3945 if (cfg->dig_in_pin)
3946 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
3947 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003948 for (i = 0; i < spec->num_pwrs; i++) {
3949 hda_nid_t nid = spec->pwr_nids[i];
3950 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003951
Takashi Iwaif73d3582008-11-25 08:21:51 +01003952 if (is_nid_hp_pin(cfg, nid) && spec->hp_detect)
3953 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003954
Takashi Iwaif73d3582008-11-25 08:21:51 +01003955 pinctl = snd_hda_codec_read(codec, nid, 0,
3956 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3957 /* outputs are only ports capable of power management
3958 * any attempts on powering down a input port cause the
3959 * referenced VREF to act quirky.
3960 */
3961 if (pinctl & AC_PINCTL_IN_EN)
3962 continue;
3963 def_conf = snd_hda_codec_read(codec, nid, 0,
3964 AC_VERB_GET_CONFIG_DEFAULT, 0);
3965 def_conf = get_defcfg_connect(def_conf);
3966 /* skip any ports that don't have jacks since presence
3967 * detection is useless */
3968 if (def_conf != AC_JACK_PORT_COMPLEX) {
3969 if (def_conf != AC_JACK_PORT_NONE)
3970 stac_toggle_power_map(codec, nid, 1);
3971 continue;
3972 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003973 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
3974 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003975 }
3976 if (spec->dac_list)
3977 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02003978 return 0;
3979}
3980
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003981static void stac92xx_free_jacks(struct hda_codec *codec)
3982{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003983#ifdef CONFIG_SND_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01003984 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003985 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01003986 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003987 struct sigmatel_jack *jacks = spec->jacks.list;
3988 int i;
3989 for (i = 0; i < spec->jacks.used; i++)
3990 snd_device_free(codec->bus->card, &jacks[i].jack);
3991 }
3992 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003993#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003994}
3995
Takashi Iwai603c4012008-07-30 15:01:44 +02003996static void stac92xx_free_kctls(struct hda_codec *codec)
3997{
3998 struct sigmatel_spec *spec = codec->spec;
3999
4000 if (spec->kctls.list) {
4001 struct snd_kcontrol_new *kctl = spec->kctls.list;
4002 int i;
4003 for (i = 0; i < spec->kctls.used; i++)
4004 kfree(kctl[i].name);
4005 }
4006 snd_array_free(&spec->kctls);
4007}
4008
Matt2f2f4252005-04-13 14:45:30 +02004009static void stac92xx_free(struct hda_codec *codec)
4010{
Mattc7d4b2f2005-06-27 14:59:41 +02004011 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004012
4013 if (! spec)
4014 return;
4015
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004016 kfree(spec->pin_configs);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004017 stac92xx_free_jacks(codec);
4018 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004019
Mattc7d4b2f2005-06-27 14:59:41 +02004020 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004021 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004022}
4023
Matt4e550962005-07-04 17:51:39 +02004024static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4025 unsigned int flag)
4026{
4027 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4028 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004029
Takashi Iwaif9acba42007-05-29 18:01:06 +02004030 if (pin_ctl & AC_PINCTL_IN_EN) {
4031 /*
4032 * we need to check the current set-up direction of
4033 * shared input pins since they can be switched via
4034 * "xxx as Output" mixer switch
4035 */
4036 struct sigmatel_spec *spec = codec->spec;
4037 struct auto_pin_cfg *cfg = &spec->autocfg;
4038 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
4039 spec->line_switch) ||
4040 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
4041 spec->mic_switch))
4042 return;
4043 }
4044
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004045 /* if setting pin direction bits, clear the current
4046 direction bits first */
4047 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4048 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4049
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004050 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02004051 AC_VERB_SET_PIN_WIDGET_CONTROL,
4052 pin_ctl | flag);
4053}
4054
4055static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4056 unsigned int flag)
4057{
4058 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4059 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004060 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02004061 AC_VERB_SET_PIN_WIDGET_CONTROL,
4062 pin_ctl & ~flag);
4063}
4064
Jiang Zhe40c1d302007-11-12 13:05:16 +01004065static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004066{
4067 if (!nid)
4068 return 0;
4069 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Jiang Zhe40c1d302007-11-12 13:05:16 +01004070 & (1 << 31)) {
4071 unsigned int pinctl;
4072 pinctl = snd_hda_codec_read(codec, nid, 0,
4073 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4074 if (pinctl & AC_PINCTL_IN_EN)
4075 return 0; /* mic- or line-input */
4076 else
4077 return 1; /* HP-output */
4078 }
Takashi Iwai314634b2006-09-21 11:56:18 +02004079 return 0;
4080}
4081
Takashi Iwaid7a89432008-11-12 09:48:04 +01004082/* return non-zero if the hp-pin of the given array index isn't
4083 * a jack-detection target
4084 */
4085static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4086{
4087 struct auto_pin_cfg *cfg = &spec->autocfg;
4088
4089 /* ignore sensing of shared line and mic jacks */
4090 if (spec->line_switch &&
4091 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_LINE])
4092 return 1;
4093 if (spec->mic_switch &&
4094 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_MIC])
4095 return 1;
4096 /* ignore if the pin is set as line-out */
4097 if (cfg->hp_pins[i] == spec->hp_switch)
4098 return 1;
4099 return 0;
4100}
4101
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004102static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004103{
4104 struct sigmatel_spec *spec = codec->spec;
4105 struct auto_pin_cfg *cfg = &spec->autocfg;
4106 int i, presence;
4107
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004108 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004109 if (spec->gpio_mute)
4110 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4111 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4112
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004113 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004114 if (presence)
4115 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004116 if (no_hp_sensing(spec, i))
4117 continue;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004118 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004119 }
Matt4e550962005-07-04 17:51:39 +02004120
4121 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004122 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004123 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004124 stac92xx_reset_pinctl(codec, spec->hp_switch,
4125 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004126 for (i = 0; i < cfg->line_outs; i++)
4127 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4128 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004129 for (i = 0; i < cfg->speaker_outs; i++)
4130 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4131 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004132 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004133 stac_gpio_set(codec, spec->gpio_mask,
4134 spec->gpio_dir, spec->gpio_data &
4135 ~spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004136 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004137 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004138 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004139 stac92xx_set_pinctl(codec, spec->hp_switch,
4140 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004141 for (i = 0; i < cfg->line_outs; i++)
4142 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4143 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004144 for (i = 0; i < cfg->speaker_outs; i++)
4145 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4146 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004147 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004148 stac_gpio_set(codec, spec->gpio_mask,
4149 spec->gpio_dir, spec->gpio_data |
4150 spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004151 }
Takashi Iwaid7a89432008-11-12 09:48:04 +01004152 /* toggle hp outs */
4153 for (i = 0; i < cfg->hp_outs; i++) {
4154 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4155 if (no_hp_sensing(spec, i))
4156 continue;
4157 if (presence)
4158 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4159 else
4160 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4161 }
Matt4e550962005-07-04 17:51:39 +02004162}
4163
Takashi Iwaif73d3582008-11-25 08:21:51 +01004164static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4165 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004166{
4167 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004168 unsigned int idx, val;
4169
4170 for (idx = 0; idx < spec->num_pwrs; idx++) {
4171 if (spec->pwr_nids[idx] == nid)
4172 break;
4173 }
4174 if (idx >= spec->num_pwrs)
4175 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004176
4177 /* several codecs have two power down bits */
4178 if (spec->pwr_mapping)
4179 idx = spec->pwr_mapping[idx];
4180 else
4181 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004182
Takashi Iwaif73d3582008-11-25 08:21:51 +01004183 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4184 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004185 val &= ~idx;
4186 else
4187 val |= idx;
4188
4189 /* power down unused output ports */
4190 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004191}
4192
Takashi Iwaif73d3582008-11-25 08:21:51 +01004193static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4194{
4195 stac_toggle_power_map(codec, nid, get_hp_pin_presence(codec, nid));
4196}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004197
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004198static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4199{
4200 struct sigmatel_spec *spec = codec->spec;
4201 struct sigmatel_jack *jacks = spec->jacks.list;
4202
4203 if (jacks) {
4204 int i;
4205 for (i = 0; i < spec->jacks.used; i++) {
4206 if (jacks->nid == nid) {
4207 unsigned int pin_ctl =
4208 snd_hda_codec_read(codec, nid,
4209 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4210 0x00);
4211 int type = jacks->type;
4212 if (type == (SND_JACK_LINEOUT
4213 | SND_JACK_HEADPHONE))
4214 type = (pin_ctl & AC_PINCTL_HP_EN)
4215 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4216 snd_jack_report(jacks->jack,
4217 get_hp_pin_presence(codec, nid)
4218 ? type : 0);
4219 }
4220 jacks++;
4221 }
4222 }
4223}
Matt2f2f4252005-04-13 14:45:30 +02004224
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004225static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4226 unsigned char type)
4227{
4228 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4229 if (!event)
4230 return;
4231 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4232}
4233
Takashi Iwai314634b2006-09-21 11:56:18 +02004234static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4235{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004236 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004237 struct sigmatel_event *event;
4238 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004239
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004240 tag = (res >> 26) & 0x7f;
4241 event = stac_get_event_from_tag(codec, tag);
4242 if (!event)
4243 return;
4244
4245 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004246 case STAC_HP_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004247 stac92xx_hp_detect(codec);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004248 /* fallthru */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004249 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004250 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004251 if (spec->num_pwrs > 0)
4252 stac92xx_pin_sense(codec, event->nid);
4253 stac92xx_report_jack(codec, event->nid);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004254 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004255 case STAC_VREF_EVENT:
4256 data = snd_hda_codec_read(codec, codec->afg, 0,
4257 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004258 /* toggle VREF state based on GPIOx status */
4259 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004260 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004261 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004262 }
4263}
4264
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004265#ifdef CONFIG_PROC_FS
4266static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4267 struct hda_codec *codec, hda_nid_t nid)
4268{
4269 if (nid == codec->afg)
4270 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4271 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4272}
4273
4274static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4275 struct hda_codec *codec,
4276 unsigned int verb)
4277{
4278 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4279 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4280}
4281
4282/* stac92hd71bxx, stac92hd73xx */
4283static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4284 struct hda_codec *codec, hda_nid_t nid)
4285{
4286 stac92hd_proc_hook(buffer, codec, nid);
4287 if (nid == codec->afg)
4288 analog_loop_proc_hook(buffer, codec, 0xfa0);
4289}
4290
4291static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4292 struct hda_codec *codec, hda_nid_t nid)
4293{
4294 if (nid == codec->afg)
4295 analog_loop_proc_hook(buffer, codec, 0xfe0);
4296}
4297
4298static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4299 struct hda_codec *codec, hda_nid_t nid)
4300{
4301 if (nid == codec->afg)
4302 analog_loop_proc_hook(buffer, codec, 0xfeb);
4303}
4304#else
4305#define stac92hd_proc_hook NULL
4306#define stac92hd7x_proc_hook NULL
4307#define stac9205_proc_hook NULL
4308#define stac927x_proc_hook NULL
4309#endif
4310
Takashi Iwaicb53c622007-08-10 17:21:45 +02004311#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004312static int stac92xx_resume(struct hda_codec *codec)
4313{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004314 struct sigmatel_spec *spec = codec->spec;
4315
Richard Fish11b44bb2006-08-23 18:31:34 +02004316 stac92xx_set_config_regs(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004317 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004318 snd_hda_codec_resume_amp(codec);
4319 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004320 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004321 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004322 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4323 STAC_HP_EVENT);
Mattff6fdc32005-06-27 15:06:52 +02004324 return 0;
4325}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004326
4327static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4328{
4329 struct sigmatel_spec *spec = codec->spec;
4330 if (spec->eapd_mask)
4331 stac_gpio_set(codec, spec->gpio_mask,
4332 spec->gpio_dir, spec->gpio_data &
4333 ~spec->eapd_mask);
4334 return 0;
4335}
Mattff6fdc32005-06-27 15:06:52 +02004336#endif
4337
Matt2f2f4252005-04-13 14:45:30 +02004338static struct hda_codec_ops stac92xx_patch_ops = {
4339 .build_controls = stac92xx_build_controls,
4340 .build_pcms = stac92xx_build_pcms,
4341 .init = stac92xx_init,
4342 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004343 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004344#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004345 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004346 .resume = stac92xx_resume,
4347#endif
Matt2f2f4252005-04-13 14:45:30 +02004348};
4349
4350static int patch_stac9200(struct hda_codec *codec)
4351{
4352 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004353 int err;
Matt2f2f4252005-04-13 14:45:30 +02004354
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004355 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004356 if (spec == NULL)
4357 return -ENOMEM;
4358
4359 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004360 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004361 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004362 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4363 stac9200_models,
4364 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02004365 if (spec->board_config < 0) {
4366 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4367 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004368 } else
4369 err = stac_save_pin_cfgs(codec,
4370 stac9200_brd_tbl[spec->board_config]);
4371 if (err < 0) {
4372 stac92xx_free(codec);
4373 return err;
Matt Porter403d1942005-11-29 15:00:51 +01004374 }
Matt2f2f4252005-04-13 14:45:30 +02004375
4376 spec->multiout.max_channels = 2;
4377 spec->multiout.num_dacs = 1;
4378 spec->multiout.dac_nids = stac9200_dac_nids;
4379 spec->adc_nids = stac9200_adc_nids;
4380 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004381 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004382 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004383 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004384 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004385
Tobin Davisbf277782008-02-03 20:31:47 +01004386 if (spec->board_config == STAC_9200_GATEWAY ||
4387 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004388 spec->init = stac9200_eapd_init;
4389 else
4390 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004391 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004392
Takashi Iwai117f2572008-03-18 09:53:23 +01004393 if (spec->board_config == STAC_9200_PANASONIC) {
4394 spec->gpio_mask = spec->gpio_dir = 0x09;
4395 spec->gpio_data = 0x00;
4396 }
4397
Mattc7d4b2f2005-06-27 14:59:41 +02004398 err = stac9200_parse_auto_config(codec);
4399 if (err < 0) {
4400 stac92xx_free(codec);
4401 return err;
4402 }
Matt2f2f4252005-04-13 14:45:30 +02004403
4404 codec->patch_ops = stac92xx_patch_ops;
4405
4406 return 0;
4407}
4408
Tobin Davis8e21c342007-01-08 11:04:17 +01004409static int patch_stac925x(struct hda_codec *codec)
4410{
4411 struct sigmatel_spec *spec;
4412 int err;
4413
4414 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4415 if (spec == NULL)
4416 return -ENOMEM;
4417
4418 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004419 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004420 spec->pin_nids = stac925x_pin_nids;
4421 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
4422 stac925x_models,
4423 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004424 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01004425 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02004426 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
4427 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01004428 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004429 } else
4430 err = stac_save_pin_cfgs(codec,
4431 stac925x_brd_tbl[spec->board_config]);
4432 if (err < 0) {
4433 stac92xx_free(codec);
4434 return err;
Tobin Davis8e21c342007-01-08 11:04:17 +01004435 }
4436
4437 spec->multiout.max_channels = 2;
4438 spec->multiout.num_dacs = 1;
4439 spec->multiout.dac_nids = stac925x_dac_nids;
4440 spec->adc_nids = stac925x_adc_nids;
4441 spec->mux_nids = stac925x_mux_nids;
4442 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004443 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004444 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004445 switch (codec->vendor_id) {
4446 case 0x83847632: /* STAC9202 */
4447 case 0x83847633: /* STAC9202D */
4448 case 0x83847636: /* STAC9251 */
4449 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004450 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004451 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004452 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4453 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004454 break;
4455 default:
4456 spec->num_dmics = 0;
4457 break;
4458 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004459
4460 spec->init = stac925x_core_init;
4461 spec->mixer = stac925x_mixer;
4462
4463 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004464 if (!err) {
4465 if (spec->board_config < 0) {
4466 printk(KERN_WARNING "hda_codec: No auto-config is "
4467 "available, default to model=ref\n");
4468 spec->board_config = STAC_925x_REF;
4469 goto again;
4470 }
4471 err = -EINVAL;
4472 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004473 if (err < 0) {
4474 stac92xx_free(codec);
4475 return err;
4476 }
4477
4478 codec->patch_ops = stac92xx_patch_ops;
4479
4480 return 0;
4481}
4482
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004483static struct hda_input_mux stac92hd73xx_dmux = {
4484 .num_items = 4,
4485 .items = {
4486 { "Analog Inputs", 0x0b },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004487 { "Digital Mic 1", 0x09 },
4488 { "Digital Mic 2", 0x0a },
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004489 { "CD", 0x08 },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004490 }
4491};
4492
4493static int patch_stac92hd73xx(struct hda_codec *codec)
4494{
4495 struct sigmatel_spec *spec;
4496 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4497 int err = 0;
4498
4499 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4500 if (spec == NULL)
4501 return -ENOMEM;
4502
4503 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004504 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004505 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4506 spec->pin_nids = stac92hd73xx_pin_nids;
4507 spec->board_config = snd_hda_check_board_config(codec,
4508 STAC_92HD73XX_MODELS,
4509 stac92hd73xx_models,
4510 stac92hd73xx_cfg_tbl);
4511again:
4512 if (spec->board_config < 0) {
4513 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4514 " STAC92HD73XX, using BIOS defaults\n");
4515 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004516 } else
4517 err = stac_save_pin_cfgs(codec,
4518 stac92hd73xx_brd_tbl[spec->board_config]);
4519 if (err < 0) {
4520 stac92xx_free(codec);
4521 return err;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004522 }
4523
4524 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
4525 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4526
4527 if (spec->multiout.num_dacs < 0) {
4528 printk(KERN_WARNING "hda_codec: Could not determine "
4529 "number of channels defaulting to DAC count\n");
4530 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
4531 }
4532
4533 switch (spec->multiout.num_dacs) {
4534 case 0x3: /* 6 Channel */
4535 spec->mixer = stac92hd73xx_6ch_mixer;
4536 spec->init = stac92hd73xx_6ch_core_init;
4537 break;
4538 case 0x4: /* 8 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004539 spec->mixer = stac92hd73xx_8ch_mixer;
4540 spec->init = stac92hd73xx_8ch_core_init;
4541 break;
4542 case 0x5: /* 10 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004543 spec->mixer = stac92hd73xx_10ch_mixer;
4544 spec->init = stac92hd73xx_10ch_core_init;
4545 };
4546
4547 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
4548 spec->aloopback_mask = 0x01;
4549 spec->aloopback_shift = 8;
4550
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004551 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004552 spec->mux_nids = stac92hd73xx_mux_nids;
4553 spec->adc_nids = stac92hd73xx_adc_nids;
4554 spec->dmic_nids = stac92hd73xx_dmic_nids;
4555 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004556 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04004557 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004558 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004559
4560 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4561 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01004562 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004563 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4564 sizeof(stac92hd73xx_dmux));
4565
Matthew Ranostaya7662642008-02-21 07:51:14 +01004566 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004567 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004568 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004569 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004570 case STAC_DELL_M6_AMIC:
4571 case STAC_DELL_M6_DMIC:
4572 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004573 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004574 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4575 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004576 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004577 spec->num_amps = 1;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004578
4579 if (!spec->init)
4580 spec->init = dell_m6_core_init;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004581 switch (spec->board_config) {
4582 case STAC_DELL_M6_AMIC: /* Analog Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004583 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4584 spec->num_dmics = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004585 spec->private_dimux.num_items = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004586 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004587 case STAC_DELL_M6_DMIC: /* Digital Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004588 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4589 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004590 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004591 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004592 case STAC_DELL_M6_BOTH: /* Both */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004593 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4594 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4595 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004596 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004597 break;
4598 }
4599 break;
4600 default:
4601 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004602 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004603 spec->eapd_switch = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004604 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04004605 if (spec->board_config > STAC_92HD73XX_REF) {
4606 /* GPIO0 High = Enable EAPD */
4607 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4608 spec->gpio_data = 0x01;
4609 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004610 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004611
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004612 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4613 spec->pwr_nids = stac92hd73xx_pwr_nids;
4614
Matthew Ranostayd9737752008-09-07 12:03:41 +02004615 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004616
4617 if (!err) {
4618 if (spec->board_config < 0) {
4619 printk(KERN_WARNING "hda_codec: No auto-config is "
4620 "available, default to model=ref\n");
4621 spec->board_config = STAC_92HD73XX_REF;
4622 goto again;
4623 }
4624 err = -EINVAL;
4625 }
4626
4627 if (err < 0) {
4628 stac92xx_free(codec);
4629 return err;
4630 }
4631
4632 codec->patch_ops = stac92xx_patch_ops;
4633
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004634 codec->proc_widget_hook = stac92hd7x_proc_hook;
4635
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004636 return 0;
4637}
4638
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004639static struct hda_input_mux stac92hd83xxx_dmux = {
4640 .num_items = 3,
4641 .items = {
4642 { "Analog Inputs", 0x03 },
4643 { "Digital Mic 1", 0x04 },
4644 { "Digital Mic 2", 0x05 },
4645 }
4646};
4647
4648static int patch_stac92hd83xxx(struct hda_codec *codec)
4649{
4650 struct sigmatel_spec *spec;
4651 int err;
4652
4653 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4654 if (spec == NULL)
4655 return -ENOMEM;
4656
4657 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004658 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004659 spec->mono_nid = 0x19;
4660 spec->digbeep_nid = 0x21;
4661 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4662 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4663 spec->adc_nids = stac92hd83xxx_adc_nids;
4664 spec->pwr_nids = stac92hd83xxx_pwr_nids;
4665 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4666 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
4667 spec->multiout.dac_nids = stac92hd83xxx_dac_nids;
4668
4669 spec->init = stac92hd83xxx_core_init;
4670 switch (codec->vendor_id) {
4671 case 0x111d7605:
4672 spec->multiout.num_dacs = STAC92HD81_DAC_COUNT;
4673 break;
4674 default:
4675 spec->num_pwrs--;
4676 spec->init++; /* switch to config #2 */
4677 spec->multiout.num_dacs = STAC92HD83_DAC_COUNT;
4678 }
4679
4680 spec->mixer = stac92hd83xxx_mixer;
4681 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4682 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4683 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
4684 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4685 spec->dinput_mux = &stac92hd83xxx_dmux;
4686 spec->pin_nids = stac92hd83xxx_pin_nids;
4687 spec->board_config = snd_hda_check_board_config(codec,
4688 STAC_92HD83XXX_MODELS,
4689 stac92hd83xxx_models,
4690 stac92hd83xxx_cfg_tbl);
4691again:
4692 if (spec->board_config < 0) {
4693 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4694 " STAC92HD83XXX, using BIOS defaults\n");
4695 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004696 } else
4697 err = stac_save_pin_cfgs(codec,
4698 stac92hd83xxx_brd_tbl[spec->board_config]);
4699 if (err < 0) {
4700 stac92xx_free(codec);
4701 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004702 }
4703
4704 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4705 if (!err) {
4706 if (spec->board_config < 0) {
4707 printk(KERN_WARNING "hda_codec: No auto-config is "
4708 "available, default to model=ref\n");
4709 spec->board_config = STAC_92HD83XXX_REF;
4710 goto again;
4711 }
4712 err = -EINVAL;
4713 }
4714
4715 if (err < 0) {
4716 stac92xx_free(codec);
4717 return err;
4718 }
4719
4720 codec->patch_ops = stac92xx_patch_ops;
4721
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004722 codec->proc_widget_hook = stac92hd_proc_hook;
4723
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004724 return 0;
4725}
4726
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004727#ifdef SND_HDA_NEEDS_RESUME
4728static void stac92hd71xx_set_power_state(struct hda_codec *codec, int pwr)
4729{
4730 struct sigmatel_spec *spec = codec->spec;
4731 int i;
4732 snd_hda_codec_write_cache(codec, codec->afg, 0,
4733 AC_VERB_SET_POWER_STATE, pwr);
4734
4735 msleep(1);
4736 for (i = 0; i < spec->num_adcs; i++) {
4737 snd_hda_codec_write_cache(codec,
4738 spec->adc_nids[i], 0,
4739 AC_VERB_SET_POWER_STATE, pwr);
4740 }
4741};
4742
4743static int stac92hd71xx_resume(struct hda_codec *codec)
4744{
4745 stac92hd71xx_set_power_state(codec, AC_PWRST_D0);
4746 return stac92xx_resume(codec);
4747}
4748
4749static int stac92hd71xx_suspend(struct hda_codec *codec, pm_message_t state)
4750{
4751 stac92hd71xx_set_power_state(codec, AC_PWRST_D3);
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004752 return stac92xx_suspend(codec, state);
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004753};
4754
4755#endif
4756
4757static struct hda_codec_ops stac92hd71bxx_patch_ops = {
4758 .build_controls = stac92xx_build_controls,
4759 .build_pcms = stac92xx_build_pcms,
4760 .init = stac92xx_init,
4761 .free = stac92xx_free,
4762 .unsol_event = stac92xx_unsol_event,
4763#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004764 .suspend = stac92hd71xx_suspend,
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004765 .resume = stac92hd71xx_resume,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004766#endif
4767};
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004768
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004769static struct hda_input_mux stac92hd71bxx_dmux = {
4770 .num_items = 4,
4771 .items = {
4772 { "Analog Inputs", 0x00 },
4773 { "Mixer", 0x01 },
4774 { "Digital Mic 1", 0x02 },
4775 { "Digital Mic 2", 0x03 },
4776 }
4777};
4778
Matthew Ranostaye035b842007-11-06 11:53:55 +01004779static int patch_stac92hd71bxx(struct hda_codec *codec)
4780{
4781 struct sigmatel_spec *spec;
4782 int err = 0;
4783
4784 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4785 if (spec == NULL)
4786 return -ENOMEM;
4787
4788 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004789 codec->patch_ops = stac92xx_patch_ops;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004790 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004791 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004792 spec->pin_nids = stac92hd71bxx_pin_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004793 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4794 sizeof(stac92hd71bxx_dmux));
Matthew Ranostaye035b842007-11-06 11:53:55 +01004795 spec->board_config = snd_hda_check_board_config(codec,
4796 STAC_92HD71BXX_MODELS,
4797 stac92hd71bxx_models,
4798 stac92hd71bxx_cfg_tbl);
4799again:
4800 if (spec->board_config < 0) {
4801 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4802 " STAC92HD71BXX, using BIOS defaults\n");
4803 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004804 } else
4805 err = stac_save_pin_cfgs(codec,
4806 stac92hd71bxx_brd_tbl[spec->board_config]);
4807 if (err < 0) {
4808 stac92xx_free(codec);
4809 return err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004810 }
4811
Takashi Iwai41c3b642008-11-18 10:45:15 +01004812 if (spec->board_config > STAC_92HD71BXX_REF) {
4813 /* GPIO0 = EAPD */
4814 spec->gpio_mask = 0x01;
4815 spec->gpio_dir = 0x01;
4816 spec->gpio_data = 0x01;
4817 }
4818
Matthew Ranostay541eee82007-12-14 12:08:04 +01004819 switch (codec->vendor_id) {
4820 case 0x111d76b6: /* 4 Port without Analog Mixer */
4821 case 0x111d76b7:
4822 case 0x111d76b4: /* 6 Port without Analog Mixer */
4823 case 0x111d76b5:
4824 spec->mixer = stac92hd71bxx_mixer;
4825 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004826 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004827 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004828 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01004829 switch (spec->board_config) {
4830 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04004831 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004832 err = stac_add_event(spec, codec->afg,
4833 STAC_VREF_EVENT, 0x02);
4834 if (err < 0)
4835 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01004836 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04004837 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4838 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004839 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004840 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004841 spec->gpio_mask |= 0x02;
4842 break;
4843 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004844 if ((codec->revision_id & 0xf) == 0 ||
4845 (codec->revision_id & 0xf) == 1) {
4846#ifdef SND_HDA_NEEDS_RESUME
4847 codec->patch_ops = stac92hd71bxx_patch_ops;
4848#endif
4849 spec->stream_delay = 40; /* 40 milliseconds */
4850 }
4851
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004852 /* no output amps */
4853 spec->num_pwrs = 0;
4854 spec->mixer = stac92hd71bxx_analog_mixer;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004855 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004856
4857 /* disable VSW */
4858 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004859 stac_change_pin_config(codec, 0xf, 0x40f000f0);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004860 break;
4861 case 0x111d7603: /* 6 Port with Analog Mixer */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004862 if ((codec->revision_id & 0xf) == 1) {
4863#ifdef SND_HDA_NEEDS_RESUME
4864 codec->patch_ops = stac92hd71bxx_patch_ops;
4865#endif
4866 spec->stream_delay = 40; /* 40 milliseconds */
4867 }
4868
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004869 /* no output amps */
4870 spec->num_pwrs = 0;
4871 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01004872 default:
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004873 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004874 spec->mixer = stac92hd71bxx_analog_mixer;
4875 spec->init = stac92hd71bxx_analog_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004876 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004877 }
4878
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004879 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004880 spec->aloopback_shift = 0;
4881
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004882 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004883 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004884 spec->mux_nids = stac92hd71bxx_mux_nids;
4885 spec->adc_nids = stac92hd71bxx_adc_nids;
4886 spec->dmic_nids = stac92hd71bxx_dmic_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004887 spec->dmux_nids = stac92hd71bxx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004888 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004889 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004890
4891 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
4892 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004893
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004894 switch (spec->board_config) {
4895 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004896 /* enable internal microphone */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004897 stac_change_pin_config(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04004898 stac92xx_auto_set_pinctl(codec, 0x0e,
4899 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05004900 /* fallthru */
4901 case STAC_DELL_M4_2:
4902 spec->num_dmics = 0;
4903 spec->num_smuxes = 0;
4904 spec->num_dmuxes = 0;
4905 break;
4906 case STAC_DELL_M4_1:
4907 case STAC_DELL_M4_3:
4908 spec->num_dmics = 1;
4909 spec->num_smuxes = 0;
4910 spec->num_dmuxes = 0;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004911 break;
4912 default:
4913 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
4914 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
4915 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
4916 };
4917
Takashi Iwaiaea7bb02008-02-25 18:26:41 +01004918 spec->multiout.num_dacs = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004919 spec->multiout.hp_nid = 0x11;
4920 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004921 if (spec->dinput_mux)
4922 spec->private_dimux.num_items +=
4923 spec->num_dmics -
4924 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004925
4926 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
4927 if (!err) {
4928 if (spec->board_config < 0) {
4929 printk(KERN_WARNING "hda_codec: No auto-config is "
4930 "available, default to model=ref\n");
4931 spec->board_config = STAC_92HD71BXX_REF;
4932 goto again;
4933 }
4934 err = -EINVAL;
4935 }
4936
4937 if (err < 0) {
4938 stac92xx_free(codec);
4939 return err;
4940 }
4941
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004942 codec->proc_widget_hook = stac92hd7x_proc_hook;
4943
Matthew Ranostaye035b842007-11-06 11:53:55 +01004944 return 0;
4945};
4946
Matt2f2f4252005-04-13 14:45:30 +02004947static int patch_stac922x(struct hda_codec *codec)
4948{
4949 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004950 int err;
Matt2f2f4252005-04-13 14:45:30 +02004951
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004952 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004953 if (spec == NULL)
4954 return -ENOMEM;
4955
4956 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004957 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004958 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004959 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
4960 stac922x_models,
4961 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08004962 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004963 spec->gpio_mask = spec->gpio_dir = 0x03;
4964 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004965 /* Intel Macs have all same PCI SSID, so we need to check
4966 * codec SSID to distinguish the exact models
4967 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01004968 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004969 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004970
4971 case 0x106b0800:
4972 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02004973 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004974 case 0x106b0600:
4975 case 0x106b0700:
4976 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01004977 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004978 case 0x106b0e00:
4979 case 0x106b0f00:
4980 case 0x106b1600:
4981 case 0x106b1700:
4982 case 0x106b0200:
4983 case 0x106b1e00:
4984 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004985 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004986 case 0x106b1a00:
4987 case 0x00000100:
4988 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02004989 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004990 case 0x106b0a00:
4991 case 0x106b2200:
4992 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02004993 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08004994 default:
4995 spec->board_config = STAC_INTEL_MAC_V3;
4996 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004997 }
4998 }
4999
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005000 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02005001 if (spec->board_config < 0) {
5002 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
5003 "using BIOS defaults\n");
5004 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005005 } else
5006 err = stac_save_pin_cfgs(codec,
5007 stac922x_brd_tbl[spec->board_config]);
5008 if (err < 0) {
5009 stac92xx_free(codec);
5010 return err;
Matt Porter403d1942005-11-29 15:00:51 +01005011 }
Matt2f2f4252005-04-13 14:45:30 +02005012
Matt2f2f4252005-04-13 14:45:30 +02005013 spec->adc_nids = stac922x_adc_nids;
5014 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005015 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005016 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005017 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005018 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005019
5020 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005021 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005022
5023 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005024
Matt Porter3cc08dc2006-01-23 15:27:49 +01005025 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005026 if (!err) {
5027 if (spec->board_config < 0) {
5028 printk(KERN_WARNING "hda_codec: No auto-config is "
5029 "available, default to model=ref\n");
5030 spec->board_config = STAC_D945_REF;
5031 goto again;
5032 }
5033 err = -EINVAL;
5034 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005035 if (err < 0) {
5036 stac92xx_free(codec);
5037 return err;
5038 }
5039
5040 codec->patch_ops = stac92xx_patch_ops;
5041
Takashi Iwai807a46362007-05-29 19:01:37 +02005042 /* Fix Mux capture level; max to 2 */
5043 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5044 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5045 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5046 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5047 (0 << AC_AMPCAP_MUTE_SHIFT));
5048
Matt Porter3cc08dc2006-01-23 15:27:49 +01005049 return 0;
5050}
5051
5052static int patch_stac927x(struct hda_codec *codec)
5053{
5054 struct sigmatel_spec *spec;
5055 int err;
5056
5057 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5058 if (spec == NULL)
5059 return -ENOMEM;
5060
5061 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005062 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005063 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005064 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5065 stac927x_models,
5066 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005067 again:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005068 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
5069 if (spec->board_config < 0)
5070 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5071 "STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02005072 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005073 } else
5074 err = stac_save_pin_cfgs(codec,
5075 stac927x_brd_tbl[spec->board_config]);
5076 if (err < 0) {
5077 stac92xx_free(codec);
5078 return err;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005079 }
5080
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005081 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005082 spec->adc_nids = stac927x_adc_nids;
5083 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5084 spec->mux_nids = stac927x_mux_nids;
5085 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005086 spec->smux_nids = stac927x_smux_nids;
5087 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005088 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005089 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005090 spec->multiout.dac_nids = spec->dac_nids;
5091
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005092 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005093 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005094 case STAC_D965_5ST:
5095 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005096 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005097 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005098 spec->num_dmics = 0;
5099
Tobin Davis93ed1502006-09-01 21:03:12 +02005100 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005101 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005102 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005103 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005104 switch (codec->subsystem_id) {
5105 case 0x10280209:
5106 case 0x1028022e:
5107 /* correct the device field to SPDIF out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005108 stac_change_pin_config(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005109 break;
5110 };
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005111 /* configure the analog microphone on some laptops */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005112 stac_change_pin_config(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005113 /* correct the front output jack as a hp out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005114 stac_change_pin_config(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005115 /* correct the front input jack as a mic */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005116 stac_change_pin_config(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005117 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005118 case STAC_DELL_3ST:
5119 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005120 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005121 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005122 spec->dmic_nids = stac927x_dmic_nids;
5123 spec->num_dmics = STAC927X_NUM_DMICS;
5124
Tobin Davis93ed1502006-09-01 21:03:12 +02005125 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005126 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005127 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005128 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005129 break;
5130 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005131 if (spec->board_config > STAC_D965_REF) {
5132 /* GPIO0 High = Enable EAPD */
5133 spec->eapd_mask = spec->gpio_mask = 0x01;
5134 spec->gpio_dir = spec->gpio_data = 0x01;
5135 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005136 spec->num_dmics = 0;
5137
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005138 spec->init = stac927x_core_init;
5139 spec->mixer = stac927x_mixer;
5140 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005141
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005142 spec->num_pwrs = 0;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005143 spec->aloopback_mask = 0x40;
5144 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005145 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005146
Matt Porter3cc08dc2006-01-23 15:27:49 +01005147 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005148 if (!err) {
5149 if (spec->board_config < 0) {
5150 printk(KERN_WARNING "hda_codec: No auto-config is "
5151 "available, default to model=ref\n");
5152 spec->board_config = STAC_D965_REF;
5153 goto again;
5154 }
5155 err = -EINVAL;
5156 }
Mattc7d4b2f2005-06-27 14:59:41 +02005157 if (err < 0) {
5158 stac92xx_free(codec);
5159 return err;
5160 }
Matt2f2f4252005-04-13 14:45:30 +02005161
5162 codec->patch_ops = stac92xx_patch_ops;
5163
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005164 codec->proc_widget_hook = stac927x_proc_hook;
5165
Takashi Iwai52987652008-01-16 16:09:47 +01005166 /*
5167 * !!FIXME!!
5168 * The STAC927x seem to require fairly long delays for certain
5169 * command sequences. With too short delays (even if the answer
5170 * is set to RIRB properly), it results in the silence output
5171 * on some hardwares like Dell.
5172 *
5173 * The below flag enables the longer delay (see get_response
5174 * in hda_intel.c).
5175 */
5176 codec->bus->needs_damn_long_delay = 1;
5177
Matt2f2f4252005-04-13 14:45:30 +02005178 return 0;
5179}
5180
Matt Porterf3302a52006-07-31 12:49:34 +02005181static int patch_stac9205(struct hda_codec *codec)
5182{
5183 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005184 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005185
5186 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5187 if (spec == NULL)
5188 return -ENOMEM;
5189
5190 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005191 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005192 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005193 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5194 stac9205_models,
5195 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005196 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02005197 if (spec->board_config < 0) {
5198 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
5199 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005200 } else
5201 err = stac_save_pin_cfgs(codec,
5202 stac9205_brd_tbl[spec->board_config]);
5203 if (err < 0) {
5204 stac92xx_free(codec);
5205 return err;
Matt Porterf3302a52006-07-31 12:49:34 +02005206 }
5207
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005208 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005209 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005210 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005211 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005212 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005213 spec->smux_nids = stac9205_smux_nids;
5214 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005215 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005216 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005217 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005218 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005219 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005220
5221 spec->init = stac9205_core_init;
5222 spec->mixer = stac9205_mixer;
5223
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005224 spec->aloopback_mask = 0x40;
5225 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005226 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005227 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005228
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005229 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005230 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005231 /* Enable SPDIF in/out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005232 stac_change_pin_config(codec, 0x1f, 0x01441030);
5233 stac_change_pin_config(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005234
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005235 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005236 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5237 if (err < 0)
5238 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005239 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005240 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5241 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005242 AC_VERB_SET_UNSOLICITED_ENABLE,
5243 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005244
5245 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005246 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005247 spec->gpio_mask = 0x1b;
5248 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005249 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005250 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005251 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005252 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005253 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005254 case STAC_9205_REF:
5255 /* SPDIF-In enabled */
5256 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005257 default:
5258 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005259 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005260 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005261 break;
5262 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005263
Matt Porterf3302a52006-07-31 12:49:34 +02005264 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005265 if (!err) {
5266 if (spec->board_config < 0) {
5267 printk(KERN_WARNING "hda_codec: No auto-config is "
5268 "available, default to model=ref\n");
5269 spec->board_config = STAC_9205_REF;
5270 goto again;
5271 }
5272 err = -EINVAL;
5273 }
Matt Porterf3302a52006-07-31 12:49:34 +02005274 if (err < 0) {
5275 stac92xx_free(codec);
5276 return err;
5277 }
5278
5279 codec->patch_ops = stac92xx_patch_ops;
5280
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005281 codec->proc_widget_hook = stac9205_proc_hook;
5282
Matt Porterf3302a52006-07-31 12:49:34 +02005283 return 0;
5284}
5285
Matt2f2f4252005-04-13 14:45:30 +02005286/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005287 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005288 */
5289
Guillaume Munch99ccc562006-08-16 19:35:12 +02005290/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005291static hda_nid_t vaio_dacs[] = { 0x2 };
5292#define VAIO_HP_DAC 0x5
5293static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
5294static hda_nid_t vaio_mux_nids[] = { 0x15 };
5295
5296static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02005297 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01005298 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02005299 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005300 { "Mic Jack", 0x1 },
5301 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01005302 { "PCM", 0x3 },
5303 }
5304};
5305
5306static struct hda_verb vaio_init[] = {
5307 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005308 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01005309 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5310 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5311 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5312 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005313 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005314 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5315 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5316 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5317 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5318 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5319 {}
5320};
5321
Guillaume Munch6d859062006-08-22 17:15:47 +02005322static struct hda_verb vaio_ar_init[] = {
5323 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5324 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5325 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5326 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5327/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
5328 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005329 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02005330 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5331 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5332/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
5333 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5334 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5335 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5336 {}
5337};
5338
Takashi Iwaidb064e52006-03-16 16:04:58 +01005339static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwai127e82e2008-11-14 14:03:33 +01005340 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5341 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5342 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5343 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
Takashi Iwaidb064e52006-03-16 16:04:58 +01005344 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5345 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5346 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5347 {
5348 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5349 .name = "Capture Source",
5350 .count = 1,
5351 .info = stac92xx_mux_enum_info,
5352 .get = stac92xx_mux_enum_get,
5353 .put = stac92xx_mux_enum_put,
5354 },
5355 {}
5356};
5357
Guillaume Munch6d859062006-08-22 17:15:47 +02005358static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwai127e82e2008-11-14 14:03:33 +01005359 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5360 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5361 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5362 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
Guillaume Munch6d859062006-08-22 17:15:47 +02005363 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5364 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5365 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5366 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
5367 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
5368 {
5369 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5370 .name = "Capture Source",
5371 .count = 1,
5372 .info = stac92xx_mux_enum_info,
5373 .get = stac92xx_mux_enum_get,
5374 .put = stac92xx_mux_enum_put,
5375 },
5376 {}
5377};
5378
5379static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01005380 .build_controls = stac92xx_build_controls,
5381 .build_pcms = stac92xx_build_pcms,
5382 .init = stac92xx_init,
5383 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02005384#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01005385 .resume = stac92xx_resume,
5386#endif
5387};
5388
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005389static int stac9872_vaio_init(struct hda_codec *codec)
5390{
5391 int err;
5392
5393 err = stac92xx_init(codec);
5394 if (err < 0)
5395 return err;
5396 if (codec->patch_ops.unsol_event)
5397 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
5398 return 0;
5399}
5400
5401static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
5402{
Jiang Zhe40c1d302007-11-12 13:05:16 +01005403 if (get_hp_pin_presence(codec, 0x0a)) {
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005404 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5405 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5406 } else {
5407 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5408 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5409 }
5410}
5411
5412static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
5413{
5414 switch (res >> 26) {
5415 case STAC_HP_EVENT:
5416 stac9872_vaio_hp_detect(codec, res);
5417 break;
5418 }
5419}
5420
5421static struct hda_codec_ops stac9872_vaio_patch_ops = {
5422 .build_controls = stac92xx_build_controls,
5423 .build_pcms = stac92xx_build_pcms,
5424 .init = stac9872_vaio_init,
5425 .free = stac92xx_free,
5426 .unsol_event = stac9872_vaio_unsol_event,
5427#ifdef CONFIG_PM
5428 .resume = stac92xx_resume,
5429#endif
5430};
5431
Guillaume Munch6d859062006-08-22 17:15:47 +02005432enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
5433 CXD9872RD_VAIO,
5434 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
5435 STAC9872AK_VAIO,
5436 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
5437 STAC9872K_VAIO,
5438 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005439 CXD9872AKD_VAIO,
5440 STAC_9872_MODELS,
5441};
Takashi Iwaidb064e52006-03-16 16:04:58 +01005442
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005443static const char *stac9872_models[STAC_9872_MODELS] = {
5444 [CXD9872RD_VAIO] = "vaio",
5445 [CXD9872AKD_VAIO] = "vaio-ar",
5446};
5447
5448static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5449 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
5450 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
5451 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01005452 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01005453 {}
5454};
5455
Guillaume Munch6d859062006-08-22 17:15:47 +02005456static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005457{
5458 struct sigmatel_spec *spec;
5459 int board_config;
5460
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005461 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5462 stac9872_models,
5463 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01005464 if (board_config < 0)
5465 /* unknown config, let generic-parser do its job... */
5466 return snd_hda_parse_generic_codec(codec);
5467
5468 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5469 if (spec == NULL)
5470 return -ENOMEM;
5471
5472 codec->spec = spec;
5473 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02005474 case CXD9872RD_VAIO:
5475 case STAC9872AK_VAIO:
5476 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01005477 spec->mixer = vaio_mixer;
5478 spec->init = vaio_init;
5479 spec->multiout.max_channels = 2;
5480 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5481 spec->multiout.dac_nids = vaio_dacs;
5482 spec->multiout.hp_nid = VAIO_HP_DAC;
5483 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5484 spec->adc_nids = vaio_adcs;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005485 spec->num_pwrs = 0;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005486 spec->input_mux = &vaio_mux;
5487 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005488 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005489 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02005490
5491 case CXD9872AKD_VAIO:
5492 spec->mixer = vaio_ar_mixer;
5493 spec->init = vaio_ar_init;
5494 spec->multiout.max_channels = 2;
5495 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5496 spec->multiout.dac_nids = vaio_dacs;
5497 spec->multiout.hp_nid = VAIO_HP_DAC;
5498 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005499 spec->num_pwrs = 0;
Guillaume Munch6d859062006-08-22 17:15:47 +02005500 spec->adc_nids = vaio_adcs;
5501 spec->input_mux = &vaio_mux;
5502 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005503 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02005504 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005505 }
5506
Takashi Iwaidb064e52006-03-16 16:04:58 +01005507 return 0;
5508}
5509
5510
5511/*
Matt2f2f4252005-04-13 14:45:30 +02005512 * patch entries
5513 */
5514struct hda_codec_preset snd_hda_preset_sigmatel[] = {
5515 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5516 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5517 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5518 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5519 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5520 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5521 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005522 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5523 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5524 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5525 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5526 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5527 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005528 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5529 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5530 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5531 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5532 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5533 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5534 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5535 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5536 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5537 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005538 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5539 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5540 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5541 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5542 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5543 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005544 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5545 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005546 /* The following does not take into account .id=0x83847661 when subsys =
5547 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5548 * currently not fully supported.
5549 */
5550 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5551 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5552 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02005553 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5554 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5555 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5556 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5557 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5558 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5559 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5560 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005561 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005562 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5563 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005564 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005565 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5566 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005567 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005568 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5569 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5570 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5571 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5572 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5573 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5574 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5575 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005576 {} /* terminator */
5577};