blob: cc0e26c6997889fcd7d1794cc89361c453fd4e05 [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 Ranostay4fe51952008-01-29 15:28:44 +0100202 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200203 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-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 Ranostay4fe51952008-01-29 15:28:44 +0100209
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200210 /* stream */
211 unsigned int stream_delay;
212
Matthew Ranostay4fe51952008-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 Iwai6e34c032009-09-14 15:42:18 +02001693 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1694 "HP dv6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02001695 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1696 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001697 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1698 "unknown Dell", STAC_DELL_M4_1),
1699 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1700 "unknown Dell", STAC_DELL_M4_1),
1701 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1702 "unknown Dell", STAC_DELL_M4_1),
1703 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1704 "unknown Dell", STAC_DELL_M4_1),
1705 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1706 "unknown Dell", STAC_DELL_M4_1),
1707 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1708 "unknown Dell", STAC_DELL_M4_1),
1709 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1710 "unknown Dell", STAC_DELL_M4_1),
1711 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1712 "unknown Dell", STAC_DELL_M4_2),
1713 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1714 "unknown Dell", STAC_DELL_M4_2),
1715 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1716 "unknown Dell", STAC_DELL_M4_2),
1717 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1718 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001719 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1720 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001721 {} /* terminator */
1722};
1723
Matt Porter403d1942005-11-29 15:00:51 +01001724static unsigned int ref922x_pin_configs[10] = {
1725 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1726 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001727 0x40000100, 0x40000100,
1728};
1729
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001730/*
1731 STAC 922X pin configs for
1732 102801A7
1733 102801AB
1734 102801A9
1735 102801D1
1736 102801D2
1737*/
1738static unsigned int dell_922x_d81_pin_configs[10] = {
1739 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1740 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1741 0x01813122, 0x400001f2,
1742};
1743
1744/*
1745 STAC 922X pin configs for
1746 102801AC
1747 102801D0
1748*/
1749static unsigned int dell_922x_d82_pin_configs[10] = {
1750 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1751 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1752 0x01813122, 0x400001f1,
1753};
1754
1755/*
1756 STAC 922X pin configs for
1757 102801BF
1758*/
1759static unsigned int dell_922x_m81_pin_configs[10] = {
1760 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1761 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1762 0x40C003f1, 0x405003f0,
1763};
1764
1765/*
1766 STAC 9221 A1 pin configs for
1767 102801D7 (Dell XPS M1210)
1768*/
1769static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001770 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1771 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001772 0x508003f3, 0x405003f4,
1773};
1774
Matt Porter403d1942005-11-29 15:00:51 +01001775static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001776 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001777 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1778 0x02a19120, 0x40000100,
1779};
1780
1781static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001782 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1783 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001784 0x02a19320, 0x40000100,
1785};
1786
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001787static unsigned int intel_mac_v1_pin_configs[10] = {
1788 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1789 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001790 0x400000fc, 0x400000fb,
1791};
1792
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001793static unsigned int intel_mac_v2_pin_configs[10] = {
1794 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1795 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001796 0x400000fc, 0x400000fb,
1797};
1798
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001799static unsigned int intel_mac_v3_pin_configs[10] = {
1800 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1801 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1802 0x400000fc, 0x400000fb,
1803};
1804
1805static unsigned int intel_mac_v4_pin_configs[10] = {
1806 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1807 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1808 0x400000fc, 0x400000fb,
1809};
1810
1811static unsigned int intel_mac_v5_pin_configs[10] = {
1812 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1813 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1814 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001815};
1816
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001817static unsigned int ecs202_pin_configs[10] = {
1818 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1819 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1820 0x9037012e, 0x40e000f2,
1821};
Takashi Iwai76c08822007-06-19 12:17:42 +02001822
Takashi Iwai19039bd2006-06-28 15:52:16 +02001823static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001824 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001825 [STAC_D945GTP3] = d945gtp3_pin_configs,
1826 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001827 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1828 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1829 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1830 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1831 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001832 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001833 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001834 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1835 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1836 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1837 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1838 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1839 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001840 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001841 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1842 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1843 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1844 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001845};
1846
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001847static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001848 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001849 [STAC_D945_REF] = "ref",
1850 [STAC_D945GTP5] = "5stack",
1851 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001852 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1853 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1854 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1855 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1856 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001857 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001858 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001859 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001860 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001861 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1862 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001863 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001864 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001865 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001866 [STAC_922X_DELL_D81] = "dell-d81",
1867 [STAC_922X_DELL_D82] = "dell-d82",
1868 [STAC_922X_DELL_M81] = "dell-m81",
1869 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001870};
1871
1872static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1873 /* SigmaTel reference board */
1874 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1875 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001876 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1877 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001878 /* Intel 945G based systems */
1879 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1880 "Intel D945G", STAC_D945GTP3),
1881 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1882 "Intel D945G", STAC_D945GTP3),
1883 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1884 "Intel D945G", STAC_D945GTP3),
1885 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1886 "Intel D945G", STAC_D945GTP3),
1887 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1888 "Intel D945G", STAC_D945GTP3),
1889 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1890 "Intel D945G", STAC_D945GTP3),
1891 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1892 "Intel D945G", STAC_D945GTP3),
1893 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1894 "Intel D945G", STAC_D945GTP3),
1895 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1896 "Intel D945G", STAC_D945GTP3),
1897 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1898 "Intel D945G", STAC_D945GTP3),
1899 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1900 "Intel D945G", STAC_D945GTP3),
1901 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1902 "Intel D945G", STAC_D945GTP3),
1903 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1904 "Intel D945G", STAC_D945GTP3),
1905 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1906 "Intel D945G", STAC_D945GTP3),
1907 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1908 "Intel D945G", STAC_D945GTP3),
1909 /* Intel D945G 5-stack systems */
1910 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1911 "Intel D945G", STAC_D945GTP5),
1912 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1913 "Intel D945G", STAC_D945GTP5),
1914 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1915 "Intel D945G", STAC_D945GTP5),
1916 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1917 "Intel D945G", STAC_D945GTP5),
1918 /* Intel 945P based systems */
1919 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1920 "Intel D945P", STAC_D945GTP3),
1921 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1922 "Intel D945P", STAC_D945GTP3),
1923 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1924 "Intel D945P", STAC_D945GTP3),
1925 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1926 "Intel D945P", STAC_D945GTP3),
1927 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1928 "Intel D945P", STAC_D945GTP3),
1929 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1930 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01001931 /* other intel */
1932 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
1933 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001934 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08001935 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001936 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001937 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001938 /* Dell systems */
1939 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1940 "unknown Dell", STAC_922X_DELL_D81),
1941 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1942 "unknown Dell", STAC_922X_DELL_D81),
1943 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1944 "unknown Dell", STAC_922X_DELL_D81),
1945 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1946 "unknown Dell", STAC_922X_DELL_D82),
1947 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1948 "unknown Dell", STAC_922X_DELL_M81),
1949 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1950 "unknown Dell", STAC_922X_DELL_D82),
1951 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1952 "unknown Dell", STAC_922X_DELL_D81),
1953 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1954 "unknown Dell", STAC_922X_DELL_D81),
1955 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1956 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001957 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01001958 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02001959 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01001960 {} /* terminator */
1961};
1962
Matt Porter3cc08dc2006-01-23 15:27:49 +01001963static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001964 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1965 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1966 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1967 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001968};
1969
Tobin Davis93ed1502006-09-01 21:03:12 +02001970static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001971 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1972 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1973 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1974 0x40000100, 0x40000100
1975};
1976
Tobin Davis93ed1502006-09-01 21:03:12 +02001977static unsigned int d965_5st_pin_configs[14] = {
1978 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1979 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1980 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1981 0x40000100, 0x40000100
1982};
1983
Takashi Iwai679d92e2009-05-24 19:00:08 +02001984static unsigned int d965_5st_no_fp_pin_configs[14] = {
1985 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
1986 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1987 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1988 0x40000100, 0x40000100
1989};
1990
Tobin Davis4ff076e2007-08-07 11:48:12 +02001991static unsigned int dell_3st_pin_configs[14] = {
1992 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1993 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001994 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001995 0x40c003fc, 0x40000100
1996};
1997
Tobin Davis93ed1502006-09-01 21:03:12 +02001998static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01001999 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002000 [STAC_D965_REF] = ref927x_pin_configs,
2001 [STAC_D965_3ST] = d965_3st_pin_configs,
2002 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002003 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002004 [STAC_DELL_3ST] = dell_3st_pin_configs,
2005 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002006};
2007
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002008static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002009 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002010 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002011 [STAC_D965_REF] = "ref",
2012 [STAC_D965_3ST] = "3stack",
2013 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002014 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002015 [STAC_DELL_3ST] = "dell-3stack",
2016 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002017};
2018
2019static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2020 /* SigmaTel reference board */
2021 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2022 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002023 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2024 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002025 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002026 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2027 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002028 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002029 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2030 "Intel D965", STAC_D965_3ST),
2031 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2032 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002033 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002034 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002035 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002036 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2037 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002038 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002039 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2040 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002041 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002042 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002043 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2044 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2045 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2046 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002047 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002048 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2049 "Intel D965", STAC_D965_5ST),
2050 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2051 "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002052 {} /* terminator */
2053};
2054
Matt Porterf3302a52006-07-31 12:49:34 +02002055static unsigned int ref9205_pin_configs[12] = {
2056 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002057 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002058 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002059};
2060
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002061/*
2062 STAC 9205 pin configs for
2063 102801F1
2064 102801F2
2065 102801FC
2066 102801FD
2067 10280204
2068 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002069 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002070*/
2071static unsigned int dell_9205_m42_pin_configs[12] = {
2072 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2073 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2074 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2075};
2076
2077/*
2078 STAC 9205 pin configs for
2079 102801F9
2080 102801FA
2081 102801FE
2082 102801FF (Dell Precision M4300)
2083 10280206
2084 10280200
2085 10280201
2086*/
2087static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002088 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2089 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2090 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2091};
2092
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002093static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002094 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2095 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2096 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2097};
2098
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002099static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002100 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002101 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2102 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2103 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002104 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002105};
2106
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002107static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002108 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002109 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002110 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002111 [STAC_9205_DELL_M43] = "dell-m43",
2112 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002113 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002114};
2115
2116static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2117 /* SigmaTel reference board */
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2119 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002120 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2121 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002122 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2123 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002124 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002125 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2126 "unknown Dell", STAC_9205_DELL_M42),
2127 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2128 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002129 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002130 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002131 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2132 "Dell Precision", STAC_9205_DELL_M43),
2133 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2134 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002135 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2136 "unknown Dell", STAC_9205_DELL_M42),
2137 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2138 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002139 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2140 "Dell Precision", STAC_9205_DELL_M43),
2141 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002142 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002143 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2144 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002145 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2146 "Dell Precision", STAC_9205_DELL_M43),
2147 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2148 "Dell Precision", STAC_9205_DELL_M43),
2149 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2150 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002151 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2152 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002153 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2154 "Dell Vostro 1500", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002155 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002156 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002157 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002158 {} /* terminator */
2159};
2160
Takashi Iwai330ee992009-02-20 14:33:36 +01002161static void stac92xx_set_config_regs(struct hda_codec *codec,
2162 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002163{
2164 int i;
2165 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002166
Takashi Iwai330ee992009-02-20 14:33:36 +01002167 if (!pincfgs)
2168 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002169
Matthew Ranostay87d48362007-07-17 11:52:24 +02002170 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002171 if (spec->pin_nids[i] && pincfgs[i])
2172 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2173 pincfgs[i]);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002174}
2175
Matt2f2f4252005-04-13 14:45:30 +02002176/*
2177 * Analog playback callbacks
2178 */
2179static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2180 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002181 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002182{
2183 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002184 if (spec->stream_delay)
2185 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002186 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2187 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002188}
2189
2190static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2191 struct hda_codec *codec,
2192 unsigned int stream_tag,
2193 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002194 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002195{
2196 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002197 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002198}
2199
2200static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2201 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002202 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002203{
2204 struct sigmatel_spec *spec = codec->spec;
2205 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2206}
2207
2208/*
Mattdabbed62005-06-14 10:19:34 +02002209 * Digital playback callbacks
2210 */
2211static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2212 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002213 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002214{
2215 struct sigmatel_spec *spec = codec->spec;
2216 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2217}
2218
2219static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2220 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002221 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002222{
2223 struct sigmatel_spec *spec = codec->spec;
2224 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2225}
2226
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002227static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2228 struct hda_codec *codec,
2229 unsigned int stream_tag,
2230 unsigned int format,
2231 struct snd_pcm_substream *substream)
2232{
2233 struct sigmatel_spec *spec = codec->spec;
2234 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2235 stream_tag, format, substream);
2236}
2237
Takashi Iwai9411e212009-02-13 11:32:28 +01002238static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2239 struct hda_codec *codec,
2240 struct snd_pcm_substream *substream)
2241{
2242 struct sigmatel_spec *spec = codec->spec;
2243 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2244}
2245
Mattdabbed62005-06-14 10:19:34 +02002246
2247/*
Matt2f2f4252005-04-13 14:45:30 +02002248 * Analog capture callbacks
2249 */
2250static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2251 struct hda_codec *codec,
2252 unsigned int stream_tag,
2253 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002254 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002255{
2256 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002257 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002258
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002259 if (spec->powerdown_adcs) {
2260 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002261 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002262 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2263 }
2264 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002265 return 0;
2266}
2267
2268static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2269 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002270 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002271{
2272 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002273 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002274
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002275 snd_hda_codec_cleanup_stream(codec, nid);
2276 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002277 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002278 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002279 return 0;
2280}
2281
Mattdabbed62005-06-14 10:19:34 +02002282static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2283 .substreams = 1,
2284 .channels_min = 2,
2285 .channels_max = 2,
2286 /* NID is set in stac92xx_build_pcms */
2287 .ops = {
2288 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002289 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002290 .prepare = stac92xx_dig_playback_pcm_prepare,
2291 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002292 },
2293};
2294
2295static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2296 .substreams = 1,
2297 .channels_min = 2,
2298 .channels_max = 2,
2299 /* NID is set in stac92xx_build_pcms */
2300};
2301
Matt2f2f4252005-04-13 14:45:30 +02002302static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2303 .substreams = 1,
2304 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002305 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002306 .nid = 0x02, /* NID to query formats and rates */
2307 .ops = {
2308 .open = stac92xx_playback_pcm_open,
2309 .prepare = stac92xx_playback_pcm_prepare,
2310 .cleanup = stac92xx_playback_pcm_cleanup
2311 },
2312};
2313
Matt Porter3cc08dc2006-01-23 15:27:49 +01002314static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2315 .substreams = 1,
2316 .channels_min = 2,
2317 .channels_max = 2,
2318 .nid = 0x06, /* NID to query formats and rates */
2319 .ops = {
2320 .open = stac92xx_playback_pcm_open,
2321 .prepare = stac92xx_playback_pcm_prepare,
2322 .cleanup = stac92xx_playback_pcm_cleanup
2323 },
2324};
2325
Matt2f2f4252005-04-13 14:45:30 +02002326static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002327 .channels_min = 2,
2328 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002329 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002330 .ops = {
2331 .prepare = stac92xx_capture_pcm_prepare,
2332 .cleanup = stac92xx_capture_pcm_cleanup
2333 },
2334};
2335
2336static int stac92xx_build_pcms(struct hda_codec *codec)
2337{
2338 struct sigmatel_spec *spec = codec->spec;
2339 struct hda_pcm *info = spec->pcm_rec;
2340
2341 codec->num_pcms = 1;
2342 codec->pcm_info = info;
2343
Mattc7d4b2f2005-06-27 14:59:41 +02002344 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002345 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002346 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2347 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002348 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002349 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002350 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002351
2352 if (spec->alt_switch) {
2353 codec->num_pcms++;
2354 info++;
2355 info->name = "STAC92xx Analog Alt";
2356 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2357 }
Matt2f2f4252005-04-13 14:45:30 +02002358
Mattdabbed62005-06-14 10:19:34 +02002359 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2360 codec->num_pcms++;
2361 info++;
2362 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002363 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002364 if (spec->multiout.dig_out_nid) {
2365 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2366 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2367 }
2368 if (spec->dig_in_nid) {
2369 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2370 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2371 }
2372 }
2373
Matt2f2f4252005-04-13 14:45:30 +02002374 return 0;
2375}
2376
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002377static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2378 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002379{
Takashi Iwai1327a322009-03-23 13:07:47 +01002380 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002381 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2382 if (pincap & AC_PINCAP_VREF_100)
2383 return AC_PINCTL_VREF_100;
2384 if (pincap & AC_PINCAP_VREF_80)
2385 return AC_PINCTL_VREF_80;
2386 if (pincap & AC_PINCAP_VREF_50)
2387 return AC_PINCTL_VREF_50;
2388 if (pincap & AC_PINCAP_VREF_GRD)
2389 return AC_PINCTL_VREF_GRD;
2390 return 0;
2391}
2392
Matt Porter403d1942005-11-29 15:00:51 +01002393static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2394
2395{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002396 snd_hda_codec_write_cache(codec, nid, 0,
2397 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002398}
2399
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002400#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2401
2402static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2403 struct snd_ctl_elem_value *ucontrol)
2404{
2405 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2406 struct sigmatel_spec *spec = codec->spec;
2407
Takashi Iwaid7a89432008-11-12 09:48:04 +01002408 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002409 return 0;
2410}
2411
Takashi Iwai62558ce2009-07-29 14:23:09 +02002412static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002413
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002414static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2415 struct snd_ctl_elem_value *ucontrol)
2416{
2417 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2418 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002419 int nid = kcontrol->private_value;
2420
2421 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002422
2423 /* check to be sure that the ports are upto date with
2424 * switch changes
2425 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002426 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002427
2428 return 1;
2429}
2430
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002431static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2432 struct snd_ctl_elem_info *uinfo)
2433{
2434 int i;
2435 static char *texts[] = {
2436 "Mic In", "Line In", "Line Out"
2437 };
2438
2439 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2440 struct sigmatel_spec *spec = codec->spec;
2441 hda_nid_t nid = kcontrol->private_value;
2442
2443 if (nid == spec->mic_switch || nid == spec->line_switch)
2444 i = 3;
2445 else
2446 i = 2;
2447
2448 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2449 uinfo->value.enumerated.items = i;
2450 uinfo->count = 1;
2451 if (uinfo->value.enumerated.item >= i)
2452 uinfo->value.enumerated.item = i-1;
2453 strcpy(uinfo->value.enumerated.name,
2454 texts[uinfo->value.enumerated.item]);
2455
2456 return 0;
2457}
2458
2459static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2460 struct snd_ctl_elem_value *ucontrol)
2461{
2462 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2463 hda_nid_t nid = kcontrol->private_value;
2464 unsigned int vref = stac92xx_vref_get(codec, nid);
2465
2466 if (vref == stac92xx_get_default_vref(codec, nid))
2467 ucontrol->value.enumerated.item[0] = 0;
2468 else if (vref == AC_PINCTL_VREF_GRD)
2469 ucontrol->value.enumerated.item[0] = 1;
2470 else if (vref == AC_PINCTL_VREF_HIZ)
2471 ucontrol->value.enumerated.item[0] = 2;
2472
2473 return 0;
2474}
2475
2476static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2477 struct snd_ctl_elem_value *ucontrol)
2478{
2479 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2480 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002481 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002482 hda_nid_t nid = kcontrol->private_value;
2483
2484 if (ucontrol->value.enumerated.item[0] == 0)
2485 new_vref = stac92xx_get_default_vref(codec, nid);
2486 else if (ucontrol->value.enumerated.item[0] == 1)
2487 new_vref = AC_PINCTL_VREF_GRD;
2488 else if (ucontrol->value.enumerated.item[0] == 2)
2489 new_vref = AC_PINCTL_VREF_HIZ;
2490 else
2491 return 0;
2492
2493 if (new_vref != stac92xx_vref_get(codec, nid)) {
2494 error = stac92xx_vref_set(codec, nid, new_vref);
2495 return error;
2496 }
2497
2498 return 0;
2499}
2500
2501static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2502 struct snd_ctl_elem_info *uinfo)
2503{
2504 static char *texts[2];
2505 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2506 struct sigmatel_spec *spec = codec->spec;
2507
2508 if (kcontrol->private_value == spec->line_switch)
2509 texts[0] = "Line In";
2510 else
2511 texts[0] = "Mic In";
2512 texts[1] = "Line Out";
2513 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2514 uinfo->value.enumerated.items = 2;
2515 uinfo->count = 1;
2516
2517 if (uinfo->value.enumerated.item >= 2)
2518 uinfo->value.enumerated.item = 1;
2519 strcpy(uinfo->value.enumerated.name,
2520 texts[uinfo->value.enumerated.item]);
2521
2522 return 0;
2523}
Matt Porter403d1942005-11-29 15:00:51 +01002524
2525static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2526{
2527 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2528 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002529 hda_nid_t nid = kcontrol->private_value;
2530 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002531
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002532 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002533 return 0;
2534}
2535
2536static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2537{
2538 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2539 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002540 hda_nid_t nid = kcontrol->private_value;
2541 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2542 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002543
2544 spec->io_switch[io_idx] = val;
2545
2546 if (val)
2547 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002548 else {
2549 unsigned int pinctl = AC_PINCTL_IN_EN;
2550 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002551 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002552 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2553 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002554
2555 /* check the auto-mute again: we need to mute/unmute the speaker
2556 * appropriately according to the pin direction
2557 */
2558 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002559 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002560
Matt Porter403d1942005-11-29 15:00:51 +01002561 return 1;
2562}
2563
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002564#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2565
2566static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2567 struct snd_ctl_elem_value *ucontrol)
2568{
2569 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2570 struct sigmatel_spec *spec = codec->spec;
2571
2572 ucontrol->value.integer.value[0] = spec->clfe_swap;
2573 return 0;
2574}
2575
2576static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2577 struct snd_ctl_elem_value *ucontrol)
2578{
2579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2580 struct sigmatel_spec *spec = codec->spec;
2581 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002582 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002583
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002584 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002585 return 0;
2586
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002587 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002588
2589 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2590 spec->clfe_swap ? 0x4 : 0x0);
2591
2592 return 1;
2593}
2594
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002595#define STAC_CODEC_HP_SWITCH(xname) \
2596 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2597 .name = xname, \
2598 .index = 0, \
2599 .info = stac92xx_hp_switch_info, \
2600 .get = stac92xx_hp_switch_get, \
2601 .put = stac92xx_hp_switch_put, \
2602 }
2603
Matt Porter403d1942005-11-29 15:00:51 +01002604#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2605 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2606 .name = xname, \
2607 .index = 0, \
2608 .info = stac92xx_io_switch_info, \
2609 .get = stac92xx_io_switch_get, \
2610 .put = stac92xx_io_switch_put, \
2611 .private_value = xpval, \
2612 }
2613
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002614#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2615 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2616 .name = xname, \
2617 .index = 0, \
2618 .info = stac92xx_clfe_switch_info, \
2619 .get = stac92xx_clfe_switch_get, \
2620 .put = stac92xx_clfe_switch_put, \
2621 .private_value = xpval, \
2622 }
Matt Porter403d1942005-11-29 15:00:51 +01002623
Mattc7d4b2f2005-06-27 14:59:41 +02002624enum {
2625 STAC_CTL_WIDGET_VOL,
2626 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002627 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002628 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002629 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002630 STAC_CTL_WIDGET_CLFE_SWITCH,
2631 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002632};
2633
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002634static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002635 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2636 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002637 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002638 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002639 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002640 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002641 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002642};
2643
2644/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002645static struct snd_kcontrol_new *
2646stac_control_new(struct sigmatel_spec *spec,
2647 struct snd_kcontrol_new *ktemp,
2648 const char *name)
Mattc7d4b2f2005-06-27 14:59:41 +02002649{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002650 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002651
Takashi Iwai603c4012008-07-30 15:01:44 +02002652 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2653 knew = snd_array_new(&spec->kctls);
2654 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002655 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002656 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002657 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002658 if (!knew->name) {
2659 /* roolback */
2660 memset(knew, 0, sizeof(*knew));
2661 spec->kctls.alloced--;
2662 return NULL;
2663 }
2664 return knew;
2665}
2666
2667static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2668 struct snd_kcontrol_new *ktemp,
2669 int idx, const char *name,
2670 unsigned long val)
2671{
2672 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2673 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002674 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002675 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002676 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002677 return 0;
2678}
2679
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002680static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2681 int type, int idx, const char *name,
2682 unsigned long val)
2683{
2684 return stac92xx_add_control_temp(spec,
2685 &stac92xx_control_templates[type],
2686 idx, name, val);
2687}
2688
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002689
2690/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002691static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2692 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002693{
2694 return stac92xx_add_control_idx(spec, type, 0, name, val);
2695}
2696
Takashi Iwaie3c75962009-01-23 11:57:22 +01002697static struct snd_kcontrol_new stac_input_src_temp = {
2698 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2699 .name = "Input Source",
2700 .info = stac92xx_mux_enum_info,
2701 .get = stac92xx_mux_enum_get,
2702 .put = stac92xx_mux_enum_put,
2703};
2704
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002705static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2706 hda_nid_t nid, int idx)
2707{
2708 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2709 int control = 0;
2710 struct sigmatel_spec *spec = codec->spec;
2711 char name[22];
2712
2713 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2714 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2715 && nid == spec->line_switch)
2716 control = STAC_CTL_WIDGET_IO_SWITCH;
2717 else if (snd_hda_query_pin_caps(codec, nid)
2718 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2719 control = STAC_CTL_WIDGET_DC_BIAS;
2720 else if (nid == spec->mic_switch)
2721 control = STAC_CTL_WIDGET_IO_SWITCH;
2722 }
2723
2724 if (control) {
2725 strcpy(name, auto_pin_cfg_labels[idx]);
2726 return stac92xx_add_control(codec->spec, control,
2727 strcat(name, " Jack Mode"), nid);
2728 }
2729
2730 return 0;
2731}
2732
Takashi Iwaie3c75962009-01-23 11:57:22 +01002733static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2734{
2735 struct snd_kcontrol_new *knew;
2736 struct hda_input_mux *imux = &spec->private_imux;
2737
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002738 if (spec->auto_mic)
2739 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002740 if (!spec->num_adcs || imux->num_items <= 1)
2741 return 0; /* no need for input source control */
2742 knew = stac_control_new(spec, &stac_input_src_temp,
2743 stac_input_src_temp.name);
2744 if (!knew)
2745 return -ENOMEM;
2746 knew->count = spec->num_adcs;
2747 return 0;
2748}
2749
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002750/* check whether the line-input can be used as line-out */
2751static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002752{
2753 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002754 struct auto_pin_cfg *cfg = &spec->autocfg;
2755 hda_nid_t nid;
2756 unsigned int pincap;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002757
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002758 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2759 return 0;
2760 nid = cfg->input_pins[AUTO_PIN_LINE];
Takashi Iwai1327a322009-03-23 13:07:47 +01002761 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002762 if (pincap & AC_PINCAP_OUT)
2763 return nid;
Matt Porter403d1942005-11-29 15:00:51 +01002764 return 0;
2765}
2766
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002767/* check whether the mic-input can be used as line-out */
2768static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2769{
2770 struct sigmatel_spec *spec = codec->spec;
2771 struct auto_pin_cfg *cfg = &spec->autocfg;
2772 unsigned int def_conf, pincap;
2773 unsigned int mic_pin;
2774
2775 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2776 return 0;
2777 mic_pin = AUTO_PIN_MIC;
2778 for (;;) {
2779 hda_nid_t nid = cfg->input_pins[mic_pin];
Takashi Iwai330ee992009-02-20 14:33:36 +01002780 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002781 /* some laptops have an internal analog microphone
2782 * which can't be used as a output */
2783 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai1327a322009-03-23 13:07:47 +01002784 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002785 if (pincap & AC_PINCAP_OUT)
2786 return nid;
2787 }
2788 if (mic_pin == AUTO_PIN_MIC)
2789 mic_pin = AUTO_PIN_FRONT_MIC;
2790 else
2791 break;
2792 }
2793 return 0;
2794}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002795
2796static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2797{
2798 int i;
2799
2800 for (i = 0; i < spec->multiout.num_dacs; i++) {
2801 if (spec->multiout.dac_nids[i] == nid)
2802 return 1;
2803 }
2804
2805 return 0;
2806}
2807
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002808static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2809{
2810 int i;
2811 if (is_in_dac_nids(spec, nid))
2812 return 1;
2813 for (i = 0; i < spec->autocfg.hp_outs; i++)
2814 if (spec->hp_dacs[i] == nid)
2815 return 1;
2816 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2817 if (spec->speaker_dacs[i] == nid)
2818 return 1;
2819 return 0;
2820}
2821
2822static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2823{
2824 struct sigmatel_spec *spec = codec->spec;
2825 int j, conn_len;
2826 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2827 unsigned int wcaps, wtype;
2828
2829 conn_len = snd_hda_get_connections(codec, nid, conn,
2830 HDA_MAX_CONNECTIONS);
2831 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002832 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002833 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002834 /* we check only analog outputs */
2835 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2836 continue;
2837 /* if this route has a free DAC, assign it */
2838 if (!check_all_dac_nids(spec, conn[j])) {
2839 if (conn_len > 1) {
2840 /* select this DAC in the pin's input mux */
2841 snd_hda_codec_write_cache(codec, nid, 0,
2842 AC_VERB_SET_CONNECT_SEL, j);
2843 }
2844 return conn[j];
2845 }
2846 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002847 /* if all DACs are already assigned, connect to the primary DAC */
2848 if (conn_len > 1) {
2849 for (j = 0; j < conn_len; j++) {
2850 if (conn[j] == spec->multiout.dac_nids[0]) {
2851 snd_hda_codec_write_cache(codec, nid, 0,
2852 AC_VERB_SET_CONNECT_SEL, j);
2853 break;
2854 }
2855 }
2856 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002857 return 0;
2858}
2859
2860static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2861static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2862
Matt Porter3cc08dc2006-01-23 15:27:49 +01002863/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002864 * Fill in the dac_nids table from the parsed pin configuration
2865 * This function only works when every pin in line_out_pins[]
2866 * contains atleast one DAC in its connection list. Some 92xx
2867 * codecs are not connected directly to a DAC, such as the 9200
2868 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002869 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002870static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002871{
2872 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002873 struct auto_pin_cfg *cfg = &spec->autocfg;
2874 int i;
2875 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002876
Mattc7d4b2f2005-06-27 14:59:41 +02002877 for (i = 0; i < cfg->line_outs; i++) {
2878 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002879 dac = get_unassigned_dac(codec, nid);
2880 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002881 if (spec->multiout.num_dacs > 0) {
2882 /* we have already working output pins,
2883 * so let's drop the broken ones again
2884 */
2885 cfg->line_outs = spec->multiout.num_dacs;
2886 break;
2887 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002888 /* error out, no available DAC found */
2889 snd_printk(KERN_ERR
2890 "%s: No available DAC for pin 0x%x\n",
2891 __func__, nid);
2892 return -ENODEV;
2893 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002894 add_spec_dacs(spec, dac);
2895 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002896
Takashi Iwai139e0712009-03-06 12:10:41 +01002897 for (i = 0; i < cfg->hp_outs; i++) {
2898 nid = cfg->hp_pins[i];
2899 dac = get_unassigned_dac(codec, nid);
2900 if (dac) {
2901 if (!spec->multiout.hp_nid)
2902 spec->multiout.hp_nid = dac;
2903 else
2904 add_spec_extra_dacs(spec, dac);
2905 }
2906 spec->hp_dacs[i] = dac;
2907 }
2908
2909 for (i = 0; i < cfg->speaker_outs; i++) {
2910 nid = cfg->speaker_pins[i];
2911 dac = get_unassigned_dac(codec, nid);
2912 if (dac)
2913 add_spec_extra_dacs(spec, dac);
2914 spec->speaker_dacs[i] = dac;
2915 }
2916
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002917 /* add line-in as output */
2918 nid = check_line_out_switch(codec);
2919 if (nid) {
2920 dac = get_unassigned_dac(codec, nid);
2921 if (dac) {
2922 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2923 nid, cfg->line_outs);
2924 cfg->line_out_pins[cfg->line_outs] = nid;
2925 cfg->line_outs++;
2926 spec->line_switch = nid;
2927 add_spec_dacs(spec, dac);
2928 }
2929 }
2930 /* add mic as output */
2931 nid = check_mic_out_switch(codec);
2932 if (nid) {
2933 dac = get_unassigned_dac(codec, nid);
2934 if (dac) {
2935 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
2936 nid, cfg->line_outs);
2937 cfg->line_out_pins[cfg->line_outs] = nid;
2938 cfg->line_outs++;
2939 spec->mic_switch = nid;
2940 add_spec_dacs(spec, dac);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002941 }
Mattc7d4b2f2005-06-27 14:59:41 +02002942 }
2943
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002944 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02002945 spec->multiout.num_dacs,
2946 spec->multiout.dac_nids[0],
2947 spec->multiout.dac_nids[1],
2948 spec->multiout.dac_nids[2],
2949 spec->multiout.dac_nids[3],
2950 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002951
Mattc7d4b2f2005-06-27 14:59:41 +02002952 return 0;
2953}
2954
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002955/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01002956static int create_controls_idx(struct hda_codec *codec, const char *pfx,
2957 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002958{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002959 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002960 char name[32];
2961 int err;
2962
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002963 if (!spec->check_volume_offset) {
2964 unsigned int caps, step, nums, db_scale;
2965 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
2966 step = (caps & AC_AMPCAP_STEP_SIZE) >>
2967 AC_AMPCAP_STEP_SIZE_SHIFT;
2968 step = (step + 1) * 25; /* in .01dB unit */
2969 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
2970 AC_AMPCAP_NUM_STEPS_SHIFT;
2971 db_scale = nums * step;
2972 /* if dB scale is over -64dB, and finer enough,
2973 * let's reduce it to half
2974 */
2975 if (db_scale > 6400 && nums >= 0x1f)
2976 spec->volume_offset = nums / 2;
2977 spec->check_volume_offset = 1;
2978 }
2979
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002980 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01002981 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002982 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
2983 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002984 if (err < 0)
2985 return err;
2986 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01002987 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002988 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2989 if (err < 0)
2990 return err;
2991 return 0;
2992}
2993
Takashi Iwai668b9652009-03-06 10:13:24 +01002994#define create_controls(codec, pfx, nid, chs) \
2995 create_controls_idx(codec, pfx, 0, nid, chs)
2996
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002997static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2998{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002999 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003000 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3001 return 1;
3002 } else {
3003 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3004 spec->multiout.num_dacs++;
3005 }
3006 return 0;
3007}
3008
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003009static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003010{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003011 int i;
3012 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3013 if (!spec->multiout.extra_out_nid[i]) {
3014 spec->multiout.extra_out_nid[i] = nid;
3015 return 0;
3016 }
3017 }
3018 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3019 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003020}
3021
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003022/* Create output controls
3023 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3024 */
3025static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3026 const hda_nid_t *pins,
3027 const hda_nid_t *dac_nids,
3028 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003029{
Takashi Iwai76624532008-12-19 10:09:47 +01003030 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003031 static const char *chname[4] = {
3032 "Front", "Surround", NULL /*CLFE*/, "Side"
3033 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003034 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003035 int i, err;
3036 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003037
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003038 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003039 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3040 wid_caps = get_wcaps(codec, pins[i]);
3041 if (wid_caps & AC_WCAP_UNSOL_CAP)
3042 spec->hp_detect = 1;
3043 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003044 nid = dac_nids[i];
3045 if (!nid)
3046 continue;
3047 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003048 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003049 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003050 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003051 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003052 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003053 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003054 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003055
3056 wid_caps = get_wcaps(codec, nid);
3057
3058 if (wid_caps & AC_WCAP_LR_SWAP) {
3059 err = stac92xx_add_control(spec,
3060 STAC_CTL_WIDGET_CLFE_SWITCH,
3061 "Swap Center/LFE Playback Switch", nid);
3062
3063 if (err < 0)
3064 return err;
3065 }
3066
Mattc7d4b2f2005-06-27 14:59:41 +02003067 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003068 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003069 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003070 switch (type) {
3071 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003072 name = "Headphone";
3073 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003074 break;
3075 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003076 name = "Speaker";
3077 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003078 break;
3079 default:
3080 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003081 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003082 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003083 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003084 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003085 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003086 return err;
3087 }
3088 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003089 return 0;
3090}
3091
Takashi Iwai6479c632009-07-28 18:20:25 +02003092static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3093 unsigned long sw, int idx)
3094{
3095 int err;
3096 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003097 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003098 if (err < 0)
3099 return err;
3100 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003101 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003102 if (err < 0)
3103 return err;
3104 return 0;
3105}
3106
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003107/* add playback controls from the parsed DAC table */
3108static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3109 const struct auto_pin_cfg *cfg)
3110{
3111 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003112 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003113 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003114 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003115
3116 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3117 spec->multiout.dac_nids,
3118 cfg->line_out_type);
3119 if (err < 0)
3120 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003121
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003122 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003123 err = stac92xx_add_control(spec,
3124 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003125 "Headphone as Line Out Switch",
3126 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003127 if (err < 0)
3128 return err;
3129 }
3130
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003131 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3132 nid = cfg->input_pins[idx];
3133 if (nid) {
3134 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3135 if (err < 0)
3136 return err;
3137 }
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003138 }
Matt Porter403d1942005-11-29 15:00:51 +01003139
Mattc7d4b2f2005-06-27 14:59:41 +02003140 return 0;
3141}
3142
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003143/* add playback controls for Speaker and HP outputs */
3144static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3145 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003146{
3147 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003148 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003149
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003150 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3151 spec->hp_dacs, AUTO_PIN_HP_OUT);
3152 if (err < 0)
3153 return err;
3154
3155 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3156 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3157 if (err < 0)
3158 return err;
3159
Mattc7d4b2f2005-06-27 14:59:41 +02003160 return 0;
3161}
3162
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003163/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003164static const char *stac92xx_mono_labels[4] = {
3165 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003166};
3167
3168/* create mono mux for mono out on capable codecs */
3169static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3170{
3171 struct sigmatel_spec *spec = codec->spec;
3172 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3173 int i, num_cons;
3174 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3175
3176 num_cons = snd_hda_get_connections(codec,
3177 spec->mono_nid,
3178 con_lst,
3179 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003180 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003181 return -EINVAL;
3182
3183 for (i = 0; i < num_cons; i++) {
3184 mono_mux->items[mono_mux->num_items].label =
3185 stac92xx_mono_labels[i];
3186 mono_mux->items[mono_mux->num_items].index = i;
3187 mono_mux->num_items++;
3188 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003189
3190 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3191 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003192}
3193
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003194/* create PC beep volume controls */
3195static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3196 hda_nid_t nid)
3197{
3198 struct sigmatel_spec *spec = codec->spec;
3199 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3200 int err;
3201
3202 /* check for mute support for the the amp */
3203 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3204 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3205 "PC Beep Playback Switch",
3206 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3207 if (err < 0)
3208 return err;
3209 }
3210
3211 /* check to see if there is volume support for the amp */
3212 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3213 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3214 "PC Beep Playback Volume",
3215 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3216 if (err < 0)
3217 return err;
3218 }
3219 return 0;
3220}
3221
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003222#ifdef CONFIG_SND_HDA_INPUT_BEEP
3223#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3224
3225static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3226 struct snd_ctl_elem_value *ucontrol)
3227{
3228 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3229 ucontrol->value.integer.value[0] = codec->beep->enabled;
3230 return 0;
3231}
3232
3233static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3234 struct snd_ctl_elem_value *ucontrol)
3235{
3236 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3237 int enabled = !!ucontrol->value.integer.value[0];
3238 if (codec->beep->enabled != enabled) {
3239 codec->beep->enabled = enabled;
3240 return 1;
3241 }
3242 return 0;
3243}
3244
3245static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3246 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3247 .info = stac92xx_dig_beep_switch_info,
3248 .get = stac92xx_dig_beep_switch_get,
3249 .put = stac92xx_dig_beep_switch_put,
3250};
3251
3252static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3253{
3254 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3255 0, "PC Beep Playback Switch", 0);
3256}
3257#endif
3258
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003259static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3260{
3261 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003262 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003263
3264 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003265 hda_nid_t nid;
3266 unsigned int wcaps;
3267 unsigned long val;
3268
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003269 nid = spec->mux_nids[i];
3270 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003271 if (!(wcaps & AC_WCAP_OUT_AMP))
3272 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003273
Takashi Iwai667067d2009-08-13 18:14:42 +02003274 /* check whether already the same control was created as
3275 * normal Capture Volume.
3276 */
3277 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3278 for (j = 0; j < spec->num_caps; j++) {
3279 if (spec->capvols[j] == val)
3280 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003281 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003282 if (j < spec->num_caps)
3283 continue;
3284
3285 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3286 "Mux Capture Volume", val);
3287 if (err < 0)
3288 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003289 }
3290 return 0;
3291};
3292
Matthew Ranostayd9737752008-09-07 12:03:41 +02003293static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003294 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003295};
3296
3297static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3298{
3299 struct sigmatel_spec *spec = codec->spec;
3300 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003301 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003302 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003303 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003304
3305 num_cons = snd_hda_get_connections(codec,
3306 spec->smux_nids[0],
3307 con_lst,
3308 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003309 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003310 return -EINVAL;
3311
Matthew Ranostay65973632008-09-16 10:39:37 -04003312 if (!labels)
3313 labels = stac92xx_spdif_labels;
3314
Matthew Ranostayd9737752008-09-07 12:03:41 +02003315 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003316 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003317 spdif_mux->items[spdif_mux->num_items].index = i;
3318 spdif_mux->num_items++;
3319 }
3320
3321 return 0;
3322}
3323
Matt Porter8b657272006-10-26 17:12:59 +02003324/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003325static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003326 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3327 "Digital Mic 3", "Digital Mic 4"
3328};
3329
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003330static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3331 hda_nid_t nid)
3332{
3333 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3334 int i, nums;
3335
3336 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3337 for (i = 0; i < nums; i++)
3338 if (conn[i] == nid)
3339 return i;
3340 return -1;
3341}
3342
Takashi Iwai667067d2009-08-13 18:14:42 +02003343/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003344/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003345static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003346 const char *label, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003347{
3348 unsigned int caps, nums;
3349 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003350 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003351
Takashi Iwai96f845d2009-08-29 00:49:36 +02003352 if (direction == HDA_OUTPUT)
3353 caps = AC_WCAP_OUT_AMP;
3354 else
3355 caps = AC_WCAP_IN_AMP;
3356 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003357 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003358 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003359 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3360 if (!nums)
3361 return 0;
3362 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003363 err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3364 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3365 if (err < 0)
3366 return err;
3367 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003368}
3369
Matt Porter8b657272006-10-26 17:12:59 +02003370/* create playback/capture controls for input pins on dmic capable codecs */
3371static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3372 const struct auto_pin_cfg *cfg)
3373{
3374 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003375 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003376 struct hda_input_mux *dimux = &spec->private_dimux;
Takashi Iwai5207e102009-07-30 13:09:08 +02003377 int err, i, active_mics;
3378 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003379
3380 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3381 dimux->items[dimux->num_items].index = 0;
3382 dimux->num_items++;
3383
Takashi Iwai5207e102009-07-30 13:09:08 +02003384 active_mics = 0;
3385 for (i = 0; i < spec->num_dmics; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003386 /* check the validity: sometimes it's a dead vendor-spec node */
3387 if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3388 != AC_WID_PIN)
3389 continue;
Takashi Iwai5207e102009-07-30 13:09:08 +02003390 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3391 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3392 active_mics++;
3393 }
3394
Matt Porter8b657272006-10-26 17:12:59 +02003395 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003396 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003397 int index;
Takashi Iwai5207e102009-07-30 13:09:08 +02003398 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003399
Takashi Iwai667067d2009-08-13 18:14:42 +02003400 nid = spec->dmic_nids[i];
3401 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3402 continue;
3403 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003404 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3405 continue;
3406
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003407 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3408 if (index < 0)
3409 continue;
3410
Takashi Iwai5207e102009-07-30 13:09:08 +02003411 if (active_mics == 1)
3412 label = "Digital Mic";
3413 else
3414 label = stac92xx_dmic_labels[dimux->num_items];
3415
Takashi Iwai96f845d2009-08-29 00:49:36 +02003416 err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003417 if (err < 0)
3418 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003419 if (!err) {
3420 err = create_elem_capture_vol(codec, nid, label,
3421 HDA_OUTPUT);
3422 if (err < 0)
3423 return err;
3424 }
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003425
Takashi Iwai5207e102009-07-30 13:09:08 +02003426 dimux->items[dimux->num_items].label = label;
Matt Porter8b657272006-10-26 17:12:59 +02003427 dimux->items[dimux->num_items].index = index;
3428 dimux->num_items++;
Takashi Iwai5207e102009-07-30 13:09:08 +02003429 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3430 imux->items[imux->num_items].label = label;
3431 imux->items[imux->num_items].index = index;
3432 imux->num_items++;
3433 }
Matt Porter8b657272006-10-26 17:12:59 +02003434 }
3435
3436 return 0;
3437}
3438
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003439static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3440 hda_nid_t *fixed, hda_nid_t *ext)
3441{
3442 unsigned int cfg;
3443
3444 if (!nid)
3445 return 0;
3446 cfg = snd_hda_codec_get_pincfg(codec, nid);
3447 switch (get_defcfg_connect(cfg)) {
3448 case AC_JACK_PORT_FIXED:
3449 if (*fixed)
3450 return 1; /* already occupied */
3451 *fixed = nid;
3452 break;
3453 case AC_JACK_PORT_COMPLEX:
3454 if (*ext)
3455 return 1; /* already occupied */
3456 *ext = nid;
3457 break;
3458 }
3459 return 0;
3460}
3461
3462static int set_mic_route(struct hda_codec *codec,
3463 struct sigmatel_mic_route *mic,
3464 hda_nid_t pin)
3465{
3466 struct sigmatel_spec *spec = codec->spec;
3467 struct auto_pin_cfg *cfg = &spec->autocfg;
3468 int i;
3469
3470 mic->pin = pin;
3471 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3472 if (pin == cfg->input_pins[i])
3473 break;
3474 if (i <= AUTO_PIN_FRONT_MIC) {
3475 /* analog pin */
3476 mic->dmux_idx = 0;
3477 i = get_connection_index(codec, spec->mux_nids[0], pin);
3478 if (i < 0)
3479 return -1;
3480 mic->mux_idx = i;
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003481 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003482 /* digital pin */
3483 mic->mux_idx = 0;
3484 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3485 if (i < 0)
3486 return -1;
3487 mic->dmux_idx = i;
3488 }
3489 return 0;
3490}
3491
3492/* return non-zero if the device is for automatic mic switch */
3493static int stac_check_auto_mic(struct hda_codec *codec)
3494{
3495 struct sigmatel_spec *spec = codec->spec;
3496 struct auto_pin_cfg *cfg = &spec->autocfg;
3497 hda_nid_t fixed, ext;
3498 int i;
3499
3500 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3501 if (cfg->input_pins[i])
3502 return 0; /* must be exclusively mics */
3503 }
3504 fixed = ext = 0;
3505 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3506 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3507 return 0;
3508 for (i = 0; i < spec->num_dmics; i++)
3509 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3510 return 0;
3511 if (!fixed || !ext)
3512 return 0;
3513 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3514 return 0; /* no unsol support */
3515 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3516 set_mic_route(codec, &spec->int_mic, fixed))
3517 return 0; /* something is wrong */
3518 return 1;
3519}
3520
Mattc7d4b2f2005-06-27 14:59:41 +02003521/* create playback/capture controls for input pins */
3522static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3523{
3524 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003525 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003526 int i, j;
Mattc7d4b2f2005-06-27 14:59:41 +02003527
3528 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003529 hda_nid_t nid = cfg->input_pins[i];
3530 int index, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003531
Takashi Iwai667067d2009-08-13 18:14:42 +02003532 if (!nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02003533 continue;
3534 index = -1;
3535 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003536 index = get_connection_index(codec, spec->mux_nids[j],
3537 nid);
3538 if (index >= 0)
3539 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003540 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003541 if (index < 0)
3542 continue;
3543
3544 err = create_elem_capture_vol(codec, nid,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003545 auto_pin_cfg_labels[i],
3546 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003547 if (err < 0)
3548 return err;
3549
Takashi Iwai314634b2006-09-21 11:56:18 +02003550 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3551 imux->items[imux->num_items].index = index;
3552 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003553 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003554 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003555
Steve Longerbeam7b043892007-05-03 20:50:03 +02003556 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003557 /*
3558 * Set the current input for the muxes.
3559 * The STAC9221 has two input muxes with identical source
3560 * NID lists. Hopefully this won't get confused.
3561 */
3562 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003563 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3564 AC_VERB_SET_CONNECT_SEL,
3565 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003566 }
3567 }
3568
Mattc7d4b2f2005-06-27 14:59:41 +02003569 return 0;
3570}
3571
Mattc7d4b2f2005-06-27 14:59:41 +02003572static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3573{
3574 struct sigmatel_spec *spec = codec->spec;
3575 int i;
3576
3577 for (i = 0; i < spec->autocfg.line_outs; i++) {
3578 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3579 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3580 }
3581}
3582
3583static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3584{
3585 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003586 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003587
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003588 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3589 hda_nid_t pin;
3590 pin = spec->autocfg.hp_pins[i];
3591 if (pin) /* connect to front */
3592 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3593 }
3594 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3595 hda_nid_t pin;
3596 pin = spec->autocfg.speaker_pins[i];
3597 if (pin) /* connect to front */
3598 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3599 }
Mattc7d4b2f2005-06-27 14:59:41 +02003600}
3601
Matt Porter3cc08dc2006-01-23 15:27:49 +01003602static 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 +02003603{
3604 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003605 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003606 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003607
Matt Porter8b657272006-10-26 17:12:59 +02003608 if ((err = snd_hda_parse_pin_def_config(codec,
3609 &spec->autocfg,
3610 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003611 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003612 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003613 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003614
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003615 /* If we have no real line-out pin and multiple hp-outs, HPs should
3616 * be set up as multi-channel outputs.
3617 */
3618 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3619 spec->autocfg.hp_outs > 1) {
3620 /* Copy hp_outs to line_outs, backup line_outs in
3621 * speaker_outs so that the following routines can handle
3622 * HP pins as primary outputs.
3623 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003624 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003625 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3626 sizeof(spec->autocfg.line_out_pins));
3627 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3628 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3629 sizeof(spec->autocfg.hp_pins));
3630 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003631 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3632 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003633 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003634 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003635 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003636 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3637 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003638 u32 caps = query_amp_caps(codec,
3639 spec->autocfg.mono_out_pin, dir);
3640 hda_nid_t conn_list[1];
3641
3642 /* get the mixer node and then the mono mux if it exists */
3643 if (snd_hda_get_connections(codec,
3644 spec->autocfg.mono_out_pin, conn_list, 1) &&
3645 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003646 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003647
3648 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003649 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003650 /* LR swap check, some stac925x have a mux that
3651 * changes the DACs output path instead of the
3652 * mono-mux path.
3653 */
3654 if (wid_type == AC_WID_AUD_SEL &&
3655 !(wcaps & AC_WCAP_LR_SWAP))
3656 spec->mono_nid = conn_list[0];
3657 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003658 if (dir) {
3659 hda_nid_t nid = spec->autocfg.mono_out_pin;
3660
3661 /* most mono outs have a least a mute/unmute switch */
3662 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3663 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3664 "Mono Playback Switch",
3665 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003666 if (err < 0)
3667 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003668 /* check for volume support for the amp */
3669 if ((caps & AC_AMPCAP_NUM_STEPS)
3670 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3671 err = stac92xx_add_control(spec,
3672 STAC_CTL_WIDGET_VOL,
3673 "Mono Playback Volume",
3674 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3675 if (err < 0)
3676 return err;
3677 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003678 }
3679
3680 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3681 AC_PINCTL_OUT_EN);
3682 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003683
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003684 if (!spec->multiout.num_dacs) {
3685 err = stac92xx_auto_fill_dac_nids(codec);
3686 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003687 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003688 err = stac92xx_auto_create_multi_out_ctls(codec,
3689 &spec->autocfg);
3690 if (err < 0)
3691 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003692 }
Mattc7d4b2f2005-06-27 14:59:41 +02003693
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003694 /* setup analog beep controls */
3695 if (spec->anabeep_nid > 0) {
3696 err = stac92xx_auto_create_beep_ctls(codec,
3697 spec->anabeep_nid);
3698 if (err < 0)
3699 return err;
3700 }
3701
3702 /* setup digital beep controls and input device */
3703#ifdef CONFIG_SND_HDA_INPUT_BEEP
3704 if (spec->digbeep_nid > 0) {
3705 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003706 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003707
3708 err = stac92xx_auto_create_beep_ctls(codec, nid);
3709 if (err < 0)
3710 return err;
3711 err = snd_hda_attach_beep_device(codec, nid);
3712 if (err < 0)
3713 return err;
Takashi Iwaifa797962009-05-19 12:50:04 +02003714 /* IDT/STAC codecs have linear beep tone parameter */
3715 codec->beep->linear_tone = 1;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003716 /* if no beep switch is available, make its own one */
3717 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3718 if (codec->beep &&
3719 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3720 err = stac92xx_beep_switch_ctl(codec);
3721 if (err < 0)
3722 return err;
3723 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003724 }
3725#endif
3726
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003727 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003728 if (err < 0)
3729 return err;
3730
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003731 /* All output parsing done, now restore the swapped hp pins */
3732 if (hp_swap) {
3733 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3734 sizeof(spec->autocfg.hp_pins));
3735 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3736 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3737 spec->autocfg.line_outs = 0;
3738 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003739
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003740 if (stac_check_auto_mic(codec)) {
3741 spec->auto_mic = 1;
3742 /* only one capture for auto-mic */
3743 spec->num_adcs = 1;
3744 spec->num_caps = 1;
3745 spec->num_muxes = 1;
3746 }
3747
Takashi Iwai6479c632009-07-28 18:20:25 +02003748 for (i = 0; i < spec->num_caps; i++) {
3749 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3750 spec->capsws[i], i);
3751 if (err < 0)
3752 return err;
3753 }
3754
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003755 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003756 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003757 return err;
3758
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003759 if (spec->mono_nid > 0) {
3760 err = stac92xx_auto_create_mono_output_ctls(codec);
3761 if (err < 0)
3762 return err;
3763 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003764 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003765 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3766 &spec->autocfg)) < 0)
3767 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003768 if (spec->num_muxes > 0) {
3769 err = stac92xx_auto_create_mux_input_ctls(codec);
3770 if (err < 0)
3771 return err;
3772 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003773 if (spec->num_smuxes > 0) {
3774 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3775 if (err < 0)
3776 return err;
3777 }
Matt Porter8b657272006-10-26 17:12:59 +02003778
Takashi Iwaie3c75962009-01-23 11:57:22 +01003779 err = stac92xx_add_input_source(spec);
3780 if (err < 0)
3781 return err;
3782
Mattc7d4b2f2005-06-27 14:59:41 +02003783 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003784 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003785 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003786
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003787 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003788 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003789 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003790 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003791
Takashi Iwai603c4012008-07-30 15:01:44 +02003792 if (spec->kctls.list)
3793 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003794
3795 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003796 if (!spec->dinput_mux)
3797 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003798 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003799 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003800 return 1;
3801}
3802
Takashi Iwai82bc9552006-03-21 11:24:42 +01003803/* add playback controls for HP output */
3804static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3805 struct auto_pin_cfg *cfg)
3806{
3807 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003808 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003809 unsigned int wid_caps;
3810
3811 if (! pin)
3812 return 0;
3813
3814 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003815 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003816 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003817
3818 return 0;
3819}
3820
Richard Fish160ea0d2006-09-06 13:58:25 +02003821/* add playback controls for LFE output */
3822static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3823 struct auto_pin_cfg *cfg)
3824{
3825 struct sigmatel_spec *spec = codec->spec;
3826 int err;
3827 hda_nid_t lfe_pin = 0x0;
3828 int i;
3829
3830 /*
3831 * search speaker outs and line outs for a mono speaker pin
3832 * with an amp. If one is found, add LFE controls
3833 * for it.
3834 */
3835 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3836 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003837 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003838 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3839 if (wcaps == AC_WCAP_OUT_AMP)
3840 /* found a mono speaker with an amp, must be lfe */
3841 lfe_pin = pin;
3842 }
3843
3844 /* if speaker_outs is 0, then speakers may be in line_outs */
3845 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3846 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3847 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003848 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01003849 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01003850 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003851 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003852 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3853 if (wcaps == AC_WCAP_OUT_AMP)
3854 /* found a mono speaker with an amp,
3855 must be lfe */
3856 lfe_pin = pin;
3857 }
3858 }
3859 }
3860
3861 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003862 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003863 if (err < 0)
3864 return err;
3865 }
3866
3867 return 0;
3868}
3869
Mattc7d4b2f2005-06-27 14:59:41 +02003870static int stac9200_parse_auto_config(struct hda_codec *codec)
3871{
3872 struct sigmatel_spec *spec = codec->spec;
3873 int err;
3874
Kailang Yangdf694da2005-12-05 19:42:22 +01003875 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003876 return err;
3877
3878 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3879 return err;
3880
Takashi Iwai82bc9552006-03-21 11:24:42 +01003881 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3882 return err;
3883
Richard Fish160ea0d2006-09-06 13:58:25 +02003884 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3885 return err;
3886
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003887 if (spec->num_muxes > 0) {
3888 err = stac92xx_auto_create_mux_input_ctls(codec);
3889 if (err < 0)
3890 return err;
3891 }
3892
Takashi Iwaie3c75962009-01-23 11:57:22 +01003893 err = stac92xx_add_input_source(spec);
3894 if (err < 0)
3895 return err;
3896
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003897 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02003898 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003899 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003900 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003901
Takashi Iwai603c4012008-07-30 15:01:44 +02003902 if (spec->kctls.list)
3903 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003904
3905 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003906 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003907
3908 return 1;
3909}
3910
Sam Revitch62fe78e2006-05-10 15:09:17 +02003911/*
3912 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3913 * funky external mute control using GPIO pins.
3914 */
3915
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003916static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003917 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003918{
3919 unsigned int gpiostate, gpiomask, gpiodir;
3920
3921 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3922 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003923 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003924
3925 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3926 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003927 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003928
3929 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3930 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003931 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003932
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003933 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003934 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3935
3936 snd_hda_codec_write(codec, codec->afg, 0,
3937 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003938 snd_hda_codec_read(codec, codec->afg, 0,
3939 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003940
3941 msleep(1);
3942
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003943 snd_hda_codec_read(codec, codec->afg, 0,
3944 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003945}
3946
Takashi Iwai8c8145b2009-06-22 17:00:38 +02003947#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +02003948static void stac92xx_free_jack_priv(struct snd_jack *jack)
3949{
3950 struct sigmatel_jack *jacks = jack->private_data;
3951 jacks->nid = 0;
3952 jacks->jack = NULL;
3953}
3954#endif
3955
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003956static int stac92xx_add_jack(struct hda_codec *codec,
3957 hda_nid_t nid, int type)
3958{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02003959#ifdef CONFIG_SND_HDA_INPUT_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003960 struct sigmatel_spec *spec = codec->spec;
3961 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01003962 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003963 int connectivity = get_defcfg_connect(def_conf);
3964 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02003965 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003966
3967 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3968 return 0;
3969
3970 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3971 jack = snd_array_new(&spec->jacks);
3972 if (!jack)
3973 return -ENOMEM;
3974 jack->nid = nid;
3975 jack->type = type;
3976
Takashi Iwai86de74162009-07-22 16:02:46 +02003977 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003978 snd_hda_get_jack_type(def_conf),
3979 snd_hda_get_jack_connectivity(def_conf),
3980 snd_hda_get_jack_location(def_conf));
3981
Takashi Iwai95c09092009-04-14 16:15:29 +02003982 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
3983 if (err < 0) {
3984 jack->nid = 0;
3985 return err;
3986 }
3987 jack->jack->private_data = jack;
3988 jack->jack->private_free = stac92xx_free_jack_priv;
Takashi Iwaie4973e12008-11-18 09:32:42 +01003989#endif
Takashi Iwai95c09092009-04-14 16:15:29 +02003990 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003991}
3992
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003993static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3994 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003995{
3996 struct sigmatel_event *event;
3997
3998 snd_array_init(&spec->events, sizeof(*event), 32);
3999 event = snd_array_new(&spec->events);
4000 if (!event)
4001 return -ENOMEM;
4002 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004003 event->type = type;
4004 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004005 event->data = data;
4006
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004007 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004008}
4009
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004010static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004011 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004012{
4013 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004014 struct sigmatel_event *event = spec->events.list;
4015 int i;
4016
4017 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004018 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004019 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004020 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004021 return NULL;
4022}
4023
4024static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4025 unsigned char tag)
4026{
4027 struct sigmatel_spec *spec = codec->spec;
4028 struct sigmatel_event *event = spec->events.list;
4029 int i;
4030
4031 for (i = 0; i < spec->events.used; i++, event++) {
4032 if (event->tag == tag)
4033 return event;
4034 }
4035 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004036}
4037
Takashi Iwai62558ce2009-07-29 14:23:09 +02004038/* check if given nid is a valid pin and no other events are assigned
4039 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4040 * Otherwise, returns zero.
4041 */
4042static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4043 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004044{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004045 struct sigmatel_event *event;
4046 int tag;
4047
4048 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004049 return 0;
4050 event = stac_get_event(codec, nid);
4051 if (event) {
4052 if (event->type != type)
4053 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004054 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004055 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004056 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004057 if (tag < 0)
4058 return 0;
4059 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004060 snd_hda_codec_write_cache(codec, nid, 0,
4061 AC_VERB_SET_UNSOLICITED_ENABLE,
4062 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004063 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004064}
4065
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004066static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4067{
4068 int i;
4069 for (i = 0; i < cfg->hp_outs; i++)
4070 if (cfg->hp_pins[i] == nid)
4071 return 1; /* nid is a HP-Out */
4072
4073 return 0; /* nid is not a HP-Out */
4074};
4075
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004076static void stac92xx_power_down(struct hda_codec *codec)
4077{
4078 struct sigmatel_spec *spec = codec->spec;
4079
4080 /* power down inactive DACs */
4081 hda_nid_t *dac;
4082 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004083 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004084 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004085 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4086}
4087
Takashi Iwaif73d3582008-11-25 08:21:51 +01004088static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4089 int enable);
4090
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004091/* override some hints from the hwdep entry */
4092static void stac_store_hints(struct hda_codec *codec)
4093{
4094 struct sigmatel_spec *spec = codec->spec;
4095 const char *p;
4096 int val;
4097
4098 val = snd_hda_get_bool_hint(codec, "hp_detect");
4099 if (val >= 0)
4100 spec->hp_detect = val;
4101 p = snd_hda_get_hint(codec, "gpio_mask");
4102 if (p) {
4103 spec->gpio_mask = simple_strtoul(p, NULL, 0);
4104 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4105 spec->gpio_mask;
4106 }
4107 p = snd_hda_get_hint(codec, "gpio_dir");
4108 if (p)
4109 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4110 p = snd_hda_get_hint(codec, "gpio_data");
4111 if (p)
4112 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4113 p = snd_hda_get_hint(codec, "eapd_mask");
4114 if (p)
4115 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4116 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4117 if (val >= 0)
4118 spec->eapd_switch = val;
4119}
4120
Mattc7d4b2f2005-06-27 14:59:41 +02004121static int stac92xx_init(struct hda_codec *codec)
4122{
4123 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004124 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004125 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004126 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004127
Mattc7d4b2f2005-06-27 14:59:41 +02004128 snd_hda_sequence_write(codec, spec->init);
4129
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004130 /* power down adcs initially */
4131 if (spec->powerdown_adcs)
4132 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004133 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004134 spec->adc_nids[i], 0,
4135 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004136
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004137 /* override some hints */
4138 stac_store_hints(codec);
4139
Takashi Iwaif73d3582008-11-25 08:21:51 +01004140 /* set up GPIO */
4141 gpio = spec->gpio_data;
4142 /* turn on EAPD statically when spec->eapd_switch isn't set.
4143 * otherwise, unsol event will turn it on/off dynamically
4144 */
4145 if (!spec->eapd_switch)
4146 gpio |= spec->eapd_mask;
4147 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4148
Takashi Iwai82bc9552006-03-21 11:24:42 +01004149 /* set up pins */
4150 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004151 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004152 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004153 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004154 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004155 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004156 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4157 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004158 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004159 for (i = 0; i < cfg->line_outs; i++) {
4160 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004161 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4162 }
4163 }
4164
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004165 /* force to enable the first line-out; the others are set up
4166 * in unsol_event
4167 */
4168 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004169 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004170 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004171 if (cfg->hp_pins[0])
4172 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4173 else if (cfg->line_out_pins[0])
4174 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004175 } else {
4176 stac92xx_auto_init_multi_out(codec);
4177 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004178 for (i = 0; i < cfg->hp_outs; i++)
4179 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004180 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004181 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004182 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004183 if (spec->dmux_nids)
4184 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004185 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004186 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4187 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4188 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004189 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01004190 hda_nid_t nid = cfg->input_pins[i];
4191 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004192 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004193 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4194 /* for mic pins, force to initialize */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02004195 pinctl = stac92xx_get_default_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004196 pinctl |= AC_PINCTL_IN_EN;
4197 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004198 } else {
4199 pinctl = snd_hda_codec_read(codec, nid, 0,
4200 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4201 /* if PINCTL already set then skip */
Takashi Iwai5dd17cb2009-05-07 16:22:53 +02004202 /* Also, if both INPUT and OUTPUT are set,
4203 * it must be a BIOS bug; need to override, too
4204 */
4205 if (!(pinctl & AC_PINCTL_IN_EN) ||
4206 (pinctl & AC_PINCTL_OUT_EN)) {
4207 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004208 pinctl |= AC_PINCTL_IN_EN;
4209 stac92xx_auto_set_pinctl(codec, nid,
4210 pinctl);
4211 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004212 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004213 conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004214 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004215 if (enable_pin_detect(codec, nid,
4216 STAC_INSERT_EVENT))
4217 stac_issue_unsol_event(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004218 }
Takashi Iwaic960a032006-03-23 17:06:28 +01004219 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004220 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004221 for (i = 0; i < spec->num_dmics; i++)
4222 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4223 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004224 if (cfg->dig_out_pins[0])
4225 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004226 AC_PINCTL_OUT_EN);
4227 if (cfg->dig_in_pin)
4228 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4229 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004230 for (i = 0; i < spec->num_pwrs; i++) {
4231 hda_nid_t nid = spec->pwr_nids[i];
4232 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004233
Takashi Iwaieb632122008-12-19 16:39:48 +01004234 /* power on when no jack detection is available */
4235 if (!spec->hp_detect) {
4236 stac_toggle_power_map(codec, nid, 1);
4237 continue;
4238 }
4239
4240 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004241 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004242
Takashi Iwaif73d3582008-11-25 08:21:51 +01004243 pinctl = snd_hda_codec_read(codec, nid, 0,
4244 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4245 /* outputs are only ports capable of power management
4246 * any attempts on powering down a input port cause the
4247 * referenced VREF to act quirky.
4248 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004249 if (pinctl & AC_PINCTL_IN_EN) {
4250 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004251 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004252 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004253 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004254 def_conf = get_defcfg_connect(def_conf);
4255 /* skip any ports that don't have jacks since presence
4256 * detection is useless */
4257 if (def_conf != AC_JACK_PORT_COMPLEX) {
4258 if (def_conf != AC_JACK_PORT_NONE)
4259 stac_toggle_power_map(codec, nid, 1);
4260 continue;
4261 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004262 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4263 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004264 }
4265 if (spec->dac_list)
4266 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004267 return 0;
4268}
4269
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004270static void stac92xx_free_jacks(struct hda_codec *codec)
4271{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004272#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwaib94d3532008-11-21 09:08:06 +01004273 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004274 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d3532008-11-21 09:08:06 +01004275 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004276 struct sigmatel_jack *jacks = spec->jacks.list;
4277 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +02004278 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4279 if (jacks->jack)
4280 snd_device_free(codec->bus->card, jacks->jack);
4281 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004282 }
4283 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004284#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004285}
4286
Takashi Iwai603c4012008-07-30 15:01:44 +02004287static void stac92xx_free_kctls(struct hda_codec *codec)
4288{
4289 struct sigmatel_spec *spec = codec->spec;
4290
4291 if (spec->kctls.list) {
4292 struct snd_kcontrol_new *kctl = spec->kctls.list;
4293 int i;
4294 for (i = 0; i < spec->kctls.used; i++)
4295 kfree(kctl[i].name);
4296 }
4297 snd_array_free(&spec->kctls);
4298}
4299
Matt2f2f4252005-04-13 14:45:30 +02004300static void stac92xx_free(struct hda_codec *codec)
4301{
Mattc7d4b2f2005-06-27 14:59:41 +02004302 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004303
4304 if (! spec)
4305 return;
4306
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004307 stac92xx_free_jacks(codec);
4308 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004309
Mattc7d4b2f2005-06-27 14:59:41 +02004310 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004311 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004312}
4313
Matt4e550962005-07-04 17:51:39 +02004314static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4315 unsigned int flag)
4316{
Takashi Iwai8ce841982009-01-22 16:59:20 +01004317 unsigned int old_ctl, pin_ctl;
4318
4319 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004320 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004321
Takashi Iwaif9acba42007-05-29 18:01:06 +02004322 if (pin_ctl & AC_PINCTL_IN_EN) {
4323 /*
4324 * we need to check the current set-up direction of
4325 * shared input pins since they can be switched via
4326 * "xxx as Output" mixer switch
4327 */
4328 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004329 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004330 return;
4331 }
4332
Takashi Iwai8ce841982009-01-22 16:59:20 +01004333 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004334 /* if setting pin direction bits, clear the current
4335 direction bits first */
4336 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4337 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4338
Takashi Iwai8ce841982009-01-22 16:59:20 +01004339 pin_ctl |= flag;
4340 if (old_ctl != pin_ctl)
4341 snd_hda_codec_write_cache(codec, nid, 0,
4342 AC_VERB_SET_PIN_WIDGET_CONTROL,
4343 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004344}
4345
4346static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4347 unsigned int flag)
4348{
4349 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4350 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce841982009-01-22 16:59:20 +01004351 if (pin_ctl & flag)
4352 snd_hda_codec_write_cache(codec, nid, 0,
4353 AC_VERB_SET_PIN_WIDGET_CONTROL,
4354 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004355}
4356
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004357static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004358{
4359 if (!nid)
4360 return 0;
4361 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004362 & (1 << 31))
4363 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004364 return 0;
4365}
4366
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004367static void stac92xx_line_out_detect(struct hda_codec *codec,
4368 int presence)
4369{
4370 struct sigmatel_spec *spec = codec->spec;
4371 struct auto_pin_cfg *cfg = &spec->autocfg;
4372 int i;
4373
4374 for (i = 0; i < cfg->line_outs; i++) {
4375 if (presence)
4376 break;
4377 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4378 if (presence) {
4379 unsigned int pinctl;
4380 pinctl = snd_hda_codec_read(codec,
4381 cfg->line_out_pins[i], 0,
4382 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4383 if (pinctl & AC_PINCTL_IN_EN)
4384 presence = 0; /* mic- or line-input */
4385 }
4386 }
4387
4388 if (presence) {
4389 /* disable speakers */
4390 for (i = 0; i < cfg->speaker_outs; i++)
4391 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4392 AC_PINCTL_OUT_EN);
4393 if (spec->eapd_mask && spec->eapd_switch)
4394 stac_gpio_set(codec, spec->gpio_mask,
4395 spec->gpio_dir, spec->gpio_data &
4396 ~spec->eapd_mask);
4397 } else {
4398 /* enable speakers */
4399 for (i = 0; i < cfg->speaker_outs; i++)
4400 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4401 AC_PINCTL_OUT_EN);
4402 if (spec->eapd_mask && spec->eapd_switch)
4403 stac_gpio_set(codec, spec->gpio_mask,
4404 spec->gpio_dir, spec->gpio_data |
4405 spec->eapd_mask);
4406 }
4407}
4408
Takashi Iwaid7a89432008-11-12 09:48:04 +01004409/* return non-zero if the hp-pin of the given array index isn't
4410 * a jack-detection target
4411 */
4412static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4413{
4414 struct auto_pin_cfg *cfg = &spec->autocfg;
4415
4416 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004417 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004418 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004419 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004420 return 1;
4421 /* ignore if the pin is set as line-out */
4422 if (cfg->hp_pins[i] == spec->hp_switch)
4423 return 1;
4424 return 0;
4425}
4426
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004427static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004428{
4429 struct sigmatel_spec *spec = codec->spec;
4430 struct auto_pin_cfg *cfg = &spec->autocfg;
4431 int i, presence;
4432
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004433 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004434 if (spec->gpio_mute)
4435 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4436 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4437
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004438 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004439 if (presence)
4440 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004441 if (no_hp_sensing(spec, i))
4442 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004443 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4444 if (presence) {
4445 unsigned int pinctl;
4446 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4447 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4448 if (pinctl & AC_PINCTL_IN_EN)
4449 presence = 0; /* mic- or line-input */
4450 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004451 }
Matt4e550962005-07-04 17:51:39 +02004452
4453 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004454 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004455 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004456 stac92xx_reset_pinctl(codec, spec->hp_switch,
4457 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004458 for (i = 0; i < cfg->line_outs; i++)
4459 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4460 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004461 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004462 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004463 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004464 stac92xx_set_pinctl(codec, spec->hp_switch,
4465 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004466 for (i = 0; i < cfg->line_outs; i++)
4467 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4468 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004469 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004470 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004471 /* toggle hp outs */
4472 for (i = 0; i < cfg->hp_outs; i++) {
4473 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4474 if (no_hp_sensing(spec, i))
4475 continue;
4476 if (presence)
4477 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004478#if 0 /* FIXME */
4479/* Resetting the pinctl like below may lead to (a sort of) regressions
4480 * on some devices since they use the HP pin actually for line/speaker
4481 * outs although the default pin config shows a different pin (that is
4482 * wrong and useless).
4483 *
4484 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4485 * But, disabling the code below just works around it, and I'm too tired of
4486 * bug reports with such devices...
4487 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004488 else
4489 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004490#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004491 }
Matt4e550962005-07-04 17:51:39 +02004492}
4493
Takashi Iwaif73d3582008-11-25 08:21:51 +01004494static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4495 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004496{
4497 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004498 unsigned int idx, val;
4499
4500 for (idx = 0; idx < spec->num_pwrs; idx++) {
4501 if (spec->pwr_nids[idx] == nid)
4502 break;
4503 }
4504 if (idx >= spec->num_pwrs)
4505 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004506
4507 /* several codecs have two power down bits */
4508 if (spec->pwr_mapping)
4509 idx = spec->pwr_mapping[idx];
4510 else
4511 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004512
Takashi Iwaif73d3582008-11-25 08:21:51 +01004513 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4514 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004515 val &= ~idx;
4516 else
4517 val |= idx;
4518
4519 /* power down unused output ports */
4520 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004521}
4522
Takashi Iwaif73d3582008-11-25 08:21:51 +01004523static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4524{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004525 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004526}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004527
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004528static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4529{
4530 struct sigmatel_spec *spec = codec->spec;
4531 struct sigmatel_jack *jacks = spec->jacks.list;
4532
4533 if (jacks) {
4534 int i;
4535 for (i = 0; i < spec->jacks.used; i++) {
4536 if (jacks->nid == nid) {
4537 unsigned int pin_ctl =
4538 snd_hda_codec_read(codec, nid,
4539 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4540 0x00);
4541 int type = jacks->type;
4542 if (type == (SND_JACK_LINEOUT
4543 | SND_JACK_HEADPHONE))
4544 type = (pin_ctl & AC_PINCTL_HP_EN)
4545 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4546 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004547 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004548 ? type : 0);
4549 }
4550 jacks++;
4551 }
4552 }
4553}
Matt2f2f4252005-04-13 14:45:30 +02004554
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004555static void stac92xx_mic_detect(struct hda_codec *codec)
4556{
4557 struct sigmatel_spec *spec = codec->spec;
4558 struct sigmatel_mic_route *mic;
4559
4560 if (get_pin_presence(codec, spec->ext_mic.pin))
4561 mic = &spec->ext_mic;
4562 else
4563 mic = &spec->int_mic;
4564 if (mic->dmux_idx)
4565 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4566 AC_VERB_SET_CONNECT_SEL,
4567 mic->dmux_idx);
4568 else
4569 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4570 AC_VERB_SET_CONNECT_SEL,
4571 mic->mux_idx);
4572}
4573
Takashi Iwai62558ce2009-07-29 14:23:09 +02004574static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004575{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004576 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004577 if (!event)
4578 return;
4579 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4580}
4581
Takashi Iwai314634b2006-09-21 11:56:18 +02004582static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4583{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004584 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004585 struct sigmatel_event *event;
4586 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004587
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004588 tag = (res >> 26) & 0x7f;
4589 event = stac_get_event_from_tag(codec, tag);
4590 if (!event)
4591 return;
4592
4593 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004594 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004595 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004596 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004597 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004598 case STAC_MIC_EVENT:
4599 stac92xx_mic_detect(codec);
4600 break;
4601 }
4602
4603 switch (event->type) {
4604 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004605 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004606 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004607 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004608 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004609 if (spec->num_pwrs > 0)
4610 stac92xx_pin_sense(codec, event->nid);
4611 stac92xx_report_jack(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004612
4613 switch (codec->subsystem_id) {
4614 case 0x103c308f:
4615 if (event->nid == 0xb) {
4616 int pin = AC_PINCTL_IN_EN;
4617
4618 if (get_pin_presence(codec, 0xa)
4619 && get_pin_presence(codec, 0xb))
4620 pin |= AC_PINCTL_VREF_80;
4621 if (!get_pin_presence(codec, 0xb))
4622 pin |= AC_PINCTL_VREF_80;
4623
4624 /* toggle VREF state based on mic + hp pin
4625 * status
4626 */
4627 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4628 }
4629 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004630 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004631 case STAC_VREF_EVENT:
4632 data = snd_hda_codec_read(codec, codec->afg, 0,
4633 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004634 /* toggle VREF state based on GPIOx status */
4635 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004636 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004637 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004638 }
4639}
4640
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004641#ifdef CONFIG_PROC_FS
4642static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4643 struct hda_codec *codec, hda_nid_t nid)
4644{
4645 if (nid == codec->afg)
4646 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4647 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4648}
4649
4650static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4651 struct hda_codec *codec,
4652 unsigned int verb)
4653{
4654 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4655 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4656}
4657
4658/* stac92hd71bxx, stac92hd73xx */
4659static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4660 struct hda_codec *codec, hda_nid_t nid)
4661{
4662 stac92hd_proc_hook(buffer, codec, nid);
4663 if (nid == codec->afg)
4664 analog_loop_proc_hook(buffer, codec, 0xfa0);
4665}
4666
4667static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4668 struct hda_codec *codec, hda_nid_t nid)
4669{
4670 if (nid == codec->afg)
4671 analog_loop_proc_hook(buffer, codec, 0xfe0);
4672}
4673
4674static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4675 struct hda_codec *codec, hda_nid_t nid)
4676{
4677 if (nid == codec->afg)
4678 analog_loop_proc_hook(buffer, codec, 0xfeb);
4679}
4680#else
4681#define stac92hd_proc_hook NULL
4682#define stac92hd7x_proc_hook NULL
4683#define stac9205_proc_hook NULL
4684#define stac927x_proc_hook NULL
4685#endif
4686
Takashi Iwaicb53c622007-08-10 17:21:45 +02004687#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004688static int stac92xx_resume(struct hda_codec *codec)
4689{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004690 struct sigmatel_spec *spec = codec->spec;
4691
Takashi Iwai2c885872008-11-18 09:36:55 +01004692 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004693 snd_hda_codec_resume_amp(codec);
4694 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004695 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004696 if (spec->hp_detect) {
4697 if (spec->autocfg.hp_pins[0])
4698 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4699 else if (spec->autocfg.line_out_pins[0])
4700 stac_issue_unsol_event(codec,
4701 spec->autocfg.line_out_pins[0]);
4702 }
Mattff6fdc32005-06-27 15:06:52 +02004703 return 0;
4704}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004705
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004706/*
James Gardiner514bf542009-05-03 04:00:44 -04004707 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004708 * check for mute state only on Speakers (nid = 0x10)
4709 *
4710 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4711 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004712 *
4713 * Changed name to reflect that it now works for any designated
4714 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004715 */
4716
4717#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004718static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004719 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004720{
4721 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004722
4723 if (nid == 0x10) {
4724 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004725 HDA_AMP_MUTE)
Takashi Iwai86d190e2009-05-26 15:18:58 +02004726 spec->gpio_data &= ~spec->gpio_led; /* orange */
Takashi Iwaiba84bfc2009-05-30 08:59:03 +02004727 else
4728 spec->gpio_data |= spec->gpio_led; /* white */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004729
4730 stac_gpio_set(codec, spec->gpio_mask,
4731 spec->gpio_dir,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004732 spec->gpio_data);
4733 }
4734
4735 return 0;
4736}
4737#endif
4738
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004739static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4740{
4741 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004742 int i;
4743 hda_nid_t nid;
4744
4745 /* reset each pin before powering down DAC/ADC to avoid click noise */
4746 nid = codec->start_nid;
4747 for (i = 0; i < codec->num_nodes; i++, nid++) {
4748 unsigned int wcaps = get_wcaps(codec, nid);
Takashi Iwaia22d5432009-07-27 12:54:26 +02004749 unsigned int wid_type = get_wcaps_type(wcaps);
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004750 if (wid_type == AC_WID_PIN)
4751 snd_hda_codec_read(codec, nid, 0,
4752 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4753 }
4754
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004755 if (spec->eapd_mask)
4756 stac_gpio_set(codec, spec->gpio_mask,
4757 spec->gpio_dir, spec->gpio_data &
4758 ~spec->eapd_mask);
4759 return 0;
4760}
Mattff6fdc32005-06-27 15:06:52 +02004761#endif
4762
Matt2f2f4252005-04-13 14:45:30 +02004763static struct hda_codec_ops stac92xx_patch_ops = {
4764 .build_controls = stac92xx_build_controls,
4765 .build_pcms = stac92xx_build_pcms,
4766 .init = stac92xx_init,
4767 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004768 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004769#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004770 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004771 .resume = stac92xx_resume,
4772#endif
Matt2f2f4252005-04-13 14:45:30 +02004773};
4774
4775static int patch_stac9200(struct hda_codec *codec)
4776{
4777 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004778 int err;
Matt2f2f4252005-04-13 14:45:30 +02004779
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004780 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004781 if (spec == NULL)
4782 return -ENOMEM;
4783
4784 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004785 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004786 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004787 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4788 stac9200_models,
4789 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01004790 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004791 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4792 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004793 else
4794 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004795 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02004796
4797 spec->multiout.max_channels = 2;
4798 spec->multiout.num_dacs = 1;
4799 spec->multiout.dac_nids = stac9200_dac_nids;
4800 spec->adc_nids = stac9200_adc_nids;
4801 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004802 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004803 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004804 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004805 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004806
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02004807 if (spec->board_config == STAC_9200_M4 ||
4808 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01004809 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004810 spec->init = stac9200_eapd_init;
4811 else
4812 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004813 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004814
Takashi Iwai117f2572008-03-18 09:53:23 +01004815 if (spec->board_config == STAC_9200_PANASONIC) {
4816 spec->gpio_mask = spec->gpio_dir = 0x09;
4817 spec->gpio_data = 0x00;
4818 }
4819
Mattc7d4b2f2005-06-27 14:59:41 +02004820 err = stac9200_parse_auto_config(codec);
4821 if (err < 0) {
4822 stac92xx_free(codec);
4823 return err;
4824 }
Matt2f2f4252005-04-13 14:45:30 +02004825
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01004826 /* CF-74 has no headphone detection, and the driver should *NOT*
4827 * do detection and HP/speaker toggle because the hardware does it.
4828 */
4829 if (spec->board_config == STAC_9200_PANASONIC)
4830 spec->hp_detect = 0;
4831
Matt2f2f4252005-04-13 14:45:30 +02004832 codec->patch_ops = stac92xx_patch_ops;
4833
4834 return 0;
4835}
4836
Tobin Davis8e21c342007-01-08 11:04:17 +01004837static int patch_stac925x(struct hda_codec *codec)
4838{
4839 struct sigmatel_spec *spec;
4840 int err;
4841
4842 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4843 if (spec == NULL)
4844 return -ENOMEM;
4845
4846 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004847 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004848 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004849
4850 /* Check first for codec ID */
4851 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
4852 STAC_925x_MODELS,
4853 stac925x_models,
4854 stac925x_codec_id_cfg_tbl);
4855
4856 /* Now checks for PCI ID, if codec ID is not found */
4857 if (spec->board_config < 0)
4858 spec->board_config = snd_hda_check_board_config(codec,
4859 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01004860 stac925x_models,
4861 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004862 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004863 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004864 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4865 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004866 else
4867 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004868 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01004869
4870 spec->multiout.max_channels = 2;
4871 spec->multiout.num_dacs = 1;
4872 spec->multiout.dac_nids = stac925x_dac_nids;
4873 spec->adc_nids = stac925x_adc_nids;
4874 spec->mux_nids = stac925x_mux_nids;
4875 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004876 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004877 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004878 switch (codec->vendor_id) {
4879 case 0x83847632: /* STAC9202 */
4880 case 0x83847633: /* STAC9202D */
4881 case 0x83847636: /* STAC9251 */
4882 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004883 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004884 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004885 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4886 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004887 break;
4888 default:
4889 spec->num_dmics = 0;
4890 break;
4891 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004892
4893 spec->init = stac925x_core_init;
4894 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02004895 spec->num_caps = 1;
4896 spec->capvols = stac925x_capvols;
4897 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01004898
4899 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004900 if (!err) {
4901 if (spec->board_config < 0) {
4902 printk(KERN_WARNING "hda_codec: No auto-config is "
4903 "available, default to model=ref\n");
4904 spec->board_config = STAC_925x_REF;
4905 goto again;
4906 }
4907 err = -EINVAL;
4908 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004909 if (err < 0) {
4910 stac92xx_free(codec);
4911 return err;
4912 }
4913
4914 codec->patch_ops = stac92xx_patch_ops;
4915
4916 return 0;
4917}
4918
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004919static int patch_stac92hd73xx(struct hda_codec *codec)
4920{
4921 struct sigmatel_spec *spec;
4922 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4923 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004924 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004925
4926 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4927 if (spec == NULL)
4928 return -ENOMEM;
4929
4930 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004931 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004932 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4933 spec->pin_nids = stac92hd73xx_pin_nids;
4934 spec->board_config = snd_hda_check_board_config(codec,
4935 STAC_92HD73XX_MODELS,
4936 stac92hd73xx_models,
4937 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02004938 /* check codec subsystem id if not found */
4939 if (spec->board_config < 0)
4940 spec->board_config =
4941 snd_hda_check_board_codec_sid_config(codec,
4942 STAC_92HD73XX_MODELS, stac92hd73xx_models,
4943 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004944again:
Takashi Iwai330ee992009-02-20 14:33:36 +01004945 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004946 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4947 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004948 else
4949 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004950 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004951
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004952 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004953 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4954
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004955 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004956 printk(KERN_WARNING "hda_codec: Could not determine "
4957 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004958 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004959 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02004960 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004961 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004962 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004963 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004964 break;
4965 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004966 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004967 break;
4968 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01004969 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
4970 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004971 }
4972 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004973
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004974 spec->aloopback_mask = 0x01;
4975 spec->aloopback_shift = 8;
4976
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004977 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004978 spec->mux_nids = stac92hd73xx_mux_nids;
4979 spec->adc_nids = stac92hd73xx_adc_nids;
4980 spec->dmic_nids = stac92hd73xx_dmic_nids;
4981 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004982 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004983
4984 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4985 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01004986 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004987
Takashi Iwai6479c632009-07-28 18:20:25 +02004988 spec->num_caps = STAC92HD73XX_NUM_CAPS;
4989 spec->capvols = stac92hd73xx_capvols;
4990 spec->capsws = stac92hd73xx_capsws;
4991
Matthew Ranostaya7662642008-02-21 07:51:14 +01004992 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004993 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004994 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004995 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004996 case STAC_DELL_M6_AMIC:
4997 case STAC_DELL_M6_DMIC:
4998 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004999 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005000 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005001
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005002 switch (spec->board_config) {
5003 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005004 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005005 spec->num_dmics = 0;
5006 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005007 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005008 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005009 spec->num_dmics = 1;
5010 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005011 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005012 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5013 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005014 spec->num_dmics = 1;
5015 break;
5016 }
5017 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005018 case STAC_ALIENWARE_M17X:
5019 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5020 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5021 spec->eapd_switch = 0;
5022 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005023 default:
5024 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005025 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005026 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005027 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005028 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005029 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005030 /* GPIO0 High = Enable EAPD */
5031 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5032 spec->gpio_data = 0x01;
5033 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005034
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005035 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5036 spec->pwr_nids = stac92hd73xx_pwr_nids;
5037
Matthew Ranostayd9737752008-09-07 12:03:41 +02005038 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005039
5040 if (!err) {
5041 if (spec->board_config < 0) {
5042 printk(KERN_WARNING "hda_codec: No auto-config is "
5043 "available, default to model=ref\n");
5044 spec->board_config = STAC_92HD73XX_REF;
5045 goto again;
5046 }
5047 err = -EINVAL;
5048 }
5049
5050 if (err < 0) {
5051 stac92xx_free(codec);
5052 return err;
5053 }
5054
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005055 if (spec->board_config == STAC_92HD73XX_NO_JD)
5056 spec->hp_detect = 0;
5057
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005058 codec->patch_ops = stac92xx_patch_ops;
5059
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005060 codec->proc_widget_hook = stac92hd7x_proc_hook;
5061
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005062 return 0;
5063}
5064
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005065static int patch_stac92hd83xxx(struct hda_codec *codec)
5066{
5067 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005068 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005069 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005070 int num_dacs;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005071 hda_nid_t nid;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005072
5073 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5074 if (spec == NULL)
5075 return -ENOMEM;
5076
5077 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005078 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005079 spec->mono_nid = 0x19;
5080 spec->digbeep_nid = 0x21;
Takashi Iwai667067d2009-08-13 18:14:42 +02005081 spec->mux_nids = stac92hd83xxx_mux_nids;
5082 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005083 spec->adc_nids = stac92hd83xxx_adc_nids;
Takashi Iwai7570ef12009-08-15 11:57:53 +02005084 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005085 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5086 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5087 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005088 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005089
5090 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005091 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005092 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005093 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5094 spec->capvols = stac92hd83xxx_capvols;
5095 spec->capsws = stac92hd83xxx_capsws;
5096
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005097 spec->board_config = snd_hda_check_board_config(codec,
5098 STAC_92HD83XXX_MODELS,
5099 stac92hd83xxx_models,
5100 stac92hd83xxx_cfg_tbl);
5101again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005102 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005103 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5104 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005105 else
5106 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005107 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005108
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005109 switch (codec->vendor_id) {
5110 case 0x111d7604:
5111 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005112 case 0x111d76d5:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005113 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5114 break;
5115 spec->num_pwrs = 0;
5116 break;
5117 }
5118
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005119 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5120 if (!err) {
5121 if (spec->board_config < 0) {
5122 printk(KERN_WARNING "hda_codec: No auto-config is "
5123 "available, default to model=ref\n");
5124 spec->board_config = STAC_92HD83XXX_REF;
5125 goto again;
5126 }
5127 err = -EINVAL;
5128 }
5129
5130 if (err < 0) {
5131 stac92xx_free(codec);
5132 return err;
5133 }
5134
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005135 switch (spec->board_config) {
5136 case STAC_DELL_S14:
5137 nid = 0xf;
5138 break;
5139 default:
5140 nid = 0xe;
5141 break;
5142 }
5143
5144 num_dacs = snd_hda_get_connections(codec, nid,
5145 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02005146 if (num_dacs < 0)
5147 num_dacs = STAC92HD83_DAC_COUNT;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005148
5149 /* set port X to select the last DAC
5150 */
5151 snd_hda_codec_write_cache(codec, nid, 0,
5152 AC_VERB_SET_CONNECT_SEL, num_dacs);
5153
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005154 codec->patch_ops = stac92xx_patch_ops;
5155
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005156 codec->proc_widget_hook = stac92hd_proc_hook;
5157
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005158 return 0;
5159}
5160
Takashi Iwai330ee992009-02-20 14:33:36 +01005161/* get the pin connection (fixed, none, etc) */
5162static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5163{
5164 struct sigmatel_spec *spec = codec->spec;
5165 unsigned int cfg;
5166
5167 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5168 return get_defcfg_connect(cfg);
5169}
5170
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005171static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5172 hda_nid_t *nids, int num_nids)
5173{
5174 struct sigmatel_spec *spec = codec->spec;
5175 int idx, num;
5176 unsigned int def_conf;
5177
5178 for (num = 0; num < num_nids; num++) {
5179 for (idx = 0; idx < spec->num_pins; idx++)
5180 if (spec->pin_nids[idx] == nids[num])
5181 break;
5182 if (idx >= spec->num_pins)
5183 break;
Takashi Iwai330ee992009-02-20 14:33:36 +01005184 def_conf = stac_get_defcfg_connect(codec, idx);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005185 if (def_conf == AC_JACK_PORT_NONE)
5186 break;
5187 }
5188 return num;
5189}
5190
5191static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5192 hda_nid_t dig0pin)
5193{
5194 struct sigmatel_spec *spec = codec->spec;
5195 int idx;
5196
5197 for (idx = 0; idx < spec->num_pins; idx++)
5198 if (spec->pin_nids[idx] == dig0pin)
5199 break;
5200 if ((idx + 2) >= spec->num_pins)
5201 return 0;
5202
5203 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005204 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005205 return 2;
5206
5207 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005208 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005209 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005210 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005211 return 1;
5212 else
5213 return 0;
5214}
5215
Matthew Ranostaye035b842007-11-06 11:53:55 +01005216static int patch_stac92hd71bxx(struct hda_codec *codec)
5217{
5218 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005219 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005220 int err = 0;
5221
5222 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5223 if (spec == NULL)
5224 return -ENOMEM;
5225
5226 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005227 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005228 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5229 switch (codec->vendor_id) {
5230 case 0x111d76b6:
5231 case 0x111d76b7:
5232 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5233 break;
5234 case 0x111d7603:
5235 case 0x111d7608:
5236 /* On 92HD75Bx 0x27 isn't a pin nid */
5237 spec->num_pins--;
5238 /* fallthrough */
5239 default:
5240 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5241 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005242 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005243 spec->board_config = snd_hda_check_board_config(codec,
5244 STAC_92HD71BXX_MODELS,
5245 stac92hd71bxx_models,
5246 stac92hd71bxx_cfg_tbl);
5247again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005248 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005249 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5250 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005251 else
5252 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005253 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005254
Takashi Iwaifc64b262009-09-14 15:33:01 +02005255 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005256 /* GPIO0 = EAPD */
5257 spec->gpio_mask = 0x01;
5258 spec->gpio_dir = 0x01;
5259 spec->gpio_data = 0x01;
5260 }
5261
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005262 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5263 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5264
Takashi Iwai6479c632009-07-28 18:20:25 +02005265 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5266 spec->capvols = stac92hd71bxx_capvols;
5267 spec->capsws = stac92hd71bxx_capsws;
5268
Matthew Ranostay541eee82007-12-14 12:08:04 +01005269 switch (codec->vendor_id) {
5270 case 0x111d76b6: /* 4 Port without Analog Mixer */
5271 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005272 unmute_init++;
5273 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005274 case 0x111d76b4: /* 6 Port without Analog Mixer */
5275 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005276 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005277 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005278 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5279 stac92hd71bxx_dmic_nids,
5280 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005281 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005282 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005283 switch (spec->board_config) {
5284 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005285 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005286 err = stac_add_event(spec, codec->afg,
5287 STAC_VREF_EVENT, 0x02);
5288 if (err < 0)
5289 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005290 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005291 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5292 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005293 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005294 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005295 spec->gpio_mask |= 0x02;
5296 break;
5297 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005298 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005299 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005300 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005301
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005302 /* no output amps */
5303 spec->num_pwrs = 0;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005304 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005305 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005306 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005307 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5308 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005309 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5310 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5311 stac92hd71bxx_dmic_nids,
5312 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005313 break;
5314 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005315 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005316 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005317
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005318 /* no output amps */
5319 spec->num_pwrs = 0;
5320 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005321 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005322 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005323 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005324 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5325 stac92hd71bxx_dmic_nids,
5326 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005327 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005328 }
5329
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005330 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5331 snd_hda_sequence_write_cache(codec, unmute_init);
5332
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005333 /* Some HP machines seem to have unstable codec communications
5334 * especially with ATI fglrx driver. For recovering from the
5335 * CORB/RIRB stall, allow the BUS reset and keep always sync
5336 */
5337 if (spec->board_config == STAC_HP_DV5) {
5338 codec->bus->sync_write = 1;
5339 codec->bus->allow_bus_reset = 1;
5340 }
5341
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005342 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005343 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005344 spec->aloopback_shift = 0;
5345
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005346 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005347 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005348 spec->mux_nids = stac92hd71bxx_mux_nids;
5349 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005350 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005351 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005352
5353 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5354 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005355 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005356 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005357
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005358 switch (spec->board_config) {
5359 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005360 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005361 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005362 stac92xx_auto_set_pinctl(codec, 0x0e,
5363 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005364 /* fallthru */
5365 case STAC_DELL_M4_2:
5366 spec->num_dmics = 0;
5367 spec->num_smuxes = 0;
5368 spec->num_dmuxes = 0;
5369 break;
5370 case STAC_DELL_M4_1:
5371 case STAC_DELL_M4_3:
5372 spec->num_dmics = 1;
5373 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005374 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005375 break;
James Gardiner514bf542009-05-03 04:00:44 -04005376 case STAC_HP_DV4_1222NR:
5377 spec->num_dmics = 1;
5378 /* I don't know if it needs 1 or 2 smuxes - will wait for
5379 * bug reports to fix if needed
5380 */
5381 spec->num_smuxes = 1;
5382 spec->num_dmuxes = 1;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005383 spec->gpio_led = 0x01;
James Gardiner514bf542009-05-03 04:00:44 -04005384 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005385 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005386 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005387 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005388 /* HP dv6 gives the headphone pin as a line-out. Thus we
5389 * need to set hp_detect flag here to force to enable HP
5390 * detection.
5391 */
5392 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005393 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005394 case STAC_HP_HDX:
5395 spec->num_dmics = 1;
5396 spec->num_dmuxes = 1;
5397 spec->num_smuxes = 1;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005398 /* orange/white mute led on GPIO3, orange=0, white=1 */
Takashi Iwai86d190e2009-05-26 15:18:58 +02005399 spec->gpio_led = 0x08;
5400 break;
5401 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005402
Takashi Iwai86d190e2009-05-26 15:18:58 +02005403#ifdef CONFIG_SND_HDA_POWER_SAVE
5404 if (spec->gpio_led) {
5405 spec->gpio_mask |= spec->gpio_led;
5406 spec->gpio_dir |= spec->gpio_led;
5407 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005408 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005409 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005410 stac92xx_hp_check_power_status;
5411 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005412#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005413
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005414 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005415
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005416 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005417 if (!err) {
5418 if (spec->board_config < 0) {
5419 printk(KERN_WARNING "hda_codec: No auto-config is "
5420 "available, default to model=ref\n");
5421 spec->board_config = STAC_92HD71BXX_REF;
5422 goto again;
5423 }
5424 err = -EINVAL;
5425 }
5426
5427 if (err < 0) {
5428 stac92xx_free(codec);
5429 return err;
5430 }
5431
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005432 codec->proc_widget_hook = stac92hd7x_proc_hook;
5433
Matthew Ranostaye035b842007-11-06 11:53:55 +01005434 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005435}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005436
Matt2f2f4252005-04-13 14:45:30 +02005437static int patch_stac922x(struct hda_codec *codec)
5438{
5439 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005440 int err;
Matt2f2f4252005-04-13 14:45:30 +02005441
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005442 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005443 if (spec == NULL)
5444 return -ENOMEM;
5445
5446 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005447 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005448 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005449 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5450 stac922x_models,
5451 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005452 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005453 spec->gpio_mask = spec->gpio_dir = 0x03;
5454 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005455 /* Intel Macs have all same PCI SSID, so we need to check
5456 * codec SSID to distinguish the exact models
5457 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005458 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005459 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005460
5461 case 0x106b0800:
5462 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005463 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005464 case 0x106b0600:
5465 case 0x106b0700:
5466 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005467 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005468 case 0x106b0e00:
5469 case 0x106b0f00:
5470 case 0x106b1600:
5471 case 0x106b1700:
5472 case 0x106b0200:
5473 case 0x106b1e00:
5474 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005475 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005476 case 0x106b1a00:
5477 case 0x00000100:
5478 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005479 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005480 case 0x106b0a00:
5481 case 0x106b2200:
5482 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005483 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005484 default:
5485 spec->board_config = STAC_INTEL_MAC_V3;
5486 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005487 }
5488 }
5489
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005490 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005491 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005492 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5493 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005494 else
5495 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005496 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005497
Matt2f2f4252005-04-13 14:45:30 +02005498 spec->adc_nids = stac922x_adc_nids;
5499 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005500 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005501 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005502 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005503 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005504
5505 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005506
5507 spec->num_caps = STAC922X_NUM_CAPS;
5508 spec->capvols = stac922x_capvols;
5509 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005510
5511 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005512
Matt Porter3cc08dc2006-01-23 15:27:49 +01005513 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005514 if (!err) {
5515 if (spec->board_config < 0) {
5516 printk(KERN_WARNING "hda_codec: No auto-config is "
5517 "available, default to model=ref\n");
5518 spec->board_config = STAC_D945_REF;
5519 goto again;
5520 }
5521 err = -EINVAL;
5522 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005523 if (err < 0) {
5524 stac92xx_free(codec);
5525 return err;
5526 }
5527
5528 codec->patch_ops = stac92xx_patch_ops;
5529
Takashi Iwai807a46362007-05-29 19:01:37 +02005530 /* Fix Mux capture level; max to 2 */
5531 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5532 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5533 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5534 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5535 (0 << AC_AMPCAP_MUTE_SHIFT));
5536
Matt Porter3cc08dc2006-01-23 15:27:49 +01005537 return 0;
5538}
5539
5540static int patch_stac927x(struct hda_codec *codec)
5541{
5542 struct sigmatel_spec *spec;
5543 int err;
5544
5545 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5546 if (spec == NULL)
5547 return -ENOMEM;
5548
5549 codec->spec = spec;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005550 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005551 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005552 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005553 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5554 stac927x_models,
5555 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005556 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005557 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005558 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5559 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005560 else
5561 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005562 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005563
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005564 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005565 spec->adc_nids = stac927x_adc_nids;
5566 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5567 spec->mux_nids = stac927x_mux_nids;
5568 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005569 spec->smux_nids = stac927x_smux_nids;
5570 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005571 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005572 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005573 spec->multiout.dac_nids = spec->dac_nids;
5574
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005575 if (spec->board_config != STAC_D965_REF) {
5576 /* GPIO0 High = Enable EAPD */
5577 spec->eapd_mask = spec->gpio_mask = 0x01;
5578 spec->gpio_dir = spec->gpio_data = 0x01;
5579 }
5580
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005581 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005582 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005583 case STAC_D965_5ST:
5584 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005585 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02005586 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005587 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005588 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005589 switch (codec->subsystem_id) {
5590 case 0x10280209:
5591 case 0x1028022e:
5592 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005593 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005594 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005595 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005596 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005597 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005598 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005599 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005600 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005601 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005602 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005603 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005604 if (codec->subsystem_id != 0x1028022f) {
5605 /* GPIO2 High = Enable EAPD */
5606 spec->eapd_mask = spec->gpio_mask = 0x04;
5607 spec->gpio_dir = spec->gpio_data = 0x04;
5608 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005609 spec->dmic_nids = stac927x_dmic_nids;
5610 spec->num_dmics = STAC927X_NUM_DMICS;
5611
Tobin Davis93ed1502006-09-01 21:03:12 +02005612 spec->init = d965_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005613 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005614 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005615 break;
5616 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005617 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005618 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005619 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005620 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005621
Takashi Iwai6479c632009-07-28 18:20:25 +02005622 spec->num_caps = STAC927X_NUM_CAPS;
5623 spec->capvols = stac927x_capvols;
5624 spec->capsws = stac927x_capsws;
5625
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005626 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005627 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005628 spec->aloopback_mask = 0x40;
5629 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005630 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005631
Matt Porter3cc08dc2006-01-23 15:27:49 +01005632 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005633 if (!err) {
5634 if (spec->board_config < 0) {
5635 printk(KERN_WARNING "hda_codec: No auto-config is "
5636 "available, default to model=ref\n");
5637 spec->board_config = STAC_D965_REF;
5638 goto again;
5639 }
5640 err = -EINVAL;
5641 }
Mattc7d4b2f2005-06-27 14:59:41 +02005642 if (err < 0) {
5643 stac92xx_free(codec);
5644 return err;
5645 }
Matt2f2f4252005-04-13 14:45:30 +02005646
5647 codec->patch_ops = stac92xx_patch_ops;
5648
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005649 codec->proc_widget_hook = stac927x_proc_hook;
5650
Takashi Iwai52987652008-01-16 16:09:47 +01005651 /*
5652 * !!FIXME!!
5653 * The STAC927x seem to require fairly long delays for certain
5654 * command sequences. With too short delays (even if the answer
5655 * is set to RIRB properly), it results in the silence output
5656 * on some hardwares like Dell.
5657 *
5658 * The below flag enables the longer delay (see get_response
5659 * in hda_intel.c).
5660 */
5661 codec->bus->needs_damn_long_delay = 1;
5662
Takashi Iwaie28d8322008-12-17 13:48:29 +01005663 /* no jack detecion for ref-no-jd model */
5664 if (spec->board_config == STAC_D965_REF_NO_JD)
5665 spec->hp_detect = 0;
5666
Matt2f2f4252005-04-13 14:45:30 +02005667 return 0;
5668}
5669
Matt Porterf3302a52006-07-31 12:49:34 +02005670static int patch_stac9205(struct hda_codec *codec)
5671{
5672 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005673 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005674
5675 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5676 if (spec == NULL)
5677 return -ENOMEM;
5678
5679 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005680 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005681 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005682 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5683 stac9205_models,
5684 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005685 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005686 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005687 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5688 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005689 else
5690 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005691 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02005692
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005693 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005694 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005695 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005696 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005697 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005698 spec->smux_nids = stac9205_smux_nids;
5699 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005700 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005701 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005702 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005703 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005704 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005705
5706 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005707 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02005708
Takashi Iwai6479c632009-07-28 18:20:25 +02005709 spec->num_caps = STAC9205_NUM_CAPS;
5710 spec->capvols = stac9205_capvols;
5711 spec->capsws = stac9205_capsws;
5712
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005713 spec->aloopback_mask = 0x40;
5714 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01005715 /* Turn on/off EAPD per HP plugging */
5716 if (spec->board_config != STAC_9205_EAPD)
5717 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005718 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005719
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005720 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005721 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005722 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005723 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5724 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005725
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005726 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005727 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5728 if (err < 0)
5729 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005730 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005731 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5732 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005733 AC_VERB_SET_UNSOLICITED_ENABLE,
5734 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005735
5736 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005737 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005738 spec->gpio_mask = 0x1b;
5739 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005740 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005741 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005742 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005743 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005744 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005745 case STAC_9205_REF:
5746 /* SPDIF-In enabled */
5747 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005748 default:
5749 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005750 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005751 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005752 break;
5753 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005754
Matt Porterf3302a52006-07-31 12:49:34 +02005755 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005756 if (!err) {
5757 if (spec->board_config < 0) {
5758 printk(KERN_WARNING "hda_codec: No auto-config is "
5759 "available, default to model=ref\n");
5760 spec->board_config = STAC_9205_REF;
5761 goto again;
5762 }
5763 err = -EINVAL;
5764 }
Matt Porterf3302a52006-07-31 12:49:34 +02005765 if (err < 0) {
5766 stac92xx_free(codec);
5767 return err;
5768 }
5769
5770 codec->patch_ops = stac92xx_patch_ops;
5771
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005772 codec->proc_widget_hook = stac9205_proc_hook;
5773
Matt Porterf3302a52006-07-31 12:49:34 +02005774 return 0;
5775}
5776
Matt2f2f4252005-04-13 14:45:30 +02005777/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005778 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005779 */
5780
Takashi Iwai1e137f92009-01-21 07:41:22 +01005781static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02005782 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005783 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5784 {}
5785};
5786
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005787static hda_nid_t stac9872_pin_nids[] = {
5788 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5789 0x11, 0x13, 0x14,
5790};
5791
5792static hda_nid_t stac9872_adc_nids[] = {
5793 0x8 /*,0x6*/
5794};
5795
5796static hda_nid_t stac9872_mux_nids[] = {
5797 0x15
5798};
5799
Takashi Iwai6479c632009-07-28 18:20:25 +02005800static unsigned long stac9872_capvols[] = {
5801 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
5802};
5803#define stac9872_capsws stac9872_capvols
5804
Takashi Iwai307282c2009-03-12 18:17:58 +01005805static unsigned int stac9872_vaio_pin_configs[9] = {
5806 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
5807 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
5808 0x90a7013e
5809};
5810
5811static const char *stac9872_models[STAC_9872_MODELS] = {
5812 [STAC_9872_AUTO] = "auto",
5813 [STAC_9872_VAIO] = "vaio",
5814};
5815
5816static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
5817 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
5818};
5819
5820static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02005821 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
5822 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01005823 {} /* terminator */
5824};
5825
Guillaume Munch6d859062006-08-22 17:15:47 +02005826static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005827{
5828 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01005829 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005830
Takashi Iwaidb064e52006-03-16 16:04:58 +01005831 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5832 if (spec == NULL)
5833 return -ENOMEM;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005834 codec->spec = spec;
Takashi Iwaib04add92009-07-20 08:01:36 +02005835 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5836 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005837
5838 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5839 stac9872_models,
5840 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01005841 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005842 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5843 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01005844 else
5845 stac92xx_set_config_regs(codec,
5846 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005847
Takashi Iwai1e137f92009-01-21 07:41:22 +01005848 spec->multiout.dac_nids = spec->dac_nids;
5849 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5850 spec->adc_nids = stac9872_adc_nids;
5851 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5852 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01005853 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005854 spec->num_caps = 1;
5855 spec->capvols = stac9872_capvols;
5856 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005857
Takashi Iwai1e137f92009-01-21 07:41:22 +01005858 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5859 if (err < 0) {
5860 stac92xx_free(codec);
5861 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005862 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01005863 spec->input_mux = &spec->private_imux;
5864 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005865 return 0;
5866}
5867
5868
5869/*
Matt2f2f4252005-04-13 14:45:30 +02005870 * patch entries
5871 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005872static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02005873 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5874 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5875 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5876 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5877 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5878 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5879 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005880 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5881 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5882 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5883 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5884 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5885 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005886 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5887 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5888 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5889 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5890 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5891 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5892 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5893 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5894 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5895 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005896 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5897 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5898 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5899 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5900 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5901 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005902 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5903 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005904 /* The following does not take into account .id=0x83847661 when subsys =
5905 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5906 * currently not fully supported.
5907 */
5908 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5909 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5910 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01005911 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02005912 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5913 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5914 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5915 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5916 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5917 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5918 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5919 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005920 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005921 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5922 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005923 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005924 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005925 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5926 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005927 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005928 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5929 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5930 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5931 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5932 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5933 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5934 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5935 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005936 {} /* terminator */
5937};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005938
5939MODULE_ALIAS("snd-hda-codec-id:8384*");
5940MODULE_ALIAS("snd-hda-codec-id:111d*");
5941
5942MODULE_LICENSE("GPL");
5943MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5944
5945static struct hda_codec_preset_list sigmatel_list = {
5946 .preset = snd_hda_preset_sigmatel,
5947 .owner = THIS_MODULE,
5948};
5949
5950static int __init patch_sigmatel_init(void)
5951{
5952 return snd_hda_add_codec_preset(&sigmatel_list);
5953}
5954
5955static void __exit patch_sigmatel_exit(void)
5956{
5957 snd_hda_delete_codec_preset(&sigmatel_list);
5958}
5959
5960module_init(patch_sigmatel_init)
5961module_exit(patch_sigmatel_exit)