blob: fb9f4ccba885d5fb6c112d797418aa978bae93ec [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
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400158struct sigmatel_event {
159 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100160 unsigned char type;
161 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400162 int data;
163};
164
165struct sigmatel_jack {
166 hda_nid_t nid;
167 int type;
168 struct snd_jack *jack;
169};
170
Matt2f2f4252005-04-13 14:45:30 +0200171struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100172 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200173 unsigned int num_mixers;
174
Matt Porter403d1942005-11-29 15:00:51 +0100175 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500176 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200177 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100178 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100179 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400180 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100181 unsigned int check_volume_offset:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200182
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100183 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200184 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100185 unsigned int gpio_mask;
186 unsigned int gpio_dir;
187 unsigned int gpio_data;
188 unsigned int gpio_mute;
189
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200190 /* stream */
191 unsigned int stream_delay;
192
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100193 /* analog loopback */
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100194 struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100195 unsigned char aloopback_mask;
196 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200197
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100198 /* power management */
199 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200200 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100201 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100202 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100203
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400204 /* jack detection */
205 struct snd_array jacks;
206
207 /* events */
208 struct snd_array events;
209
Matt2f2f4252005-04-13 14:45:30 +0200210 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100211 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400212 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100213 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200214 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100215 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100216 hda_nid_t hp_dacs[5];
217 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200218
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100219 int volume_offset;
220
Matt2f2f4252005-04-13 14:45:30 +0200221 /* capture */
222 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200223 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200224 hda_nid_t *mux_nids;
225 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200226 hda_nid_t *dmic_nids;
227 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100228 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100229 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200230 hda_nid_t *smux_nids;
231 unsigned int num_smuxes;
Matthew Ranostay65973632008-09-16 10:39:37 -0400232 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200233
Mattdabbed62005-06-14 10:19:34 +0200234 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100235 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200236 hda_nid_t anabeep_nid;
237 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200238
Matt2f2f4252005-04-13 14:45:30 +0200239 /* pin widgets */
240 hda_nid_t *pin_nids;
241 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200242
243 /* codec specific stuff */
244 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100245 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200246
247 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200248 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100249 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200250 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100251 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200252 struct hda_input_mux *sinput_mux;
253 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400254 unsigned int cur_amux;
255 hda_nid_t *amp_nids;
256 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200257 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200258
Matt Porter403d1942005-11-29 15:00:51 +0100259 /* i/o switches */
260 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200261 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100262 hda_nid_t line_switch; /* shared line-in for input and output */
263 hda_nid_t mic_switch; /* shared mic-in for input and output */
264 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200265 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200266
Mattc7d4b2f2005-06-27 14:59:41 +0200267 struct hda_pcm pcm_rec[2]; /* PCM information */
268
269 /* dynamic controls and input_mux */
270 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200271 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200272 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200273 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200274 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400275 struct hda_input_mux private_amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100276 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200277};
278
279static hda_nid_t stac9200_adc_nids[1] = {
280 0x03,
281};
282
283static hda_nid_t stac9200_mux_nids[1] = {
284 0x0c,
285};
286
287static hda_nid_t stac9200_dac_nids[1] = {
288 0x02,
289};
290
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100291static hda_nid_t stac92hd73xx_pwr_nids[8] = {
292 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
293 0x0f, 0x10, 0x11
294};
295
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400296static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
297 0x26, 0,
298};
299
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100300static hda_nid_t stac92hd73xx_adc_nids[2] = {
301 0x1a, 0x1b
302};
303
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400304#define DELL_M6_AMP 2
305static hda_nid_t stac92hd73xx_amp_nids[3] = {
306 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400307};
308
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100309#define STAC92HD73XX_NUM_DMICS 2
310static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
311 0x13, 0x14, 0
312};
313
314#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100315
316static hda_nid_t stac92hd73xx_mux_nids[4] = {
317 0x28, 0x29, 0x2a, 0x2b,
318};
319
320static hda_nid_t stac92hd73xx_dmux_nids[2] = {
321 0x20, 0x21,
322};
323
Matthew Ranostayd9737752008-09-07 12:03:41 +0200324static hda_nid_t stac92hd73xx_smux_nids[2] = {
325 0x22, 0x23,
326};
327
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200328#define STAC92HD83XXX_NUM_DMICS 2
329static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
330 0x11, 0x12, 0
331};
332
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200333#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200334
335static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
336 0x17, 0x18,
337};
338
339static hda_nid_t stac92hd83xxx_adc_nids[2] = {
340 0x15, 0x16,
341};
342
343static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
344 0xa, 0xb, 0xd, 0xe,
345};
346
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400347static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
348 0x1e, 0,
349};
350
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200351static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500352 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200353};
354
Takashi Iwai9248f262009-01-14 09:40:25 +0100355static hda_nid_t stac92hd83xxx_amp_nids[1] = {
Matthew Ranostayc15c5062009-01-13 13:30:07 -0500356 0xc,
357};
358
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100359static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
360 0x0a, 0x0d, 0x0f
361};
362
Matthew Ranostaye035b842007-11-06 11:53:55 +0100363static hda_nid_t stac92hd71bxx_adc_nids[2] = {
364 0x12, 0x13,
365};
366
367static hda_nid_t stac92hd71bxx_mux_nids[2] = {
368 0x1a, 0x1b
369};
370
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400371static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
372 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100373};
374
Matthew Ranostayd9737752008-09-07 12:03:41 +0200375static hda_nid_t stac92hd71bxx_smux_nids[2] = {
376 0x24, 0x25,
377};
378
Matthew Ranostaye035b842007-11-06 11:53:55 +0100379#define STAC92HD71BXX_NUM_DMICS 2
380static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
381 0x18, 0x19, 0
382};
383
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400384static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
385 0x22, 0
386};
387
Tobin Davis8e21c342007-01-08 11:04:17 +0100388static hda_nid_t stac925x_adc_nids[1] = {
389 0x03,
390};
391
392static hda_nid_t stac925x_mux_nids[1] = {
393 0x0f,
394};
395
396static hda_nid_t stac925x_dac_nids[1] = {
397 0x02,
398};
399
Takashi Iwaif6e98522007-10-16 14:27:04 +0200400#define STAC925X_NUM_DMICS 1
401static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
402 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200403};
404
Takashi Iwai1697055e2007-12-18 18:05:52 +0100405static hda_nid_t stac925x_dmux_nids[1] = {
406 0x14,
407};
408
Matt2f2f4252005-04-13 14:45:30 +0200409static hda_nid_t stac922x_adc_nids[2] = {
410 0x06, 0x07,
411};
412
413static hda_nid_t stac922x_mux_nids[2] = {
414 0x12, 0x13,
415};
416
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500417static hda_nid_t stac927x_slave_dig_outs[2] = {
418 0x1f, 0,
419};
420
Matt Porter3cc08dc2006-01-23 15:27:49 +0100421static hda_nid_t stac927x_adc_nids[3] = {
422 0x07, 0x08, 0x09
423};
424
425static hda_nid_t stac927x_mux_nids[3] = {
426 0x15, 0x16, 0x17
427};
428
Matthew Ranostayd9737752008-09-07 12:03:41 +0200429static hda_nid_t stac927x_smux_nids[1] = {
430 0x21,
431};
432
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100433static hda_nid_t stac927x_dac_nids[6] = {
434 0x02, 0x03, 0x04, 0x05, 0x06, 0
435};
436
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100437static hda_nid_t stac927x_dmux_nids[1] = {
438 0x1b,
439};
440
Matthew Ranostay7f168592007-10-18 17:38:17 +0200441#define STAC927X_NUM_DMICS 2
442static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
443 0x13, 0x14, 0
444};
445
Matthew Ranostay65973632008-09-16 10:39:37 -0400446static const char *stac927x_spdif_labels[5] = {
447 "Digital Playback", "ADAT", "Analog Mux 1",
448 "Analog Mux 2", "Analog Mux 3"
449};
450
Matt Porterf3302a52006-07-31 12:49:34 +0200451static hda_nid_t stac9205_adc_nids[2] = {
452 0x12, 0x13
453};
454
455static hda_nid_t stac9205_mux_nids[2] = {
456 0x19, 0x1a
457};
458
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100459static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100460 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100461};
462
Matthew Ranostayd9737752008-09-07 12:03:41 +0200463static hda_nid_t stac9205_smux_nids[1] = {
464 0x21,
465};
466
Takashi Iwaif6e98522007-10-16 14:27:04 +0200467#define STAC9205_NUM_DMICS 2
468static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
469 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200470};
471
Mattc7d4b2f2005-06-27 14:59:41 +0200472static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200473 0x08, 0x09, 0x0d, 0x0e,
474 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200475};
476
Tobin Davis8e21c342007-01-08 11:04:17 +0100477static hda_nid_t stac925x_pin_nids[8] = {
478 0x07, 0x08, 0x0a, 0x0b,
479 0x0c, 0x0d, 0x10, 0x11,
480};
481
Matt2f2f4252005-04-13 14:45:30 +0200482static hda_nid_t stac922x_pin_nids[10] = {
483 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
484 0x0f, 0x10, 0x11, 0x15, 0x1b,
485};
486
Matthew Ranostaya7662642008-02-21 07:51:14 +0100487static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100488 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
489 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200490 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100491};
492
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500493static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200494 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500495 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200496};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500497
498#define STAC92HD71BXX_NUM_PINS 13
499static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
500 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
501 0x00, 0x14, 0x18, 0x19, 0x1e,
502 0x1f, 0x20, 0x27
503};
504static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100505 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
506 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500507 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100508};
509
Matt Porter3cc08dc2006-01-23 15:27:49 +0100510static hda_nid_t stac927x_pin_nids[14] = {
511 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
512 0x0f, 0x10, 0x11, 0x12, 0x13,
513 0x14, 0x21, 0x22, 0x23,
514};
515
Matt Porterf3302a52006-07-31 12:49:34 +0200516static hda_nid_t stac9205_pin_nids[12] = {
517 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
518 0x0f, 0x14, 0x16, 0x17, 0x18,
519 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200520};
521
Matthew Ranostay89385032008-09-11 09:49:39 -0400522#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
523
524static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
525 struct snd_ctl_elem_value *ucontrol)
526{
527 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
528 struct sigmatel_spec *spec = codec->spec;
529 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
530
531 kcontrol->private_value ^= get_amp_nid(kcontrol);
532 kcontrol->private_value |= nid;
533
534 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
535}
536
537static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
538 struct snd_ctl_elem_value *ucontrol)
539{
540 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
541 struct sigmatel_spec *spec = codec->spec;
542 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
543
544 kcontrol->private_value ^= get_amp_nid(kcontrol);
545 kcontrol->private_value |= nid;
546
547 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
548}
549
Matt Porter8b657272006-10-26 17:12:59 +0200550static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
551 struct snd_ctl_elem_info *uinfo)
552{
553 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
554 struct sigmatel_spec *spec = codec->spec;
555 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
556}
557
558static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
559 struct snd_ctl_elem_value *ucontrol)
560{
561 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
562 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100563 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200564
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100565 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200566 return 0;
567}
568
569static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
570 struct snd_ctl_elem_value *ucontrol)
571{
572 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
573 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100574 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200575
576 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100577 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200578}
579
Matthew Ranostayd9737752008-09-07 12:03:41 +0200580static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
581 struct snd_ctl_elem_info *uinfo)
582{
583 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
584 struct sigmatel_spec *spec = codec->spec;
585 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
586}
587
588static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
589 struct snd_ctl_elem_value *ucontrol)
590{
591 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
592 struct sigmatel_spec *spec = codec->spec;
593 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
594
595 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
596 return 0;
597}
598
599static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
600 struct snd_ctl_elem_value *ucontrol)
601{
602 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
603 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400604 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200605 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400606 int err, val;
607 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200608
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400609 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200610 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400611 if (err < 0)
612 return err;
613
614 if (spec->spdif_mute) {
615 if (smux_idx == 0)
616 nid = spec->multiout.dig_out_nid;
617 else
618 nid = codec->slave_dig_outs[smux_idx - 1];
619 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100620 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400621 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100622 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400623 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100624 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
625 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400626 }
627 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200628}
629
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100630static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200631{
632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200634 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200635}
636
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100637static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200638{
639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
640 struct sigmatel_spec *spec = codec->spec;
641 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
642
643 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
644 return 0;
645}
646
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100647static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200648{
649 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
650 struct sigmatel_spec *spec = codec->spec;
651 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
652
Mattc7d4b2f2005-06-27 14:59:41 +0200653 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200654 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
655}
656
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100657static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
658 struct snd_ctl_elem_info *uinfo)
659{
660 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
661 struct sigmatel_spec *spec = codec->spec;
662 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
663}
664
665static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
666 struct snd_ctl_elem_value *ucontrol)
667{
668 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
669 struct sigmatel_spec *spec = codec->spec;
670
671 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
672 return 0;
673}
674
675static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
676 struct snd_ctl_elem_value *ucontrol)
677{
678 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
679 struct sigmatel_spec *spec = codec->spec;
680
681 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
682 spec->mono_nid, &spec->cur_mmux);
683}
684
Matthew Ranostay89385032008-09-11 09:49:39 -0400685static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
686 struct snd_ctl_elem_info *uinfo)
687{
688 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
689 struct sigmatel_spec *spec = codec->spec;
690 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
691}
692
693static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
694 struct snd_ctl_elem_value *ucontrol)
695{
696 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
697 struct sigmatel_spec *spec = codec->spec;
698
699 ucontrol->value.enumerated.item[0] = spec->cur_amux;
700 return 0;
701}
702
703static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
704 struct snd_ctl_elem_value *ucontrol)
705{
706 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
707 struct sigmatel_spec *spec = codec->spec;
708 struct snd_kcontrol *ctl =
709 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
710 if (!ctl)
711 return -EINVAL;
712
713 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
714 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
715
716 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
717 0, &spec->cur_amux);
718}
719
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200720#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
721
722static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
723 struct snd_ctl_elem_value *ucontrol)
724{
725 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100726 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200727 struct sigmatel_spec *spec = codec->spec;
728
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100729 ucontrol->value.integer.value[0] = !!(spec->aloopback &
730 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200731 return 0;
732}
733
734static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
735 struct snd_ctl_elem_value *ucontrol)
736{
737 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
738 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100739 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200740 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100741 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200742
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100743 idx_val = spec->aloopback_mask << idx;
744 if (ucontrol->value.integer.value[0])
745 val = spec->aloopback | idx_val;
746 else
747 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100748 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200749 return 0;
750
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100751 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200752
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100753 /* Only return the bits defined by the shift value of the
754 * first two bytes of the mask
755 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200756 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100757 kcontrol->private_value & 0xFFFF, 0x0);
758 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200759
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100760 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200761 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100762 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200763 } else {
764 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100765 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200766 }
767
768 snd_hda_codec_write_cache(codec, codec->afg, 0,
769 kcontrol->private_value >> 16, dac_mode);
770
771 return 1;
772}
773
Mattc7d4b2f2005-06-27 14:59:41 +0200774static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200775 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200776 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200777 {}
778};
779
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200780static struct hda_verb stac9200_eapd_init[] = {
781 /* set dac0mux for dac converter */
782 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
783 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
784 {}
785};
786
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100787static struct hda_verb stac92hd73xx_6ch_core_init[] = {
788 /* set master volume and direct control */
789 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100790 /* setup adcs to point to mixer */
791 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
792 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100793 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
794 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
795 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
796 /* setup import muxs */
797 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
798 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
799 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
800 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
801 {}
802};
803
Matthew Ranostayd654a662008-03-14 08:46:51 +0100804static struct hda_verb dell_eq_core_init[] = {
805 /* set master volume to max value without distortion
806 * and direct control */
807 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100808 /* setup adcs to point to mixer */
809 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
810 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
811 /* setup import muxs */
812 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
813 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
814 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
815 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
816 {}
817};
818
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100819static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500820 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100821 /* setup adcs to point to mixer */
822 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
823 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
824 /* setup import muxs */
825 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
826 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
827 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
828 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
829 {}
830};
831
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100832static struct hda_verb stac92hd73xx_8ch_core_init[] = {
833 /* set master volume and direct control */
834 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100835 /* setup adcs to point to mixer */
836 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
837 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100838 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
839 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
840 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
841 /* setup import muxs */
842 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
843 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
844 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
845 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
846 {}
847};
848
849static struct hda_verb stac92hd73xx_10ch_core_init[] = {
850 /* set master volume and direct control */
851 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100852 /* dac3 is connected to import3 mux */
853 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100854 /* setup adcs to point to mixer */
855 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
856 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100857 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
858 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
859 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
860 /* setup import muxs */
861 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
862 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
863 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
864 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
865 {}
866};
867
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200868static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500869 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
870 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
871 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200872
873 /* power state controls amps */
874 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200875 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200876};
877
Matthew Ranostaye035b842007-11-06 11:53:55 +0100878static struct hda_verb stac92hd71bxx_core_init[] = {
879 /* set master volume and direct control */
880 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200881 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100882};
883
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500884#define HD_DISABLE_PORTF 1
Matthew Ranostay541eee82007-12-14 12:08:04 +0100885static struct hda_verb stac92hd71bxx_analog_core_init[] = {
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200886 /* start of config #1 */
887
888 /* connect port 0f to audio mixer */
889 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200890 /* start of config #2 */
891
Matthew Ranostay541eee82007-12-14 12:08:04 +0100892 /* set master volume and direct control */
893 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500894 {}
895};
896
897static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
898 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
899 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100900 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
901 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100902 {}
903};
904
Tobin Davis8e21c342007-01-08 11:04:17 +0100905static struct hda_verb stac925x_core_init[] = {
906 /* set dac0mux for dac converter */
907 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100908 /* mute the master volume */
909 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100910 {}
911};
912
Mattc7d4b2f2005-06-27 14:59:41 +0200913static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200914 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200915 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200916 {}
917};
918
Tobin Davis93ed1502006-09-01 21:03:12 +0200919static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200920 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200921 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200922 /* unmute node 0x1b */
923 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
924 /* select node 0x03 as DAC */
925 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
926 {}
927};
928
Matt Porter3cc08dc2006-01-23 15:27:49 +0100929static struct hda_verb stac927x_core_init[] = {
930 /* set master volume and direct control */
931 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200932 /* enable analog pc beep path */
933 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100934 {}
935};
936
Matt Porterf3302a52006-07-31 12:49:34 +0200937static struct hda_verb stac9205_core_init[] = {
938 /* set master volume and direct control */
939 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200940 /* enable analog pc beep path */
941 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200942 {}
943};
944
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100945#define STAC_MONO_MUX \
946 { \
947 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
948 .name = "Mono Mux", \
949 .count = 1, \
950 .info = stac92xx_mono_mux_enum_info, \
951 .get = stac92xx_mono_mux_enum_get, \
952 .put = stac92xx_mono_mux_enum_put, \
953 }
954
Matthew Ranostay89385032008-09-11 09:49:39 -0400955#define STAC_AMP_MUX \
956 { \
957 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
958 .name = "Amp Selector Capture Switch", \
959 .count = 1, \
960 .info = stac92xx_amp_mux_enum_info, \
961 .get = stac92xx_amp_mux_enum_get, \
962 .put = stac92xx_amp_mux_enum_put, \
963 }
964
965#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
966 { \
967 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
968 .name = xname, \
969 .index = 0, \
970 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
971 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
972 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
973 .info = stac92xx_amp_volume_info, \
974 .get = stac92xx_amp_volume_get, \
975 .put = stac92xx_amp_volume_put, \
976 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
977 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
978 }
979
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100980#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200981 { \
982 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
983 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100984 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200985 .info = stac92xx_aloopback_info, \
986 .get = stac92xx_aloopback_get, \
987 .put = stac92xx_aloopback_put, \
988 .private_value = verb_read | (verb_write << 16), \
989 }
990
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100991static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200992 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
993 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200994 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
995 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200996 { } /* end */
997};
998
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400999#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001000static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001001 /* start of config #1 */
1002 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1003 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1004
1005 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1006 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1007
1008 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1009 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1010
1011 /* start of config #2 */
1012 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1013 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1014
1015 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1016 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1017
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001018 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1019 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1020
1021 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1022 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1023
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001024 { } /* end */
1025};
1026
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001027static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1028 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1029 {}
1030};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001031
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001032static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1033 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1034 {}
1035};
1036
1037static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1038 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1039 {}
1040};
1041
1042static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001043 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1044 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1045
1046 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1047 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1048
1049 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1050 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1051
1052 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1053 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1054
1055 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1056 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1057
1058 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1059 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1060
1061 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1062 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1063 { } /* end */
1064};
1065
1066static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001067 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1068 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1069
1070 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1071 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1072
1073 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1074 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1075
1076 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1077 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1078
1079 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1080 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1081
1082 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1083 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1084
1085 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1086 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1087 { } /* end */
1088};
1089
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001090
1091static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1092 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1093 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1094
1095 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1096 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1097
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001098 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1099 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001100
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001101 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1102 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001103
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001104 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1105 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001106
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001107 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1108 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001109
1110 /*
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001111 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1112 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001113 */
1114 { } /* end */
1115};
1116
Matthew Ranostay541eee82007-12-14 12:08:04 +01001117static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostay9b359472007-11-07 13:03:12 +01001118 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1119 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay9b359472007-11-07 13:03:12 +01001120
1121 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1122 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001123 /* analog pc-beep replaced with digital beep support */
1124 /*
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001125 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1126 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001127 */
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001128
Matthew Ranostay687cb982008-10-11 13:52:43 -04001129 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1130 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001131
Matthew Ranostay687cb982008-10-11 13:52:43 -04001132 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1133 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001134
1135 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1136 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1137
1138 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1139 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001140 { } /* end */
1141};
1142
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001143static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1144 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1145};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001146
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001147static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +01001148 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1149 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001150
1151 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1152 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001153 { } /* end */
1154};
1155
Tobin Davis8e21c342007-01-08 11:04:17 +01001156static struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwaic9280d62009-01-15 17:31:00 +01001157 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1158 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Tobin Davis8e21c342007-01-08 11:04:17 +01001159 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
Mauro Carvalho Chehab587755f2008-05-25 18:20:06 +02001160 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
Tobin Davis8e21c342007-01-08 11:04:17 +01001161 { } /* end */
1162};
1163
Takashi Iwaid1d985f2006-11-23 19:27:12 +01001164static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001165 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1166 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001167
1168 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1169 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001170 { } /* end */
1171};
1172
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001173static struct snd_kcontrol_new stac9205_loopback[] = {
1174 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1175 {}
1176};
1177
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001178/* This needs to be generated dynamically based on sequence */
1179static struct snd_kcontrol_new stac922x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001180 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1181 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001182
1183 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1184 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001185 { } /* end */
1186};
1187
1188
1189static struct snd_kcontrol_new stac927x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001190 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1191 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001192
1193 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1194 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001195
1196 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1197 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +02001198 { } /* end */
1199};
1200
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001201static struct snd_kcontrol_new stac927x_loopback[] = {
1202 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1203 {}
1204};
1205
Takashi Iwai1697055e2007-12-18 18:05:52 +01001206static struct snd_kcontrol_new stac_dmux_mixer = {
1207 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1208 .name = "Digital Input Source",
1209 /* count set later */
1210 .info = stac92xx_dmux_enum_info,
1211 .get = stac92xx_dmux_enum_get,
1212 .put = stac92xx_dmux_enum_put,
1213};
1214
Matthew Ranostayd9737752008-09-07 12:03:41 +02001215static struct snd_kcontrol_new stac_smux_mixer = {
1216 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001217 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001218 /* count set later */
1219 .info = stac92xx_smux_enum_info,
1220 .get = stac92xx_smux_enum_get,
1221 .put = stac92xx_smux_enum_put,
1222};
1223
Takashi Iwai2134ea42008-01-10 16:53:55 +01001224static const char *slave_vols[] = {
1225 "Front Playback Volume",
1226 "Surround Playback Volume",
1227 "Center Playback Volume",
1228 "LFE Playback Volume",
1229 "Side Playback Volume",
1230 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001231 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001232 NULL
1233};
1234
1235static const char *slave_sws[] = {
1236 "Front Playback Switch",
1237 "Surround Playback Switch",
1238 "Center Playback Switch",
1239 "LFE Playback Switch",
1240 "Side Playback Switch",
1241 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001242 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001243 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001244 NULL
1245};
1246
Takashi Iwai603c4012008-07-30 15:01:44 +02001247static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001248static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001249
Matt2f2f4252005-04-13 14:45:30 +02001250static int stac92xx_build_controls(struct hda_codec *codec)
1251{
1252 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001253 struct auto_pin_cfg *cfg = &spec->autocfg;
1254 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001255 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001256 int i;
Matt2f2f4252005-04-13 14:45:30 +02001257
1258 err = snd_hda_add_new_ctls(codec, spec->mixer);
1259 if (err < 0)
1260 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001261
1262 for (i = 0; i < spec->num_mixers; i++) {
1263 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1264 if (err < 0)
1265 return err;
1266 }
Takashi Iwai1697055e2007-12-18 18:05:52 +01001267 if (spec->num_dmuxes > 0) {
1268 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001269 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001270 snd_ctl_new1(&stac_dmux_mixer, codec));
1271 if (err < 0)
1272 return err;
1273 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001274 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001275 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1276 struct hda_input_mux *smux = &spec->private_smux;
1277 /* check for mute support on SPDIF out */
1278 if (wcaps & AC_WCAP_OUT_AMP) {
1279 smux->items[smux->num_items].label = "Off";
1280 smux->items[smux->num_items].index = 0;
1281 smux->num_items++;
1282 spec->spdif_mute = 1;
1283 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001284 stac_smux_mixer.count = spec->num_smuxes;
Takashi Iwai4f2d23e2008-12-19 10:14:13 +01001285 err = snd_hda_ctl_add(codec,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001286 snd_ctl_new1(&stac_smux_mixer, codec));
1287 if (err < 0)
1288 return err;
1289 }
Mattc7d4b2f2005-06-27 14:59:41 +02001290
Mattdabbed62005-06-14 10:19:34 +02001291 if (spec->multiout.dig_out_nid) {
1292 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1293 if (err < 0)
1294 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001295 err = snd_hda_create_spdif_share_sw(codec,
1296 &spec->multiout);
1297 if (err < 0)
1298 return err;
1299 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001300 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001301 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001302 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1303 if (err < 0)
1304 return err;
1305 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001306
1307 /* if we have no master control, let's create it */
1308 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001309 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001310 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001311 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001312 /* correct volume offset */
1313 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001314 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001315 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001316 if (err < 0)
1317 return err;
1318 }
1319 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1320 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1321 NULL, slave_sws);
1322 if (err < 0)
1323 return err;
1324 }
1325
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001326 if (spec->aloopback_ctl &&
1327 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1328 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1329 if (err < 0)
1330 return err;
1331 }
1332
Takashi Iwai603c4012008-07-30 15:01:44 +02001333 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001334
1335 /* create jack input elements */
1336 if (spec->hp_detect) {
1337 for (i = 0; i < cfg->hp_outs; i++) {
1338 int type = SND_JACK_HEADPHONE;
1339 nid = cfg->hp_pins[i];
1340 /* jack detection */
1341 if (cfg->hp_outs == i)
1342 type |= SND_JACK_LINEOUT;
1343 err = stac92xx_add_jack(codec, nid, type);
1344 if (err < 0)
1345 return err;
1346 }
1347 }
1348 for (i = 0; i < cfg->line_outs; i++) {
1349 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1350 SND_JACK_LINEOUT);
1351 if (err < 0)
1352 return err;
1353 }
1354 for (i = 0; i < AUTO_PIN_LAST; i++) {
1355 nid = cfg->input_pins[i];
1356 if (nid) {
1357 err = stac92xx_add_jack(codec, nid,
1358 SND_JACK_MICROPHONE);
1359 if (err < 0)
1360 return err;
1361 }
1362 }
1363
Mattdabbed62005-06-14 10:19:34 +02001364 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001365}
1366
Matt Porter403d1942005-11-29 15:00:51 +01001367static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001368 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001369 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1370};
1371
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001372static unsigned int gateway9200_m4_pin_configs[8] = {
1373 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1374 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1375};
1376static unsigned int gateway9200_m4_2_pin_configs[8] = {
1377 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1378 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1379};
1380
1381/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001382 STAC 9200 pin configs for
1383 102801A8
1384 102801DE
1385 102801E8
1386*/
1387static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001388 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1389 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001390};
1391
1392/*
1393 STAC 9200 pin configs for
1394 102801C0
1395 102801C1
1396*/
1397static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001398 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1399 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001400};
1401
1402/*
1403 STAC 9200 pin configs for
1404 102801C4 (Dell Dimension E310)
1405 102801C5
1406 102801C7
1407 102801D9
1408 102801DA
1409 102801E3
1410*/
1411static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001412 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1413 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001414};
1415
1416
1417/*
1418 STAC 9200-32 pin configs for
1419 102801B5 (Dell Inspiron 630m)
1420 102801D8 (Dell Inspiron 640m)
1421*/
1422static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001423 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1424 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001425};
1426
1427/*
1428 STAC 9200-32 pin configs for
1429 102801C2 (Dell Latitude D620)
1430 102801C8
1431 102801CC (Dell Latitude D820)
1432 102801D4
1433 102801D6
1434*/
1435static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001436 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1437 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001438};
1439
1440/*
1441 STAC 9200-32 pin configs for
1442 102801CE (Dell XPS M1710)
1443 102801CF (Dell Precision M90)
1444*/
1445static unsigned int dell9200_m23_pin_configs[8] = {
1446 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1447 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1448};
1449
1450/*
1451 STAC 9200-32 pin configs for
1452 102801C9
1453 102801CA
1454 102801CB (Dell Latitude 120L)
1455 102801D3
1456*/
1457static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001458 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1459 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001460};
1461
1462/*
1463 STAC 9200-32 pin configs for
1464 102801BD (Dell Inspiron E1505n)
1465 102801EE
1466 102801EF
1467*/
1468static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001469 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1470 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001471};
1472
1473/*
1474 STAC 9200-32 pin configs for
1475 102801F5 (Dell Inspiron 1501)
1476 102801F6
1477*/
1478static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001479 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1480 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001481};
1482
1483/*
1484 STAC 9200-32
1485 102801CD (Dell Inspiron E1705/9400)
1486*/
1487static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001488 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1489 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001490};
1491
Tobin Davisbf277782008-02-03 20:31:47 +01001492static unsigned int oqo9200_pin_configs[8] = {
1493 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1494 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1495};
1496
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001497
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001498static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1499 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001500 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001501 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1502 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1503 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1504 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1505 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1506 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1507 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1508 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1509 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1510 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001511 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1512 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001513 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001514};
1515
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001516static const char *stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001517 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001518 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001519 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001520 [STAC_9200_DELL_D21] = "dell-d21",
1521 [STAC_9200_DELL_D22] = "dell-d22",
1522 [STAC_9200_DELL_D23] = "dell-d23",
1523 [STAC_9200_DELL_M21] = "dell-m21",
1524 [STAC_9200_DELL_M22] = "dell-m22",
1525 [STAC_9200_DELL_M23] = "dell-m23",
1526 [STAC_9200_DELL_M24] = "dell-m24",
1527 [STAC_9200_DELL_M25] = "dell-m25",
1528 [STAC_9200_DELL_M26] = "dell-m26",
1529 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001530 [STAC_9200_M4] = "gateway-m4",
1531 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001532 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001533};
1534
1535static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1536 /* SigmaTel reference board */
1537 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1538 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001539 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1540 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001541 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001542 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1543 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001544 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001545 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1546 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1547 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1548 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1549 "unknown Dell", STAC_9200_DELL_D22),
1550 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1551 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001552 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001553 "Dell Latitude D620", STAC_9200_DELL_M22),
1554 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1555 "unknown Dell", STAC_9200_DELL_D23),
1556 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1557 "unknown Dell", STAC_9200_DELL_D23),
1558 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1559 "unknown Dell", STAC_9200_DELL_M22),
1560 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1561 "unknown Dell", STAC_9200_DELL_M24),
1562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1563 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001565 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001567 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001569 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001571 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001573 "Dell Precision M90", STAC_9200_DELL_M23),
1574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1575 "unknown Dell", STAC_9200_DELL_M22),
1576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1577 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001578 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001579 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001581 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1582 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1583 "unknown Dell", STAC_9200_DELL_D23),
1584 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1585 "unknown Dell", STAC_9200_DELL_D23),
1586 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1587 "unknown Dell", STAC_9200_DELL_D21),
1588 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1589 "unknown Dell", STAC_9200_DELL_D23),
1590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1591 "unknown Dell", STAC_9200_DELL_D21),
1592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1593 "unknown Dell", STAC_9200_DELL_M25),
1594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1595 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001597 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1599 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001600 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001601 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001602 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001603 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1604 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1605 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001606 /* OQO Mobile */
1607 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001608 {} /* terminator */
1609};
1610
Tobin Davis8e21c342007-01-08 11:04:17 +01001611static unsigned int ref925x_pin_configs[8] = {
1612 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001613 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001614};
1615
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001616static unsigned int stac925xM1_pin_configs[8] = {
1617 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1618 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001619};
1620
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001621static unsigned int stac925xM1_2_pin_configs[8] = {
1622 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1623 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1624};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001625
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001626static unsigned int stac925xM2_pin_configs[8] = {
1627 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1628 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001629};
1630
Tobin Davis8e21c342007-01-08 11:04:17 +01001631static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001632 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1633 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1634};
1635
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001636static unsigned int stac925xM3_pin_configs[8] = {
1637 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1638 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1639};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001640
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001641static unsigned int stac925xM5_pin_configs[8] = {
1642 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1643 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1644};
1645
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001646static unsigned int stac925xM6_pin_configs[8] = {
1647 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1648 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001649};
1650
1651static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1652 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001653 [STAC_M1] = stac925xM1_pin_configs,
1654 [STAC_M1_2] = stac925xM1_2_pin_configs,
1655 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001656 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001657 [STAC_M3] = stac925xM3_pin_configs,
1658 [STAC_M5] = stac925xM5_pin_configs,
1659 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001660};
1661
1662static const char *stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001663 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001664 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001665 [STAC_M1] = "m1",
1666 [STAC_M1_2] = "m1-2",
1667 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001668 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001669 [STAC_M3] = "m3",
1670 [STAC_M5] = "m5",
1671 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001672};
1673
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001674static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001675 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1676 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1677 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1678 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001679 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001680 /* Not sure about the brand name for those */
1681 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1682 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1683 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1684 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001685 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001686};
1687
1688static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1689 /* SigmaTel reference board */
1690 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001691 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001692 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001693
1694 /* Default table for unknown ID */
1695 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1696
Tobin Davis8e21c342007-01-08 11:04:17 +01001697 {} /* terminator */
1698};
1699
Matthew Ranostaya7662642008-02-21 07:51:14 +01001700static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001701 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1702 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1703 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001704 0x01452050,
1705};
1706
1707static unsigned int dell_m6_pin_configs[13] = {
1708 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001709 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001710 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1711 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001712};
1713
1714static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001715 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001716 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1717 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1718 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001719 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001720};
1721
1722static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001723 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001724 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001725 [STAC_92HD73XX_REF] = "ref",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001726 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1727 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1728 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001729 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001730};
1731
1732static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1733 /* SigmaTel reference board */
1734 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001735 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001736 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1737 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001738 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001739 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001740 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001741 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001742 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001743 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001744 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001745 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001746 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001747 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001748 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001749 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001750 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001751 "unknown Dell", STAC_DELL_M6_DMIC),
1752 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1753 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001754 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001755 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001756 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1757 "Dell Studio 17", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001758 {} /* terminator */
1759};
1760
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001761static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001762 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1763 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001764 0x01451160, 0x98560170,
1765};
1766
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001767static unsigned int dell_s14_pin_configs[10] = {
1768 0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1769 0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1770 0x40f000f0, 0x40f000f0,
1771};
1772
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001773static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1774 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001775 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001776 [STAC_DELL_S14] = dell_s14_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001777};
1778
1779static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001780 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001781 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001782 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001783 [STAC_DELL_S14] = "dell-s14",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001784};
1785
1786static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1787 /* SigmaTel reference board */
1788 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001789 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001790 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1791 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001792 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1793 "unknown Dell", STAC_DELL_S14),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001794 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001795};
1796
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001797static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001798 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001799 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001800 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1801 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001802};
1803
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001804static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001805 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001806 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001807 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1808 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001809};
1810
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001811static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001812 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1813 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001814 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1815 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001816};
1817
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001818static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001819 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1820 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001821 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1822 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001823};
1824
Matthew Ranostaye035b842007-11-06 11:53:55 +01001825static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1826 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001827 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1828 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001829 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001830 [STAC_HP_M4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001831 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001832 [STAC_HP_HDX] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001833};
1834
1835static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001836 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001837 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001838 [STAC_DELL_M4_1] = "dell-m4-1",
1839 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001840 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001841 [STAC_HP_M4] = "hp-m4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001842 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001843 [STAC_HP_HDX] = "hp-hdx",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001844};
1845
1846static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1847 /* SigmaTel reference board */
1848 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1849 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001850 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1851 "DFI LanParty", STAC_92HD71BXX_REF),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001852 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1853 "HP dv4-7", STAC_HP_DV5),
1854 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1855 "HP dv4-7", STAC_HP_DV5),
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001856 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001857 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001858 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1859 "HP HDX", STAC_HP_HDX), /* HDX16 */
1860 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1861 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostaya7662642008-02-21 07:51:14 +01001862 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1863 "unknown Dell", STAC_DELL_M4_1),
1864 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1865 "unknown Dell", STAC_DELL_M4_1),
1866 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1867 "unknown Dell", STAC_DELL_M4_1),
1868 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1869 "unknown Dell", STAC_DELL_M4_1),
1870 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1871 "unknown Dell", STAC_DELL_M4_1),
1872 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1873 "unknown Dell", STAC_DELL_M4_1),
1874 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1875 "unknown Dell", STAC_DELL_M4_1),
1876 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1877 "unknown Dell", STAC_DELL_M4_2),
1878 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1879 "unknown Dell", STAC_DELL_M4_2),
1880 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1881 "unknown Dell", STAC_DELL_M4_2),
1882 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1883 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001884 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1885 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001886 {} /* terminator */
1887};
1888
Matt Porter403d1942005-11-29 15:00:51 +01001889static unsigned int ref922x_pin_configs[10] = {
1890 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1891 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001892 0x40000100, 0x40000100,
1893};
1894
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001895/*
1896 STAC 922X pin configs for
1897 102801A7
1898 102801AB
1899 102801A9
1900 102801D1
1901 102801D2
1902*/
1903static unsigned int dell_922x_d81_pin_configs[10] = {
1904 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1905 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1906 0x01813122, 0x400001f2,
1907};
1908
1909/*
1910 STAC 922X pin configs for
1911 102801AC
1912 102801D0
1913*/
1914static unsigned int dell_922x_d82_pin_configs[10] = {
1915 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1916 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1917 0x01813122, 0x400001f1,
1918};
1919
1920/*
1921 STAC 922X pin configs for
1922 102801BF
1923*/
1924static unsigned int dell_922x_m81_pin_configs[10] = {
1925 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1926 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1927 0x40C003f1, 0x405003f0,
1928};
1929
1930/*
1931 STAC 9221 A1 pin configs for
1932 102801D7 (Dell XPS M1210)
1933*/
1934static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001935 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1936 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001937 0x508003f3, 0x405003f4,
1938};
1939
Matt Porter403d1942005-11-29 15:00:51 +01001940static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001941 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001942 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1943 0x02a19120, 0x40000100,
1944};
1945
1946static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001947 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1948 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001949 0x02a19320, 0x40000100,
1950};
1951
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001952static unsigned int intel_mac_v1_pin_configs[10] = {
1953 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1954 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001955 0x400000fc, 0x400000fb,
1956};
1957
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001958static unsigned int intel_mac_v2_pin_configs[10] = {
1959 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1960 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001961 0x400000fc, 0x400000fb,
1962};
1963
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001964static unsigned int intel_mac_v3_pin_configs[10] = {
1965 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1966 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1967 0x400000fc, 0x400000fb,
1968};
1969
1970static unsigned int intel_mac_v4_pin_configs[10] = {
1971 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1972 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1973 0x400000fc, 0x400000fb,
1974};
1975
1976static unsigned int intel_mac_v5_pin_configs[10] = {
1977 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1978 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1979 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001980};
1981
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001982static unsigned int ecs202_pin_configs[10] = {
1983 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1984 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1985 0x9037012e, 0x40e000f2,
1986};
Takashi Iwai76c08822007-06-19 12:17:42 +02001987
Takashi Iwai19039bd2006-06-28 15:52:16 +02001988static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001989 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001990 [STAC_D945GTP3] = d945gtp3_pin_configs,
1991 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001992 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1993 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1994 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1995 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1996 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001997 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001998 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001999 [STAC_MACMINI] = intel_mac_v3_pin_configs,
2000 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2001 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2002 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2003 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2004 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002005 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002006 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2007 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2008 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2009 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01002010};
2011
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002012static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002013 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002014 [STAC_D945_REF] = "ref",
2015 [STAC_D945GTP5] = "5stack",
2016 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002017 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2018 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2019 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2020 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2021 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08002022 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002023 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002024 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002025 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002026 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2027 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02002028 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002029 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002030 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002031 [STAC_922X_DELL_D81] = "dell-d81",
2032 [STAC_922X_DELL_D82] = "dell-d82",
2033 [STAC_922X_DELL_M81] = "dell-m81",
2034 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002035};
2036
2037static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2038 /* SigmaTel reference board */
2039 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2040 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002041 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2042 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002043 /* Intel 945G based systems */
2044 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2045 "Intel D945G", STAC_D945GTP3),
2046 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2047 "Intel D945G", STAC_D945GTP3),
2048 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2049 "Intel D945G", STAC_D945GTP3),
2050 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2051 "Intel D945G", STAC_D945GTP3),
2052 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2053 "Intel D945G", STAC_D945GTP3),
2054 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2055 "Intel D945G", STAC_D945GTP3),
2056 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2057 "Intel D945G", STAC_D945GTP3),
2058 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2059 "Intel D945G", STAC_D945GTP3),
2060 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2061 "Intel D945G", STAC_D945GTP3),
2062 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2063 "Intel D945G", STAC_D945GTP3),
2064 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2065 "Intel D945G", STAC_D945GTP3),
2066 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2067 "Intel D945G", STAC_D945GTP3),
2068 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2069 "Intel D945G", STAC_D945GTP3),
2070 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2071 "Intel D945G", STAC_D945GTP3),
2072 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2073 "Intel D945G", STAC_D945GTP3),
2074 /* Intel D945G 5-stack systems */
2075 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2076 "Intel D945G", STAC_D945GTP5),
2077 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2078 "Intel D945G", STAC_D945GTP5),
2079 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2080 "Intel D945G", STAC_D945GTP5),
2081 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2082 "Intel D945G", STAC_D945GTP5),
2083 /* Intel 945P based systems */
2084 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2085 "Intel D945P", STAC_D945GTP3),
2086 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2087 "Intel D945P", STAC_D945GTP3),
2088 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2089 "Intel D945P", STAC_D945GTP3),
2090 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2091 "Intel D945P", STAC_D945GTP3),
2092 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2093 "Intel D945P", STAC_D945GTP3),
2094 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2095 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002096 /* other intel */
2097 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2098 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002099 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002100 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002101 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002102 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002103 /* Dell systems */
2104 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2105 "unknown Dell", STAC_922X_DELL_D81),
2106 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2107 "unknown Dell", STAC_922X_DELL_D81),
2108 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2109 "unknown Dell", STAC_922X_DELL_D81),
2110 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2111 "unknown Dell", STAC_922X_DELL_D82),
2112 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2113 "unknown Dell", STAC_922X_DELL_M81),
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2115 "unknown Dell", STAC_922X_DELL_D82),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2117 "unknown Dell", STAC_922X_DELL_D81),
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2119 "unknown Dell", STAC_922X_DELL_D81),
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2121 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002122 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002123 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002124 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002125 {} /* terminator */
2126};
2127
Matt Porter3cc08dc2006-01-23 15:27:49 +01002128static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002129 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2130 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2131 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2132 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002133};
2134
Tobin Davis93ed1502006-09-01 21:03:12 +02002135static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002136 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2137 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2138 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2139 0x40000100, 0x40000100
2140};
2141
Tobin Davis93ed1502006-09-01 21:03:12 +02002142static unsigned int d965_5st_pin_configs[14] = {
2143 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2144 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2145 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2146 0x40000100, 0x40000100
2147};
2148
Tobin Davis4ff076e2007-08-07 11:48:12 +02002149static unsigned int dell_3st_pin_configs[14] = {
2150 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2151 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002152 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002153 0x40c003fc, 0x40000100
2154};
2155
Tobin Davis93ed1502006-09-01 21:03:12 +02002156static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002157 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002158 [STAC_D965_REF] = ref927x_pin_configs,
2159 [STAC_D965_3ST] = d965_3st_pin_configs,
2160 [STAC_D965_5ST] = d965_5st_pin_configs,
2161 [STAC_DELL_3ST] = dell_3st_pin_configs,
2162 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002163};
2164
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002165static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002166 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002167 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002168 [STAC_D965_REF] = "ref",
2169 [STAC_D965_3ST] = "3stack",
2170 [STAC_D965_5ST] = "5stack",
2171 [STAC_DELL_3ST] = "dell-3stack",
2172 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002173};
2174
2175static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2176 /* SigmaTel reference board */
2177 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2178 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002179 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2180 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002181 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002182 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2183 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002184 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002185 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2186 "Intel D965", STAC_D965_3ST),
2187 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2188 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002189 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002190 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002191 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002192 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2193 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002194 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002195 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2196 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002197 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Takashi Iwai24918b62008-09-30 12:58:54 +02002198 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002199 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2200 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2201 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2202 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002203 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002204 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2205 "Intel D965", STAC_D965_5ST),
2206 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2207 "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002208 {} /* terminator */
2209};
2210
Matt Porterf3302a52006-07-31 12:49:34 +02002211static unsigned int ref9205_pin_configs[12] = {
2212 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002213 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002214 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002215};
2216
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002217/*
2218 STAC 9205 pin configs for
2219 102801F1
2220 102801F2
2221 102801FC
2222 102801FD
2223 10280204
2224 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002225 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002226*/
2227static unsigned int dell_9205_m42_pin_configs[12] = {
2228 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2229 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2230 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2231};
2232
2233/*
2234 STAC 9205 pin configs for
2235 102801F9
2236 102801FA
2237 102801FE
2238 102801FF (Dell Precision M4300)
2239 10280206
2240 10280200
2241 10280201
2242*/
2243static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002244 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2245 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2246 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2247};
2248
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002249static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002250 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2251 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2252 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2253};
2254
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002255static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002256 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002257 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2258 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2259 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002260 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002261};
2262
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002263static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002264 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002265 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002266 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002267 [STAC_9205_DELL_M43] = "dell-m43",
2268 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002269 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002270};
2271
2272static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2273 /* SigmaTel reference board */
2274 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2275 "DFI LanParty", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002276 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2277 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002278 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002279 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2280 "unknown Dell", STAC_9205_DELL_M42),
2281 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2282 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002283 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002284 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002285 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2286 "Dell Precision", STAC_9205_DELL_M43),
2287 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2288 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002289 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2290 "unknown Dell", STAC_9205_DELL_M42),
2291 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2292 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002293 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2294 "Dell Precision", STAC_9205_DELL_M43),
2295 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002296 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002297 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2298 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002299 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2300 "Dell Precision", STAC_9205_DELL_M43),
2301 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2302 "Dell Precision", STAC_9205_DELL_M43),
2303 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2304 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002305 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2306 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002307 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2308 "Dell Vostro 1500", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002309 /* Gateway */
2310 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002311 {} /* terminator */
2312};
2313
Takashi Iwai330ee992009-02-20 14:33:36 +01002314static void stac92xx_set_config_regs(struct hda_codec *codec,
2315 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002316{
2317 int i;
2318 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002319
Takashi Iwai330ee992009-02-20 14:33:36 +01002320 if (!pincfgs)
2321 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002322
Matthew Ranostay87d48362007-07-17 11:52:24 +02002323 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002324 if (spec->pin_nids[i] && pincfgs[i])
2325 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2326 pincfgs[i]);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002327}
2328
Matt2f2f4252005-04-13 14:45:30 +02002329/*
2330 * Analog playback callbacks
2331 */
2332static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2333 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002334 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002335{
2336 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002337 if (spec->stream_delay)
2338 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002339 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2340 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002341}
2342
2343static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2344 struct hda_codec *codec,
2345 unsigned int stream_tag,
2346 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002347 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002348{
2349 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002350 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002351}
2352
2353static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2354 struct hda_codec *codec,
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;
2358 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2359}
2360
2361/*
Mattdabbed62005-06-14 10:19:34 +02002362 * Digital playback callbacks
2363 */
2364static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2365 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002366 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002367{
2368 struct sigmatel_spec *spec = codec->spec;
2369 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2370}
2371
2372static int stac92xx_dig_playback_pcm_close(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_close(codec, &spec->multiout);
2378}
2379
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002380static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2381 struct hda_codec *codec,
2382 unsigned int stream_tag,
2383 unsigned int format,
2384 struct snd_pcm_substream *substream)
2385{
2386 struct sigmatel_spec *spec = codec->spec;
2387 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2388 stream_tag, format, substream);
2389}
2390
Takashi Iwai9411e212009-02-13 11:32:28 +01002391static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2392 struct hda_codec *codec,
2393 struct snd_pcm_substream *substream)
2394{
2395 struct sigmatel_spec *spec = codec->spec;
2396 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2397}
2398
Mattdabbed62005-06-14 10:19:34 +02002399
2400/*
Matt2f2f4252005-04-13 14:45:30 +02002401 * Analog capture callbacks
2402 */
2403static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2404 struct hda_codec *codec,
2405 unsigned int stream_tag,
2406 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002407 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002408{
2409 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002410 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002411
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002412 if (spec->powerdown_adcs) {
2413 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002414 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002415 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2416 }
2417 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002418 return 0;
2419}
2420
2421static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2422 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002423 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002424{
2425 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002426 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002427
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002428 snd_hda_codec_cleanup_stream(codec, nid);
2429 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002430 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002431 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002432 return 0;
2433}
2434
Mattdabbed62005-06-14 10:19:34 +02002435static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2436 .substreams = 1,
2437 .channels_min = 2,
2438 .channels_max = 2,
2439 /* NID is set in stac92xx_build_pcms */
2440 .ops = {
2441 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002442 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002443 .prepare = stac92xx_dig_playback_pcm_prepare,
2444 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002445 },
2446};
2447
2448static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2449 .substreams = 1,
2450 .channels_min = 2,
2451 .channels_max = 2,
2452 /* NID is set in stac92xx_build_pcms */
2453};
2454
Matt2f2f4252005-04-13 14:45:30 +02002455static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2456 .substreams = 1,
2457 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002458 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002459 .nid = 0x02, /* NID to query formats and rates */
2460 .ops = {
2461 .open = stac92xx_playback_pcm_open,
2462 .prepare = stac92xx_playback_pcm_prepare,
2463 .cleanup = stac92xx_playback_pcm_cleanup
2464 },
2465};
2466
Matt Porter3cc08dc2006-01-23 15:27:49 +01002467static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2468 .substreams = 1,
2469 .channels_min = 2,
2470 .channels_max = 2,
2471 .nid = 0x06, /* NID to query formats and rates */
2472 .ops = {
2473 .open = stac92xx_playback_pcm_open,
2474 .prepare = stac92xx_playback_pcm_prepare,
2475 .cleanup = stac92xx_playback_pcm_cleanup
2476 },
2477};
2478
Matt2f2f4252005-04-13 14:45:30 +02002479static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002480 .channels_min = 2,
2481 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002482 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002483 .ops = {
2484 .prepare = stac92xx_capture_pcm_prepare,
2485 .cleanup = stac92xx_capture_pcm_cleanup
2486 },
2487};
2488
2489static int stac92xx_build_pcms(struct hda_codec *codec)
2490{
2491 struct sigmatel_spec *spec = codec->spec;
2492 struct hda_pcm *info = spec->pcm_rec;
2493
2494 codec->num_pcms = 1;
2495 codec->pcm_info = info;
2496
Mattc7d4b2f2005-06-27 14:59:41 +02002497 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002498 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002499 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2500 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002501 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002502 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002503 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002504
2505 if (spec->alt_switch) {
2506 codec->num_pcms++;
2507 info++;
2508 info->name = "STAC92xx Analog Alt";
2509 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2510 }
Matt2f2f4252005-04-13 14:45:30 +02002511
Mattdabbed62005-06-14 10:19:34 +02002512 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2513 codec->num_pcms++;
2514 info++;
2515 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002516 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002517 if (spec->multiout.dig_out_nid) {
2518 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2519 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2520 }
2521 if (spec->dig_in_nid) {
2522 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2523 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2524 }
2525 }
2526
Matt2f2f4252005-04-13 14:45:30 +02002527 return 0;
2528}
2529
Takashi Iwaic960a032006-03-23 17:06:28 +01002530static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2531{
2532 unsigned int pincap = snd_hda_param_read(codec, nid,
2533 AC_PAR_PIN_CAP);
2534 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2535 if (pincap & AC_PINCAP_VREF_100)
2536 return AC_PINCTL_VREF_100;
2537 if (pincap & AC_PINCAP_VREF_80)
2538 return AC_PINCTL_VREF_80;
2539 if (pincap & AC_PINCAP_VREF_50)
2540 return AC_PINCTL_VREF_50;
2541 if (pincap & AC_PINCAP_VREF_GRD)
2542 return AC_PINCTL_VREF_GRD;
2543 return 0;
2544}
2545
Matt Porter403d1942005-11-29 15:00:51 +01002546static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2547
2548{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002549 snd_hda_codec_write_cache(codec, nid, 0,
2550 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002551}
2552
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002553#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2554
2555static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2556 struct snd_ctl_elem_value *ucontrol)
2557{
2558 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2559 struct sigmatel_spec *spec = codec->spec;
2560
Takashi Iwaid7a89432008-11-12 09:48:04 +01002561 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002562 return 0;
2563}
2564
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002565static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2566 unsigned char type);
2567
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002568static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2569 struct snd_ctl_elem_value *ucontrol)
2570{
2571 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2572 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002573 int nid = kcontrol->private_value;
2574
2575 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002576
2577 /* check to be sure that the ports are upto date with
2578 * switch changes
2579 */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002580 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002581
2582 return 1;
2583}
2584
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002585#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01002586
2587static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2588{
2589 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2590 struct sigmatel_spec *spec = codec->spec;
2591 int io_idx = kcontrol-> private_value & 0xff;
2592
2593 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2594 return 0;
2595}
2596
2597static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2598{
2599 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2600 struct sigmatel_spec *spec = codec->spec;
2601 hda_nid_t nid = kcontrol->private_value >> 8;
2602 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002603 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01002604
2605 spec->io_switch[io_idx] = val;
2606
2607 if (val)
2608 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002609 else {
2610 unsigned int pinctl = AC_PINCTL_IN_EN;
2611 if (io_idx) /* set VREF for mic */
2612 pinctl |= stac92xx_get_vref(codec, nid);
2613 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2614 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002615
2616 /* check the auto-mute again: we need to mute/unmute the speaker
2617 * appropriately according to the pin direction
2618 */
2619 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002620 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002621
Matt Porter403d1942005-11-29 15:00:51 +01002622 return 1;
2623}
2624
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002625#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2626
2627static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2628 struct snd_ctl_elem_value *ucontrol)
2629{
2630 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2631 struct sigmatel_spec *spec = codec->spec;
2632
2633 ucontrol->value.integer.value[0] = spec->clfe_swap;
2634 return 0;
2635}
2636
2637static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2638 struct snd_ctl_elem_value *ucontrol)
2639{
2640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2641 struct sigmatel_spec *spec = codec->spec;
2642 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002643 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002644
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002645 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002646 return 0;
2647
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002648 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002649
2650 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2651 spec->clfe_swap ? 0x4 : 0x0);
2652
2653 return 1;
2654}
2655
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002656#define STAC_CODEC_HP_SWITCH(xname) \
2657 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2658 .name = xname, \
2659 .index = 0, \
2660 .info = stac92xx_hp_switch_info, \
2661 .get = stac92xx_hp_switch_get, \
2662 .put = stac92xx_hp_switch_put, \
2663 }
2664
Matt Porter403d1942005-11-29 15:00:51 +01002665#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2666 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2667 .name = xname, \
2668 .index = 0, \
2669 .info = stac92xx_io_switch_info, \
2670 .get = stac92xx_io_switch_get, \
2671 .put = stac92xx_io_switch_put, \
2672 .private_value = xpval, \
2673 }
2674
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002675#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2676 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2677 .name = xname, \
2678 .index = 0, \
2679 .info = stac92xx_clfe_switch_info, \
2680 .get = stac92xx_clfe_switch_get, \
2681 .put = stac92xx_clfe_switch_put, \
2682 .private_value = xpval, \
2683 }
Matt Porter403d1942005-11-29 15:00:51 +01002684
Mattc7d4b2f2005-06-27 14:59:41 +02002685enum {
2686 STAC_CTL_WIDGET_VOL,
2687 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002688 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002689 STAC_CTL_WIDGET_AMP_MUX,
2690 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002691 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002692 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002693 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02002694};
2695
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002696static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002697 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2698 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002699 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002700 STAC_AMP_MUX,
2701 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002702 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002703 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002704 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002705};
2706
2707/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002708static struct snd_kcontrol_new *
2709stac_control_new(struct sigmatel_spec *spec,
2710 struct snd_kcontrol_new *ktemp,
2711 const char *name)
Mattc7d4b2f2005-06-27 14:59:41 +02002712{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002713 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002714
Takashi Iwai603c4012008-07-30 15:01:44 +02002715 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2716 knew = snd_array_new(&spec->kctls);
2717 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002718 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002719 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002720 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002721 if (!knew->name) {
2722 /* roolback */
2723 memset(knew, 0, sizeof(*knew));
2724 spec->kctls.alloced--;
2725 return NULL;
2726 }
2727 return knew;
2728}
2729
2730static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2731 struct snd_kcontrol_new *ktemp,
2732 int idx, const char *name,
2733 unsigned long val)
2734{
2735 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2736 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002737 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002738 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002739 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002740 return 0;
2741}
2742
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002743static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2744 int type, int idx, const char *name,
2745 unsigned long val)
2746{
2747 return stac92xx_add_control_temp(spec,
2748 &stac92xx_control_templates[type],
2749 idx, name, val);
2750}
2751
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002752
2753/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002754static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2755 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002756{
2757 return stac92xx_add_control_idx(spec, type, 0, name, val);
2758}
2759
Takashi Iwaie3c75962009-01-23 11:57:22 +01002760static struct snd_kcontrol_new stac_input_src_temp = {
2761 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2762 .name = "Input Source",
2763 .info = stac92xx_mux_enum_info,
2764 .get = stac92xx_mux_enum_get,
2765 .put = stac92xx_mux_enum_put,
2766};
2767
2768static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2769{
2770 struct snd_kcontrol_new *knew;
2771 struct hda_input_mux *imux = &spec->private_imux;
2772
2773 if (!spec->num_adcs || imux->num_items <= 1)
2774 return 0; /* no need for input source control */
2775 knew = stac_control_new(spec, &stac_input_src_temp,
2776 stac_input_src_temp.name);
2777 if (!knew)
2778 return -ENOMEM;
2779 knew->count = spec->num_adcs;
2780 return 0;
2781}
2782
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002783/* check whether the line-input can be used as line-out */
2784static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002785{
2786 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002787 struct auto_pin_cfg *cfg = &spec->autocfg;
2788 hda_nid_t nid;
2789 unsigned int pincap;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002790
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002791 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2792 return 0;
2793 nid = cfg->input_pins[AUTO_PIN_LINE];
2794 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
2795 if (pincap & AC_PINCAP_OUT)
2796 return nid;
Matt Porter403d1942005-11-29 15:00:51 +01002797 return 0;
2798}
2799
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002800/* check whether the mic-input can be used as line-out */
2801static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2802{
2803 struct sigmatel_spec *spec = codec->spec;
2804 struct auto_pin_cfg *cfg = &spec->autocfg;
2805 unsigned int def_conf, pincap;
2806 unsigned int mic_pin;
2807
2808 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2809 return 0;
2810 mic_pin = AUTO_PIN_MIC;
2811 for (;;) {
2812 hda_nid_t nid = cfg->input_pins[mic_pin];
Takashi Iwai330ee992009-02-20 14:33:36 +01002813 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002814 /* some laptops have an internal analog microphone
2815 * which can't be used as a output */
2816 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2817 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
2818 if (pincap & AC_PINCAP_OUT)
2819 return nid;
2820 }
2821 if (mic_pin == AUTO_PIN_MIC)
2822 mic_pin = AUTO_PIN_FRONT_MIC;
2823 else
2824 break;
2825 }
2826 return 0;
2827}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002828
2829static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2830{
2831 int i;
2832
2833 for (i = 0; i < spec->multiout.num_dacs; i++) {
2834 if (spec->multiout.dac_nids[i] == nid)
2835 return 1;
2836 }
2837
2838 return 0;
2839}
2840
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002841static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2842{
2843 int i;
2844 if (is_in_dac_nids(spec, nid))
2845 return 1;
2846 for (i = 0; i < spec->autocfg.hp_outs; i++)
2847 if (spec->hp_dacs[i] == nid)
2848 return 1;
2849 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2850 if (spec->speaker_dacs[i] == nid)
2851 return 1;
2852 return 0;
2853}
2854
2855static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2856{
2857 struct sigmatel_spec *spec = codec->spec;
2858 int j, conn_len;
2859 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2860 unsigned int wcaps, wtype;
2861
2862 conn_len = snd_hda_get_connections(codec, nid, conn,
2863 HDA_MAX_CONNECTIONS);
2864 for (j = 0; j < conn_len; j++) {
2865 wcaps = snd_hda_param_read(codec, conn[j],
2866 AC_PAR_AUDIO_WIDGET_CAP);
2867 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2868 /* we check only analog outputs */
2869 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2870 continue;
2871 /* if this route has a free DAC, assign it */
2872 if (!check_all_dac_nids(spec, conn[j])) {
2873 if (conn_len > 1) {
2874 /* select this DAC in the pin's input mux */
2875 snd_hda_codec_write_cache(codec, nid, 0,
2876 AC_VERB_SET_CONNECT_SEL, j);
2877 }
2878 return conn[j];
2879 }
2880 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002881 /* if all DACs are already assigned, connect to the primary DAC */
2882 if (conn_len > 1) {
2883 for (j = 0; j < conn_len; j++) {
2884 if (conn[j] == spec->multiout.dac_nids[0]) {
2885 snd_hda_codec_write_cache(codec, nid, 0,
2886 AC_VERB_SET_CONNECT_SEL, j);
2887 break;
2888 }
2889 }
2890 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002891 return 0;
2892}
2893
2894static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2895static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2896
Matt Porter3cc08dc2006-01-23 15:27:49 +01002897/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002898 * Fill in the dac_nids table from the parsed pin configuration
2899 * This function only works when every pin in line_out_pins[]
2900 * contains atleast one DAC in its connection list. Some 92xx
2901 * codecs are not connected directly to a DAC, such as the 9200
2902 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002903 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002904static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002905{
2906 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002907 struct auto_pin_cfg *cfg = &spec->autocfg;
2908 int i;
2909 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002910
Mattc7d4b2f2005-06-27 14:59:41 +02002911 for (i = 0; i < cfg->line_outs; i++) {
2912 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002913 dac = get_unassigned_dac(codec, nid);
2914 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002915 if (spec->multiout.num_dacs > 0) {
2916 /* we have already working output pins,
2917 * so let's drop the broken ones again
2918 */
2919 cfg->line_outs = spec->multiout.num_dacs;
2920 break;
2921 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002922 /* error out, no available DAC found */
2923 snd_printk(KERN_ERR
2924 "%s: No available DAC for pin 0x%x\n",
2925 __func__, nid);
2926 return -ENODEV;
2927 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002928 add_spec_dacs(spec, dac);
2929 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002930
Takashi Iwai139e0712009-03-06 12:10:41 +01002931 for (i = 0; i < cfg->hp_outs; i++) {
2932 nid = cfg->hp_pins[i];
2933 dac = get_unassigned_dac(codec, nid);
2934 if (dac) {
2935 if (!spec->multiout.hp_nid)
2936 spec->multiout.hp_nid = dac;
2937 else
2938 add_spec_extra_dacs(spec, dac);
2939 }
2940 spec->hp_dacs[i] = dac;
2941 }
2942
2943 for (i = 0; i < cfg->speaker_outs; i++) {
2944 nid = cfg->speaker_pins[i];
2945 dac = get_unassigned_dac(codec, nid);
2946 if (dac)
2947 add_spec_extra_dacs(spec, dac);
2948 spec->speaker_dacs[i] = dac;
2949 }
2950
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002951 /* add line-in as output */
2952 nid = check_line_out_switch(codec);
2953 if (nid) {
2954 dac = get_unassigned_dac(codec, nid);
2955 if (dac) {
2956 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2957 nid, cfg->line_outs);
2958 cfg->line_out_pins[cfg->line_outs] = nid;
2959 cfg->line_outs++;
2960 spec->line_switch = nid;
2961 add_spec_dacs(spec, dac);
2962 }
2963 }
2964 /* add mic as output */
2965 nid = check_mic_out_switch(codec);
2966 if (nid) {
2967 dac = get_unassigned_dac(codec, nid);
2968 if (dac) {
2969 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
2970 nid, cfg->line_outs);
2971 cfg->line_out_pins[cfg->line_outs] = nid;
2972 cfg->line_outs++;
2973 spec->mic_switch = nid;
2974 add_spec_dacs(spec, dac);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002975 }
Mattc7d4b2f2005-06-27 14:59:41 +02002976 }
2977
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002978 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02002979 spec->multiout.num_dacs,
2980 spec->multiout.dac_nids[0],
2981 spec->multiout.dac_nids[1],
2982 spec->multiout.dac_nids[2],
2983 spec->multiout.dac_nids[3],
2984 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002985
Mattc7d4b2f2005-06-27 14:59:41 +02002986 return 0;
2987}
2988
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002989/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01002990static int create_controls_idx(struct hda_codec *codec, const char *pfx,
2991 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002992{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002993 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002994 char name[32];
2995 int err;
2996
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002997 if (!spec->check_volume_offset) {
2998 unsigned int caps, step, nums, db_scale;
2999 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3000 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3001 AC_AMPCAP_STEP_SIZE_SHIFT;
3002 step = (step + 1) * 25; /* in .01dB unit */
3003 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3004 AC_AMPCAP_NUM_STEPS_SHIFT;
3005 db_scale = nums * step;
3006 /* if dB scale is over -64dB, and finer enough,
3007 * let's reduce it to half
3008 */
3009 if (db_scale > 6400 && nums >= 0x1f)
3010 spec->volume_offset = nums / 2;
3011 spec->check_volume_offset = 1;
3012 }
3013
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003014 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003015 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003016 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3017 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003018 if (err < 0)
3019 return err;
3020 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003021 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003022 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3023 if (err < 0)
3024 return err;
3025 return 0;
3026}
3027
Takashi Iwai668b9652009-03-06 10:13:24 +01003028#define create_controls(codec, pfx, nid, chs) \
3029 create_controls_idx(codec, pfx, 0, nid, chs)
3030
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003031static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3032{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003033 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003034 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3035 return 1;
3036 } else {
3037 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3038 spec->multiout.num_dacs++;
3039 }
3040 return 0;
3041}
3042
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003043static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003044{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003045 int i;
3046 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3047 if (!spec->multiout.extra_out_nid[i]) {
3048 spec->multiout.extra_out_nid[i] = nid;
3049 return 0;
3050 }
3051 }
3052 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3053 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003054}
3055
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003056/* Create output controls
3057 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3058 */
3059static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3060 const hda_nid_t *pins,
3061 const hda_nid_t *dac_nids,
3062 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003063{
Takashi Iwai76624532008-12-19 10:09:47 +01003064 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003065 static const char *chname[4] = {
3066 "Front", "Surround", NULL /*CLFE*/, "Side"
3067 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003068 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003069 int i, err;
3070 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003071
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003072 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3073 nid = dac_nids[i];
3074 if (!nid)
3075 continue;
3076 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003077 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003078 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003079 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003080 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003081 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003082 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003083 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003084
3085 wid_caps = get_wcaps(codec, nid);
3086
3087 if (wid_caps & AC_WCAP_LR_SWAP) {
3088 err = stac92xx_add_control(spec,
3089 STAC_CTL_WIDGET_CLFE_SWITCH,
3090 "Swap Center/LFE Playback Switch", nid);
3091
3092 if (err < 0)
3093 return err;
3094 }
3095
Mattc7d4b2f2005-06-27 14:59:41 +02003096 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003097 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003098 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003099 switch (type) {
3100 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003101 name = "Headphone";
3102 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003103 break;
3104 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003105 name = "Speaker";
3106 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003107 break;
3108 default:
3109 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003110 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003111 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003112 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003113 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003114 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003115 return err;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003116 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3117 wid_caps = get_wcaps(codec, pins[i]);
3118 if (wid_caps & AC_WCAP_UNSOL_CAP)
3119 spec->hp_detect = 1;
3120 }
Mattc7d4b2f2005-06-27 14:59:41 +02003121 }
3122 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003123 return 0;
3124}
3125
3126/* add playback controls from the parsed DAC table */
3127static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3128 const struct auto_pin_cfg *cfg)
3129{
3130 struct sigmatel_spec *spec = codec->spec;
3131 int err;
3132
3133 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3134 spec->multiout.dac_nids,
3135 cfg->line_out_type);
3136 if (err < 0)
3137 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003138
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003139 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003140 err = stac92xx_add_control(spec,
3141 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003142 "Headphone as Line Out Switch",
3143 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003144 if (err < 0)
3145 return err;
3146 }
3147
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003148 if (spec->line_switch) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003149 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH,
3150 "Line In as Output Switch",
3151 spec->line_switch << 8);
3152 if (err < 0)
3153 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003154 }
Matt Porter403d1942005-11-29 15:00:51 +01003155
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003156 if (spec->mic_switch) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003157 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH,
3158 "Mic as Output Switch",
3159 (spec->mic_switch << 8) | 1);
3160 if (err < 0)
3161 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003162 }
Matt Porter403d1942005-11-29 15:00:51 +01003163
Mattc7d4b2f2005-06-27 14:59:41 +02003164 return 0;
3165}
3166
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003167/* add playback controls for Speaker and HP outputs */
3168static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3169 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003170{
3171 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003172 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003173
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003174 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3175 spec->hp_dacs, AUTO_PIN_HP_OUT);
3176 if (err < 0)
3177 return err;
3178
3179 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3180 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3181 if (err < 0)
3182 return err;
3183
Mattc7d4b2f2005-06-27 14:59:41 +02003184 return 0;
3185}
3186
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003187/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003188static const char *stac92xx_mono_labels[4] = {
3189 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003190};
3191
3192/* create mono mux for mono out on capable codecs */
3193static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3194{
3195 struct sigmatel_spec *spec = codec->spec;
3196 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3197 int i, num_cons;
3198 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3199
3200 num_cons = snd_hda_get_connections(codec,
3201 spec->mono_nid,
3202 con_lst,
3203 HDA_MAX_NUM_INPUTS);
3204 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3205 return -EINVAL;
3206
3207 for (i = 0; i < num_cons; i++) {
3208 mono_mux->items[mono_mux->num_items].label =
3209 stac92xx_mono_labels[i];
3210 mono_mux->items[mono_mux->num_items].index = i;
3211 mono_mux->num_items++;
3212 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003213
3214 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3215 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003216}
3217
Matthew Ranostay89385032008-09-11 09:49:39 -04003218/* labels for amp mux outputs */
3219static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003220 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003221};
3222
3223/* create amp out controls mux on capable codecs */
3224static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3225{
3226 struct sigmatel_spec *spec = codec->spec;
3227 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3228 int i, err;
3229
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003230 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003231 amp_mux->items[amp_mux->num_items].label =
3232 stac92xx_amp_labels[i];
3233 amp_mux->items[amp_mux->num_items].index = i;
3234 amp_mux->num_items++;
3235 }
3236
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003237 if (spec->num_amps > 1) {
3238 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3239 "Amp Selector Capture Switch", 0);
3240 if (err < 0)
3241 return err;
3242 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003243 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3244 "Amp Capture Volume",
3245 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3246}
3247
3248
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003249/* create PC beep volume controls */
3250static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3251 hda_nid_t nid)
3252{
3253 struct sigmatel_spec *spec = codec->spec;
3254 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3255 int err;
3256
3257 /* check for mute support for the the amp */
3258 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3259 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3260 "PC Beep Playback Switch",
3261 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3262 if (err < 0)
3263 return err;
3264 }
3265
3266 /* check to see if there is volume support for the amp */
3267 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3268 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3269 "PC Beep Playback Volume",
3270 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3271 if (err < 0)
3272 return err;
3273 }
3274 return 0;
3275}
3276
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003277#ifdef CONFIG_SND_HDA_INPUT_BEEP
3278#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3279
3280static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3281 struct snd_ctl_elem_value *ucontrol)
3282{
3283 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3284 ucontrol->value.integer.value[0] = codec->beep->enabled;
3285 return 0;
3286}
3287
3288static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3289 struct snd_ctl_elem_value *ucontrol)
3290{
3291 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3292 int enabled = !!ucontrol->value.integer.value[0];
3293 if (codec->beep->enabled != enabled) {
3294 codec->beep->enabled = enabled;
3295 return 1;
3296 }
3297 return 0;
3298}
3299
3300static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3301 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3302 .info = stac92xx_dig_beep_switch_info,
3303 .get = stac92xx_dig_beep_switch_get,
3304 .put = stac92xx_dig_beep_switch_put,
3305};
3306
3307static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3308{
3309 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3310 0, "PC Beep Playback Switch", 0);
3311}
3312#endif
3313
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003314static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3315{
3316 struct sigmatel_spec *spec = codec->spec;
3317 int wcaps, nid, i, err = 0;
3318
3319 for (i = 0; i < spec->num_muxes; i++) {
3320 nid = spec->mux_nids[i];
3321 wcaps = get_wcaps(codec, nid);
3322
3323 if (wcaps & AC_WCAP_OUT_AMP) {
3324 err = stac92xx_add_control_idx(spec,
3325 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3326 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3327 if (err < 0)
3328 return err;
3329 }
3330 }
3331 return 0;
3332};
3333
Matthew Ranostayd9737752008-09-07 12:03:41 +02003334static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003335 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003336};
3337
3338static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3339{
3340 struct sigmatel_spec *spec = codec->spec;
3341 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003342 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003343 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003344 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003345
3346 num_cons = snd_hda_get_connections(codec,
3347 spec->smux_nids[0],
3348 con_lst,
3349 HDA_MAX_NUM_INPUTS);
Matthew Ranostay65973632008-09-16 10:39:37 -04003350 if (!num_cons)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003351 return -EINVAL;
3352
Matthew Ranostay65973632008-09-16 10:39:37 -04003353 if (!labels)
3354 labels = stac92xx_spdif_labels;
3355
Matthew Ranostayd9737752008-09-07 12:03:41 +02003356 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003357 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003358 spdif_mux->items[spdif_mux->num_items].index = i;
3359 spdif_mux->num_items++;
3360 }
3361
3362 return 0;
3363}
3364
Matt Porter8b657272006-10-26 17:12:59 +02003365/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003366static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003367 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3368 "Digital Mic 3", "Digital Mic 4"
3369};
3370
3371/* create playback/capture controls for input pins on dmic capable codecs */
3372static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3373 const struct auto_pin_cfg *cfg)
3374{
3375 struct sigmatel_spec *spec = codec->spec;
3376 struct hda_input_mux *dimux = &spec->private_dimux;
3377 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003378 int err, i, j;
3379 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02003380
3381 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3382 dimux->items[dimux->num_items].index = 0;
3383 dimux->num_items++;
3384
3385 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003386 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003387 int index;
3388 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003389 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02003390 unsigned int def_conf;
3391
Takashi Iwai330ee992009-02-20 14:33:36 +01003392 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
Matt Porter8b657272006-10-26 17:12:59 +02003393 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3394 continue;
3395
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003396 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02003397 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003398 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02003399 con_lst,
3400 HDA_MAX_NUM_INPUTS);
3401 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003402 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02003403 index = j;
3404 goto found;
3405 }
3406 continue;
3407found:
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003408 wcaps = get_wcaps(codec, nid) &
3409 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003410
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003411 if (wcaps) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003412 sprintf(name, "%s Capture Volume",
3413 stac92xx_dmic_labels[dimux->num_items]);
3414
3415 err = stac92xx_add_control(spec,
3416 STAC_CTL_WIDGET_VOL,
3417 name,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003418 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3419 (wcaps & AC_WCAP_OUT_AMP) ?
3420 HDA_OUTPUT : HDA_INPUT));
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003421 if (err < 0)
3422 return err;
3423 }
3424
Matt Porter8b657272006-10-26 17:12:59 +02003425 dimux->items[dimux->num_items].label =
3426 stac92xx_dmic_labels[dimux->num_items];
3427 dimux->items[dimux->num_items].index = index;
3428 dimux->num_items++;
3429 }
3430
3431 return 0;
3432}
3433
Mattc7d4b2f2005-06-27 14:59:41 +02003434/* create playback/capture controls for input pins */
3435static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3436{
3437 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003438 struct hda_input_mux *imux = &spec->private_imux;
3439 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3440 int i, j, k;
3441
3442 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003443 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02003444
Takashi Iwai314634b2006-09-21 11:56:18 +02003445 if (!cfg->input_pins[i])
3446 continue;
3447 index = -1;
3448 for (j = 0; j < spec->num_muxes; j++) {
3449 int num_cons;
3450 num_cons = snd_hda_get_connections(codec,
3451 spec->mux_nids[j],
3452 con_lst,
3453 HDA_MAX_NUM_INPUTS);
3454 for (k = 0; k < num_cons; k++)
3455 if (con_lst[k] == cfg->input_pins[i]) {
3456 index = k;
3457 goto found;
3458 }
Mattc7d4b2f2005-06-27 14:59:41 +02003459 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003460 continue;
3461 found:
3462 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3463 imux->items[imux->num_items].index = index;
3464 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003465 }
3466
Steve Longerbeam7b043892007-05-03 20:50:03 +02003467 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003468 /*
3469 * Set the current input for the muxes.
3470 * The STAC9221 has two input muxes with identical source
3471 * NID lists. Hopefully this won't get confused.
3472 */
3473 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003474 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3475 AC_VERB_SET_CONNECT_SEL,
3476 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003477 }
3478 }
3479
Mattc7d4b2f2005-06-27 14:59:41 +02003480 return 0;
3481}
3482
Mattc7d4b2f2005-06-27 14:59:41 +02003483static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3484{
3485 struct sigmatel_spec *spec = codec->spec;
3486 int i;
3487
3488 for (i = 0; i < spec->autocfg.line_outs; i++) {
3489 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3490 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3491 }
3492}
3493
3494static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3495{
3496 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003497 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003498
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003499 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3500 hda_nid_t pin;
3501 pin = spec->autocfg.hp_pins[i];
3502 if (pin) /* connect to front */
3503 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3504 }
3505 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3506 hda_nid_t pin;
3507 pin = spec->autocfg.speaker_pins[i];
3508 if (pin) /* connect to front */
3509 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3510 }
Mattc7d4b2f2005-06-27 14:59:41 +02003511}
3512
Matt Porter3cc08dc2006-01-23 15:27:49 +01003513static 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 +02003514{
3515 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003516 int hp_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003517 int err;
3518
Matt Porter8b657272006-10-26 17:12:59 +02003519 if ((err = snd_hda_parse_pin_def_config(codec,
3520 &spec->autocfg,
3521 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003522 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003523 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003524 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003525
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003526 /* If we have no real line-out pin and multiple hp-outs, HPs should
3527 * be set up as multi-channel outputs.
3528 */
3529 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3530 spec->autocfg.hp_outs > 1) {
3531 /* Copy hp_outs to line_outs, backup line_outs in
3532 * speaker_outs so that the following routines can handle
3533 * HP pins as primary outputs.
3534 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003535 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003536 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3537 sizeof(spec->autocfg.line_out_pins));
3538 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3539 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3540 sizeof(spec->autocfg.hp_pins));
3541 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003542 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3543 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003544 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003545 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003546 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003547 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3548 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003549 u32 caps = query_amp_caps(codec,
3550 spec->autocfg.mono_out_pin, dir);
3551 hda_nid_t conn_list[1];
3552
3553 /* get the mixer node and then the mono mux if it exists */
3554 if (snd_hda_get_connections(codec,
3555 spec->autocfg.mono_out_pin, conn_list, 1) &&
3556 snd_hda_get_connections(codec, conn_list[0],
3557 conn_list, 1)) {
3558
3559 int wcaps = get_wcaps(codec, conn_list[0]);
3560 int wid_type = (wcaps & AC_WCAP_TYPE)
3561 >> AC_WCAP_TYPE_SHIFT;
3562 /* LR swap check, some stac925x have a mux that
3563 * changes the DACs output path instead of the
3564 * mono-mux path.
3565 */
3566 if (wid_type == AC_WID_AUD_SEL &&
3567 !(wcaps & AC_WCAP_LR_SWAP))
3568 spec->mono_nid = conn_list[0];
3569 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003570 if (dir) {
3571 hda_nid_t nid = spec->autocfg.mono_out_pin;
3572
3573 /* most mono outs have a least a mute/unmute switch */
3574 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3575 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3576 "Mono Playback Switch",
3577 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003578 if (err < 0)
3579 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003580 /* check for volume support for the amp */
3581 if ((caps & AC_AMPCAP_NUM_STEPS)
3582 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3583 err = stac92xx_add_control(spec,
3584 STAC_CTL_WIDGET_VOL,
3585 "Mono Playback Volume",
3586 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3587 if (err < 0)
3588 return err;
3589 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003590 }
3591
3592 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3593 AC_PINCTL_OUT_EN);
3594 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003595
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003596 if (!spec->multiout.num_dacs) {
3597 err = stac92xx_auto_fill_dac_nids(codec);
3598 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003599 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003600 err = stac92xx_auto_create_multi_out_ctls(codec,
3601 &spec->autocfg);
3602 if (err < 0)
3603 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003604 }
Mattc7d4b2f2005-06-27 14:59:41 +02003605
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003606 /* setup analog beep controls */
3607 if (spec->anabeep_nid > 0) {
3608 err = stac92xx_auto_create_beep_ctls(codec,
3609 spec->anabeep_nid);
3610 if (err < 0)
3611 return err;
3612 }
3613
3614 /* setup digital beep controls and input device */
3615#ifdef CONFIG_SND_HDA_INPUT_BEEP
3616 if (spec->digbeep_nid > 0) {
3617 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003618 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003619
3620 err = stac92xx_auto_create_beep_ctls(codec, nid);
3621 if (err < 0)
3622 return err;
3623 err = snd_hda_attach_beep_device(codec, nid);
3624 if (err < 0)
3625 return err;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003626 /* if no beep switch is available, make its own one */
3627 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3628 if (codec->beep &&
3629 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3630 err = stac92xx_beep_switch_ctl(codec);
3631 if (err < 0)
3632 return err;
3633 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003634 }
3635#endif
3636
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003637 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003638 if (err < 0)
3639 return err;
3640
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003641 /* All output parsing done, now restore the swapped hp pins */
3642 if (hp_swap) {
3643 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3644 sizeof(spec->autocfg.hp_pins));
3645 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3646 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3647 spec->autocfg.line_outs = 0;
3648 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003649
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003650 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003651 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003652 return err;
3653
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003654 if (spec->mono_nid > 0) {
3655 err = stac92xx_auto_create_mono_output_ctls(codec);
3656 if (err < 0)
3657 return err;
3658 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003659 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003660 err = stac92xx_auto_create_amp_output_ctls(codec);
3661 if (err < 0)
3662 return err;
3663 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003664 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003665 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3666 &spec->autocfg)) < 0)
3667 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003668 if (spec->num_muxes > 0) {
3669 err = stac92xx_auto_create_mux_input_ctls(codec);
3670 if (err < 0)
3671 return err;
3672 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003673 if (spec->num_smuxes > 0) {
3674 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3675 if (err < 0)
3676 return err;
3677 }
Matt Porter8b657272006-10-26 17:12:59 +02003678
Takashi Iwaie3c75962009-01-23 11:57:22 +01003679 err = stac92xx_add_input_source(spec);
3680 if (err < 0)
3681 return err;
3682
Mattc7d4b2f2005-06-27 14:59:41 +02003683 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003684 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003685 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003686
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003687 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003688 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003689 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003690 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003691
Takashi Iwai603c4012008-07-30 15:01:44 +02003692 if (spec->kctls.list)
3693 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003694
3695 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003696 if (!spec->dinput_mux)
3697 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003698 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003699 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04003700 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003701 return 1;
3702}
3703
Takashi Iwai82bc9552006-03-21 11:24:42 +01003704/* add playback controls for HP output */
3705static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3706 struct auto_pin_cfg *cfg)
3707{
3708 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003709 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003710 unsigned int wid_caps;
3711
3712 if (! pin)
3713 return 0;
3714
3715 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003716 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003717 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003718
3719 return 0;
3720}
3721
Richard Fish160ea0d2006-09-06 13:58:25 +02003722/* add playback controls for LFE output */
3723static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3724 struct auto_pin_cfg *cfg)
3725{
3726 struct sigmatel_spec *spec = codec->spec;
3727 int err;
3728 hda_nid_t lfe_pin = 0x0;
3729 int i;
3730
3731 /*
3732 * search speaker outs and line outs for a mono speaker pin
3733 * with an amp. If one is found, add LFE controls
3734 * for it.
3735 */
3736 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3737 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003738 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003739 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3740 if (wcaps == AC_WCAP_OUT_AMP)
3741 /* found a mono speaker with an amp, must be lfe */
3742 lfe_pin = pin;
3743 }
3744
3745 /* if speaker_outs is 0, then speakers may be in line_outs */
3746 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3747 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3748 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003749 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01003750 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01003751 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003752 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003753 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3754 if (wcaps == AC_WCAP_OUT_AMP)
3755 /* found a mono speaker with an amp,
3756 must be lfe */
3757 lfe_pin = pin;
3758 }
3759 }
3760 }
3761
3762 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003763 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003764 if (err < 0)
3765 return err;
3766 }
3767
3768 return 0;
3769}
3770
Mattc7d4b2f2005-06-27 14:59:41 +02003771static int stac9200_parse_auto_config(struct hda_codec *codec)
3772{
3773 struct sigmatel_spec *spec = codec->spec;
3774 int err;
3775
Kailang Yangdf694da2005-12-05 19:42:22 +01003776 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003777 return err;
3778
3779 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3780 return err;
3781
Takashi Iwai82bc9552006-03-21 11:24:42 +01003782 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3783 return err;
3784
Richard Fish160ea0d2006-09-06 13:58:25 +02003785 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3786 return err;
3787
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003788 if (spec->num_muxes > 0) {
3789 err = stac92xx_auto_create_mux_input_ctls(codec);
3790 if (err < 0)
3791 return err;
3792 }
3793
Takashi Iwaie3c75962009-01-23 11:57:22 +01003794 err = stac92xx_add_input_source(spec);
3795 if (err < 0)
3796 return err;
3797
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003798 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02003799 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003800 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003801 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003802
Takashi Iwai603c4012008-07-30 15:01:44 +02003803 if (spec->kctls.list)
3804 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003805
3806 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003807 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003808
3809 return 1;
3810}
3811
Sam Revitch62fe78e2006-05-10 15:09:17 +02003812/*
3813 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3814 * funky external mute control using GPIO pins.
3815 */
3816
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003817static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003818 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003819{
3820 unsigned int gpiostate, gpiomask, gpiodir;
3821
3822 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3823 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003824 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003825
3826 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3827 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003828 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003829
3830 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3831 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003832 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003833
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003834 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003835 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3836
3837 snd_hda_codec_write(codec, codec->afg, 0,
3838 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003839 snd_hda_codec_read(codec, codec->afg, 0,
3840 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003841
3842 msleep(1);
3843
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003844 snd_hda_codec_read(codec, codec->afg, 0,
3845 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003846}
3847
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003848static int stac92xx_add_jack(struct hda_codec *codec,
3849 hda_nid_t nid, int type)
3850{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003851#ifdef CONFIG_SND_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003852 struct sigmatel_spec *spec = codec->spec;
3853 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01003854 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003855 int connectivity = get_defcfg_connect(def_conf);
3856 char name[32];
3857
3858 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3859 return 0;
3860
3861 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3862 jack = snd_array_new(&spec->jacks);
3863 if (!jack)
3864 return -ENOMEM;
3865 jack->nid = nid;
3866 jack->type = type;
3867
3868 sprintf(name, "%s at %s %s Jack",
3869 snd_hda_get_jack_type(def_conf),
3870 snd_hda_get_jack_connectivity(def_conf),
3871 snd_hda_get_jack_location(def_conf));
3872
3873 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003874#else
3875 return 0;
3876#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003877}
3878
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003879static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3880 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003881{
3882 struct sigmatel_event *event;
3883
3884 snd_array_init(&spec->events, sizeof(*event), 32);
3885 event = snd_array_new(&spec->events);
3886 if (!event)
3887 return -ENOMEM;
3888 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003889 event->type = type;
3890 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003891 event->data = data;
3892
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003893 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003894}
3895
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003896static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
3897 hda_nid_t nid, unsigned char type)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003898{
3899 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003900 struct sigmatel_event *event = spec->events.list;
3901 int i;
3902
3903 for (i = 0; i < spec->events.used; i++, event++) {
3904 if (event->nid == nid && event->type == type)
3905 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003906 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003907 return NULL;
3908}
3909
3910static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
3911 unsigned char tag)
3912{
3913 struct sigmatel_spec *spec = codec->spec;
3914 struct sigmatel_event *event = spec->events.list;
3915 int i;
3916
3917 for (i = 0; i < spec->events.used; i++, event++) {
3918 if (event->tag == tag)
3919 return event;
3920 }
3921 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003922}
3923
Takashi Iwai314634b2006-09-21 11:56:18 +02003924static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003925 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02003926{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003927 struct sigmatel_event *event;
3928 int tag;
3929
3930 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
3931 return;
3932 event = stac_get_event(codec, nid, type);
3933 if (event)
3934 tag = event->tag;
3935 else
3936 tag = stac_add_event(codec->spec, nid, type, 0);
3937 if (tag < 0)
3938 return;
3939 snd_hda_codec_write_cache(codec, nid, 0,
3940 AC_VERB_SET_UNSOLICITED_ENABLE,
3941 AC_USRSP_EN | tag);
Takashi Iwai314634b2006-09-21 11:56:18 +02003942}
3943
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003944static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3945{
3946 int i;
3947 for (i = 0; i < cfg->hp_outs; i++)
3948 if (cfg->hp_pins[i] == nid)
3949 return 1; /* nid is a HP-Out */
3950
3951 return 0; /* nid is not a HP-Out */
3952};
3953
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003954static void stac92xx_power_down(struct hda_codec *codec)
3955{
3956 struct sigmatel_spec *spec = codec->spec;
3957
3958 /* power down inactive DACs */
3959 hda_nid_t *dac;
3960 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003961 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01003962 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003963 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3964}
3965
Takashi Iwaif73d3582008-11-25 08:21:51 +01003966static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3967 int enable);
3968
Takashi Iwai6565e4f2009-03-02 14:38:35 +01003969/* override some hints from the hwdep entry */
3970static void stac_store_hints(struct hda_codec *codec)
3971{
3972 struct sigmatel_spec *spec = codec->spec;
3973 const char *p;
3974 int val;
3975
3976 val = snd_hda_get_bool_hint(codec, "hp_detect");
3977 if (val >= 0)
3978 spec->hp_detect = val;
3979 p = snd_hda_get_hint(codec, "gpio_mask");
3980 if (p) {
3981 spec->gpio_mask = simple_strtoul(p, NULL, 0);
3982 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
3983 spec->gpio_mask;
3984 }
3985 p = snd_hda_get_hint(codec, "gpio_dir");
3986 if (p)
3987 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
3988 p = snd_hda_get_hint(codec, "gpio_data");
3989 if (p)
3990 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
3991 p = snd_hda_get_hint(codec, "eapd_mask");
3992 if (p)
3993 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
3994 val = snd_hda_get_bool_hint(codec, "eapd_switch");
3995 if (val >= 0)
3996 spec->eapd_switch = val;
3997}
3998
Mattc7d4b2f2005-06-27 14:59:41 +02003999static int stac92xx_init(struct hda_codec *codec)
4000{
4001 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004002 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004003 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004004 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004005
Mattc7d4b2f2005-06-27 14:59:41 +02004006 snd_hda_sequence_write(codec, spec->init);
4007
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004008 /* power down adcs initially */
4009 if (spec->powerdown_adcs)
4010 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004011 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004012 spec->adc_nids[i], 0,
4013 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004014
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004015 /* override some hints */
4016 stac_store_hints(codec);
4017
Takashi Iwaif73d3582008-11-25 08:21:51 +01004018 /* set up GPIO */
4019 gpio = spec->gpio_data;
4020 /* turn on EAPD statically when spec->eapd_switch isn't set.
4021 * otherwise, unsol event will turn it on/off dynamically
4022 */
4023 if (!spec->eapd_switch)
4024 gpio |= spec->eapd_mask;
4025 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4026
Takashi Iwai82bc9552006-03-21 11:24:42 +01004027 /* set up pins */
4028 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004029 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004030 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004031 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004032 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004033 }
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004034 /* force to enable the first line-out; the others are set up
4035 * in unsol_event
4036 */
4037 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004038 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004039 /* fake event to set up pins */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004040 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4041 STAC_HP_EVENT);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004042 } else {
4043 stac92xx_auto_init_multi_out(codec);
4044 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004045 for (i = 0; i < cfg->hp_outs; i++)
4046 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004047 }
4048 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01004049 hda_nid_t nid = cfg->input_pins[i];
4050 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004051 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004052 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4053 /* for mic pins, force to initialize */
4054 pinctl = stac92xx_get_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004055 pinctl |= AC_PINCTL_IN_EN;
4056 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004057 } else {
4058 pinctl = snd_hda_codec_read(codec, nid, 0,
4059 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4060 /* if PINCTL already set then skip */
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004061 if (!(pinctl & AC_PINCTL_IN_EN)) {
4062 pinctl |= AC_PINCTL_IN_EN;
4063 stac92xx_auto_set_pinctl(codec, nid,
4064 pinctl);
4065 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004066 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004067 conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004068 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4069 enable_pin_detect(codec, nid,
4070 STAC_INSERT_EVENT);
4071 stac_issue_unsol_event(codec, nid,
4072 STAC_INSERT_EVENT);
4073 }
Takashi Iwaic960a032006-03-23 17:06:28 +01004074 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004075 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004076 for (i = 0; i < spec->num_dmics; i++)
4077 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4078 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004079 if (cfg->dig_out_pins[0])
4080 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004081 AC_PINCTL_OUT_EN);
4082 if (cfg->dig_in_pin)
4083 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4084 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004085 for (i = 0; i < spec->num_pwrs; i++) {
4086 hda_nid_t nid = spec->pwr_nids[i];
4087 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004088
Takashi Iwaieb632122008-12-19 16:39:48 +01004089 /* power on when no jack detection is available */
4090 if (!spec->hp_detect) {
4091 stac_toggle_power_map(codec, nid, 1);
4092 continue;
4093 }
4094
4095 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004096 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004097
Takashi Iwaif73d3582008-11-25 08:21:51 +01004098 pinctl = snd_hda_codec_read(codec, nid, 0,
4099 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4100 /* outputs are only ports capable of power management
4101 * any attempts on powering down a input port cause the
4102 * referenced VREF to act quirky.
4103 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004104 if (pinctl & AC_PINCTL_IN_EN) {
4105 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004106 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004107 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004108 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004109 def_conf = get_defcfg_connect(def_conf);
4110 /* skip any ports that don't have jacks since presence
4111 * detection is useless */
4112 if (def_conf != AC_JACK_PORT_COMPLEX) {
4113 if (def_conf != AC_JACK_PORT_NONE)
4114 stac_toggle_power_map(codec, nid, 1);
4115 continue;
4116 }
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004117 if (!stac_get_event(codec, nid, STAC_INSERT_EVENT)) {
4118 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
4119 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
4120 }
Takashi Iwaif73d3582008-11-25 08:21:51 +01004121 }
4122 if (spec->dac_list)
4123 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004124 return 0;
4125}
4126
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004127static void stac92xx_free_jacks(struct hda_codec *codec)
4128{
Takashi Iwaie4973e12008-11-18 09:32:42 +01004129#ifdef CONFIG_SND_JACK
Takashi Iwaib94d3532008-11-21 09:08:06 +01004130 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004131 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d3532008-11-21 09:08:06 +01004132 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004133 struct sigmatel_jack *jacks = spec->jacks.list;
4134 int i;
4135 for (i = 0; i < spec->jacks.used; i++)
4136 snd_device_free(codec->bus->card, &jacks[i].jack);
4137 }
4138 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004139#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004140}
4141
Takashi Iwai603c4012008-07-30 15:01:44 +02004142static void stac92xx_free_kctls(struct hda_codec *codec)
4143{
4144 struct sigmatel_spec *spec = codec->spec;
4145
4146 if (spec->kctls.list) {
4147 struct snd_kcontrol_new *kctl = spec->kctls.list;
4148 int i;
4149 for (i = 0; i < spec->kctls.used; i++)
4150 kfree(kctl[i].name);
4151 }
4152 snd_array_free(&spec->kctls);
4153}
4154
Matt2f2f4252005-04-13 14:45:30 +02004155static void stac92xx_free(struct hda_codec *codec)
4156{
Mattc7d4b2f2005-06-27 14:59:41 +02004157 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004158
4159 if (! spec)
4160 return;
4161
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004162 stac92xx_free_jacks(codec);
4163 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004164
Mattc7d4b2f2005-06-27 14:59:41 +02004165 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004166 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004167}
4168
Matt4e550962005-07-04 17:51:39 +02004169static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4170 unsigned int flag)
4171{
Takashi Iwai8ce841982009-01-22 16:59:20 +01004172 unsigned int old_ctl, pin_ctl;
4173
4174 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004175 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004176
Takashi Iwaif9acba42007-05-29 18:01:06 +02004177 if (pin_ctl & AC_PINCTL_IN_EN) {
4178 /*
4179 * we need to check the current set-up direction of
4180 * shared input pins since they can be switched via
4181 * "xxx as Output" mixer switch
4182 */
4183 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004184 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004185 return;
4186 }
4187
Takashi Iwai8ce841982009-01-22 16:59:20 +01004188 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004189 /* if setting pin direction bits, clear the current
4190 direction bits first */
4191 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4192 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4193
Takashi Iwai8ce841982009-01-22 16:59:20 +01004194 pin_ctl |= flag;
4195 if (old_ctl != pin_ctl)
4196 snd_hda_codec_write_cache(codec, nid, 0,
4197 AC_VERB_SET_PIN_WIDGET_CONTROL,
4198 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004199}
4200
4201static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4202 unsigned int flag)
4203{
4204 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4205 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce841982009-01-22 16:59:20 +01004206 if (pin_ctl & flag)
4207 snd_hda_codec_write_cache(codec, nid, 0,
4208 AC_VERB_SET_PIN_WIDGET_CONTROL,
4209 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004210}
4211
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004212static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004213{
4214 if (!nid)
4215 return 0;
4216 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004217 & (1 << 31))
4218 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004219 return 0;
4220}
4221
Takashi Iwaid7a89432008-11-12 09:48:04 +01004222/* return non-zero if the hp-pin of the given array index isn't
4223 * a jack-detection target
4224 */
4225static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4226{
4227 struct auto_pin_cfg *cfg = &spec->autocfg;
4228
4229 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004230 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004231 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004232 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004233 return 1;
4234 /* ignore if the pin is set as line-out */
4235 if (cfg->hp_pins[i] == spec->hp_switch)
4236 return 1;
4237 return 0;
4238}
4239
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004240static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004241{
4242 struct sigmatel_spec *spec = codec->spec;
4243 struct auto_pin_cfg *cfg = &spec->autocfg;
4244 int i, presence;
4245
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004246 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004247 if (spec->gpio_mute)
4248 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4249 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4250
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004251 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004252 if (presence)
4253 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004254 if (no_hp_sensing(spec, i))
4255 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004256 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4257 if (presence) {
4258 unsigned int pinctl;
4259 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4260 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4261 if (pinctl & AC_PINCTL_IN_EN)
4262 presence = 0; /* mic- or line-input */
4263 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004264 }
Matt4e550962005-07-04 17:51:39 +02004265
4266 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004267 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004268 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004269 stac92xx_reset_pinctl(codec, spec->hp_switch,
4270 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004271 for (i = 0; i < cfg->line_outs; i++)
4272 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4273 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004274 for (i = 0; i < cfg->speaker_outs; i++)
4275 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4276 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004277 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004278 stac_gpio_set(codec, spec->gpio_mask,
4279 spec->gpio_dir, spec->gpio_data &
4280 ~spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004281 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004282 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004283 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004284 stac92xx_set_pinctl(codec, spec->hp_switch,
4285 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004286 for (i = 0; i < cfg->line_outs; i++)
4287 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4288 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004289 for (i = 0; i < cfg->speaker_outs; i++)
4290 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4291 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004292 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004293 stac_gpio_set(codec, spec->gpio_mask,
4294 spec->gpio_dir, spec->gpio_data |
4295 spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004296 }
Takashi Iwaid7a89432008-11-12 09:48:04 +01004297 /* toggle hp outs */
4298 for (i = 0; i < cfg->hp_outs; i++) {
4299 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4300 if (no_hp_sensing(spec, i))
4301 continue;
4302 if (presence)
4303 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004304#if 0 /* FIXME */
4305/* Resetting the pinctl like below may lead to (a sort of) regressions
4306 * on some devices since they use the HP pin actually for line/speaker
4307 * outs although the default pin config shows a different pin (that is
4308 * wrong and useless).
4309 *
4310 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4311 * But, disabling the code below just works around it, and I'm too tired of
4312 * bug reports with such devices...
4313 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004314 else
4315 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004316#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004317 }
Matt4e550962005-07-04 17:51:39 +02004318}
4319
Takashi Iwaif73d3582008-11-25 08:21:51 +01004320static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4321 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004322{
4323 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004324 unsigned int idx, val;
4325
4326 for (idx = 0; idx < spec->num_pwrs; idx++) {
4327 if (spec->pwr_nids[idx] == nid)
4328 break;
4329 }
4330 if (idx >= spec->num_pwrs)
4331 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004332
4333 /* several codecs have two power down bits */
4334 if (spec->pwr_mapping)
4335 idx = spec->pwr_mapping[idx];
4336 else
4337 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004338
Takashi Iwaif73d3582008-11-25 08:21:51 +01004339 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4340 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004341 val &= ~idx;
4342 else
4343 val |= idx;
4344
4345 /* power down unused output ports */
4346 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004347}
4348
Takashi Iwaif73d3582008-11-25 08:21:51 +01004349static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4350{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004351 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004352}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004353
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004354static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4355{
4356 struct sigmatel_spec *spec = codec->spec;
4357 struct sigmatel_jack *jacks = spec->jacks.list;
4358
4359 if (jacks) {
4360 int i;
4361 for (i = 0; i < spec->jacks.used; i++) {
4362 if (jacks->nid == nid) {
4363 unsigned int pin_ctl =
4364 snd_hda_codec_read(codec, nid,
4365 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4366 0x00);
4367 int type = jacks->type;
4368 if (type == (SND_JACK_LINEOUT
4369 | SND_JACK_HEADPHONE))
4370 type = (pin_ctl & AC_PINCTL_HP_EN)
4371 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4372 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004373 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004374 ? type : 0);
4375 }
4376 jacks++;
4377 }
4378 }
4379}
Matt2f2f4252005-04-13 14:45:30 +02004380
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004381static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4382 unsigned char type)
4383{
4384 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4385 if (!event)
4386 return;
4387 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4388}
4389
Takashi Iwai314634b2006-09-21 11:56:18 +02004390static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4391{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004392 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004393 struct sigmatel_event *event;
4394 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004395
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004396 tag = (res >> 26) & 0x7f;
4397 event = stac_get_event_from_tag(codec, tag);
4398 if (!event)
4399 return;
4400
4401 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004402 case STAC_HP_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004403 stac92xx_hp_detect(codec);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004404 /* fallthru */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004405 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004406 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004407 if (spec->num_pwrs > 0)
4408 stac92xx_pin_sense(codec, event->nid);
4409 stac92xx_report_jack(codec, event->nid);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004410 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004411 case STAC_VREF_EVENT:
4412 data = snd_hda_codec_read(codec, codec->afg, 0,
4413 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004414 /* toggle VREF state based on GPIOx status */
4415 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004416 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004417 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004418 }
4419}
4420
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004421#ifdef CONFIG_PROC_FS
4422static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4423 struct hda_codec *codec, hda_nid_t nid)
4424{
4425 if (nid == codec->afg)
4426 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4427 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4428}
4429
4430static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4431 struct hda_codec *codec,
4432 unsigned int verb)
4433{
4434 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4435 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4436}
4437
4438/* stac92hd71bxx, stac92hd73xx */
4439static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4440 struct hda_codec *codec, hda_nid_t nid)
4441{
4442 stac92hd_proc_hook(buffer, codec, nid);
4443 if (nid == codec->afg)
4444 analog_loop_proc_hook(buffer, codec, 0xfa0);
4445}
4446
4447static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4448 struct hda_codec *codec, hda_nid_t nid)
4449{
4450 if (nid == codec->afg)
4451 analog_loop_proc_hook(buffer, codec, 0xfe0);
4452}
4453
4454static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4455 struct hda_codec *codec, hda_nid_t nid)
4456{
4457 if (nid == codec->afg)
4458 analog_loop_proc_hook(buffer, codec, 0xfeb);
4459}
4460#else
4461#define stac92hd_proc_hook NULL
4462#define stac92hd7x_proc_hook NULL
4463#define stac9205_proc_hook NULL
4464#define stac927x_proc_hook NULL
4465#endif
4466
Takashi Iwaicb53c622007-08-10 17:21:45 +02004467#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004468static int stac92xx_resume(struct hda_codec *codec)
4469{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004470 struct sigmatel_spec *spec = codec->spec;
4471
Takashi Iwai2c885872008-11-18 09:36:55 +01004472 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004473 snd_hda_codec_resume_amp(codec);
4474 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004475 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004476 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004477 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4478 STAC_HP_EVENT);
Mattff6fdc32005-06-27 15:06:52 +02004479 return 0;
4480}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004481
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004482
4483/*
4484 * using power check for controlling mute led of HP HDX notebooks
4485 * check for mute state only on Speakers (nid = 0x10)
4486 *
4487 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4488 * the LED is NOT working properly !
4489 */
4490
4491#ifdef CONFIG_SND_HDA_POWER_SAVE
4492static int stac92xx_check_power_status (struct hda_codec * codec, hda_nid_t nid)
4493{
4494 struct sigmatel_spec *spec = codec->spec;
4495
4496 /* only handle on HP HDX */
4497 if (spec->board_config != STAC_HP_HDX)
4498 return 0;
4499
4500 if (nid == 0x10)
4501 {
4502 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4503 HDA_AMP_MUTE)
4504 spec->gpio_data &= ~0x08; /* orange */
4505 else
4506 spec->gpio_data |= 0x08; /* white */
4507
4508 stac_gpio_set(codec, spec->gpio_mask,
4509 spec->gpio_dir,
4510 spec->gpio_data);
4511 }
4512
4513 return 0;
4514}
4515#endif
4516
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004517static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4518{
4519 struct sigmatel_spec *spec = codec->spec;
4520 if (spec->eapd_mask)
4521 stac_gpio_set(codec, spec->gpio_mask,
4522 spec->gpio_dir, spec->gpio_data &
4523 ~spec->eapd_mask);
4524 return 0;
4525}
Mattff6fdc32005-06-27 15:06:52 +02004526#endif
4527
Matt2f2f4252005-04-13 14:45:30 +02004528static struct hda_codec_ops stac92xx_patch_ops = {
4529 .build_controls = stac92xx_build_controls,
4530 .build_pcms = stac92xx_build_pcms,
4531 .init = stac92xx_init,
4532 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004533 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004534#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004535 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004536 .resume = stac92xx_resume,
4537#endif
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004538#ifdef CONFIG_SND_HDA_POWER_SAVE
4539 .check_power_status = stac92xx_check_power_status,
4540#endif
Matt2f2f4252005-04-13 14:45:30 +02004541};
4542
4543static int patch_stac9200(struct hda_codec *codec)
4544{
4545 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004546 int err;
Matt2f2f4252005-04-13 14:45:30 +02004547
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004548 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004549 if (spec == NULL)
4550 return -ENOMEM;
4551
4552 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004553 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004554 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004555 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4556 stac9200_models,
4557 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01004558 if (spec->board_config < 0)
Richard Fish11b44bb2006-08-23 18:31:34 +02004559 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01004560 else
4561 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004562 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02004563
4564 spec->multiout.max_channels = 2;
4565 spec->multiout.num_dacs = 1;
4566 spec->multiout.dac_nids = stac9200_dac_nids;
4567 spec->adc_nids = stac9200_adc_nids;
4568 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004569 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004570 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004571 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004572 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004573
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02004574 if (spec->board_config == STAC_9200_M4 ||
4575 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01004576 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004577 spec->init = stac9200_eapd_init;
4578 else
4579 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004580 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004581
Takashi Iwai117f2572008-03-18 09:53:23 +01004582 if (spec->board_config == STAC_9200_PANASONIC) {
4583 spec->gpio_mask = spec->gpio_dir = 0x09;
4584 spec->gpio_data = 0x00;
4585 }
4586
Mattc7d4b2f2005-06-27 14:59:41 +02004587 err = stac9200_parse_auto_config(codec);
4588 if (err < 0) {
4589 stac92xx_free(codec);
4590 return err;
4591 }
Matt2f2f4252005-04-13 14:45:30 +02004592
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01004593 /* CF-74 has no headphone detection, and the driver should *NOT*
4594 * do detection and HP/speaker toggle because the hardware does it.
4595 */
4596 if (spec->board_config == STAC_9200_PANASONIC)
4597 spec->hp_detect = 0;
4598
Matt2f2f4252005-04-13 14:45:30 +02004599 codec->patch_ops = stac92xx_patch_ops;
4600
4601 return 0;
4602}
4603
Tobin Davis8e21c342007-01-08 11:04:17 +01004604static int patch_stac925x(struct hda_codec *codec)
4605{
4606 struct sigmatel_spec *spec;
4607 int err;
4608
4609 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4610 if (spec == NULL)
4611 return -ENOMEM;
4612
4613 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004614 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004615 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004616
4617 /* Check first for codec ID */
4618 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
4619 STAC_925x_MODELS,
4620 stac925x_models,
4621 stac925x_codec_id_cfg_tbl);
4622
4623 /* Now checks for PCI ID, if codec ID is not found */
4624 if (spec->board_config < 0)
4625 spec->board_config = snd_hda_check_board_config(codec,
4626 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01004627 stac925x_models,
4628 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004629 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004630 if (spec->board_config < 0)
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004631 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
Tobin Davis2c11f952007-05-17 09:36:34 +02004632 "using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01004633 else
4634 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004635 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01004636
4637 spec->multiout.max_channels = 2;
4638 spec->multiout.num_dacs = 1;
4639 spec->multiout.dac_nids = stac925x_dac_nids;
4640 spec->adc_nids = stac925x_adc_nids;
4641 spec->mux_nids = stac925x_mux_nids;
4642 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004643 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004644 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004645 switch (codec->vendor_id) {
4646 case 0x83847632: /* STAC9202 */
4647 case 0x83847633: /* STAC9202D */
4648 case 0x83847636: /* STAC9251 */
4649 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004650 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004651 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004652 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4653 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004654 break;
4655 default:
4656 spec->num_dmics = 0;
4657 break;
4658 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004659
4660 spec->init = stac925x_core_init;
4661 spec->mixer = stac925x_mixer;
4662
4663 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004664 if (!err) {
4665 if (spec->board_config < 0) {
4666 printk(KERN_WARNING "hda_codec: No auto-config is "
4667 "available, default to model=ref\n");
4668 spec->board_config = STAC_925x_REF;
4669 goto again;
4670 }
4671 err = -EINVAL;
4672 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004673 if (err < 0) {
4674 stac92xx_free(codec);
4675 return err;
4676 }
4677
4678 codec->patch_ops = stac92xx_patch_ops;
4679
4680 return 0;
4681}
4682
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004683static struct hda_input_mux stac92hd73xx_dmux = {
4684 .num_items = 4,
4685 .items = {
4686 { "Analog Inputs", 0x0b },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004687 { "Digital Mic 1", 0x09 },
4688 { "Digital Mic 2", 0x0a },
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004689 { "CD", 0x08 },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004690 }
4691};
4692
4693static int patch_stac92hd73xx(struct hda_codec *codec)
4694{
4695 struct sigmatel_spec *spec;
4696 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4697 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004698 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004699
4700 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4701 if (spec == NULL)
4702 return -ENOMEM;
4703
4704 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004705 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004706 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4707 spec->pin_nids = stac92hd73xx_pin_nids;
4708 spec->board_config = snd_hda_check_board_config(codec,
4709 STAC_92HD73XX_MODELS,
4710 stac92hd73xx_models,
4711 stac92hd73xx_cfg_tbl);
4712again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004713 if (spec->board_config < 0)
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004714 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4715 " STAC92HD73XX, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01004716 else
4717 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004718 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004719
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004720 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004721 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4722
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004723 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004724 printk(KERN_WARNING "hda_codec: Could not determine "
4725 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004726 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004727 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004728 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004729 case 0x3: /* 6 Channel */
4730 spec->mixer = stac92hd73xx_6ch_mixer;
4731 spec->init = stac92hd73xx_6ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004732 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004733 break;
4734 case 0x4: /* 8 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004735 spec->mixer = stac92hd73xx_8ch_mixer;
4736 spec->init = stac92hd73xx_8ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004737 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004738 break;
4739 case 0x5: /* 10 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004740 spec->mixer = stac92hd73xx_10ch_mixer;
4741 spec->init = stac92hd73xx_10ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004742 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
4743 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004744 }
4745 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004746
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004747 spec->aloopback_mask = 0x01;
4748 spec->aloopback_shift = 8;
4749
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004750 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004751 spec->mux_nids = stac92hd73xx_mux_nids;
4752 spec->adc_nids = stac92hd73xx_adc_nids;
4753 spec->dmic_nids = stac92hd73xx_dmic_nids;
4754 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004755 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04004756 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004757 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004758
4759 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4760 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01004761 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004762 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4763 sizeof(stac92hd73xx_dmux));
4764
Matthew Ranostaya7662642008-02-21 07:51:14 +01004765 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004766 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004767 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004768 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004769 case STAC_DELL_M6_AMIC:
4770 case STAC_DELL_M6_DMIC:
4771 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004772 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004773 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4774 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004775 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004776 spec->num_amps = 1;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004777
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004778 if (spec->board_config != STAC_DELL_EQ)
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004779 spec->init = dell_m6_core_init;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004780 switch (spec->board_config) {
4781 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01004782 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01004783 spec->num_dmics = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004784 spec->private_dimux.num_items = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004785 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004786 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01004787 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01004788 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004789 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004790 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004791 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01004792 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
4793 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01004794 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004795 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004796 break;
4797 }
4798 break;
4799 default:
4800 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004801 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004802 spec->eapd_switch = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004803 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04004804 if (spec->board_config > STAC_92HD73XX_REF) {
4805 /* GPIO0 High = Enable EAPD */
4806 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4807 spec->gpio_data = 0x01;
4808 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004809 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004810
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004811 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4812 spec->pwr_nids = stac92hd73xx_pwr_nids;
4813
Matthew Ranostayd9737752008-09-07 12:03:41 +02004814 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004815
4816 if (!err) {
4817 if (spec->board_config < 0) {
4818 printk(KERN_WARNING "hda_codec: No auto-config is "
4819 "available, default to model=ref\n");
4820 spec->board_config = STAC_92HD73XX_REF;
4821 goto again;
4822 }
4823 err = -EINVAL;
4824 }
4825
4826 if (err < 0) {
4827 stac92xx_free(codec);
4828 return err;
4829 }
4830
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01004831 if (spec->board_config == STAC_92HD73XX_NO_JD)
4832 spec->hp_detect = 0;
4833
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004834 codec->patch_ops = stac92xx_patch_ops;
4835
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004836 codec->proc_widget_hook = stac92hd7x_proc_hook;
4837
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004838 return 0;
4839}
4840
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004841static struct hda_input_mux stac92hd83xxx_dmux = {
4842 .num_items = 3,
4843 .items = {
4844 { "Analog Inputs", 0x03 },
4845 { "Digital Mic 1", 0x04 },
4846 { "Digital Mic 2", 0x05 },
4847 }
4848};
4849
4850static int patch_stac92hd83xxx(struct hda_codec *codec)
4851{
4852 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05004853 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004854 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05004855 int num_dacs;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05004856 hda_nid_t nid;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004857
4858 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4859 if (spec == NULL)
4860 return -ENOMEM;
4861
4862 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004863 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004864 spec->mono_nid = 0x19;
4865 spec->digbeep_nid = 0x21;
4866 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4867 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4868 spec->adc_nids = stac92hd83xxx_adc_nids;
4869 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayc15c5062009-01-13 13:30:07 -05004870 spec->amp_nids = stac92hd83xxx_amp_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004871 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4872 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004873 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004874
4875 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004876 spec->mixer = stac92hd83xxx_mixer;
4877 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4878 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4879 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayc15c5062009-01-13 13:30:07 -05004880 spec->num_amps = ARRAY_SIZE(stac92hd83xxx_amp_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004881 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4882 spec->dinput_mux = &stac92hd83xxx_dmux;
4883 spec->pin_nids = stac92hd83xxx_pin_nids;
4884 spec->board_config = snd_hda_check_board_config(codec,
4885 STAC_92HD83XXX_MODELS,
4886 stac92hd83xxx_models,
4887 stac92hd83xxx_cfg_tbl);
4888again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004889 if (spec->board_config < 0)
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004890 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4891 " STAC92HD83XXX, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01004892 else
4893 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004894 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004895
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05004896 switch (codec->vendor_id) {
4897 case 0x111d7604:
4898 case 0x111d7605:
4899 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
4900 break;
4901 spec->num_pwrs = 0;
4902 break;
4903 }
4904
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004905 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4906 if (!err) {
4907 if (spec->board_config < 0) {
4908 printk(KERN_WARNING "hda_codec: No auto-config is "
4909 "available, default to model=ref\n");
4910 spec->board_config = STAC_92HD83XXX_REF;
4911 goto again;
4912 }
4913 err = -EINVAL;
4914 }
4915
4916 if (err < 0) {
4917 stac92xx_free(codec);
4918 return err;
4919 }
4920
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05004921 switch (spec->board_config) {
4922 case STAC_DELL_S14:
4923 nid = 0xf;
4924 break;
4925 default:
4926 nid = 0xe;
4927 break;
4928 }
4929
4930 num_dacs = snd_hda_get_connections(codec, nid,
4931 conn, STAC92HD83_DAC_COUNT + 1) - 1;
4932
4933 /* set port X to select the last DAC
4934 */
4935 snd_hda_codec_write_cache(codec, nid, 0,
4936 AC_VERB_SET_CONNECT_SEL, num_dacs);
4937
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004938 codec->patch_ops = stac92xx_patch_ops;
4939
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004940 codec->proc_widget_hook = stac92hd_proc_hook;
4941
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004942 return 0;
4943}
4944
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05004945static struct hda_input_mux stac92hd71bxx_dmux_nomixer = {
4946 .num_items = 3,
4947 .items = {
4948 { "Analog Inputs", 0x00 },
4949 { "Digital Mic 1", 0x02 },
4950 { "Digital Mic 2", 0x03 },
4951 }
4952};
4953
4954static struct hda_input_mux stac92hd71bxx_dmux_amixer = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004955 .num_items = 4,
4956 .items = {
4957 { "Analog Inputs", 0x00 },
4958 { "Mixer", 0x01 },
4959 { "Digital Mic 1", 0x02 },
4960 { "Digital Mic 2", 0x03 },
4961 }
4962};
4963
Takashi Iwai330ee992009-02-20 14:33:36 +01004964/* get the pin connection (fixed, none, etc) */
4965static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4966{
4967 struct sigmatel_spec *spec = codec->spec;
4968 unsigned int cfg;
4969
4970 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4971 return get_defcfg_connect(cfg);
4972}
4973
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05004974static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
4975 hda_nid_t *nids, int num_nids)
4976{
4977 struct sigmatel_spec *spec = codec->spec;
4978 int idx, num;
4979 unsigned int def_conf;
4980
4981 for (num = 0; num < num_nids; num++) {
4982 for (idx = 0; idx < spec->num_pins; idx++)
4983 if (spec->pin_nids[idx] == nids[num])
4984 break;
4985 if (idx >= spec->num_pins)
4986 break;
Takashi Iwai330ee992009-02-20 14:33:36 +01004987 def_conf = stac_get_defcfg_connect(codec, idx);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05004988 if (def_conf == AC_JACK_PORT_NONE)
4989 break;
4990 }
4991 return num;
4992}
4993
4994static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
4995 hda_nid_t dig0pin)
4996{
4997 struct sigmatel_spec *spec = codec->spec;
4998 int idx;
4999
5000 for (idx = 0; idx < spec->num_pins; idx++)
5001 if (spec->pin_nids[idx] == dig0pin)
5002 break;
5003 if ((idx + 2) >= spec->num_pins)
5004 return 0;
5005
5006 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005007 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005008 return 2;
5009
5010 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005011 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005012 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005013 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005014 return 1;
5015 else
5016 return 0;
5017}
5018
Matthew Ranostaye035b842007-11-06 11:53:55 +01005019static int patch_stac92hd71bxx(struct hda_codec *codec)
5020{
5021 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005022 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005023 int err = 0;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005024 unsigned int ndmic_nids = 0;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005025
5026 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5027 if (spec == NULL)
5028 return -ENOMEM;
5029
5030 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005031 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005032 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5033 switch (codec->vendor_id) {
5034 case 0x111d76b6:
5035 case 0x111d76b7:
5036 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5037 break;
5038 case 0x111d7603:
5039 case 0x111d7608:
5040 /* On 92HD75Bx 0x27 isn't a pin nid */
5041 spec->num_pins--;
5042 /* fallthrough */
5043 default:
5044 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5045 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005046 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005047 spec->board_config = snd_hda_check_board_config(codec,
5048 STAC_92HD71BXX_MODELS,
5049 stac92hd71bxx_models,
5050 stac92hd71bxx_cfg_tbl);
5051again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005052 if (spec->board_config < 0)
Matthew Ranostaye035b842007-11-06 11:53:55 +01005053 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5054 " STAC92HD71BXX, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01005055 else
5056 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005057 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005058
Takashi Iwai41c3b642008-11-18 10:45:15 +01005059 if (spec->board_config > STAC_92HD71BXX_REF) {
5060 /* GPIO0 = EAPD */
5061 spec->gpio_mask = 0x01;
5062 spec->gpio_dir = 0x01;
5063 spec->gpio_data = 0x01;
5064 }
5065
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005066 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5067 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5068
Matthew Ranostay541eee82007-12-14 12:08:04 +01005069 switch (codec->vendor_id) {
5070 case 0x111d76b6: /* 4 Port without Analog Mixer */
5071 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005072 unmute_init++;
5073 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005074 case 0x111d76b4: /* 6 Port without Analog Mixer */
5075 case 0x111d76b5:
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005076 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_nomixer,
5077 sizeof(stac92hd71bxx_dmux_nomixer));
Matthew Ranostay541eee82007-12-14 12:08:04 +01005078 spec->mixer = stac92hd71bxx_mixer;
5079 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005080 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005081 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5082 stac92hd71bxx_dmic_nids,
5083 STAC92HD71BXX_NUM_DMICS);
5084 if (spec->num_dmics) {
5085 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5086 spec->dinput_mux = &spec->private_dimux;
5087 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5088 }
Matthew Ranostay541eee82007-12-14 12:08:04 +01005089 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005090 case 0x111d7608: /* 5 Port with Analog Mixer */
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005091 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5092 sizeof(stac92hd71bxx_dmux_amixer));
5093 spec->private_dimux.num_items--;
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005094 switch (spec->board_config) {
5095 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005096 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005097 err = stac_add_event(spec, codec->afg,
5098 STAC_VREF_EVENT, 0x02);
5099 if (err < 0)
5100 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005101 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005102 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5103 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005104 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005105 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005106 spec->gpio_mask |= 0x02;
5107 break;
5108 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005109 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005110 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005111 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005112
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005113 /* no output amps */
5114 spec->num_pwrs = 0;
5115 spec->mixer = stac92hd71bxx_analog_mixer;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005116 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005117
5118 /* disable VSW */
5119 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005120 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005121 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5122 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005123 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5124 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5125 stac92hd71bxx_dmic_nids,
5126 STAC92HD71BXX_NUM_DMICS - 1);
5127 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5128 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 2;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005129 break;
5130 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005131 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005132 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005133
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005134 /* no output amps */
5135 spec->num_pwrs = 0;
5136 /* fallthru */
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005137 case 0x111d76b2: /* Codec of HP HDX16/HDX18 */
5138
5139 /* orange/white mute led on GPIO3, orange=0, white=1 */
5140 spec->gpio_mask |= 0x08;
5141 spec->gpio_dir |= 0x08;
5142 spec->gpio_data |= 0x08; /* set to white */
5143 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005144 default:
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005145 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5146 sizeof(stac92hd71bxx_dmux_amixer));
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005147 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005148 spec->mixer = stac92hd71bxx_analog_mixer;
5149 spec->init = stac92hd71bxx_analog_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005150 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005151 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5152 stac92hd71bxx_dmic_nids,
5153 STAC92HD71BXX_NUM_DMICS);
5154 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5155 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005156 }
5157
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005158 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5159 snd_hda_sequence_write_cache(codec, unmute_init);
5160
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005161 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005162 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005163 spec->aloopback_shift = 0;
5164
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005165 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005166 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005167 spec->mux_nids = stac92hd71bxx_mux_nids;
5168 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005169 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005170 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005171
5172 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5173 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005174 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005175
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005176 switch (spec->board_config) {
5177 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005178 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005179 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005180 stac92xx_auto_set_pinctl(codec, 0x0e,
5181 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005182 /* fallthru */
5183 case STAC_DELL_M4_2:
5184 spec->num_dmics = 0;
5185 spec->num_smuxes = 0;
5186 spec->num_dmuxes = 0;
5187 break;
5188 case STAC_DELL_M4_1:
5189 case STAC_DELL_M4_3:
5190 spec->num_dmics = 1;
5191 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005192 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005193 break;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005194 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005195 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005196 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5197 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005198 case STAC_HP_HDX:
5199 spec->num_dmics = 1;
5200 spec->num_dmuxes = 1;
5201 spec->num_smuxes = 1;
5202 break;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005203 };
5204
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005205 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005206 if (spec->dinput_mux)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005207 spec->private_dimux.num_items += spec->num_dmics - ndmic_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005208
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005209 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005210 if (!err) {
5211 if (spec->board_config < 0) {
5212 printk(KERN_WARNING "hda_codec: No auto-config is "
5213 "available, default to model=ref\n");
5214 spec->board_config = STAC_92HD71BXX_REF;
5215 goto again;
5216 }
5217 err = -EINVAL;
5218 }
5219
5220 if (err < 0) {
5221 stac92xx_free(codec);
5222 return err;
5223 }
5224
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005225 codec->proc_widget_hook = stac92hd7x_proc_hook;
5226
Matthew Ranostaye035b842007-11-06 11:53:55 +01005227 return 0;
5228};
5229
Matt2f2f4252005-04-13 14:45:30 +02005230static int patch_stac922x(struct hda_codec *codec)
5231{
5232 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005233 int err;
Matt2f2f4252005-04-13 14:45:30 +02005234
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005235 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005236 if (spec == NULL)
5237 return -ENOMEM;
5238
5239 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005240 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005241 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005242 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5243 stac922x_models,
5244 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005245 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005246 spec->gpio_mask = spec->gpio_dir = 0x03;
5247 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005248 /* Intel Macs have all same PCI SSID, so we need to check
5249 * codec SSID to distinguish the exact models
5250 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005251 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005252 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005253
5254 case 0x106b0800:
5255 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005256 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005257 case 0x106b0600:
5258 case 0x106b0700:
5259 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005260 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005261 case 0x106b0e00:
5262 case 0x106b0f00:
5263 case 0x106b1600:
5264 case 0x106b1700:
5265 case 0x106b0200:
5266 case 0x106b1e00:
5267 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005268 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005269 case 0x106b1a00:
5270 case 0x00000100:
5271 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005272 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005273 case 0x106b0a00:
5274 case 0x106b2200:
5275 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005276 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005277 default:
5278 spec->board_config = STAC_INTEL_MAC_V3;
5279 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005280 }
5281 }
5282
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005283 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005284 if (spec->board_config < 0)
Richard Fish11b44bb2006-08-23 18:31:34 +02005285 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
5286 "using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01005287 else
5288 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005289 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005290
Matt2f2f4252005-04-13 14:45:30 +02005291 spec->adc_nids = stac922x_adc_nids;
5292 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005293 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005294 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005295 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005296 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005297
5298 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005299 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005300
5301 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005302
Matt Porter3cc08dc2006-01-23 15:27:49 +01005303 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005304 if (!err) {
5305 if (spec->board_config < 0) {
5306 printk(KERN_WARNING "hda_codec: No auto-config is "
5307 "available, default to model=ref\n");
5308 spec->board_config = STAC_D945_REF;
5309 goto again;
5310 }
5311 err = -EINVAL;
5312 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005313 if (err < 0) {
5314 stac92xx_free(codec);
5315 return err;
5316 }
5317
5318 codec->patch_ops = stac92xx_patch_ops;
5319
Takashi Iwai807a46362007-05-29 19:01:37 +02005320 /* Fix Mux capture level; max to 2 */
5321 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5322 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5323 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5324 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5325 (0 << AC_AMPCAP_MUTE_SHIFT));
5326
Matt Porter3cc08dc2006-01-23 15:27:49 +01005327 return 0;
5328}
5329
5330static int patch_stac927x(struct hda_codec *codec)
5331{
5332 struct sigmatel_spec *spec;
5333 int err;
5334
5335 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5336 if (spec == NULL)
5337 return -ENOMEM;
5338
5339 codec->spec = spec;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005340 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005341 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005342 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005343 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5344 stac927x_models,
5345 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005346 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005347 if (spec->board_config < 0)
Herton Ronaldo Krzesinskic98041f2009-02-11 20:33:15 -02005348 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5349 "STAC927x, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01005350 else
5351 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005352 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005353
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005354 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005355 spec->adc_nids = stac927x_adc_nids;
5356 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5357 spec->mux_nids = stac927x_mux_nids;
5358 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005359 spec->smux_nids = stac927x_smux_nids;
5360 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005361 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005362 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005363 spec->multiout.dac_nids = spec->dac_nids;
5364
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005365 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005366 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005367 case STAC_D965_5ST:
5368 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005369 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005370 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005371 spec->num_dmics = 0;
5372
Tobin Davis93ed1502006-09-01 21:03:12 +02005373 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005374 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005375 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005376 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005377 switch (codec->subsystem_id) {
5378 case 0x10280209:
5379 case 0x1028022e:
5380 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005381 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005382 break;
5383 };
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005384 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005385 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005386 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005387 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005388 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005389 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005390 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005391 case STAC_DELL_3ST:
5392 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005393 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005394 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005395 spec->dmic_nids = stac927x_dmic_nids;
5396 spec->num_dmics = STAC927X_NUM_DMICS;
5397
Tobin Davis93ed1502006-09-01 21:03:12 +02005398 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005399 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005400 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005401 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005402 break;
5403 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005404 if (spec->board_config > STAC_D965_REF) {
5405 /* GPIO0 High = Enable EAPD */
5406 spec->eapd_mask = spec->gpio_mask = 0x01;
5407 spec->gpio_dir = spec->gpio_data = 0x01;
5408 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005409 spec->num_dmics = 0;
5410
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005411 spec->init = stac927x_core_init;
5412 spec->mixer = stac927x_mixer;
5413 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005414
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005415 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005416 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005417 spec->aloopback_mask = 0x40;
5418 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005419 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005420
Matt Porter3cc08dc2006-01-23 15:27:49 +01005421 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005422 if (!err) {
5423 if (spec->board_config < 0) {
5424 printk(KERN_WARNING "hda_codec: No auto-config is "
5425 "available, default to model=ref\n");
5426 spec->board_config = STAC_D965_REF;
5427 goto again;
5428 }
5429 err = -EINVAL;
5430 }
Mattc7d4b2f2005-06-27 14:59:41 +02005431 if (err < 0) {
5432 stac92xx_free(codec);
5433 return err;
5434 }
Matt2f2f4252005-04-13 14:45:30 +02005435
5436 codec->patch_ops = stac92xx_patch_ops;
5437
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005438 codec->proc_widget_hook = stac927x_proc_hook;
5439
Takashi Iwai52987652008-01-16 16:09:47 +01005440 /*
5441 * !!FIXME!!
5442 * The STAC927x seem to require fairly long delays for certain
5443 * command sequences. With too short delays (even if the answer
5444 * is set to RIRB properly), it results in the silence output
5445 * on some hardwares like Dell.
5446 *
5447 * The below flag enables the longer delay (see get_response
5448 * in hda_intel.c).
5449 */
5450 codec->bus->needs_damn_long_delay = 1;
5451
Takashi Iwaie28d8322008-12-17 13:48:29 +01005452 /* no jack detecion for ref-no-jd model */
5453 if (spec->board_config == STAC_D965_REF_NO_JD)
5454 spec->hp_detect = 0;
5455
Matt2f2f4252005-04-13 14:45:30 +02005456 return 0;
5457}
5458
Matt Porterf3302a52006-07-31 12:49:34 +02005459static int patch_stac9205(struct hda_codec *codec)
5460{
5461 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005462 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005463
5464 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5465 if (spec == NULL)
5466 return -ENOMEM;
5467
5468 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005469 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005470 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005471 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5472 stac9205_models,
5473 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005474 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005475 if (spec->board_config < 0)
Richard Fish11b44bb2006-08-23 18:31:34 +02005476 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
Takashi Iwai330ee992009-02-20 14:33:36 +01005477 else
5478 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005479 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02005480
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005481 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005482 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005483 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005484 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005485 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005486 spec->smux_nids = stac9205_smux_nids;
5487 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005488 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005489 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005490 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005491 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005492 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005493
5494 spec->init = stac9205_core_init;
5495 spec->mixer = stac9205_mixer;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005496 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02005497
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005498 spec->aloopback_mask = 0x40;
5499 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01005500 /* Turn on/off EAPD per HP plugging */
5501 if (spec->board_config != STAC_9205_EAPD)
5502 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005503 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005504
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005505 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005506 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005507 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005508 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5509 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005510
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005511 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005512 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5513 if (err < 0)
5514 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005515 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005516 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5517 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005518 AC_VERB_SET_UNSOLICITED_ENABLE,
5519 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005520
5521 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005522 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005523 spec->gpio_mask = 0x1b;
5524 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005525 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005526 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005527 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005528 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005529 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005530 case STAC_9205_REF:
5531 /* SPDIF-In enabled */
5532 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005533 default:
5534 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005535 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005536 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005537 break;
5538 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005539
Matt Porterf3302a52006-07-31 12:49:34 +02005540 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005541 if (!err) {
5542 if (spec->board_config < 0) {
5543 printk(KERN_WARNING "hda_codec: No auto-config is "
5544 "available, default to model=ref\n");
5545 spec->board_config = STAC_9205_REF;
5546 goto again;
5547 }
5548 err = -EINVAL;
5549 }
Matt Porterf3302a52006-07-31 12:49:34 +02005550 if (err < 0) {
5551 stac92xx_free(codec);
5552 return err;
5553 }
5554
5555 codec->patch_ops = stac92xx_patch_ops;
5556
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005557 codec->proc_widget_hook = stac9205_proc_hook;
5558
Matt Porterf3302a52006-07-31 12:49:34 +02005559 return 0;
5560}
5561
Matt2f2f4252005-04-13 14:45:30 +02005562/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005563 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005564 */
5565
Takashi Iwai1e137f92009-01-21 07:41:22 +01005566static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02005567 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005568 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5569 {}
5570};
5571
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005572static struct snd_kcontrol_new stac9872_mixer[] = {
5573 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5574 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005575 { } /* end */
5576};
5577
5578static hda_nid_t stac9872_pin_nids[] = {
5579 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5580 0x11, 0x13, 0x14,
5581};
5582
5583static hda_nid_t stac9872_adc_nids[] = {
5584 0x8 /*,0x6*/
5585};
5586
5587static hda_nid_t stac9872_mux_nids[] = {
5588 0x15
5589};
5590
Guillaume Munch6d859062006-08-22 17:15:47 +02005591static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005592{
5593 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01005594 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005595
Takashi Iwaidb064e52006-03-16 16:04:58 +01005596 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5597 if (spec == NULL)
5598 return -ENOMEM;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005599 codec->spec = spec;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005600
Takashi Iwai1e137f92009-01-21 07:41:22 +01005601#if 0 /* no model right now */
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005602 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5603 stac9872_models,
5604 stac9872_cfg_tbl);
Takashi Iwai1e137f92009-01-21 07:41:22 +01005605#endif
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005606
Takashi Iwai1e137f92009-01-21 07:41:22 +01005607 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5608 spec->pin_nids = stac9872_pin_nids;
5609 spec->multiout.dac_nids = spec->dac_nids;
5610 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5611 spec->adc_nids = stac9872_adc_nids;
5612 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5613 spec->mux_nids = stac9872_mux_nids;
5614 spec->mixer = stac9872_mixer;
5615 spec->init = stac9872_core_init;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005616
Takashi Iwai1e137f92009-01-21 07:41:22 +01005617 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5618 if (err < 0) {
5619 stac92xx_free(codec);
5620 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005621 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01005622 spec->input_mux = &spec->private_imux;
5623 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005624 return 0;
5625}
5626
5627
5628/*
Matt2f2f4252005-04-13 14:45:30 +02005629 * patch entries
5630 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005631static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02005632 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5633 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5634 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5635 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5636 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5637 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5638 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005639 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5640 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5641 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5642 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5643 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5644 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005645 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5646 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5647 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5648 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5649 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5650 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5651 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5652 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5653 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5654 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005655 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5656 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5657 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5658 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5659 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5660 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005661 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5662 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005663 /* The following does not take into account .id=0x83847661 when subsys =
5664 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5665 * currently not fully supported.
5666 */
5667 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5668 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5669 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02005670 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5671 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5672 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5673 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5674 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5675 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5676 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5677 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005678 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005679 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5680 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005681 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005682 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5683 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005684 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005685 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5686 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5687 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5688 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5689 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5690 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5691 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5692 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005693 {} /* terminator */
5694};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005695
5696MODULE_ALIAS("snd-hda-codec-id:8384*");
5697MODULE_ALIAS("snd-hda-codec-id:111d*");
5698
5699MODULE_LICENSE("GPL");
5700MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5701
5702static struct hda_codec_preset_list sigmatel_list = {
5703 .preset = snd_hda_preset_sigmatel,
5704 .owner = THIS_MODULE,
5705};
5706
5707static int __init patch_sigmatel_init(void)
5708{
5709 return snd_hda_add_codec_preset(&sigmatel_list);
5710}
5711
5712static void __exit patch_sigmatel_exit(void)
5713{
5714 snd_hda_delete_codec_preset(&sigmatel_list);
5715}
5716
5717module_init(patch_sigmatel_init)
5718module_exit(patch_sigmatel_exit)