blob: 4da72403fc87e52610f17aa3fce8814f3913fa89 [file] [log] [blame]
Matt2f2f4252005-04-13 14:45:30 +02001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for SigmaTel STAC92xx
5 *
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
Matt Porter403d1942005-11-29 15:00:51 +01007 * Matt Porter <mporter@embeddedalley.com>
Matt2f2f4252005-04-13 14:45:30 +02008 *
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 *
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
Matt2f2f4252005-04-13 14:45:30 +020027#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/slab.h>
30#include <linux/pci.h>
31#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020032#include <sound/asoundef.h>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040033#include <sound/jack.h>
Matt2f2f4252005-04-13 14:45:30 +020034#include "hda_codec.h"
35#include "hda_local.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020036#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020037
Takashi Iwaic6e4c662008-11-25 11:58:19 +010038enum {
39 STAC_VREF_EVENT = 1,
40 STAC_INSERT_EVENT,
41 STAC_PWR_EVENT,
42 STAC_HP_EVENT,
43};
Matt4e550962005-07-04 17:51:39 +020044
Takashi Iwaif5fcc132006-11-24 17:07:44 +010045enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010046 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010047 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,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020059 STAC_9200_M4,
60 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010061 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010062 STAC_9200_MODELS
63};
64
65enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010066 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010067 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020068 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020069 STAC_9205_DELL_M43,
70 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010071 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010072 STAC_9205_MODELS
73};
74
75enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010076 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010077 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010078 STAC_92HD73XX_REF,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010079 STAC_DELL_M6_AMIC,
80 STAC_DELL_M6_DMIC,
81 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050082 STAC_DELL_EQ,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010083 STAC_92HD73XX_MODELS
84};
85
86enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010087 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020088 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050089 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050090 STAC_DELL_S14,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020091 STAC_92HD83XXX_MODELS
92};
93
94enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010095 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +010096 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010097 STAC_DELL_M4_1,
98 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -050099 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400100 STAC_HP_M4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100101 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100102 STAC_HP_HDX,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100103 STAC_92HD71BXX_MODELS
104};
105
106enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100107 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100108 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200109 STAC_M1,
110 STAC_M1_2,
111 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100112 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200113 STAC_M3,
114 STAC_M5,
115 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100116 STAC_925x_MODELS
117};
118
119enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100120 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100121 STAC_D945_REF,
122 STAC_D945GTP3,
123 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200124 STAC_INTEL_MAC_V1,
125 STAC_INTEL_MAC_V2,
126 STAC_INTEL_MAC_V3,
127 STAC_INTEL_MAC_V4,
128 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800129 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
130 * is given, one of the above models will be
131 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200132 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100133 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100134 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100135 STAC_MACBOOK_PRO_V1,
136 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200137 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200138 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300139 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200140 STAC_922X_DELL_D81,
141 STAC_922X_DELL_D82,
142 STAC_922X_DELL_M81,
143 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100144 STAC_922X_MODELS
145};
146
147enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100148 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100149 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100150 STAC_D965_REF,
151 STAC_D965_3ST,
152 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200153 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100154 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100155 STAC_927X_MODELS
156};
Matt Porter403d1942005-11-29 15:00:51 +0100157
Takashi Iwai307282c2009-03-12 18:17:58 +0100158enum {
159 STAC_9872_AUTO,
160 STAC_9872_VAIO,
161 STAC_9872_MODELS
162};
163
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400164struct sigmatel_event {
165 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100166 unsigned char type;
167 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400168 int data;
169};
170
171struct sigmatel_jack {
172 hda_nid_t nid;
173 int type;
174 struct snd_jack *jack;
175};
176
Matt2f2f4252005-04-13 14:45:30 +0200177struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100178 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200179 unsigned int num_mixers;
180
Matt Porter403d1942005-11-29 15:00:51 +0100181 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500182 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200183 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100184 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100185 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400186 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100187 unsigned int check_volume_offset:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200188
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100189 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200190 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100191 unsigned int gpio_mask;
192 unsigned int gpio_dir;
193 unsigned int gpio_data;
194 unsigned int gpio_mute;
195
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200196 /* stream */
197 unsigned int stream_delay;
198
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100199 /* analog loopback */
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100200 struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100201 unsigned char aloopback_mask;
202 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200203
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100204 /* power management */
205 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200206 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100207 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100208 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100209
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400210 /* jack detection */
211 struct snd_array jacks;
212
213 /* events */
214 struct snd_array events;
215
Matt2f2f4252005-04-13 14:45:30 +0200216 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100217 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400218 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100219 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200220 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100221 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100222 hda_nid_t hp_dacs[5];
223 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200224
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100225 int volume_offset;
226
Matt2f2f4252005-04-13 14:45:30 +0200227 /* capture */
228 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200229 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200230 hda_nid_t *mux_nids;
231 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200232 hda_nid_t *dmic_nids;
233 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100234 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100235 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200236 hda_nid_t *smux_nids;
237 unsigned int num_smuxes;
Matthew Ranostay65973632008-09-16 10:39:37 -0400238 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200239
Mattdabbed62005-06-14 10:19:34 +0200240 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100241 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200242 hda_nid_t anabeep_nid;
243 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200244
Matt2f2f4252005-04-13 14:45:30 +0200245 /* pin widgets */
246 hda_nid_t *pin_nids;
247 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200248
249 /* codec specific stuff */
250 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100251 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200252
253 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200254 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100255 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200256 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100257 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200258 struct hda_input_mux *sinput_mux;
259 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400260 unsigned int cur_amux;
261 hda_nid_t *amp_nids;
262 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200263 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200264
Matt Porter403d1942005-11-29 15:00:51 +0100265 /* i/o switches */
266 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200267 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100268 hda_nid_t line_switch; /* shared line-in for input and output */
269 hda_nid_t mic_switch; /* shared mic-in for input and output */
270 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200271 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200272
Mattc7d4b2f2005-06-27 14:59:41 +0200273 struct hda_pcm pcm_rec[2]; /* PCM information */
274
275 /* dynamic controls and input_mux */
276 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200277 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200278 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200279 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200280 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400281 struct hda_input_mux private_amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100282 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200283};
284
285static hda_nid_t stac9200_adc_nids[1] = {
286 0x03,
287};
288
289static hda_nid_t stac9200_mux_nids[1] = {
290 0x0c,
291};
292
293static hda_nid_t stac9200_dac_nids[1] = {
294 0x02,
295};
296
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100297static hda_nid_t stac92hd73xx_pwr_nids[8] = {
298 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
299 0x0f, 0x10, 0x11
300};
301
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400302static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
303 0x26, 0,
304};
305
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100306static hda_nid_t stac92hd73xx_adc_nids[2] = {
307 0x1a, 0x1b
308};
309
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400310#define DELL_M6_AMP 2
311static hda_nid_t stac92hd73xx_amp_nids[3] = {
312 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400313};
314
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100315#define STAC92HD73XX_NUM_DMICS 2
316static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
317 0x13, 0x14, 0
318};
319
320#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100321
322static hda_nid_t stac92hd73xx_mux_nids[4] = {
323 0x28, 0x29, 0x2a, 0x2b,
324};
325
326static hda_nid_t stac92hd73xx_dmux_nids[2] = {
327 0x20, 0x21,
328};
329
Matthew Ranostayd9737752008-09-07 12:03:41 +0200330static hda_nid_t stac92hd73xx_smux_nids[2] = {
331 0x22, 0x23,
332};
333
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200334#define STAC92HD83XXX_NUM_DMICS 2
335static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
336 0x11, 0x12, 0
337};
338
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200339#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200340
341static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
342 0x17, 0x18,
343};
344
345static hda_nid_t stac92hd83xxx_adc_nids[2] = {
346 0x15, 0x16,
347};
348
349static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
350 0xa, 0xb, 0xd, 0xe,
351};
352
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400353static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
354 0x1e, 0,
355};
356
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200357static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500358 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200359};
360
Takashi Iwai9248f262009-01-14 09:40:25 +0100361static hda_nid_t stac92hd83xxx_amp_nids[1] = {
Matthew Ranostayc15c5062009-01-13 13:30:07 -0500362 0xc,
363};
364
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100365static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
366 0x0a, 0x0d, 0x0f
367};
368
Matthew Ranostaye035b842007-11-06 11:53:55 +0100369static hda_nid_t stac92hd71bxx_adc_nids[2] = {
370 0x12, 0x13,
371};
372
373static hda_nid_t stac92hd71bxx_mux_nids[2] = {
374 0x1a, 0x1b
375};
376
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400377static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
378 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100379};
380
Matthew Ranostayd9737752008-09-07 12:03:41 +0200381static hda_nid_t stac92hd71bxx_smux_nids[2] = {
382 0x24, 0x25,
383};
384
Matthew Ranostaye035b842007-11-06 11:53:55 +0100385#define STAC92HD71BXX_NUM_DMICS 2
386static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
387 0x18, 0x19, 0
388};
389
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400390static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
391 0x22, 0
392};
393
Tobin Davis8e21c342007-01-08 11:04:17 +0100394static hda_nid_t stac925x_adc_nids[1] = {
395 0x03,
396};
397
398static hda_nid_t stac925x_mux_nids[1] = {
399 0x0f,
400};
401
402static hda_nid_t stac925x_dac_nids[1] = {
403 0x02,
404};
405
Takashi Iwaif6e98522007-10-16 14:27:04 +0200406#define STAC925X_NUM_DMICS 1
407static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
408 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200409};
410
Takashi Iwai1697055e2007-12-18 18:05:52 +0100411static hda_nid_t stac925x_dmux_nids[1] = {
412 0x14,
413};
414
Matt2f2f4252005-04-13 14:45:30 +0200415static hda_nid_t stac922x_adc_nids[2] = {
416 0x06, 0x07,
417};
418
419static hda_nid_t stac922x_mux_nids[2] = {
420 0x12, 0x13,
421};
422
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500423static hda_nid_t stac927x_slave_dig_outs[2] = {
424 0x1f, 0,
425};
426
Matt Porter3cc08dc2006-01-23 15:27:49 +0100427static hda_nid_t stac927x_adc_nids[3] = {
428 0x07, 0x08, 0x09
429};
430
431static hda_nid_t stac927x_mux_nids[3] = {
432 0x15, 0x16, 0x17
433};
434
Matthew Ranostayd9737752008-09-07 12:03:41 +0200435static hda_nid_t stac927x_smux_nids[1] = {
436 0x21,
437};
438
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100439static hda_nid_t stac927x_dac_nids[6] = {
440 0x02, 0x03, 0x04, 0x05, 0x06, 0
441};
442
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100443static hda_nid_t stac927x_dmux_nids[1] = {
444 0x1b,
445};
446
Matthew Ranostay7f168592007-10-18 17:38:17 +0200447#define STAC927X_NUM_DMICS 2
448static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
449 0x13, 0x14, 0
450};
451
Matthew Ranostay65973632008-09-16 10:39:37 -0400452static const char *stac927x_spdif_labels[5] = {
453 "Digital Playback", "ADAT", "Analog Mux 1",
454 "Analog Mux 2", "Analog Mux 3"
455};
456
Matt Porterf3302a52006-07-31 12:49:34 +0200457static hda_nid_t stac9205_adc_nids[2] = {
458 0x12, 0x13
459};
460
461static hda_nid_t stac9205_mux_nids[2] = {
462 0x19, 0x1a
463};
464
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100465static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100466 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100467};
468
Matthew Ranostayd9737752008-09-07 12:03:41 +0200469static hda_nid_t stac9205_smux_nids[1] = {
470 0x21,
471};
472
Takashi Iwaif6e98522007-10-16 14:27:04 +0200473#define STAC9205_NUM_DMICS 2
474static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
475 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200476};
477
Mattc7d4b2f2005-06-27 14:59:41 +0200478static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200479 0x08, 0x09, 0x0d, 0x0e,
480 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200481};
482
Tobin Davis8e21c342007-01-08 11:04:17 +0100483static hda_nid_t stac925x_pin_nids[8] = {
484 0x07, 0x08, 0x0a, 0x0b,
485 0x0c, 0x0d, 0x10, 0x11,
486};
487
Matt2f2f4252005-04-13 14:45:30 +0200488static hda_nid_t stac922x_pin_nids[10] = {
489 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
490 0x0f, 0x10, 0x11, 0x15, 0x1b,
491};
492
Matthew Ranostaya7662642008-02-21 07:51:14 +0100493static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100494 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
495 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200496 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100497};
498
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500499static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200500 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500501 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200502};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500503
504#define STAC92HD71BXX_NUM_PINS 13
505static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
506 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
507 0x00, 0x14, 0x18, 0x19, 0x1e,
508 0x1f, 0x20, 0x27
509};
510static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100511 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
512 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500513 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100514};
515
Matt Porter3cc08dc2006-01-23 15:27:49 +0100516static hda_nid_t stac927x_pin_nids[14] = {
517 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
518 0x0f, 0x10, 0x11, 0x12, 0x13,
519 0x14, 0x21, 0x22, 0x23,
520};
521
Matt Porterf3302a52006-07-31 12:49:34 +0200522static hda_nid_t stac9205_pin_nids[12] = {
523 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
524 0x0f, 0x14, 0x16, 0x17, 0x18,
525 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200526};
527
Matthew Ranostay89385032008-09-11 09:49:39 -0400528#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
529
530static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
531 struct snd_ctl_elem_value *ucontrol)
532{
533 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
534 struct sigmatel_spec *spec = codec->spec;
535 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
536
537 kcontrol->private_value ^= get_amp_nid(kcontrol);
538 kcontrol->private_value |= nid;
539
540 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
541}
542
543static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
544 struct snd_ctl_elem_value *ucontrol)
545{
546 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
547 struct sigmatel_spec *spec = codec->spec;
548 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
549
550 kcontrol->private_value ^= get_amp_nid(kcontrol);
551 kcontrol->private_value |= nid;
552
553 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
554}
555
Matt Porter8b657272006-10-26 17:12:59 +0200556static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
557 struct snd_ctl_elem_info *uinfo)
558{
559 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
560 struct sigmatel_spec *spec = codec->spec;
561 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
562}
563
564static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
565 struct snd_ctl_elem_value *ucontrol)
566{
567 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
568 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100569 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200570
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100571 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200572 return 0;
573}
574
575static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
576 struct snd_ctl_elem_value *ucontrol)
577{
578 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
579 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100580 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200581
582 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100583 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200584}
585
Matthew Ranostayd9737752008-09-07 12:03:41 +0200586static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
587 struct snd_ctl_elem_info *uinfo)
588{
589 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
590 struct sigmatel_spec *spec = codec->spec;
591 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
592}
593
594static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
595 struct snd_ctl_elem_value *ucontrol)
596{
597 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
598 struct sigmatel_spec *spec = codec->spec;
599 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
600
601 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
602 return 0;
603}
604
605static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
606 struct snd_ctl_elem_value *ucontrol)
607{
608 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
609 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400610 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200611 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400612 int err, val;
613 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200614
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400615 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200616 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400617 if (err < 0)
618 return err;
619
620 if (spec->spdif_mute) {
621 if (smux_idx == 0)
622 nid = spec->multiout.dig_out_nid;
623 else
624 nid = codec->slave_dig_outs[smux_idx - 1];
625 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100626 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400627 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100628 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400629 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100630 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
631 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400632 }
633 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200634}
635
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100636static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200637{
638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200640 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200641}
642
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100643static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200644{
645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646 struct sigmatel_spec *spec = codec->spec;
647 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
648
649 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
650 return 0;
651}
652
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100653static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200654{
655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
656 struct sigmatel_spec *spec = codec->spec;
657 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
658
Mattc7d4b2f2005-06-27 14:59:41 +0200659 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200660 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
661}
662
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100663static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
664 struct snd_ctl_elem_info *uinfo)
665{
666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
667 struct sigmatel_spec *spec = codec->spec;
668 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
669}
670
671static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
672 struct snd_ctl_elem_value *ucontrol)
673{
674 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
675 struct sigmatel_spec *spec = codec->spec;
676
677 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
678 return 0;
679}
680
681static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
682 struct snd_ctl_elem_value *ucontrol)
683{
684 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
685 struct sigmatel_spec *spec = codec->spec;
686
687 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
688 spec->mono_nid, &spec->cur_mmux);
689}
690
Matthew Ranostay89385032008-09-11 09:49:39 -0400691static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
692 struct snd_ctl_elem_info *uinfo)
693{
694 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
695 struct sigmatel_spec *spec = codec->spec;
696 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
697}
698
699static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
700 struct snd_ctl_elem_value *ucontrol)
701{
702 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
703 struct sigmatel_spec *spec = codec->spec;
704
705 ucontrol->value.enumerated.item[0] = spec->cur_amux;
706 return 0;
707}
708
709static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
710 struct snd_ctl_elem_value *ucontrol)
711{
712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
713 struct sigmatel_spec *spec = codec->spec;
714 struct snd_kcontrol *ctl =
715 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
716 if (!ctl)
717 return -EINVAL;
718
719 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
720 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
721
722 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
723 0, &spec->cur_amux);
724}
725
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200726#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
727
728static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
729 struct snd_ctl_elem_value *ucontrol)
730{
731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100732 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200733 struct sigmatel_spec *spec = codec->spec;
734
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100735 ucontrol->value.integer.value[0] = !!(spec->aloopback &
736 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200737 return 0;
738}
739
740static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
741 struct snd_ctl_elem_value *ucontrol)
742{
743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
744 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100745 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200746 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100747 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200748
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100749 idx_val = spec->aloopback_mask << idx;
750 if (ucontrol->value.integer.value[0])
751 val = spec->aloopback | idx_val;
752 else
753 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100754 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200755 return 0;
756
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100757 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200758
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100759 /* Only return the bits defined by the shift value of the
760 * first two bytes of the mask
761 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200762 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100763 kcontrol->private_value & 0xFFFF, 0x0);
764 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200765
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100766 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200767 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100768 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200769 } else {
770 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100771 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200772 }
773
774 snd_hda_codec_write_cache(codec, codec->afg, 0,
775 kcontrol->private_value >> 16, dac_mode);
776
777 return 1;
778}
779
Mattc7d4b2f2005-06-27 14:59:41 +0200780static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200781 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200782 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200783 {}
784};
785
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200786static struct hda_verb stac9200_eapd_init[] = {
787 /* set dac0mux for dac converter */
788 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
789 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
790 {}
791};
792
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100793static struct hda_verb stac92hd73xx_6ch_core_init[] = {
794 /* set master volume and direct control */
795 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100796 /* setup adcs to point to mixer */
797 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
798 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100799 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
800 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
801 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
802 /* setup import muxs */
803 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
804 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
805 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
806 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
807 {}
808};
809
Matthew Ranostayd654a662008-03-14 08:46:51 +0100810static struct hda_verb dell_eq_core_init[] = {
811 /* set master volume to max value without distortion
812 * and direct control */
813 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100814 /* setup adcs to point to mixer */
815 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
816 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
817 /* setup import muxs */
818 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
819 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
820 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
821 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
822 {}
823};
824
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100825static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500826 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100827 /* setup adcs to point to mixer */
828 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
829 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
830 /* setup import muxs */
831 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
832 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
833 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
834 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
835 {}
836};
837
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100838static struct hda_verb stac92hd73xx_8ch_core_init[] = {
839 /* set master volume and direct control */
840 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100841 /* setup adcs to point to mixer */
842 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
843 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100844 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
845 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
846 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
847 /* setup import muxs */
848 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
849 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
850 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
851 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
852 {}
853};
854
855static struct hda_verb stac92hd73xx_10ch_core_init[] = {
856 /* set master volume and direct control */
857 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100858 /* dac3 is connected to import3 mux */
859 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100860 /* setup adcs to point to mixer */
861 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
862 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100863 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
864 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
865 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
866 /* setup import muxs */
867 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
868 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
869 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
870 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
871 {}
872};
873
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200874static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500875 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
876 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
877 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200878
879 /* power state controls amps */
880 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200881 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200882};
883
Matthew Ranostaye035b842007-11-06 11:53:55 +0100884static struct hda_verb stac92hd71bxx_core_init[] = {
885 /* set master volume and direct control */
886 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200887 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100888};
889
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500890#define HD_DISABLE_PORTF 1
Matthew Ranostay541eee82007-12-14 12:08:04 +0100891static struct hda_verb stac92hd71bxx_analog_core_init[] = {
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200892 /* start of config #1 */
893
894 /* connect port 0f to audio mixer */
895 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200896 /* start of config #2 */
897
Matthew Ranostay541eee82007-12-14 12:08:04 +0100898 /* set master volume and direct control */
899 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500900 {}
901};
902
903static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
904 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
905 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
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},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100914 /* mute the master volume */
915 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100916 {}
917};
918
Mattc7d4b2f2005-06-27 14:59:41 +0200919static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200920 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200921 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200922 {}
923};
924
Tobin Davis93ed1502006-09-01 21:03:12 +0200925static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200926 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200927 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200928 /* unmute node 0x1b */
929 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
930 /* select node 0x03 as DAC */
931 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
932 {}
933};
934
Matt Porter3cc08dc2006-01-23 15:27:49 +0100935static struct hda_verb stac927x_core_init[] = {
936 /* set master volume and direct control */
937 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200938 /* enable analog pc beep path */
939 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100940 {}
941};
942
Matt Porterf3302a52006-07-31 12:49:34 +0200943static struct hda_verb stac9205_core_init[] = {
944 /* set master volume and direct control */
945 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200946 /* enable analog pc beep path */
947 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200948 {}
949};
950
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100951#define STAC_MONO_MUX \
952 { \
953 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
954 .name = "Mono Mux", \
955 .count = 1, \
956 .info = stac92xx_mono_mux_enum_info, \
957 .get = stac92xx_mono_mux_enum_get, \
958 .put = stac92xx_mono_mux_enum_put, \
959 }
960
Matthew Ranostay89385032008-09-11 09:49:39 -0400961#define STAC_AMP_MUX \
962 { \
963 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
964 .name = "Amp Selector Capture Switch", \
965 .count = 1, \
966 .info = stac92xx_amp_mux_enum_info, \
967 .get = stac92xx_amp_mux_enum_get, \
968 .put = stac92xx_amp_mux_enum_put, \
969 }
970
971#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
972 { \
973 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
974 .name = xname, \
975 .index = 0, \
976 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
977 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
978 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
979 .info = stac92xx_amp_volume_info, \
980 .get = stac92xx_amp_volume_get, \
981 .put = stac92xx_amp_volume_put, \
982 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
983 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
984 }
985
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100986#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200987 { \
988 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
989 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100990 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200991 .info = stac92xx_aloopback_info, \
992 .get = stac92xx_aloopback_get, \
993 .put = stac92xx_aloopback_put, \
994 .private_value = verb_read | (verb_write << 16), \
995 }
996
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100997static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200998 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
999 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001000 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1001 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001002 { } /* end */
1003};
1004
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001005#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001006static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001007 /* start of config #1 */
1008 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1009 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1010
1011 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1012 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1013
1014 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1015 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1016
1017 /* start of config #2 */
1018 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1019 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1020
1021 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1022 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1023
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001024 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1025 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1026
1027 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1028 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1029
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001030 { } /* end */
1031};
1032
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001033static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1034 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1035 {}
1036};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001037
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001038static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1039 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1040 {}
1041};
1042
1043static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1044 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1045 {}
1046};
1047
1048static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001049 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1050 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1051
1052 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1053 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1054
1055 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1056 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1057
1058 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1059 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1060
1061 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1062 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1063
1064 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1065 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1066
1067 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1068 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1069 { } /* end */
1070};
1071
1072static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
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
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001104 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1105 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001106
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001107 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1108 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001109
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001110 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1111 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001112
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001113 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1114 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001115
1116 /*
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001117 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1118 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001119 */
1120 { } /* end */
1121};
1122
Matthew Ranostay541eee82007-12-14 12:08:04 +01001123static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostay9b359472007-11-07 13:03:12 +01001124 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1125 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay9b359472007-11-07 13:03:12 +01001126
1127 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1128 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001129 /* analog pc-beep replaced with digital beep support */
1130 /*
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001131 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1132 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001133 */
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001134
Matthew Ranostay687cb982008-10-11 13:52:43 -04001135 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1136 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001137
Matthew Ranostay687cb982008-10-11 13:52:43 -04001138 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1139 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001140
1141 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1142 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1143
1144 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1145 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001146 { } /* end */
1147};
1148
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001149static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1150 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1151};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001152
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001153static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +01001154 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1155 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001156
1157 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1158 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001159 { } /* end */
1160};
1161
Tobin Davis8e21c342007-01-08 11:04:17 +01001162static struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwaic9280d62009-01-15 17:31:00 +01001163 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1164 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Tobin Davis8e21c342007-01-08 11:04:17 +01001165 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
Mauro Carvalho Chehab587755f2008-05-25 18:20:06 +02001166 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
Tobin Davis8e21c342007-01-08 11:04:17 +01001167 { } /* end */
1168};
1169
Takashi Iwaid1d985f2006-11-23 19:27:12 +01001170static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001171 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1172 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001173
1174 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1175 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001176 { } /* end */
1177};
1178
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001179static struct snd_kcontrol_new stac9205_loopback[] = {
1180 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1181 {}
1182};
1183
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001184/* This needs to be generated dynamically based on sequence */
1185static struct snd_kcontrol_new stac922x_mixer[] = {
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[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001196 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1197 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001198
1199 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1200 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001201
1202 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1203 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +02001204 { } /* end */
1205};
1206
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001207static struct snd_kcontrol_new stac927x_loopback[] = {
1208 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1209 {}
1210};
1211
Takashi Iwai1697055e2007-12-18 18:05:52 +01001212static struct snd_kcontrol_new stac_dmux_mixer = {
1213 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1214 .name = "Digital Input Source",
1215 /* count set later */
1216 .info = stac92xx_dmux_enum_info,
1217 .get = stac92xx_dmux_enum_get,
1218 .put = stac92xx_dmux_enum_put,
1219};
1220
Matthew Ranostayd9737752008-09-07 12:03:41 +02001221static struct snd_kcontrol_new stac_smux_mixer = {
1222 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001223 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001224 /* count set later */
1225 .info = stac92xx_smux_enum_info,
1226 .get = stac92xx_smux_enum_get,
1227 .put = stac92xx_smux_enum_put,
1228};
1229
Takashi Iwai2134ea42008-01-10 16:53:55 +01001230static const char *slave_vols[] = {
1231 "Front Playback Volume",
1232 "Surround Playback Volume",
1233 "Center Playback Volume",
1234 "LFE Playback Volume",
1235 "Side Playback Volume",
1236 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001237 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001238 NULL
1239};
1240
1241static const char *slave_sws[] = {
1242 "Front Playback Switch",
1243 "Surround Playback Switch",
1244 "Center Playback Switch",
1245 "LFE Playback Switch",
1246 "Side Playback Switch",
1247 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001248 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001249 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001250 NULL
1251};
1252
Takashi Iwai603c4012008-07-30 15:01:44 +02001253static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001254static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001255
Matt2f2f4252005-04-13 14:45:30 +02001256static int stac92xx_build_controls(struct hda_codec *codec)
1257{
1258 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001259 struct auto_pin_cfg *cfg = &spec->autocfg;
1260 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001261 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001262 int i;
Matt2f2f4252005-04-13 14:45:30 +02001263
1264 err = snd_hda_add_new_ctls(codec, spec->mixer);
1265 if (err < 0)
1266 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001267
1268 for (i = 0; i < spec->num_mixers; i++) {
1269 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1270 if (err < 0)
1271 return err;
1272 }
Takashi Iwai1697055e2007-12-18 18:05:52 +01001273 if (spec->num_dmuxes > 0) {
1274 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001275 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001276 snd_ctl_new1(&stac_dmux_mixer, codec));
1277 if (err < 0)
1278 return err;
1279 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001280 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001281 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1282 struct hda_input_mux *smux = &spec->private_smux;
1283 /* check for mute support on SPDIF out */
1284 if (wcaps & AC_WCAP_OUT_AMP) {
1285 smux->items[smux->num_items].label = "Off";
1286 smux->items[smux->num_items].index = 0;
1287 smux->num_items++;
1288 spec->spdif_mute = 1;
1289 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001290 stac_smux_mixer.count = spec->num_smuxes;
Takashi Iwai4f2d23e2008-12-19 10:14:13 +01001291 err = snd_hda_ctl_add(codec,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001292 snd_ctl_new1(&stac_smux_mixer, codec));
1293 if (err < 0)
1294 return err;
1295 }
Mattc7d4b2f2005-06-27 14:59:41 +02001296
Mattdabbed62005-06-14 10:19:34 +02001297 if (spec->multiout.dig_out_nid) {
1298 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1299 if (err < 0)
1300 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001301 err = snd_hda_create_spdif_share_sw(codec,
1302 &spec->multiout);
1303 if (err < 0)
1304 return err;
1305 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001306 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001307 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001308 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1309 if (err < 0)
1310 return err;
1311 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001312
1313 /* if we have no master control, let's create it */
1314 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001315 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001316 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001317 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001318 /* correct volume offset */
1319 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001320 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001321 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001322 if (err < 0)
1323 return err;
1324 }
1325 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1326 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1327 NULL, slave_sws);
1328 if (err < 0)
1329 return err;
1330 }
1331
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001332 if (spec->aloopback_ctl &&
1333 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1334 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1335 if (err < 0)
1336 return err;
1337 }
1338
Takashi Iwai603c4012008-07-30 15:01:44 +02001339 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001340
1341 /* create jack input elements */
1342 if (spec->hp_detect) {
1343 for (i = 0; i < cfg->hp_outs; i++) {
1344 int type = SND_JACK_HEADPHONE;
1345 nid = cfg->hp_pins[i];
1346 /* jack detection */
1347 if (cfg->hp_outs == i)
1348 type |= SND_JACK_LINEOUT;
1349 err = stac92xx_add_jack(codec, nid, type);
1350 if (err < 0)
1351 return err;
1352 }
1353 }
1354 for (i = 0; i < cfg->line_outs; i++) {
1355 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1356 SND_JACK_LINEOUT);
1357 if (err < 0)
1358 return err;
1359 }
1360 for (i = 0; i < AUTO_PIN_LAST; i++) {
1361 nid = cfg->input_pins[i];
1362 if (nid) {
1363 err = stac92xx_add_jack(codec, nid,
1364 SND_JACK_MICROPHONE);
1365 if (err < 0)
1366 return err;
1367 }
1368 }
1369
Mattdabbed62005-06-14 10:19:34 +02001370 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001371}
1372
Matt Porter403d1942005-11-29 15:00:51 +01001373static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001374 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001375 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1376};
1377
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001378static unsigned int gateway9200_m4_pin_configs[8] = {
1379 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1380 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1381};
1382static unsigned int gateway9200_m4_2_pin_configs[8] = {
1383 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1384 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1385};
1386
1387/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001388 STAC 9200 pin configs for
1389 102801A8
1390 102801DE
1391 102801E8
1392*/
1393static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001394 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1395 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001396};
1397
1398/*
1399 STAC 9200 pin configs for
1400 102801C0
1401 102801C1
1402*/
1403static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001404 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1405 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001406};
1407
1408/*
1409 STAC 9200 pin configs for
1410 102801C4 (Dell Dimension E310)
1411 102801C5
1412 102801C7
1413 102801D9
1414 102801DA
1415 102801E3
1416*/
1417static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001418 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1419 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001420};
1421
1422
1423/*
1424 STAC 9200-32 pin configs for
1425 102801B5 (Dell Inspiron 630m)
1426 102801D8 (Dell Inspiron 640m)
1427*/
1428static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001429 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1430 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001431};
1432
1433/*
1434 STAC 9200-32 pin configs for
1435 102801C2 (Dell Latitude D620)
1436 102801C8
1437 102801CC (Dell Latitude D820)
1438 102801D4
1439 102801D6
1440*/
1441static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001442 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1443 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001444};
1445
1446/*
1447 STAC 9200-32 pin configs for
1448 102801CE (Dell XPS M1710)
1449 102801CF (Dell Precision M90)
1450*/
1451static unsigned int dell9200_m23_pin_configs[8] = {
1452 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1453 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1454};
1455
1456/*
1457 STAC 9200-32 pin configs for
1458 102801C9
1459 102801CA
1460 102801CB (Dell Latitude 120L)
1461 102801D3
1462*/
1463static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001464 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1465 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001466};
1467
1468/*
1469 STAC 9200-32 pin configs for
1470 102801BD (Dell Inspiron E1505n)
1471 102801EE
1472 102801EF
1473*/
1474static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001475 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1476 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001477};
1478
1479/*
1480 STAC 9200-32 pin configs for
1481 102801F5 (Dell Inspiron 1501)
1482 102801F6
1483*/
1484static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001485 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1486 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001487};
1488
1489/*
1490 STAC 9200-32
1491 102801CD (Dell Inspiron E1705/9400)
1492*/
1493static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001494 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1495 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001496};
1497
Tobin Davisbf277782008-02-03 20:31:47 +01001498static unsigned int oqo9200_pin_configs[8] = {
1499 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1500 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1501};
1502
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001503
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001504static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1505 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001506 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001507 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1508 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1509 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1510 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1511 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1512 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1513 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1514 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1515 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1516 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001517 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1518 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001519 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001520};
1521
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001522static const char *stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001523 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001524 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001525 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001526 [STAC_9200_DELL_D21] = "dell-d21",
1527 [STAC_9200_DELL_D22] = "dell-d22",
1528 [STAC_9200_DELL_D23] = "dell-d23",
1529 [STAC_9200_DELL_M21] = "dell-m21",
1530 [STAC_9200_DELL_M22] = "dell-m22",
1531 [STAC_9200_DELL_M23] = "dell-m23",
1532 [STAC_9200_DELL_M24] = "dell-m24",
1533 [STAC_9200_DELL_M25] = "dell-m25",
1534 [STAC_9200_DELL_M26] = "dell-m26",
1535 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001536 [STAC_9200_M4] = "gateway-m4",
1537 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001538 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001539};
1540
1541static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1542 /* SigmaTel reference board */
1543 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1544 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001545 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1546 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001547 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001548 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1549 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001550 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001551 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1552 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1553 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1554 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1555 "unknown Dell", STAC_9200_DELL_D22),
1556 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1557 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001558 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001559 "Dell Latitude D620", STAC_9200_DELL_M22),
1560 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1561 "unknown Dell", STAC_9200_DELL_D23),
1562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1563 "unknown Dell", STAC_9200_DELL_D23),
1564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1565 "unknown Dell", STAC_9200_DELL_M22),
1566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1567 "unknown Dell", STAC_9200_DELL_M24),
1568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1569 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001571 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001573 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001575 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001577 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001578 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001579 "Dell Precision M90", STAC_9200_DELL_M23),
1580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1581 "unknown Dell", STAC_9200_DELL_M22),
1582 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1583 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001584 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001585 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001586 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001587 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1588 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1589 "unknown Dell", STAC_9200_DELL_D23),
1590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1591 "unknown Dell", STAC_9200_DELL_D23),
1592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1593 "unknown Dell", STAC_9200_DELL_D21),
1594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1595 "unknown Dell", STAC_9200_DELL_D23),
1596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1597 "unknown Dell", STAC_9200_DELL_D21),
1598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1599 "unknown Dell", STAC_9200_DELL_M25),
1600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1601 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001602 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001603 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1604 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1605 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001606 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001607 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001608 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001609 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1610 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1611 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001612 /* OQO Mobile */
1613 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001614 {} /* terminator */
1615};
1616
Tobin Davis8e21c342007-01-08 11:04:17 +01001617static unsigned int ref925x_pin_configs[8] = {
1618 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001619 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001620};
1621
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001622static unsigned int stac925xM1_pin_configs[8] = {
1623 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1624 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001625};
1626
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001627static unsigned int stac925xM1_2_pin_configs[8] = {
1628 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1629 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1630};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001631
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001632static unsigned int stac925xM2_pin_configs[8] = {
1633 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1634 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001635};
1636
Tobin Davis8e21c342007-01-08 11:04:17 +01001637static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001638 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1639 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1640};
1641
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001642static unsigned int stac925xM3_pin_configs[8] = {
1643 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1644 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1645};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001646
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001647static unsigned int stac925xM5_pin_configs[8] = {
1648 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1649 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1650};
1651
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001652static unsigned int stac925xM6_pin_configs[8] = {
1653 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1654 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001655};
1656
1657static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1658 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001659 [STAC_M1] = stac925xM1_pin_configs,
1660 [STAC_M1_2] = stac925xM1_2_pin_configs,
1661 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001662 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001663 [STAC_M3] = stac925xM3_pin_configs,
1664 [STAC_M5] = stac925xM5_pin_configs,
1665 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001666};
1667
1668static const char *stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001669 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001670 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001671 [STAC_M1] = "m1",
1672 [STAC_M1_2] = "m1-2",
1673 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001674 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001675 [STAC_M3] = "m3",
1676 [STAC_M5] = "m5",
1677 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001678};
1679
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001680static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001681 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1682 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1683 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1684 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001685 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001686 /* Not sure about the brand name for those */
1687 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1688 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1689 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1690 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001691 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001692};
1693
1694static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1695 /* SigmaTel reference board */
1696 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001697 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001698 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001699
1700 /* Default table for unknown ID */
1701 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1702
Tobin Davis8e21c342007-01-08 11:04:17 +01001703 {} /* terminator */
1704};
1705
Matthew Ranostaya7662642008-02-21 07:51:14 +01001706static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001707 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1708 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1709 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001710 0x01452050,
1711};
1712
1713static unsigned int dell_m6_pin_configs[13] = {
1714 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001715 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001716 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1717 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001718};
1719
1720static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001721 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001722 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1723 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1724 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001725 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001726};
1727
1728static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001729 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001730 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001731 [STAC_92HD73XX_REF] = "ref",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001732 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1733 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1734 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001735 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001736};
1737
1738static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1739 /* SigmaTel reference board */
1740 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001741 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001742 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1743 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001744 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001745 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001746 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001747 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001748 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001749 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001750 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001751 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001752 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001753 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001754 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001755 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001756 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001757 "unknown Dell", STAC_DELL_M6_DMIC),
1758 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1759 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001760 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001761 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001762 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1763 "Dell Studio 17", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001764 {} /* terminator */
1765};
1766
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001767static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001768 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1769 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001770 0x01451160, 0x98560170,
1771};
1772
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001773static unsigned int dell_s14_pin_configs[10] = {
1774 0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1775 0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1776 0x40f000f0, 0x40f000f0,
1777};
1778
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001779static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1780 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001781 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001782 [STAC_DELL_S14] = dell_s14_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001783};
1784
1785static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001786 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001787 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001788 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001789 [STAC_DELL_S14] = "dell-s14",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001790};
1791
1792static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1793 /* SigmaTel reference board */
1794 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001795 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001796 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1797 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001798 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1799 "unknown Dell", STAC_DELL_S14),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001800 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001801};
1802
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001803static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001804 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001805 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001806 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1807 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001808};
1809
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001810static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001811 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001812 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001813 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1814 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001815};
1816
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001817static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001818 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1819 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001820 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1821 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001822};
1823
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001824static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001825 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1826 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001827 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1828 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001829};
1830
Matthew Ranostaye035b842007-11-06 11:53:55 +01001831static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1832 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001833 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1834 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001835 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001836 [STAC_HP_M4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001837 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001838 [STAC_HP_HDX] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001839};
1840
1841static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001842 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001843 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001844 [STAC_DELL_M4_1] = "dell-m4-1",
1845 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001846 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001847 [STAC_HP_M4] = "hp-m4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001848 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001849 [STAC_HP_HDX] = "hp-hdx",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001850};
1851
1852static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1853 /* SigmaTel reference board */
1854 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1855 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001856 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1857 "DFI LanParty", STAC_92HD71BXX_REF),
Takashi Iwai58d83952009-03-13 17:04:34 +01001858 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1859 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001860 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1861 "HP dv4-7", STAC_HP_DV5),
1862 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1863 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001864 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1865 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001866 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001867 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001868 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001869 "HP HDX", STAC_HP_HDX), /* HDX16 */
Matthew Ranostaya7662642008-02-21 07:51:14 +01001870 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1871 "unknown Dell", STAC_DELL_M4_1),
1872 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1873 "unknown Dell", STAC_DELL_M4_1),
1874 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1875 "unknown Dell", STAC_DELL_M4_1),
1876 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1877 "unknown Dell", STAC_DELL_M4_1),
1878 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1879 "unknown Dell", STAC_DELL_M4_1),
1880 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1881 "unknown Dell", STAC_DELL_M4_1),
1882 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1883 "unknown Dell", STAC_DELL_M4_1),
1884 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1885 "unknown Dell", STAC_DELL_M4_2),
1886 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1887 "unknown Dell", STAC_DELL_M4_2),
1888 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1889 "unknown Dell", STAC_DELL_M4_2),
1890 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1891 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001892 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1893 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001894 {} /* terminator */
1895};
1896
Matt Porter403d1942005-11-29 15:00:51 +01001897static unsigned int ref922x_pin_configs[10] = {
1898 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1899 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001900 0x40000100, 0x40000100,
1901};
1902
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001903/*
1904 STAC 922X pin configs for
1905 102801A7
1906 102801AB
1907 102801A9
1908 102801D1
1909 102801D2
1910*/
1911static unsigned int dell_922x_d81_pin_configs[10] = {
1912 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1913 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1914 0x01813122, 0x400001f2,
1915};
1916
1917/*
1918 STAC 922X pin configs for
1919 102801AC
1920 102801D0
1921*/
1922static unsigned int dell_922x_d82_pin_configs[10] = {
1923 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1924 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1925 0x01813122, 0x400001f1,
1926};
1927
1928/*
1929 STAC 922X pin configs for
1930 102801BF
1931*/
1932static unsigned int dell_922x_m81_pin_configs[10] = {
1933 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1934 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1935 0x40C003f1, 0x405003f0,
1936};
1937
1938/*
1939 STAC 9221 A1 pin configs for
1940 102801D7 (Dell XPS M1210)
1941*/
1942static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001943 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1944 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001945 0x508003f3, 0x405003f4,
1946};
1947
Matt Porter403d1942005-11-29 15:00:51 +01001948static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001949 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001950 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1951 0x02a19120, 0x40000100,
1952};
1953
1954static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001955 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1956 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001957 0x02a19320, 0x40000100,
1958};
1959
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001960static unsigned int intel_mac_v1_pin_configs[10] = {
1961 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1962 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001963 0x400000fc, 0x400000fb,
1964};
1965
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001966static unsigned int intel_mac_v2_pin_configs[10] = {
1967 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1968 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001969 0x400000fc, 0x400000fb,
1970};
1971
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001972static unsigned int intel_mac_v3_pin_configs[10] = {
1973 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1974 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1975 0x400000fc, 0x400000fb,
1976};
1977
1978static unsigned int intel_mac_v4_pin_configs[10] = {
1979 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1980 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1981 0x400000fc, 0x400000fb,
1982};
1983
1984static unsigned int intel_mac_v5_pin_configs[10] = {
1985 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1986 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1987 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001988};
1989
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001990static unsigned int ecs202_pin_configs[10] = {
1991 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1992 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1993 0x9037012e, 0x40e000f2,
1994};
Takashi Iwai76c08822007-06-19 12:17:42 +02001995
Takashi Iwai19039bd2006-06-28 15:52:16 +02001996static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001997 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001998 [STAC_D945GTP3] = d945gtp3_pin_configs,
1999 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002000 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
2001 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
2002 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
2003 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
2004 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002005 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002006 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002007 [STAC_MACMINI] = intel_mac_v3_pin_configs,
2008 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2009 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2010 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2011 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2012 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002013 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002014 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2015 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2016 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2017 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01002018};
2019
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002020static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002021 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002022 [STAC_D945_REF] = "ref",
2023 [STAC_D945GTP5] = "5stack",
2024 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002025 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2026 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2027 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2028 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2029 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08002030 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002031 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002032 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002033 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002034 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2035 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02002036 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002037 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002038 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002039 [STAC_922X_DELL_D81] = "dell-d81",
2040 [STAC_922X_DELL_D82] = "dell-d82",
2041 [STAC_922X_DELL_M81] = "dell-m81",
2042 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002043};
2044
2045static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2046 /* SigmaTel reference board */
2047 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2048 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002049 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2050 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002051 /* Intel 945G based systems */
2052 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2053 "Intel D945G", STAC_D945GTP3),
2054 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2055 "Intel D945G", STAC_D945GTP3),
2056 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2057 "Intel D945G", STAC_D945GTP3),
2058 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2059 "Intel D945G", STAC_D945GTP3),
2060 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2061 "Intel D945G", STAC_D945GTP3),
2062 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2063 "Intel D945G", STAC_D945GTP3),
2064 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2065 "Intel D945G", STAC_D945GTP3),
2066 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2067 "Intel D945G", STAC_D945GTP3),
2068 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2069 "Intel D945G", STAC_D945GTP3),
2070 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2071 "Intel D945G", STAC_D945GTP3),
2072 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2073 "Intel D945G", STAC_D945GTP3),
2074 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2075 "Intel D945G", STAC_D945GTP3),
2076 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2077 "Intel D945G", STAC_D945GTP3),
2078 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2079 "Intel D945G", STAC_D945GTP3),
2080 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2081 "Intel D945G", STAC_D945GTP3),
2082 /* Intel D945G 5-stack systems */
2083 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2084 "Intel D945G", STAC_D945GTP5),
2085 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2086 "Intel D945G", STAC_D945GTP5),
2087 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2088 "Intel D945G", STAC_D945GTP5),
2089 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2090 "Intel D945G", STAC_D945GTP5),
2091 /* Intel 945P based systems */
2092 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2093 "Intel D945P", STAC_D945GTP3),
2094 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2095 "Intel D945P", STAC_D945GTP3),
2096 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2097 "Intel D945P", STAC_D945GTP3),
2098 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2099 "Intel D945P", STAC_D945GTP3),
2100 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2101 "Intel D945P", STAC_D945GTP3),
2102 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2103 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002104 /* other intel */
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2106 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002107 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002108 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002109 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002110 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002111 /* Dell systems */
2112 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2113 "unknown Dell", STAC_922X_DELL_D81),
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2115 "unknown Dell", STAC_922X_DELL_D81),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2117 "unknown Dell", STAC_922X_DELL_D81),
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2119 "unknown Dell", STAC_922X_DELL_D82),
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2121 "unknown Dell", STAC_922X_DELL_M81),
2122 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2123 "unknown Dell", STAC_922X_DELL_D82),
2124 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2125 "unknown Dell", STAC_922X_DELL_D81),
2126 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2127 "unknown Dell", STAC_922X_DELL_D81),
2128 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2129 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002130 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002131 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002132 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002133 {} /* terminator */
2134};
2135
Matt Porter3cc08dc2006-01-23 15:27:49 +01002136static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002137 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2138 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2139 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2140 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002141};
2142
Tobin Davis93ed1502006-09-01 21:03:12 +02002143static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002144 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2145 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2146 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2147 0x40000100, 0x40000100
2148};
2149
Tobin Davis93ed1502006-09-01 21:03:12 +02002150static unsigned int d965_5st_pin_configs[14] = {
2151 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2152 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2153 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2154 0x40000100, 0x40000100
2155};
2156
Tobin Davis4ff076e2007-08-07 11:48:12 +02002157static unsigned int dell_3st_pin_configs[14] = {
2158 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2159 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002160 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002161 0x40c003fc, 0x40000100
2162};
2163
Tobin Davis93ed1502006-09-01 21:03:12 +02002164static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002165 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002166 [STAC_D965_REF] = ref927x_pin_configs,
2167 [STAC_D965_3ST] = d965_3st_pin_configs,
2168 [STAC_D965_5ST] = d965_5st_pin_configs,
2169 [STAC_DELL_3ST] = dell_3st_pin_configs,
2170 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002171};
2172
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002173static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002174 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002175 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002176 [STAC_D965_REF] = "ref",
2177 [STAC_D965_3ST] = "3stack",
2178 [STAC_D965_5ST] = "5stack",
2179 [STAC_DELL_3ST] = "dell-3stack",
2180 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002181};
2182
2183static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2184 /* SigmaTel reference board */
2185 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2186 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002187 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2188 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002189 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002190 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2191 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002192 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002193 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2194 "Intel D965", STAC_D965_3ST),
2195 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2196 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002197 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002198 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002199 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002200 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2201 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002202 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002203 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2204 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002205 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Takashi Iwai24918b62008-09-30 12:58:54 +02002206 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002207 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2209 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2210 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002211 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002212 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2213 "Intel D965", STAC_D965_5ST),
2214 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2215 "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002216 {} /* terminator */
2217};
2218
Matt Porterf3302a52006-07-31 12:49:34 +02002219static unsigned int ref9205_pin_configs[12] = {
2220 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002221 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002222 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002223};
2224
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002225/*
2226 STAC 9205 pin configs for
2227 102801F1
2228 102801F2
2229 102801FC
2230 102801FD
2231 10280204
2232 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002233 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002234*/
2235static unsigned int dell_9205_m42_pin_configs[12] = {
2236 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2237 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2238 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2239};
2240
2241/*
2242 STAC 9205 pin configs for
2243 102801F9
2244 102801FA
2245 102801FE
2246 102801FF (Dell Precision M4300)
2247 10280206
2248 10280200
2249 10280201
2250*/
2251static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002252 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2253 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2254 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2255};
2256
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002257static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002258 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2259 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2260 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2261};
2262
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002263static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002264 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002265 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2266 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2267 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002268 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002269};
2270
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002271static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002272 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002273 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002274 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002275 [STAC_9205_DELL_M43] = "dell-m43",
2276 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002277 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002278};
2279
2280static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2281 /* SigmaTel reference board */
2282 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2283 "DFI LanParty", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002284 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2285 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002286 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002287 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2288 "unknown Dell", STAC_9205_DELL_M42),
2289 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2290 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002291 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002292 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002293 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2294 "Dell Precision", STAC_9205_DELL_M43),
2295 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2296 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002297 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2298 "unknown Dell", STAC_9205_DELL_M42),
2299 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2300 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002301 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2302 "Dell Precision", STAC_9205_DELL_M43),
2303 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002304 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002305 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2306 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002307 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2308 "Dell Precision", STAC_9205_DELL_M43),
2309 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2310 "Dell Precision", STAC_9205_DELL_M43),
2311 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2312 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002313 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2314 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002315 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2316 "Dell Vostro 1500", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002317 /* Gateway */
2318 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002319 {} /* terminator */
2320};
2321
Takashi Iwai330ee992009-02-20 14:33:36 +01002322static void stac92xx_set_config_regs(struct hda_codec *codec,
2323 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002324{
2325 int i;
2326 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002327
Takashi Iwai330ee992009-02-20 14:33:36 +01002328 if (!pincfgs)
2329 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002330
Matthew Ranostay87d48362007-07-17 11:52:24 +02002331 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002332 if (spec->pin_nids[i] && pincfgs[i])
2333 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2334 pincfgs[i]);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002335}
2336
Matt2f2f4252005-04-13 14:45:30 +02002337/*
2338 * Analog playback callbacks
2339 */
2340static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2341 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002342 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002343{
2344 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002345 if (spec->stream_delay)
2346 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002347 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2348 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002349}
2350
2351static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2352 struct hda_codec *codec,
2353 unsigned int stream_tag,
2354 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002355 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002356{
2357 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002358 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002359}
2360
2361static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2362 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002363 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002364{
2365 struct sigmatel_spec *spec = codec->spec;
2366 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2367}
2368
2369/*
Mattdabbed62005-06-14 10:19:34 +02002370 * Digital playback callbacks
2371 */
2372static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2373 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002374 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002375{
2376 struct sigmatel_spec *spec = codec->spec;
2377 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2378}
2379
2380static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2381 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002382 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002383{
2384 struct sigmatel_spec *spec = codec->spec;
2385 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2386}
2387
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002388static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2389 struct hda_codec *codec,
2390 unsigned int stream_tag,
2391 unsigned int format,
2392 struct snd_pcm_substream *substream)
2393{
2394 struct sigmatel_spec *spec = codec->spec;
2395 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2396 stream_tag, format, substream);
2397}
2398
Takashi Iwai9411e212009-02-13 11:32:28 +01002399static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2400 struct hda_codec *codec,
2401 struct snd_pcm_substream *substream)
2402{
2403 struct sigmatel_spec *spec = codec->spec;
2404 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2405}
2406
Mattdabbed62005-06-14 10:19:34 +02002407
2408/*
Matt2f2f4252005-04-13 14:45:30 +02002409 * Analog capture callbacks
2410 */
2411static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2412 struct hda_codec *codec,
2413 unsigned int stream_tag,
2414 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002415 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002416{
2417 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002418 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002419
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002420 if (spec->powerdown_adcs) {
2421 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002422 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002423 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2424 }
2425 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002426 return 0;
2427}
2428
2429static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2430 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002431 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002432{
2433 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002434 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002435
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002436 snd_hda_codec_cleanup_stream(codec, nid);
2437 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002438 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002439 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002440 return 0;
2441}
2442
Mattdabbed62005-06-14 10:19:34 +02002443static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2444 .substreams = 1,
2445 .channels_min = 2,
2446 .channels_max = 2,
2447 /* NID is set in stac92xx_build_pcms */
2448 .ops = {
2449 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002450 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002451 .prepare = stac92xx_dig_playback_pcm_prepare,
2452 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002453 },
2454};
2455
2456static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2457 .substreams = 1,
2458 .channels_min = 2,
2459 .channels_max = 2,
2460 /* NID is set in stac92xx_build_pcms */
2461};
2462
Matt2f2f4252005-04-13 14:45:30 +02002463static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2464 .substreams = 1,
2465 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002466 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002467 .nid = 0x02, /* NID to query formats and rates */
2468 .ops = {
2469 .open = stac92xx_playback_pcm_open,
2470 .prepare = stac92xx_playback_pcm_prepare,
2471 .cleanup = stac92xx_playback_pcm_cleanup
2472 },
2473};
2474
Matt Porter3cc08dc2006-01-23 15:27:49 +01002475static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2476 .substreams = 1,
2477 .channels_min = 2,
2478 .channels_max = 2,
2479 .nid = 0x06, /* NID to query formats and rates */
2480 .ops = {
2481 .open = stac92xx_playback_pcm_open,
2482 .prepare = stac92xx_playback_pcm_prepare,
2483 .cleanup = stac92xx_playback_pcm_cleanup
2484 },
2485};
2486
Matt2f2f4252005-04-13 14:45:30 +02002487static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002488 .channels_min = 2,
2489 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002490 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002491 .ops = {
2492 .prepare = stac92xx_capture_pcm_prepare,
2493 .cleanup = stac92xx_capture_pcm_cleanup
2494 },
2495};
2496
2497static int stac92xx_build_pcms(struct hda_codec *codec)
2498{
2499 struct sigmatel_spec *spec = codec->spec;
2500 struct hda_pcm *info = spec->pcm_rec;
2501
2502 codec->num_pcms = 1;
2503 codec->pcm_info = info;
2504
Mattc7d4b2f2005-06-27 14:59:41 +02002505 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002506 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002507 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2508 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002509 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002510 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002511 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002512
2513 if (spec->alt_switch) {
2514 codec->num_pcms++;
2515 info++;
2516 info->name = "STAC92xx Analog Alt";
2517 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2518 }
Matt2f2f4252005-04-13 14:45:30 +02002519
Mattdabbed62005-06-14 10:19:34 +02002520 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2521 codec->num_pcms++;
2522 info++;
2523 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002524 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002525 if (spec->multiout.dig_out_nid) {
2526 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2527 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2528 }
2529 if (spec->dig_in_nid) {
2530 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2531 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2532 }
2533 }
2534
Matt2f2f4252005-04-13 14:45:30 +02002535 return 0;
2536}
2537
Takashi Iwaic960a032006-03-23 17:06:28 +01002538static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2539{
2540 unsigned int pincap = snd_hda_param_read(codec, nid,
2541 AC_PAR_PIN_CAP);
2542 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2543 if (pincap & AC_PINCAP_VREF_100)
2544 return AC_PINCTL_VREF_100;
2545 if (pincap & AC_PINCAP_VREF_80)
2546 return AC_PINCTL_VREF_80;
2547 if (pincap & AC_PINCAP_VREF_50)
2548 return AC_PINCTL_VREF_50;
2549 if (pincap & AC_PINCAP_VREF_GRD)
2550 return AC_PINCTL_VREF_GRD;
2551 return 0;
2552}
2553
Matt Porter403d1942005-11-29 15:00:51 +01002554static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2555
2556{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002557 snd_hda_codec_write_cache(codec, nid, 0,
2558 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002559}
2560
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002561#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2562
2563static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2564 struct snd_ctl_elem_value *ucontrol)
2565{
2566 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2567 struct sigmatel_spec *spec = codec->spec;
2568
Takashi Iwaid7a89432008-11-12 09:48:04 +01002569 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002570 return 0;
2571}
2572
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002573static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2574 unsigned char type);
2575
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002576static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2577 struct snd_ctl_elem_value *ucontrol)
2578{
2579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2580 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002581 int nid = kcontrol->private_value;
2582
2583 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002584
2585 /* check to be sure that the ports are upto date with
2586 * switch changes
2587 */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002588 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002589
2590 return 1;
2591}
2592
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002593#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01002594
2595static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2596{
2597 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2598 struct sigmatel_spec *spec = codec->spec;
2599 int io_idx = kcontrol-> private_value & 0xff;
2600
2601 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2602 return 0;
2603}
2604
2605static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2606{
2607 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2608 struct sigmatel_spec *spec = codec->spec;
2609 hda_nid_t nid = kcontrol->private_value >> 8;
2610 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002611 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01002612
2613 spec->io_switch[io_idx] = val;
2614
2615 if (val)
2616 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002617 else {
2618 unsigned int pinctl = AC_PINCTL_IN_EN;
2619 if (io_idx) /* set VREF for mic */
2620 pinctl |= stac92xx_get_vref(codec, nid);
2621 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2622 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002623
2624 /* check the auto-mute again: we need to mute/unmute the speaker
2625 * appropriately according to the pin direction
2626 */
2627 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002628 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002629
Matt Porter403d1942005-11-29 15:00:51 +01002630 return 1;
2631}
2632
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002633#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2634
2635static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2636 struct snd_ctl_elem_value *ucontrol)
2637{
2638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2639 struct sigmatel_spec *spec = codec->spec;
2640
2641 ucontrol->value.integer.value[0] = spec->clfe_swap;
2642 return 0;
2643}
2644
2645static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2646 struct snd_ctl_elem_value *ucontrol)
2647{
2648 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2649 struct sigmatel_spec *spec = codec->spec;
2650 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002651 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002652
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002653 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002654 return 0;
2655
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002656 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002657
2658 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2659 spec->clfe_swap ? 0x4 : 0x0);
2660
2661 return 1;
2662}
2663
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002664#define STAC_CODEC_HP_SWITCH(xname) \
2665 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2666 .name = xname, \
2667 .index = 0, \
2668 .info = stac92xx_hp_switch_info, \
2669 .get = stac92xx_hp_switch_get, \
2670 .put = stac92xx_hp_switch_put, \
2671 }
2672
Matt Porter403d1942005-11-29 15:00:51 +01002673#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2674 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2675 .name = xname, \
2676 .index = 0, \
2677 .info = stac92xx_io_switch_info, \
2678 .get = stac92xx_io_switch_get, \
2679 .put = stac92xx_io_switch_put, \
2680 .private_value = xpval, \
2681 }
2682
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002683#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2684 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2685 .name = xname, \
2686 .index = 0, \
2687 .info = stac92xx_clfe_switch_info, \
2688 .get = stac92xx_clfe_switch_get, \
2689 .put = stac92xx_clfe_switch_put, \
2690 .private_value = xpval, \
2691 }
Matt Porter403d1942005-11-29 15:00:51 +01002692
Mattc7d4b2f2005-06-27 14:59:41 +02002693enum {
2694 STAC_CTL_WIDGET_VOL,
2695 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002696 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002697 STAC_CTL_WIDGET_AMP_MUX,
2698 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002699 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002700 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002701 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02002702};
2703
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002704static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002705 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2706 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002707 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002708 STAC_AMP_MUX,
2709 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002710 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002711 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002712 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002713};
2714
2715/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002716static struct snd_kcontrol_new *
2717stac_control_new(struct sigmatel_spec *spec,
2718 struct snd_kcontrol_new *ktemp,
2719 const char *name)
Mattc7d4b2f2005-06-27 14:59:41 +02002720{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002721 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002722
Takashi Iwai603c4012008-07-30 15:01:44 +02002723 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2724 knew = snd_array_new(&spec->kctls);
2725 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002726 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002727 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002728 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002729 if (!knew->name) {
2730 /* roolback */
2731 memset(knew, 0, sizeof(*knew));
2732 spec->kctls.alloced--;
2733 return NULL;
2734 }
2735 return knew;
2736}
2737
2738static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2739 struct snd_kcontrol_new *ktemp,
2740 int idx, const char *name,
2741 unsigned long val)
2742{
2743 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2744 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002745 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002746 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002747 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002748 return 0;
2749}
2750
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002751static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2752 int type, int idx, const char *name,
2753 unsigned long val)
2754{
2755 return stac92xx_add_control_temp(spec,
2756 &stac92xx_control_templates[type],
2757 idx, name, val);
2758}
2759
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002760
2761/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002762static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2763 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002764{
2765 return stac92xx_add_control_idx(spec, type, 0, name, val);
2766}
2767
Takashi Iwaie3c75962009-01-23 11:57:22 +01002768static struct snd_kcontrol_new stac_input_src_temp = {
2769 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2770 .name = "Input Source",
2771 .info = stac92xx_mux_enum_info,
2772 .get = stac92xx_mux_enum_get,
2773 .put = stac92xx_mux_enum_put,
2774};
2775
2776static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2777{
2778 struct snd_kcontrol_new *knew;
2779 struct hda_input_mux *imux = &spec->private_imux;
2780
2781 if (!spec->num_adcs || imux->num_items <= 1)
2782 return 0; /* no need for input source control */
2783 knew = stac_control_new(spec, &stac_input_src_temp,
2784 stac_input_src_temp.name);
2785 if (!knew)
2786 return -ENOMEM;
2787 knew->count = spec->num_adcs;
2788 return 0;
2789}
2790
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002791/* check whether the line-input can be used as line-out */
2792static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002793{
2794 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002795 struct auto_pin_cfg *cfg = &spec->autocfg;
2796 hda_nid_t nid;
2797 unsigned int pincap;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002798
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002799 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2800 return 0;
2801 nid = cfg->input_pins[AUTO_PIN_LINE];
2802 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
2803 if (pincap & AC_PINCAP_OUT)
2804 return nid;
Matt Porter403d1942005-11-29 15:00:51 +01002805 return 0;
2806}
2807
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002808/* check whether the mic-input can be used as line-out */
2809static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2810{
2811 struct sigmatel_spec *spec = codec->spec;
2812 struct auto_pin_cfg *cfg = &spec->autocfg;
2813 unsigned int def_conf, pincap;
2814 unsigned int mic_pin;
2815
2816 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2817 return 0;
2818 mic_pin = AUTO_PIN_MIC;
2819 for (;;) {
2820 hda_nid_t nid = cfg->input_pins[mic_pin];
Takashi Iwai330ee992009-02-20 14:33:36 +01002821 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002822 /* some laptops have an internal analog microphone
2823 * which can't be used as a output */
2824 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2825 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
2826 if (pincap & AC_PINCAP_OUT)
2827 return nid;
2828 }
2829 if (mic_pin == AUTO_PIN_MIC)
2830 mic_pin = AUTO_PIN_FRONT_MIC;
2831 else
2832 break;
2833 }
2834 return 0;
2835}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002836
2837static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2838{
2839 int i;
2840
2841 for (i = 0; i < spec->multiout.num_dacs; i++) {
2842 if (spec->multiout.dac_nids[i] == nid)
2843 return 1;
2844 }
2845
2846 return 0;
2847}
2848
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002849static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2850{
2851 int i;
2852 if (is_in_dac_nids(spec, nid))
2853 return 1;
2854 for (i = 0; i < spec->autocfg.hp_outs; i++)
2855 if (spec->hp_dacs[i] == nid)
2856 return 1;
2857 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2858 if (spec->speaker_dacs[i] == nid)
2859 return 1;
2860 return 0;
2861}
2862
2863static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2864{
2865 struct sigmatel_spec *spec = codec->spec;
2866 int j, conn_len;
2867 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2868 unsigned int wcaps, wtype;
2869
2870 conn_len = snd_hda_get_connections(codec, nid, conn,
2871 HDA_MAX_CONNECTIONS);
2872 for (j = 0; j < conn_len; j++) {
2873 wcaps = snd_hda_param_read(codec, conn[j],
2874 AC_PAR_AUDIO_WIDGET_CAP);
2875 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2876 /* we check only analog outputs */
2877 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2878 continue;
2879 /* if this route has a free DAC, assign it */
2880 if (!check_all_dac_nids(spec, conn[j])) {
2881 if (conn_len > 1) {
2882 /* select this DAC in the pin's input mux */
2883 snd_hda_codec_write_cache(codec, nid, 0,
2884 AC_VERB_SET_CONNECT_SEL, j);
2885 }
2886 return conn[j];
2887 }
2888 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002889 /* if all DACs are already assigned, connect to the primary DAC */
2890 if (conn_len > 1) {
2891 for (j = 0; j < conn_len; j++) {
2892 if (conn[j] == spec->multiout.dac_nids[0]) {
2893 snd_hda_codec_write_cache(codec, nid, 0,
2894 AC_VERB_SET_CONNECT_SEL, j);
2895 break;
2896 }
2897 }
2898 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002899 return 0;
2900}
2901
2902static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2903static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2904
Matt Porter3cc08dc2006-01-23 15:27:49 +01002905/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002906 * Fill in the dac_nids table from the parsed pin configuration
2907 * This function only works when every pin in line_out_pins[]
2908 * contains atleast one DAC in its connection list. Some 92xx
2909 * codecs are not connected directly to a DAC, such as the 9200
2910 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002911 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002912static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002913{
2914 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002915 struct auto_pin_cfg *cfg = &spec->autocfg;
2916 int i;
2917 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002918
Mattc7d4b2f2005-06-27 14:59:41 +02002919 for (i = 0; i < cfg->line_outs; i++) {
2920 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002921 dac = get_unassigned_dac(codec, nid);
2922 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002923 if (spec->multiout.num_dacs > 0) {
2924 /* we have already working output pins,
2925 * so let's drop the broken ones again
2926 */
2927 cfg->line_outs = spec->multiout.num_dacs;
2928 break;
2929 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002930 /* error out, no available DAC found */
2931 snd_printk(KERN_ERR
2932 "%s: No available DAC for pin 0x%x\n",
2933 __func__, nid);
2934 return -ENODEV;
2935 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002936 add_spec_dacs(spec, dac);
2937 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002938
Takashi Iwai139e0712009-03-06 12:10:41 +01002939 for (i = 0; i < cfg->hp_outs; i++) {
2940 nid = cfg->hp_pins[i];
2941 dac = get_unassigned_dac(codec, nid);
2942 if (dac) {
2943 if (!spec->multiout.hp_nid)
2944 spec->multiout.hp_nid = dac;
2945 else
2946 add_spec_extra_dacs(spec, dac);
2947 }
2948 spec->hp_dacs[i] = dac;
2949 }
2950
2951 for (i = 0; i < cfg->speaker_outs; i++) {
2952 nid = cfg->speaker_pins[i];
2953 dac = get_unassigned_dac(codec, nid);
2954 if (dac)
2955 add_spec_extra_dacs(spec, dac);
2956 spec->speaker_dacs[i] = dac;
2957 }
2958
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002959 /* add line-in as output */
2960 nid = check_line_out_switch(codec);
2961 if (nid) {
2962 dac = get_unassigned_dac(codec, nid);
2963 if (dac) {
2964 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2965 nid, cfg->line_outs);
2966 cfg->line_out_pins[cfg->line_outs] = nid;
2967 cfg->line_outs++;
2968 spec->line_switch = nid;
2969 add_spec_dacs(spec, dac);
2970 }
2971 }
2972 /* add mic as output */
2973 nid = check_mic_out_switch(codec);
2974 if (nid) {
2975 dac = get_unassigned_dac(codec, nid);
2976 if (dac) {
2977 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
2978 nid, cfg->line_outs);
2979 cfg->line_out_pins[cfg->line_outs] = nid;
2980 cfg->line_outs++;
2981 spec->mic_switch = nid;
2982 add_spec_dacs(spec, dac);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002983 }
Mattc7d4b2f2005-06-27 14:59:41 +02002984 }
2985
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002986 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02002987 spec->multiout.num_dacs,
2988 spec->multiout.dac_nids[0],
2989 spec->multiout.dac_nids[1],
2990 spec->multiout.dac_nids[2],
2991 spec->multiout.dac_nids[3],
2992 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002993
Mattc7d4b2f2005-06-27 14:59:41 +02002994 return 0;
2995}
2996
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002997/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01002998static int create_controls_idx(struct hda_codec *codec, const char *pfx,
2999 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003000{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003001 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003002 char name[32];
3003 int err;
3004
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003005 if (!spec->check_volume_offset) {
3006 unsigned int caps, step, nums, db_scale;
3007 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3008 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3009 AC_AMPCAP_STEP_SIZE_SHIFT;
3010 step = (step + 1) * 25; /* in .01dB unit */
3011 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3012 AC_AMPCAP_NUM_STEPS_SHIFT;
3013 db_scale = nums * step;
3014 /* if dB scale is over -64dB, and finer enough,
3015 * let's reduce it to half
3016 */
3017 if (db_scale > 6400 && nums >= 0x1f)
3018 spec->volume_offset = nums / 2;
3019 spec->check_volume_offset = 1;
3020 }
3021
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003022 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003023 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003024 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3025 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003026 if (err < 0)
3027 return err;
3028 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003029 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003030 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3031 if (err < 0)
3032 return err;
3033 return 0;
3034}
3035
Takashi Iwai668b9652009-03-06 10:13:24 +01003036#define create_controls(codec, pfx, nid, chs) \
3037 create_controls_idx(codec, pfx, 0, nid, chs)
3038
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003039static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3040{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003041 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003042 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3043 return 1;
3044 } else {
3045 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3046 spec->multiout.num_dacs++;
3047 }
3048 return 0;
3049}
3050
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003051static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003052{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003053 int i;
3054 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3055 if (!spec->multiout.extra_out_nid[i]) {
3056 spec->multiout.extra_out_nid[i] = nid;
3057 return 0;
3058 }
3059 }
3060 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3061 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003062}
3063
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003064/* Create output controls
3065 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3066 */
3067static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3068 const hda_nid_t *pins,
3069 const hda_nid_t *dac_nids,
3070 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003071{
Takashi Iwai76624532008-12-19 10:09:47 +01003072 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003073 static const char *chname[4] = {
3074 "Front", "Surround", NULL /*CLFE*/, "Side"
3075 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003076 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003077 int i, err;
3078 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003079
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003080 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3081 nid = dac_nids[i];
3082 if (!nid)
3083 continue;
3084 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003085 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003086 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003087 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003088 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003089 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003090 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003091 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003092
3093 wid_caps = get_wcaps(codec, nid);
3094
3095 if (wid_caps & AC_WCAP_LR_SWAP) {
3096 err = stac92xx_add_control(spec,
3097 STAC_CTL_WIDGET_CLFE_SWITCH,
3098 "Swap Center/LFE Playback Switch", nid);
3099
3100 if (err < 0)
3101 return err;
3102 }
3103
Mattc7d4b2f2005-06-27 14:59:41 +02003104 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003105 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003106 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003107 switch (type) {
3108 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003109 name = "Headphone";
3110 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003111 break;
3112 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003113 name = "Speaker";
3114 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003115 break;
3116 default:
3117 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003118 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003119 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003120 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003121 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003122 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003123 return err;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003124 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3125 wid_caps = get_wcaps(codec, pins[i]);
3126 if (wid_caps & AC_WCAP_UNSOL_CAP)
3127 spec->hp_detect = 1;
3128 }
Mattc7d4b2f2005-06-27 14:59:41 +02003129 }
3130 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003131 return 0;
3132}
3133
3134/* add playback controls from the parsed DAC table */
3135static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3136 const struct auto_pin_cfg *cfg)
3137{
3138 struct sigmatel_spec *spec = codec->spec;
3139 int err;
3140
3141 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3142 spec->multiout.dac_nids,
3143 cfg->line_out_type);
3144 if (err < 0)
3145 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003146
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003147 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003148 err = stac92xx_add_control(spec,
3149 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003150 "Headphone as Line Out Switch",
3151 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003152 if (err < 0)
3153 return err;
3154 }
3155
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003156 if (spec->line_switch) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003157 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH,
3158 "Line In as Output Switch",
3159 spec->line_switch << 8);
3160 if (err < 0)
3161 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003162 }
Matt Porter403d1942005-11-29 15:00:51 +01003163
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003164 if (spec->mic_switch) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003165 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH,
3166 "Mic as Output Switch",
3167 (spec->mic_switch << 8) | 1);
3168 if (err < 0)
3169 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003170 }
Matt Porter403d1942005-11-29 15:00:51 +01003171
Mattc7d4b2f2005-06-27 14:59:41 +02003172 return 0;
3173}
3174
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003175/* add playback controls for Speaker and HP outputs */
3176static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3177 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003178{
3179 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003180 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003181
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003182 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3183 spec->hp_dacs, AUTO_PIN_HP_OUT);
3184 if (err < 0)
3185 return err;
3186
3187 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3188 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3189 if (err < 0)
3190 return err;
3191
Mattc7d4b2f2005-06-27 14:59:41 +02003192 return 0;
3193}
3194
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003195/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003196static const char *stac92xx_mono_labels[4] = {
3197 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003198};
3199
3200/* create mono mux for mono out on capable codecs */
3201static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3202{
3203 struct sigmatel_spec *spec = codec->spec;
3204 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3205 int i, num_cons;
3206 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3207
3208 num_cons = snd_hda_get_connections(codec,
3209 spec->mono_nid,
3210 con_lst,
3211 HDA_MAX_NUM_INPUTS);
3212 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3213 return -EINVAL;
3214
3215 for (i = 0; i < num_cons; i++) {
3216 mono_mux->items[mono_mux->num_items].label =
3217 stac92xx_mono_labels[i];
3218 mono_mux->items[mono_mux->num_items].index = i;
3219 mono_mux->num_items++;
3220 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003221
3222 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3223 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003224}
3225
Matthew Ranostay89385032008-09-11 09:49:39 -04003226/* labels for amp mux outputs */
3227static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003228 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003229};
3230
3231/* create amp out controls mux on capable codecs */
3232static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3233{
3234 struct sigmatel_spec *spec = codec->spec;
3235 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3236 int i, err;
3237
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003238 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003239 amp_mux->items[amp_mux->num_items].label =
3240 stac92xx_amp_labels[i];
3241 amp_mux->items[amp_mux->num_items].index = i;
3242 amp_mux->num_items++;
3243 }
3244
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003245 if (spec->num_amps > 1) {
3246 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3247 "Amp Selector Capture Switch", 0);
3248 if (err < 0)
3249 return err;
3250 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003251 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3252 "Amp Capture Volume",
3253 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3254}
3255
3256
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003257/* create PC beep volume controls */
3258static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3259 hda_nid_t nid)
3260{
3261 struct sigmatel_spec *spec = codec->spec;
3262 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3263 int err;
3264
3265 /* check for mute support for the the amp */
3266 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3267 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3268 "PC Beep Playback Switch",
3269 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3270 if (err < 0)
3271 return err;
3272 }
3273
3274 /* check to see if there is volume support for the amp */
3275 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3276 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3277 "PC Beep Playback Volume",
3278 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3279 if (err < 0)
3280 return err;
3281 }
3282 return 0;
3283}
3284
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003285#ifdef CONFIG_SND_HDA_INPUT_BEEP
3286#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3287
3288static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3289 struct snd_ctl_elem_value *ucontrol)
3290{
3291 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3292 ucontrol->value.integer.value[0] = codec->beep->enabled;
3293 return 0;
3294}
3295
3296static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3297 struct snd_ctl_elem_value *ucontrol)
3298{
3299 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3300 int enabled = !!ucontrol->value.integer.value[0];
3301 if (codec->beep->enabled != enabled) {
3302 codec->beep->enabled = enabled;
3303 return 1;
3304 }
3305 return 0;
3306}
3307
3308static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3309 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3310 .info = stac92xx_dig_beep_switch_info,
3311 .get = stac92xx_dig_beep_switch_get,
3312 .put = stac92xx_dig_beep_switch_put,
3313};
3314
3315static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3316{
3317 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3318 0, "PC Beep Playback Switch", 0);
3319}
3320#endif
3321
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003322static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3323{
3324 struct sigmatel_spec *spec = codec->spec;
3325 int wcaps, nid, i, err = 0;
3326
3327 for (i = 0; i < spec->num_muxes; i++) {
3328 nid = spec->mux_nids[i];
3329 wcaps = get_wcaps(codec, nid);
3330
3331 if (wcaps & AC_WCAP_OUT_AMP) {
3332 err = stac92xx_add_control_idx(spec,
3333 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3334 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3335 if (err < 0)
3336 return err;
3337 }
3338 }
3339 return 0;
3340};
3341
Matthew Ranostayd9737752008-09-07 12:03:41 +02003342static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003343 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003344};
3345
3346static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3347{
3348 struct sigmatel_spec *spec = codec->spec;
3349 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003350 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003351 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003352 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003353
3354 num_cons = snd_hda_get_connections(codec,
3355 spec->smux_nids[0],
3356 con_lst,
3357 HDA_MAX_NUM_INPUTS);
Matthew Ranostay65973632008-09-16 10:39:37 -04003358 if (!num_cons)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003359 return -EINVAL;
3360
Matthew Ranostay65973632008-09-16 10:39:37 -04003361 if (!labels)
3362 labels = stac92xx_spdif_labels;
3363
Matthew Ranostayd9737752008-09-07 12:03:41 +02003364 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003365 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003366 spdif_mux->items[spdif_mux->num_items].index = i;
3367 spdif_mux->num_items++;
3368 }
3369
3370 return 0;
3371}
3372
Matt Porter8b657272006-10-26 17:12:59 +02003373/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003374static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003375 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3376 "Digital Mic 3", "Digital Mic 4"
3377};
3378
3379/* create playback/capture controls for input pins on dmic capable codecs */
3380static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3381 const struct auto_pin_cfg *cfg)
3382{
3383 struct sigmatel_spec *spec = codec->spec;
3384 struct hda_input_mux *dimux = &spec->private_dimux;
3385 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003386 int err, i, j;
3387 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02003388
3389 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3390 dimux->items[dimux->num_items].index = 0;
3391 dimux->num_items++;
3392
3393 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003394 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003395 int index;
3396 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003397 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02003398 unsigned int def_conf;
3399
Takashi Iwai330ee992009-02-20 14:33:36 +01003400 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
Matt Porter8b657272006-10-26 17:12:59 +02003401 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3402 continue;
3403
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003404 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02003405 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003406 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02003407 con_lst,
3408 HDA_MAX_NUM_INPUTS);
3409 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003410 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02003411 index = j;
3412 goto found;
3413 }
3414 continue;
3415found:
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003416 wcaps = get_wcaps(codec, nid) &
3417 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003418
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003419 if (wcaps) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003420 sprintf(name, "%s Capture Volume",
3421 stac92xx_dmic_labels[dimux->num_items]);
3422
3423 err = stac92xx_add_control(spec,
3424 STAC_CTL_WIDGET_VOL,
3425 name,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003426 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3427 (wcaps & AC_WCAP_OUT_AMP) ?
3428 HDA_OUTPUT : HDA_INPUT));
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003429 if (err < 0)
3430 return err;
3431 }
3432
Matt Porter8b657272006-10-26 17:12:59 +02003433 dimux->items[dimux->num_items].label =
3434 stac92xx_dmic_labels[dimux->num_items];
3435 dimux->items[dimux->num_items].index = index;
3436 dimux->num_items++;
3437 }
3438
3439 return 0;
3440}
3441
Mattc7d4b2f2005-06-27 14:59:41 +02003442/* create playback/capture controls for input pins */
3443static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3444{
3445 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003446 struct hda_input_mux *imux = &spec->private_imux;
3447 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3448 int i, j, k;
3449
3450 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003451 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02003452
Takashi Iwai314634b2006-09-21 11:56:18 +02003453 if (!cfg->input_pins[i])
3454 continue;
3455 index = -1;
3456 for (j = 0; j < spec->num_muxes; j++) {
3457 int num_cons;
3458 num_cons = snd_hda_get_connections(codec,
3459 spec->mux_nids[j],
3460 con_lst,
3461 HDA_MAX_NUM_INPUTS);
3462 for (k = 0; k < num_cons; k++)
3463 if (con_lst[k] == cfg->input_pins[i]) {
3464 index = k;
3465 goto found;
3466 }
Mattc7d4b2f2005-06-27 14:59:41 +02003467 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003468 continue;
3469 found:
3470 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3471 imux->items[imux->num_items].index = index;
3472 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003473 }
3474
Steve Longerbeam7b043892007-05-03 20:50:03 +02003475 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003476 /*
3477 * Set the current input for the muxes.
3478 * The STAC9221 has two input muxes with identical source
3479 * NID lists. Hopefully this won't get confused.
3480 */
3481 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003482 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3483 AC_VERB_SET_CONNECT_SEL,
3484 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003485 }
3486 }
3487
Mattc7d4b2f2005-06-27 14:59:41 +02003488 return 0;
3489}
3490
Mattc7d4b2f2005-06-27 14:59:41 +02003491static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3492{
3493 struct sigmatel_spec *spec = codec->spec;
3494 int i;
3495
3496 for (i = 0; i < spec->autocfg.line_outs; i++) {
3497 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3498 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3499 }
3500}
3501
3502static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3503{
3504 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003505 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003506
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003507 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3508 hda_nid_t pin;
3509 pin = spec->autocfg.hp_pins[i];
3510 if (pin) /* connect to front */
3511 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3512 }
3513 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3514 hda_nid_t pin;
3515 pin = spec->autocfg.speaker_pins[i];
3516 if (pin) /* connect to front */
3517 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3518 }
Mattc7d4b2f2005-06-27 14:59:41 +02003519}
3520
Matt Porter3cc08dc2006-01-23 15:27:49 +01003521static 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 +02003522{
3523 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003524 int hp_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003525 int err;
3526
Matt Porter8b657272006-10-26 17:12:59 +02003527 if ((err = snd_hda_parse_pin_def_config(codec,
3528 &spec->autocfg,
3529 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003530 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003531 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003532 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003533
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003534 /* If we have no real line-out pin and multiple hp-outs, HPs should
3535 * be set up as multi-channel outputs.
3536 */
3537 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3538 spec->autocfg.hp_outs > 1) {
3539 /* Copy hp_outs to line_outs, backup line_outs in
3540 * speaker_outs so that the following routines can handle
3541 * HP pins as primary outputs.
3542 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003543 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003544 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3545 sizeof(spec->autocfg.line_out_pins));
3546 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3547 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3548 sizeof(spec->autocfg.hp_pins));
3549 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003550 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3551 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003552 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003553 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003554 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003555 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3556 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003557 u32 caps = query_amp_caps(codec,
3558 spec->autocfg.mono_out_pin, dir);
3559 hda_nid_t conn_list[1];
3560
3561 /* get the mixer node and then the mono mux if it exists */
3562 if (snd_hda_get_connections(codec,
3563 spec->autocfg.mono_out_pin, conn_list, 1) &&
3564 snd_hda_get_connections(codec, conn_list[0],
3565 conn_list, 1)) {
3566
3567 int wcaps = get_wcaps(codec, conn_list[0]);
3568 int wid_type = (wcaps & AC_WCAP_TYPE)
3569 >> AC_WCAP_TYPE_SHIFT;
3570 /* LR swap check, some stac925x have a mux that
3571 * changes the DACs output path instead of the
3572 * mono-mux path.
3573 */
3574 if (wid_type == AC_WID_AUD_SEL &&
3575 !(wcaps & AC_WCAP_LR_SWAP))
3576 spec->mono_nid = conn_list[0];
3577 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003578 if (dir) {
3579 hda_nid_t nid = spec->autocfg.mono_out_pin;
3580
3581 /* most mono outs have a least a mute/unmute switch */
3582 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3583 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3584 "Mono Playback Switch",
3585 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003586 if (err < 0)
3587 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003588 /* check for volume support for the amp */
3589 if ((caps & AC_AMPCAP_NUM_STEPS)
3590 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3591 err = stac92xx_add_control(spec,
3592 STAC_CTL_WIDGET_VOL,
3593 "Mono Playback Volume",
3594 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3595 if (err < 0)
3596 return err;
3597 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003598 }
3599
3600 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3601 AC_PINCTL_OUT_EN);
3602 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003603
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003604 if (!spec->multiout.num_dacs) {
3605 err = stac92xx_auto_fill_dac_nids(codec);
3606 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003607 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003608 err = stac92xx_auto_create_multi_out_ctls(codec,
3609 &spec->autocfg);
3610 if (err < 0)
3611 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003612 }
Mattc7d4b2f2005-06-27 14:59:41 +02003613
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003614 /* setup analog beep controls */
3615 if (spec->anabeep_nid > 0) {
3616 err = stac92xx_auto_create_beep_ctls(codec,
3617 spec->anabeep_nid);
3618 if (err < 0)
3619 return err;
3620 }
3621
3622 /* setup digital beep controls and input device */
3623#ifdef CONFIG_SND_HDA_INPUT_BEEP
3624 if (spec->digbeep_nid > 0) {
3625 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003626 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003627
3628 err = stac92xx_auto_create_beep_ctls(codec, nid);
3629 if (err < 0)
3630 return err;
3631 err = snd_hda_attach_beep_device(codec, nid);
3632 if (err < 0)
3633 return err;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003634 /* if no beep switch is available, make its own one */
3635 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3636 if (codec->beep &&
3637 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3638 err = stac92xx_beep_switch_ctl(codec);
3639 if (err < 0)
3640 return err;
3641 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003642 }
3643#endif
3644
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003645 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003646 if (err < 0)
3647 return err;
3648
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003649 /* All output parsing done, now restore the swapped hp pins */
3650 if (hp_swap) {
3651 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3652 sizeof(spec->autocfg.hp_pins));
3653 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3654 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3655 spec->autocfg.line_outs = 0;
3656 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003657
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003658 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003659 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003660 return err;
3661
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003662 if (spec->mono_nid > 0) {
3663 err = stac92xx_auto_create_mono_output_ctls(codec);
3664 if (err < 0)
3665 return err;
3666 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003667 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003668 err = stac92xx_auto_create_amp_output_ctls(codec);
3669 if (err < 0)
3670 return err;
3671 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003672 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003673 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3674 &spec->autocfg)) < 0)
3675 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003676 if (spec->num_muxes > 0) {
3677 err = stac92xx_auto_create_mux_input_ctls(codec);
3678 if (err < 0)
3679 return err;
3680 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003681 if (spec->num_smuxes > 0) {
3682 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3683 if (err < 0)
3684 return err;
3685 }
Matt Porter8b657272006-10-26 17:12:59 +02003686
Takashi Iwaie3c75962009-01-23 11:57:22 +01003687 err = stac92xx_add_input_source(spec);
3688 if (err < 0)
3689 return err;
3690
Mattc7d4b2f2005-06-27 14:59:41 +02003691 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003692 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003693 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003694
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003695 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003696 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003697 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003698 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003699
Takashi Iwai603c4012008-07-30 15:01:44 +02003700 if (spec->kctls.list)
3701 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003702
3703 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003704 if (!spec->dinput_mux)
3705 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003706 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003707 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04003708 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003709 return 1;
3710}
3711
Takashi Iwai82bc9552006-03-21 11:24:42 +01003712/* add playback controls for HP output */
3713static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3714 struct auto_pin_cfg *cfg)
3715{
3716 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003717 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003718 unsigned int wid_caps;
3719
3720 if (! pin)
3721 return 0;
3722
3723 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003724 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003725 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003726
3727 return 0;
3728}
3729
Richard Fish160ea0d2006-09-06 13:58:25 +02003730/* add playback controls for LFE output */
3731static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3732 struct auto_pin_cfg *cfg)
3733{
3734 struct sigmatel_spec *spec = codec->spec;
3735 int err;
3736 hda_nid_t lfe_pin = 0x0;
3737 int i;
3738
3739 /*
3740 * search speaker outs and line outs for a mono speaker pin
3741 * with an amp. If one is found, add LFE controls
3742 * for it.
3743 */
3744 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3745 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003746 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003747 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3748 if (wcaps == AC_WCAP_OUT_AMP)
3749 /* found a mono speaker with an amp, must be lfe */
3750 lfe_pin = pin;
3751 }
3752
3753 /* if speaker_outs is 0, then speakers may be in line_outs */
3754 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3755 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3756 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003757 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01003758 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01003759 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003760 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003761 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3762 if (wcaps == AC_WCAP_OUT_AMP)
3763 /* found a mono speaker with an amp,
3764 must be lfe */
3765 lfe_pin = pin;
3766 }
3767 }
3768 }
3769
3770 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003771 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003772 if (err < 0)
3773 return err;
3774 }
3775
3776 return 0;
3777}
3778
Mattc7d4b2f2005-06-27 14:59:41 +02003779static int stac9200_parse_auto_config(struct hda_codec *codec)
3780{
3781 struct sigmatel_spec *spec = codec->spec;
3782 int err;
3783
Kailang Yangdf694da2005-12-05 19:42:22 +01003784 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003785 return err;
3786
3787 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3788 return err;
3789
Takashi Iwai82bc9552006-03-21 11:24:42 +01003790 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3791 return err;
3792
Richard Fish160ea0d2006-09-06 13:58:25 +02003793 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3794 return err;
3795
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003796 if (spec->num_muxes > 0) {
3797 err = stac92xx_auto_create_mux_input_ctls(codec);
3798 if (err < 0)
3799 return err;
3800 }
3801
Takashi Iwaie3c75962009-01-23 11:57:22 +01003802 err = stac92xx_add_input_source(spec);
3803 if (err < 0)
3804 return err;
3805
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003806 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02003807 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003808 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003809 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003810
Takashi Iwai603c4012008-07-30 15:01:44 +02003811 if (spec->kctls.list)
3812 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003813
3814 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003815 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003816
3817 return 1;
3818}
3819
Sam Revitch62fe78e2006-05-10 15:09:17 +02003820/*
3821 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3822 * funky external mute control using GPIO pins.
3823 */
3824
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003825static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003826 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003827{
3828 unsigned int gpiostate, gpiomask, gpiodir;
3829
3830 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3831 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003832 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003833
3834 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3835 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003836 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003837
3838 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3839 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003840 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003841
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003842 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003843 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3844
3845 snd_hda_codec_write(codec, codec->afg, 0,
3846 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003847 snd_hda_codec_read(codec, codec->afg, 0,
3848 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003849
3850 msleep(1);
3851
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003852 snd_hda_codec_read(codec, codec->afg, 0,
3853 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003854}
3855
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003856static int stac92xx_add_jack(struct hda_codec *codec,
3857 hda_nid_t nid, int type)
3858{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003859#ifdef CONFIG_SND_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003860 struct sigmatel_spec *spec = codec->spec;
3861 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01003862 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003863 int connectivity = get_defcfg_connect(def_conf);
3864 char name[32];
3865
3866 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3867 return 0;
3868
3869 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3870 jack = snd_array_new(&spec->jacks);
3871 if (!jack)
3872 return -ENOMEM;
3873 jack->nid = nid;
3874 jack->type = type;
3875
3876 sprintf(name, "%s at %s %s Jack",
3877 snd_hda_get_jack_type(def_conf),
3878 snd_hda_get_jack_connectivity(def_conf),
3879 snd_hda_get_jack_location(def_conf));
3880
3881 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003882#else
3883 return 0;
3884#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003885}
3886
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003887static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3888 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003889{
3890 struct sigmatel_event *event;
3891
3892 snd_array_init(&spec->events, sizeof(*event), 32);
3893 event = snd_array_new(&spec->events);
3894 if (!event)
3895 return -ENOMEM;
3896 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003897 event->type = type;
3898 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003899 event->data = data;
3900
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003901 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003902}
3903
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003904static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
3905 hda_nid_t nid, unsigned char type)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003906{
3907 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003908 struct sigmatel_event *event = spec->events.list;
3909 int i;
3910
3911 for (i = 0; i < spec->events.used; i++, event++) {
3912 if (event->nid == nid && event->type == type)
3913 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003914 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003915 return NULL;
3916}
3917
3918static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
3919 unsigned char tag)
3920{
3921 struct sigmatel_spec *spec = codec->spec;
3922 struct sigmatel_event *event = spec->events.list;
3923 int i;
3924
3925 for (i = 0; i < spec->events.used; i++, event++) {
3926 if (event->tag == tag)
3927 return event;
3928 }
3929 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003930}
3931
Takashi Iwai314634b2006-09-21 11:56:18 +02003932static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003933 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02003934{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003935 struct sigmatel_event *event;
3936 int tag;
3937
3938 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
3939 return;
3940 event = stac_get_event(codec, nid, type);
3941 if (event)
3942 tag = event->tag;
3943 else
3944 tag = stac_add_event(codec->spec, nid, type, 0);
3945 if (tag < 0)
3946 return;
3947 snd_hda_codec_write_cache(codec, nid, 0,
3948 AC_VERB_SET_UNSOLICITED_ENABLE,
3949 AC_USRSP_EN | tag);
Takashi Iwai314634b2006-09-21 11:56:18 +02003950}
3951
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003952static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3953{
3954 int i;
3955 for (i = 0; i < cfg->hp_outs; i++)
3956 if (cfg->hp_pins[i] == nid)
3957 return 1; /* nid is a HP-Out */
3958
3959 return 0; /* nid is not a HP-Out */
3960};
3961
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003962static void stac92xx_power_down(struct hda_codec *codec)
3963{
3964 struct sigmatel_spec *spec = codec->spec;
3965
3966 /* power down inactive DACs */
3967 hda_nid_t *dac;
3968 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003969 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01003970 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003971 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3972}
3973
Takashi Iwaif73d3582008-11-25 08:21:51 +01003974static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3975 int enable);
3976
Takashi Iwai6565e4f2009-03-02 14:38:35 +01003977/* override some hints from the hwdep entry */
3978static void stac_store_hints(struct hda_codec *codec)
3979{
3980 struct sigmatel_spec *spec = codec->spec;
3981 const char *p;
3982 int val;
3983
3984 val = snd_hda_get_bool_hint(codec, "hp_detect");
3985 if (val >= 0)
3986 spec->hp_detect = val;
3987 p = snd_hda_get_hint(codec, "gpio_mask");
3988 if (p) {
3989 spec->gpio_mask = simple_strtoul(p, NULL, 0);
3990 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
3991 spec->gpio_mask;
3992 }
3993 p = snd_hda_get_hint(codec, "gpio_dir");
3994 if (p)
3995 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
3996 p = snd_hda_get_hint(codec, "gpio_data");
3997 if (p)
3998 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
3999 p = snd_hda_get_hint(codec, "eapd_mask");
4000 if (p)
4001 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4002 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4003 if (val >= 0)
4004 spec->eapd_switch = val;
4005}
4006
Mattc7d4b2f2005-06-27 14:59:41 +02004007static int stac92xx_init(struct hda_codec *codec)
4008{
4009 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004010 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004011 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004012 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004013
Mattc7d4b2f2005-06-27 14:59:41 +02004014 snd_hda_sequence_write(codec, spec->init);
4015
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004016 /* power down adcs initially */
4017 if (spec->powerdown_adcs)
4018 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004019 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004020 spec->adc_nids[i], 0,
4021 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004022
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004023 /* override some hints */
4024 stac_store_hints(codec);
4025
Takashi Iwaif73d3582008-11-25 08:21:51 +01004026 /* set up GPIO */
4027 gpio = spec->gpio_data;
4028 /* turn on EAPD statically when spec->eapd_switch isn't set.
4029 * otherwise, unsol event will turn it on/off dynamically
4030 */
4031 if (!spec->eapd_switch)
4032 gpio |= spec->eapd_mask;
4033 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4034
Takashi Iwai82bc9552006-03-21 11:24:42 +01004035 /* set up pins */
4036 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004037 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004038 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004039 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004040 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004041 }
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004042 /* force to enable the first line-out; the others are set up
4043 * in unsol_event
4044 */
4045 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004046 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004047 /* fake event to set up pins */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004048 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4049 STAC_HP_EVENT);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004050 } else {
4051 stac92xx_auto_init_multi_out(codec);
4052 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004053 for (i = 0; i < cfg->hp_outs; i++)
4054 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004055 }
4056 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01004057 hda_nid_t nid = cfg->input_pins[i];
4058 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004059 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004060 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4061 /* for mic pins, force to initialize */
4062 pinctl = stac92xx_get_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004063 pinctl |= AC_PINCTL_IN_EN;
4064 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004065 } else {
4066 pinctl = snd_hda_codec_read(codec, nid, 0,
4067 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4068 /* if PINCTL already set then skip */
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004069 if (!(pinctl & AC_PINCTL_IN_EN)) {
4070 pinctl |= AC_PINCTL_IN_EN;
4071 stac92xx_auto_set_pinctl(codec, nid,
4072 pinctl);
4073 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004074 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004075 conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004076 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4077 enable_pin_detect(codec, nid,
4078 STAC_INSERT_EVENT);
4079 stac_issue_unsol_event(codec, nid,
4080 STAC_INSERT_EVENT);
4081 }
Takashi Iwaic960a032006-03-23 17:06:28 +01004082 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004083 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004084 for (i = 0; i < spec->num_dmics; i++)
4085 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4086 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004087 if (cfg->dig_out_pins[0])
4088 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004089 AC_PINCTL_OUT_EN);
4090 if (cfg->dig_in_pin)
4091 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4092 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004093 for (i = 0; i < spec->num_pwrs; i++) {
4094 hda_nid_t nid = spec->pwr_nids[i];
4095 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004096
Takashi Iwaieb632122008-12-19 16:39:48 +01004097 /* power on when no jack detection is available */
4098 if (!spec->hp_detect) {
4099 stac_toggle_power_map(codec, nid, 1);
4100 continue;
4101 }
4102
4103 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004104 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004105
Takashi Iwaif73d3582008-11-25 08:21:51 +01004106 pinctl = snd_hda_codec_read(codec, nid, 0,
4107 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4108 /* outputs are only ports capable of power management
4109 * any attempts on powering down a input port cause the
4110 * referenced VREF to act quirky.
4111 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004112 if (pinctl & AC_PINCTL_IN_EN) {
4113 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004114 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004115 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004116 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004117 def_conf = get_defcfg_connect(def_conf);
4118 /* skip any ports that don't have jacks since presence
4119 * detection is useless */
4120 if (def_conf != AC_JACK_PORT_COMPLEX) {
4121 if (def_conf != AC_JACK_PORT_NONE)
4122 stac_toggle_power_map(codec, nid, 1);
4123 continue;
4124 }
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004125 if (!stac_get_event(codec, nid, STAC_INSERT_EVENT)) {
4126 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
4127 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
4128 }
Takashi Iwaif73d3582008-11-25 08:21:51 +01004129 }
4130 if (spec->dac_list)
4131 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004132 return 0;
4133}
4134
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004135static void stac92xx_free_jacks(struct hda_codec *codec)
4136{
Takashi Iwaie4973e12008-11-18 09:32:42 +01004137#ifdef CONFIG_SND_JACK
Takashi Iwaib94d3532008-11-21 09:08:06 +01004138 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004139 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d3532008-11-21 09:08:06 +01004140 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004141 struct sigmatel_jack *jacks = spec->jacks.list;
4142 int i;
4143 for (i = 0; i < spec->jacks.used; i++)
4144 snd_device_free(codec->bus->card, &jacks[i].jack);
4145 }
4146 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004147#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004148}
4149
Takashi Iwai603c4012008-07-30 15:01:44 +02004150static void stac92xx_free_kctls(struct hda_codec *codec)
4151{
4152 struct sigmatel_spec *spec = codec->spec;
4153
4154 if (spec->kctls.list) {
4155 struct snd_kcontrol_new *kctl = spec->kctls.list;
4156 int i;
4157 for (i = 0; i < spec->kctls.used; i++)
4158 kfree(kctl[i].name);
4159 }
4160 snd_array_free(&spec->kctls);
4161}
4162
Matt2f2f4252005-04-13 14:45:30 +02004163static void stac92xx_free(struct hda_codec *codec)
4164{
Mattc7d4b2f2005-06-27 14:59:41 +02004165 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004166
4167 if (! spec)
4168 return;
4169
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004170 stac92xx_free_jacks(codec);
4171 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004172
Mattc7d4b2f2005-06-27 14:59:41 +02004173 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004174 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004175}
4176
Matt4e550962005-07-04 17:51:39 +02004177static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4178 unsigned int flag)
4179{
Takashi Iwai8ce841982009-01-22 16:59:20 +01004180 unsigned int old_ctl, pin_ctl;
4181
4182 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004183 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004184
Takashi Iwaif9acba42007-05-29 18:01:06 +02004185 if (pin_ctl & AC_PINCTL_IN_EN) {
4186 /*
4187 * we need to check the current set-up direction of
4188 * shared input pins since they can be switched via
4189 * "xxx as Output" mixer switch
4190 */
4191 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004192 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004193 return;
4194 }
4195
Takashi Iwai8ce841982009-01-22 16:59:20 +01004196 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004197 /* if setting pin direction bits, clear the current
4198 direction bits first */
4199 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4200 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4201
Takashi Iwai8ce841982009-01-22 16:59:20 +01004202 pin_ctl |= flag;
4203 if (old_ctl != pin_ctl)
4204 snd_hda_codec_write_cache(codec, nid, 0,
4205 AC_VERB_SET_PIN_WIDGET_CONTROL,
4206 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004207}
4208
4209static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4210 unsigned int flag)
4211{
4212 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4213 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce841982009-01-22 16:59:20 +01004214 if (pin_ctl & flag)
4215 snd_hda_codec_write_cache(codec, nid, 0,
4216 AC_VERB_SET_PIN_WIDGET_CONTROL,
4217 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004218}
4219
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004220static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004221{
4222 if (!nid)
4223 return 0;
4224 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004225 & (1 << 31))
4226 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004227 return 0;
4228}
4229
Takashi Iwaid7a89432008-11-12 09:48:04 +01004230/* return non-zero if the hp-pin of the given array index isn't
4231 * a jack-detection target
4232 */
4233static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4234{
4235 struct auto_pin_cfg *cfg = &spec->autocfg;
4236
4237 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004238 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004239 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004240 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004241 return 1;
4242 /* ignore if the pin is set as line-out */
4243 if (cfg->hp_pins[i] == spec->hp_switch)
4244 return 1;
4245 return 0;
4246}
4247
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004248static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004249{
4250 struct sigmatel_spec *spec = codec->spec;
4251 struct auto_pin_cfg *cfg = &spec->autocfg;
4252 int i, presence;
4253
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004254 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004255 if (spec->gpio_mute)
4256 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4257 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4258
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004259 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004260 if (presence)
4261 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004262 if (no_hp_sensing(spec, i))
4263 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004264 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4265 if (presence) {
4266 unsigned int pinctl;
4267 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4268 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4269 if (pinctl & AC_PINCTL_IN_EN)
4270 presence = 0; /* mic- or line-input */
4271 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004272 }
Matt4e550962005-07-04 17:51:39 +02004273
4274 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004275 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004276 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004277 stac92xx_reset_pinctl(codec, spec->hp_switch,
4278 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004279 for (i = 0; i < cfg->line_outs; i++)
4280 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4281 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004282 for (i = 0; i < cfg->speaker_outs; i++)
4283 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4284 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004285 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004286 stac_gpio_set(codec, spec->gpio_mask,
4287 spec->gpio_dir, spec->gpio_data &
4288 ~spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004289 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004290 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004291 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004292 stac92xx_set_pinctl(codec, spec->hp_switch,
4293 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004294 for (i = 0; i < cfg->line_outs; i++)
4295 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4296 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004297 for (i = 0; i < cfg->speaker_outs; i++)
4298 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4299 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004300 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004301 stac_gpio_set(codec, spec->gpio_mask,
4302 spec->gpio_dir, spec->gpio_data |
4303 spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004304 }
Takashi Iwaid7a89432008-11-12 09:48:04 +01004305 /* toggle hp outs */
4306 for (i = 0; i < cfg->hp_outs; i++) {
4307 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4308 if (no_hp_sensing(spec, i))
4309 continue;
4310 if (presence)
4311 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004312#if 0 /* FIXME */
4313/* Resetting the pinctl like below may lead to (a sort of) regressions
4314 * on some devices since they use the HP pin actually for line/speaker
4315 * outs although the default pin config shows a different pin (that is
4316 * wrong and useless).
4317 *
4318 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4319 * But, disabling the code below just works around it, and I'm too tired of
4320 * bug reports with such devices...
4321 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004322 else
4323 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004324#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004325 }
Matt4e550962005-07-04 17:51:39 +02004326}
4327
Takashi Iwaif73d3582008-11-25 08:21:51 +01004328static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4329 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004330{
4331 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004332 unsigned int idx, val;
4333
4334 for (idx = 0; idx < spec->num_pwrs; idx++) {
4335 if (spec->pwr_nids[idx] == nid)
4336 break;
4337 }
4338 if (idx >= spec->num_pwrs)
4339 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004340
4341 /* several codecs have two power down bits */
4342 if (spec->pwr_mapping)
4343 idx = spec->pwr_mapping[idx];
4344 else
4345 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004346
Takashi Iwaif73d3582008-11-25 08:21:51 +01004347 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4348 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004349 val &= ~idx;
4350 else
4351 val |= idx;
4352
4353 /* power down unused output ports */
4354 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004355}
4356
Takashi Iwaif73d3582008-11-25 08:21:51 +01004357static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4358{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004359 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004360}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004361
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004362static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4363{
4364 struct sigmatel_spec *spec = codec->spec;
4365 struct sigmatel_jack *jacks = spec->jacks.list;
4366
4367 if (jacks) {
4368 int i;
4369 for (i = 0; i < spec->jacks.used; i++) {
4370 if (jacks->nid == nid) {
4371 unsigned int pin_ctl =
4372 snd_hda_codec_read(codec, nid,
4373 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4374 0x00);
4375 int type = jacks->type;
4376 if (type == (SND_JACK_LINEOUT
4377 | SND_JACK_HEADPHONE))
4378 type = (pin_ctl & AC_PINCTL_HP_EN)
4379 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4380 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004381 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004382 ? type : 0);
4383 }
4384 jacks++;
4385 }
4386 }
4387}
Matt2f2f4252005-04-13 14:45:30 +02004388
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004389static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4390 unsigned char type)
4391{
4392 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4393 if (!event)
4394 return;
4395 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4396}
4397
Takashi Iwai314634b2006-09-21 11:56:18 +02004398static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4399{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004400 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004401 struct sigmatel_event *event;
4402 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004403
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004404 tag = (res >> 26) & 0x7f;
4405 event = stac_get_event_from_tag(codec, tag);
4406 if (!event)
4407 return;
4408
4409 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004410 case STAC_HP_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004411 stac92xx_hp_detect(codec);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004412 /* fallthru */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004413 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004414 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004415 if (spec->num_pwrs > 0)
4416 stac92xx_pin_sense(codec, event->nid);
4417 stac92xx_report_jack(codec, event->nid);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004418 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004419 case STAC_VREF_EVENT:
4420 data = snd_hda_codec_read(codec, codec->afg, 0,
4421 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004422 /* toggle VREF state based on GPIOx status */
4423 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004424 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004425 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004426 }
4427}
4428
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004429#ifdef CONFIG_PROC_FS
4430static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4431 struct hda_codec *codec, hda_nid_t nid)
4432{
4433 if (nid == codec->afg)
4434 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4435 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4436}
4437
4438static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4439 struct hda_codec *codec,
4440 unsigned int verb)
4441{
4442 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4443 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4444}
4445
4446/* stac92hd71bxx, stac92hd73xx */
4447static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4448 struct hda_codec *codec, hda_nid_t nid)
4449{
4450 stac92hd_proc_hook(buffer, codec, nid);
4451 if (nid == codec->afg)
4452 analog_loop_proc_hook(buffer, codec, 0xfa0);
4453}
4454
4455static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4456 struct hda_codec *codec, hda_nid_t nid)
4457{
4458 if (nid == codec->afg)
4459 analog_loop_proc_hook(buffer, codec, 0xfe0);
4460}
4461
4462static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4463 struct hda_codec *codec, hda_nid_t nid)
4464{
4465 if (nid == codec->afg)
4466 analog_loop_proc_hook(buffer, codec, 0xfeb);
4467}
4468#else
4469#define stac92hd_proc_hook NULL
4470#define stac92hd7x_proc_hook NULL
4471#define stac9205_proc_hook NULL
4472#define stac927x_proc_hook NULL
4473#endif
4474
Takashi Iwaicb53c622007-08-10 17:21:45 +02004475#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004476static int stac92xx_resume(struct hda_codec *codec)
4477{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004478 struct sigmatel_spec *spec = codec->spec;
4479
Takashi Iwai2c885872008-11-18 09:36:55 +01004480 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004481 snd_hda_codec_resume_amp(codec);
4482 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004483 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004484 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004485 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4486 STAC_HP_EVENT);
Mattff6fdc32005-06-27 15:06:52 +02004487 return 0;
4488}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004489
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004490
4491/*
4492 * using power check for controlling mute led of HP HDX notebooks
4493 * check for mute state only on Speakers (nid = 0x10)
4494 *
4495 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4496 * the LED is NOT working properly !
4497 */
4498
4499#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004500static int stac92xx_hp_hdx_check_power_status(struct hda_codec *codec,
4501 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004502{
4503 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004504
4505 if (nid == 0x10) {
4506 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004507 HDA_AMP_MUTE)
4508 spec->gpio_data &= ~0x08; /* orange */
4509 else
4510 spec->gpio_data |= 0x08; /* white */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004511
4512 stac_gpio_set(codec, spec->gpio_mask,
4513 spec->gpio_dir,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004514 spec->gpio_data);
4515 }
4516
4517 return 0;
4518}
4519#endif
4520
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004521static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4522{
4523 struct sigmatel_spec *spec = codec->spec;
4524 if (spec->eapd_mask)
4525 stac_gpio_set(codec, spec->gpio_mask,
4526 spec->gpio_dir, spec->gpio_data &
4527 ~spec->eapd_mask);
4528 return 0;
4529}
Mattff6fdc32005-06-27 15:06:52 +02004530#endif
4531
Matt2f2f4252005-04-13 14:45:30 +02004532static struct hda_codec_ops stac92xx_patch_ops = {
4533 .build_controls = stac92xx_build_controls,
4534 .build_pcms = stac92xx_build_pcms,
4535 .init = stac92xx_init,
4536 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004537 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004538#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004539 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004540 .resume = stac92xx_resume,
4541#endif
Matt2f2f4252005-04-13 14:45:30 +02004542};
4543
4544static int patch_stac9200(struct hda_codec *codec)
4545{
4546 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004547 int err;
Matt2f2f4252005-04-13 14:45:30 +02004548
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004549 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004550 if (spec == NULL)
4551 return -ENOMEM;
4552
4553 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004554 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004555 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004556 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4557 stac9200_models,
4558 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01004559 if (spec->board_config < 0)
Richard Fish11b44bb2006-08-23 18:31:34 +02004560 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01004561 else
4562 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004563 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02004564
4565 spec->multiout.max_channels = 2;
4566 spec->multiout.num_dacs = 1;
4567 spec->multiout.dac_nids = stac9200_dac_nids;
4568 spec->adc_nids = stac9200_adc_nids;
4569 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004570 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004571 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004572 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004573 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004574
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02004575 if (spec->board_config == STAC_9200_M4 ||
4576 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01004577 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004578 spec->init = stac9200_eapd_init;
4579 else
4580 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004581 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004582
Takashi Iwai117f2572008-03-18 09:53:23 +01004583 if (spec->board_config == STAC_9200_PANASONIC) {
4584 spec->gpio_mask = spec->gpio_dir = 0x09;
4585 spec->gpio_data = 0x00;
4586 }
4587
Mattc7d4b2f2005-06-27 14:59:41 +02004588 err = stac9200_parse_auto_config(codec);
4589 if (err < 0) {
4590 stac92xx_free(codec);
4591 return err;
4592 }
Matt2f2f4252005-04-13 14:45:30 +02004593
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01004594 /* CF-74 has no headphone detection, and the driver should *NOT*
4595 * do detection and HP/speaker toggle because the hardware does it.
4596 */
4597 if (spec->board_config == STAC_9200_PANASONIC)
4598 spec->hp_detect = 0;
4599
Matt2f2f4252005-04-13 14:45:30 +02004600 codec->patch_ops = stac92xx_patch_ops;
4601
4602 return 0;
4603}
4604
Tobin Davis8e21c342007-01-08 11:04:17 +01004605static int patch_stac925x(struct hda_codec *codec)
4606{
4607 struct sigmatel_spec *spec;
4608 int err;
4609
4610 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4611 if (spec == NULL)
4612 return -ENOMEM;
4613
4614 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004615 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004616 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004617
4618 /* Check first for codec ID */
4619 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
4620 STAC_925x_MODELS,
4621 stac925x_models,
4622 stac925x_codec_id_cfg_tbl);
4623
4624 /* Now checks for PCI ID, if codec ID is not found */
4625 if (spec->board_config < 0)
4626 spec->board_config = snd_hda_check_board_config(codec,
4627 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01004628 stac925x_models,
4629 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004630 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004631 if (spec->board_config < 0)
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004632 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
Tobin Davis2c11f952007-05-17 09:36:34 +02004633 "using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01004634 else
4635 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004636 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01004637
4638 spec->multiout.max_channels = 2;
4639 spec->multiout.num_dacs = 1;
4640 spec->multiout.dac_nids = stac925x_dac_nids;
4641 spec->adc_nids = stac925x_adc_nids;
4642 spec->mux_nids = stac925x_mux_nids;
4643 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004644 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004645 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004646 switch (codec->vendor_id) {
4647 case 0x83847632: /* STAC9202 */
4648 case 0x83847633: /* STAC9202D */
4649 case 0x83847636: /* STAC9251 */
4650 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004651 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004652 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004653 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4654 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004655 break;
4656 default:
4657 spec->num_dmics = 0;
4658 break;
4659 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004660
4661 spec->init = stac925x_core_init;
4662 spec->mixer = stac925x_mixer;
4663
4664 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004665 if (!err) {
4666 if (spec->board_config < 0) {
4667 printk(KERN_WARNING "hda_codec: No auto-config is "
4668 "available, default to model=ref\n");
4669 spec->board_config = STAC_925x_REF;
4670 goto again;
4671 }
4672 err = -EINVAL;
4673 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004674 if (err < 0) {
4675 stac92xx_free(codec);
4676 return err;
4677 }
4678
4679 codec->patch_ops = stac92xx_patch_ops;
4680
4681 return 0;
4682}
4683
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004684static struct hda_input_mux stac92hd73xx_dmux = {
4685 .num_items = 4,
4686 .items = {
4687 { "Analog Inputs", 0x0b },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004688 { "Digital Mic 1", 0x09 },
4689 { "Digital Mic 2", 0x0a },
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004690 { "CD", 0x08 },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004691 }
4692};
4693
4694static int patch_stac92hd73xx(struct hda_codec *codec)
4695{
4696 struct sigmatel_spec *spec;
4697 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4698 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004699 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004700
4701 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4702 if (spec == NULL)
4703 return -ENOMEM;
4704
4705 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004706 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004707 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4708 spec->pin_nids = stac92hd73xx_pin_nids;
4709 spec->board_config = snd_hda_check_board_config(codec,
4710 STAC_92HD73XX_MODELS,
4711 stac92hd73xx_models,
4712 stac92hd73xx_cfg_tbl);
4713again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004714 if (spec->board_config < 0)
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004715 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4716 " STAC92HD73XX, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01004717 else
4718 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004719 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004720
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004721 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004722 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4723
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004724 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004725 printk(KERN_WARNING "hda_codec: Could not determine "
4726 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004727 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004728 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004729 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004730 case 0x3: /* 6 Channel */
4731 spec->mixer = stac92hd73xx_6ch_mixer;
4732 spec->init = stac92hd73xx_6ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004733 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004734 break;
4735 case 0x4: /* 8 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004736 spec->mixer = stac92hd73xx_8ch_mixer;
4737 spec->init = stac92hd73xx_8ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004738 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004739 break;
4740 case 0x5: /* 10 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004741 spec->mixer = stac92hd73xx_10ch_mixer;
4742 spec->init = stac92hd73xx_10ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004743 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
4744 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004745 }
4746 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004747
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004748 spec->aloopback_mask = 0x01;
4749 spec->aloopback_shift = 8;
4750
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004751 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004752 spec->mux_nids = stac92hd73xx_mux_nids;
4753 spec->adc_nids = stac92hd73xx_adc_nids;
4754 spec->dmic_nids = stac92hd73xx_dmic_nids;
4755 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004756 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04004757 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004758 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004759
4760 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4761 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01004762 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004763 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4764 sizeof(stac92hd73xx_dmux));
4765
Matthew Ranostaya7662642008-02-21 07:51:14 +01004766 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004767 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004768 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004769 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004770 case STAC_DELL_M6_AMIC:
4771 case STAC_DELL_M6_DMIC:
4772 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004773 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004774 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4775 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004776 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004777 spec->num_amps = 1;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004778
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004779 if (spec->board_config != STAC_DELL_EQ)
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004780 spec->init = dell_m6_core_init;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004781 switch (spec->board_config) {
4782 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01004783 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01004784 spec->num_dmics = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004785 spec->private_dimux.num_items = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004786 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004787 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01004788 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01004789 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004790 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004791 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004792 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01004793 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
4794 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01004795 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004796 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004797 break;
4798 }
4799 break;
4800 default:
4801 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004802 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004803 spec->eapd_switch = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004804 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04004805 if (spec->board_config > STAC_92HD73XX_REF) {
4806 /* GPIO0 High = Enable EAPD */
4807 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4808 spec->gpio_data = 0x01;
4809 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004810 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004811
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004812 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4813 spec->pwr_nids = stac92hd73xx_pwr_nids;
4814
Matthew Ranostayd9737752008-09-07 12:03:41 +02004815 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004816
4817 if (!err) {
4818 if (spec->board_config < 0) {
4819 printk(KERN_WARNING "hda_codec: No auto-config is "
4820 "available, default to model=ref\n");
4821 spec->board_config = STAC_92HD73XX_REF;
4822 goto again;
4823 }
4824 err = -EINVAL;
4825 }
4826
4827 if (err < 0) {
4828 stac92xx_free(codec);
4829 return err;
4830 }
4831
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01004832 if (spec->board_config == STAC_92HD73XX_NO_JD)
4833 spec->hp_detect = 0;
4834
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004835 codec->patch_ops = stac92xx_patch_ops;
4836
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004837 codec->proc_widget_hook = stac92hd7x_proc_hook;
4838
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004839 return 0;
4840}
4841
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004842static struct hda_input_mux stac92hd83xxx_dmux = {
4843 .num_items = 3,
4844 .items = {
4845 { "Analog Inputs", 0x03 },
4846 { "Digital Mic 1", 0x04 },
4847 { "Digital Mic 2", 0x05 },
4848 }
4849};
4850
4851static int patch_stac92hd83xxx(struct hda_codec *codec)
4852{
4853 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05004854 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004855 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05004856 int num_dacs;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05004857 hda_nid_t nid;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004858
4859 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4860 if (spec == NULL)
4861 return -ENOMEM;
4862
4863 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004864 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004865 spec->mono_nid = 0x19;
4866 spec->digbeep_nid = 0x21;
4867 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4868 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4869 spec->adc_nids = stac92hd83xxx_adc_nids;
4870 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayc15c5062009-01-13 13:30:07 -05004871 spec->amp_nids = stac92hd83xxx_amp_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004872 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4873 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004874 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004875
4876 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004877 spec->mixer = stac92hd83xxx_mixer;
4878 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4879 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4880 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayc15c5062009-01-13 13:30:07 -05004881 spec->num_amps = ARRAY_SIZE(stac92hd83xxx_amp_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004882 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4883 spec->dinput_mux = &stac92hd83xxx_dmux;
4884 spec->pin_nids = stac92hd83xxx_pin_nids;
4885 spec->board_config = snd_hda_check_board_config(codec,
4886 STAC_92HD83XXX_MODELS,
4887 stac92hd83xxx_models,
4888 stac92hd83xxx_cfg_tbl);
4889again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004890 if (spec->board_config < 0)
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004891 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4892 " STAC92HD83XXX, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01004893 else
4894 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004895 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004896
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05004897 switch (codec->vendor_id) {
4898 case 0x111d7604:
4899 case 0x111d7605:
4900 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
4901 break;
4902 spec->num_pwrs = 0;
4903 break;
4904 }
4905
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004906 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4907 if (!err) {
4908 if (spec->board_config < 0) {
4909 printk(KERN_WARNING "hda_codec: No auto-config is "
4910 "available, default to model=ref\n");
4911 spec->board_config = STAC_92HD83XXX_REF;
4912 goto again;
4913 }
4914 err = -EINVAL;
4915 }
4916
4917 if (err < 0) {
4918 stac92xx_free(codec);
4919 return err;
4920 }
4921
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05004922 switch (spec->board_config) {
4923 case STAC_DELL_S14:
4924 nid = 0xf;
4925 break;
4926 default:
4927 nid = 0xe;
4928 break;
4929 }
4930
4931 num_dacs = snd_hda_get_connections(codec, nid,
4932 conn, STAC92HD83_DAC_COUNT + 1) - 1;
4933
4934 /* set port X to select the last DAC
4935 */
4936 snd_hda_codec_write_cache(codec, nid, 0,
4937 AC_VERB_SET_CONNECT_SEL, num_dacs);
4938
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004939 codec->patch_ops = stac92xx_patch_ops;
4940
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004941 codec->proc_widget_hook = stac92hd_proc_hook;
4942
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004943 return 0;
4944}
4945
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05004946static struct hda_input_mux stac92hd71bxx_dmux_nomixer = {
4947 .num_items = 3,
4948 .items = {
4949 { "Analog Inputs", 0x00 },
4950 { "Digital Mic 1", 0x02 },
4951 { "Digital Mic 2", 0x03 },
4952 }
4953};
4954
4955static struct hda_input_mux stac92hd71bxx_dmux_amixer = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004956 .num_items = 4,
4957 .items = {
4958 { "Analog Inputs", 0x00 },
4959 { "Mixer", 0x01 },
4960 { "Digital Mic 1", 0x02 },
4961 { "Digital Mic 2", 0x03 },
4962 }
4963};
4964
Takashi Iwai330ee992009-02-20 14:33:36 +01004965/* get the pin connection (fixed, none, etc) */
4966static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4967{
4968 struct sigmatel_spec *spec = codec->spec;
4969 unsigned int cfg;
4970
4971 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4972 return get_defcfg_connect(cfg);
4973}
4974
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05004975static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
4976 hda_nid_t *nids, int num_nids)
4977{
4978 struct sigmatel_spec *spec = codec->spec;
4979 int idx, num;
4980 unsigned int def_conf;
4981
4982 for (num = 0; num < num_nids; num++) {
4983 for (idx = 0; idx < spec->num_pins; idx++)
4984 if (spec->pin_nids[idx] == nids[num])
4985 break;
4986 if (idx >= spec->num_pins)
4987 break;
Takashi Iwai330ee992009-02-20 14:33:36 +01004988 def_conf = stac_get_defcfg_connect(codec, idx);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05004989 if (def_conf == AC_JACK_PORT_NONE)
4990 break;
4991 }
4992 return num;
4993}
4994
4995static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
4996 hda_nid_t dig0pin)
4997{
4998 struct sigmatel_spec *spec = codec->spec;
4999 int idx;
5000
5001 for (idx = 0; idx < spec->num_pins; idx++)
5002 if (spec->pin_nids[idx] == dig0pin)
5003 break;
5004 if ((idx + 2) >= spec->num_pins)
5005 return 0;
5006
5007 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005008 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005009 return 2;
5010
5011 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005012 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005013 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005014 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005015 return 1;
5016 else
5017 return 0;
5018}
5019
Matthew Ranostaye035b842007-11-06 11:53:55 +01005020static int patch_stac92hd71bxx(struct hda_codec *codec)
5021{
5022 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005023 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005024 int err = 0;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005025 unsigned int ndmic_nids = 0;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005026
5027 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5028 if (spec == NULL)
5029 return -ENOMEM;
5030
5031 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005032 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005033 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5034 switch (codec->vendor_id) {
5035 case 0x111d76b6:
5036 case 0x111d76b7:
5037 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5038 break;
5039 case 0x111d7603:
5040 case 0x111d7608:
5041 /* On 92HD75Bx 0x27 isn't a pin nid */
5042 spec->num_pins--;
5043 /* fallthrough */
5044 default:
5045 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5046 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005047 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005048 spec->board_config = snd_hda_check_board_config(codec,
5049 STAC_92HD71BXX_MODELS,
5050 stac92hd71bxx_models,
5051 stac92hd71bxx_cfg_tbl);
5052again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005053 if (spec->board_config < 0)
Matthew Ranostaye035b842007-11-06 11:53:55 +01005054 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5055 " STAC92HD71BXX, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01005056 else
5057 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005058 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005059
Takashi Iwai41c3b642008-11-18 10:45:15 +01005060 if (spec->board_config > STAC_92HD71BXX_REF) {
5061 /* GPIO0 = EAPD */
5062 spec->gpio_mask = 0x01;
5063 spec->gpio_dir = 0x01;
5064 spec->gpio_data = 0x01;
5065 }
5066
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005067 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5068 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5069
Matthew Ranostay541eee82007-12-14 12:08:04 +01005070 switch (codec->vendor_id) {
5071 case 0x111d76b6: /* 4 Port without Analog Mixer */
5072 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005073 unmute_init++;
5074 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005075 case 0x111d76b4: /* 6 Port without Analog Mixer */
5076 case 0x111d76b5:
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005077 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_nomixer,
5078 sizeof(stac92hd71bxx_dmux_nomixer));
Matthew Ranostay541eee82007-12-14 12:08:04 +01005079 spec->mixer = stac92hd71bxx_mixer;
5080 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005081 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005082 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5083 stac92hd71bxx_dmic_nids,
5084 STAC92HD71BXX_NUM_DMICS);
5085 if (spec->num_dmics) {
5086 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5087 spec->dinput_mux = &spec->private_dimux;
5088 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5089 }
Matthew Ranostay541eee82007-12-14 12:08:04 +01005090 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005091 case 0x111d7608: /* 5 Port with Analog Mixer */
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005092 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5093 sizeof(stac92hd71bxx_dmux_amixer));
5094 spec->private_dimux.num_items--;
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005095 switch (spec->board_config) {
5096 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005097 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005098 err = stac_add_event(spec, codec->afg,
5099 STAC_VREF_EVENT, 0x02);
5100 if (err < 0)
5101 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005102 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005103 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5104 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005105 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005106 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005107 spec->gpio_mask |= 0x02;
5108 break;
5109 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005110 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005111 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005112 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005113
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005114 /* no output amps */
5115 spec->num_pwrs = 0;
5116 spec->mixer = stac92hd71bxx_analog_mixer;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005117 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005118
5119 /* disable VSW */
5120 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005121 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005122 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5123 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005124 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5125 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5126 stac92hd71bxx_dmic_nids,
5127 STAC92HD71BXX_NUM_DMICS - 1);
5128 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5129 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 2;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005130 break;
5131 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005132 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005133 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005134
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005135 /* no output amps */
5136 spec->num_pwrs = 0;
5137 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005138 default:
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005139 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5140 sizeof(stac92hd71bxx_dmux_amixer));
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005141 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005142 spec->mixer = stac92hd71bxx_analog_mixer;
5143 spec->init = stac92hd71bxx_analog_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005144 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005145 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5146 stac92hd71bxx_dmic_nids,
5147 STAC92HD71BXX_NUM_DMICS);
5148 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5149 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005150 }
5151
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005152 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5153 snd_hda_sequence_write_cache(codec, unmute_init);
5154
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005155 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005156 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005157 spec->aloopback_shift = 0;
5158
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005159 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005160 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005161 spec->mux_nids = stac92hd71bxx_mux_nids;
5162 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005163 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005164 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005165
5166 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5167 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005168 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005169
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005170 switch (spec->board_config) {
5171 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005172 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005173 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005174 stac92xx_auto_set_pinctl(codec, 0x0e,
5175 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005176 /* fallthru */
5177 case STAC_DELL_M4_2:
5178 spec->num_dmics = 0;
5179 spec->num_smuxes = 0;
5180 spec->num_dmuxes = 0;
5181 break;
5182 case STAC_DELL_M4_1:
5183 case STAC_DELL_M4_3:
5184 spec->num_dmics = 1;
5185 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005186 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005187 break;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005188 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005189 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005190 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5191 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005192 case STAC_HP_HDX:
5193 spec->num_dmics = 1;
5194 spec->num_dmuxes = 1;
5195 spec->num_smuxes = 1;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005196 /*
Christoph Plattner443e26d2009-03-10 00:05:56 +01005197 * For controlling MUTE LED on HP HDX16/HDX18 notebooks,
5198 * the CONFIG_SND_HDA_POWER_SAVE is needed to be set.
5199 */
5200#ifdef CONFIG_SND_HDA_POWER_SAVE
5201 /* orange/white mute led on GPIO3, orange=0, white=1 */
5202 spec->gpio_mask |= 0x08;
5203 spec->gpio_dir |= 0x08;
5204 spec->gpio_data |= 0x08; /* set to white */
5205
5206 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005207 codec->patch_ops.check_power_status =
Christoph Plattner443e26d2009-03-10 00:05:56 +01005208 stac92xx_hp_hdx_check_power_status;
5209#endif
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005210 break;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005211 };
5212
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005213 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005214 if (spec->dinput_mux)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005215 spec->private_dimux.num_items += spec->num_dmics - ndmic_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005216
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005217 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005218 if (!err) {
5219 if (spec->board_config < 0) {
5220 printk(KERN_WARNING "hda_codec: No auto-config is "
5221 "available, default to model=ref\n");
5222 spec->board_config = STAC_92HD71BXX_REF;
5223 goto again;
5224 }
5225 err = -EINVAL;
5226 }
5227
5228 if (err < 0) {
5229 stac92xx_free(codec);
5230 return err;
5231 }
5232
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005233 codec->proc_widget_hook = stac92hd7x_proc_hook;
5234
Matthew Ranostaye035b842007-11-06 11:53:55 +01005235 return 0;
5236};
5237
Matt2f2f4252005-04-13 14:45:30 +02005238static int patch_stac922x(struct hda_codec *codec)
5239{
5240 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005241 int err;
Matt2f2f4252005-04-13 14:45:30 +02005242
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005243 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005244 if (spec == NULL)
5245 return -ENOMEM;
5246
5247 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005248 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005249 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005250 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5251 stac922x_models,
5252 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005253 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005254 spec->gpio_mask = spec->gpio_dir = 0x03;
5255 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005256 /* Intel Macs have all same PCI SSID, so we need to check
5257 * codec SSID to distinguish the exact models
5258 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005259 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005260 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005261
5262 case 0x106b0800:
5263 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005264 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005265 case 0x106b0600:
5266 case 0x106b0700:
5267 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005268 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005269 case 0x106b0e00:
5270 case 0x106b0f00:
5271 case 0x106b1600:
5272 case 0x106b1700:
5273 case 0x106b0200:
5274 case 0x106b1e00:
5275 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005276 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005277 case 0x106b1a00:
5278 case 0x00000100:
5279 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005280 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005281 case 0x106b0a00:
5282 case 0x106b2200:
5283 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005284 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005285 default:
5286 spec->board_config = STAC_INTEL_MAC_V3;
5287 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005288 }
5289 }
5290
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005291 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005292 if (spec->board_config < 0)
Richard Fish11b44bb2006-08-23 18:31:34 +02005293 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
5294 "using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01005295 else
5296 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005297 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005298
Matt2f2f4252005-04-13 14:45:30 +02005299 spec->adc_nids = stac922x_adc_nids;
5300 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005301 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005302 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005303 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005304 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005305
5306 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005307 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005308
5309 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005310
Matt Porter3cc08dc2006-01-23 15:27:49 +01005311 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005312 if (!err) {
5313 if (spec->board_config < 0) {
5314 printk(KERN_WARNING "hda_codec: No auto-config is "
5315 "available, default to model=ref\n");
5316 spec->board_config = STAC_D945_REF;
5317 goto again;
5318 }
5319 err = -EINVAL;
5320 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005321 if (err < 0) {
5322 stac92xx_free(codec);
5323 return err;
5324 }
5325
5326 codec->patch_ops = stac92xx_patch_ops;
5327
Takashi Iwai807a46362007-05-29 19:01:37 +02005328 /* Fix Mux capture level; max to 2 */
5329 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5330 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5331 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5332 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5333 (0 << AC_AMPCAP_MUTE_SHIFT));
5334
Matt Porter3cc08dc2006-01-23 15:27:49 +01005335 return 0;
5336}
5337
5338static int patch_stac927x(struct hda_codec *codec)
5339{
5340 struct sigmatel_spec *spec;
5341 int err;
5342
5343 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5344 if (spec == NULL)
5345 return -ENOMEM;
5346
5347 codec->spec = spec;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005348 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005349 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005350 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005351 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5352 stac927x_models,
5353 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005354 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005355 if (spec->board_config < 0)
Herton Ronaldo Krzesinskic98041f2009-02-11 20:33:15 -02005356 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5357 "STAC927x, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01005358 else
5359 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005360 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005361
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005362 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005363 spec->adc_nids = stac927x_adc_nids;
5364 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5365 spec->mux_nids = stac927x_mux_nids;
5366 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005367 spec->smux_nids = stac927x_smux_nids;
5368 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005369 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005370 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005371 spec->multiout.dac_nids = spec->dac_nids;
5372
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005373 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005374 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005375 case STAC_D965_5ST:
5376 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005377 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005378 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005379 spec->num_dmics = 0;
5380
Tobin Davis93ed1502006-09-01 21:03:12 +02005381 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005382 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005383 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005384 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005385 switch (codec->subsystem_id) {
5386 case 0x10280209:
5387 case 0x1028022e:
5388 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005389 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005390 break;
5391 };
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005392 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005393 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005394 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005395 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005396 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005397 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005398 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005399 case STAC_DELL_3ST:
5400 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005401 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005402 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005403 spec->dmic_nids = stac927x_dmic_nids;
5404 spec->num_dmics = STAC927X_NUM_DMICS;
5405
Tobin Davis93ed1502006-09-01 21:03:12 +02005406 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005407 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005408 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005409 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005410 break;
5411 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005412 if (spec->board_config > STAC_D965_REF) {
5413 /* GPIO0 High = Enable EAPD */
5414 spec->eapd_mask = spec->gpio_mask = 0x01;
5415 spec->gpio_dir = spec->gpio_data = 0x01;
5416 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005417 spec->num_dmics = 0;
5418
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005419 spec->init = stac927x_core_init;
5420 spec->mixer = stac927x_mixer;
5421 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005422
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005423 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005424 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005425 spec->aloopback_mask = 0x40;
5426 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005427 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005428
Matt Porter3cc08dc2006-01-23 15:27:49 +01005429 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005430 if (!err) {
5431 if (spec->board_config < 0) {
5432 printk(KERN_WARNING "hda_codec: No auto-config is "
5433 "available, default to model=ref\n");
5434 spec->board_config = STAC_D965_REF;
5435 goto again;
5436 }
5437 err = -EINVAL;
5438 }
Mattc7d4b2f2005-06-27 14:59:41 +02005439 if (err < 0) {
5440 stac92xx_free(codec);
5441 return err;
5442 }
Matt2f2f4252005-04-13 14:45:30 +02005443
5444 codec->patch_ops = stac92xx_patch_ops;
5445
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005446 codec->proc_widget_hook = stac927x_proc_hook;
5447
Takashi Iwai52987652008-01-16 16:09:47 +01005448 /*
5449 * !!FIXME!!
5450 * The STAC927x seem to require fairly long delays for certain
5451 * command sequences. With too short delays (even if the answer
5452 * is set to RIRB properly), it results in the silence output
5453 * on some hardwares like Dell.
5454 *
5455 * The below flag enables the longer delay (see get_response
5456 * in hda_intel.c).
5457 */
5458 codec->bus->needs_damn_long_delay = 1;
5459
Takashi Iwaie28d8322008-12-17 13:48:29 +01005460 /* no jack detecion for ref-no-jd model */
5461 if (spec->board_config == STAC_D965_REF_NO_JD)
5462 spec->hp_detect = 0;
5463
Matt2f2f4252005-04-13 14:45:30 +02005464 return 0;
5465}
5466
Matt Porterf3302a52006-07-31 12:49:34 +02005467static int patch_stac9205(struct hda_codec *codec)
5468{
5469 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005470 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005471
5472 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5473 if (spec == NULL)
5474 return -ENOMEM;
5475
5476 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005477 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005478 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005479 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5480 stac9205_models,
5481 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005482 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005483 if (spec->board_config < 0)
Richard Fish11b44bb2006-08-23 18:31:34 +02005484 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01005485 else
5486 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005487 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02005488
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005489 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005490 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005491 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005492 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005493 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005494 spec->smux_nids = stac9205_smux_nids;
5495 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005496 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005497 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005498 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005499 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005500 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005501
5502 spec->init = stac9205_core_init;
5503 spec->mixer = stac9205_mixer;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005504 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02005505
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005506 spec->aloopback_mask = 0x40;
5507 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01005508 /* Turn on/off EAPD per HP plugging */
5509 if (spec->board_config != STAC_9205_EAPD)
5510 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005511 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005512
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005513 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005514 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005515 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005516 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5517 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005518
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005519 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005520 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5521 if (err < 0)
5522 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005523 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005524 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5525 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005526 AC_VERB_SET_UNSOLICITED_ENABLE,
5527 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005528
5529 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005530 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005531 spec->gpio_mask = 0x1b;
5532 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005533 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005534 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005535 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005536 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005537 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005538 case STAC_9205_REF:
5539 /* SPDIF-In enabled */
5540 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005541 default:
5542 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005543 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005544 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005545 break;
5546 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005547
Matt Porterf3302a52006-07-31 12:49:34 +02005548 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005549 if (!err) {
5550 if (spec->board_config < 0) {
5551 printk(KERN_WARNING "hda_codec: No auto-config is "
5552 "available, default to model=ref\n");
5553 spec->board_config = STAC_9205_REF;
5554 goto again;
5555 }
5556 err = -EINVAL;
5557 }
Matt Porterf3302a52006-07-31 12:49:34 +02005558 if (err < 0) {
5559 stac92xx_free(codec);
5560 return err;
5561 }
5562
5563 codec->patch_ops = stac92xx_patch_ops;
5564
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005565 codec->proc_widget_hook = stac9205_proc_hook;
5566
Matt Porterf3302a52006-07-31 12:49:34 +02005567 return 0;
5568}
5569
Matt2f2f4252005-04-13 14:45:30 +02005570/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005571 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005572 */
5573
Takashi Iwai1e137f92009-01-21 07:41:22 +01005574static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02005575 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005576 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5577 {}
5578};
5579
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005580static struct snd_kcontrol_new stac9872_mixer[] = {
5581 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5582 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005583 { } /* end */
5584};
5585
5586static hda_nid_t stac9872_pin_nids[] = {
5587 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5588 0x11, 0x13, 0x14,
5589};
5590
5591static hda_nid_t stac9872_adc_nids[] = {
5592 0x8 /*,0x6*/
5593};
5594
5595static hda_nid_t stac9872_mux_nids[] = {
5596 0x15
5597};
5598
Takashi Iwai307282c2009-03-12 18:17:58 +01005599static unsigned int stac9872_vaio_pin_configs[9] = {
5600 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
5601 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
5602 0x90a7013e
5603};
5604
5605static const char *stac9872_models[STAC_9872_MODELS] = {
5606 [STAC_9872_AUTO] = "auto",
5607 [STAC_9872_VAIO] = "vaio",
5608};
5609
5610static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
5611 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
5612};
5613
5614static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5615 {} /* terminator */
5616};
5617
Guillaume Munch6d859062006-08-22 17:15:47 +02005618static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005619{
5620 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01005621 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005622
Takashi Iwaidb064e52006-03-16 16:04:58 +01005623 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5624 if (spec == NULL)
5625 return -ENOMEM;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005626 codec->spec = spec;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005627
5628 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5629 stac9872_models,
5630 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01005631 if (spec->board_config < 0)
5632 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9872, "
5633 "using BIOS defaults\n");
5634 else
5635 stac92xx_set_config_regs(codec,
5636 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005637
Takashi Iwai1e137f92009-01-21 07:41:22 +01005638 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5639 spec->pin_nids = stac9872_pin_nids;
5640 spec->multiout.dac_nids = spec->dac_nids;
5641 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5642 spec->adc_nids = stac9872_adc_nids;
5643 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5644 spec->mux_nids = stac9872_mux_nids;
5645 spec->mixer = stac9872_mixer;
5646 spec->init = stac9872_core_init;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005647
Takashi Iwai1e137f92009-01-21 07:41:22 +01005648 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5649 if (err < 0) {
5650 stac92xx_free(codec);
5651 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005652 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01005653 spec->input_mux = &spec->private_imux;
5654 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005655 return 0;
5656}
5657
5658
5659/*
Matt2f2f4252005-04-13 14:45:30 +02005660 * patch entries
5661 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005662static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02005663 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5664 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5665 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5666 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5667 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5668 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5669 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005670 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5671 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5672 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5673 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5674 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5675 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005676 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5677 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5678 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5679 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5680 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5681 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5682 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5683 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5684 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5685 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005686 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5687 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5688 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5689 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5690 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5691 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005692 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5693 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005694 /* The following does not take into account .id=0x83847661 when subsys =
5695 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5696 * currently not fully supported.
5697 */
5698 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5699 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5700 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02005701 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5702 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5703 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5704 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5705 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5706 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5707 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5708 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005709 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005710 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5711 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005712 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005713 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5714 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005715 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005716 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5717 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5718 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5719 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5720 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5721 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5722 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5723 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005724 {} /* terminator */
5725};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005726
5727MODULE_ALIAS("snd-hda-codec-id:8384*");
5728MODULE_ALIAS("snd-hda-codec-id:111d*");
5729
5730MODULE_LICENSE("GPL");
5731MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5732
5733static struct hda_codec_preset_list sigmatel_list = {
5734 .preset = snd_hda_preset_sigmatel,
5735 .owner = THIS_MODULE,
5736};
5737
5738static int __init patch_sigmatel_init(void)
5739{
5740 return snd_hda_add_codec_preset(&sigmatel_list);
5741}
5742
5743static void __exit patch_sigmatel_exit(void)
5744{
5745 snd_hda_delete_codec_preset(&sigmatel_list);
5746}
5747
5748module_init(patch_sigmatel_init)
5749module_exit(patch_sigmatel_exit)