blob: e31e53dc6962335458639d33cf5adda136dcd3a1 [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 Iwaif5fcc132006-11-24 17:07:44 +0100161 STAC_927X_MODELS
162};
Matt Porter403d1942005-11-29 15:00:51 +0100163
Takashi Iwai307282c2009-03-12 18:17:58 +0100164enum {
165 STAC_9872_AUTO,
166 STAC_9872_VAIO,
167 STAC_9872_MODELS
168};
169
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400170struct sigmatel_event {
171 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100172 unsigned char type;
173 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400174 int data;
175};
176
177struct sigmatel_jack {
178 hda_nid_t nid;
179 int type;
180 struct snd_jack *jack;
181};
182
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200183struct sigmatel_mic_route {
184 hda_nid_t pin;
185 unsigned char mux_idx;
186 unsigned char dmux_idx;
187};
188
Matt2f2f4252005-04-13 14:45:30 +0200189struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100190 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200191 unsigned int num_mixers;
192
Matt Porter403d1942005-11-29 15:00:51 +0100193 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500194 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200195 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100196 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100197 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400198 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100199 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200200 unsigned int auto_mic:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200201
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100202 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200203 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100204 unsigned int gpio_mask;
205 unsigned int gpio_dir;
206 unsigned int gpio_data;
207 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200208 unsigned int gpio_led;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100209
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200210 /* stream */
211 unsigned int stream_delay;
212
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100213 /* analog loopback */
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100214 struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100215 unsigned char aloopback_mask;
216 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200217
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100218 /* power management */
219 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200220 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100221 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100222 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100223
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400224 /* jack detection */
225 struct snd_array jacks;
226
227 /* events */
228 struct snd_array events;
229
Matt2f2f4252005-04-13 14:45:30 +0200230 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100231 struct hda_input_mux *mono_mux;
232 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200233 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100234 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100235 hda_nid_t hp_dacs[5];
236 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200237
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100238 int volume_offset;
239
Matt2f2f4252005-04-13 14:45:30 +0200240 /* capture */
241 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200242 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200243 hda_nid_t *mux_nids;
244 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200245 hda_nid_t *dmic_nids;
246 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100247 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100248 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200249 hda_nid_t *smux_nids;
250 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200251 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200252
253 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
254 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
255 unsigned int num_caps; /* number of capture volume/switch elements */
256
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200257 struct sigmatel_mic_route ext_mic;
258 struct sigmatel_mic_route int_mic;
259
Matthew Ranostay65973632008-09-16 10:39:37 -0400260 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200261
Mattdabbed62005-06-14 10:19:34 +0200262 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100263 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200264 hda_nid_t anabeep_nid;
265 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200266
Matt2f2f4252005-04-13 14:45:30 +0200267 /* pin widgets */
268 hda_nid_t *pin_nids;
269 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200270
271 /* codec specific stuff */
272 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100273 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200274
275 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200276 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100277 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200278 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100279 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200280 struct hda_input_mux *sinput_mux;
281 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400282 unsigned int cur_amux;
283 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200284 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200285
Matt Porter403d1942005-11-29 15:00:51 +0100286 /* i/o switches */
287 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200288 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100289 hda_nid_t line_switch; /* shared line-in for input and output */
290 hda_nid_t mic_switch; /* shared mic-in for input and output */
291 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200292 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200293
Mattc7d4b2f2005-06-27 14:59:41 +0200294 struct hda_pcm pcm_rec[2]; /* PCM information */
295
296 /* dynamic controls and input_mux */
297 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200298 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200299 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200300 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200301 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100302 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200303};
304
305static hda_nid_t stac9200_adc_nids[1] = {
306 0x03,
307};
308
309static hda_nid_t stac9200_mux_nids[1] = {
310 0x0c,
311};
312
313static hda_nid_t stac9200_dac_nids[1] = {
314 0x02,
315};
316
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100317static hda_nid_t stac92hd73xx_pwr_nids[8] = {
318 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
319 0x0f, 0x10, 0x11
320};
321
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400322static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
323 0x26, 0,
324};
325
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100326static hda_nid_t stac92hd73xx_adc_nids[2] = {
327 0x1a, 0x1b
328};
329
330#define STAC92HD73XX_NUM_DMICS 2
331static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
332 0x13, 0x14, 0
333};
334
335#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100336
Takashi Iwaie2aec172009-09-02 01:00:05 +0200337static hda_nid_t stac92hd73xx_mux_nids[2] = {
338 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100339};
340
341static hda_nid_t stac92hd73xx_dmux_nids[2] = {
342 0x20, 0x21,
343};
344
Matthew Ranostayd9737752008-09-07 12:03:41 +0200345static hda_nid_t stac92hd73xx_smux_nids[2] = {
346 0x22, 0x23,
347};
348
Takashi Iwai6479c632009-07-28 18:20:25 +0200349#define STAC92HD73XX_NUM_CAPS 2
350static unsigned long stac92hd73xx_capvols[] = {
351 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
352 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
353};
354#define stac92hd73xx_capsws stac92hd73xx_capvols
355
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200356#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200357
Takashi Iwai667067d2009-08-13 18:14:42 +0200358static hda_nid_t stac92hd83xxx_mux_nids[2] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200359 0x17, 0x18,
360};
361
362static hda_nid_t stac92hd83xxx_adc_nids[2] = {
363 0x15, 0x16,
364};
365
366static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
367 0xa, 0xb, 0xd, 0xe,
368};
369
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400370static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
371 0x1e, 0,
372};
373
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200374static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500375 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200376};
377
Takashi Iwai6479c632009-07-28 18:20:25 +0200378#define STAC92HD83XXX_NUM_CAPS 2
379static unsigned long stac92hd83xxx_capvols[] = {
380 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
381 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
382};
383#define stac92hd83xxx_capsws stac92hd83xxx_capvols
384
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100385static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
386 0x0a, 0x0d, 0x0f
387};
388
Matthew Ranostaye035b842007-11-06 11:53:55 +0100389static hda_nid_t stac92hd71bxx_adc_nids[2] = {
390 0x12, 0x13,
391};
392
393static hda_nid_t stac92hd71bxx_mux_nids[2] = {
394 0x1a, 0x1b
395};
396
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400397static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
398 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100399};
400
Matthew Ranostayd9737752008-09-07 12:03:41 +0200401static hda_nid_t stac92hd71bxx_smux_nids[2] = {
402 0x24, 0x25,
403};
404
Matthew Ranostaye035b842007-11-06 11:53:55 +0100405#define STAC92HD71BXX_NUM_DMICS 2
406static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
407 0x18, 0x19, 0
408};
409
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400410static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
411 0x22, 0
412};
413
Takashi Iwai6479c632009-07-28 18:20:25 +0200414#define STAC92HD71BXX_NUM_CAPS 2
415static unsigned long stac92hd71bxx_capvols[] = {
416 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
417 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
418};
419#define stac92hd71bxx_capsws stac92hd71bxx_capvols
420
Tobin Davis8e21c342007-01-08 11:04:17 +0100421static hda_nid_t stac925x_adc_nids[1] = {
422 0x03,
423};
424
425static hda_nid_t stac925x_mux_nids[1] = {
426 0x0f,
427};
428
429static hda_nid_t stac925x_dac_nids[1] = {
430 0x02,
431};
432
Takashi Iwaif6e98522007-10-16 14:27:04 +0200433#define STAC925X_NUM_DMICS 1
434static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
435 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200436};
437
Takashi Iwai1697055e2007-12-18 18:05:52 +0100438static hda_nid_t stac925x_dmux_nids[1] = {
439 0x14,
440};
441
Takashi Iwai6479c632009-07-28 18:20:25 +0200442static unsigned long stac925x_capvols[] = {
443 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
444};
445static unsigned long stac925x_capsws[] = {
446 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
447};
448
Matt2f2f4252005-04-13 14:45:30 +0200449static hda_nid_t stac922x_adc_nids[2] = {
450 0x06, 0x07,
451};
452
453static hda_nid_t stac922x_mux_nids[2] = {
454 0x12, 0x13,
455};
456
Takashi Iwai6479c632009-07-28 18:20:25 +0200457#define STAC922X_NUM_CAPS 2
458static unsigned long stac922x_capvols[] = {
459 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
460 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
461};
462#define stac922x_capsws stac922x_capvols
463
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500464static hda_nid_t stac927x_slave_dig_outs[2] = {
465 0x1f, 0,
466};
467
Matt Porter3cc08dc2006-01-23 15:27:49 +0100468static hda_nid_t stac927x_adc_nids[3] = {
469 0x07, 0x08, 0x09
470};
471
472static hda_nid_t stac927x_mux_nids[3] = {
473 0x15, 0x16, 0x17
474};
475
Matthew Ranostayd9737752008-09-07 12:03:41 +0200476static hda_nid_t stac927x_smux_nids[1] = {
477 0x21,
478};
479
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100480static hda_nid_t stac927x_dac_nids[6] = {
481 0x02, 0x03, 0x04, 0x05, 0x06, 0
482};
483
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100484static hda_nid_t stac927x_dmux_nids[1] = {
485 0x1b,
486};
487
Matthew Ranostay7f168592007-10-18 17:38:17 +0200488#define STAC927X_NUM_DMICS 2
489static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
490 0x13, 0x14, 0
491};
492
Takashi Iwai6479c632009-07-28 18:20:25 +0200493#define STAC927X_NUM_CAPS 3
494static unsigned long stac927x_capvols[] = {
495 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
496 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
497 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
498};
499static unsigned long stac927x_capsws[] = {
500 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
501 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
502 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
503};
504
Matthew Ranostay65973632008-09-16 10:39:37 -0400505static const char *stac927x_spdif_labels[5] = {
506 "Digital Playback", "ADAT", "Analog Mux 1",
507 "Analog Mux 2", "Analog Mux 3"
508};
509
Matt Porterf3302a52006-07-31 12:49:34 +0200510static hda_nid_t stac9205_adc_nids[2] = {
511 0x12, 0x13
512};
513
514static hda_nid_t stac9205_mux_nids[2] = {
515 0x19, 0x1a
516};
517
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100518static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100519 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100520};
521
Matthew Ranostayd9737752008-09-07 12:03:41 +0200522static hda_nid_t stac9205_smux_nids[1] = {
523 0x21,
524};
525
Takashi Iwaif6e98522007-10-16 14:27:04 +0200526#define STAC9205_NUM_DMICS 2
527static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
528 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200529};
530
Takashi Iwai6479c632009-07-28 18:20:25 +0200531#define STAC9205_NUM_CAPS 2
532static unsigned long stac9205_capvols[] = {
533 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
534 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
535};
536static unsigned long stac9205_capsws[] = {
537 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
538 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
539};
540
Mattc7d4b2f2005-06-27 14:59:41 +0200541static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200542 0x08, 0x09, 0x0d, 0x0e,
543 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200544};
545
Tobin Davis8e21c342007-01-08 11:04:17 +0100546static hda_nid_t stac925x_pin_nids[8] = {
547 0x07, 0x08, 0x0a, 0x0b,
548 0x0c, 0x0d, 0x10, 0x11,
549};
550
Matt2f2f4252005-04-13 14:45:30 +0200551static hda_nid_t stac922x_pin_nids[10] = {
552 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
553 0x0f, 0x10, 0x11, 0x15, 0x1b,
554};
555
Matthew Ranostaya7662642008-02-21 07:51:14 +0100556static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100557 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
558 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200559 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100560};
561
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500562static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200563 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500564 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200565};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500566
567#define STAC92HD71BXX_NUM_PINS 13
568static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
569 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
570 0x00, 0x14, 0x18, 0x19, 0x1e,
571 0x1f, 0x20, 0x27
572};
573static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100574 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
575 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500576 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100577};
578
Matt Porter3cc08dc2006-01-23 15:27:49 +0100579static hda_nid_t stac927x_pin_nids[14] = {
580 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
581 0x0f, 0x10, 0x11, 0x12, 0x13,
582 0x14, 0x21, 0x22, 0x23,
583};
584
Matt Porterf3302a52006-07-31 12:49:34 +0200585static hda_nid_t stac9205_pin_nids[12] = {
586 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
587 0x0f, 0x14, 0x16, 0x17, 0x18,
588 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200589};
590
Matt Porter8b657272006-10-26 17:12:59 +0200591static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
592 struct snd_ctl_elem_info *uinfo)
593{
594 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
595 struct sigmatel_spec *spec = codec->spec;
596 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
597}
598
599static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
600 struct snd_ctl_elem_value *ucontrol)
601{
602 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
603 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100604 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200605
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100606 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200607 return 0;
608}
609
610static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
611 struct snd_ctl_elem_value *ucontrol)
612{
613 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
614 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100615 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200616
617 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100618 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200619}
620
Matthew Ranostayd9737752008-09-07 12:03:41 +0200621static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
622 struct snd_ctl_elem_info *uinfo)
623{
624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
625 struct sigmatel_spec *spec = codec->spec;
626 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
627}
628
629static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
630 struct snd_ctl_elem_value *ucontrol)
631{
632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633 struct sigmatel_spec *spec = codec->spec;
634 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
635
636 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
637 return 0;
638}
639
640static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
641 struct snd_ctl_elem_value *ucontrol)
642{
643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
644 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400645 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200646 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400647 int err, val;
648 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200649
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400650 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200651 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400652 if (err < 0)
653 return err;
654
655 if (spec->spdif_mute) {
656 if (smux_idx == 0)
657 nid = spec->multiout.dig_out_nid;
658 else
659 nid = codec->slave_dig_outs[smux_idx - 1];
660 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100661 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400662 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100663 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400664 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100665 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
666 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400667 }
668 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200669}
670
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200671static unsigned int stac92xx_vref_set(struct hda_codec *codec,
672 hda_nid_t nid, unsigned int new_vref)
673{
Takashi Iwaib8621512009-06-22 08:00:10 +0200674 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200675 unsigned int pincfg;
676 pincfg = snd_hda_codec_read(codec, nid, 0,
677 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
678
679 pincfg &= 0xff;
680 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
681 pincfg |= new_vref;
682
683 if (new_vref == AC_PINCTL_VREF_HIZ)
684 pincfg |= AC_PINCTL_OUT_EN;
685 else
686 pincfg |= AC_PINCTL_IN_EN;
687
688 error = snd_hda_codec_write_cache(codec, nid, 0,
689 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
690 if (error < 0)
691 return error;
692 else
693 return 1;
694}
695
696static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
697{
698 unsigned int vref;
699 vref = snd_hda_codec_read(codec, nid, 0,
700 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
701 vref &= AC_PINCTL_VREFEN;
702 return vref;
703}
704
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100705static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200706{
707 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
708 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200709 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200710}
711
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100712static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200713{
714 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
715 struct sigmatel_spec *spec = codec->spec;
716 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
717
718 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
719 return 0;
720}
721
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100722static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200723{
724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
725 struct sigmatel_spec *spec = codec->spec;
726 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200727 const struct hda_input_mux *imux = spec->input_mux;
728 unsigned int idx, prev_idx;
Matt2f2f4252005-04-13 14:45:30 +0200729
Takashi Iwai5207e102009-07-30 13:09:08 +0200730 idx = ucontrol->value.enumerated.item[0];
731 if (idx >= imux->num_items)
732 idx = imux->num_items - 1;
733 prev_idx = spec->cur_mux[adc_idx];
734 if (prev_idx == idx)
735 return 0;
736 if (idx < spec->num_analog_muxes) {
737 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
738 AC_VERB_SET_CONNECT_SEL,
739 imux->items[idx].index);
740 if (prev_idx >= spec->num_analog_muxes) {
741 imux = spec->dinput_mux;
742 /* 0 = analog */
743 snd_hda_codec_write_cache(codec,
744 spec->dmux_nids[adc_idx], 0,
745 AC_VERB_SET_CONNECT_SEL,
746 imux->items[0].index);
747 }
748 } else {
749 imux = spec->dinput_mux;
750 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
751 AC_VERB_SET_CONNECT_SEL,
752 imux->items[idx - 1].index);
753 }
754 spec->cur_mux[adc_idx] = idx;
755 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200756}
757
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100758static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
759 struct snd_ctl_elem_info *uinfo)
760{
761 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
762 struct sigmatel_spec *spec = codec->spec;
763 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
764}
765
766static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
767 struct snd_ctl_elem_value *ucontrol)
768{
769 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
770 struct sigmatel_spec *spec = codec->spec;
771
772 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
773 return 0;
774}
775
776static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
777 struct snd_ctl_elem_value *ucontrol)
778{
779 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
780 struct sigmatel_spec *spec = codec->spec;
781
782 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
783 spec->mono_nid, &spec->cur_mmux);
784}
785
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200786#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
787
788static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
789 struct snd_ctl_elem_value *ucontrol)
790{
791 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100792 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200793 struct sigmatel_spec *spec = codec->spec;
794
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100795 ucontrol->value.integer.value[0] = !!(spec->aloopback &
796 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200797 return 0;
798}
799
800static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
801 struct snd_ctl_elem_value *ucontrol)
802{
803 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
804 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100805 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200806 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100807 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200808
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100809 idx_val = spec->aloopback_mask << idx;
810 if (ucontrol->value.integer.value[0])
811 val = spec->aloopback | idx_val;
812 else
813 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100814 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200815 return 0;
816
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100817 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200818
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100819 /* Only return the bits defined by the shift value of the
820 * first two bytes of the mask
821 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200822 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100823 kcontrol->private_value & 0xFFFF, 0x0);
824 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200825
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100826 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200827 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100828 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200829 } else {
830 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100831 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200832 }
833
834 snd_hda_codec_write_cache(codec, codec->afg, 0,
835 kcontrol->private_value >> 16, dac_mode);
836
837 return 1;
838}
839
Mattc7d4b2f2005-06-27 14:59:41 +0200840static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200841 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200842 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200843 {}
844};
845
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200846static struct hda_verb stac9200_eapd_init[] = {
847 /* set dac0mux for dac converter */
848 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
849 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
850 {}
851};
852
Matthew Ranostayd654a662008-03-14 08:46:51 +0100853static struct hda_verb dell_eq_core_init[] = {
854 /* set master volume to max value without distortion
855 * and direct control */
856 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100857 {}
858};
859
Takashi Iwaie2aec172009-09-02 01:00:05 +0200860static struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100861 /* set master volume and direct control */
862 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100863 {}
864};
865
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200866static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500867 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
868 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
869 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200870
871 /* power state controls amps */
872 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200873 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200874};
875
Matthew Ranostaye035b842007-11-06 11:53:55 +0100876static struct hda_verb stac92hd71bxx_core_init[] = {
877 /* set master volume and direct control */
878 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200879 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100880};
881
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500882static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
883 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
884 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100885 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
886 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100887 {}
888};
889
Tobin Davis8e21c342007-01-08 11:04:17 +0100890static struct hda_verb stac925x_core_init[] = {
891 /* set dac0mux for dac converter */
892 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100893 /* mute the master volume */
894 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100895 {}
896};
897
Mattc7d4b2f2005-06-27 14:59:41 +0200898static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200899 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200900 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200901 {}
902};
903
Tobin Davis93ed1502006-09-01 21:03:12 +0200904static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200905 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200906 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200907 /* unmute node 0x1b */
908 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
909 /* select node 0x03 as DAC */
910 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
911 {}
912};
913
Matt Porter3cc08dc2006-01-23 15:27:49 +0100914static struct hda_verb stac927x_core_init[] = {
915 /* set master volume and direct control */
916 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200917 /* enable analog pc beep path */
918 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100919 {}
920};
921
Matt Porterf3302a52006-07-31 12:49:34 +0200922static struct hda_verb stac9205_core_init[] = {
923 /* set master volume and direct control */
924 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200925 /* enable analog pc beep path */
926 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200927 {}
928};
929
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100930#define STAC_MONO_MUX \
931 { \
932 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
933 .name = "Mono Mux", \
934 .count = 1, \
935 .info = stac92xx_mono_mux_enum_info, \
936 .get = stac92xx_mono_mux_enum_get, \
937 .put = stac92xx_mono_mux_enum_put, \
938 }
939
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100940#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200941 { \
942 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
943 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100944 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200945 .info = stac92xx_aloopback_info, \
946 .get = stac92xx_aloopback_get, \
947 .put = stac92xx_aloopback_put, \
948 .private_value = verb_read | (verb_write << 16), \
949 }
950
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200951#define DC_BIAS(xname, idx, nid) \
952 { \
953 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
954 .name = xname, \
955 .index = idx, \
956 .info = stac92xx_dc_bias_info, \
957 .get = stac92xx_dc_bias_get, \
958 .put = stac92xx_dc_bias_put, \
959 .private_value = nid, \
960 }
961
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100962static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200963 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
964 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200965 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
966 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200967 { } /* end */
968};
969
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100970static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
971 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
972 {}
973};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100974
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100975static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
976 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
977 {}
978};
979
980static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
981 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
982 {}
983};
984
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200985
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100986static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
987 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
988};
Matthew Ranostay541eee82007-12-14 12:08:04 +0100989
Tobin Davis8e21c342007-01-08 11:04:17 +0100990static struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwaic9280d62009-01-15 17:31:00 +0100991 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
992 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200993 { } /* end */
994};
995
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100996static struct snd_kcontrol_new stac9205_loopback[] = {
997 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
998 {}
999};
1000
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001001static struct snd_kcontrol_new stac927x_loopback[] = {
1002 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1003 {}
1004};
1005
Takashi Iwai1697055e2007-12-18 18:05:52 +01001006static struct snd_kcontrol_new stac_dmux_mixer = {
1007 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1008 .name = "Digital Input Source",
1009 /* count set later */
1010 .info = stac92xx_dmux_enum_info,
1011 .get = stac92xx_dmux_enum_get,
1012 .put = stac92xx_dmux_enum_put,
1013};
1014
Matthew Ranostayd9737752008-09-07 12:03:41 +02001015static struct snd_kcontrol_new stac_smux_mixer = {
1016 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001017 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001018 /* count set later */
1019 .info = stac92xx_smux_enum_info,
1020 .get = stac92xx_smux_enum_get,
1021 .put = stac92xx_smux_enum_put,
1022};
1023
Takashi Iwai2134ea42008-01-10 16:53:55 +01001024static const char *slave_vols[] = {
1025 "Front Playback Volume",
1026 "Surround Playback Volume",
1027 "Center Playback Volume",
1028 "LFE Playback Volume",
1029 "Side Playback Volume",
1030 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001031 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001032 NULL
1033};
1034
1035static const char *slave_sws[] = {
1036 "Front Playback Switch",
1037 "Surround Playback Switch",
1038 "Center Playback Switch",
1039 "LFE Playback Switch",
1040 "Side Playback Switch",
1041 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001042 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001043 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001044 NULL
1045};
1046
Takashi Iwai603c4012008-07-30 15:01:44 +02001047static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001048static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001049
Matt2f2f4252005-04-13 14:45:30 +02001050static int stac92xx_build_controls(struct hda_codec *codec)
1051{
1052 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001053 struct auto_pin_cfg *cfg = &spec->autocfg;
1054 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001055 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001056 int i;
Matt2f2f4252005-04-13 14:45:30 +02001057
Takashi Iwai6479c632009-07-28 18:20:25 +02001058 if (spec->mixer) {
1059 err = snd_hda_add_new_ctls(codec, spec->mixer);
1060 if (err < 0)
1061 return err;
1062 }
Mattc7d4b2f2005-06-27 14:59:41 +02001063
1064 for (i = 0; i < spec->num_mixers; i++) {
1065 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1066 if (err < 0)
1067 return err;
1068 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001069 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1070 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001071 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001072 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001073 snd_ctl_new1(&stac_dmux_mixer, codec));
1074 if (err < 0)
1075 return err;
1076 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001077 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001078 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1079 struct hda_input_mux *smux = &spec->private_smux;
1080 /* check for mute support on SPDIF out */
1081 if (wcaps & AC_WCAP_OUT_AMP) {
1082 smux->items[smux->num_items].label = "Off";
1083 smux->items[smux->num_items].index = 0;
1084 smux->num_items++;
1085 spec->spdif_mute = 1;
1086 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001087 stac_smux_mixer.count = spec->num_smuxes;
Takashi Iwai4f2d23e2008-12-19 10:14:13 +01001088 err = snd_hda_ctl_add(codec,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001089 snd_ctl_new1(&stac_smux_mixer, codec));
1090 if (err < 0)
1091 return err;
1092 }
Mattc7d4b2f2005-06-27 14:59:41 +02001093
Mattdabbed62005-06-14 10:19:34 +02001094 if (spec->multiout.dig_out_nid) {
1095 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1096 if (err < 0)
1097 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001098 err = snd_hda_create_spdif_share_sw(codec,
1099 &spec->multiout);
1100 if (err < 0)
1101 return err;
1102 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001103 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001104 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001105 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1106 if (err < 0)
1107 return err;
1108 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001109
1110 /* if we have no master control, let's create it */
1111 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001112 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001113 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001114 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001115 /* correct volume offset */
1116 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001117 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001118 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001119 if (err < 0)
1120 return err;
1121 }
1122 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1123 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1124 NULL, slave_sws);
1125 if (err < 0)
1126 return err;
1127 }
1128
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001129 if (spec->aloopback_ctl &&
1130 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1131 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1132 if (err < 0)
1133 return err;
1134 }
1135
Takashi Iwai603c4012008-07-30 15:01:44 +02001136 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001137
1138 /* create jack input elements */
1139 if (spec->hp_detect) {
1140 for (i = 0; i < cfg->hp_outs; i++) {
1141 int type = SND_JACK_HEADPHONE;
1142 nid = cfg->hp_pins[i];
1143 /* jack detection */
1144 if (cfg->hp_outs == i)
1145 type |= SND_JACK_LINEOUT;
1146 err = stac92xx_add_jack(codec, nid, type);
1147 if (err < 0)
1148 return err;
1149 }
1150 }
1151 for (i = 0; i < cfg->line_outs; i++) {
1152 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1153 SND_JACK_LINEOUT);
1154 if (err < 0)
1155 return err;
1156 }
1157 for (i = 0; i < AUTO_PIN_LAST; i++) {
1158 nid = cfg->input_pins[i];
1159 if (nid) {
1160 err = stac92xx_add_jack(codec, nid,
1161 SND_JACK_MICROPHONE);
1162 if (err < 0)
1163 return err;
1164 }
1165 }
1166
Mattdabbed62005-06-14 10:19:34 +02001167 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001168}
1169
Matt Porter403d1942005-11-29 15:00:51 +01001170static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001171 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001172 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1173};
1174
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001175static unsigned int gateway9200_m4_pin_configs[8] = {
1176 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1177 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1178};
1179static unsigned int gateway9200_m4_2_pin_configs[8] = {
1180 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1181 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1182};
1183
1184/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001185 STAC 9200 pin configs for
1186 102801A8
1187 102801DE
1188 102801E8
1189*/
1190static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001191 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1192 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001193};
1194
1195/*
1196 STAC 9200 pin configs for
1197 102801C0
1198 102801C1
1199*/
1200static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001201 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1202 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001203};
1204
1205/*
1206 STAC 9200 pin configs for
1207 102801C4 (Dell Dimension E310)
1208 102801C5
1209 102801C7
1210 102801D9
1211 102801DA
1212 102801E3
1213*/
1214static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001215 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1216 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001217};
1218
1219
1220/*
1221 STAC 9200-32 pin configs for
1222 102801B5 (Dell Inspiron 630m)
1223 102801D8 (Dell Inspiron 640m)
1224*/
1225static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001226 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1227 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001228};
1229
1230/*
1231 STAC 9200-32 pin configs for
1232 102801C2 (Dell Latitude D620)
1233 102801C8
1234 102801CC (Dell Latitude D820)
1235 102801D4
1236 102801D6
1237*/
1238static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001239 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1240 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001241};
1242
1243/*
1244 STAC 9200-32 pin configs for
1245 102801CE (Dell XPS M1710)
1246 102801CF (Dell Precision M90)
1247*/
1248static unsigned int dell9200_m23_pin_configs[8] = {
1249 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1250 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1251};
1252
1253/*
1254 STAC 9200-32 pin configs for
1255 102801C9
1256 102801CA
1257 102801CB (Dell Latitude 120L)
1258 102801D3
1259*/
1260static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001261 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1262 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001263};
1264
1265/*
1266 STAC 9200-32 pin configs for
1267 102801BD (Dell Inspiron E1505n)
1268 102801EE
1269 102801EF
1270*/
1271static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001272 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1273 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001274};
1275
1276/*
1277 STAC 9200-32 pin configs for
1278 102801F5 (Dell Inspiron 1501)
1279 102801F6
1280*/
1281static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001282 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1283 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001284};
1285
1286/*
1287 STAC 9200-32
1288 102801CD (Dell Inspiron E1705/9400)
1289*/
1290static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001291 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1292 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001293};
1294
Tobin Davisbf277782008-02-03 20:31:47 +01001295static unsigned int oqo9200_pin_configs[8] = {
1296 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1297 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1298};
1299
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001300
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001301static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1302 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001303 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001304 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1305 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1306 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1307 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1308 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1309 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1310 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1311 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1312 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1313 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001314 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1315 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001316 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001317};
1318
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001319static const char *stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001320 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001321 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001322 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001323 [STAC_9200_DELL_D21] = "dell-d21",
1324 [STAC_9200_DELL_D22] = "dell-d22",
1325 [STAC_9200_DELL_D23] = "dell-d23",
1326 [STAC_9200_DELL_M21] = "dell-m21",
1327 [STAC_9200_DELL_M22] = "dell-m22",
1328 [STAC_9200_DELL_M23] = "dell-m23",
1329 [STAC_9200_DELL_M24] = "dell-m24",
1330 [STAC_9200_DELL_M25] = "dell-m25",
1331 [STAC_9200_DELL_M26] = "dell-m26",
1332 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001333 [STAC_9200_M4] = "gateway-m4",
1334 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001335 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001336};
1337
1338static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1339 /* SigmaTel reference board */
1340 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1341 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001342 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1343 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001344 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001345 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1346 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001347 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001348 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1349 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1350 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1351 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1352 "unknown Dell", STAC_9200_DELL_D22),
1353 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1354 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001355 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001356 "Dell Latitude D620", STAC_9200_DELL_M22),
1357 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1358 "unknown Dell", STAC_9200_DELL_D23),
1359 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1360 "unknown Dell", STAC_9200_DELL_D23),
1361 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1362 "unknown Dell", STAC_9200_DELL_M22),
1363 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1364 "unknown Dell", STAC_9200_DELL_M24),
1365 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1366 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001367 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001368 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001369 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001370 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001371 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001372 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001373 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001374 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001375 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001376 "Dell Precision M90", STAC_9200_DELL_M23),
1377 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1378 "unknown Dell", STAC_9200_DELL_M22),
1379 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1380 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001381 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001382 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001383 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001384 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1385 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1386 "unknown Dell", STAC_9200_DELL_D23),
1387 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1388 "unknown Dell", STAC_9200_DELL_D23),
1389 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1390 "unknown Dell", STAC_9200_DELL_D21),
1391 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1392 "unknown Dell", STAC_9200_DELL_D23),
1393 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1394 "unknown Dell", STAC_9200_DELL_D21),
1395 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1396 "unknown Dell", STAC_9200_DELL_M25),
1397 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1398 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001399 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001400 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1401 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1402 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001403 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001404 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001405 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001406 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1407 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1408 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001409 /* OQO Mobile */
1410 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001411 {} /* terminator */
1412};
1413
Tobin Davis8e21c342007-01-08 11:04:17 +01001414static unsigned int ref925x_pin_configs[8] = {
1415 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001416 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001417};
1418
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001419static unsigned int stac925xM1_pin_configs[8] = {
1420 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1421 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001422};
1423
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001424static unsigned int stac925xM1_2_pin_configs[8] = {
1425 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1426 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1427};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001428
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001429static unsigned int stac925xM2_pin_configs[8] = {
1430 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1431 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001432};
1433
Tobin Davis8e21c342007-01-08 11:04:17 +01001434static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001435 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1436 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1437};
1438
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001439static unsigned int stac925xM3_pin_configs[8] = {
1440 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1441 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1442};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001443
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001444static unsigned int stac925xM5_pin_configs[8] = {
1445 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1446 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1447};
1448
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001449static unsigned int stac925xM6_pin_configs[8] = {
1450 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1451 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001452};
1453
1454static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1455 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001456 [STAC_M1] = stac925xM1_pin_configs,
1457 [STAC_M1_2] = stac925xM1_2_pin_configs,
1458 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001459 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001460 [STAC_M3] = stac925xM3_pin_configs,
1461 [STAC_M5] = stac925xM5_pin_configs,
1462 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001463};
1464
1465static const char *stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001466 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001467 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001468 [STAC_M1] = "m1",
1469 [STAC_M1_2] = "m1-2",
1470 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001471 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001472 [STAC_M3] = "m3",
1473 [STAC_M5] = "m5",
1474 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001475};
1476
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001477static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001478 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1479 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1480 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1481 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001482 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001483 /* Not sure about the brand name for those */
1484 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1485 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1486 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1487 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001488 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001489};
1490
1491static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1492 /* SigmaTel reference board */
1493 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001494 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001495 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001496
1497 /* Default table for unknown ID */
1498 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1499
Tobin Davis8e21c342007-01-08 11:04:17 +01001500 {} /* terminator */
1501};
1502
Matthew Ranostaya7662642008-02-21 07:51:14 +01001503static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001504 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1505 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1506 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001507 0x01452050,
1508};
1509
1510static unsigned int dell_m6_pin_configs[13] = {
1511 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001512 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001513 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1514 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001515};
1516
Takashi Iwai842ae632009-09-02 07:43:08 +02001517static unsigned int alienware_m17x_pin_configs[13] = {
1518 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1519 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1520 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1521 0x904601b0,
1522};
1523
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001524static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001525 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001526 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1527 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1528 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001529 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001530 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001531};
1532
1533static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001534 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001535 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001536 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001537 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001538 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1539 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1540 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001541 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001542 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001543};
1544
1545static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1546 /* SigmaTel reference board */
1547 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001548 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001549 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1550 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001551 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1552 "Intel DG45ID", STAC_92HD73XX_INTEL),
1553 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1554 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001555 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001556 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001557 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001558 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001559 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001560 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001561 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001562 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001563 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001564 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001565 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001566 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001567 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001568 "unknown Dell", STAC_DELL_M6_DMIC),
1569 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1570 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001571 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001572 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001573 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1574 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001575 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1576 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001577 {} /* terminator */
1578};
1579
Takashi Iwai842ae632009-09-02 07:43:08 +02001580static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1581 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1582 "Alienware M17x", STAC_ALIENWARE_M17X),
1583 {} /* terminator */
1584};
1585
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001586static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001587 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1588 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001589 0x01451160, 0x98560170,
1590};
1591
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001592static unsigned int dell_s14_pin_configs[10] = {
1593 0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1594 0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1595 0x40f000f0, 0x40f000f0,
1596};
1597
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001598static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1599 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001600 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001601 [STAC_DELL_S14] = dell_s14_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001602};
1603
1604static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001605 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001606 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001607 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001608 [STAC_DELL_S14] = "dell-s14",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001609};
1610
1611static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1612 /* SigmaTel reference board */
1613 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001614 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001615 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1616 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001617 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1618 "unknown Dell", STAC_DELL_S14),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001619 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001620};
1621
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001622static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001623 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001624 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001625 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1626 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001627};
1628
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001629static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001630 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001631 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001632 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1633 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001634};
1635
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001636static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001637 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1638 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001639 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1640 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001641};
1642
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001643static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001644 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1645 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001646 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1647 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001648};
1649
Matthew Ranostaye035b842007-11-06 11:53:55 +01001650static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1651 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001652 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1653 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001654 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001655 [STAC_HP_M4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001656 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001657 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001658 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001659};
1660
1661static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001662 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001663 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001664 [STAC_DELL_M4_1] = "dell-m4-1",
1665 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001666 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001667 [STAC_HP_M4] = "hp-m4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001668 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001669 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001670 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001671};
1672
1673static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1674 /* SigmaTel reference board */
1675 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1676 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001677 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1678 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001679 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1680 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Takashi Iwai58d83952009-03-13 17:04:34 +01001681 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1682 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001683 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1684 "HP dv4-7", STAC_HP_DV5),
1685 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1686 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001687 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1688 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001689 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001690 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001691 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001692 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai1972d022009-08-06 08:44:43 +02001693 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1694 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001695 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1696 "unknown Dell", STAC_DELL_M4_1),
1697 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1698 "unknown Dell", STAC_DELL_M4_1),
1699 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1700 "unknown Dell", STAC_DELL_M4_1),
1701 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1702 "unknown Dell", STAC_DELL_M4_1),
1703 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1704 "unknown Dell", STAC_DELL_M4_1),
1705 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1706 "unknown Dell", STAC_DELL_M4_1),
1707 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1708 "unknown Dell", STAC_DELL_M4_1),
1709 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1710 "unknown Dell", STAC_DELL_M4_2),
1711 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1712 "unknown Dell", STAC_DELL_M4_2),
1713 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1714 "unknown Dell", STAC_DELL_M4_2),
1715 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1716 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001717 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1718 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001719 {} /* terminator */
1720};
1721
Matt Porter403d1942005-11-29 15:00:51 +01001722static unsigned int ref922x_pin_configs[10] = {
1723 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1724 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001725 0x40000100, 0x40000100,
1726};
1727
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001728/*
1729 STAC 922X pin configs for
1730 102801A7
1731 102801AB
1732 102801A9
1733 102801D1
1734 102801D2
1735*/
1736static unsigned int dell_922x_d81_pin_configs[10] = {
1737 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1738 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1739 0x01813122, 0x400001f2,
1740};
1741
1742/*
1743 STAC 922X pin configs for
1744 102801AC
1745 102801D0
1746*/
1747static unsigned int dell_922x_d82_pin_configs[10] = {
1748 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1749 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1750 0x01813122, 0x400001f1,
1751};
1752
1753/*
1754 STAC 922X pin configs for
1755 102801BF
1756*/
1757static unsigned int dell_922x_m81_pin_configs[10] = {
1758 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1759 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1760 0x40C003f1, 0x405003f0,
1761};
1762
1763/*
1764 STAC 9221 A1 pin configs for
1765 102801D7 (Dell XPS M1210)
1766*/
1767static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001768 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1769 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001770 0x508003f3, 0x405003f4,
1771};
1772
Matt Porter403d1942005-11-29 15:00:51 +01001773static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001774 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001775 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1776 0x02a19120, 0x40000100,
1777};
1778
1779static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001780 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1781 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001782 0x02a19320, 0x40000100,
1783};
1784
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001785static unsigned int intel_mac_v1_pin_configs[10] = {
1786 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1787 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001788 0x400000fc, 0x400000fb,
1789};
1790
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001791static unsigned int intel_mac_v2_pin_configs[10] = {
1792 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1793 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001794 0x400000fc, 0x400000fb,
1795};
1796
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001797static unsigned int intel_mac_v3_pin_configs[10] = {
1798 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1799 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1800 0x400000fc, 0x400000fb,
1801};
1802
1803static unsigned int intel_mac_v4_pin_configs[10] = {
1804 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1805 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1806 0x400000fc, 0x400000fb,
1807};
1808
1809static unsigned int intel_mac_v5_pin_configs[10] = {
1810 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1811 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1812 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001813};
1814
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001815static unsigned int ecs202_pin_configs[10] = {
1816 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1817 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1818 0x9037012e, 0x40e000f2,
1819};
Takashi Iwai76c08822007-06-19 12:17:42 +02001820
Takashi Iwai19039bd2006-06-28 15:52:16 +02001821static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001822 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001823 [STAC_D945GTP3] = d945gtp3_pin_configs,
1824 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001825 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1826 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1827 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1828 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1829 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001830 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001831 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001832 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1833 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1834 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1835 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1836 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1837 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001838 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001839 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1840 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1841 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1842 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001843};
1844
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001845static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001846 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001847 [STAC_D945_REF] = "ref",
1848 [STAC_D945GTP5] = "5stack",
1849 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001850 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1851 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1852 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1853 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1854 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001855 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001856 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001857 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001858 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001859 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1860 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001861 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001862 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001863 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001864 [STAC_922X_DELL_D81] = "dell-d81",
1865 [STAC_922X_DELL_D82] = "dell-d82",
1866 [STAC_922X_DELL_M81] = "dell-m81",
1867 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001868};
1869
1870static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1871 /* SigmaTel reference board */
1872 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1873 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001874 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1875 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001876 /* Intel 945G based systems */
1877 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1878 "Intel D945G", STAC_D945GTP3),
1879 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1880 "Intel D945G", STAC_D945GTP3),
1881 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1882 "Intel D945G", STAC_D945GTP3),
1883 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1884 "Intel D945G", STAC_D945GTP3),
1885 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1886 "Intel D945G", STAC_D945GTP3),
1887 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1888 "Intel D945G", STAC_D945GTP3),
1889 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1890 "Intel D945G", STAC_D945GTP3),
1891 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1892 "Intel D945G", STAC_D945GTP3),
1893 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1894 "Intel D945G", STAC_D945GTP3),
1895 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1896 "Intel D945G", STAC_D945GTP3),
1897 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1898 "Intel D945G", STAC_D945GTP3),
1899 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1900 "Intel D945G", STAC_D945GTP3),
1901 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1902 "Intel D945G", STAC_D945GTP3),
1903 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1904 "Intel D945G", STAC_D945GTP3),
1905 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1906 "Intel D945G", STAC_D945GTP3),
1907 /* Intel D945G 5-stack systems */
1908 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1909 "Intel D945G", STAC_D945GTP5),
1910 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1911 "Intel D945G", STAC_D945GTP5),
1912 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1913 "Intel D945G", STAC_D945GTP5),
1914 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1915 "Intel D945G", STAC_D945GTP5),
1916 /* Intel 945P based systems */
1917 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1918 "Intel D945P", STAC_D945GTP3),
1919 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1920 "Intel D945P", STAC_D945GTP3),
1921 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1922 "Intel D945P", STAC_D945GTP3),
1923 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1924 "Intel D945P", STAC_D945GTP3),
1925 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1926 "Intel D945P", STAC_D945GTP3),
1927 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1928 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01001929 /* other intel */
1930 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
1931 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001932 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08001933 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001934 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001935 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001936 /* Dell systems */
1937 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1938 "unknown Dell", STAC_922X_DELL_D81),
1939 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1940 "unknown Dell", STAC_922X_DELL_D81),
1941 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1942 "unknown Dell", STAC_922X_DELL_D81),
1943 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1944 "unknown Dell", STAC_922X_DELL_D82),
1945 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1946 "unknown Dell", STAC_922X_DELL_M81),
1947 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1948 "unknown Dell", STAC_922X_DELL_D82),
1949 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1950 "unknown Dell", STAC_922X_DELL_D81),
1951 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1952 "unknown Dell", STAC_922X_DELL_D81),
1953 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1954 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001955 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001956 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02001957 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01001958 {} /* terminator */
1959};
1960
Matt Porter3cc08dc2006-01-23 15:27:49 +01001961static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001962 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1963 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1964 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1965 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001966};
1967
Tobin Davis93ed1502006-09-01 21:03:12 +02001968static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001969 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1970 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1971 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1972 0x40000100, 0x40000100
1973};
1974
Tobin Davis93ed1502006-09-01 21:03:12 +02001975static unsigned int d965_5st_pin_configs[14] = {
1976 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1977 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1978 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1979 0x40000100, 0x40000100
1980};
1981
Takashi Iwai679d92e2009-05-24 19:00:08 +02001982static unsigned int d965_5st_no_fp_pin_configs[14] = {
1983 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
1984 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1985 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1986 0x40000100, 0x40000100
1987};
1988
Tobin Davis4ff076e2007-08-07 11:48:12 +02001989static unsigned int dell_3st_pin_configs[14] = {
1990 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1991 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001992 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001993 0x40c003fc, 0x40000100
1994};
1995
Tobin Davis93ed1502006-09-01 21:03:12 +02001996static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01001997 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001998 [STAC_D965_REF] = ref927x_pin_configs,
1999 [STAC_D965_3ST] = d965_3st_pin_configs,
2000 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002001 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002002 [STAC_DELL_3ST] = dell_3st_pin_configs,
2003 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002004};
2005
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002006static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002007 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002008 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002009 [STAC_D965_REF] = "ref",
2010 [STAC_D965_3ST] = "3stack",
2011 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002012 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002013 [STAC_DELL_3ST] = "dell-3stack",
2014 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002015};
2016
2017static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2018 /* SigmaTel reference board */
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2020 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002021 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2022 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002023 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002024 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2025 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002026 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002027 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2028 "Intel D965", STAC_D965_3ST),
2029 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2030 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002031 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002032 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002033 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002034 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2035 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002036 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002037 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2038 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002039 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002040 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002041 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2042 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2043 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2044 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002045 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002046 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2047 "Intel D965", STAC_D965_5ST),
2048 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2049 "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002050 {} /* terminator */
2051};
2052
Matt Porterf3302a52006-07-31 12:49:34 +02002053static unsigned int ref9205_pin_configs[12] = {
2054 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002055 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002056 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002057};
2058
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002059/*
2060 STAC 9205 pin configs for
2061 102801F1
2062 102801F2
2063 102801FC
2064 102801FD
2065 10280204
2066 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002067 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002068*/
2069static unsigned int dell_9205_m42_pin_configs[12] = {
2070 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2071 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2072 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2073};
2074
2075/*
2076 STAC 9205 pin configs for
2077 102801F9
2078 102801FA
2079 102801FE
2080 102801FF (Dell Precision M4300)
2081 10280206
2082 10280200
2083 10280201
2084*/
2085static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002086 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2087 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2088 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2089};
2090
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002091static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002092 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2093 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2094 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2095};
2096
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002097static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002098 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002099 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2100 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2101 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002102 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002103};
2104
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002105static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002106 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002107 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002108 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002109 [STAC_9205_DELL_M43] = "dell-m43",
2110 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002111 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002112};
2113
2114static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2115 /* SigmaTel reference board */
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2117 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002118 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2119 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002120 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2121 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002122 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002123 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2124 "unknown Dell", STAC_9205_DELL_M42),
2125 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2126 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002127 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002128 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002129 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2130 "Dell Precision", STAC_9205_DELL_M43),
2131 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2132 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002133 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2134 "unknown Dell", STAC_9205_DELL_M42),
2135 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2136 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002137 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2138 "Dell Precision", STAC_9205_DELL_M43),
2139 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002140 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002141 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2142 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002143 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2144 "Dell Precision", STAC_9205_DELL_M43),
2145 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2146 "Dell Precision", STAC_9205_DELL_M43),
2147 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2148 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002149 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2150 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002151 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2152 "Dell Vostro 1500", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002153 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002154 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002155 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002156 {} /* terminator */
2157};
2158
Takashi Iwai330ee992009-02-20 14:33:36 +01002159static void stac92xx_set_config_regs(struct hda_codec *codec,
2160 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002161{
2162 int i;
2163 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002164
Takashi Iwai330ee992009-02-20 14:33:36 +01002165 if (!pincfgs)
2166 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002167
Matthew Ranostay87d48362007-07-17 11:52:24 +02002168 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002169 if (spec->pin_nids[i] && pincfgs[i])
2170 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2171 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002172}
2173
Matt2f2f4252005-04-13 14:45:30 +02002174/*
2175 * Analog playback callbacks
2176 */
2177static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2178 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002179 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002180{
2181 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002182 if (spec->stream_delay)
2183 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002184 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2185 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002186}
2187
2188static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2189 struct hda_codec *codec,
2190 unsigned int stream_tag,
2191 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002192 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002193{
2194 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002195 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002196}
2197
2198static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2199 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002200 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002201{
2202 struct sigmatel_spec *spec = codec->spec;
2203 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2204}
2205
2206/*
Mattdabbed62005-06-14 10:19:34 +02002207 * Digital playback callbacks
2208 */
2209static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2210 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002211 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002212{
2213 struct sigmatel_spec *spec = codec->spec;
2214 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2215}
2216
2217static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2218 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002219 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002220{
2221 struct sigmatel_spec *spec = codec->spec;
2222 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2223}
2224
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002225static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2226 struct hda_codec *codec,
2227 unsigned int stream_tag,
2228 unsigned int format,
2229 struct snd_pcm_substream *substream)
2230{
2231 struct sigmatel_spec *spec = codec->spec;
2232 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2233 stream_tag, format, substream);
2234}
2235
Takashi Iwai9411e212009-02-13 11:32:28 +01002236static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2237 struct hda_codec *codec,
2238 struct snd_pcm_substream *substream)
2239{
2240 struct sigmatel_spec *spec = codec->spec;
2241 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2242}
2243
Mattdabbed62005-06-14 10:19:34 +02002244
2245/*
Matt2f2f4252005-04-13 14:45:30 +02002246 * Analog capture callbacks
2247 */
2248static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2249 struct hda_codec *codec,
2250 unsigned int stream_tag,
2251 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002252 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002253{
2254 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002255 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002256
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002257 if (spec->powerdown_adcs) {
2258 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002259 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002260 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2261 }
2262 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002263 return 0;
2264}
2265
2266static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2267 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002268 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002269{
2270 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002271 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002272
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002273 snd_hda_codec_cleanup_stream(codec, nid);
2274 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002275 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002276 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002277 return 0;
2278}
2279
Mattdabbed62005-06-14 10:19:34 +02002280static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2281 .substreams = 1,
2282 .channels_min = 2,
2283 .channels_max = 2,
2284 /* NID is set in stac92xx_build_pcms */
2285 .ops = {
2286 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002287 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002288 .prepare = stac92xx_dig_playback_pcm_prepare,
2289 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002290 },
2291};
2292
2293static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2294 .substreams = 1,
2295 .channels_min = 2,
2296 .channels_max = 2,
2297 /* NID is set in stac92xx_build_pcms */
2298};
2299
Matt2f2f4252005-04-13 14:45:30 +02002300static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2301 .substreams = 1,
2302 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002303 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002304 .nid = 0x02, /* NID to query formats and rates */
2305 .ops = {
2306 .open = stac92xx_playback_pcm_open,
2307 .prepare = stac92xx_playback_pcm_prepare,
2308 .cleanup = stac92xx_playback_pcm_cleanup
2309 },
2310};
2311
Matt Porter3cc08dc2006-01-23 15:27:49 +01002312static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2313 .substreams = 1,
2314 .channels_min = 2,
2315 .channels_max = 2,
2316 .nid = 0x06, /* NID to query formats and rates */
2317 .ops = {
2318 .open = stac92xx_playback_pcm_open,
2319 .prepare = stac92xx_playback_pcm_prepare,
2320 .cleanup = stac92xx_playback_pcm_cleanup
2321 },
2322};
2323
Matt2f2f4252005-04-13 14:45:30 +02002324static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002325 .channels_min = 2,
2326 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002327 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002328 .ops = {
2329 .prepare = stac92xx_capture_pcm_prepare,
2330 .cleanup = stac92xx_capture_pcm_cleanup
2331 },
2332};
2333
2334static int stac92xx_build_pcms(struct hda_codec *codec)
2335{
2336 struct sigmatel_spec *spec = codec->spec;
2337 struct hda_pcm *info = spec->pcm_rec;
2338
2339 codec->num_pcms = 1;
2340 codec->pcm_info = info;
2341
Mattc7d4b2f2005-06-27 14:59:41 +02002342 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002343 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002344 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2345 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002346 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002347 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002348 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002349
2350 if (spec->alt_switch) {
2351 codec->num_pcms++;
2352 info++;
2353 info->name = "STAC92xx Analog Alt";
2354 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2355 }
Matt2f2f4252005-04-13 14:45:30 +02002356
Mattdabbed62005-06-14 10:19:34 +02002357 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2358 codec->num_pcms++;
2359 info++;
2360 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002361 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002362 if (spec->multiout.dig_out_nid) {
2363 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2364 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2365 }
2366 if (spec->dig_in_nid) {
2367 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2368 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2369 }
2370 }
2371
Matt2f2f4252005-04-13 14:45:30 +02002372 return 0;
2373}
2374
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002375static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2376 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002377{
Takashi Iwai1327a322009-03-23 13:07:47 +01002378 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002379 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2380 if (pincap & AC_PINCAP_VREF_100)
2381 return AC_PINCTL_VREF_100;
2382 if (pincap & AC_PINCAP_VREF_80)
2383 return AC_PINCTL_VREF_80;
2384 if (pincap & AC_PINCAP_VREF_50)
2385 return AC_PINCTL_VREF_50;
2386 if (pincap & AC_PINCAP_VREF_GRD)
2387 return AC_PINCTL_VREF_GRD;
2388 return 0;
2389}
2390
Matt Porter403d1942005-11-29 15:00:51 +01002391static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2392
2393{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002394 snd_hda_codec_write_cache(codec, nid, 0,
2395 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002396}
2397
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002398#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2399
2400static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2401 struct snd_ctl_elem_value *ucontrol)
2402{
2403 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2404 struct sigmatel_spec *spec = codec->spec;
2405
Takashi Iwaid7a89432008-11-12 09:48:04 +01002406 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002407 return 0;
2408}
2409
Takashi Iwai62558ce2009-07-29 14:23:09 +02002410static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002411
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002412static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2413 struct snd_ctl_elem_value *ucontrol)
2414{
2415 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2416 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002417 int nid = kcontrol->private_value;
2418
2419 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002420
2421 /* check to be sure that the ports are upto date with
2422 * switch changes
2423 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002424 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002425
2426 return 1;
2427}
2428
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002429static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2430 struct snd_ctl_elem_info *uinfo)
2431{
2432 int i;
2433 static char *texts[] = {
2434 "Mic In", "Line In", "Line Out"
2435 };
2436
2437 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2438 struct sigmatel_spec *spec = codec->spec;
2439 hda_nid_t nid = kcontrol->private_value;
2440
2441 if (nid == spec->mic_switch || nid == spec->line_switch)
2442 i = 3;
2443 else
2444 i = 2;
2445
2446 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2447 uinfo->value.enumerated.items = i;
2448 uinfo->count = 1;
2449 if (uinfo->value.enumerated.item >= i)
2450 uinfo->value.enumerated.item = i-1;
2451 strcpy(uinfo->value.enumerated.name,
2452 texts[uinfo->value.enumerated.item]);
2453
2454 return 0;
2455}
2456
2457static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2458 struct snd_ctl_elem_value *ucontrol)
2459{
2460 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2461 hda_nid_t nid = kcontrol->private_value;
2462 unsigned int vref = stac92xx_vref_get(codec, nid);
2463
2464 if (vref == stac92xx_get_default_vref(codec, nid))
2465 ucontrol->value.enumerated.item[0] = 0;
2466 else if (vref == AC_PINCTL_VREF_GRD)
2467 ucontrol->value.enumerated.item[0] = 1;
2468 else if (vref == AC_PINCTL_VREF_HIZ)
2469 ucontrol->value.enumerated.item[0] = 2;
2470
2471 return 0;
2472}
2473
2474static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2475 struct snd_ctl_elem_value *ucontrol)
2476{
2477 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2478 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002479 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002480 hda_nid_t nid = kcontrol->private_value;
2481
2482 if (ucontrol->value.enumerated.item[0] == 0)
2483 new_vref = stac92xx_get_default_vref(codec, nid);
2484 else if (ucontrol->value.enumerated.item[0] == 1)
2485 new_vref = AC_PINCTL_VREF_GRD;
2486 else if (ucontrol->value.enumerated.item[0] == 2)
2487 new_vref = AC_PINCTL_VREF_HIZ;
2488 else
2489 return 0;
2490
2491 if (new_vref != stac92xx_vref_get(codec, nid)) {
2492 error = stac92xx_vref_set(codec, nid, new_vref);
2493 return error;
2494 }
2495
2496 return 0;
2497}
2498
2499static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2500 struct snd_ctl_elem_info *uinfo)
2501{
2502 static char *texts[2];
2503 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2504 struct sigmatel_spec *spec = codec->spec;
2505
2506 if (kcontrol->private_value == spec->line_switch)
2507 texts[0] = "Line In";
2508 else
2509 texts[0] = "Mic In";
2510 texts[1] = "Line Out";
2511 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2512 uinfo->value.enumerated.items = 2;
2513 uinfo->count = 1;
2514
2515 if (uinfo->value.enumerated.item >= 2)
2516 uinfo->value.enumerated.item = 1;
2517 strcpy(uinfo->value.enumerated.name,
2518 texts[uinfo->value.enumerated.item]);
2519
2520 return 0;
2521}
Matt Porter403d1942005-11-29 15:00:51 +01002522
2523static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2524{
2525 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2526 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002527 hda_nid_t nid = kcontrol->private_value;
2528 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002529
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002530 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002531 return 0;
2532}
2533
2534static int stac92xx_io_switch_put(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;
2540 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002541
2542 spec->io_switch[io_idx] = val;
2543
2544 if (val)
2545 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002546 else {
2547 unsigned int pinctl = AC_PINCTL_IN_EN;
2548 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002549 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002550 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2551 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002552
2553 /* check the auto-mute again: we need to mute/unmute the speaker
2554 * appropriately according to the pin direction
2555 */
2556 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002557 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002558
Matt Porter403d1942005-11-29 15:00:51 +01002559 return 1;
2560}
2561
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002562#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2563
2564static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2565 struct snd_ctl_elem_value *ucontrol)
2566{
2567 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2568 struct sigmatel_spec *spec = codec->spec;
2569
2570 ucontrol->value.integer.value[0] = spec->clfe_swap;
2571 return 0;
2572}
2573
2574static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2575 struct snd_ctl_elem_value *ucontrol)
2576{
2577 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2578 struct sigmatel_spec *spec = codec->spec;
2579 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002580 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002581
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002582 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002583 return 0;
2584
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002585 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002586
2587 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2588 spec->clfe_swap ? 0x4 : 0x0);
2589
2590 return 1;
2591}
2592
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002593#define STAC_CODEC_HP_SWITCH(xname) \
2594 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2595 .name = xname, \
2596 .index = 0, \
2597 .info = stac92xx_hp_switch_info, \
2598 .get = stac92xx_hp_switch_get, \
2599 .put = stac92xx_hp_switch_put, \
2600 }
2601
Matt Porter403d1942005-11-29 15:00:51 +01002602#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2603 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2604 .name = xname, \
2605 .index = 0, \
2606 .info = stac92xx_io_switch_info, \
2607 .get = stac92xx_io_switch_get, \
2608 .put = stac92xx_io_switch_put, \
2609 .private_value = xpval, \
2610 }
2611
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002612#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2613 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2614 .name = xname, \
2615 .index = 0, \
2616 .info = stac92xx_clfe_switch_info, \
2617 .get = stac92xx_clfe_switch_get, \
2618 .put = stac92xx_clfe_switch_put, \
2619 .private_value = xpval, \
2620 }
Matt Porter403d1942005-11-29 15:00:51 +01002621
Mattc7d4b2f2005-06-27 14:59:41 +02002622enum {
2623 STAC_CTL_WIDGET_VOL,
2624 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002625 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002626 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002627 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002628 STAC_CTL_WIDGET_CLFE_SWITCH,
2629 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002630};
2631
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002632static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002633 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2634 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002635 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002636 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002637 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002638 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002639 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002640};
2641
2642/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002643static struct snd_kcontrol_new *
2644stac_control_new(struct sigmatel_spec *spec,
2645 struct snd_kcontrol_new *ktemp,
2646 const char *name)
Mattc7d4b2f2005-06-27 14:59:41 +02002647{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002648 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002649
Takashi Iwai603c4012008-07-30 15:01:44 +02002650 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2651 knew = snd_array_new(&spec->kctls);
2652 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002653 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002654 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002655 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002656 if (!knew->name) {
2657 /* roolback */
2658 memset(knew, 0, sizeof(*knew));
2659 spec->kctls.alloced--;
2660 return NULL;
2661 }
2662 return knew;
2663}
2664
2665static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2666 struct snd_kcontrol_new *ktemp,
2667 int idx, const char *name,
2668 unsigned long val)
2669{
2670 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2671 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002672 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002673 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002674 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002675 return 0;
2676}
2677
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002678static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2679 int type, int idx, const char *name,
2680 unsigned long val)
2681{
2682 return stac92xx_add_control_temp(spec,
2683 &stac92xx_control_templates[type],
2684 idx, name, val);
2685}
2686
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002687
2688/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002689static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2690 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002691{
2692 return stac92xx_add_control_idx(spec, type, 0, name, val);
2693}
2694
Takashi Iwaie3c75962009-01-23 11:57:22 +01002695static struct snd_kcontrol_new stac_input_src_temp = {
2696 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2697 .name = "Input Source",
2698 .info = stac92xx_mux_enum_info,
2699 .get = stac92xx_mux_enum_get,
2700 .put = stac92xx_mux_enum_put,
2701};
2702
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002703static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2704 hda_nid_t nid, int idx)
2705{
2706 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2707 int control = 0;
2708 struct sigmatel_spec *spec = codec->spec;
2709 char name[22];
2710
2711 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2712 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2713 && nid == spec->line_switch)
2714 control = STAC_CTL_WIDGET_IO_SWITCH;
2715 else if (snd_hda_query_pin_caps(codec, nid)
2716 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2717 control = STAC_CTL_WIDGET_DC_BIAS;
2718 else if (nid == spec->mic_switch)
2719 control = STAC_CTL_WIDGET_IO_SWITCH;
2720 }
2721
2722 if (control) {
2723 strcpy(name, auto_pin_cfg_labels[idx]);
2724 return stac92xx_add_control(codec->spec, control,
2725 strcat(name, " Jack Mode"), nid);
2726 }
2727
2728 return 0;
2729}
2730
Takashi Iwaie3c75962009-01-23 11:57:22 +01002731static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2732{
2733 struct snd_kcontrol_new *knew;
2734 struct hda_input_mux *imux = &spec->private_imux;
2735
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002736 if (spec->auto_mic)
2737 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002738 if (!spec->num_adcs || imux->num_items <= 1)
2739 return 0; /* no need for input source control */
2740 knew = stac_control_new(spec, &stac_input_src_temp,
2741 stac_input_src_temp.name);
2742 if (!knew)
2743 return -ENOMEM;
2744 knew->count = spec->num_adcs;
2745 return 0;
2746}
2747
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002748/* check whether the line-input can be used as line-out */
2749static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002750{
2751 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002752 struct auto_pin_cfg *cfg = &spec->autocfg;
2753 hda_nid_t nid;
2754 unsigned int pincap;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002755
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002756 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2757 return 0;
2758 nid = cfg->input_pins[AUTO_PIN_LINE];
Takashi Iwai1327a322009-03-23 13:07:47 +01002759 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002760 if (pincap & AC_PINCAP_OUT)
2761 return nid;
Matt Porter403d1942005-11-29 15:00:51 +01002762 return 0;
2763}
2764
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002765/* check whether the mic-input can be used as line-out */
2766static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2767{
2768 struct sigmatel_spec *spec = codec->spec;
2769 struct auto_pin_cfg *cfg = &spec->autocfg;
2770 unsigned int def_conf, pincap;
2771 unsigned int mic_pin;
2772
2773 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2774 return 0;
2775 mic_pin = AUTO_PIN_MIC;
2776 for (;;) {
2777 hda_nid_t nid = cfg->input_pins[mic_pin];
Takashi Iwai330ee992009-02-20 14:33:36 +01002778 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002779 /* some laptops have an internal analog microphone
2780 * which can't be used as a output */
2781 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai1327a322009-03-23 13:07:47 +01002782 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002783 if (pincap & AC_PINCAP_OUT)
2784 return nid;
2785 }
2786 if (mic_pin == AUTO_PIN_MIC)
2787 mic_pin = AUTO_PIN_FRONT_MIC;
2788 else
2789 break;
2790 }
2791 return 0;
2792}
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002793
2794static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2795{
2796 int i;
2797
2798 for (i = 0; i < spec->multiout.num_dacs; i++) {
2799 if (spec->multiout.dac_nids[i] == nid)
2800 return 1;
2801 }
2802
2803 return 0;
2804}
2805
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002806static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2807{
2808 int i;
2809 if (is_in_dac_nids(spec, nid))
2810 return 1;
2811 for (i = 0; i < spec->autocfg.hp_outs; i++)
2812 if (spec->hp_dacs[i] == nid)
2813 return 1;
2814 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2815 if (spec->speaker_dacs[i] == nid)
2816 return 1;
2817 return 0;
2818}
2819
2820static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2821{
2822 struct sigmatel_spec *spec = codec->spec;
2823 int j, conn_len;
2824 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2825 unsigned int wcaps, wtype;
2826
2827 conn_len = snd_hda_get_connections(codec, nid, conn,
2828 HDA_MAX_CONNECTIONS);
2829 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002830 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002831 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002832 /* we check only analog outputs */
2833 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2834 continue;
2835 /* if this route has a free DAC, assign it */
2836 if (!check_all_dac_nids(spec, conn[j])) {
2837 if (conn_len > 1) {
2838 /* select this DAC in the pin's input mux */
2839 snd_hda_codec_write_cache(codec, nid, 0,
2840 AC_VERB_SET_CONNECT_SEL, j);
2841 }
2842 return conn[j];
2843 }
2844 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002845 /* if all DACs are already assigned, connect to the primary DAC */
2846 if (conn_len > 1) {
2847 for (j = 0; j < conn_len; j++) {
2848 if (conn[j] == spec->multiout.dac_nids[0]) {
2849 snd_hda_codec_write_cache(codec, nid, 0,
2850 AC_VERB_SET_CONNECT_SEL, j);
2851 break;
2852 }
2853 }
2854 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002855 return 0;
2856}
2857
2858static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2859static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2860
Matt Porter3cc08dc2006-01-23 15:27:49 +01002861/*
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002862 * Fill in the dac_nids table from the parsed pin configuration
2863 * This function only works when every pin in line_out_pins[]
2864 * contains atleast one DAC in its connection list. Some 92xx
2865 * codecs are not connected directly to a DAC, such as the 9200
2866 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002867 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002868static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002869{
2870 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002871 struct auto_pin_cfg *cfg = &spec->autocfg;
2872 int i;
2873 hda_nid_t nid, dac;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002874
Mattc7d4b2f2005-06-27 14:59:41 +02002875 for (i = 0; i < cfg->line_outs; i++) {
2876 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002877 dac = get_unassigned_dac(codec, nid);
2878 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002879 if (spec->multiout.num_dacs > 0) {
2880 /* we have already working output pins,
2881 * so let's drop the broken ones again
2882 */
2883 cfg->line_outs = spec->multiout.num_dacs;
2884 break;
2885 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002886 /* error out, no available DAC found */
2887 snd_printk(KERN_ERR
2888 "%s: No available DAC for pin 0x%x\n",
2889 __func__, nid);
2890 return -ENODEV;
2891 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002892 add_spec_dacs(spec, dac);
2893 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002894
Takashi Iwai139e0712009-03-06 12:10:41 +01002895 for (i = 0; i < cfg->hp_outs; i++) {
2896 nid = cfg->hp_pins[i];
2897 dac = get_unassigned_dac(codec, nid);
2898 if (dac) {
2899 if (!spec->multiout.hp_nid)
2900 spec->multiout.hp_nid = dac;
2901 else
2902 add_spec_extra_dacs(spec, dac);
2903 }
2904 spec->hp_dacs[i] = dac;
2905 }
2906
2907 for (i = 0; i < cfg->speaker_outs; i++) {
2908 nid = cfg->speaker_pins[i];
2909 dac = get_unassigned_dac(codec, nid);
2910 if (dac)
2911 add_spec_extra_dacs(spec, dac);
2912 spec->speaker_dacs[i] = dac;
2913 }
2914
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002915 /* add line-in as output */
2916 nid = check_line_out_switch(codec);
2917 if (nid) {
2918 dac = get_unassigned_dac(codec, nid);
2919 if (dac) {
2920 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2921 nid, cfg->line_outs);
2922 cfg->line_out_pins[cfg->line_outs] = nid;
2923 cfg->line_outs++;
2924 spec->line_switch = nid;
2925 add_spec_dacs(spec, dac);
2926 }
2927 }
2928 /* add mic as output */
2929 nid = check_mic_out_switch(codec);
2930 if (nid) {
2931 dac = get_unassigned_dac(codec, nid);
2932 if (dac) {
2933 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
2934 nid, cfg->line_outs);
2935 cfg->line_out_pins[cfg->line_outs] = nid;
2936 cfg->line_outs++;
2937 spec->mic_switch = nid;
2938 add_spec_dacs(spec, dac);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002939 }
Mattc7d4b2f2005-06-27 14:59:41 +02002940 }
2941
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002942 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002943 spec->multiout.num_dacs,
2944 spec->multiout.dac_nids[0],
2945 spec->multiout.dac_nids[1],
2946 spec->multiout.dac_nids[2],
2947 spec->multiout.dac_nids[3],
2948 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002949
Mattc7d4b2f2005-06-27 14:59:41 +02002950 return 0;
2951}
2952
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002953/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01002954static int create_controls_idx(struct hda_codec *codec, const char *pfx,
2955 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002956{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002957 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002958 char name[32];
2959 int err;
2960
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002961 if (!spec->check_volume_offset) {
2962 unsigned int caps, step, nums, db_scale;
2963 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
2964 step = (caps & AC_AMPCAP_STEP_SIZE) >>
2965 AC_AMPCAP_STEP_SIZE_SHIFT;
2966 step = (step + 1) * 25; /* in .01dB unit */
2967 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
2968 AC_AMPCAP_NUM_STEPS_SHIFT;
2969 db_scale = nums * step;
2970 /* if dB scale is over -64dB, and finer enough,
2971 * let's reduce it to half
2972 */
2973 if (db_scale > 6400 && nums >= 0x1f)
2974 spec->volume_offset = nums / 2;
2975 spec->check_volume_offset = 1;
2976 }
2977
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002978 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01002979 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002980 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
2981 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002982 if (err < 0)
2983 return err;
2984 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01002985 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002986 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2987 if (err < 0)
2988 return err;
2989 return 0;
2990}
2991
Takashi Iwai668b9652009-03-06 10:13:24 +01002992#define create_controls(codec, pfx, nid, chs) \
2993 create_controls_idx(codec, pfx, 0, nid, chs)
2994
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002995static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2996{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002997 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002998 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2999 return 1;
3000 } else {
3001 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3002 spec->multiout.num_dacs++;
3003 }
3004 return 0;
3005}
3006
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003007static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003008{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003009 int i;
3010 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3011 if (!spec->multiout.extra_out_nid[i]) {
3012 spec->multiout.extra_out_nid[i] = nid;
3013 return 0;
3014 }
3015 }
3016 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3017 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003018}
3019
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003020/* Create output controls
3021 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3022 */
3023static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3024 const hda_nid_t *pins,
3025 const hda_nid_t *dac_nids,
3026 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003027{
Takashi Iwai76624532008-12-19 10:09:47 +01003028 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003029 static const char *chname[4] = {
3030 "Front", "Surround", NULL /*CLFE*/, "Side"
3031 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003032 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003033 int i, err;
3034 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003035
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003036 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003037 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3038 wid_caps = get_wcaps(codec, pins[i]);
3039 if (wid_caps & AC_WCAP_UNSOL_CAP)
3040 spec->hp_detect = 1;
3041 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003042 nid = dac_nids[i];
3043 if (!nid)
3044 continue;
3045 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003046 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003047 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003048 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003049 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003050 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003051 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003052 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003053
3054 wid_caps = get_wcaps(codec, nid);
3055
3056 if (wid_caps & AC_WCAP_LR_SWAP) {
3057 err = stac92xx_add_control(spec,
3058 STAC_CTL_WIDGET_CLFE_SWITCH,
3059 "Swap Center/LFE Playback Switch", nid);
3060
3061 if (err < 0)
3062 return err;
3063 }
3064
Mattc7d4b2f2005-06-27 14:59:41 +02003065 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003066 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003067 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003068 switch (type) {
3069 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003070 name = "Headphone";
3071 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003072 break;
3073 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003074 name = "Speaker";
3075 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003076 break;
3077 default:
3078 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003079 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003080 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003081 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003082 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003083 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003084 return err;
3085 }
3086 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003087 return 0;
3088}
3089
Takashi Iwai6479c632009-07-28 18:20:25 +02003090static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3091 unsigned long sw, int idx)
3092{
3093 int err;
3094 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd82009-07-30 09:24:29 +02003095 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003096 if (err < 0)
3097 return err;
3098 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd82009-07-30 09:24:29 +02003099 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003100 if (err < 0)
3101 return err;
3102 return 0;
3103}
3104
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003105/* add playback controls from the parsed DAC table */
3106static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3107 const struct auto_pin_cfg *cfg)
3108{
3109 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003110 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003111 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003112 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003113
3114 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3115 spec->multiout.dac_nids,
3116 cfg->line_out_type);
3117 if (err < 0)
3118 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003119
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003120 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003121 err = stac92xx_add_control(spec,
3122 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003123 "Headphone as Line Out Switch",
3124 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003125 if (err < 0)
3126 return err;
3127 }
3128
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003129 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3130 nid = cfg->input_pins[idx];
3131 if (nid) {
3132 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3133 if (err < 0)
3134 return err;
3135 }
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003136 }
Matt Porter403d1942005-11-29 15:00:51 +01003137
Mattc7d4b2f2005-06-27 14:59:41 +02003138 return 0;
3139}
3140
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003141/* add playback controls for Speaker and HP outputs */
3142static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3143 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003144{
3145 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003146 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003147
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003148 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3149 spec->hp_dacs, AUTO_PIN_HP_OUT);
3150 if (err < 0)
3151 return err;
3152
3153 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3154 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3155 if (err < 0)
3156 return err;
3157
Mattc7d4b2f2005-06-27 14:59:41 +02003158 return 0;
3159}
3160
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003161/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003162static const char *stac92xx_mono_labels[4] = {
3163 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003164};
3165
3166/* create mono mux for mono out on capable codecs */
3167static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3168{
3169 struct sigmatel_spec *spec = codec->spec;
3170 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3171 int i, num_cons;
3172 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3173
3174 num_cons = snd_hda_get_connections(codec,
3175 spec->mono_nid,
3176 con_lst,
3177 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003178 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003179 return -EINVAL;
3180
3181 for (i = 0; i < num_cons; i++) {
3182 mono_mux->items[mono_mux->num_items].label =
3183 stac92xx_mono_labels[i];
3184 mono_mux->items[mono_mux->num_items].index = i;
3185 mono_mux->num_items++;
3186 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003187
3188 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3189 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003190}
3191
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003192/* create PC beep volume controls */
3193static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3194 hda_nid_t nid)
3195{
3196 struct sigmatel_spec *spec = codec->spec;
3197 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3198 int err;
3199
3200 /* check for mute support for the the amp */
3201 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3202 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3203 "PC Beep Playback Switch",
3204 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3205 if (err < 0)
3206 return err;
3207 }
3208
3209 /* check to see if there is volume support for the amp */
3210 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3211 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3212 "PC Beep Playback Volume",
3213 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3214 if (err < 0)
3215 return err;
3216 }
3217 return 0;
3218}
3219
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003220#ifdef CONFIG_SND_HDA_INPUT_BEEP
3221#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3222
3223static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3224 struct snd_ctl_elem_value *ucontrol)
3225{
3226 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3227 ucontrol->value.integer.value[0] = codec->beep->enabled;
3228 return 0;
3229}
3230
3231static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3232 struct snd_ctl_elem_value *ucontrol)
3233{
3234 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3235 int enabled = !!ucontrol->value.integer.value[0];
3236 if (codec->beep->enabled != enabled) {
3237 codec->beep->enabled = enabled;
3238 return 1;
3239 }
3240 return 0;
3241}
3242
3243static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3245 .info = stac92xx_dig_beep_switch_info,
3246 .get = stac92xx_dig_beep_switch_get,
3247 .put = stac92xx_dig_beep_switch_put,
3248};
3249
3250static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3251{
3252 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3253 0, "PC Beep Playback Switch", 0);
3254}
3255#endif
3256
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003257static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3258{
3259 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003260 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003261
3262 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003263 hda_nid_t nid;
3264 unsigned int wcaps;
3265 unsigned long val;
3266
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003267 nid = spec->mux_nids[i];
3268 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003269 if (!(wcaps & AC_WCAP_OUT_AMP))
3270 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003271
Takashi Iwai667067d2009-08-13 18:14:42 +02003272 /* check whether already the same control was created as
3273 * normal Capture Volume.
3274 */
3275 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3276 for (j = 0; j < spec->num_caps; j++) {
3277 if (spec->capvols[j] == val)
3278 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003279 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003280 if (j < spec->num_caps)
3281 continue;
3282
3283 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3284 "Mux Capture Volume", val);
3285 if (err < 0)
3286 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003287 }
3288 return 0;
3289};
3290
Matthew Ranostayd9737752008-09-07 12:03:41 +02003291static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003292 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003293};
3294
3295static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3296{
3297 struct sigmatel_spec *spec = codec->spec;
3298 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003299 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003300 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003301 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003302
3303 num_cons = snd_hda_get_connections(codec,
3304 spec->smux_nids[0],
3305 con_lst,
3306 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003307 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003308 return -EINVAL;
3309
Matthew Ranostay65973632008-09-16 10:39:37 -04003310 if (!labels)
3311 labels = stac92xx_spdif_labels;
3312
Matthew Ranostayd9737752008-09-07 12:03:41 +02003313 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003314 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003315 spdif_mux->items[spdif_mux->num_items].index = i;
3316 spdif_mux->num_items++;
3317 }
3318
3319 return 0;
3320}
3321
Matt Porter8b657272006-10-26 17:12:59 +02003322/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003323static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003324 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3325 "Digital Mic 3", "Digital Mic 4"
3326};
3327
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003328static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3329 hda_nid_t nid)
3330{
3331 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3332 int i, nums;
3333
3334 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3335 for (i = 0; i < nums; i++)
3336 if (conn[i] == nid)
3337 return i;
3338 return -1;
3339}
3340
Takashi Iwai667067d2009-08-13 18:14:42 +02003341/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003342/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003343static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003344 const char *label, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003345{
3346 unsigned int caps, nums;
3347 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003348 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003349
Takashi Iwai96f845d2009-08-29 00:49:36 +02003350 if (direction == HDA_OUTPUT)
3351 caps = AC_WCAP_OUT_AMP;
3352 else
3353 caps = AC_WCAP_IN_AMP;
3354 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003355 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003356 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003357 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3358 if (!nums)
3359 return 0;
3360 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003361 err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3362 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3363 if (err < 0)
3364 return err;
3365 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003366}
3367
Matt Porter8b657272006-10-26 17:12:59 +02003368/* create playback/capture controls for input pins on dmic capable codecs */
3369static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3370 const struct auto_pin_cfg *cfg)
3371{
3372 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003373 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003374 struct hda_input_mux *dimux = &spec->private_dimux;
Takashi Iwai5207e102009-07-30 13:09:08 +02003375 int err, i, active_mics;
3376 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003377
3378 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3379 dimux->items[dimux->num_items].index = 0;
3380 dimux->num_items++;
3381
Takashi Iwai5207e102009-07-30 13:09:08 +02003382 active_mics = 0;
3383 for (i = 0; i < spec->num_dmics; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003384 /* check the validity: sometimes it's a dead vendor-spec node */
3385 if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3386 != AC_WID_PIN)
3387 continue;
Takashi Iwai5207e102009-07-30 13:09:08 +02003388 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3389 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3390 active_mics++;
3391 }
3392
Matt Porter8b657272006-10-26 17:12:59 +02003393 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003394 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003395 int index;
Takashi Iwai5207e102009-07-30 13:09:08 +02003396 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003397
Takashi Iwai667067d2009-08-13 18:14:42 +02003398 nid = spec->dmic_nids[i];
3399 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3400 continue;
3401 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003402 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3403 continue;
3404
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003405 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3406 if (index < 0)
3407 continue;
3408
Takashi Iwai5207e102009-07-30 13:09:08 +02003409 if (active_mics == 1)
3410 label = "Digital Mic";
3411 else
3412 label = stac92xx_dmic_labels[dimux->num_items];
3413
Takashi Iwai96f845d2009-08-29 00:49:36 +02003414 err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003415 if (err < 0)
3416 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003417 if (!err) {
3418 err = create_elem_capture_vol(codec, nid, label,
3419 HDA_OUTPUT);
3420 if (err < 0)
3421 return err;
3422 }
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003423
Takashi Iwai5207e102009-07-30 13:09:08 +02003424 dimux->items[dimux->num_items].label = label;
Matt Porter8b657272006-10-26 17:12:59 +02003425 dimux->items[dimux->num_items].index = index;
3426 dimux->num_items++;
Takashi Iwai5207e102009-07-30 13:09:08 +02003427 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3428 imux->items[imux->num_items].label = label;
3429 imux->items[imux->num_items].index = index;
3430 imux->num_items++;
3431 }
Matt Porter8b657272006-10-26 17:12:59 +02003432 }
3433
3434 return 0;
3435}
3436
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003437static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3438 hda_nid_t *fixed, hda_nid_t *ext)
3439{
3440 unsigned int cfg;
3441
3442 if (!nid)
3443 return 0;
3444 cfg = snd_hda_codec_get_pincfg(codec, nid);
3445 switch (get_defcfg_connect(cfg)) {
3446 case AC_JACK_PORT_FIXED:
3447 if (*fixed)
3448 return 1; /* already occupied */
3449 *fixed = nid;
3450 break;
3451 case AC_JACK_PORT_COMPLEX:
3452 if (*ext)
3453 return 1; /* already occupied */
3454 *ext = nid;
3455 break;
3456 }
3457 return 0;
3458}
3459
3460static int set_mic_route(struct hda_codec *codec,
3461 struct sigmatel_mic_route *mic,
3462 hda_nid_t pin)
3463{
3464 struct sigmatel_spec *spec = codec->spec;
3465 struct auto_pin_cfg *cfg = &spec->autocfg;
3466 int i;
3467
3468 mic->pin = pin;
3469 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3470 if (pin == cfg->input_pins[i])
3471 break;
3472 if (i <= AUTO_PIN_FRONT_MIC) {
3473 /* analog pin */
3474 mic->dmux_idx = 0;
3475 i = get_connection_index(codec, spec->mux_nids[0], pin);
3476 if (i < 0)
3477 return -1;
3478 mic->mux_idx = i;
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003479 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003480 /* digital pin */
3481 mic->mux_idx = 0;
3482 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3483 if (i < 0)
3484 return -1;
3485 mic->dmux_idx = i;
3486 }
3487 return 0;
3488}
3489
3490/* return non-zero if the device is for automatic mic switch */
3491static int stac_check_auto_mic(struct hda_codec *codec)
3492{
3493 struct sigmatel_spec *spec = codec->spec;
3494 struct auto_pin_cfg *cfg = &spec->autocfg;
3495 hda_nid_t fixed, ext;
3496 int i;
3497
3498 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3499 if (cfg->input_pins[i])
3500 return 0; /* must be exclusively mics */
3501 }
3502 fixed = ext = 0;
3503 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3504 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3505 return 0;
3506 for (i = 0; i < spec->num_dmics; i++)
3507 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3508 return 0;
3509 if (!fixed || !ext)
3510 return 0;
3511 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3512 return 0; /* no unsol support */
3513 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3514 set_mic_route(codec, &spec->int_mic, fixed))
3515 return 0; /* something is wrong */
3516 return 1;
3517}
3518
Mattc7d4b2f2005-06-27 14:59:41 +02003519/* create playback/capture controls for input pins */
3520static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3521{
3522 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003523 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003524 int i, j;
Mattc7d4b2f2005-06-27 14:59:41 +02003525
3526 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003527 hda_nid_t nid = cfg->input_pins[i];
3528 int index, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003529
Takashi Iwai667067d2009-08-13 18:14:42 +02003530 if (!nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02003531 continue;
3532 index = -1;
3533 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003534 index = get_connection_index(codec, spec->mux_nids[j],
3535 nid);
3536 if (index >= 0)
3537 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003538 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003539 if (index < 0)
3540 continue;
3541
3542 err = create_elem_capture_vol(codec, nid,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003543 auto_pin_cfg_labels[i],
3544 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003545 if (err < 0)
3546 return err;
3547
Takashi Iwai314634b2006-09-21 11:56:18 +02003548 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3549 imux->items[imux->num_items].index = index;
3550 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003551 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003552 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003553
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003554 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003555 /*
3556 * Set the current input for the muxes.
3557 * The STAC9221 has two input muxes with identical source
3558 * NID lists. Hopefully this won't get confused.
3559 */
3560 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003561 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3562 AC_VERB_SET_CONNECT_SEL,
3563 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003564 }
3565 }
3566
Mattc7d4b2f2005-06-27 14:59:41 +02003567 return 0;
3568}
3569
Mattc7d4b2f2005-06-27 14:59:41 +02003570static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3571{
3572 struct sigmatel_spec *spec = codec->spec;
3573 int i;
3574
3575 for (i = 0; i < spec->autocfg.line_outs; i++) {
3576 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3577 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3578 }
3579}
3580
3581static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3582{
3583 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003584 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003585
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003586 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3587 hda_nid_t pin;
3588 pin = spec->autocfg.hp_pins[i];
3589 if (pin) /* connect to front */
3590 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3591 }
3592 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3593 hda_nid_t pin;
3594 pin = spec->autocfg.speaker_pins[i];
3595 if (pin) /* connect to front */
3596 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3597 }
Mattc7d4b2f2005-06-27 14:59:41 +02003598}
3599
Matt Porter3cc08dc2006-01-23 15:27:49 +01003600static 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 +02003601{
3602 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003603 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003604 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003605
Matt Porter8b657272006-10-26 17:12:59 +02003606 if ((err = snd_hda_parse_pin_def_config(codec,
3607 &spec->autocfg,
3608 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003609 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003610 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003611 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003612
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003613 /* If we have no real line-out pin and multiple hp-outs, HPs should
3614 * be set up as multi-channel outputs.
3615 */
3616 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3617 spec->autocfg.hp_outs > 1) {
3618 /* Copy hp_outs to line_outs, backup line_outs in
3619 * speaker_outs so that the following routines can handle
3620 * HP pins as primary outputs.
3621 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003622 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003623 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3624 sizeof(spec->autocfg.line_out_pins));
3625 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3626 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3627 sizeof(spec->autocfg.hp_pins));
3628 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003629 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3630 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003631 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003632 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003633 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003634 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3635 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003636 u32 caps = query_amp_caps(codec,
3637 spec->autocfg.mono_out_pin, dir);
3638 hda_nid_t conn_list[1];
3639
3640 /* get the mixer node and then the mono mux if it exists */
3641 if (snd_hda_get_connections(codec,
3642 spec->autocfg.mono_out_pin, conn_list, 1) &&
3643 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003644 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003645
3646 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003647 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003648 /* LR swap check, some stac925x have a mux that
3649 * changes the DACs output path instead of the
3650 * mono-mux path.
3651 */
3652 if (wid_type == AC_WID_AUD_SEL &&
3653 !(wcaps & AC_WCAP_LR_SWAP))
3654 spec->mono_nid = conn_list[0];
3655 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003656 if (dir) {
3657 hda_nid_t nid = spec->autocfg.mono_out_pin;
3658
3659 /* most mono outs have a least a mute/unmute switch */
3660 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3661 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3662 "Mono Playback Switch",
3663 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003664 if (err < 0)
3665 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003666 /* check for volume support for the amp */
3667 if ((caps & AC_AMPCAP_NUM_STEPS)
3668 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3669 err = stac92xx_add_control(spec,
3670 STAC_CTL_WIDGET_VOL,
3671 "Mono Playback Volume",
3672 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3673 if (err < 0)
3674 return err;
3675 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003676 }
3677
3678 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3679 AC_PINCTL_OUT_EN);
3680 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003681
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003682 if (!spec->multiout.num_dacs) {
3683 err = stac92xx_auto_fill_dac_nids(codec);
3684 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003685 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003686 err = stac92xx_auto_create_multi_out_ctls(codec,
3687 &spec->autocfg);
3688 if (err < 0)
3689 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003690 }
Mattc7d4b2f2005-06-27 14:59:41 +02003691
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003692 /* setup analog beep controls */
3693 if (spec->anabeep_nid > 0) {
3694 err = stac92xx_auto_create_beep_ctls(codec,
3695 spec->anabeep_nid);
3696 if (err < 0)
3697 return err;
3698 }
3699
3700 /* setup digital beep controls and input device */
3701#ifdef CONFIG_SND_HDA_INPUT_BEEP
3702 if (spec->digbeep_nid > 0) {
3703 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003704 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003705
3706 err = stac92xx_auto_create_beep_ctls(codec, nid);
3707 if (err < 0)
3708 return err;
3709 err = snd_hda_attach_beep_device(codec, nid);
3710 if (err < 0)
3711 return err;
Takashi Iwaifa797962009-05-19 12:50:04 +02003712 /* IDT/STAC codecs have linear beep tone parameter */
3713 codec->beep->linear_tone = 1;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003714 /* if no beep switch is available, make its own one */
3715 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3716 if (codec->beep &&
3717 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3718 err = stac92xx_beep_switch_ctl(codec);
3719 if (err < 0)
3720 return err;
3721 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003722 }
3723#endif
3724
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003725 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003726 if (err < 0)
3727 return err;
3728
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003729 /* All output parsing done, now restore the swapped hp pins */
3730 if (hp_swap) {
3731 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3732 sizeof(spec->autocfg.hp_pins));
3733 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3734 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3735 spec->autocfg.line_outs = 0;
3736 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003737
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003738 if (stac_check_auto_mic(codec)) {
3739 spec->auto_mic = 1;
3740 /* only one capture for auto-mic */
3741 spec->num_adcs = 1;
3742 spec->num_caps = 1;
3743 spec->num_muxes = 1;
3744 }
3745
Takashi Iwai6479c632009-07-28 18:20:25 +02003746 for (i = 0; i < spec->num_caps; i++) {
3747 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3748 spec->capsws[i], i);
3749 if (err < 0)
3750 return err;
3751 }
3752
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003753 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003754 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003755 return err;
3756
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003757 if (spec->mono_nid > 0) {
3758 err = stac92xx_auto_create_mono_output_ctls(codec);
3759 if (err < 0)
3760 return err;
3761 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003762 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003763 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3764 &spec->autocfg)) < 0)
3765 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003766 if (spec->num_muxes > 0) {
3767 err = stac92xx_auto_create_mux_input_ctls(codec);
3768 if (err < 0)
3769 return err;
3770 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003771 if (spec->num_smuxes > 0) {
3772 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3773 if (err < 0)
3774 return err;
3775 }
Matt Porter8b657272006-10-26 17:12:59 +02003776
Takashi Iwaie3c75962009-01-23 11:57:22 +01003777 err = stac92xx_add_input_source(spec);
3778 if (err < 0)
3779 return err;
3780
Mattc7d4b2f2005-06-27 14:59:41 +02003781 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003782 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003783 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003784
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003785 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003786 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003787 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003788 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003789
Takashi Iwai603c4012008-07-30 15:01:44 +02003790 if (spec->kctls.list)
3791 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003792
3793 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003794 if (!spec->dinput_mux)
3795 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003796 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003797 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003798 return 1;
3799}
3800
Takashi Iwai82bc9552006-03-21 11:24:42 +01003801/* add playback controls for HP output */
3802static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3803 struct auto_pin_cfg *cfg)
3804{
3805 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003806 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003807 unsigned int wid_caps;
3808
3809 if (! pin)
3810 return 0;
3811
3812 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003813 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003814 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003815
3816 return 0;
3817}
3818
Richard Fish160ea0d2006-09-06 13:58:25 +02003819/* add playback controls for LFE output */
3820static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3821 struct auto_pin_cfg *cfg)
3822{
3823 struct sigmatel_spec *spec = codec->spec;
3824 int err;
3825 hda_nid_t lfe_pin = 0x0;
3826 int i;
3827
3828 /*
3829 * search speaker outs and line outs for a mono speaker pin
3830 * with an amp. If one is found, add LFE controls
3831 * for it.
3832 */
3833 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3834 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003835 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003836 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3837 if (wcaps == AC_WCAP_OUT_AMP)
3838 /* found a mono speaker with an amp, must be lfe */
3839 lfe_pin = pin;
3840 }
3841
3842 /* if speaker_outs is 0, then speakers may be in line_outs */
3843 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3844 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3845 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003846 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01003847 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01003848 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003849 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003850 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3851 if (wcaps == AC_WCAP_OUT_AMP)
3852 /* found a mono speaker with an amp,
3853 must be lfe */
3854 lfe_pin = pin;
3855 }
3856 }
3857 }
3858
3859 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003860 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003861 if (err < 0)
3862 return err;
3863 }
3864
3865 return 0;
3866}
3867
Mattc7d4b2f2005-06-27 14:59:41 +02003868static int stac9200_parse_auto_config(struct hda_codec *codec)
3869{
3870 struct sigmatel_spec *spec = codec->spec;
3871 int err;
3872
Kailang Yangdf694da2005-12-05 19:42:22 +01003873 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003874 return err;
3875
3876 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3877 return err;
3878
Takashi Iwai82bc9552006-03-21 11:24:42 +01003879 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3880 return err;
3881
Richard Fish160ea0d2006-09-06 13:58:25 +02003882 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3883 return err;
3884
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003885 if (spec->num_muxes > 0) {
3886 err = stac92xx_auto_create_mux_input_ctls(codec);
3887 if (err < 0)
3888 return err;
3889 }
3890
Takashi Iwaie3c75962009-01-23 11:57:22 +01003891 err = stac92xx_add_input_source(spec);
3892 if (err < 0)
3893 return err;
3894
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003895 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02003896 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003897 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003898 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003899
Takashi Iwai603c4012008-07-30 15:01:44 +02003900 if (spec->kctls.list)
3901 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003902
3903 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003904 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003905
3906 return 1;
3907}
3908
Sam Revitch62fe78e2006-05-10 15:09:17 +02003909/*
3910 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3911 * funky external mute control using GPIO pins.
3912 */
3913
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003914static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003915 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003916{
3917 unsigned int gpiostate, gpiomask, gpiodir;
3918
3919 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3920 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003921 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003922
3923 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3924 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003925 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003926
3927 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3928 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003929 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003930
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003931 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003932 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3933
3934 snd_hda_codec_write(codec, codec->afg, 0,
3935 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003936 snd_hda_codec_read(codec, codec->afg, 0,
3937 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003938
3939 msleep(1);
3940
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003941 snd_hda_codec_read(codec, codec->afg, 0,
3942 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003943}
3944
Takashi Iwai8c8145b2009-06-22 17:00:38 +02003945#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +02003946static void stac92xx_free_jack_priv(struct snd_jack *jack)
3947{
3948 struct sigmatel_jack *jacks = jack->private_data;
3949 jacks->nid = 0;
3950 jacks->jack = NULL;
3951}
3952#endif
3953
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003954static int stac92xx_add_jack(struct hda_codec *codec,
3955 hda_nid_t nid, int type)
3956{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02003957#ifdef CONFIG_SND_HDA_INPUT_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003958 struct sigmatel_spec *spec = codec->spec;
3959 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01003960 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003961 int connectivity = get_defcfg_connect(def_conf);
3962 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02003963 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003964
3965 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3966 return 0;
3967
3968 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3969 jack = snd_array_new(&spec->jacks);
3970 if (!jack)
3971 return -ENOMEM;
3972 jack->nid = nid;
3973 jack->type = type;
3974
Takashi Iwai86de7412009-07-22 16:02:46 +02003975 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003976 snd_hda_get_jack_type(def_conf),
3977 snd_hda_get_jack_connectivity(def_conf),
3978 snd_hda_get_jack_location(def_conf));
3979
Takashi Iwai95c09092009-04-14 16:15:29 +02003980 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
3981 if (err < 0) {
3982 jack->nid = 0;
3983 return err;
3984 }
3985 jack->jack->private_data = jack;
3986 jack->jack->private_free = stac92xx_free_jack_priv;
Takashi Iwaie4973e12008-11-18 09:32:42 +01003987#endif
Takashi Iwai95c09092009-04-14 16:15:29 +02003988 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003989}
3990
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003991static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3992 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003993{
3994 struct sigmatel_event *event;
3995
3996 snd_array_init(&spec->events, sizeof(*event), 32);
3997 event = snd_array_new(&spec->events);
3998 if (!event)
3999 return -ENOMEM;
4000 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004001 event->type = type;
4002 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004003 event->data = data;
4004
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004005 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004006}
4007
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004008static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004009 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004010{
4011 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004012 struct sigmatel_event *event = spec->events.list;
4013 int i;
4014
4015 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004016 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004017 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004018 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004019 return NULL;
4020}
4021
4022static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4023 unsigned char tag)
4024{
4025 struct sigmatel_spec *spec = codec->spec;
4026 struct sigmatel_event *event = spec->events.list;
4027 int i;
4028
4029 for (i = 0; i < spec->events.used; i++, event++) {
4030 if (event->tag == tag)
4031 return event;
4032 }
4033 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004034}
4035
Takashi Iwai62558ce2009-07-29 14:23:09 +02004036/* check if given nid is a valid pin and no other events are assigned
4037 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4038 * Otherwise, returns zero.
4039 */
4040static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4041 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004042{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004043 struct sigmatel_event *event;
4044 int tag;
4045
4046 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004047 return 0;
4048 event = stac_get_event(codec, nid);
4049 if (event) {
4050 if (event->type != type)
4051 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004052 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004053 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004054 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004055 if (tag < 0)
4056 return 0;
4057 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004058 snd_hda_codec_write_cache(codec, nid, 0,
4059 AC_VERB_SET_UNSOLICITED_ENABLE,
4060 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004061 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004062}
4063
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004064static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4065{
4066 int i;
4067 for (i = 0; i < cfg->hp_outs; i++)
4068 if (cfg->hp_pins[i] == nid)
4069 return 1; /* nid is a HP-Out */
4070
4071 return 0; /* nid is not a HP-Out */
4072};
4073
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004074static void stac92xx_power_down(struct hda_codec *codec)
4075{
4076 struct sigmatel_spec *spec = codec->spec;
4077
4078 /* power down inactive DACs */
4079 hda_nid_t *dac;
4080 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004081 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004082 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004083 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4084}
4085
Takashi Iwaif73d3582008-11-25 08:21:51 +01004086static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4087 int enable);
4088
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004089/* override some hints from the hwdep entry */
4090static void stac_store_hints(struct hda_codec *codec)
4091{
4092 struct sigmatel_spec *spec = codec->spec;
4093 const char *p;
4094 int val;
4095
4096 val = snd_hda_get_bool_hint(codec, "hp_detect");
4097 if (val >= 0)
4098 spec->hp_detect = val;
4099 p = snd_hda_get_hint(codec, "gpio_mask");
4100 if (p) {
4101 spec->gpio_mask = simple_strtoul(p, NULL, 0);
4102 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4103 spec->gpio_mask;
4104 }
4105 p = snd_hda_get_hint(codec, "gpio_dir");
4106 if (p)
4107 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4108 p = snd_hda_get_hint(codec, "gpio_data");
4109 if (p)
4110 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4111 p = snd_hda_get_hint(codec, "eapd_mask");
4112 if (p)
4113 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4114 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4115 if (val >= 0)
4116 spec->eapd_switch = val;
4117}
4118
Mattc7d4b2f2005-06-27 14:59:41 +02004119static int stac92xx_init(struct hda_codec *codec)
4120{
4121 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004122 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004123 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004124 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004125
Mattc7d4b2f2005-06-27 14:59:41 +02004126 snd_hda_sequence_write(codec, spec->init);
4127
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004128 /* power down adcs initially */
4129 if (spec->powerdown_adcs)
4130 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004131 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004132 spec->adc_nids[i], 0,
4133 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004134
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004135 /* override some hints */
4136 stac_store_hints(codec);
4137
Takashi Iwaif73d3582008-11-25 08:21:51 +01004138 /* set up GPIO */
4139 gpio = spec->gpio_data;
4140 /* turn on EAPD statically when spec->eapd_switch isn't set.
4141 * otherwise, unsol event will turn it on/off dynamically
4142 */
4143 if (!spec->eapd_switch)
4144 gpio |= spec->eapd_mask;
4145 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4146
Takashi Iwai82bc9552006-03-21 11:24:42 +01004147 /* set up pins */
4148 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004149 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004150 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004151 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004152 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004153 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004154 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4155 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004156 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004157 for (i = 0; i < cfg->line_outs; i++) {
4158 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004159 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4160 }
4161 }
4162
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004163 /* force to enable the first line-out; the others are set up
4164 * in unsol_event
4165 */
4166 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004167 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004168 /* fake event to set up pins */
Takashi Iwai62558ce2009-07-29 14:23:09 +02004169 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004170 } else {
4171 stac92xx_auto_init_multi_out(codec);
4172 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004173 for (i = 0; i < cfg->hp_outs; i++)
4174 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004175 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004176 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004177 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004178 if (spec->dmux_nids)
4179 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004180 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004181 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4182 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4183 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004184 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01004185 hda_nid_t nid = cfg->input_pins[i];
4186 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004187 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004188 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4189 /* for mic pins, force to initialize */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02004190 pinctl = stac92xx_get_default_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004191 pinctl |= AC_PINCTL_IN_EN;
4192 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004193 } else {
4194 pinctl = snd_hda_codec_read(codec, nid, 0,
4195 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4196 /* if PINCTL already set then skip */
Takashi Iwai5dd17cb2009-05-07 16:22:53 +02004197 /* Also, if both INPUT and OUTPUT are set,
4198 * it must be a BIOS bug; need to override, too
4199 */
4200 if (!(pinctl & AC_PINCTL_IN_EN) ||
4201 (pinctl & AC_PINCTL_OUT_EN)) {
4202 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004203 pinctl |= AC_PINCTL_IN_EN;
4204 stac92xx_auto_set_pinctl(codec, nid,
4205 pinctl);
4206 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004207 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004208 conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004209 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004210 if (enable_pin_detect(codec, nid,
4211 STAC_INSERT_EVENT))
4212 stac_issue_unsol_event(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004213 }
Takashi Iwaic960a032006-03-23 17:06:28 +01004214 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004215 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004216 for (i = 0; i < spec->num_dmics; i++)
4217 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4218 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004219 if (cfg->dig_out_pins[0])
4220 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004221 AC_PINCTL_OUT_EN);
4222 if (cfg->dig_in_pin)
4223 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4224 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004225 for (i = 0; i < spec->num_pwrs; i++) {
4226 hda_nid_t nid = spec->pwr_nids[i];
4227 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004228
Takashi Iwaieb632122008-12-19 16:39:48 +01004229 /* power on when no jack detection is available */
4230 if (!spec->hp_detect) {
4231 stac_toggle_power_map(codec, nid, 1);
4232 continue;
4233 }
4234
4235 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004236 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004237
Takashi Iwaif73d3582008-11-25 08:21:51 +01004238 pinctl = snd_hda_codec_read(codec, nid, 0,
4239 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4240 /* outputs are only ports capable of power management
4241 * any attempts on powering down a input port cause the
4242 * referenced VREF to act quirky.
4243 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004244 if (pinctl & AC_PINCTL_IN_EN) {
4245 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004246 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004247 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004248 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004249 def_conf = get_defcfg_connect(def_conf);
4250 /* skip any ports that don't have jacks since presence
4251 * detection is useless */
4252 if (def_conf != AC_JACK_PORT_COMPLEX) {
4253 if (def_conf != AC_JACK_PORT_NONE)
4254 stac_toggle_power_map(codec, nid, 1);
4255 continue;
4256 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004257 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4258 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004259 }
4260 if (spec->dac_list)
4261 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004262 return 0;
4263}
4264
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004265static void stac92xx_free_jacks(struct hda_codec *codec)
4266{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004267#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01004268 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004269 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01004270 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004271 struct sigmatel_jack *jacks = spec->jacks.list;
4272 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +02004273 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4274 if (jacks->jack)
4275 snd_device_free(codec->bus->card, jacks->jack);
4276 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004277 }
4278 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004279#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004280}
4281
Takashi Iwai603c4012008-07-30 15:01:44 +02004282static void stac92xx_free_kctls(struct hda_codec *codec)
4283{
4284 struct sigmatel_spec *spec = codec->spec;
4285
4286 if (spec->kctls.list) {
4287 struct snd_kcontrol_new *kctl = spec->kctls.list;
4288 int i;
4289 for (i = 0; i < spec->kctls.used; i++)
4290 kfree(kctl[i].name);
4291 }
4292 snd_array_free(&spec->kctls);
4293}
4294
Matt2f2f4252005-04-13 14:45:30 +02004295static void stac92xx_free(struct hda_codec *codec)
4296{
Mattc7d4b2f2005-06-27 14:59:41 +02004297 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004298
4299 if (! spec)
4300 return;
4301
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004302 stac92xx_free_jacks(codec);
4303 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004304
Mattc7d4b2f2005-06-27 14:59:41 +02004305 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004306 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004307}
4308
Matt4e550962005-07-04 17:51:39 +02004309static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4310 unsigned int flag)
4311{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004312 unsigned int old_ctl, pin_ctl;
4313
4314 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004315 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004316
Takashi Iwaif9acba42007-05-29 18:01:06 +02004317 if (pin_ctl & AC_PINCTL_IN_EN) {
4318 /*
4319 * we need to check the current set-up direction of
4320 * shared input pins since they can be switched via
4321 * "xxx as Output" mixer switch
4322 */
4323 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004324 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004325 return;
4326 }
4327
Takashi Iwai8ce84192009-01-22 16:59:20 +01004328 old_ctl = pin_ctl;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004329 /* if setting pin direction bits, clear the current
4330 direction bits first */
4331 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4332 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4333
Takashi Iwai8ce84192009-01-22 16:59:20 +01004334 pin_ctl |= flag;
4335 if (old_ctl != pin_ctl)
4336 snd_hda_codec_write_cache(codec, nid, 0,
4337 AC_VERB_SET_PIN_WIDGET_CONTROL,
4338 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004339}
4340
4341static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4342 unsigned int flag)
4343{
4344 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4345 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004346 if (pin_ctl & flag)
4347 snd_hda_codec_write_cache(codec, nid, 0,
4348 AC_VERB_SET_PIN_WIDGET_CONTROL,
4349 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004350}
4351
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004352static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004353{
4354 if (!nid)
4355 return 0;
4356 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004357 & (1 << 31))
4358 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004359 return 0;
4360}
4361
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004362static void stac92xx_line_out_detect(struct hda_codec *codec,
4363 int presence)
4364{
4365 struct sigmatel_spec *spec = codec->spec;
4366 struct auto_pin_cfg *cfg = &spec->autocfg;
4367 int i;
4368
4369 for (i = 0; i < cfg->line_outs; i++) {
4370 if (presence)
4371 break;
4372 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4373 if (presence) {
4374 unsigned int pinctl;
4375 pinctl = snd_hda_codec_read(codec,
4376 cfg->line_out_pins[i], 0,
4377 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4378 if (pinctl & AC_PINCTL_IN_EN)
4379 presence = 0; /* mic- or line-input */
4380 }
4381 }
4382
4383 if (presence) {
4384 /* disable speakers */
4385 for (i = 0; i < cfg->speaker_outs; i++)
4386 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4387 AC_PINCTL_OUT_EN);
4388 if (spec->eapd_mask && spec->eapd_switch)
4389 stac_gpio_set(codec, spec->gpio_mask,
4390 spec->gpio_dir, spec->gpio_data &
4391 ~spec->eapd_mask);
4392 } else {
4393 /* enable speakers */
4394 for (i = 0; i < cfg->speaker_outs; i++)
4395 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4396 AC_PINCTL_OUT_EN);
4397 if (spec->eapd_mask && spec->eapd_switch)
4398 stac_gpio_set(codec, spec->gpio_mask,
4399 spec->gpio_dir, spec->gpio_data |
4400 spec->eapd_mask);
4401 }
4402}
4403
Takashi Iwaid7a89432008-11-12 09:48:04 +01004404/* return non-zero if the hp-pin of the given array index isn't
4405 * a jack-detection target
4406 */
4407static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4408{
4409 struct auto_pin_cfg *cfg = &spec->autocfg;
4410
4411 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004412 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004413 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004414 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004415 return 1;
4416 /* ignore if the pin is set as line-out */
4417 if (cfg->hp_pins[i] == spec->hp_switch)
4418 return 1;
4419 return 0;
4420}
4421
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004422static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004423{
4424 struct sigmatel_spec *spec = codec->spec;
4425 struct auto_pin_cfg *cfg = &spec->autocfg;
4426 int i, presence;
4427
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004428 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004429 if (spec->gpio_mute)
4430 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4431 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4432
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004433 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004434 if (presence)
4435 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004436 if (no_hp_sensing(spec, i))
4437 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004438 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4439 if (presence) {
4440 unsigned int pinctl;
4441 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4442 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4443 if (pinctl & AC_PINCTL_IN_EN)
4444 presence = 0; /* mic- or line-input */
4445 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004446 }
Matt4e550962005-07-04 17:51:39 +02004447
4448 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004449 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004450 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004451 stac92xx_reset_pinctl(codec, spec->hp_switch,
4452 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004453 for (i = 0; i < cfg->line_outs; i++)
4454 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4455 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004456 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004457 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004458 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004459 stac92xx_set_pinctl(codec, spec->hp_switch,
4460 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004461 for (i = 0; i < cfg->line_outs; i++)
4462 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4463 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004464 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004465 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004466 /* toggle hp outs */
4467 for (i = 0; i < cfg->hp_outs; i++) {
4468 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4469 if (no_hp_sensing(spec, i))
4470 continue;
4471 if (presence)
4472 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004473#if 0 /* FIXME */
4474/* Resetting the pinctl like below may lead to (a sort of) regressions
4475 * on some devices since they use the HP pin actually for line/speaker
4476 * outs although the default pin config shows a different pin (that is
4477 * wrong and useless).
4478 *
4479 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4480 * But, disabling the code below just works around it, and I'm too tired of
4481 * bug reports with such devices...
4482 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004483 else
4484 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004485#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004486 }
Matt4e550962005-07-04 17:51:39 +02004487}
4488
Takashi Iwaif73d3582008-11-25 08:21:51 +01004489static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4490 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004491{
4492 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004493 unsigned int idx, val;
4494
4495 for (idx = 0; idx < spec->num_pwrs; idx++) {
4496 if (spec->pwr_nids[idx] == nid)
4497 break;
4498 }
4499 if (idx >= spec->num_pwrs)
4500 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004501
4502 /* several codecs have two power down bits */
4503 if (spec->pwr_mapping)
4504 idx = spec->pwr_mapping[idx];
4505 else
4506 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004507
Takashi Iwaif73d3582008-11-25 08:21:51 +01004508 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4509 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004510 val &= ~idx;
4511 else
4512 val |= idx;
4513
4514 /* power down unused output ports */
4515 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004516}
4517
Takashi Iwaif73d3582008-11-25 08:21:51 +01004518static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4519{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004520 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004521}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004522
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004523static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4524{
4525 struct sigmatel_spec *spec = codec->spec;
4526 struct sigmatel_jack *jacks = spec->jacks.list;
4527
4528 if (jacks) {
4529 int i;
4530 for (i = 0; i < spec->jacks.used; i++) {
4531 if (jacks->nid == nid) {
4532 unsigned int pin_ctl =
4533 snd_hda_codec_read(codec, nid,
4534 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4535 0x00);
4536 int type = jacks->type;
4537 if (type == (SND_JACK_LINEOUT
4538 | SND_JACK_HEADPHONE))
4539 type = (pin_ctl & AC_PINCTL_HP_EN)
4540 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4541 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004542 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004543 ? type : 0);
4544 }
4545 jacks++;
4546 }
4547 }
4548}
Matt2f2f4252005-04-13 14:45:30 +02004549
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004550static void stac92xx_mic_detect(struct hda_codec *codec)
4551{
4552 struct sigmatel_spec *spec = codec->spec;
4553 struct sigmatel_mic_route *mic;
4554
4555 if (get_pin_presence(codec, spec->ext_mic.pin))
4556 mic = &spec->ext_mic;
4557 else
4558 mic = &spec->int_mic;
4559 if (mic->dmux_idx)
4560 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4561 AC_VERB_SET_CONNECT_SEL,
4562 mic->dmux_idx);
4563 else
4564 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4565 AC_VERB_SET_CONNECT_SEL,
4566 mic->mux_idx);
4567}
4568
Takashi Iwai62558ce2009-07-29 14:23:09 +02004569static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004570{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004571 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004572 if (!event)
4573 return;
4574 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4575}
4576
Takashi Iwai314634b2006-09-21 11:56:18 +02004577static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4578{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004579 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004580 struct sigmatel_event *event;
4581 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004582
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004583 tag = (res >> 26) & 0x7f;
4584 event = stac_get_event_from_tag(codec, tag);
4585 if (!event)
4586 return;
4587
4588 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004589 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004590 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004591 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004592 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004593 case STAC_MIC_EVENT:
4594 stac92xx_mic_detect(codec);
4595 break;
4596 }
4597
4598 switch (event->type) {
4599 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004600 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004601 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004602 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004603 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004604 if (spec->num_pwrs > 0)
4605 stac92xx_pin_sense(codec, event->nid);
4606 stac92xx_report_jack(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004607
4608 switch (codec->subsystem_id) {
4609 case 0x103c308f:
4610 if (event->nid == 0xb) {
4611 int pin = AC_PINCTL_IN_EN;
4612
4613 if (get_pin_presence(codec, 0xa)
4614 && get_pin_presence(codec, 0xb))
4615 pin |= AC_PINCTL_VREF_80;
4616 if (!get_pin_presence(codec, 0xb))
4617 pin |= AC_PINCTL_VREF_80;
4618
4619 /* toggle VREF state based on mic + hp pin
4620 * status
4621 */
4622 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4623 }
4624 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004625 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004626 case STAC_VREF_EVENT:
4627 data = snd_hda_codec_read(codec, codec->afg, 0,
4628 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004629 /* toggle VREF state based on GPIOx status */
4630 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004631 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004632 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004633 }
4634}
4635
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004636#ifdef CONFIG_PROC_FS
4637static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4638 struct hda_codec *codec, hda_nid_t nid)
4639{
4640 if (nid == codec->afg)
4641 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4642 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4643}
4644
4645static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4646 struct hda_codec *codec,
4647 unsigned int verb)
4648{
4649 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4650 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4651}
4652
4653/* stac92hd71bxx, stac92hd73xx */
4654static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4655 struct hda_codec *codec, hda_nid_t nid)
4656{
4657 stac92hd_proc_hook(buffer, codec, nid);
4658 if (nid == codec->afg)
4659 analog_loop_proc_hook(buffer, codec, 0xfa0);
4660}
4661
4662static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4663 struct hda_codec *codec, hda_nid_t nid)
4664{
4665 if (nid == codec->afg)
4666 analog_loop_proc_hook(buffer, codec, 0xfe0);
4667}
4668
4669static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4670 struct hda_codec *codec, hda_nid_t nid)
4671{
4672 if (nid == codec->afg)
4673 analog_loop_proc_hook(buffer, codec, 0xfeb);
4674}
4675#else
4676#define stac92hd_proc_hook NULL
4677#define stac92hd7x_proc_hook NULL
4678#define stac9205_proc_hook NULL
4679#define stac927x_proc_hook NULL
4680#endif
4681
Takashi Iwaicb53c622007-08-10 17:21:45 +02004682#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004683static int stac92xx_resume(struct hda_codec *codec)
4684{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004685 struct sigmatel_spec *spec = codec->spec;
4686
Takashi Iwai2c885872008-11-18 09:36:55 +01004687 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004688 snd_hda_codec_resume_amp(codec);
4689 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004690 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004691 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02004692 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
Mattff6fdc32005-06-27 15:06:52 +02004693 return 0;
4694}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004695
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004696/*
James Gardiner514bf542009-05-03 04:00:44 -04004697 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004698 * check for mute state only on Speakers (nid = 0x10)
4699 *
4700 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4701 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004702 *
4703 * Changed name to reflect that it now works for any designated
4704 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004705 */
4706
4707#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004708static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004709 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004710{
4711 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004712
4713 if (nid == 0x10) {
4714 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004715 HDA_AMP_MUTE)
Takashi Iwai86d190e2009-05-26 15:18:58 +02004716 spec->gpio_data &= ~spec->gpio_led; /* orange */
Takashi Iwaiba84bfc2009-05-30 08:59:03 +02004717 else
4718 spec->gpio_data |= spec->gpio_led; /* white */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004719
4720 stac_gpio_set(codec, spec->gpio_mask,
4721 spec->gpio_dir,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004722 spec->gpio_data);
4723 }
4724
4725 return 0;
4726}
4727#endif
4728
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004729static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4730{
4731 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004732 int i;
4733 hda_nid_t nid;
4734
4735 /* reset each pin before powering down DAC/ADC to avoid click noise */
4736 nid = codec->start_nid;
4737 for (i = 0; i < codec->num_nodes; i++, nid++) {
4738 unsigned int wcaps = get_wcaps(codec, nid);
Takashi Iwaia22d5432009-07-27 12:54:26 +02004739 unsigned int wid_type = get_wcaps_type(wcaps);
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004740 if (wid_type == AC_WID_PIN)
4741 snd_hda_codec_read(codec, nid, 0,
4742 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4743 }
4744
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004745 if (spec->eapd_mask)
4746 stac_gpio_set(codec, spec->gpio_mask,
4747 spec->gpio_dir, spec->gpio_data &
4748 ~spec->eapd_mask);
4749 return 0;
4750}
Mattff6fdc32005-06-27 15:06:52 +02004751#endif
4752
Matt2f2f4252005-04-13 14:45:30 +02004753static struct hda_codec_ops stac92xx_patch_ops = {
4754 .build_controls = stac92xx_build_controls,
4755 .build_pcms = stac92xx_build_pcms,
4756 .init = stac92xx_init,
4757 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004758 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004759#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004760 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004761 .resume = stac92xx_resume,
4762#endif
Matt2f2f4252005-04-13 14:45:30 +02004763};
4764
4765static int patch_stac9200(struct hda_codec *codec)
4766{
4767 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004768 int err;
Matt2f2f4252005-04-13 14:45:30 +02004769
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004770 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004771 if (spec == NULL)
4772 return -ENOMEM;
4773
4774 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004775 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004776 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004777 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4778 stac9200_models,
4779 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01004780 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004781 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4782 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004783 else
4784 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004785 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02004786
4787 spec->multiout.max_channels = 2;
4788 spec->multiout.num_dacs = 1;
4789 spec->multiout.dac_nids = stac9200_dac_nids;
4790 spec->adc_nids = stac9200_adc_nids;
4791 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004792 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004793 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004794 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004795 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004796
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02004797 if (spec->board_config == STAC_9200_M4 ||
4798 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01004799 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004800 spec->init = stac9200_eapd_init;
4801 else
4802 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004803 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004804
Takashi Iwai117f2572008-03-18 09:53:23 +01004805 if (spec->board_config == STAC_9200_PANASONIC) {
4806 spec->gpio_mask = spec->gpio_dir = 0x09;
4807 spec->gpio_data = 0x00;
4808 }
4809
Mattc7d4b2f2005-06-27 14:59:41 +02004810 err = stac9200_parse_auto_config(codec);
4811 if (err < 0) {
4812 stac92xx_free(codec);
4813 return err;
4814 }
Matt2f2f4252005-04-13 14:45:30 +02004815
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01004816 /* CF-74 has no headphone detection, and the driver should *NOT*
4817 * do detection and HP/speaker toggle because the hardware does it.
4818 */
4819 if (spec->board_config == STAC_9200_PANASONIC)
4820 spec->hp_detect = 0;
4821
Matt2f2f4252005-04-13 14:45:30 +02004822 codec->patch_ops = stac92xx_patch_ops;
4823
4824 return 0;
4825}
4826
Tobin Davis8e21c342007-01-08 11:04:17 +01004827static int patch_stac925x(struct hda_codec *codec)
4828{
4829 struct sigmatel_spec *spec;
4830 int err;
4831
4832 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4833 if (spec == NULL)
4834 return -ENOMEM;
4835
4836 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004837 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004838 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004839
4840 /* Check first for codec ID */
4841 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
4842 STAC_925x_MODELS,
4843 stac925x_models,
4844 stac925x_codec_id_cfg_tbl);
4845
4846 /* Now checks for PCI ID, if codec ID is not found */
4847 if (spec->board_config < 0)
4848 spec->board_config = snd_hda_check_board_config(codec,
4849 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01004850 stac925x_models,
4851 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004852 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004853 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004854 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4855 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004856 else
4857 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004858 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01004859
4860 spec->multiout.max_channels = 2;
4861 spec->multiout.num_dacs = 1;
4862 spec->multiout.dac_nids = stac925x_dac_nids;
4863 spec->adc_nids = stac925x_adc_nids;
4864 spec->mux_nids = stac925x_mux_nids;
4865 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004866 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004867 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004868 switch (codec->vendor_id) {
4869 case 0x83847632: /* STAC9202 */
4870 case 0x83847633: /* STAC9202D */
4871 case 0x83847636: /* STAC9251 */
4872 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004873 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004874 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004875 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4876 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004877 break;
4878 default:
4879 spec->num_dmics = 0;
4880 break;
4881 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004882
4883 spec->init = stac925x_core_init;
4884 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02004885 spec->num_caps = 1;
4886 spec->capvols = stac925x_capvols;
4887 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01004888
4889 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004890 if (!err) {
4891 if (spec->board_config < 0) {
4892 printk(KERN_WARNING "hda_codec: No auto-config is "
4893 "available, default to model=ref\n");
4894 spec->board_config = STAC_925x_REF;
4895 goto again;
4896 }
4897 err = -EINVAL;
4898 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004899 if (err < 0) {
4900 stac92xx_free(codec);
4901 return err;
4902 }
4903
4904 codec->patch_ops = stac92xx_patch_ops;
4905
4906 return 0;
4907}
4908
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004909static int patch_stac92hd73xx(struct hda_codec *codec)
4910{
4911 struct sigmatel_spec *spec;
4912 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4913 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004914 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004915
4916 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4917 if (spec == NULL)
4918 return -ENOMEM;
4919
4920 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004921 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004922 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4923 spec->pin_nids = stac92hd73xx_pin_nids;
4924 spec->board_config = snd_hda_check_board_config(codec,
4925 STAC_92HD73XX_MODELS,
4926 stac92hd73xx_models,
4927 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02004928 /* check codec subsystem id if not found */
4929 if (spec->board_config < 0)
4930 spec->board_config =
4931 snd_hda_check_board_codec_sid_config(codec,
4932 STAC_92HD73XX_MODELS, stac92hd73xx_models,
4933 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004934again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004935 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004936 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4937 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004938 else
4939 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004940 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004941
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004942 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004943 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4944
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004945 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004946 printk(KERN_WARNING "hda_codec: Could not determine "
4947 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004948 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004949 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02004950 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004951 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004952 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004953 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004954 break;
4955 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004956 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004957 break;
4958 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004959 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
4960 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004961 }
4962 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004963
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004964 spec->aloopback_mask = 0x01;
4965 spec->aloopback_shift = 8;
4966
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004967 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004968 spec->mux_nids = stac92hd73xx_mux_nids;
4969 spec->adc_nids = stac92hd73xx_adc_nids;
4970 spec->dmic_nids = stac92hd73xx_dmic_nids;
4971 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004972 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004973
4974 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4975 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01004976 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004977
Takashi Iwai6479c632009-07-28 18:20:25 +02004978 spec->num_caps = STAC92HD73XX_NUM_CAPS;
4979 spec->capvols = stac92hd73xx_capvols;
4980 spec->capsws = stac92hd73xx_capsws;
4981
Matthew Ranostaya7662642008-02-21 07:51:14 +01004982 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004983 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004984 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004985 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004986 case STAC_DELL_M6_AMIC:
4987 case STAC_DELL_M6_DMIC:
4988 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004989 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004990 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004991
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004992 switch (spec->board_config) {
4993 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01004994 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01004995 spec->num_dmics = 0;
4996 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004997 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01004998 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01004999 spec->num_dmics = 1;
5000 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005001 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005002 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5003 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005004 spec->num_dmics = 1;
5005 break;
5006 }
5007 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005008 case STAC_ALIENWARE_M17X:
5009 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5010 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5011 spec->eapd_switch = 0;
5012 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005013 default:
5014 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005015 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005016 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005017 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005018 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005019 if (spec->board_config > STAC_92HD73XX_REF) {
5020 /* GPIO0 High = Enable EAPD */
5021 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5022 spec->gpio_data = 0x01;
5023 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005024
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005025 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5026 spec->pwr_nids = stac92hd73xx_pwr_nids;
5027
Matthew Ranostayd9737752008-09-07 12:03:41 +02005028 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005029
5030 if (!err) {
5031 if (spec->board_config < 0) {
5032 printk(KERN_WARNING "hda_codec: No auto-config is "
5033 "available, default to model=ref\n");
5034 spec->board_config = STAC_92HD73XX_REF;
5035 goto again;
5036 }
5037 err = -EINVAL;
5038 }
5039
5040 if (err < 0) {
5041 stac92xx_free(codec);
5042 return err;
5043 }
5044
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005045 if (spec->board_config == STAC_92HD73XX_NO_JD)
5046 spec->hp_detect = 0;
5047
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005048 codec->patch_ops = stac92xx_patch_ops;
5049
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005050 codec->proc_widget_hook = stac92hd7x_proc_hook;
5051
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005052 return 0;
5053}
5054
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005055static int patch_stac92hd83xxx(struct hda_codec *codec)
5056{
5057 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005058 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005059 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005060 int num_dacs;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005061 hda_nid_t nid;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005062
5063 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5064 if (spec == NULL)
5065 return -ENOMEM;
5066
5067 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005068 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005069 spec->mono_nid = 0x19;
5070 spec->digbeep_nid = 0x21;
Takashi Iwai667067d2009-08-13 18:14:42 +02005071 spec->mux_nids = stac92hd83xxx_mux_nids;
5072 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005073 spec->adc_nids = stac92hd83xxx_adc_nids;
Takashi Iwai7570ef12009-08-15 11:57:53 +02005074 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005075 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5076 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5077 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005078 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005079
5080 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005081 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005082 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005083 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5084 spec->capvols = stac92hd83xxx_capvols;
5085 spec->capsws = stac92hd83xxx_capsws;
5086
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005087 spec->board_config = snd_hda_check_board_config(codec,
5088 STAC_92HD83XXX_MODELS,
5089 stac92hd83xxx_models,
5090 stac92hd83xxx_cfg_tbl);
5091again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005092 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005093 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5094 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005095 else
5096 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005097 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005098
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005099 switch (codec->vendor_id) {
5100 case 0x111d7604:
5101 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005102 case 0x111d76d5:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005103 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5104 break;
5105 spec->num_pwrs = 0;
5106 break;
5107 }
5108
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005109 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5110 if (!err) {
5111 if (spec->board_config < 0) {
5112 printk(KERN_WARNING "hda_codec: No auto-config is "
5113 "available, default to model=ref\n");
5114 spec->board_config = STAC_92HD83XXX_REF;
5115 goto again;
5116 }
5117 err = -EINVAL;
5118 }
5119
5120 if (err < 0) {
5121 stac92xx_free(codec);
5122 return err;
5123 }
5124
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005125 switch (spec->board_config) {
5126 case STAC_DELL_S14:
5127 nid = 0xf;
5128 break;
5129 default:
5130 nid = 0xe;
5131 break;
5132 }
5133
5134 num_dacs = snd_hda_get_connections(codec, nid,
5135 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02005136 if (num_dacs < 0)
5137 num_dacs = STAC92HD83_DAC_COUNT;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005138
5139 /* set port X to select the last DAC
5140 */
5141 snd_hda_codec_write_cache(codec, nid, 0,
5142 AC_VERB_SET_CONNECT_SEL, num_dacs);
5143
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005144 codec->patch_ops = stac92xx_patch_ops;
5145
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005146 codec->proc_widget_hook = stac92hd_proc_hook;
5147
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005148 return 0;
5149}
5150
Takashi Iwai330ee992009-02-20 14:33:36 +01005151/* get the pin connection (fixed, none, etc) */
5152static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5153{
5154 struct sigmatel_spec *spec = codec->spec;
5155 unsigned int cfg;
5156
5157 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5158 return get_defcfg_connect(cfg);
5159}
5160
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005161static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5162 hda_nid_t *nids, int num_nids)
5163{
5164 struct sigmatel_spec *spec = codec->spec;
5165 int idx, num;
5166 unsigned int def_conf;
5167
5168 for (num = 0; num < num_nids; num++) {
5169 for (idx = 0; idx < spec->num_pins; idx++)
5170 if (spec->pin_nids[idx] == nids[num])
5171 break;
5172 if (idx >= spec->num_pins)
5173 break;
Takashi Iwai330ee992009-02-20 14:33:36 +01005174 def_conf = stac_get_defcfg_connect(codec, idx);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005175 if (def_conf == AC_JACK_PORT_NONE)
5176 break;
5177 }
5178 return num;
5179}
5180
5181static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5182 hda_nid_t dig0pin)
5183{
5184 struct sigmatel_spec *spec = codec->spec;
5185 int idx;
5186
5187 for (idx = 0; idx < spec->num_pins; idx++)
5188 if (spec->pin_nids[idx] == dig0pin)
5189 break;
5190 if ((idx + 2) >= spec->num_pins)
5191 return 0;
5192
5193 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005194 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005195 return 2;
5196
5197 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005198 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005199 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005200 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005201 return 1;
5202 else
5203 return 0;
5204}
5205
Matthew Ranostaye035b842007-11-06 11:53:55 +01005206static int patch_stac92hd71bxx(struct hda_codec *codec)
5207{
5208 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005209 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005210 int err = 0;
5211
5212 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5213 if (spec == NULL)
5214 return -ENOMEM;
5215
5216 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005217 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005218 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5219 switch (codec->vendor_id) {
5220 case 0x111d76b6:
5221 case 0x111d76b7:
5222 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5223 break;
5224 case 0x111d7603:
5225 case 0x111d7608:
5226 /* On 92HD75Bx 0x27 isn't a pin nid */
5227 spec->num_pins--;
5228 /* fallthrough */
5229 default:
5230 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5231 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005232 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005233 spec->board_config = snd_hda_check_board_config(codec,
5234 STAC_92HD71BXX_MODELS,
5235 stac92hd71bxx_models,
5236 stac92hd71bxx_cfg_tbl);
5237again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005238 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005239 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5240 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005241 else
5242 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005243 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005244
Takashi Iwai41c3b642008-11-18 10:45:15 +01005245 if (spec->board_config > STAC_92HD71BXX_REF) {
5246 /* GPIO0 = EAPD */
5247 spec->gpio_mask = 0x01;
5248 spec->gpio_dir = 0x01;
5249 spec->gpio_data = 0x01;
5250 }
5251
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005252 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5253 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5254
Takashi Iwai6479c632009-07-28 18:20:25 +02005255 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5256 spec->capvols = stac92hd71bxx_capvols;
5257 spec->capsws = stac92hd71bxx_capsws;
5258
Matthew Ranostay541eee82007-12-14 12:08:04 +01005259 switch (codec->vendor_id) {
5260 case 0x111d76b6: /* 4 Port without Analog Mixer */
5261 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005262 unmute_init++;
5263 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005264 case 0x111d76b4: /* 6 Port without Analog Mixer */
5265 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005266 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005267 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005268 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5269 stac92hd71bxx_dmic_nids,
5270 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005271 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005272 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005273 switch (spec->board_config) {
5274 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005275 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005276 err = stac_add_event(spec, codec->afg,
5277 STAC_VREF_EVENT, 0x02);
5278 if (err < 0)
5279 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005280 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005281 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5282 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005283 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005284 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005285 spec->gpio_mask |= 0x02;
5286 break;
5287 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005288 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005289 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005290 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005291
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005292 /* no output amps */
5293 spec->num_pwrs = 0;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005294 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005295 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005296 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005297 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5298 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005299 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5300 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5301 stac92hd71bxx_dmic_nids,
5302 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005303 break;
5304 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005305 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005306 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005307
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005308 /* no output amps */
5309 spec->num_pwrs = 0;
5310 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005311 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005312 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005313 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005314 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5315 stac92hd71bxx_dmic_nids,
5316 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005317 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005318 }
5319
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005320 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5321 snd_hda_sequence_write_cache(codec, unmute_init);
5322
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005323 /* Some HP machines seem to have unstable codec communications
5324 * especially with ATI fglrx driver. For recovering from the
5325 * CORB/RIRB stall, allow the BUS reset and keep always sync
5326 */
5327 if (spec->board_config == STAC_HP_DV5) {
5328 codec->bus->sync_write = 1;
5329 codec->bus->allow_bus_reset = 1;
5330 }
5331
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005332 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005333 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005334 spec->aloopback_shift = 0;
5335
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005336 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005337 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005338 spec->mux_nids = stac92hd71bxx_mux_nids;
5339 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005340 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005341 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005342
5343 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5344 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005345 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005346 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005347
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005348 switch (spec->board_config) {
5349 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005350 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005351 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea7152008-10-09 08:37:28 -04005352 stac92xx_auto_set_pinctl(codec, 0x0e,
5353 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005354 /* fallthru */
5355 case STAC_DELL_M4_2:
5356 spec->num_dmics = 0;
5357 spec->num_smuxes = 0;
5358 spec->num_dmuxes = 0;
5359 break;
5360 case STAC_DELL_M4_1:
5361 case STAC_DELL_M4_3:
5362 spec->num_dmics = 1;
5363 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005364 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005365 break;
James Gardiner514bf542009-05-03 04:00:44 -04005366 case STAC_HP_DV4_1222NR:
5367 spec->num_dmics = 1;
5368 /* I don't know if it needs 1 or 2 smuxes - will wait for
5369 * bug reports to fix if needed
5370 */
5371 spec->num_smuxes = 1;
5372 spec->num_dmuxes = 1;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005373 spec->gpio_led = 0x01;
James Gardiner514bf542009-05-03 04:00:44 -04005374 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005375 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005376 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005377 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5378 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005379 case STAC_HP_HDX:
5380 spec->num_dmics = 1;
5381 spec->num_dmuxes = 1;
5382 spec->num_smuxes = 1;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005383 /* orange/white mute led on GPIO3, orange=0, white=1 */
Takashi Iwai86d190e2009-05-26 15:18:58 +02005384 spec->gpio_led = 0x08;
5385 break;
5386 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005387
Takashi Iwai86d190e2009-05-26 15:18:58 +02005388#ifdef CONFIG_SND_HDA_POWER_SAVE
5389 if (spec->gpio_led) {
5390 spec->gpio_mask |= spec->gpio_led;
5391 spec->gpio_dir |= spec->gpio_led;
5392 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005393 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005394 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005395 stac92xx_hp_check_power_status;
5396 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005397#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005398
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005399 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005400
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005401 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005402 if (!err) {
5403 if (spec->board_config < 0) {
5404 printk(KERN_WARNING "hda_codec: No auto-config is "
5405 "available, default to model=ref\n");
5406 spec->board_config = STAC_92HD71BXX_REF;
5407 goto again;
5408 }
5409 err = -EINVAL;
5410 }
5411
5412 if (err < 0) {
5413 stac92xx_free(codec);
5414 return err;
5415 }
5416
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005417 codec->proc_widget_hook = stac92hd7x_proc_hook;
5418
Matthew Ranostaye035b842007-11-06 11:53:55 +01005419 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005420}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005421
Matt2f2f4252005-04-13 14:45:30 +02005422static int patch_stac922x(struct hda_codec *codec)
5423{
5424 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005425 int err;
Matt2f2f4252005-04-13 14:45:30 +02005426
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005427 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005428 if (spec == NULL)
5429 return -ENOMEM;
5430
5431 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005432 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005433 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005434 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5435 stac922x_models,
5436 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005437 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005438 spec->gpio_mask = spec->gpio_dir = 0x03;
5439 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005440 /* Intel Macs have all same PCI SSID, so we need to check
5441 * codec SSID to distinguish the exact models
5442 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005443 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005444 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005445
5446 case 0x106b0800:
5447 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005448 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005449 case 0x106b0600:
5450 case 0x106b0700:
5451 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005452 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005453 case 0x106b0e00:
5454 case 0x106b0f00:
5455 case 0x106b1600:
5456 case 0x106b1700:
5457 case 0x106b0200:
5458 case 0x106b1e00:
5459 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005460 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005461 case 0x106b1a00:
5462 case 0x00000100:
5463 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005464 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005465 case 0x106b0a00:
5466 case 0x106b2200:
5467 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005468 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005469 default:
5470 spec->board_config = STAC_INTEL_MAC_V3;
5471 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005472 }
5473 }
5474
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005475 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005476 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005477 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5478 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005479 else
5480 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005481 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005482
Matt2f2f4252005-04-13 14:45:30 +02005483 spec->adc_nids = stac922x_adc_nids;
5484 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005485 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005486 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005487 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005488 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005489
5490 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005491
5492 spec->num_caps = STAC922X_NUM_CAPS;
5493 spec->capvols = stac922x_capvols;
5494 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005495
5496 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005497
Matt Porter3cc08dc2006-01-23 15:27:49 +01005498 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005499 if (!err) {
5500 if (spec->board_config < 0) {
5501 printk(KERN_WARNING "hda_codec: No auto-config is "
5502 "available, default to model=ref\n");
5503 spec->board_config = STAC_D945_REF;
5504 goto again;
5505 }
5506 err = -EINVAL;
5507 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005508 if (err < 0) {
5509 stac92xx_free(codec);
5510 return err;
5511 }
5512
5513 codec->patch_ops = stac92xx_patch_ops;
5514
Takashi Iwai807a46362007-05-29 19:01:37 +02005515 /* Fix Mux capture level; max to 2 */
5516 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5517 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5518 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5519 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5520 (0 << AC_AMPCAP_MUTE_SHIFT));
5521
Matt Porter3cc08dc2006-01-23 15:27:49 +01005522 return 0;
5523}
5524
5525static int patch_stac927x(struct hda_codec *codec)
5526{
5527 struct sigmatel_spec *spec;
5528 int err;
5529
5530 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5531 if (spec == NULL)
5532 return -ENOMEM;
5533
5534 codec->spec = spec;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005535 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005536 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005537 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005538 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5539 stac927x_models,
5540 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005541 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005542 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005543 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5544 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005545 else
5546 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005547 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005548
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005549 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005550 spec->adc_nids = stac927x_adc_nids;
5551 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5552 spec->mux_nids = stac927x_mux_nids;
5553 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005554 spec->smux_nids = stac927x_smux_nids;
5555 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005556 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005557 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005558 spec->multiout.dac_nids = spec->dac_nids;
5559
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005560 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005561 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005562 case STAC_D965_5ST:
5563 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005564 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005565 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005566 spec->num_dmics = 0;
5567
Tobin Davis93ed1502006-09-01 21:03:12 +02005568 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005569 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005570 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005571 switch (codec->subsystem_id) {
5572 case 0x10280209:
5573 case 0x1028022e:
5574 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005575 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005576 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005577 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005578 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005579 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005580 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005581 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005582 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005583 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005584 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005585 case STAC_DELL_3ST:
5586 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005587 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005588 spec->gpio_data = 0x04;
Chengu Wang84d3dc22009-07-30 19:43:55 +08005589 switch (codec->subsystem_id) {
5590 case 0x1028022f:
5591 /* correct EAPD to be GPIO0 */
5592 spec->eapd_mask = spec->gpio_mask = 0x01;
5593 spec->gpio_dir = spec->gpio_data = 0x01;
5594 break;
5595 };
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005596 spec->dmic_nids = stac927x_dmic_nids;
5597 spec->num_dmics = STAC927X_NUM_DMICS;
5598
Tobin Davis93ed1502006-09-01 21:03:12 +02005599 spec->init = d965_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005600 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005601 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005602 break;
5603 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005604 if (spec->board_config > STAC_D965_REF) {
5605 /* GPIO0 High = Enable EAPD */
5606 spec->eapd_mask = spec->gpio_mask = 0x01;
5607 spec->gpio_dir = spec->gpio_data = 0x01;
5608 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005609 spec->num_dmics = 0;
5610
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005611 spec->init = stac927x_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005612 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005613
Takashi Iwai6479c632009-07-28 18:20:25 +02005614 spec->num_caps = STAC927X_NUM_CAPS;
5615 spec->capvols = stac927x_capvols;
5616 spec->capsws = stac927x_capsws;
5617
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005618 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005619 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005620 spec->aloopback_mask = 0x40;
5621 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005622 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005623
Matt Porter3cc08dc2006-01-23 15:27:49 +01005624 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005625 if (!err) {
5626 if (spec->board_config < 0) {
5627 printk(KERN_WARNING "hda_codec: No auto-config is "
5628 "available, default to model=ref\n");
5629 spec->board_config = STAC_D965_REF;
5630 goto again;
5631 }
5632 err = -EINVAL;
5633 }
Mattc7d4b2f2005-06-27 14:59:41 +02005634 if (err < 0) {
5635 stac92xx_free(codec);
5636 return err;
5637 }
Matt2f2f4252005-04-13 14:45:30 +02005638
5639 codec->patch_ops = stac92xx_patch_ops;
5640
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005641 codec->proc_widget_hook = stac927x_proc_hook;
5642
Takashi Iwai52987652008-01-16 16:09:47 +01005643 /*
5644 * !!FIXME!!
5645 * The STAC927x seem to require fairly long delays for certain
5646 * command sequences. With too short delays (even if the answer
5647 * is set to RIRB properly), it results in the silence output
5648 * on some hardwares like Dell.
5649 *
5650 * The below flag enables the longer delay (see get_response
5651 * in hda_intel.c).
5652 */
5653 codec->bus->needs_damn_long_delay = 1;
5654
Takashi Iwaie28d8322008-12-17 13:48:29 +01005655 /* no jack detecion for ref-no-jd model */
5656 if (spec->board_config == STAC_D965_REF_NO_JD)
5657 spec->hp_detect = 0;
5658
Matt2f2f4252005-04-13 14:45:30 +02005659 return 0;
5660}
5661
Matt Porterf3302a52006-07-31 12:49:34 +02005662static int patch_stac9205(struct hda_codec *codec)
5663{
5664 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005665 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005666
5667 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5668 if (spec == NULL)
5669 return -ENOMEM;
5670
5671 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005672 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005673 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005674 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5675 stac9205_models,
5676 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005677 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005678 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005679 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5680 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005681 else
5682 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005683 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02005684
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005685 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005686 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005687 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005688 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005689 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005690 spec->smux_nids = stac9205_smux_nids;
5691 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005692 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005693 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005694 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005695 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005696 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005697
5698 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005699 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02005700
Takashi Iwai6479c632009-07-28 18:20:25 +02005701 spec->num_caps = STAC9205_NUM_CAPS;
5702 spec->capvols = stac9205_capvols;
5703 spec->capsws = stac9205_capsws;
5704
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005705 spec->aloopback_mask = 0x40;
5706 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01005707 /* Turn on/off EAPD per HP plugging */
5708 if (spec->board_config != STAC_9205_EAPD)
5709 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005710 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005711
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005712 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005713 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005714 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005715 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5716 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005717
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005718 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005719 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5720 if (err < 0)
5721 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005722 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005723 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5724 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005725 AC_VERB_SET_UNSOLICITED_ENABLE,
5726 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005727
5728 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005729 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005730 spec->gpio_mask = 0x1b;
5731 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005732 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005733 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005734 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005735 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005736 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005737 case STAC_9205_REF:
5738 /* SPDIF-In enabled */
5739 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005740 default:
5741 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005742 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005743 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005744 break;
5745 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005746
Matt Porterf3302a52006-07-31 12:49:34 +02005747 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005748 if (!err) {
5749 if (spec->board_config < 0) {
5750 printk(KERN_WARNING "hda_codec: No auto-config is "
5751 "available, default to model=ref\n");
5752 spec->board_config = STAC_9205_REF;
5753 goto again;
5754 }
5755 err = -EINVAL;
5756 }
Matt Porterf3302a52006-07-31 12:49:34 +02005757 if (err < 0) {
5758 stac92xx_free(codec);
5759 return err;
5760 }
5761
5762 codec->patch_ops = stac92xx_patch_ops;
5763
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005764 codec->proc_widget_hook = stac9205_proc_hook;
5765
Matt Porterf3302a52006-07-31 12:49:34 +02005766 return 0;
5767}
5768
Matt2f2f4252005-04-13 14:45:30 +02005769/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005770 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005771 */
5772
Takashi Iwai1e137f92009-01-21 07:41:22 +01005773static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02005774 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005775 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5776 {}
5777};
5778
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005779static hda_nid_t stac9872_pin_nids[] = {
5780 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5781 0x11, 0x13, 0x14,
5782};
5783
5784static hda_nid_t stac9872_adc_nids[] = {
5785 0x8 /*,0x6*/
5786};
5787
5788static hda_nid_t stac9872_mux_nids[] = {
5789 0x15
5790};
5791
Takashi Iwai6479c632009-07-28 18:20:25 +02005792static unsigned long stac9872_capvols[] = {
5793 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
5794};
5795#define stac9872_capsws stac9872_capvols
5796
Takashi Iwai307282c2009-03-12 18:17:58 +01005797static unsigned int stac9872_vaio_pin_configs[9] = {
5798 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
5799 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
5800 0x90a7013e
5801};
5802
5803static const char *stac9872_models[STAC_9872_MODELS] = {
5804 [STAC_9872_AUTO] = "auto",
5805 [STAC_9872_VAIO] = "vaio",
5806};
5807
5808static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
5809 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
5810};
5811
5812static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02005813 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
5814 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01005815 {} /* terminator */
5816};
5817
Guillaume Munch6d859062006-08-22 17:15:47 +02005818static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005819{
5820 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01005821 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005822
Takashi Iwaidb064e52006-03-16 16:04:58 +01005823 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5824 if (spec == NULL)
5825 return -ENOMEM;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005826 codec->spec = spec;
Takashi Iwaib04add92009-07-20 08:01:36 +02005827 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5828 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005829
5830 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5831 stac9872_models,
5832 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01005833 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005834 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5835 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01005836 else
5837 stac92xx_set_config_regs(codec,
5838 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005839
Takashi Iwai1e137f92009-01-21 07:41:22 +01005840 spec->multiout.dac_nids = spec->dac_nids;
5841 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5842 spec->adc_nids = stac9872_adc_nids;
5843 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5844 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01005845 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005846 spec->num_caps = 1;
5847 spec->capvols = stac9872_capvols;
5848 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005849
Takashi Iwai1e137f92009-01-21 07:41:22 +01005850 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5851 if (err < 0) {
5852 stac92xx_free(codec);
5853 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005854 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01005855 spec->input_mux = &spec->private_imux;
5856 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005857 return 0;
5858}
5859
5860
5861/*
Matt2f2f4252005-04-13 14:45:30 +02005862 * patch entries
5863 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005864static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02005865 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5866 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5867 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5868 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5869 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5870 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5871 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005872 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5873 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5874 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5875 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5876 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5877 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005878 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5879 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5880 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5881 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5882 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5883 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5884 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5885 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5886 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5887 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005888 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5889 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5890 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5891 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5892 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5893 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005894 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5895 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005896 /* The following does not take into account .id=0x83847661 when subsys =
5897 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5898 * currently not fully supported.
5899 */
5900 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5901 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5902 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01005903 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02005904 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5905 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5906 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5907 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5908 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5909 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5910 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5911 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005912 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005913 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5914 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005915 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005916 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005917 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5918 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005919 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005920 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5921 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5922 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5923 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5924 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5925 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5926 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5927 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005928 {} /* terminator */
5929};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005930
5931MODULE_ALIAS("snd-hda-codec-id:8384*");
5932MODULE_ALIAS("snd-hda-codec-id:111d*");
5933
5934MODULE_LICENSE("GPL");
5935MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5936
5937static struct hda_codec_preset_list sigmatel_list = {
5938 .preset = snd_hda_preset_sigmatel,
5939 .owner = THIS_MODULE,
5940};
5941
5942static int __init patch_sigmatel_init(void)
5943{
5944 return snd_hda_add_codec_preset(&sigmatel_list);
5945}
5946
5947static void __exit patch_sigmatel_exit(void)
5948{
5949 snd_hda_delete_codec_preset(&sigmatel_list);
5950}
5951
5952module_init(patch_sigmatel_init)
5953module_exit(patch_sigmatel_exit)