blob: 75736827425d86fee59617912c3f992316b919dd [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,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020043 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020044 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010045};
Matt4e550962005-07-04 17:51:39 +020046
Takashi Iwaif5fcc132006-11-24 17:07:44 +010047enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010048 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010049 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010050 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020051 STAC_9200_DELL_D21,
52 STAC_9200_DELL_D22,
53 STAC_9200_DELL_D23,
54 STAC_9200_DELL_M21,
55 STAC_9200_DELL_M22,
56 STAC_9200_DELL_M23,
57 STAC_9200_DELL_M24,
58 STAC_9200_DELL_M25,
59 STAC_9200_DELL_M26,
60 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020061 STAC_9200_M4,
62 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010063 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010064 STAC_9200_MODELS
65};
66
67enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010068 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010069 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020070 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020071 STAC_9205_DELL_M43,
72 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010073 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010074 STAC_9205_MODELS
75};
76
77enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010078 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010079 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010080 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080081 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010082 STAC_DELL_M6_AMIC,
83 STAC_DELL_M6_DMIC,
84 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050085 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020086 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010087 STAC_92HD73XX_MODELS
88};
89
90enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010091 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020092 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050093 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050094 STAC_DELL_S14,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020095 STAC_92HD83XXX_MODELS
96};
97
98enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010099 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100100 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100101 STAC_DELL_M4_1,
102 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500103 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400104 STAC_HP_M4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100105 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100106 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400107 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100108 STAC_92HD71BXX_MODELS
109};
110
111enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100112 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100113 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200114 STAC_M1,
115 STAC_M1_2,
116 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100117 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200118 STAC_M3,
119 STAC_M5,
120 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100121 STAC_925x_MODELS
122};
123
124enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100125 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100126 STAC_D945_REF,
127 STAC_D945GTP3,
128 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200129 STAC_INTEL_MAC_V1,
130 STAC_INTEL_MAC_V2,
131 STAC_INTEL_MAC_V3,
132 STAC_INTEL_MAC_V4,
133 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800134 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
135 * is given, one of the above models will be
136 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200137 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100138 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100139 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100140 STAC_MACBOOK_PRO_V1,
141 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200142 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200143 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300144 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200145 STAC_922X_DELL_D81,
146 STAC_922X_DELL_D82,
147 STAC_922X_DELL_M81,
148 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100149 STAC_922X_MODELS
150};
151
152enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100153 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100154 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100155 STAC_D965_REF,
156 STAC_D965_3ST,
157 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200158 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200159 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100160 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200161 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100162 STAC_927X_MODELS
163};
Matt Porter403d1942005-11-29 15:00:51 +0100164
Takashi Iwai307282c2009-03-12 18:17:58 +0100165enum {
166 STAC_9872_AUTO,
167 STAC_9872_VAIO,
168 STAC_9872_MODELS
169};
170
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400171struct sigmatel_event {
172 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100173 unsigned char type;
174 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400175 int data;
176};
177
178struct sigmatel_jack {
179 hda_nid_t nid;
180 int type;
181 struct snd_jack *jack;
182};
183
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200184struct sigmatel_mic_route {
185 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200186 signed char mux_idx;
187 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200188};
189
Matt2f2f4252005-04-13 14:45:30 +0200190struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100191 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200192 unsigned int num_mixers;
193
Matt Porter403d1942005-11-29 15:00:51 +0100194 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500195 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200196 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100197 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100198 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400199 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100200 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200201 unsigned int auto_mic:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200202
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100203 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200204 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100205 unsigned int gpio_mask;
206 unsigned int gpio_dir;
207 unsigned int gpio_data;
208 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200209 unsigned int gpio_led;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100210
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200211 /* stream */
212 unsigned int stream_delay;
213
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100214 /* analog loopback */
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100215 struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100216 unsigned char aloopback_mask;
217 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200218
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100219 /* power management */
220 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200221 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100222 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100223 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100224
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400225 /* jack detection */
226 struct snd_array jacks;
227
228 /* events */
229 struct snd_array events;
230
Matt2f2f4252005-04-13 14:45:30 +0200231 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100232 struct hda_input_mux *mono_mux;
233 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200234 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100235 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100236 hda_nid_t hp_dacs[5];
237 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200238
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100239 int volume_offset;
240
Matt2f2f4252005-04-13 14:45:30 +0200241 /* capture */
242 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200243 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200244 hda_nid_t *mux_nids;
245 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200246 hda_nid_t *dmic_nids;
247 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100248 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100249 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200250 hda_nid_t *smux_nids;
251 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200252 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200253
254 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
255 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
256 unsigned int num_caps; /* number of capture volume/switch elements */
257
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200258 struct sigmatel_mic_route ext_mic;
259 struct sigmatel_mic_route int_mic;
260
Matthew Ranostay65973632008-09-16 10:39:37 -0400261 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200262
Mattdabbed62005-06-14 10:19:34 +0200263 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100264 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200265 hda_nid_t anabeep_nid;
266 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200267
Matt2f2f4252005-04-13 14:45:30 +0200268 /* pin widgets */
269 hda_nid_t *pin_nids;
270 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200271
272 /* codec specific stuff */
273 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100274 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200275
276 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200277 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100278 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200279 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100280 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200281 struct hda_input_mux *sinput_mux;
282 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400283 unsigned int cur_amux;
284 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200285 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200286
Matt Porter403d1942005-11-29 15:00:51 +0100287 /* i/o switches */
288 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200289 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100290 hda_nid_t line_switch; /* shared line-in for input and output */
291 hda_nid_t mic_switch; /* shared mic-in for input and output */
292 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200293 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200294
Mattc7d4b2f2005-06-27 14:59:41 +0200295 struct hda_pcm pcm_rec[2]; /* PCM information */
296
297 /* dynamic controls and input_mux */
298 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200299 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200300 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200301 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200302 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100303 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200304};
305
306static hda_nid_t stac9200_adc_nids[1] = {
307 0x03,
308};
309
310static hda_nid_t stac9200_mux_nids[1] = {
311 0x0c,
312};
313
314static hda_nid_t stac9200_dac_nids[1] = {
315 0x02,
316};
317
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100318static hda_nid_t stac92hd73xx_pwr_nids[8] = {
319 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
320 0x0f, 0x10, 0x11
321};
322
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400323static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
324 0x26, 0,
325};
326
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100327static hda_nid_t stac92hd73xx_adc_nids[2] = {
328 0x1a, 0x1b
329};
330
331#define STAC92HD73XX_NUM_DMICS 2
332static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
333 0x13, 0x14, 0
334};
335
336#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100337
Takashi Iwaie2aec172009-09-02 01:00:05 +0200338static hda_nid_t stac92hd73xx_mux_nids[2] = {
339 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100340};
341
342static hda_nid_t stac92hd73xx_dmux_nids[2] = {
343 0x20, 0x21,
344};
345
Matthew Ranostayd9737752008-09-07 12:03:41 +0200346static hda_nid_t stac92hd73xx_smux_nids[2] = {
347 0x22, 0x23,
348};
349
Takashi Iwai6479c632009-07-28 18:20:25 +0200350#define STAC92HD73XX_NUM_CAPS 2
351static unsigned long stac92hd73xx_capvols[] = {
352 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
353 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
354};
355#define stac92hd73xx_capsws stac92hd73xx_capvols
356
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200357#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200358
Takashi Iwai667067d2009-08-13 18:14:42 +0200359static hda_nid_t stac92hd83xxx_mux_nids[2] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200360 0x17, 0x18,
361};
362
363static hda_nid_t stac92hd83xxx_adc_nids[2] = {
364 0x15, 0x16,
365};
366
367static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
368 0xa, 0xb, 0xd, 0xe,
369};
370
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400371static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
372 0x1e, 0,
373};
374
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200375static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500376 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200377};
378
Takashi Iwai6479c632009-07-28 18:20:25 +0200379#define STAC92HD83XXX_NUM_CAPS 2
380static unsigned long stac92hd83xxx_capvols[] = {
381 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
382 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
383};
384#define stac92hd83xxx_capsws stac92hd83xxx_capvols
385
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100386static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
387 0x0a, 0x0d, 0x0f
388};
389
Matthew Ranostaye035b842007-11-06 11:53:55 +0100390static hda_nid_t stac92hd71bxx_adc_nids[2] = {
391 0x12, 0x13,
392};
393
394static hda_nid_t stac92hd71bxx_mux_nids[2] = {
395 0x1a, 0x1b
396};
397
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400398static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
399 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100400};
401
Matthew Ranostayd9737752008-09-07 12:03:41 +0200402static hda_nid_t stac92hd71bxx_smux_nids[2] = {
403 0x24, 0x25,
404};
405
Matthew Ranostaye035b842007-11-06 11:53:55 +0100406#define STAC92HD71BXX_NUM_DMICS 2
407static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
408 0x18, 0x19, 0
409};
410
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400411static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
412 0x22, 0
413};
414
Takashi Iwai6479c632009-07-28 18:20:25 +0200415#define STAC92HD71BXX_NUM_CAPS 2
416static unsigned long stac92hd71bxx_capvols[] = {
417 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
418 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
419};
420#define stac92hd71bxx_capsws stac92hd71bxx_capvols
421
Tobin Davis8e21c342007-01-08 11:04:17 +0100422static hda_nid_t stac925x_adc_nids[1] = {
423 0x03,
424};
425
426static hda_nid_t stac925x_mux_nids[1] = {
427 0x0f,
428};
429
430static hda_nid_t stac925x_dac_nids[1] = {
431 0x02,
432};
433
Takashi Iwaif6e98522007-10-16 14:27:04 +0200434#define STAC925X_NUM_DMICS 1
435static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
436 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200437};
438
Takashi Iwai1697055e2007-12-18 18:05:52 +0100439static hda_nid_t stac925x_dmux_nids[1] = {
440 0x14,
441};
442
Takashi Iwai6479c632009-07-28 18:20:25 +0200443static unsigned long stac925x_capvols[] = {
444 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
445};
446static unsigned long stac925x_capsws[] = {
447 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
448};
449
Matt2f2f4252005-04-13 14:45:30 +0200450static hda_nid_t stac922x_adc_nids[2] = {
451 0x06, 0x07,
452};
453
454static hda_nid_t stac922x_mux_nids[2] = {
455 0x12, 0x13,
456};
457
Takashi Iwai6479c632009-07-28 18:20:25 +0200458#define STAC922X_NUM_CAPS 2
459static unsigned long stac922x_capvols[] = {
460 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
461 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
462};
463#define stac922x_capsws stac922x_capvols
464
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500465static hda_nid_t stac927x_slave_dig_outs[2] = {
466 0x1f, 0,
467};
468
Matt Porter3cc08dc2006-01-23 15:27:49 +0100469static hda_nid_t stac927x_adc_nids[3] = {
470 0x07, 0x08, 0x09
471};
472
473static hda_nid_t stac927x_mux_nids[3] = {
474 0x15, 0x16, 0x17
475};
476
Matthew Ranostayd9737752008-09-07 12:03:41 +0200477static hda_nid_t stac927x_smux_nids[1] = {
478 0x21,
479};
480
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100481static hda_nid_t stac927x_dac_nids[6] = {
482 0x02, 0x03, 0x04, 0x05, 0x06, 0
483};
484
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100485static hda_nid_t stac927x_dmux_nids[1] = {
486 0x1b,
487};
488
Matthew Ranostay7f168592007-10-18 17:38:17 +0200489#define STAC927X_NUM_DMICS 2
490static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
491 0x13, 0x14, 0
492};
493
Takashi Iwai6479c632009-07-28 18:20:25 +0200494#define STAC927X_NUM_CAPS 3
495static unsigned long stac927x_capvols[] = {
496 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
497 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
498 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
499};
500static unsigned long stac927x_capsws[] = {
501 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
502 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
503 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
504};
505
Matthew Ranostay65973632008-09-16 10:39:37 -0400506static const char *stac927x_spdif_labels[5] = {
507 "Digital Playback", "ADAT", "Analog Mux 1",
508 "Analog Mux 2", "Analog Mux 3"
509};
510
Matt Porterf3302a52006-07-31 12:49:34 +0200511static hda_nid_t stac9205_adc_nids[2] = {
512 0x12, 0x13
513};
514
515static hda_nid_t stac9205_mux_nids[2] = {
516 0x19, 0x1a
517};
518
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100519static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100520 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100521};
522
Matthew Ranostayd9737752008-09-07 12:03:41 +0200523static hda_nid_t stac9205_smux_nids[1] = {
524 0x21,
525};
526
Takashi Iwaif6e98522007-10-16 14:27:04 +0200527#define STAC9205_NUM_DMICS 2
528static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
529 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200530};
531
Takashi Iwai6479c632009-07-28 18:20:25 +0200532#define STAC9205_NUM_CAPS 2
533static unsigned long stac9205_capvols[] = {
534 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
535 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
536};
537static unsigned long stac9205_capsws[] = {
538 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
539 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
540};
541
Mattc7d4b2f2005-06-27 14:59:41 +0200542static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200543 0x08, 0x09, 0x0d, 0x0e,
544 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200545};
546
Tobin Davis8e21c342007-01-08 11:04:17 +0100547static hda_nid_t stac925x_pin_nids[8] = {
548 0x07, 0x08, 0x0a, 0x0b,
549 0x0c, 0x0d, 0x10, 0x11,
550};
551
Matt2f2f4252005-04-13 14:45:30 +0200552static hda_nid_t stac922x_pin_nids[10] = {
553 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
554 0x0f, 0x10, 0x11, 0x15, 0x1b,
555};
556
Matthew Ranostaya7662642008-02-21 07:51:14 +0100557static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100558 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
559 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200560 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100561};
562
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500563static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200564 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500565 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200566};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500567
568#define STAC92HD71BXX_NUM_PINS 13
569static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
570 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
571 0x00, 0x14, 0x18, 0x19, 0x1e,
572 0x1f, 0x20, 0x27
573};
574static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100575 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
576 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500577 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100578};
579
Matt Porter3cc08dc2006-01-23 15:27:49 +0100580static hda_nid_t stac927x_pin_nids[14] = {
581 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
582 0x0f, 0x10, 0x11, 0x12, 0x13,
583 0x14, 0x21, 0x22, 0x23,
584};
585
Matt Porterf3302a52006-07-31 12:49:34 +0200586static hda_nid_t stac9205_pin_nids[12] = {
587 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
588 0x0f, 0x14, 0x16, 0x17, 0x18,
589 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200590};
591
Matt Porter8b657272006-10-26 17:12:59 +0200592static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
593 struct snd_ctl_elem_info *uinfo)
594{
595 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
596 struct sigmatel_spec *spec = codec->spec;
597 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
598}
599
600static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
601 struct snd_ctl_elem_value *ucontrol)
602{
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100605 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200606
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100607 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200608 return 0;
609}
610
611static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
612 struct snd_ctl_elem_value *ucontrol)
613{
614 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
615 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100616 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200617
618 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100619 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200620}
621
Matthew Ranostayd9737752008-09-07 12:03:41 +0200622static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
623 struct snd_ctl_elem_info *uinfo)
624{
625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
626 struct sigmatel_spec *spec = codec->spec;
627 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
628}
629
630static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
631 struct snd_ctl_elem_value *ucontrol)
632{
633 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
634 struct sigmatel_spec *spec = codec->spec;
635 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
636
637 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
638 return 0;
639}
640
641static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
642 struct snd_ctl_elem_value *ucontrol)
643{
644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
645 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400646 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200647 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400648 int err, val;
649 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200650
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400651 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200652 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400653 if (err < 0)
654 return err;
655
656 if (spec->spdif_mute) {
657 if (smux_idx == 0)
658 nid = spec->multiout.dig_out_nid;
659 else
660 nid = codec->slave_dig_outs[smux_idx - 1];
661 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100662 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400663 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100664 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400665 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100666 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
667 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400668 }
669 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200670}
671
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200672static unsigned int stac92xx_vref_set(struct hda_codec *codec,
673 hda_nid_t nid, unsigned int new_vref)
674{
Takashi Iwaib8621512009-06-22 08:00:10 +0200675 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200676 unsigned int pincfg;
677 pincfg = snd_hda_codec_read(codec, nid, 0,
678 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
679
680 pincfg &= 0xff;
681 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
682 pincfg |= new_vref;
683
684 if (new_vref == AC_PINCTL_VREF_HIZ)
685 pincfg |= AC_PINCTL_OUT_EN;
686 else
687 pincfg |= AC_PINCTL_IN_EN;
688
689 error = snd_hda_codec_write_cache(codec, nid, 0,
690 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
691 if (error < 0)
692 return error;
693 else
694 return 1;
695}
696
697static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
698{
699 unsigned int vref;
700 vref = snd_hda_codec_read(codec, nid, 0,
701 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
702 vref &= AC_PINCTL_VREFEN;
703 return vref;
704}
705
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100706static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200707{
708 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
709 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200710 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200711}
712
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100713static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200714{
715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
716 struct sigmatel_spec *spec = codec->spec;
717 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
718
719 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
720 return 0;
721}
722
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100723static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200724{
725 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
726 struct sigmatel_spec *spec = codec->spec;
727 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200728 const struct hda_input_mux *imux = spec->input_mux;
729 unsigned int idx, prev_idx;
Matt2f2f4252005-04-13 14:45:30 +0200730
Takashi Iwai5207e102009-07-30 13:09:08 +0200731 idx = ucontrol->value.enumerated.item[0];
732 if (idx >= imux->num_items)
733 idx = imux->num_items - 1;
734 prev_idx = spec->cur_mux[adc_idx];
735 if (prev_idx == idx)
736 return 0;
737 if (idx < spec->num_analog_muxes) {
738 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
739 AC_VERB_SET_CONNECT_SEL,
740 imux->items[idx].index);
741 if (prev_idx >= spec->num_analog_muxes) {
742 imux = spec->dinput_mux;
743 /* 0 = analog */
744 snd_hda_codec_write_cache(codec,
745 spec->dmux_nids[adc_idx], 0,
746 AC_VERB_SET_CONNECT_SEL,
747 imux->items[0].index);
748 }
749 } else {
750 imux = spec->dinput_mux;
751 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
752 AC_VERB_SET_CONNECT_SEL,
753 imux->items[idx - 1].index);
754 }
755 spec->cur_mux[adc_idx] = idx;
756 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200757}
758
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100759static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
760 struct snd_ctl_elem_info *uinfo)
761{
762 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
763 struct sigmatel_spec *spec = codec->spec;
764 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
765}
766
767static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
768 struct snd_ctl_elem_value *ucontrol)
769{
770 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
771 struct sigmatel_spec *spec = codec->spec;
772
773 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
774 return 0;
775}
776
777static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
778 struct snd_ctl_elem_value *ucontrol)
779{
780 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
781 struct sigmatel_spec *spec = codec->spec;
782
783 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
784 spec->mono_nid, &spec->cur_mmux);
785}
786
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200787#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
788
789static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
790 struct snd_ctl_elem_value *ucontrol)
791{
792 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100793 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200794 struct sigmatel_spec *spec = codec->spec;
795
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100796 ucontrol->value.integer.value[0] = !!(spec->aloopback &
797 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200798 return 0;
799}
800
801static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
802 struct snd_ctl_elem_value *ucontrol)
803{
804 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
805 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100806 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200807 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100808 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200809
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100810 idx_val = spec->aloopback_mask << idx;
811 if (ucontrol->value.integer.value[0])
812 val = spec->aloopback | idx_val;
813 else
814 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100815 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200816 return 0;
817
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100818 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200819
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100820 /* Only return the bits defined by the shift value of the
821 * first two bytes of the mask
822 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200823 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100824 kcontrol->private_value & 0xFFFF, 0x0);
825 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200826
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100827 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200828 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100829 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200830 } else {
831 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100832 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200833 }
834
835 snd_hda_codec_write_cache(codec, codec->afg, 0,
836 kcontrol->private_value >> 16, dac_mode);
837
838 return 1;
839}
840
Mattc7d4b2f2005-06-27 14:59:41 +0200841static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200842 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200843 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200844 {}
845};
846
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200847static struct hda_verb stac9200_eapd_init[] = {
848 /* set dac0mux for dac converter */
849 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
850 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
851 {}
852};
853
Matthew Ranostayd654a662008-03-14 08:46:51 +0100854static struct hda_verb dell_eq_core_init[] = {
855 /* set master volume to max value without distortion
856 * and direct control */
857 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100858 {}
859};
860
Takashi Iwaie2aec172009-09-02 01:00:05 +0200861static struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100862 /* set master volume and direct control */
863 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100864 {}
865};
866
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200867static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200868 /* power state controls amps */
869 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200870 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200871};
872
Matthew Ranostaye035b842007-11-06 11:53:55 +0100873static struct hda_verb stac92hd71bxx_core_init[] = {
874 /* set master volume and direct control */
875 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200876 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100877};
878
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500879static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
880 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
881 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100882 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
883 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100884 {}
885};
886
Tobin Davis8e21c342007-01-08 11:04:17 +0100887static struct hda_verb stac925x_core_init[] = {
888 /* set dac0mux for dac converter */
889 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100890 /* mute the master volume */
891 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100892 {}
893};
894
Mattc7d4b2f2005-06-27 14:59:41 +0200895static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200896 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200897 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200898 {}
899};
900
Tobin Davis93ed1502006-09-01 21:03:12 +0200901static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200902 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200903 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200904 /* unmute node 0x1b */
905 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
906 /* select node 0x03 as DAC */
907 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
908 {}
909};
910
Matt Porter3cc08dc2006-01-23 15:27:49 +0100911static struct hda_verb stac927x_core_init[] = {
912 /* set master volume and direct control */
913 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200914 /* enable analog pc beep path */
915 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100916 {}
917};
918
Takashi Iwai54930532009-10-11 17:38:29 +0200919static struct hda_verb stac927x_volknob_core_init[] = {
920 /* don't set delta bit */
921 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
922 /* enable analog pc beep path */
923 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
924 {}
925};
926
Matt Porterf3302a52006-07-31 12:49:34 +0200927static struct hda_verb stac9205_core_init[] = {
928 /* set master volume and direct control */
929 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200930 /* enable analog pc beep path */
931 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200932 {}
933};
934
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100935#define STAC_MONO_MUX \
936 { \
937 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
938 .name = "Mono Mux", \
939 .count = 1, \
940 .info = stac92xx_mono_mux_enum_info, \
941 .get = stac92xx_mono_mux_enum_get, \
942 .put = stac92xx_mono_mux_enum_put, \
943 }
944
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100945#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200946 { \
947 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
948 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100949 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200950 .info = stac92xx_aloopback_info, \
951 .get = stac92xx_aloopback_get, \
952 .put = stac92xx_aloopback_put, \
953 .private_value = verb_read | (verb_write << 16), \
954 }
955
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200956#define DC_BIAS(xname, idx, nid) \
957 { \
958 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
959 .name = xname, \
960 .index = idx, \
961 .info = stac92xx_dc_bias_info, \
962 .get = stac92xx_dc_bias_get, \
963 .put = stac92xx_dc_bias_put, \
964 .private_value = nid, \
965 }
966
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100967static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200968 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
969 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200970 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
971 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200972 { } /* end */
973};
974
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100975static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
976 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
977 {}
978};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100979
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100980static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
981 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
982 {}
983};
984
985static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
986 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
987 {}
988};
989
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200990
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100991static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
992 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
993};
Matthew Ranostay541eee82007-12-14 12:08:04 +0100994
Tobin Davis8e21c342007-01-08 11:04:17 +0100995static struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwaic9280d62009-01-15 17:31:00 +0100996 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
997 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200998 { } /* end */
999};
1000
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001001static struct snd_kcontrol_new stac9205_loopback[] = {
1002 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1003 {}
1004};
1005
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001006static struct snd_kcontrol_new stac927x_loopback[] = {
1007 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1008 {}
1009};
1010
Takashi Iwai1697055e2007-12-18 18:05:52 +01001011static struct snd_kcontrol_new stac_dmux_mixer = {
1012 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1013 .name = "Digital Input Source",
1014 /* count set later */
1015 .info = stac92xx_dmux_enum_info,
1016 .get = stac92xx_dmux_enum_get,
1017 .put = stac92xx_dmux_enum_put,
1018};
1019
Matthew Ranostayd9737752008-09-07 12:03:41 +02001020static struct snd_kcontrol_new stac_smux_mixer = {
1021 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001022 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001023 /* count set later */
1024 .info = stac92xx_smux_enum_info,
1025 .get = stac92xx_smux_enum_get,
1026 .put = stac92xx_smux_enum_put,
1027};
1028
Takashi Iwai2134ea42008-01-10 16:53:55 +01001029static const char *slave_vols[] = {
1030 "Front Playback Volume",
1031 "Surround Playback Volume",
1032 "Center Playback Volume",
1033 "LFE Playback Volume",
1034 "Side Playback Volume",
1035 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001036 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001037 NULL
1038};
1039
1040static const char *slave_sws[] = {
1041 "Front Playback Switch",
1042 "Surround Playback Switch",
1043 "Center Playback Switch",
1044 "LFE Playback Switch",
1045 "Side Playback Switch",
1046 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001047 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001048 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001049 NULL
1050};
1051
Takashi Iwai603c4012008-07-30 15:01:44 +02001052static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001053static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001054
Matt2f2f4252005-04-13 14:45:30 +02001055static int stac92xx_build_controls(struct hda_codec *codec)
1056{
1057 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001058 struct auto_pin_cfg *cfg = &spec->autocfg;
1059 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001060 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001061 int i;
Matt2f2f4252005-04-13 14:45:30 +02001062
Takashi Iwai6479c632009-07-28 18:20:25 +02001063 if (spec->mixer) {
1064 err = snd_hda_add_new_ctls(codec, spec->mixer);
1065 if (err < 0)
1066 return err;
1067 }
Mattc7d4b2f2005-06-27 14:59:41 +02001068
1069 for (i = 0; i < spec->num_mixers; i++) {
1070 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1071 if (err < 0)
1072 return err;
1073 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001074 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1075 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001076 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001077 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001078 snd_ctl_new1(&stac_dmux_mixer, codec));
1079 if (err < 0)
1080 return err;
1081 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001082 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001083 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1084 struct hda_input_mux *smux = &spec->private_smux;
1085 /* check for mute support on SPDIF out */
1086 if (wcaps & AC_WCAP_OUT_AMP) {
1087 smux->items[smux->num_items].label = "Off";
1088 smux->items[smux->num_items].index = 0;
1089 smux->num_items++;
1090 spec->spdif_mute = 1;
1091 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001092 stac_smux_mixer.count = spec->num_smuxes;
Takashi Iwai4f2d23e2008-12-19 10:14:13 +01001093 err = snd_hda_ctl_add(codec,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001094 snd_ctl_new1(&stac_smux_mixer, codec));
1095 if (err < 0)
1096 return err;
1097 }
Mattc7d4b2f2005-06-27 14:59:41 +02001098
Mattdabbed62005-06-14 10:19:34 +02001099 if (spec->multiout.dig_out_nid) {
1100 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1101 if (err < 0)
1102 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001103 err = snd_hda_create_spdif_share_sw(codec,
1104 &spec->multiout);
1105 if (err < 0)
1106 return err;
1107 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001108 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001109 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001110 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1111 if (err < 0)
1112 return err;
1113 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001114
1115 /* if we have no master control, let's create it */
1116 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001117 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001118 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001119 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001120 /* correct volume offset */
1121 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001122 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001123 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001124 if (err < 0)
1125 return err;
1126 }
1127 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1128 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1129 NULL, slave_sws);
1130 if (err < 0)
1131 return err;
1132 }
1133
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001134 if (spec->aloopback_ctl &&
1135 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1136 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1137 if (err < 0)
1138 return err;
1139 }
1140
Takashi Iwai603c4012008-07-30 15:01:44 +02001141 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001142
1143 /* create jack input elements */
1144 if (spec->hp_detect) {
1145 for (i = 0; i < cfg->hp_outs; i++) {
1146 int type = SND_JACK_HEADPHONE;
1147 nid = cfg->hp_pins[i];
1148 /* jack detection */
1149 if (cfg->hp_outs == i)
1150 type |= SND_JACK_LINEOUT;
1151 err = stac92xx_add_jack(codec, nid, type);
1152 if (err < 0)
1153 return err;
1154 }
1155 }
1156 for (i = 0; i < cfg->line_outs; i++) {
1157 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1158 SND_JACK_LINEOUT);
1159 if (err < 0)
1160 return err;
1161 }
1162 for (i = 0; i < AUTO_PIN_LAST; i++) {
1163 nid = cfg->input_pins[i];
1164 if (nid) {
1165 err = stac92xx_add_jack(codec, nid,
1166 SND_JACK_MICROPHONE);
1167 if (err < 0)
1168 return err;
1169 }
1170 }
1171
Mattdabbed62005-06-14 10:19:34 +02001172 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001173}
1174
Matt Porter403d1942005-11-29 15:00:51 +01001175static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001176 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001177 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1178};
1179
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001180static unsigned int gateway9200_m4_pin_configs[8] = {
1181 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1182 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1183};
1184static unsigned int gateway9200_m4_2_pin_configs[8] = {
1185 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1186 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1187};
1188
1189/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001190 STAC 9200 pin configs for
1191 102801A8
1192 102801DE
1193 102801E8
1194*/
1195static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001196 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1197 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001198};
1199
1200/*
1201 STAC 9200 pin configs for
1202 102801C0
1203 102801C1
1204*/
1205static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001206 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1207 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001208};
1209
1210/*
1211 STAC 9200 pin configs for
1212 102801C4 (Dell Dimension E310)
1213 102801C5
1214 102801C7
1215 102801D9
1216 102801DA
1217 102801E3
1218*/
1219static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001220 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1221 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001222};
1223
1224
1225/*
1226 STAC 9200-32 pin configs for
1227 102801B5 (Dell Inspiron 630m)
1228 102801D8 (Dell Inspiron 640m)
1229*/
1230static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001231 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1232 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001233};
1234
1235/*
1236 STAC 9200-32 pin configs for
1237 102801C2 (Dell Latitude D620)
1238 102801C8
1239 102801CC (Dell Latitude D820)
1240 102801D4
1241 102801D6
1242*/
1243static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001244 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1245 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001246};
1247
1248/*
1249 STAC 9200-32 pin configs for
1250 102801CE (Dell XPS M1710)
1251 102801CF (Dell Precision M90)
1252*/
1253static unsigned int dell9200_m23_pin_configs[8] = {
1254 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1255 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1256};
1257
1258/*
1259 STAC 9200-32 pin configs for
1260 102801C9
1261 102801CA
1262 102801CB (Dell Latitude 120L)
1263 102801D3
1264*/
1265static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001266 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1267 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001268};
1269
1270/*
1271 STAC 9200-32 pin configs for
1272 102801BD (Dell Inspiron E1505n)
1273 102801EE
1274 102801EF
1275*/
1276static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001277 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1278 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001279};
1280
1281/*
1282 STAC 9200-32 pin configs for
1283 102801F5 (Dell Inspiron 1501)
1284 102801F6
1285*/
1286static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001287 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1288 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001289};
1290
1291/*
1292 STAC 9200-32
1293 102801CD (Dell Inspiron E1705/9400)
1294*/
1295static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001296 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1297 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001298};
1299
Tobin Davisbf277782008-02-03 20:31:47 +01001300static unsigned int oqo9200_pin_configs[8] = {
1301 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1302 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1303};
1304
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001305
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001306static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1307 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001308 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001309 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1310 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1311 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1312 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1313 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1314 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1315 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1316 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1317 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1318 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001319 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1320 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001321 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001322};
1323
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001324static const char *stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001325 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001326 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001327 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001328 [STAC_9200_DELL_D21] = "dell-d21",
1329 [STAC_9200_DELL_D22] = "dell-d22",
1330 [STAC_9200_DELL_D23] = "dell-d23",
1331 [STAC_9200_DELL_M21] = "dell-m21",
1332 [STAC_9200_DELL_M22] = "dell-m22",
1333 [STAC_9200_DELL_M23] = "dell-m23",
1334 [STAC_9200_DELL_M24] = "dell-m24",
1335 [STAC_9200_DELL_M25] = "dell-m25",
1336 [STAC_9200_DELL_M26] = "dell-m26",
1337 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001338 [STAC_9200_M4] = "gateway-m4",
1339 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001340 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001341};
1342
1343static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1344 /* SigmaTel reference board */
1345 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1346 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001347 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1348 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001349 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001350 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1351 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001352 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001353 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1354 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1355 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1356 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1357 "unknown Dell", STAC_9200_DELL_D22),
1358 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1359 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001360 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001361 "Dell Latitude D620", STAC_9200_DELL_M22),
1362 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1363 "unknown Dell", STAC_9200_DELL_D23),
1364 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1365 "unknown Dell", STAC_9200_DELL_D23),
1366 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1367 "unknown Dell", STAC_9200_DELL_M22),
1368 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1369 "unknown Dell", STAC_9200_DELL_M24),
1370 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1371 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001372 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001373 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001374 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001375 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001376 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001377 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001378 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001379 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001380 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001381 "Dell Precision M90", STAC_9200_DELL_M23),
1382 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1383 "unknown Dell", STAC_9200_DELL_M22),
1384 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1385 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001386 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001387 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001388 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001389 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1390 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1391 "unknown Dell", STAC_9200_DELL_D23),
1392 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1393 "unknown Dell", STAC_9200_DELL_D23),
1394 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1395 "unknown Dell", STAC_9200_DELL_D21),
1396 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1397 "unknown Dell", STAC_9200_DELL_D23),
1398 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1399 "unknown Dell", STAC_9200_DELL_D21),
1400 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1401 "unknown Dell", STAC_9200_DELL_M25),
1402 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1403 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001404 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001405 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1406 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1407 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001408 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001409 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001410 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001411 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1412 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1413 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001414 /* OQO Mobile */
1415 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001416 {} /* terminator */
1417};
1418
Tobin Davis8e21c342007-01-08 11:04:17 +01001419static unsigned int ref925x_pin_configs[8] = {
1420 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001421 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001422};
1423
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001424static unsigned int stac925xM1_pin_configs[8] = {
1425 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1426 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001427};
1428
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001429static unsigned int stac925xM1_2_pin_configs[8] = {
1430 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1431 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1432};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001433
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001434static unsigned int stac925xM2_pin_configs[8] = {
1435 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1436 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001437};
1438
Tobin Davis8e21c342007-01-08 11:04:17 +01001439static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001440 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1441 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1442};
1443
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001444static unsigned int stac925xM3_pin_configs[8] = {
1445 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1446 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1447};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001448
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001449static unsigned int stac925xM5_pin_configs[8] = {
1450 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1451 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1452};
1453
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001454static unsigned int stac925xM6_pin_configs[8] = {
1455 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1456 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001457};
1458
1459static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1460 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001461 [STAC_M1] = stac925xM1_pin_configs,
1462 [STAC_M1_2] = stac925xM1_2_pin_configs,
1463 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001464 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001465 [STAC_M3] = stac925xM3_pin_configs,
1466 [STAC_M5] = stac925xM5_pin_configs,
1467 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001468};
1469
1470static const char *stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001471 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001472 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001473 [STAC_M1] = "m1",
1474 [STAC_M1_2] = "m1-2",
1475 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001476 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001477 [STAC_M3] = "m3",
1478 [STAC_M5] = "m5",
1479 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001480};
1481
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001482static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001483 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1484 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1485 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1486 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001487 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001488 /* Not sure about the brand name for those */
1489 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1490 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1491 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1492 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001493 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001494};
1495
1496static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1497 /* SigmaTel reference board */
1498 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001499 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001500 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001501
1502 /* Default table for unknown ID */
1503 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1504
Tobin Davis8e21c342007-01-08 11:04:17 +01001505 {} /* terminator */
1506};
1507
Matthew Ranostaya7662642008-02-21 07:51:14 +01001508static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001509 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1510 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1511 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001512 0x01452050,
1513};
1514
1515static unsigned int dell_m6_pin_configs[13] = {
1516 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001517 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001518 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1519 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001520};
1521
Takashi Iwai842ae632009-09-02 07:43:08 +02001522static unsigned int alienware_m17x_pin_configs[13] = {
1523 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1524 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1525 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1526 0x904601b0,
1527};
1528
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001529static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001530 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001531 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1532 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1533 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001534 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001535 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001536};
1537
1538static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001539 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001540 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001541 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001542 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001543 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1544 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1545 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001546 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001547 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001548};
1549
1550static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1551 /* SigmaTel reference board */
1552 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001553 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001554 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1555 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001556 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1557 "Intel DG45ID", STAC_92HD73XX_INTEL),
1558 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1559 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001560 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001561 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001563 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001565 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001567 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001569 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001571 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001573 "unknown Dell", STAC_DELL_M6_DMIC),
1574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1575 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001577 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001578 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1579 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1581 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001582 {} /* terminator */
1583};
1584
Takashi Iwai842ae632009-09-02 07:43:08 +02001585static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1586 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1587 "Alienware M17x", STAC_ALIENWARE_M17X),
1588 {} /* terminator */
1589};
1590
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001591static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001592 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1593 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001594 0x01451160, 0x98560170,
1595};
1596
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001597static unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001598 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1599 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001600 0x40f000f0, 0x40f000f0,
1601};
1602
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001603static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1604 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001605 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001606 [STAC_DELL_S14] = dell_s14_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001607};
1608
1609static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001610 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001611 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001612 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001613 [STAC_DELL_S14] = "dell-s14",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001614};
1615
1616static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1617 /* SigmaTel reference board */
1618 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001619 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001620 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1621 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001622 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1623 "unknown Dell", STAC_DELL_S14),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001624 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001625};
1626
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001627static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001628 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001629 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001630 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1631 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001632};
1633
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001634static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001635 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001636 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001637 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1638 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001639};
1640
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001641static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001642 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1643 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001644 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1645 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001646};
1647
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001648static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001649 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1650 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001651 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1652 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001653};
1654
Matthew Ranostaye035b842007-11-06 11:53:55 +01001655static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1656 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001657 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1658 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001659 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001660 [STAC_HP_M4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001661 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001662 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001663 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001664};
1665
1666static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001667 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001668 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001669 [STAC_DELL_M4_1] = "dell-m4-1",
1670 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001671 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001672 [STAC_HP_M4] = "hp-m4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001673 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001674 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001675 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001676};
1677
1678static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1679 /* SigmaTel reference board */
1680 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1681 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001682 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1683 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001684 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1685 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Takashi Iwai58d83952009-03-13 17:04:34 +01001686 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1687 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001688 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1689 "HP dv4-7", STAC_HP_DV5),
1690 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1691 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001692 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1693 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001694 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001695 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001696 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001697 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001698 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1699 "HP dv6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02001700 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1701 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001702 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1703 "unknown Dell", STAC_DELL_M4_1),
1704 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1705 "unknown Dell", STAC_DELL_M4_1),
1706 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1707 "unknown Dell", STAC_DELL_M4_1),
1708 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1709 "unknown Dell", STAC_DELL_M4_1),
1710 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1711 "unknown Dell", STAC_DELL_M4_1),
1712 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1713 "unknown Dell", STAC_DELL_M4_1),
1714 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1715 "unknown Dell", STAC_DELL_M4_1),
1716 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1717 "unknown Dell", STAC_DELL_M4_2),
1718 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1719 "unknown Dell", STAC_DELL_M4_2),
1720 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1721 "unknown Dell", STAC_DELL_M4_2),
1722 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1723 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001724 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1725 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001726 {} /* terminator */
1727};
1728
Matt Porter403d1942005-11-29 15:00:51 +01001729static unsigned int ref922x_pin_configs[10] = {
1730 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1731 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001732 0x40000100, 0x40000100,
1733};
1734
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001735/*
1736 STAC 922X pin configs for
1737 102801A7
1738 102801AB
1739 102801A9
1740 102801D1
1741 102801D2
1742*/
1743static unsigned int dell_922x_d81_pin_configs[10] = {
1744 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1745 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1746 0x01813122, 0x400001f2,
1747};
1748
1749/*
1750 STAC 922X pin configs for
1751 102801AC
1752 102801D0
1753*/
1754static unsigned int dell_922x_d82_pin_configs[10] = {
1755 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1756 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1757 0x01813122, 0x400001f1,
1758};
1759
1760/*
1761 STAC 922X pin configs for
1762 102801BF
1763*/
1764static unsigned int dell_922x_m81_pin_configs[10] = {
1765 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1766 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1767 0x40C003f1, 0x405003f0,
1768};
1769
1770/*
1771 STAC 9221 A1 pin configs for
1772 102801D7 (Dell XPS M1210)
1773*/
1774static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001775 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1776 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001777 0x508003f3, 0x405003f4,
1778};
1779
Matt Porter403d1942005-11-29 15:00:51 +01001780static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001781 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001782 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1783 0x02a19120, 0x40000100,
1784};
1785
1786static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001787 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1788 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001789 0x02a19320, 0x40000100,
1790};
1791
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001792static unsigned int intel_mac_v1_pin_configs[10] = {
1793 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1794 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001795 0x400000fc, 0x400000fb,
1796};
1797
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001798static unsigned int intel_mac_v2_pin_configs[10] = {
1799 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1800 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001801 0x400000fc, 0x400000fb,
1802};
1803
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001804static unsigned int intel_mac_v3_pin_configs[10] = {
1805 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1806 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1807 0x400000fc, 0x400000fb,
1808};
1809
1810static unsigned int intel_mac_v4_pin_configs[10] = {
1811 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1812 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1813 0x400000fc, 0x400000fb,
1814};
1815
1816static unsigned int intel_mac_v5_pin_configs[10] = {
1817 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1818 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1819 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001820};
1821
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001822static unsigned int ecs202_pin_configs[10] = {
1823 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1824 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1825 0x9037012e, 0x40e000f2,
1826};
Takashi Iwai76c08822007-06-19 12:17:42 +02001827
Takashi Iwai19039bd2006-06-28 15:52:16 +02001828static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001829 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001830 [STAC_D945GTP3] = d945gtp3_pin_configs,
1831 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001832 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1833 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1834 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1835 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1836 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001837 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001838 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001839 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1840 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1841 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1842 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1843 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1844 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001845 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001846 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1847 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1848 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1849 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001850};
1851
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001852static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001853 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001854 [STAC_D945_REF] = "ref",
1855 [STAC_D945GTP5] = "5stack",
1856 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001857 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1858 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1859 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1860 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1861 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001862 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001863 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001864 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001865 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001866 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1867 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001868 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001869 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001870 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001871 [STAC_922X_DELL_D81] = "dell-d81",
1872 [STAC_922X_DELL_D82] = "dell-d82",
1873 [STAC_922X_DELL_M81] = "dell-m81",
1874 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001875};
1876
1877static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1878 /* SigmaTel reference board */
1879 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1880 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001881 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1882 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001883 /* Intel 945G based systems */
1884 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1885 "Intel D945G", STAC_D945GTP3),
1886 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1887 "Intel D945G", STAC_D945GTP3),
1888 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1889 "Intel D945G", STAC_D945GTP3),
1890 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1891 "Intel D945G", STAC_D945GTP3),
1892 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1893 "Intel D945G", STAC_D945GTP3),
1894 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1895 "Intel D945G", STAC_D945GTP3),
1896 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1897 "Intel D945G", STAC_D945GTP3),
1898 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1899 "Intel D945G", STAC_D945GTP3),
1900 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1901 "Intel D945G", STAC_D945GTP3),
1902 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1903 "Intel D945G", STAC_D945GTP3),
1904 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1905 "Intel D945G", STAC_D945GTP3),
1906 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1907 "Intel D945G", STAC_D945GTP3),
1908 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1909 "Intel D945G", STAC_D945GTP3),
1910 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1911 "Intel D945G", STAC_D945GTP3),
1912 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1913 "Intel D945G", STAC_D945GTP3),
1914 /* Intel D945G 5-stack systems */
1915 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1916 "Intel D945G", STAC_D945GTP5),
1917 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1918 "Intel D945G", STAC_D945GTP5),
1919 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1920 "Intel D945G", STAC_D945GTP5),
1921 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1922 "Intel D945G", STAC_D945GTP5),
1923 /* Intel 945P based systems */
1924 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1925 "Intel D945P", STAC_D945GTP3),
1926 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1927 "Intel D945P", STAC_D945GTP3),
1928 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1929 "Intel D945P", STAC_D945GTP3),
1930 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1931 "Intel D945P", STAC_D945GTP3),
1932 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1933 "Intel D945P", STAC_D945GTP3),
1934 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1935 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01001936 /* other intel */
1937 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
1938 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001939 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08001940 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001941 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001942 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001943 /* Dell systems */
1944 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1945 "unknown Dell", STAC_922X_DELL_D81),
1946 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1947 "unknown Dell", STAC_922X_DELL_D81),
1948 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1949 "unknown Dell", STAC_922X_DELL_D81),
1950 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1951 "unknown Dell", STAC_922X_DELL_D82),
1952 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1953 "unknown Dell", STAC_922X_DELL_M81),
1954 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1955 "unknown Dell", STAC_922X_DELL_D82),
1956 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1957 "unknown Dell", STAC_922X_DELL_D81),
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1959 "unknown Dell", STAC_922X_DELL_D81),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1961 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001962 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001963 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02001964 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01001965 {} /* terminator */
1966};
1967
Matt Porter3cc08dc2006-01-23 15:27:49 +01001968static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001969 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1970 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1971 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1972 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001973};
1974
Tobin Davis93ed1502006-09-01 21:03:12 +02001975static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001976 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1977 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1978 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1979 0x40000100, 0x40000100
1980};
1981
Tobin Davis93ed1502006-09-01 21:03:12 +02001982static unsigned int d965_5st_pin_configs[14] = {
1983 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1984 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1985 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1986 0x40000100, 0x40000100
1987};
1988
Takashi Iwai679d92e2009-05-24 19:00:08 +02001989static unsigned int d965_5st_no_fp_pin_configs[14] = {
1990 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
1991 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1992 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1993 0x40000100, 0x40000100
1994};
1995
Tobin Davis4ff076e2007-08-07 11:48:12 +02001996static unsigned int dell_3st_pin_configs[14] = {
1997 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1998 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001999 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002000 0x40c003fc, 0x40000100
2001};
2002
Tobin Davis93ed1502006-09-01 21:03:12 +02002003static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002004 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002005 [STAC_D965_REF] = ref927x_pin_configs,
2006 [STAC_D965_3ST] = d965_3st_pin_configs,
2007 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002008 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002009 [STAC_DELL_3ST] = dell_3st_pin_configs,
2010 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002011 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002012};
2013
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002014static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002015 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002016 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002017 [STAC_D965_REF] = "ref",
2018 [STAC_D965_3ST] = "3stack",
2019 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002020 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002021 [STAC_DELL_3ST] = "dell-3stack",
2022 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002023 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002024};
2025
2026static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2027 /* SigmaTel reference board */
2028 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2029 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002030 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2031 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002032 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002033 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2034 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002035 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002036 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2037 "Intel D965", STAC_D965_3ST),
2038 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2039 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002040 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002041 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002042 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002043 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2044 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002045 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002046 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2047 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002048 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002049 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002050 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2051 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2052 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2053 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002054 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002055 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2056 "Intel D965", STAC_D965_5ST),
2057 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2058 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002059 /* volume-knob fixes */
2060 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002061 {} /* terminator */
2062};
2063
Matt Porterf3302a52006-07-31 12:49:34 +02002064static unsigned int ref9205_pin_configs[12] = {
2065 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002066 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002067 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002068};
2069
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002070/*
2071 STAC 9205 pin configs for
2072 102801F1
2073 102801F2
2074 102801FC
2075 102801FD
2076 10280204
2077 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002078 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002079*/
2080static unsigned int dell_9205_m42_pin_configs[12] = {
2081 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2082 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2083 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2084};
2085
2086/*
2087 STAC 9205 pin configs for
2088 102801F9
2089 102801FA
2090 102801FE
2091 102801FF (Dell Precision M4300)
2092 10280206
2093 10280200
2094 10280201
2095*/
2096static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002097 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2098 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2099 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2100};
2101
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002102static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002103 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2104 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2105 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2106};
2107
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002108static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002109 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002110 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2111 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2112 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002113 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002114};
2115
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002116static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002117 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002118 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002119 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002120 [STAC_9205_DELL_M43] = "dell-m43",
2121 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002122 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002123};
2124
2125static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2126 /* SigmaTel reference board */
2127 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2128 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002129 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2130 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002131 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2132 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002133 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002134 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2135 "unknown Dell", STAC_9205_DELL_M42),
2136 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2137 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002138 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002139 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002140 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2141 "Dell Precision", STAC_9205_DELL_M43),
2142 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2143 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002144 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2145 "unknown Dell", STAC_9205_DELL_M42),
2146 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2147 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002148 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2149 "Dell Precision", STAC_9205_DELL_M43),
2150 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002151 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002152 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2153 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002154 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2155 "Dell Precision", STAC_9205_DELL_M43),
2156 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2157 "Dell Precision", STAC_9205_DELL_M43),
2158 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2159 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002160 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2161 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002162 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2163 "Dell Vostro 1500", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002164 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002165 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002166 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002167 {} /* terminator */
2168};
2169
Takashi Iwai330ee992009-02-20 14:33:36 +01002170static void stac92xx_set_config_regs(struct hda_codec *codec,
2171 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002172{
2173 int i;
2174 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002175
Takashi Iwai330ee992009-02-20 14:33:36 +01002176 if (!pincfgs)
2177 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002178
Matthew Ranostay87d48362007-07-17 11:52:24 +02002179 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002180 if (spec->pin_nids[i] && pincfgs[i])
2181 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2182 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002183}
2184
Matt2f2f4252005-04-13 14:45:30 +02002185/*
2186 * Analog playback callbacks
2187 */
2188static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2189 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002190 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002191{
2192 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002193 if (spec->stream_delay)
2194 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002195 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2196 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002197}
2198
2199static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2200 struct hda_codec *codec,
2201 unsigned int stream_tag,
2202 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002203 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002204{
2205 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002206 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002207}
2208
2209static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2210 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002211 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002212{
2213 struct sigmatel_spec *spec = codec->spec;
2214 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2215}
2216
2217/*
Mattdabbed62005-06-14 10:19:34 +02002218 * Digital playback callbacks
2219 */
2220static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2221 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002222 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002223{
2224 struct sigmatel_spec *spec = codec->spec;
2225 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2226}
2227
2228static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2229 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002230 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002231{
2232 struct sigmatel_spec *spec = codec->spec;
2233 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2234}
2235
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002236static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2237 struct hda_codec *codec,
2238 unsigned int stream_tag,
2239 unsigned int format,
2240 struct snd_pcm_substream *substream)
2241{
2242 struct sigmatel_spec *spec = codec->spec;
2243 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2244 stream_tag, format, substream);
2245}
2246
Takashi Iwai9411e212009-02-13 11:32:28 +01002247static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2248 struct hda_codec *codec,
2249 struct snd_pcm_substream *substream)
2250{
2251 struct sigmatel_spec *spec = codec->spec;
2252 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2253}
2254
Mattdabbed62005-06-14 10:19:34 +02002255
2256/*
Matt2f2f4252005-04-13 14:45:30 +02002257 * Analog capture callbacks
2258 */
2259static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2260 struct hda_codec *codec,
2261 unsigned int stream_tag,
2262 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002263 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002264{
2265 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002266 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002267
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002268 if (spec->powerdown_adcs) {
2269 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002270 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002271 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2272 }
2273 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002274 return 0;
2275}
2276
2277static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2278 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002279 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002280{
2281 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002282 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002283
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002284 snd_hda_codec_cleanup_stream(codec, nid);
2285 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002286 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002287 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002288 return 0;
2289}
2290
Mattdabbed62005-06-14 10:19:34 +02002291static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2292 .substreams = 1,
2293 .channels_min = 2,
2294 .channels_max = 2,
2295 /* NID is set in stac92xx_build_pcms */
2296 .ops = {
2297 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002298 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002299 .prepare = stac92xx_dig_playback_pcm_prepare,
2300 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002301 },
2302};
2303
2304static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2305 .substreams = 1,
2306 .channels_min = 2,
2307 .channels_max = 2,
2308 /* NID is set in stac92xx_build_pcms */
2309};
2310
Matt2f2f4252005-04-13 14:45:30 +02002311static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2312 .substreams = 1,
2313 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002314 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002315 .nid = 0x02, /* NID to query formats and rates */
2316 .ops = {
2317 .open = stac92xx_playback_pcm_open,
2318 .prepare = stac92xx_playback_pcm_prepare,
2319 .cleanup = stac92xx_playback_pcm_cleanup
2320 },
2321};
2322
Matt Porter3cc08dc2006-01-23 15:27:49 +01002323static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2324 .substreams = 1,
2325 .channels_min = 2,
2326 .channels_max = 2,
2327 .nid = 0x06, /* NID to query formats and rates */
2328 .ops = {
2329 .open = stac92xx_playback_pcm_open,
2330 .prepare = stac92xx_playback_pcm_prepare,
2331 .cleanup = stac92xx_playback_pcm_cleanup
2332 },
2333};
2334
Matt2f2f4252005-04-13 14:45:30 +02002335static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002336 .channels_min = 2,
2337 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002338 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002339 .ops = {
2340 .prepare = stac92xx_capture_pcm_prepare,
2341 .cleanup = stac92xx_capture_pcm_cleanup
2342 },
2343};
2344
2345static int stac92xx_build_pcms(struct hda_codec *codec)
2346{
2347 struct sigmatel_spec *spec = codec->spec;
2348 struct hda_pcm *info = spec->pcm_rec;
2349
2350 codec->num_pcms = 1;
2351 codec->pcm_info = info;
2352
Mattc7d4b2f2005-06-27 14:59:41 +02002353 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002354 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002355 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2356 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002357 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002358 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002359 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002360
2361 if (spec->alt_switch) {
2362 codec->num_pcms++;
2363 info++;
2364 info->name = "STAC92xx Analog Alt";
2365 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2366 }
Matt2f2f4252005-04-13 14:45:30 +02002367
Mattdabbed62005-06-14 10:19:34 +02002368 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2369 codec->num_pcms++;
2370 info++;
2371 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002372 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002373 if (spec->multiout.dig_out_nid) {
2374 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2375 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2376 }
2377 if (spec->dig_in_nid) {
2378 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2379 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2380 }
2381 }
2382
Matt2f2f4252005-04-13 14:45:30 +02002383 return 0;
2384}
2385
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002386static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2387 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002388{
Takashi Iwai1327a322009-03-23 13:07:47 +01002389 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002390 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2391 if (pincap & AC_PINCAP_VREF_100)
2392 return AC_PINCTL_VREF_100;
2393 if (pincap & AC_PINCAP_VREF_80)
2394 return AC_PINCTL_VREF_80;
2395 if (pincap & AC_PINCAP_VREF_50)
2396 return AC_PINCTL_VREF_50;
2397 if (pincap & AC_PINCAP_VREF_GRD)
2398 return AC_PINCTL_VREF_GRD;
2399 return 0;
2400}
2401
Matt Porter403d1942005-11-29 15:00:51 +01002402static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2403
2404{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002405 snd_hda_codec_write_cache(codec, nid, 0,
2406 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002407}
2408
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002409#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2410
2411static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2412 struct snd_ctl_elem_value *ucontrol)
2413{
2414 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2415 struct sigmatel_spec *spec = codec->spec;
2416
Takashi Iwaid7a89432008-11-12 09:48:04 +01002417 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002418 return 0;
2419}
2420
Takashi Iwai62558ce2009-07-29 14:23:09 +02002421static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002422
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002423static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2424 struct snd_ctl_elem_value *ucontrol)
2425{
2426 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2427 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002428 int nid = kcontrol->private_value;
2429
2430 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002431
2432 /* check to be sure that the ports are upto date with
2433 * switch changes
2434 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002435 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002436
2437 return 1;
2438}
2439
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002440static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2441 struct snd_ctl_elem_info *uinfo)
2442{
2443 int i;
2444 static char *texts[] = {
2445 "Mic In", "Line In", "Line Out"
2446 };
2447
2448 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2449 struct sigmatel_spec *spec = codec->spec;
2450 hda_nid_t nid = kcontrol->private_value;
2451
2452 if (nid == spec->mic_switch || nid == spec->line_switch)
2453 i = 3;
2454 else
2455 i = 2;
2456
2457 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2458 uinfo->value.enumerated.items = i;
2459 uinfo->count = 1;
2460 if (uinfo->value.enumerated.item >= i)
2461 uinfo->value.enumerated.item = i-1;
2462 strcpy(uinfo->value.enumerated.name,
2463 texts[uinfo->value.enumerated.item]);
2464
2465 return 0;
2466}
2467
2468static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2469 struct snd_ctl_elem_value *ucontrol)
2470{
2471 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2472 hda_nid_t nid = kcontrol->private_value;
2473 unsigned int vref = stac92xx_vref_get(codec, nid);
2474
2475 if (vref == stac92xx_get_default_vref(codec, nid))
2476 ucontrol->value.enumerated.item[0] = 0;
2477 else if (vref == AC_PINCTL_VREF_GRD)
2478 ucontrol->value.enumerated.item[0] = 1;
2479 else if (vref == AC_PINCTL_VREF_HIZ)
2480 ucontrol->value.enumerated.item[0] = 2;
2481
2482 return 0;
2483}
2484
2485static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2486 struct snd_ctl_elem_value *ucontrol)
2487{
2488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2489 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002490 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002491 hda_nid_t nid = kcontrol->private_value;
2492
2493 if (ucontrol->value.enumerated.item[0] == 0)
2494 new_vref = stac92xx_get_default_vref(codec, nid);
2495 else if (ucontrol->value.enumerated.item[0] == 1)
2496 new_vref = AC_PINCTL_VREF_GRD;
2497 else if (ucontrol->value.enumerated.item[0] == 2)
2498 new_vref = AC_PINCTL_VREF_HIZ;
2499 else
2500 return 0;
2501
2502 if (new_vref != stac92xx_vref_get(codec, nid)) {
2503 error = stac92xx_vref_set(codec, nid, new_vref);
2504 return error;
2505 }
2506
2507 return 0;
2508}
2509
2510static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2511 struct snd_ctl_elem_info *uinfo)
2512{
2513 static char *texts[2];
2514 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2515 struct sigmatel_spec *spec = codec->spec;
2516
2517 if (kcontrol->private_value == spec->line_switch)
2518 texts[0] = "Line In";
2519 else
2520 texts[0] = "Mic In";
2521 texts[1] = "Line Out";
2522 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2523 uinfo->value.enumerated.items = 2;
2524 uinfo->count = 1;
2525
2526 if (uinfo->value.enumerated.item >= 2)
2527 uinfo->value.enumerated.item = 1;
2528 strcpy(uinfo->value.enumerated.name,
2529 texts[uinfo->value.enumerated.item]);
2530
2531 return 0;
2532}
Matt Porter403d1942005-11-29 15:00:51 +01002533
2534static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2535{
2536 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2537 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002538 hda_nid_t nid = kcontrol->private_value;
2539 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002540
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002541 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002542 return 0;
2543}
2544
2545static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2546{
2547 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2548 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002549 hda_nid_t nid = kcontrol->private_value;
2550 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2551 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002552
2553 spec->io_switch[io_idx] = val;
2554
2555 if (val)
2556 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002557 else {
2558 unsigned int pinctl = AC_PINCTL_IN_EN;
2559 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002560 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002561 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2562 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002563
2564 /* check the auto-mute again: we need to mute/unmute the speaker
2565 * appropriately according to the pin direction
2566 */
2567 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002568 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002569
Matt Porter403d1942005-11-29 15:00:51 +01002570 return 1;
2571}
2572
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002573#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2574
2575static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2576 struct snd_ctl_elem_value *ucontrol)
2577{
2578 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2579 struct sigmatel_spec *spec = codec->spec;
2580
2581 ucontrol->value.integer.value[0] = spec->clfe_swap;
2582 return 0;
2583}
2584
2585static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2586 struct snd_ctl_elem_value *ucontrol)
2587{
2588 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2589 struct sigmatel_spec *spec = codec->spec;
2590 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002591 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002592
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002593 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002594 return 0;
2595
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002596 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002597
2598 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2599 spec->clfe_swap ? 0x4 : 0x0);
2600
2601 return 1;
2602}
2603
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002604#define STAC_CODEC_HP_SWITCH(xname) \
2605 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2606 .name = xname, \
2607 .index = 0, \
2608 .info = stac92xx_hp_switch_info, \
2609 .get = stac92xx_hp_switch_get, \
2610 .put = stac92xx_hp_switch_put, \
2611 }
2612
Matt Porter403d1942005-11-29 15:00:51 +01002613#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2614 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2615 .name = xname, \
2616 .index = 0, \
2617 .info = stac92xx_io_switch_info, \
2618 .get = stac92xx_io_switch_get, \
2619 .put = stac92xx_io_switch_put, \
2620 .private_value = xpval, \
2621 }
2622
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002623#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2624 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2625 .name = xname, \
2626 .index = 0, \
2627 .info = stac92xx_clfe_switch_info, \
2628 .get = stac92xx_clfe_switch_get, \
2629 .put = stac92xx_clfe_switch_put, \
2630 .private_value = xpval, \
2631 }
Matt Porter403d1942005-11-29 15:00:51 +01002632
Mattc7d4b2f2005-06-27 14:59:41 +02002633enum {
2634 STAC_CTL_WIDGET_VOL,
2635 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002636 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002637 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002638 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002639 STAC_CTL_WIDGET_CLFE_SWITCH,
2640 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002641};
2642
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002643static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002644 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2645 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002646 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002647 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002648 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002649 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002650 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002651};
2652
2653/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002654static struct snd_kcontrol_new *
2655stac_control_new(struct sigmatel_spec *spec,
2656 struct snd_kcontrol_new *ktemp,
2657 const char *name)
Mattc7d4b2f2005-06-27 14:59:41 +02002658{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002659 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002660
Takashi Iwai603c4012008-07-30 15:01:44 +02002661 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2662 knew = snd_array_new(&spec->kctls);
2663 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002664 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002665 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002666 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002667 if (!knew->name) {
2668 /* roolback */
2669 memset(knew, 0, sizeof(*knew));
2670 spec->kctls.alloced--;
2671 return NULL;
2672 }
2673 return knew;
2674}
2675
2676static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2677 struct snd_kcontrol_new *ktemp,
2678 int idx, const char *name,
2679 unsigned long val)
2680{
2681 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2682 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002683 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002684 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002685 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002686 return 0;
2687}
2688
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002689static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2690 int type, int idx, const char *name,
2691 unsigned long val)
2692{
2693 return stac92xx_add_control_temp(spec,
2694 &stac92xx_control_templates[type],
2695 idx, name, val);
2696}
2697
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002698
2699/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002700static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2701 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002702{
2703 return stac92xx_add_control_idx(spec, type, 0, name, val);
2704}
2705
Takashi Iwaie3c75962009-01-23 11:57:22 +01002706static struct snd_kcontrol_new stac_input_src_temp = {
2707 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2708 .name = "Input Source",
2709 .info = stac92xx_mux_enum_info,
2710 .get = stac92xx_mux_enum_get,
2711 .put = stac92xx_mux_enum_put,
2712};
2713
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002714static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2715 hda_nid_t nid, int idx)
2716{
2717 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2718 int control = 0;
2719 struct sigmatel_spec *spec = codec->spec;
2720 char name[22];
2721
2722 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2723 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2724 && nid == spec->line_switch)
2725 control = STAC_CTL_WIDGET_IO_SWITCH;
2726 else if (snd_hda_query_pin_caps(codec, nid)
2727 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2728 control = STAC_CTL_WIDGET_DC_BIAS;
2729 else if (nid == spec->mic_switch)
2730 control = STAC_CTL_WIDGET_IO_SWITCH;
2731 }
2732
2733 if (control) {
2734 strcpy(name, auto_pin_cfg_labels[idx]);
2735 return stac92xx_add_control(codec->spec, control,
2736 strcat(name, " Jack Mode"), nid);
2737 }
2738
2739 return 0;
2740}
2741
Takashi Iwaie3c75962009-01-23 11:57:22 +01002742static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2743{
2744 struct snd_kcontrol_new *knew;
2745 struct hda_input_mux *imux = &spec->private_imux;
2746
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002747 if (spec->auto_mic)
2748 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002749 if (!spec->num_adcs || imux->num_items <= 1)
2750 return 0; /* no need for input source control */
2751 knew = stac_control_new(spec, &stac_input_src_temp,
2752 stac_input_src_temp.name);
2753 if (!knew)
2754 return -ENOMEM;
2755 knew->count = spec->num_adcs;
2756 return 0;
2757}
2758
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002759/* check whether the line-input can be used as line-out */
2760static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002761{
2762 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002763 struct auto_pin_cfg *cfg = &spec->autocfg;
2764 hda_nid_t nid;
2765 unsigned int pincap;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002766
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002767 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2768 return 0;
2769 nid = cfg->input_pins[AUTO_PIN_LINE];
Takashi Iwai1327a322009-03-23 13:07:47 +01002770 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002771 if (pincap & AC_PINCAP_OUT)
2772 return nid;
Matt Porter403d1942005-11-29 15:00:51 +01002773 return 0;
2774}
2775
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002776/* check whether the mic-input can be used as line-out */
2777static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2778{
2779 struct sigmatel_spec *spec = codec->spec;
2780 struct auto_pin_cfg *cfg = &spec->autocfg;
2781 unsigned int def_conf, pincap;
2782 unsigned int mic_pin;
2783
2784 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2785 return 0;
2786 mic_pin = AUTO_PIN_MIC;
2787 for (;;) {
2788 hda_nid_t nid = cfg->input_pins[mic_pin];
Takashi Iwai330ee992009-02-20 14:33:36 +01002789 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002790 /* some laptops have an internal analog microphone
2791 * which can't be used as a output */
2792 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai1327a322009-03-23 13:07:47 +01002793 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002794 if (pincap & AC_PINCAP_OUT)
2795 return nid;
2796 }
2797 if (mic_pin == AUTO_PIN_MIC)
2798 mic_pin = AUTO_PIN_FRONT_MIC;
2799 else
2800 break;
2801 }
2802 return 0;
2803}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002804
2805static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2806{
2807 int i;
2808
2809 for (i = 0; i < spec->multiout.num_dacs; i++) {
2810 if (spec->multiout.dac_nids[i] == nid)
2811 return 1;
2812 }
2813
2814 return 0;
2815}
2816
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002817static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2818{
2819 int i;
2820 if (is_in_dac_nids(spec, nid))
2821 return 1;
2822 for (i = 0; i < spec->autocfg.hp_outs; i++)
2823 if (spec->hp_dacs[i] == nid)
2824 return 1;
2825 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2826 if (spec->speaker_dacs[i] == nid)
2827 return 1;
2828 return 0;
2829}
2830
2831static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2832{
2833 struct sigmatel_spec *spec = codec->spec;
2834 int j, conn_len;
2835 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2836 unsigned int wcaps, wtype;
2837
2838 conn_len = snd_hda_get_connections(codec, nid, conn,
2839 HDA_MAX_CONNECTIONS);
2840 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002841 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002842 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002843 /* we check only analog outputs */
2844 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2845 continue;
2846 /* if this route has a free DAC, assign it */
2847 if (!check_all_dac_nids(spec, conn[j])) {
2848 if (conn_len > 1) {
2849 /* select this DAC in the pin's input mux */
2850 snd_hda_codec_write_cache(codec, nid, 0,
2851 AC_VERB_SET_CONNECT_SEL, j);
2852 }
2853 return conn[j];
2854 }
2855 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002856 /* if all DACs are already assigned, connect to the primary DAC */
2857 if (conn_len > 1) {
2858 for (j = 0; j < conn_len; j++) {
2859 if (conn[j] == spec->multiout.dac_nids[0]) {
2860 snd_hda_codec_write_cache(codec, nid, 0,
2861 AC_VERB_SET_CONNECT_SEL, j);
2862 break;
2863 }
2864 }
2865 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002866 return 0;
2867}
2868
2869static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2870static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2871
Matt Porter3cc08dc2006-01-23 15:27:49 +01002872/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002873 * Fill in the dac_nids table from the parsed pin configuration
2874 * This function only works when every pin in line_out_pins[]
2875 * contains atleast one DAC in its connection list. Some 92xx
2876 * codecs are not connected directly to a DAC, such as the 9200
2877 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002878 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002879static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002880{
2881 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002882 struct auto_pin_cfg *cfg = &spec->autocfg;
2883 int i;
2884 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002885
Mattc7d4b2f2005-06-27 14:59:41 +02002886 for (i = 0; i < cfg->line_outs; i++) {
2887 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002888 dac = get_unassigned_dac(codec, nid);
2889 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002890 if (spec->multiout.num_dacs > 0) {
2891 /* we have already working output pins,
2892 * so let's drop the broken ones again
2893 */
2894 cfg->line_outs = spec->multiout.num_dacs;
2895 break;
2896 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002897 /* error out, no available DAC found */
2898 snd_printk(KERN_ERR
2899 "%s: No available DAC for pin 0x%x\n",
2900 __func__, nid);
2901 return -ENODEV;
2902 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002903 add_spec_dacs(spec, dac);
2904 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002905
Takashi Iwai139e0712009-03-06 12:10:41 +01002906 for (i = 0; i < cfg->hp_outs; i++) {
2907 nid = cfg->hp_pins[i];
2908 dac = get_unassigned_dac(codec, nid);
2909 if (dac) {
2910 if (!spec->multiout.hp_nid)
2911 spec->multiout.hp_nid = dac;
2912 else
2913 add_spec_extra_dacs(spec, dac);
2914 }
2915 spec->hp_dacs[i] = dac;
2916 }
2917
2918 for (i = 0; i < cfg->speaker_outs; i++) {
2919 nid = cfg->speaker_pins[i];
2920 dac = get_unassigned_dac(codec, nid);
2921 if (dac)
2922 add_spec_extra_dacs(spec, dac);
2923 spec->speaker_dacs[i] = dac;
2924 }
2925
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002926 /* add line-in as output */
2927 nid = check_line_out_switch(codec);
2928 if (nid) {
2929 dac = get_unassigned_dac(codec, nid);
2930 if (dac) {
2931 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2932 nid, cfg->line_outs);
2933 cfg->line_out_pins[cfg->line_outs] = nid;
2934 cfg->line_outs++;
2935 spec->line_switch = nid;
2936 add_spec_dacs(spec, dac);
2937 }
2938 }
2939 /* add mic as output */
2940 nid = check_mic_out_switch(codec);
2941 if (nid) {
2942 dac = get_unassigned_dac(codec, nid);
2943 if (dac) {
2944 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
2945 nid, cfg->line_outs);
2946 cfg->line_out_pins[cfg->line_outs] = nid;
2947 cfg->line_outs++;
2948 spec->mic_switch = nid;
2949 add_spec_dacs(spec, dac);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002950 }
Mattc7d4b2f2005-06-27 14:59:41 +02002951 }
2952
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002953 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02002954 spec->multiout.num_dacs,
2955 spec->multiout.dac_nids[0],
2956 spec->multiout.dac_nids[1],
2957 spec->multiout.dac_nids[2],
2958 spec->multiout.dac_nids[3],
2959 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002960
Mattc7d4b2f2005-06-27 14:59:41 +02002961 return 0;
2962}
2963
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002964/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01002965static int create_controls_idx(struct hda_codec *codec, const char *pfx,
2966 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002967{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002968 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002969 char name[32];
2970 int err;
2971
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002972 if (!spec->check_volume_offset) {
2973 unsigned int caps, step, nums, db_scale;
2974 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
2975 step = (caps & AC_AMPCAP_STEP_SIZE) >>
2976 AC_AMPCAP_STEP_SIZE_SHIFT;
2977 step = (step + 1) * 25; /* in .01dB unit */
2978 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
2979 AC_AMPCAP_NUM_STEPS_SHIFT;
2980 db_scale = nums * step;
2981 /* if dB scale is over -64dB, and finer enough,
2982 * let's reduce it to half
2983 */
2984 if (db_scale > 6400 && nums >= 0x1f)
2985 spec->volume_offset = nums / 2;
2986 spec->check_volume_offset = 1;
2987 }
2988
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002989 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01002990 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002991 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
2992 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002993 if (err < 0)
2994 return err;
2995 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01002996 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002997 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2998 if (err < 0)
2999 return err;
3000 return 0;
3001}
3002
Takashi Iwai668b9652009-03-06 10:13:24 +01003003#define create_controls(codec, pfx, nid, chs) \
3004 create_controls_idx(codec, pfx, 0, nid, chs)
3005
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003006static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3007{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003008 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003009 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3010 return 1;
3011 } else {
3012 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3013 spec->multiout.num_dacs++;
3014 }
3015 return 0;
3016}
3017
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003018static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003019{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003020 int i;
3021 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3022 if (!spec->multiout.extra_out_nid[i]) {
3023 spec->multiout.extra_out_nid[i] = nid;
3024 return 0;
3025 }
3026 }
3027 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3028 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003029}
3030
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003031/* Create output controls
3032 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3033 */
3034static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3035 const hda_nid_t *pins,
3036 const hda_nid_t *dac_nids,
3037 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003038{
Takashi Iwai76624532008-12-19 10:09:47 +01003039 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003040 static const char *chname[4] = {
3041 "Front", "Surround", NULL /*CLFE*/, "Side"
3042 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003043 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003044 int i, err;
3045 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003046
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003047 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003048 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3049 wid_caps = get_wcaps(codec, pins[i]);
3050 if (wid_caps & AC_WCAP_UNSOL_CAP)
3051 spec->hp_detect = 1;
3052 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003053 nid = dac_nids[i];
3054 if (!nid)
3055 continue;
3056 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003057 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003058 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003059 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003060 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003061 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003062 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003063 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003064
3065 wid_caps = get_wcaps(codec, nid);
3066
3067 if (wid_caps & AC_WCAP_LR_SWAP) {
3068 err = stac92xx_add_control(spec,
3069 STAC_CTL_WIDGET_CLFE_SWITCH,
3070 "Swap Center/LFE Playback Switch", nid);
3071
3072 if (err < 0)
3073 return err;
3074 }
3075
Mattc7d4b2f2005-06-27 14:59:41 +02003076 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003077 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003078 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003079 switch (type) {
3080 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003081 name = "Headphone";
3082 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003083 break;
3084 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003085 name = "Speaker";
3086 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003087 break;
3088 default:
3089 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003090 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003091 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003092 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003093 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003094 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003095 return err;
3096 }
3097 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003098 return 0;
3099}
3100
Takashi Iwai6479c632009-07-28 18:20:25 +02003101static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3102 unsigned long sw, int idx)
3103{
3104 int err;
3105 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003106 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003107 if (err < 0)
3108 return err;
3109 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003110 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003111 if (err < 0)
3112 return err;
3113 return 0;
3114}
3115
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003116/* add playback controls from the parsed DAC table */
3117static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3118 const struct auto_pin_cfg *cfg)
3119{
3120 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003121 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003122 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003123 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003124
3125 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3126 spec->multiout.dac_nids,
3127 cfg->line_out_type);
3128 if (err < 0)
3129 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003130
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003131 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003132 err = stac92xx_add_control(spec,
3133 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003134 "Headphone as Line Out Switch",
3135 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003136 if (err < 0)
3137 return err;
3138 }
3139
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003140 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3141 nid = cfg->input_pins[idx];
3142 if (nid) {
3143 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3144 if (err < 0)
3145 return err;
3146 }
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003147 }
Matt Porter403d1942005-11-29 15:00:51 +01003148
Mattc7d4b2f2005-06-27 14:59:41 +02003149 return 0;
3150}
3151
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003152/* add playback controls for Speaker and HP outputs */
3153static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3154 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003155{
3156 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003157 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003158
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003159 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3160 spec->hp_dacs, AUTO_PIN_HP_OUT);
3161 if (err < 0)
3162 return err;
3163
3164 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3165 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3166 if (err < 0)
3167 return err;
3168
Mattc7d4b2f2005-06-27 14:59:41 +02003169 return 0;
3170}
3171
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003172/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003173static const char *stac92xx_mono_labels[4] = {
3174 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003175};
3176
3177/* create mono mux for mono out on capable codecs */
3178static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3179{
3180 struct sigmatel_spec *spec = codec->spec;
3181 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3182 int i, num_cons;
3183 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3184
3185 num_cons = snd_hda_get_connections(codec,
3186 spec->mono_nid,
3187 con_lst,
3188 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003189 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003190 return -EINVAL;
3191
3192 for (i = 0; i < num_cons; i++) {
3193 mono_mux->items[mono_mux->num_items].label =
3194 stac92xx_mono_labels[i];
3195 mono_mux->items[mono_mux->num_items].index = i;
3196 mono_mux->num_items++;
3197 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003198
3199 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3200 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003201}
3202
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003203/* create PC beep volume controls */
3204static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3205 hda_nid_t nid)
3206{
3207 struct sigmatel_spec *spec = codec->spec;
3208 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3209 int err;
3210
3211 /* check for mute support for the the amp */
3212 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3213 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3214 "PC Beep Playback Switch",
3215 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3216 if (err < 0)
3217 return err;
3218 }
3219
3220 /* check to see if there is volume support for the amp */
3221 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3222 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3223 "PC Beep Playback Volume",
3224 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3225 if (err < 0)
3226 return err;
3227 }
3228 return 0;
3229}
3230
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003231#ifdef CONFIG_SND_HDA_INPUT_BEEP
3232#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3233
3234static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3235 struct snd_ctl_elem_value *ucontrol)
3236{
3237 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3238 ucontrol->value.integer.value[0] = codec->beep->enabled;
3239 return 0;
3240}
3241
3242static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3243 struct snd_ctl_elem_value *ucontrol)
3244{
3245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3246 int enabled = !!ucontrol->value.integer.value[0];
3247 if (codec->beep->enabled != enabled) {
3248 codec->beep->enabled = enabled;
3249 return 1;
3250 }
3251 return 0;
3252}
3253
3254static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3255 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3256 .info = stac92xx_dig_beep_switch_info,
3257 .get = stac92xx_dig_beep_switch_get,
3258 .put = stac92xx_dig_beep_switch_put,
3259};
3260
3261static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3262{
3263 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3264 0, "PC Beep Playback Switch", 0);
3265}
3266#endif
3267
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003268static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3269{
3270 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003271 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003272
3273 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003274 hda_nid_t nid;
3275 unsigned int wcaps;
3276 unsigned long val;
3277
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003278 nid = spec->mux_nids[i];
3279 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003280 if (!(wcaps & AC_WCAP_OUT_AMP))
3281 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003282
Takashi Iwai667067d2009-08-13 18:14:42 +02003283 /* check whether already the same control was created as
3284 * normal Capture Volume.
3285 */
3286 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3287 for (j = 0; j < spec->num_caps; j++) {
3288 if (spec->capvols[j] == val)
3289 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003290 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003291 if (j < spec->num_caps)
3292 continue;
3293
3294 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3295 "Mux Capture Volume", val);
3296 if (err < 0)
3297 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003298 }
3299 return 0;
3300};
3301
Matthew Ranostayd9737752008-09-07 12:03:41 +02003302static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003303 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003304};
3305
3306static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3307{
3308 struct sigmatel_spec *spec = codec->spec;
3309 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003310 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003311 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003312 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003313
3314 num_cons = snd_hda_get_connections(codec,
3315 spec->smux_nids[0],
3316 con_lst,
3317 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003318 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003319 return -EINVAL;
3320
Matthew Ranostay65973632008-09-16 10:39:37 -04003321 if (!labels)
3322 labels = stac92xx_spdif_labels;
3323
Matthew Ranostayd9737752008-09-07 12:03:41 +02003324 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003325 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003326 spdif_mux->items[spdif_mux->num_items].index = i;
3327 spdif_mux->num_items++;
3328 }
3329
3330 return 0;
3331}
3332
Matt Porter8b657272006-10-26 17:12:59 +02003333/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003334static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003335 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3336 "Digital Mic 3", "Digital Mic 4"
3337};
3338
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003339static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3340 hda_nid_t nid)
3341{
3342 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3343 int i, nums;
3344
3345 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3346 for (i = 0; i < nums; i++)
3347 if (conn[i] == nid)
3348 return i;
3349 return -1;
3350}
3351
Takashi Iwai667067d2009-08-13 18:14:42 +02003352/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003353/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003354static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003355 const char *label, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003356{
3357 unsigned int caps, nums;
3358 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003359 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003360
Takashi Iwai96f845d2009-08-29 00:49:36 +02003361 if (direction == HDA_OUTPUT)
3362 caps = AC_WCAP_OUT_AMP;
3363 else
3364 caps = AC_WCAP_IN_AMP;
3365 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003366 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003367 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003368 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3369 if (!nums)
3370 return 0;
3371 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003372 err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3373 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3374 if (err < 0)
3375 return err;
3376 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003377}
3378
Matt Porter8b657272006-10-26 17:12:59 +02003379/* create playback/capture controls for input pins on dmic capable codecs */
3380static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3381 const struct auto_pin_cfg *cfg)
3382{
3383 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003384 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003385 struct hda_input_mux *dimux = &spec->private_dimux;
Takashi Iwai5207e102009-07-30 13:09:08 +02003386 int err, i, active_mics;
3387 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003388
3389 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3390 dimux->items[dimux->num_items].index = 0;
3391 dimux->num_items++;
3392
Takashi Iwai5207e102009-07-30 13:09:08 +02003393 active_mics = 0;
3394 for (i = 0; i < spec->num_dmics; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003395 /* check the validity: sometimes it's a dead vendor-spec node */
3396 if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3397 != AC_WID_PIN)
3398 continue;
Takashi Iwai5207e102009-07-30 13:09:08 +02003399 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3400 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3401 active_mics++;
3402 }
3403
Matt Porter8b657272006-10-26 17:12:59 +02003404 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003405 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003406 int index;
Takashi Iwai5207e102009-07-30 13:09:08 +02003407 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003408
Takashi Iwai667067d2009-08-13 18:14:42 +02003409 nid = spec->dmic_nids[i];
3410 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3411 continue;
3412 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003413 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3414 continue;
3415
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003416 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3417 if (index < 0)
3418 continue;
3419
Takashi Iwai5207e102009-07-30 13:09:08 +02003420 if (active_mics == 1)
3421 label = "Digital Mic";
3422 else
3423 label = stac92xx_dmic_labels[dimux->num_items];
3424
Takashi Iwai96f845d2009-08-29 00:49:36 +02003425 err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003426 if (err < 0)
3427 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003428 if (!err) {
3429 err = create_elem_capture_vol(codec, nid, label,
3430 HDA_OUTPUT);
3431 if (err < 0)
3432 return err;
3433 }
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003434
Takashi Iwai5207e102009-07-30 13:09:08 +02003435 dimux->items[dimux->num_items].label = label;
Matt Porter8b657272006-10-26 17:12:59 +02003436 dimux->items[dimux->num_items].index = index;
3437 dimux->num_items++;
Takashi Iwai5207e102009-07-30 13:09:08 +02003438 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3439 imux->items[imux->num_items].label = label;
3440 imux->items[imux->num_items].index = index;
3441 imux->num_items++;
3442 }
Matt Porter8b657272006-10-26 17:12:59 +02003443 }
3444
3445 return 0;
3446}
3447
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003448static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3449 hda_nid_t *fixed, hda_nid_t *ext)
3450{
3451 unsigned int cfg;
3452
3453 if (!nid)
3454 return 0;
3455 cfg = snd_hda_codec_get_pincfg(codec, nid);
3456 switch (get_defcfg_connect(cfg)) {
3457 case AC_JACK_PORT_FIXED:
3458 if (*fixed)
3459 return 1; /* already occupied */
3460 *fixed = nid;
3461 break;
3462 case AC_JACK_PORT_COMPLEX:
3463 if (*ext)
3464 return 1; /* already occupied */
3465 *ext = nid;
3466 break;
3467 }
3468 return 0;
3469}
3470
3471static int set_mic_route(struct hda_codec *codec,
3472 struct sigmatel_mic_route *mic,
3473 hda_nid_t pin)
3474{
3475 struct sigmatel_spec *spec = codec->spec;
3476 struct auto_pin_cfg *cfg = &spec->autocfg;
3477 int i;
3478
3479 mic->pin = pin;
3480 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3481 if (pin == cfg->input_pins[i])
3482 break;
3483 if (i <= AUTO_PIN_FRONT_MIC) {
3484 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003485 i = get_connection_index(codec, spec->mux_nids[0], pin);
3486 if (i < 0)
3487 return -1;
3488 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003489 mic->dmux_idx = -1;
3490 if (spec->dmux_nids)
3491 mic->dmux_idx = get_connection_index(codec,
3492 spec->dmux_nids[0],
3493 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003494 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003495 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003496 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3497 if (i < 0)
3498 return -1;
3499 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003500 mic->mux_idx = -1;
3501 if (spec->mux_nids)
3502 mic->mux_idx = get_connection_index(codec,
3503 spec->mux_nids[0],
3504 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003505 }
3506 return 0;
3507}
3508
3509/* return non-zero if the device is for automatic mic switch */
3510static int stac_check_auto_mic(struct hda_codec *codec)
3511{
3512 struct sigmatel_spec *spec = codec->spec;
3513 struct auto_pin_cfg *cfg = &spec->autocfg;
3514 hda_nid_t fixed, ext;
3515 int i;
3516
3517 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3518 if (cfg->input_pins[i])
3519 return 0; /* must be exclusively mics */
3520 }
3521 fixed = ext = 0;
3522 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3523 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3524 return 0;
3525 for (i = 0; i < spec->num_dmics; i++)
3526 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3527 return 0;
3528 if (!fixed || !ext)
3529 return 0;
3530 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3531 return 0; /* no unsol support */
3532 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3533 set_mic_route(codec, &spec->int_mic, fixed))
3534 return 0; /* something is wrong */
3535 return 1;
3536}
3537
Mattc7d4b2f2005-06-27 14:59:41 +02003538/* create playback/capture controls for input pins */
3539static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3540{
3541 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003542 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003543 int i, j;
Mattc7d4b2f2005-06-27 14:59:41 +02003544
3545 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003546 hda_nid_t nid = cfg->input_pins[i];
3547 int index, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003548
Takashi Iwai667067d2009-08-13 18:14:42 +02003549 if (!nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02003550 continue;
3551 index = -1;
3552 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003553 index = get_connection_index(codec, spec->mux_nids[j],
3554 nid);
3555 if (index >= 0)
3556 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003557 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003558 if (index < 0)
3559 continue;
3560
3561 err = create_elem_capture_vol(codec, nid,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003562 auto_pin_cfg_labels[i],
3563 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003564 if (err < 0)
3565 return err;
3566
Takashi Iwai314634b2006-09-21 11:56:18 +02003567 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3568 imux->items[imux->num_items].index = index;
3569 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003570 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003571 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003572
Steve Longerbeam7b043892007-05-03 20:50:03 +02003573 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003574 /*
3575 * Set the current input for the muxes.
3576 * The STAC9221 has two input muxes with identical source
3577 * NID lists. Hopefully this won't get confused.
3578 */
3579 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003580 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3581 AC_VERB_SET_CONNECT_SEL,
3582 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003583 }
3584 }
3585
Mattc7d4b2f2005-06-27 14:59:41 +02003586 return 0;
3587}
3588
Mattc7d4b2f2005-06-27 14:59:41 +02003589static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3590{
3591 struct sigmatel_spec *spec = codec->spec;
3592 int i;
3593
3594 for (i = 0; i < spec->autocfg.line_outs; i++) {
3595 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3596 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3597 }
3598}
3599
3600static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3601{
3602 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003603 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003604
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003605 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3606 hda_nid_t pin;
3607 pin = spec->autocfg.hp_pins[i];
3608 if (pin) /* connect to front */
3609 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3610 }
3611 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3612 hda_nid_t pin;
3613 pin = spec->autocfg.speaker_pins[i];
3614 if (pin) /* connect to front */
3615 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3616 }
Mattc7d4b2f2005-06-27 14:59:41 +02003617}
3618
Matt Porter3cc08dc2006-01-23 15:27:49 +01003619static 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 +02003620{
3621 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003622 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003623 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003624
Matt Porter8b657272006-10-26 17:12:59 +02003625 if ((err = snd_hda_parse_pin_def_config(codec,
3626 &spec->autocfg,
3627 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003628 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003629 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003630 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003631
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003632 /* If we have no real line-out pin and multiple hp-outs, HPs should
3633 * be set up as multi-channel outputs.
3634 */
3635 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3636 spec->autocfg.hp_outs > 1) {
3637 /* Copy hp_outs to line_outs, backup line_outs in
3638 * speaker_outs so that the following routines can handle
3639 * HP pins as primary outputs.
3640 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003641 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003642 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3643 sizeof(spec->autocfg.line_out_pins));
3644 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3645 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3646 sizeof(spec->autocfg.hp_pins));
3647 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003648 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3649 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003650 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003651 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003652 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003653 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3654 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003655 u32 caps = query_amp_caps(codec,
3656 spec->autocfg.mono_out_pin, dir);
3657 hda_nid_t conn_list[1];
3658
3659 /* get the mixer node and then the mono mux if it exists */
3660 if (snd_hda_get_connections(codec,
3661 spec->autocfg.mono_out_pin, conn_list, 1) &&
3662 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003663 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003664
3665 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003666 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003667 /* LR swap check, some stac925x have a mux that
3668 * changes the DACs output path instead of the
3669 * mono-mux path.
3670 */
3671 if (wid_type == AC_WID_AUD_SEL &&
3672 !(wcaps & AC_WCAP_LR_SWAP))
3673 spec->mono_nid = conn_list[0];
3674 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003675 if (dir) {
3676 hda_nid_t nid = spec->autocfg.mono_out_pin;
3677
3678 /* most mono outs have a least a mute/unmute switch */
3679 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3680 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3681 "Mono Playback Switch",
3682 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003683 if (err < 0)
3684 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003685 /* check for volume support for the amp */
3686 if ((caps & AC_AMPCAP_NUM_STEPS)
3687 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3688 err = stac92xx_add_control(spec,
3689 STAC_CTL_WIDGET_VOL,
3690 "Mono Playback Volume",
3691 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3692 if (err < 0)
3693 return err;
3694 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003695 }
3696
3697 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3698 AC_PINCTL_OUT_EN);
3699 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003700
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003701 if (!spec->multiout.num_dacs) {
3702 err = stac92xx_auto_fill_dac_nids(codec);
3703 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003704 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003705 err = stac92xx_auto_create_multi_out_ctls(codec,
3706 &spec->autocfg);
3707 if (err < 0)
3708 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003709 }
Mattc7d4b2f2005-06-27 14:59:41 +02003710
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003711 /* setup analog beep controls */
3712 if (spec->anabeep_nid > 0) {
3713 err = stac92xx_auto_create_beep_ctls(codec,
3714 spec->anabeep_nid);
3715 if (err < 0)
3716 return err;
3717 }
3718
3719 /* setup digital beep controls and input device */
3720#ifdef CONFIG_SND_HDA_INPUT_BEEP
3721 if (spec->digbeep_nid > 0) {
3722 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003723 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003724
3725 err = stac92xx_auto_create_beep_ctls(codec, nid);
3726 if (err < 0)
3727 return err;
3728 err = snd_hda_attach_beep_device(codec, nid);
3729 if (err < 0)
3730 return err;
Takashi Iwaifa797962009-05-19 12:50:04 +02003731 /* IDT/STAC codecs have linear beep tone parameter */
3732 codec->beep->linear_tone = 1;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003733 /* if no beep switch is available, make its own one */
3734 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3735 if (codec->beep &&
3736 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3737 err = stac92xx_beep_switch_ctl(codec);
3738 if (err < 0)
3739 return err;
3740 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003741 }
3742#endif
3743
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003744 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003745 if (err < 0)
3746 return err;
3747
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003748 /* All output parsing done, now restore the swapped hp pins */
3749 if (hp_swap) {
3750 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3751 sizeof(spec->autocfg.hp_pins));
3752 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3753 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3754 spec->autocfg.line_outs = 0;
3755 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003756
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003757 if (stac_check_auto_mic(codec)) {
3758 spec->auto_mic = 1;
3759 /* only one capture for auto-mic */
3760 spec->num_adcs = 1;
3761 spec->num_caps = 1;
3762 spec->num_muxes = 1;
3763 }
3764
Takashi Iwai6479c632009-07-28 18:20:25 +02003765 for (i = 0; i < spec->num_caps; i++) {
3766 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3767 spec->capsws[i], i);
3768 if (err < 0)
3769 return err;
3770 }
3771
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003772 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003773 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003774 return err;
3775
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003776 if (spec->mono_nid > 0) {
3777 err = stac92xx_auto_create_mono_output_ctls(codec);
3778 if (err < 0)
3779 return err;
3780 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003781 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003782 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3783 &spec->autocfg)) < 0)
3784 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003785 if (spec->num_muxes > 0) {
3786 err = stac92xx_auto_create_mux_input_ctls(codec);
3787 if (err < 0)
3788 return err;
3789 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003790 if (spec->num_smuxes > 0) {
3791 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3792 if (err < 0)
3793 return err;
3794 }
Matt Porter8b657272006-10-26 17:12:59 +02003795
Takashi Iwaie3c75962009-01-23 11:57:22 +01003796 err = stac92xx_add_input_source(spec);
3797 if (err < 0)
3798 return err;
3799
Mattc7d4b2f2005-06-27 14:59:41 +02003800 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003801 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003802 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003803
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003804 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003805 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003806 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003807 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003808
Takashi Iwai603c4012008-07-30 15:01:44 +02003809 if (spec->kctls.list)
3810 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003811
3812 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003813 if (!spec->dinput_mux)
3814 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003815 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003816 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003817 return 1;
3818}
3819
Takashi Iwai82bc9552006-03-21 11:24:42 +01003820/* add playback controls for HP output */
3821static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3822 struct auto_pin_cfg *cfg)
3823{
3824 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003825 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003826 unsigned int wid_caps;
3827
3828 if (! pin)
3829 return 0;
3830
3831 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003832 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003833 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003834
3835 return 0;
3836}
3837
Richard Fish160ea0d2006-09-06 13:58:25 +02003838/* add playback controls for LFE output */
3839static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3840 struct auto_pin_cfg *cfg)
3841{
3842 struct sigmatel_spec *spec = codec->spec;
3843 int err;
3844 hda_nid_t lfe_pin = 0x0;
3845 int i;
3846
3847 /*
3848 * search speaker outs and line outs for a mono speaker pin
3849 * with an amp. If one is found, add LFE controls
3850 * for it.
3851 */
3852 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3853 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003854 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003855 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3856 if (wcaps == AC_WCAP_OUT_AMP)
3857 /* found a mono speaker with an amp, must be lfe */
3858 lfe_pin = pin;
3859 }
3860
3861 /* if speaker_outs is 0, then speakers may be in line_outs */
3862 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3863 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3864 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003865 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01003866 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01003867 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003868 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003869 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3870 if (wcaps == AC_WCAP_OUT_AMP)
3871 /* found a mono speaker with an amp,
3872 must be lfe */
3873 lfe_pin = pin;
3874 }
3875 }
3876 }
3877
3878 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003879 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003880 if (err < 0)
3881 return err;
3882 }
3883
3884 return 0;
3885}
3886
Mattc7d4b2f2005-06-27 14:59:41 +02003887static int stac9200_parse_auto_config(struct hda_codec *codec)
3888{
3889 struct sigmatel_spec *spec = codec->spec;
3890 int err;
3891
Kailang Yangdf694da2005-12-05 19:42:22 +01003892 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003893 return err;
3894
3895 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3896 return err;
3897
Takashi Iwai82bc9552006-03-21 11:24:42 +01003898 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3899 return err;
3900
Richard Fish160ea0d2006-09-06 13:58:25 +02003901 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3902 return err;
3903
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003904 if (spec->num_muxes > 0) {
3905 err = stac92xx_auto_create_mux_input_ctls(codec);
3906 if (err < 0)
3907 return err;
3908 }
3909
Takashi Iwaie3c75962009-01-23 11:57:22 +01003910 err = stac92xx_add_input_source(spec);
3911 if (err < 0)
3912 return err;
3913
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003914 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02003915 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003916 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003917 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003918
Takashi Iwai603c4012008-07-30 15:01:44 +02003919 if (spec->kctls.list)
3920 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003921
3922 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003923 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003924
3925 return 1;
3926}
3927
Sam Revitch62fe78e2006-05-10 15:09:17 +02003928/*
3929 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3930 * funky external mute control using GPIO pins.
3931 */
3932
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003933static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003934 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003935{
3936 unsigned int gpiostate, gpiomask, gpiodir;
3937
3938 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3939 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003940 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003941
3942 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3943 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003944 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003945
3946 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3947 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003948 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003949
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003950 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003951 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3952
3953 snd_hda_codec_write(codec, codec->afg, 0,
3954 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003955 snd_hda_codec_read(codec, codec->afg, 0,
3956 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003957
3958 msleep(1);
3959
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003960 snd_hda_codec_read(codec, codec->afg, 0,
3961 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003962}
3963
Takashi Iwai8c8145b2009-06-22 17:00:38 +02003964#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +02003965static void stac92xx_free_jack_priv(struct snd_jack *jack)
3966{
3967 struct sigmatel_jack *jacks = jack->private_data;
3968 jacks->nid = 0;
3969 jacks->jack = NULL;
3970}
3971#endif
3972
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003973static int stac92xx_add_jack(struct hda_codec *codec,
3974 hda_nid_t nid, int type)
3975{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02003976#ifdef CONFIG_SND_HDA_INPUT_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003977 struct sigmatel_spec *spec = codec->spec;
3978 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01003979 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003980 int connectivity = get_defcfg_connect(def_conf);
3981 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02003982 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003983
3984 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3985 return 0;
3986
3987 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3988 jack = snd_array_new(&spec->jacks);
3989 if (!jack)
3990 return -ENOMEM;
3991 jack->nid = nid;
3992 jack->type = type;
3993
Takashi Iwai86de7412009-07-22 16:02:46 +02003994 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003995 snd_hda_get_jack_type(def_conf),
3996 snd_hda_get_jack_connectivity(def_conf),
3997 snd_hda_get_jack_location(def_conf));
3998
Takashi Iwai95c09092009-04-14 16:15:29 +02003999 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4000 if (err < 0) {
4001 jack->nid = 0;
4002 return err;
4003 }
4004 jack->jack->private_data = jack;
4005 jack->jack->private_free = stac92xx_free_jack_priv;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004006#endif
Takashi Iwai95c09092009-04-14 16:15:29 +02004007 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004008}
4009
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004010static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4011 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004012{
4013 struct sigmatel_event *event;
4014
4015 snd_array_init(&spec->events, sizeof(*event), 32);
4016 event = snd_array_new(&spec->events);
4017 if (!event)
4018 return -ENOMEM;
4019 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004020 event->type = type;
4021 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004022 event->data = data;
4023
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004024 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004025}
4026
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004027static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004028 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004029{
4030 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004031 struct sigmatel_event *event = spec->events.list;
4032 int i;
4033
4034 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004035 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004036 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004037 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004038 return NULL;
4039}
4040
4041static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4042 unsigned char tag)
4043{
4044 struct sigmatel_spec *spec = codec->spec;
4045 struct sigmatel_event *event = spec->events.list;
4046 int i;
4047
4048 for (i = 0; i < spec->events.used; i++, event++) {
4049 if (event->tag == tag)
4050 return event;
4051 }
4052 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004053}
4054
Takashi Iwai62558ce2009-07-29 14:23:09 +02004055/* check if given nid is a valid pin and no other events are assigned
4056 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4057 * Otherwise, returns zero.
4058 */
4059static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4060 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004061{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004062 struct sigmatel_event *event;
4063 int tag;
4064
4065 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004066 return 0;
4067 event = stac_get_event(codec, nid);
4068 if (event) {
4069 if (event->type != type)
4070 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004071 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004072 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004073 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004074 if (tag < 0)
4075 return 0;
4076 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004077 snd_hda_codec_write_cache(codec, nid, 0,
4078 AC_VERB_SET_UNSOLICITED_ENABLE,
4079 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004080 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004081}
4082
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004083static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4084{
4085 int i;
4086 for (i = 0; i < cfg->hp_outs; i++)
4087 if (cfg->hp_pins[i] == nid)
4088 return 1; /* nid is a HP-Out */
4089
4090 return 0; /* nid is not a HP-Out */
4091};
4092
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004093static void stac92xx_power_down(struct hda_codec *codec)
4094{
4095 struct sigmatel_spec *spec = codec->spec;
4096
4097 /* power down inactive DACs */
4098 hda_nid_t *dac;
4099 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004100 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004101 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004102 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4103}
4104
Takashi Iwaif73d3582008-11-25 08:21:51 +01004105static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4106 int enable);
4107
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004108/* override some hints from the hwdep entry */
4109static void stac_store_hints(struct hda_codec *codec)
4110{
4111 struct sigmatel_spec *spec = codec->spec;
4112 const char *p;
4113 int val;
4114
4115 val = snd_hda_get_bool_hint(codec, "hp_detect");
4116 if (val >= 0)
4117 spec->hp_detect = val;
4118 p = snd_hda_get_hint(codec, "gpio_mask");
4119 if (p) {
4120 spec->gpio_mask = simple_strtoul(p, NULL, 0);
4121 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4122 spec->gpio_mask;
4123 }
4124 p = snd_hda_get_hint(codec, "gpio_dir");
4125 if (p)
4126 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4127 p = snd_hda_get_hint(codec, "gpio_data");
4128 if (p)
4129 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4130 p = snd_hda_get_hint(codec, "eapd_mask");
4131 if (p)
4132 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4133 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4134 if (val >= 0)
4135 spec->eapd_switch = val;
4136}
4137
Mattc7d4b2f2005-06-27 14:59:41 +02004138static int stac92xx_init(struct hda_codec *codec)
4139{
4140 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004141 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004142 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004143 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004144
Mattc7d4b2f2005-06-27 14:59:41 +02004145 snd_hda_sequence_write(codec, spec->init);
4146
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004147 /* power down adcs initially */
4148 if (spec->powerdown_adcs)
4149 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004150 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004151 spec->adc_nids[i], 0,
4152 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004153
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004154 /* override some hints */
4155 stac_store_hints(codec);
4156
Takashi Iwaif73d3582008-11-25 08:21:51 +01004157 /* set up GPIO */
4158 gpio = spec->gpio_data;
4159 /* turn on EAPD statically when spec->eapd_switch isn't set.
4160 * otherwise, unsol event will turn it on/off dynamically
4161 */
4162 if (!spec->eapd_switch)
4163 gpio |= spec->eapd_mask;
4164 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4165
Takashi Iwai82bc9552006-03-21 11:24:42 +01004166 /* set up pins */
4167 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004168 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004169 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004170 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004171 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004172 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004173 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4174 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004175 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004176 for (i = 0; i < cfg->line_outs; i++) {
4177 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004178 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4179 }
4180 }
4181
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004182 /* force to enable the first line-out; the others are set up
4183 * in unsol_event
4184 */
4185 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004186 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004187 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004188 if (cfg->hp_pins[0])
4189 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4190 else if (cfg->line_out_pins[0])
4191 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004192 } else {
4193 stac92xx_auto_init_multi_out(codec);
4194 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004195 for (i = 0; i < cfg->hp_outs; i++)
4196 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004197 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004198 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004199 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004200 if (spec->dmux_nids)
4201 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004202 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004203 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4204 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4205 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004206 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01004207 hda_nid_t nid = cfg->input_pins[i];
4208 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004209 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004210 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4211 /* for mic pins, force to initialize */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02004212 pinctl = stac92xx_get_default_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004213 pinctl |= AC_PINCTL_IN_EN;
4214 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004215 } else {
4216 pinctl = snd_hda_codec_read(codec, nid, 0,
4217 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4218 /* if PINCTL already set then skip */
Takashi Iwai5dd17cb2009-05-07 16:22:53 +02004219 /* Also, if both INPUT and OUTPUT are set,
4220 * it must be a BIOS bug; need to override, too
4221 */
4222 if (!(pinctl & AC_PINCTL_IN_EN) ||
4223 (pinctl & AC_PINCTL_OUT_EN)) {
4224 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004225 pinctl |= AC_PINCTL_IN_EN;
4226 stac92xx_auto_set_pinctl(codec, nid,
4227 pinctl);
4228 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004229 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004230 conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004231 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004232 if (enable_pin_detect(codec, nid,
4233 STAC_INSERT_EVENT))
4234 stac_issue_unsol_event(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004235 }
Takashi Iwaic960a032006-03-23 17:06:28 +01004236 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004237 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004238 for (i = 0; i < spec->num_dmics; i++)
4239 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4240 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004241 if (cfg->dig_out_pins[0])
4242 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004243 AC_PINCTL_OUT_EN);
4244 if (cfg->dig_in_pin)
4245 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4246 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004247 for (i = 0; i < spec->num_pwrs; i++) {
4248 hda_nid_t nid = spec->pwr_nids[i];
4249 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004250
Takashi Iwaieb632122008-12-19 16:39:48 +01004251 /* power on when no jack detection is available */
4252 if (!spec->hp_detect) {
4253 stac_toggle_power_map(codec, nid, 1);
4254 continue;
4255 }
4256
4257 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004258 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004259
Takashi Iwaif73d3582008-11-25 08:21:51 +01004260 pinctl = snd_hda_codec_read(codec, nid, 0,
4261 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4262 /* outputs are only ports capable of power management
4263 * any attempts on powering down a input port cause the
4264 * referenced VREF to act quirky.
4265 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004266 if (pinctl & AC_PINCTL_IN_EN) {
4267 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004268 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004269 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004270 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004271 def_conf = get_defcfg_connect(def_conf);
4272 /* skip any ports that don't have jacks since presence
4273 * detection is useless */
4274 if (def_conf != AC_JACK_PORT_COMPLEX) {
4275 if (def_conf != AC_JACK_PORT_NONE)
4276 stac_toggle_power_map(codec, nid, 1);
4277 continue;
4278 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004279 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4280 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004281 }
4282 if (spec->dac_list)
4283 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004284 return 0;
4285}
4286
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004287static void stac92xx_free_jacks(struct hda_codec *codec)
4288{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004289#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01004290 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004291 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01004292 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004293 struct sigmatel_jack *jacks = spec->jacks.list;
4294 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +02004295 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4296 if (jacks->jack)
4297 snd_device_free(codec->bus->card, jacks->jack);
4298 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004299 }
4300 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004301#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004302}
4303
Takashi Iwai603c4012008-07-30 15:01:44 +02004304static void stac92xx_free_kctls(struct hda_codec *codec)
4305{
4306 struct sigmatel_spec *spec = codec->spec;
4307
4308 if (spec->kctls.list) {
4309 struct snd_kcontrol_new *kctl = spec->kctls.list;
4310 int i;
4311 for (i = 0; i < spec->kctls.used; i++)
4312 kfree(kctl[i].name);
4313 }
4314 snd_array_free(&spec->kctls);
4315}
4316
Matt2f2f4252005-04-13 14:45:30 +02004317static void stac92xx_free(struct hda_codec *codec)
4318{
Mattc7d4b2f2005-06-27 14:59:41 +02004319 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004320
4321 if (! spec)
4322 return;
4323
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004324 stac92xx_free_jacks(codec);
4325 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004326
Mattc7d4b2f2005-06-27 14:59:41 +02004327 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004328 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004329}
4330
Matt4e550962005-07-04 17:51:39 +02004331static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4332 unsigned int flag)
4333{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004334 unsigned int old_ctl, pin_ctl;
4335
4336 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004337 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004338
Takashi Iwaif9acba42007-05-29 18:01:06 +02004339 if (pin_ctl & AC_PINCTL_IN_EN) {
4340 /*
4341 * we need to check the current set-up direction of
4342 * shared input pins since they can be switched via
4343 * "xxx as Output" mixer switch
4344 */
4345 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004346 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004347 return;
4348 }
4349
Takashi Iwai8ce84192009-01-22 16:59:20 +01004350 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004351 /* if setting pin direction bits, clear the current
4352 direction bits first */
4353 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4354 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4355
Takashi Iwai8ce84192009-01-22 16:59:20 +01004356 pin_ctl |= flag;
4357 if (old_ctl != pin_ctl)
4358 snd_hda_codec_write_cache(codec, nid, 0,
4359 AC_VERB_SET_PIN_WIDGET_CONTROL,
4360 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004361}
4362
4363static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4364 unsigned int flag)
4365{
4366 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4367 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004368 if (pin_ctl & flag)
4369 snd_hda_codec_write_cache(codec, nid, 0,
4370 AC_VERB_SET_PIN_WIDGET_CONTROL,
4371 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004372}
4373
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004374static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004375{
4376 if (!nid)
4377 return 0;
4378 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004379 & (1 << 31))
4380 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004381 return 0;
4382}
4383
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004384static void stac92xx_line_out_detect(struct hda_codec *codec,
4385 int presence)
4386{
4387 struct sigmatel_spec *spec = codec->spec;
4388 struct auto_pin_cfg *cfg = &spec->autocfg;
4389 int i;
4390
4391 for (i = 0; i < cfg->line_outs; i++) {
4392 if (presence)
4393 break;
4394 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4395 if (presence) {
4396 unsigned int pinctl;
4397 pinctl = snd_hda_codec_read(codec,
4398 cfg->line_out_pins[i], 0,
4399 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4400 if (pinctl & AC_PINCTL_IN_EN)
4401 presence = 0; /* mic- or line-input */
4402 }
4403 }
4404
4405 if (presence) {
4406 /* disable speakers */
4407 for (i = 0; i < cfg->speaker_outs; i++)
4408 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4409 AC_PINCTL_OUT_EN);
4410 if (spec->eapd_mask && spec->eapd_switch)
4411 stac_gpio_set(codec, spec->gpio_mask,
4412 spec->gpio_dir, spec->gpio_data &
4413 ~spec->eapd_mask);
4414 } else {
4415 /* enable speakers */
4416 for (i = 0; i < cfg->speaker_outs; i++)
4417 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4418 AC_PINCTL_OUT_EN);
4419 if (spec->eapd_mask && spec->eapd_switch)
4420 stac_gpio_set(codec, spec->gpio_mask,
4421 spec->gpio_dir, spec->gpio_data |
4422 spec->eapd_mask);
4423 }
4424}
4425
Takashi Iwaid7a89432008-11-12 09:48:04 +01004426/* return non-zero if the hp-pin of the given array index isn't
4427 * a jack-detection target
4428 */
4429static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4430{
4431 struct auto_pin_cfg *cfg = &spec->autocfg;
4432
4433 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004434 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004435 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004436 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004437 return 1;
4438 /* ignore if the pin is set as line-out */
4439 if (cfg->hp_pins[i] == spec->hp_switch)
4440 return 1;
4441 return 0;
4442}
4443
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004444static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004445{
4446 struct sigmatel_spec *spec = codec->spec;
4447 struct auto_pin_cfg *cfg = &spec->autocfg;
4448 int i, presence;
4449
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004450 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004451 if (spec->gpio_mute)
4452 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4453 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4454
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004455 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004456 if (presence)
4457 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004458 if (no_hp_sensing(spec, i))
4459 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004460 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4461 if (presence) {
4462 unsigned int pinctl;
4463 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4464 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4465 if (pinctl & AC_PINCTL_IN_EN)
4466 presence = 0; /* mic- or line-input */
4467 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004468 }
Matt4e550962005-07-04 17:51:39 +02004469
4470 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004471 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004472 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004473 stac92xx_reset_pinctl(codec, spec->hp_switch,
4474 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004475 for (i = 0; i < cfg->line_outs; i++)
4476 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4477 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004478 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004479 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004480 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004481 stac92xx_set_pinctl(codec, spec->hp_switch,
4482 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004483 for (i = 0; i < cfg->line_outs; i++)
4484 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4485 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004486 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004487 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004488 /* toggle hp outs */
4489 for (i = 0; i < cfg->hp_outs; i++) {
4490 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4491 if (no_hp_sensing(spec, i))
4492 continue;
4493 if (presence)
4494 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004495#if 0 /* FIXME */
4496/* Resetting the pinctl like below may lead to (a sort of) regressions
4497 * on some devices since they use the HP pin actually for line/speaker
4498 * outs although the default pin config shows a different pin (that is
4499 * wrong and useless).
4500 *
4501 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4502 * But, disabling the code below just works around it, and I'm too tired of
4503 * bug reports with such devices...
4504 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004505 else
4506 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004507#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004508 }
Matt4e550962005-07-04 17:51:39 +02004509}
4510
Takashi Iwaif73d3582008-11-25 08:21:51 +01004511static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4512 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004513{
4514 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004515 unsigned int idx, val;
4516
4517 for (idx = 0; idx < spec->num_pwrs; idx++) {
4518 if (spec->pwr_nids[idx] == nid)
4519 break;
4520 }
4521 if (idx >= spec->num_pwrs)
4522 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004523
4524 /* several codecs have two power down bits */
4525 if (spec->pwr_mapping)
4526 idx = spec->pwr_mapping[idx];
4527 else
4528 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004529
Takashi Iwaif73d3582008-11-25 08:21:51 +01004530 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4531 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004532 val &= ~idx;
4533 else
4534 val |= idx;
4535
4536 /* power down unused output ports */
4537 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004538}
4539
Takashi Iwaif73d3582008-11-25 08:21:51 +01004540static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4541{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004542 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004543}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004544
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004545static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4546{
4547 struct sigmatel_spec *spec = codec->spec;
4548 struct sigmatel_jack *jacks = spec->jacks.list;
4549
4550 if (jacks) {
4551 int i;
4552 for (i = 0; i < spec->jacks.used; i++) {
4553 if (jacks->nid == nid) {
4554 unsigned int pin_ctl =
4555 snd_hda_codec_read(codec, nid,
4556 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4557 0x00);
4558 int type = jacks->type;
4559 if (type == (SND_JACK_LINEOUT
4560 | SND_JACK_HEADPHONE))
4561 type = (pin_ctl & AC_PINCTL_HP_EN)
4562 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4563 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004564 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004565 ? type : 0);
4566 }
4567 jacks++;
4568 }
4569 }
4570}
Matt2f2f4252005-04-13 14:45:30 +02004571
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004572static void stac92xx_mic_detect(struct hda_codec *codec)
4573{
4574 struct sigmatel_spec *spec = codec->spec;
4575 struct sigmatel_mic_route *mic;
4576
4577 if (get_pin_presence(codec, spec->ext_mic.pin))
4578 mic = &spec->ext_mic;
4579 else
4580 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004581 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004582 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4583 AC_VERB_SET_CONNECT_SEL,
4584 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004585 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004586 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4587 AC_VERB_SET_CONNECT_SEL,
4588 mic->mux_idx);
4589}
4590
Takashi Iwai62558ce2009-07-29 14:23:09 +02004591static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004592{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004593 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004594 if (!event)
4595 return;
4596 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4597}
4598
Takashi Iwai314634b2006-09-21 11:56:18 +02004599static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4600{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004601 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004602 struct sigmatel_event *event;
4603 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004604
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004605 tag = (res >> 26) & 0x7f;
4606 event = stac_get_event_from_tag(codec, tag);
4607 if (!event)
4608 return;
4609
4610 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004611 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004612 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004613 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004614 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004615 case STAC_MIC_EVENT:
4616 stac92xx_mic_detect(codec);
4617 break;
4618 }
4619
4620 switch (event->type) {
4621 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004622 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004623 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004624 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004625 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004626 if (spec->num_pwrs > 0)
4627 stac92xx_pin_sense(codec, event->nid);
4628 stac92xx_report_jack(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004629
4630 switch (codec->subsystem_id) {
4631 case 0x103c308f:
4632 if (event->nid == 0xb) {
4633 int pin = AC_PINCTL_IN_EN;
4634
4635 if (get_pin_presence(codec, 0xa)
4636 && get_pin_presence(codec, 0xb))
4637 pin |= AC_PINCTL_VREF_80;
4638 if (!get_pin_presence(codec, 0xb))
4639 pin |= AC_PINCTL_VREF_80;
4640
4641 /* toggle VREF state based on mic + hp pin
4642 * status
4643 */
4644 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4645 }
4646 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004647 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004648 case STAC_VREF_EVENT:
4649 data = snd_hda_codec_read(codec, codec->afg, 0,
4650 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004651 /* toggle VREF state based on GPIOx status */
4652 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004653 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004654 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004655 }
4656}
4657
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004658#ifdef CONFIG_PROC_FS
4659static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4660 struct hda_codec *codec, hda_nid_t nid)
4661{
4662 if (nid == codec->afg)
4663 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4664 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4665}
4666
4667static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4668 struct hda_codec *codec,
4669 unsigned int verb)
4670{
4671 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4672 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4673}
4674
4675/* stac92hd71bxx, stac92hd73xx */
4676static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4677 struct hda_codec *codec, hda_nid_t nid)
4678{
4679 stac92hd_proc_hook(buffer, codec, nid);
4680 if (nid == codec->afg)
4681 analog_loop_proc_hook(buffer, codec, 0xfa0);
4682}
4683
4684static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4685 struct hda_codec *codec, hda_nid_t nid)
4686{
4687 if (nid == codec->afg)
4688 analog_loop_proc_hook(buffer, codec, 0xfe0);
4689}
4690
4691static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4692 struct hda_codec *codec, hda_nid_t nid)
4693{
4694 if (nid == codec->afg)
4695 analog_loop_proc_hook(buffer, codec, 0xfeb);
4696}
4697#else
4698#define stac92hd_proc_hook NULL
4699#define stac92hd7x_proc_hook NULL
4700#define stac9205_proc_hook NULL
4701#define stac927x_proc_hook NULL
4702#endif
4703
Takashi Iwaicb53c622007-08-10 17:21:45 +02004704#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004705static int stac92xx_resume(struct hda_codec *codec)
4706{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004707 struct sigmatel_spec *spec = codec->spec;
4708
Takashi Iwai2c885872008-11-18 09:36:55 +01004709 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004710 snd_hda_codec_resume_amp(codec);
4711 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004712 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004713 if (spec->hp_detect) {
4714 if (spec->autocfg.hp_pins[0])
4715 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4716 else if (spec->autocfg.line_out_pins[0])
4717 stac_issue_unsol_event(codec,
4718 spec->autocfg.line_out_pins[0]);
4719 }
Mattff6fdc32005-06-27 15:06:52 +02004720 return 0;
4721}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004722
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004723/*
James Gardiner514bf542009-05-03 04:00:44 -04004724 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004725 * check for mute state only on Speakers (nid = 0x10)
4726 *
4727 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4728 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004729 *
4730 * Changed name to reflect that it now works for any designated
4731 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004732 */
4733
4734#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004735static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004736 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004737{
4738 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004739
4740 if (nid == 0x10) {
4741 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004742 HDA_AMP_MUTE)
Takashi Iwai86d190e2009-05-26 15:18:58 +02004743 spec->gpio_data &= ~spec->gpio_led; /* orange */
Takashi Iwaiba84bfc2009-05-30 08:59:03 +02004744 else
4745 spec->gpio_data |= spec->gpio_led; /* white */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004746
4747 stac_gpio_set(codec, spec->gpio_mask,
4748 spec->gpio_dir,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004749 spec->gpio_data);
4750 }
4751
4752 return 0;
4753}
4754#endif
4755
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004756static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4757{
4758 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004759 int i;
4760 hda_nid_t nid;
4761
4762 /* reset each pin before powering down DAC/ADC to avoid click noise */
4763 nid = codec->start_nid;
4764 for (i = 0; i < codec->num_nodes; i++, nid++) {
4765 unsigned int wcaps = get_wcaps(codec, nid);
Takashi Iwaia22d5432009-07-27 12:54:26 +02004766 unsigned int wid_type = get_wcaps_type(wcaps);
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004767 if (wid_type == AC_WID_PIN)
4768 snd_hda_codec_read(codec, nid, 0,
4769 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4770 }
4771
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004772 if (spec->eapd_mask)
4773 stac_gpio_set(codec, spec->gpio_mask,
4774 spec->gpio_dir, spec->gpio_data &
4775 ~spec->eapd_mask);
4776 return 0;
4777}
Mattff6fdc32005-06-27 15:06:52 +02004778#endif
4779
Matt2f2f4252005-04-13 14:45:30 +02004780static struct hda_codec_ops stac92xx_patch_ops = {
4781 .build_controls = stac92xx_build_controls,
4782 .build_pcms = stac92xx_build_pcms,
4783 .init = stac92xx_init,
4784 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004785 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004786#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004787 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004788 .resume = stac92xx_resume,
4789#endif
Matt2f2f4252005-04-13 14:45:30 +02004790};
4791
4792static int patch_stac9200(struct hda_codec *codec)
4793{
4794 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004795 int err;
Matt2f2f4252005-04-13 14:45:30 +02004796
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004797 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004798 if (spec == NULL)
4799 return -ENOMEM;
4800
4801 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004802 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004803 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004804 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4805 stac9200_models,
4806 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01004807 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004808 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4809 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004810 else
4811 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004812 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02004813
4814 spec->multiout.max_channels = 2;
4815 spec->multiout.num_dacs = 1;
4816 spec->multiout.dac_nids = stac9200_dac_nids;
4817 spec->adc_nids = stac9200_adc_nids;
4818 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004819 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004820 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004821 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004822 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004823
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02004824 if (spec->board_config == STAC_9200_M4 ||
4825 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01004826 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004827 spec->init = stac9200_eapd_init;
4828 else
4829 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004830 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004831
Takashi Iwai117f2572008-03-18 09:53:23 +01004832 if (spec->board_config == STAC_9200_PANASONIC) {
4833 spec->gpio_mask = spec->gpio_dir = 0x09;
4834 spec->gpio_data = 0x00;
4835 }
4836
Mattc7d4b2f2005-06-27 14:59:41 +02004837 err = stac9200_parse_auto_config(codec);
4838 if (err < 0) {
4839 stac92xx_free(codec);
4840 return err;
4841 }
Matt2f2f4252005-04-13 14:45:30 +02004842
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01004843 /* CF-74 has no headphone detection, and the driver should *NOT*
4844 * do detection and HP/speaker toggle because the hardware does it.
4845 */
4846 if (spec->board_config == STAC_9200_PANASONIC)
4847 spec->hp_detect = 0;
4848
Matt2f2f4252005-04-13 14:45:30 +02004849 codec->patch_ops = stac92xx_patch_ops;
4850
4851 return 0;
4852}
4853
Tobin Davis8e21c342007-01-08 11:04:17 +01004854static int patch_stac925x(struct hda_codec *codec)
4855{
4856 struct sigmatel_spec *spec;
4857 int err;
4858
4859 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4860 if (spec == NULL)
4861 return -ENOMEM;
4862
4863 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004864 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004865 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004866
4867 /* Check first for codec ID */
4868 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
4869 STAC_925x_MODELS,
4870 stac925x_models,
4871 stac925x_codec_id_cfg_tbl);
4872
4873 /* Now checks for PCI ID, if codec ID is not found */
4874 if (spec->board_config < 0)
4875 spec->board_config = snd_hda_check_board_config(codec,
4876 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01004877 stac925x_models,
4878 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004879 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004880 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004881 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4882 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004883 else
4884 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004885 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01004886
4887 spec->multiout.max_channels = 2;
4888 spec->multiout.num_dacs = 1;
4889 spec->multiout.dac_nids = stac925x_dac_nids;
4890 spec->adc_nids = stac925x_adc_nids;
4891 spec->mux_nids = stac925x_mux_nids;
4892 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004893 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004894 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004895 switch (codec->vendor_id) {
4896 case 0x83847632: /* STAC9202 */
4897 case 0x83847633: /* STAC9202D */
4898 case 0x83847636: /* STAC9251 */
4899 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004900 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004901 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004902 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4903 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004904 break;
4905 default:
4906 spec->num_dmics = 0;
4907 break;
4908 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004909
4910 spec->init = stac925x_core_init;
4911 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02004912 spec->num_caps = 1;
4913 spec->capvols = stac925x_capvols;
4914 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01004915
4916 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004917 if (!err) {
4918 if (spec->board_config < 0) {
4919 printk(KERN_WARNING "hda_codec: No auto-config is "
4920 "available, default to model=ref\n");
4921 spec->board_config = STAC_925x_REF;
4922 goto again;
4923 }
4924 err = -EINVAL;
4925 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004926 if (err < 0) {
4927 stac92xx_free(codec);
4928 return err;
4929 }
4930
4931 codec->patch_ops = stac92xx_patch_ops;
4932
4933 return 0;
4934}
4935
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004936static int patch_stac92hd73xx(struct hda_codec *codec)
4937{
4938 struct sigmatel_spec *spec;
4939 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4940 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004941 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004942
4943 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4944 if (spec == NULL)
4945 return -ENOMEM;
4946
4947 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004948 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004949 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4950 spec->pin_nids = stac92hd73xx_pin_nids;
4951 spec->board_config = snd_hda_check_board_config(codec,
4952 STAC_92HD73XX_MODELS,
4953 stac92hd73xx_models,
4954 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02004955 /* check codec subsystem id if not found */
4956 if (spec->board_config < 0)
4957 spec->board_config =
4958 snd_hda_check_board_codec_sid_config(codec,
4959 STAC_92HD73XX_MODELS, stac92hd73xx_models,
4960 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004961again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004962 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004963 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4964 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004965 else
4966 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004967 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004968
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004969 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004970 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4971
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004972 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004973 printk(KERN_WARNING "hda_codec: Could not determine "
4974 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004975 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004976 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02004977 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004978 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004979 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004980 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004981 break;
4982 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004983 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004984 break;
4985 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004986 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
4987 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004988 }
4989 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004990
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004991 spec->aloopback_mask = 0x01;
4992 spec->aloopback_shift = 8;
4993
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004994 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004995 spec->mux_nids = stac92hd73xx_mux_nids;
4996 spec->adc_nids = stac92hd73xx_adc_nids;
4997 spec->dmic_nids = stac92hd73xx_dmic_nids;
4998 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004999 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005000
5001 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5002 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005003 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005004
Takashi Iwai6479c632009-07-28 18:20:25 +02005005 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5006 spec->capvols = stac92hd73xx_capvols;
5007 spec->capsws = stac92hd73xx_capsws;
5008
Matthew Ranostaya7662642008-02-21 07:51:14 +01005009 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005010 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005011 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005012 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005013 case STAC_DELL_M6_AMIC:
5014 case STAC_DELL_M6_DMIC:
5015 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005016 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005017 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005018
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005019 switch (spec->board_config) {
5020 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005021 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005022 spec->num_dmics = 0;
5023 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005024 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005025 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005026 spec->num_dmics = 1;
5027 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005028 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005029 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5030 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005031 spec->num_dmics = 1;
5032 break;
5033 }
5034 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005035 case STAC_ALIENWARE_M17X:
5036 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5037 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5038 spec->eapd_switch = 0;
5039 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005040 default:
5041 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005042 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005043 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005044 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005045 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005046 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005047 /* GPIO0 High = Enable EAPD */
5048 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5049 spec->gpio_data = 0x01;
5050 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005051
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005052 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5053 spec->pwr_nids = stac92hd73xx_pwr_nids;
5054
Matthew Ranostayd9737752008-09-07 12:03:41 +02005055 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005056
5057 if (!err) {
5058 if (spec->board_config < 0) {
5059 printk(KERN_WARNING "hda_codec: No auto-config is "
5060 "available, default to model=ref\n");
5061 spec->board_config = STAC_92HD73XX_REF;
5062 goto again;
5063 }
5064 err = -EINVAL;
5065 }
5066
5067 if (err < 0) {
5068 stac92xx_free(codec);
5069 return err;
5070 }
5071
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005072 if (spec->board_config == STAC_92HD73XX_NO_JD)
5073 spec->hp_detect = 0;
5074
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005075 codec->patch_ops = stac92xx_patch_ops;
5076
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005077 codec->proc_widget_hook = stac92hd7x_proc_hook;
5078
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005079 return 0;
5080}
5081
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005082static int patch_stac92hd83xxx(struct hda_codec *codec)
5083{
5084 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005085 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005086 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005087 int num_dacs;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005088 hda_nid_t nid;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005089
5090 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5091 if (spec == NULL)
5092 return -ENOMEM;
5093
5094 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005095 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005096 spec->digbeep_nid = 0x21;
Takashi Iwai667067d2009-08-13 18:14:42 +02005097 spec->mux_nids = stac92hd83xxx_mux_nids;
5098 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005099 spec->adc_nids = stac92hd83xxx_adc_nids;
Takashi Iwai7570ef12009-08-15 11:57:53 +02005100 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005101 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5102 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5103 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005104 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005105
5106 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005107 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005108 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005109 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5110 spec->capvols = stac92hd83xxx_capvols;
5111 spec->capsws = stac92hd83xxx_capsws;
5112
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005113 spec->board_config = snd_hda_check_board_config(codec,
5114 STAC_92HD83XXX_MODELS,
5115 stac92hd83xxx_models,
5116 stac92hd83xxx_cfg_tbl);
5117again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005118 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005119 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5120 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005121 else
5122 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005123 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005124
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005125 switch (codec->vendor_id) {
5126 case 0x111d7604:
5127 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005128 case 0x111d76d5:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005129 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5130 break;
5131 spec->num_pwrs = 0;
5132 break;
5133 }
5134
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005135 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5136 if (!err) {
5137 if (spec->board_config < 0) {
5138 printk(KERN_WARNING "hda_codec: No auto-config is "
5139 "available, default to model=ref\n");
5140 spec->board_config = STAC_92HD83XXX_REF;
5141 goto again;
5142 }
5143 err = -EINVAL;
5144 }
5145
5146 if (err < 0) {
5147 stac92xx_free(codec);
5148 return err;
5149 }
5150
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005151 switch (spec->board_config) {
5152 case STAC_DELL_S14:
5153 nid = 0xf;
5154 break;
5155 default:
5156 nid = 0xe;
5157 break;
5158 }
5159
5160 num_dacs = snd_hda_get_connections(codec, nid,
5161 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02005162 if (num_dacs < 0)
5163 num_dacs = STAC92HD83_DAC_COUNT;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005164
5165 /* set port X to select the last DAC
5166 */
5167 snd_hda_codec_write_cache(codec, nid, 0,
5168 AC_VERB_SET_CONNECT_SEL, num_dacs);
5169
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005170 codec->patch_ops = stac92xx_patch_ops;
5171
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005172 codec->proc_widget_hook = stac92hd_proc_hook;
5173
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005174 return 0;
5175}
5176
Takashi Iwai330ee992009-02-20 14:33:36 +01005177/* get the pin connection (fixed, none, etc) */
5178static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5179{
5180 struct sigmatel_spec *spec = codec->spec;
5181 unsigned int cfg;
5182
5183 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5184 return get_defcfg_connect(cfg);
5185}
5186
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005187static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5188 hda_nid_t *nids, int num_nids)
5189{
5190 struct sigmatel_spec *spec = codec->spec;
5191 int idx, num;
5192 unsigned int def_conf;
5193
5194 for (num = 0; num < num_nids; num++) {
5195 for (idx = 0; idx < spec->num_pins; idx++)
5196 if (spec->pin_nids[idx] == nids[num])
5197 break;
5198 if (idx >= spec->num_pins)
5199 break;
Takashi Iwai330ee992009-02-20 14:33:36 +01005200 def_conf = stac_get_defcfg_connect(codec, idx);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005201 if (def_conf == AC_JACK_PORT_NONE)
5202 break;
5203 }
5204 return num;
5205}
5206
5207static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5208 hda_nid_t dig0pin)
5209{
5210 struct sigmatel_spec *spec = codec->spec;
5211 int idx;
5212
5213 for (idx = 0; idx < spec->num_pins; idx++)
5214 if (spec->pin_nids[idx] == dig0pin)
5215 break;
5216 if ((idx + 2) >= spec->num_pins)
5217 return 0;
5218
5219 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005220 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005221 return 2;
5222
5223 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005224 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005225 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005226 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005227 return 1;
5228 else
5229 return 0;
5230}
5231
Matthew Ranostaye035b842007-11-06 11:53:55 +01005232static int patch_stac92hd71bxx(struct hda_codec *codec)
5233{
5234 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005235 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005236 int err = 0;
5237
5238 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5239 if (spec == NULL)
5240 return -ENOMEM;
5241
5242 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005243 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005244 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5245 switch (codec->vendor_id) {
5246 case 0x111d76b6:
5247 case 0x111d76b7:
5248 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5249 break;
5250 case 0x111d7603:
5251 case 0x111d7608:
5252 /* On 92HD75Bx 0x27 isn't a pin nid */
5253 spec->num_pins--;
5254 /* fallthrough */
5255 default:
5256 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5257 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005258 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005259 spec->board_config = snd_hda_check_board_config(codec,
5260 STAC_92HD71BXX_MODELS,
5261 stac92hd71bxx_models,
5262 stac92hd71bxx_cfg_tbl);
5263again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005264 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005265 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5266 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005267 else
5268 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005269 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005270
Takashi Iwaifc64b262009-09-14 15:33:01 +02005271 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005272 /* GPIO0 = EAPD */
5273 spec->gpio_mask = 0x01;
5274 spec->gpio_dir = 0x01;
5275 spec->gpio_data = 0x01;
5276 }
5277
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005278 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5279 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5280
Takashi Iwai6479c632009-07-28 18:20:25 +02005281 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5282 spec->capvols = stac92hd71bxx_capvols;
5283 spec->capsws = stac92hd71bxx_capsws;
5284
Matthew Ranostay541eee82007-12-14 12:08:04 +01005285 switch (codec->vendor_id) {
5286 case 0x111d76b6: /* 4 Port without Analog Mixer */
5287 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005288 unmute_init++;
5289 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005290 case 0x111d76b4: /* 6 Port without Analog Mixer */
5291 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005292 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005293 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005294 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5295 stac92hd71bxx_dmic_nids,
5296 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005297 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005298 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005299 switch (spec->board_config) {
5300 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005301 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005302 err = stac_add_event(spec, codec->afg,
5303 STAC_VREF_EVENT, 0x02);
5304 if (err < 0)
5305 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005306 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005307 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5308 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005309 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005310 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005311 spec->gpio_mask |= 0x02;
5312 break;
5313 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005314 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005315 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005316 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005317
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005318 /* no output amps */
5319 spec->num_pwrs = 0;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005320 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005321 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005322 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005323 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5324 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005325 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5326 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5327 stac92hd71bxx_dmic_nids,
5328 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005329 break;
5330 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005331 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005332 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005333
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005334 /* no output amps */
5335 spec->num_pwrs = 0;
5336 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005337 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005338 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005339 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005340 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5341 stac92hd71bxx_dmic_nids,
5342 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005343 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005344 }
5345
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005346 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5347 snd_hda_sequence_write_cache(codec, unmute_init);
5348
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005349 /* Some HP machines seem to have unstable codec communications
5350 * especially with ATI fglrx driver. For recovering from the
5351 * CORB/RIRB stall, allow the BUS reset and keep always sync
5352 */
5353 if (spec->board_config == STAC_HP_DV5) {
5354 codec->bus->sync_write = 1;
5355 codec->bus->allow_bus_reset = 1;
5356 }
5357
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005358 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005359 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005360 spec->aloopback_shift = 0;
5361
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005362 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005363 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005364 spec->mux_nids = stac92hd71bxx_mux_nids;
5365 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005366 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005367 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005368
5369 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5370 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005371 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005372 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005373
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005374 switch (spec->board_config) {
5375 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005376 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005377 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005378 stac92xx_auto_set_pinctl(codec, 0x0e,
5379 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005380 /* fallthru */
5381 case STAC_DELL_M4_2:
5382 spec->num_dmics = 0;
5383 spec->num_smuxes = 0;
5384 spec->num_dmuxes = 0;
5385 break;
5386 case STAC_DELL_M4_1:
5387 case STAC_DELL_M4_3:
5388 spec->num_dmics = 1;
5389 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005390 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005391 break;
James Gardiner514bf542009-05-03 04:00:44 -04005392 case STAC_HP_DV4_1222NR:
5393 spec->num_dmics = 1;
5394 /* I don't know if it needs 1 or 2 smuxes - will wait for
5395 * bug reports to fix if needed
5396 */
5397 spec->num_smuxes = 1;
5398 spec->num_dmuxes = 1;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005399 spec->gpio_led = 0x01;
James Gardiner514bf542009-05-03 04:00:44 -04005400 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005401 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005402 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005403 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005404 /* HP dv6 gives the headphone pin as a line-out. Thus we
5405 * need to set hp_detect flag here to force to enable HP
5406 * detection.
5407 */
5408 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005409 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005410 case STAC_HP_HDX:
5411 spec->num_dmics = 1;
5412 spec->num_dmuxes = 1;
5413 spec->num_smuxes = 1;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005414 /* orange/white mute led on GPIO3, orange=0, white=1 */
Takashi Iwai86d190e2009-05-26 15:18:58 +02005415 spec->gpio_led = 0x08;
5416 break;
5417 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005418
Takashi Iwai86d190e2009-05-26 15:18:58 +02005419#ifdef CONFIG_SND_HDA_POWER_SAVE
5420 if (spec->gpio_led) {
5421 spec->gpio_mask |= spec->gpio_led;
5422 spec->gpio_dir |= spec->gpio_led;
5423 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005424 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005425 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005426 stac92xx_hp_check_power_status;
5427 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005428#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005429
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005430 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005431
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005432 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005433 if (!err) {
5434 if (spec->board_config < 0) {
5435 printk(KERN_WARNING "hda_codec: No auto-config is "
5436 "available, default to model=ref\n");
5437 spec->board_config = STAC_92HD71BXX_REF;
5438 goto again;
5439 }
5440 err = -EINVAL;
5441 }
5442
5443 if (err < 0) {
5444 stac92xx_free(codec);
5445 return err;
5446 }
5447
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005448 codec->proc_widget_hook = stac92hd7x_proc_hook;
5449
Matthew Ranostaye035b842007-11-06 11:53:55 +01005450 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005451}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005452
Matt2f2f4252005-04-13 14:45:30 +02005453static int patch_stac922x(struct hda_codec *codec)
5454{
5455 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005456 int err;
Matt2f2f4252005-04-13 14:45:30 +02005457
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005458 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005459 if (spec == NULL)
5460 return -ENOMEM;
5461
5462 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005463 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005464 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005465 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5466 stac922x_models,
5467 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005468 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005469 spec->gpio_mask = spec->gpio_dir = 0x03;
5470 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005471 /* Intel Macs have all same PCI SSID, so we need to check
5472 * codec SSID to distinguish the exact models
5473 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005474 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005475 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005476
5477 case 0x106b0800:
5478 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005479 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005480 case 0x106b0600:
5481 case 0x106b0700:
5482 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005483 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005484 case 0x106b0e00:
5485 case 0x106b0f00:
5486 case 0x106b1600:
5487 case 0x106b1700:
5488 case 0x106b0200:
5489 case 0x106b1e00:
5490 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005491 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005492 case 0x106b1a00:
5493 case 0x00000100:
5494 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005495 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005496 case 0x106b0a00:
5497 case 0x106b2200:
5498 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005499 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005500 default:
5501 spec->board_config = STAC_INTEL_MAC_V3;
5502 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005503 }
5504 }
5505
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005506 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005507 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005508 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5509 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005510 else
5511 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005512 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005513
Matt2f2f4252005-04-13 14:45:30 +02005514 spec->adc_nids = stac922x_adc_nids;
5515 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005516 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005517 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005518 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005519 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005520
5521 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005522
5523 spec->num_caps = STAC922X_NUM_CAPS;
5524 spec->capvols = stac922x_capvols;
5525 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005526
5527 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005528
Matt Porter3cc08dc2006-01-23 15:27:49 +01005529 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005530 if (!err) {
5531 if (spec->board_config < 0) {
5532 printk(KERN_WARNING "hda_codec: No auto-config is "
5533 "available, default to model=ref\n");
5534 spec->board_config = STAC_D945_REF;
5535 goto again;
5536 }
5537 err = -EINVAL;
5538 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005539 if (err < 0) {
5540 stac92xx_free(codec);
5541 return err;
5542 }
5543
5544 codec->patch_ops = stac92xx_patch_ops;
5545
Takashi Iwai807a46362007-05-29 19:01:37 +02005546 /* Fix Mux capture level; max to 2 */
5547 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5548 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5549 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5550 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5551 (0 << AC_AMPCAP_MUTE_SHIFT));
5552
Matt Porter3cc08dc2006-01-23 15:27:49 +01005553 return 0;
5554}
5555
5556static int patch_stac927x(struct hda_codec *codec)
5557{
5558 struct sigmatel_spec *spec;
5559 int err;
5560
5561 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5562 if (spec == NULL)
5563 return -ENOMEM;
5564
5565 codec->spec = spec;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005566 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005567 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005568 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005569 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5570 stac927x_models,
5571 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005572 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005573 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005574 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5575 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005576 else
5577 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005578 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005579
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005580 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005581 spec->adc_nids = stac927x_adc_nids;
5582 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5583 spec->mux_nids = stac927x_mux_nids;
5584 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005585 spec->smux_nids = stac927x_smux_nids;
5586 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005587 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005588 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005589 spec->multiout.dac_nids = spec->dac_nids;
5590
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005591 if (spec->board_config != STAC_D965_REF) {
5592 /* GPIO0 High = Enable EAPD */
5593 spec->eapd_mask = spec->gpio_mask = 0x01;
5594 spec->gpio_dir = spec->gpio_data = 0x01;
5595 }
5596
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005597 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005598 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005599 case STAC_D965_5ST:
5600 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005601 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02005602 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005603 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005604 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005605 switch (codec->subsystem_id) {
5606 case 0x10280209:
5607 case 0x1028022e:
5608 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005609 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005610 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005611 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005612 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005613 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005614 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005615 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005616 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005617 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005618 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005619 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005620 if (codec->subsystem_id != 0x1028022f) {
5621 /* GPIO2 High = Enable EAPD */
5622 spec->eapd_mask = spec->gpio_mask = 0x04;
5623 spec->gpio_dir = spec->gpio_data = 0x04;
5624 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005625 spec->dmic_nids = stac927x_dmic_nids;
5626 spec->num_dmics = STAC927X_NUM_DMICS;
5627
Tobin Davis93ed1502006-09-01 21:03:12 +02005628 spec->init = d965_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005629 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005630 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005631 break;
Takashi Iwai54930532009-10-11 17:38:29 +02005632 case STAC_927X_VOLKNOB:
5633 spec->num_dmics = 0;
5634 spec->init = stac927x_volknob_core_init;
5635 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005636 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005637 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005638 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005639 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005640 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005641
Takashi Iwai6479c632009-07-28 18:20:25 +02005642 spec->num_caps = STAC927X_NUM_CAPS;
5643 spec->capvols = stac927x_capvols;
5644 spec->capsws = stac927x_capsws;
5645
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005646 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005647 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005648 spec->aloopback_mask = 0x40;
5649 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005650 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005651
Matt Porter3cc08dc2006-01-23 15:27:49 +01005652 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005653 if (!err) {
5654 if (spec->board_config < 0) {
5655 printk(KERN_WARNING "hda_codec: No auto-config is "
5656 "available, default to model=ref\n");
5657 spec->board_config = STAC_D965_REF;
5658 goto again;
5659 }
5660 err = -EINVAL;
5661 }
Mattc7d4b2f2005-06-27 14:59:41 +02005662 if (err < 0) {
5663 stac92xx_free(codec);
5664 return err;
5665 }
Matt2f2f4252005-04-13 14:45:30 +02005666
5667 codec->patch_ops = stac92xx_patch_ops;
5668
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005669 codec->proc_widget_hook = stac927x_proc_hook;
5670
Takashi Iwai52987652008-01-16 16:09:47 +01005671 /*
5672 * !!FIXME!!
5673 * The STAC927x seem to require fairly long delays for certain
5674 * command sequences. With too short delays (even if the answer
5675 * is set to RIRB properly), it results in the silence output
5676 * on some hardwares like Dell.
5677 *
5678 * The below flag enables the longer delay (see get_response
5679 * in hda_intel.c).
5680 */
5681 codec->bus->needs_damn_long_delay = 1;
5682
Takashi Iwaie28d8322008-12-17 13:48:29 +01005683 /* no jack detecion for ref-no-jd model */
5684 if (spec->board_config == STAC_D965_REF_NO_JD)
5685 spec->hp_detect = 0;
5686
Matt2f2f4252005-04-13 14:45:30 +02005687 return 0;
5688}
5689
Matt Porterf3302a52006-07-31 12:49:34 +02005690static int patch_stac9205(struct hda_codec *codec)
5691{
5692 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005693 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005694
5695 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5696 if (spec == NULL)
5697 return -ENOMEM;
5698
5699 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005700 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005701 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005702 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5703 stac9205_models,
5704 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005705 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005706 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005707 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5708 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005709 else
5710 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005711 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02005712
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005713 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005714 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005715 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005716 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005717 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005718 spec->smux_nids = stac9205_smux_nids;
5719 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005720 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005721 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005722 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005723 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005724 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005725
5726 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005727 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02005728
Takashi Iwai6479c632009-07-28 18:20:25 +02005729 spec->num_caps = STAC9205_NUM_CAPS;
5730 spec->capvols = stac9205_capvols;
5731 spec->capsws = stac9205_capsws;
5732
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005733 spec->aloopback_mask = 0x40;
5734 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01005735 /* Turn on/off EAPD per HP plugging */
5736 if (spec->board_config != STAC_9205_EAPD)
5737 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005738 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005739
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005740 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005741 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005742 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005743 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5744 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005745
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005746 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005747 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5748 if (err < 0)
5749 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005750 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005751 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5752 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005753 AC_VERB_SET_UNSOLICITED_ENABLE,
5754 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005755
5756 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005757 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005758 spec->gpio_mask = 0x1b;
5759 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005760 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005761 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005762 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005763 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005764 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005765 case STAC_9205_REF:
5766 /* SPDIF-In enabled */
5767 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005768 default:
5769 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005770 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005771 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005772 break;
5773 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005774
Matt Porterf3302a52006-07-31 12:49:34 +02005775 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005776 if (!err) {
5777 if (spec->board_config < 0) {
5778 printk(KERN_WARNING "hda_codec: No auto-config is "
5779 "available, default to model=ref\n");
5780 spec->board_config = STAC_9205_REF;
5781 goto again;
5782 }
5783 err = -EINVAL;
5784 }
Matt Porterf3302a52006-07-31 12:49:34 +02005785 if (err < 0) {
5786 stac92xx_free(codec);
5787 return err;
5788 }
5789
5790 codec->patch_ops = stac92xx_patch_ops;
5791
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005792 codec->proc_widget_hook = stac9205_proc_hook;
5793
Matt Porterf3302a52006-07-31 12:49:34 +02005794 return 0;
5795}
5796
Matt2f2f4252005-04-13 14:45:30 +02005797/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005798 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005799 */
5800
Takashi Iwai1e137f92009-01-21 07:41:22 +01005801static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02005802 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005803 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5804 {}
5805};
5806
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005807static hda_nid_t stac9872_pin_nids[] = {
5808 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5809 0x11, 0x13, 0x14,
5810};
5811
5812static hda_nid_t stac9872_adc_nids[] = {
5813 0x8 /*,0x6*/
5814};
5815
5816static hda_nid_t stac9872_mux_nids[] = {
5817 0x15
5818};
5819
Takashi Iwai6479c632009-07-28 18:20:25 +02005820static unsigned long stac9872_capvols[] = {
5821 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
5822};
5823#define stac9872_capsws stac9872_capvols
5824
Takashi Iwai307282c2009-03-12 18:17:58 +01005825static unsigned int stac9872_vaio_pin_configs[9] = {
5826 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
5827 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
5828 0x90a7013e
5829};
5830
5831static const char *stac9872_models[STAC_9872_MODELS] = {
5832 [STAC_9872_AUTO] = "auto",
5833 [STAC_9872_VAIO] = "vaio",
5834};
5835
5836static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
5837 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
5838};
5839
5840static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02005841 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
5842 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01005843 {} /* terminator */
5844};
5845
Guillaume Munch6d859062006-08-22 17:15:47 +02005846static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005847{
5848 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01005849 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005850
Takashi Iwaidb064e52006-03-16 16:04:58 +01005851 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5852 if (spec == NULL)
5853 return -ENOMEM;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005854 codec->spec = spec;
Takashi Iwaib04add92009-07-20 08:01:36 +02005855 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5856 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005857
5858 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5859 stac9872_models,
5860 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01005861 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005862 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5863 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01005864 else
5865 stac92xx_set_config_regs(codec,
5866 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005867
Takashi Iwai1e137f92009-01-21 07:41:22 +01005868 spec->multiout.dac_nids = spec->dac_nids;
5869 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5870 spec->adc_nids = stac9872_adc_nids;
5871 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5872 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01005873 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005874 spec->num_caps = 1;
5875 spec->capvols = stac9872_capvols;
5876 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005877
Takashi Iwai1e137f92009-01-21 07:41:22 +01005878 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5879 if (err < 0) {
5880 stac92xx_free(codec);
5881 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005882 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01005883 spec->input_mux = &spec->private_imux;
5884 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005885 return 0;
5886}
5887
5888
5889/*
Matt2f2f4252005-04-13 14:45:30 +02005890 * patch entries
5891 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005892static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02005893 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5894 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5895 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5896 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5897 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5898 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5899 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005900 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5901 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5902 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5903 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5904 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5905 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005906 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5907 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5908 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5909 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5910 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5911 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5912 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5913 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5914 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5915 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005916 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5917 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5918 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5919 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5920 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5921 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005922 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5923 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005924 /* The following does not take into account .id=0x83847661 when subsys =
5925 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5926 * currently not fully supported.
5927 */
5928 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5929 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5930 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01005931 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02005932 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5933 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5934 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5935 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5936 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5937 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5938 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5939 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005940 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005941 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5942 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005943 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005944 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005945 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5946 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005947 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005948 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5949 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5950 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5951 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5952 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5953 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5954 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5955 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005956 {} /* terminator */
5957};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005958
5959MODULE_ALIAS("snd-hda-codec-id:8384*");
5960MODULE_ALIAS("snd-hda-codec-id:111d*");
5961
5962MODULE_LICENSE("GPL");
5963MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5964
5965static struct hda_codec_preset_list sigmatel_list = {
5966 .preset = snd_hda_preset_sigmatel,
5967 .owner = THIS_MODULE,
5968};
5969
5970static int __init patch_sigmatel_init(void)
5971{
5972 return snd_hda_add_codec_preset(&sigmatel_list);
5973}
5974
5975static void __exit patch_sigmatel_exit(void)
5976{
5977 snd_hda_delete_codec_preset(&sigmatel_list);
5978}
5979
5980module_init(patch_sigmatel_init)
5981module_exit(patch_sigmatel_exit)