blob: c7e5de6e394ee9dcd22279bb30751b0f4aa12a6b [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,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010081 STAC_DELL_M6_AMIC,
82 STAC_DELL_M6_DMIC,
83 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050084 STAC_DELL_EQ,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010085 STAC_92HD73XX_MODELS
86};
87
88enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010089 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020090 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050091 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050092 STAC_DELL_S14,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020093 STAC_92HD83XXX_MODELS
94};
95
96enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010097 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +010098 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010099 STAC_DELL_M4_1,
100 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500101 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400102 STAC_HP_M4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100103 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100104 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400105 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100106 STAC_92HD71BXX_MODELS
107};
108
109enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100110 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100111 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200112 STAC_M1,
113 STAC_M1_2,
114 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100115 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200116 STAC_M3,
117 STAC_M5,
118 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100119 STAC_925x_MODELS
120};
121
122enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100123 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100124 STAC_D945_REF,
125 STAC_D945GTP3,
126 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200127 STAC_INTEL_MAC_V1,
128 STAC_INTEL_MAC_V2,
129 STAC_INTEL_MAC_V3,
130 STAC_INTEL_MAC_V4,
131 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800132 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
133 * is given, one of the above models will be
134 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200135 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100136 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100137 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100138 STAC_MACBOOK_PRO_V1,
139 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200140 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200141 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300142 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200143 STAC_922X_DELL_D81,
144 STAC_922X_DELL_D82,
145 STAC_922X_DELL_M81,
146 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100147 STAC_922X_MODELS
148};
149
150enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100151 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100152 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100153 STAC_D965_REF,
154 STAC_D965_3ST,
155 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200156 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200157 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100158 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100159 STAC_927X_MODELS
160};
Matt Porter403d1942005-11-29 15:00:51 +0100161
Takashi Iwai307282c2009-03-12 18:17:58 +0100162enum {
163 STAC_9872_AUTO,
164 STAC_9872_VAIO,
165 STAC_9872_MODELS
166};
167
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400168struct sigmatel_event {
169 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100170 unsigned char type;
171 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400172 int data;
173};
174
175struct sigmatel_jack {
176 hda_nid_t nid;
177 int type;
178 struct snd_jack *jack;
179};
180
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200181struct sigmatel_mic_route {
182 hda_nid_t pin;
183 unsigned char mux_idx;
184 unsigned char dmux_idx;
185};
186
Matt2f2f4252005-04-13 14:45:30 +0200187struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100188 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200189 unsigned int num_mixers;
190
Matt Porter403d1942005-11-29 15:00:51 +0100191 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500192 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200193 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100194 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100195 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400196 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100197 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200198 unsigned int auto_mic:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200199
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100200 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200201 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100202 unsigned int gpio_mask;
203 unsigned int gpio_dir;
204 unsigned int gpio_data;
205 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200206 unsigned int gpio_led;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100207
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200208 /* stream */
209 unsigned int stream_delay;
210
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100211 /* analog loopback */
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100212 struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100213 unsigned char aloopback_mask;
214 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200215
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100216 /* power management */
217 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200218 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100219 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100220 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100221
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400222 /* jack detection */
223 struct snd_array jacks;
224
225 /* events */
226 struct snd_array events;
227
Matt2f2f4252005-04-13 14:45:30 +0200228 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100229 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400230 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100231 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200232 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100233 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100234 hda_nid_t hp_dacs[5];
235 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200236
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100237 int volume_offset;
238
Matt2f2f4252005-04-13 14:45:30 +0200239 /* capture */
240 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200241 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200242 hda_nid_t *mux_nids;
243 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200244 hda_nid_t *dmic_nids;
245 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100246 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100247 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200248 hda_nid_t *smux_nids;
249 unsigned int num_smuxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200250
251 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
252 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
253 unsigned int num_caps; /* number of capture volume/switch elements */
254
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200255 struct sigmatel_mic_route ext_mic;
256 struct sigmatel_mic_route int_mic;
257
Matthew Ranostay65973632008-09-16 10:39:37 -0400258 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200259
Mattdabbed62005-06-14 10:19:34 +0200260 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100261 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200262 hda_nid_t anabeep_nid;
263 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200264
Matt2f2f4252005-04-13 14:45:30 +0200265 /* pin widgets */
266 hda_nid_t *pin_nids;
267 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200268
269 /* codec specific stuff */
270 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100271 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200272
273 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200274 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100275 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200276 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100277 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200278 struct hda_input_mux *sinput_mux;
279 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400280 unsigned int cur_amux;
281 hda_nid_t *amp_nids;
282 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200283 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200284
Matt Porter403d1942005-11-29 15:00:51 +0100285 /* i/o switches */
286 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200287 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100288 hda_nid_t line_switch; /* shared line-in for input and output */
289 hda_nid_t mic_switch; /* shared mic-in for input and output */
290 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200291 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200292
Mattc7d4b2f2005-06-27 14:59:41 +0200293 struct hda_pcm pcm_rec[2]; /* PCM information */
294
295 /* dynamic controls and input_mux */
296 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200297 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200298 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200299 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200300 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400301 struct hda_input_mux private_amp_mux;
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
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400330#define DELL_M6_AMP 2
331static hda_nid_t stac92hd73xx_amp_nids[3] = {
332 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400333};
334
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100335#define STAC92HD73XX_NUM_DMICS 2
336static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
337 0x13, 0x14, 0
338};
339
340#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100341
342static hda_nid_t stac92hd73xx_mux_nids[4] = {
343 0x28, 0x29, 0x2a, 0x2b,
344};
345
346static hda_nid_t stac92hd73xx_dmux_nids[2] = {
347 0x20, 0x21,
348};
349
Matthew Ranostayd9737752008-09-07 12:03:41 +0200350static hda_nid_t stac92hd73xx_smux_nids[2] = {
351 0x22, 0x23,
352};
353
Takashi Iwai6479c632009-07-28 18:20:25 +0200354#define STAC92HD73XX_NUM_CAPS 2
355static unsigned long stac92hd73xx_capvols[] = {
356 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
357 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
358};
359#define stac92hd73xx_capsws stac92hd73xx_capvols
360
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200361#define STAC92HD83XXX_NUM_DMICS 2
362static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
363 0x11, 0x12, 0
364};
365
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200366#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200367
368static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
369 0x17, 0x18,
370};
371
372static hda_nid_t stac92hd83xxx_adc_nids[2] = {
373 0x15, 0x16,
374};
375
376static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
377 0xa, 0xb, 0xd, 0xe,
378};
379
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400380static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
381 0x1e, 0,
382};
383
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200384static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500385 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200386};
387
Takashi Iwai9248f262009-01-14 09:40:25 +0100388static hda_nid_t stac92hd83xxx_amp_nids[1] = {
Matthew Ranostayc15c5062009-01-13 13:30:07 -0500389 0xc,
390};
391
Takashi Iwai6479c632009-07-28 18:20:25 +0200392#define STAC92HD83XXX_NUM_CAPS 2
393static unsigned long stac92hd83xxx_capvols[] = {
394 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
395 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
396};
397#define stac92hd83xxx_capsws stac92hd83xxx_capvols
398
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100399static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
400 0x0a, 0x0d, 0x0f
401};
402
Matthew Ranostaye035b842007-11-06 11:53:55 +0100403static hda_nid_t stac92hd71bxx_adc_nids[2] = {
404 0x12, 0x13,
405};
406
407static hda_nid_t stac92hd71bxx_mux_nids[2] = {
408 0x1a, 0x1b
409};
410
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400411static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
412 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100413};
414
Matthew Ranostayd9737752008-09-07 12:03:41 +0200415static hda_nid_t stac92hd71bxx_smux_nids[2] = {
416 0x24, 0x25,
417};
418
Matthew Ranostaye035b842007-11-06 11:53:55 +0100419#define STAC92HD71BXX_NUM_DMICS 2
420static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
421 0x18, 0x19, 0
422};
423
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400424static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
425 0x22, 0
426};
427
Takashi Iwai6479c632009-07-28 18:20:25 +0200428#define STAC92HD71BXX_NUM_CAPS 2
429static unsigned long stac92hd71bxx_capvols[] = {
430 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
431 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
432};
433#define stac92hd71bxx_capsws stac92hd71bxx_capvols
434
Tobin Davis8e21c342007-01-08 11:04:17 +0100435static hda_nid_t stac925x_adc_nids[1] = {
436 0x03,
437};
438
439static hda_nid_t stac925x_mux_nids[1] = {
440 0x0f,
441};
442
443static hda_nid_t stac925x_dac_nids[1] = {
444 0x02,
445};
446
Takashi Iwaif6e98522007-10-16 14:27:04 +0200447#define STAC925X_NUM_DMICS 1
448static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
449 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200450};
451
Takashi Iwai1697055e2007-12-18 18:05:52 +0100452static hda_nid_t stac925x_dmux_nids[1] = {
453 0x14,
454};
455
Takashi Iwai6479c632009-07-28 18:20:25 +0200456static unsigned long stac925x_capvols[] = {
457 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
458};
459static unsigned long stac925x_capsws[] = {
460 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
461};
462
Matt2f2f4252005-04-13 14:45:30 +0200463static hda_nid_t stac922x_adc_nids[2] = {
464 0x06, 0x07,
465};
466
467static hda_nid_t stac922x_mux_nids[2] = {
468 0x12, 0x13,
469};
470
Takashi Iwai6479c632009-07-28 18:20:25 +0200471#define STAC922X_NUM_CAPS 2
472static unsigned long stac922x_capvols[] = {
473 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
474 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
475};
476#define stac922x_capsws stac922x_capvols
477
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500478static hda_nid_t stac927x_slave_dig_outs[2] = {
479 0x1f, 0,
480};
481
Matt Porter3cc08dc2006-01-23 15:27:49 +0100482static hda_nid_t stac927x_adc_nids[3] = {
483 0x07, 0x08, 0x09
484};
485
486static hda_nid_t stac927x_mux_nids[3] = {
487 0x15, 0x16, 0x17
488};
489
Matthew Ranostayd9737752008-09-07 12:03:41 +0200490static hda_nid_t stac927x_smux_nids[1] = {
491 0x21,
492};
493
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100494static hda_nid_t stac927x_dac_nids[6] = {
495 0x02, 0x03, 0x04, 0x05, 0x06, 0
496};
497
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100498static hda_nid_t stac927x_dmux_nids[1] = {
499 0x1b,
500};
501
Matthew Ranostay7f168592007-10-18 17:38:17 +0200502#define STAC927X_NUM_DMICS 2
503static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
504 0x13, 0x14, 0
505};
506
Takashi Iwai6479c632009-07-28 18:20:25 +0200507#define STAC927X_NUM_CAPS 3
508static unsigned long stac927x_capvols[] = {
509 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
510 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
511 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
512};
513static unsigned long stac927x_capsws[] = {
514 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
515 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
516 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
517};
518
Matthew Ranostay65973632008-09-16 10:39:37 -0400519static const char *stac927x_spdif_labels[5] = {
520 "Digital Playback", "ADAT", "Analog Mux 1",
521 "Analog Mux 2", "Analog Mux 3"
522};
523
Matt Porterf3302a52006-07-31 12:49:34 +0200524static hda_nid_t stac9205_adc_nids[2] = {
525 0x12, 0x13
526};
527
528static hda_nid_t stac9205_mux_nids[2] = {
529 0x19, 0x1a
530};
531
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100532static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100533 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100534};
535
Matthew Ranostayd9737752008-09-07 12:03:41 +0200536static hda_nid_t stac9205_smux_nids[1] = {
537 0x21,
538};
539
Takashi Iwaif6e98522007-10-16 14:27:04 +0200540#define STAC9205_NUM_DMICS 2
541static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
542 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200543};
544
Takashi Iwai6479c632009-07-28 18:20:25 +0200545#define STAC9205_NUM_CAPS 2
546static unsigned long stac9205_capvols[] = {
547 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
548 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
549};
550static unsigned long stac9205_capsws[] = {
551 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
552 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
553};
554
Mattc7d4b2f2005-06-27 14:59:41 +0200555static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200556 0x08, 0x09, 0x0d, 0x0e,
557 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200558};
559
Tobin Davis8e21c342007-01-08 11:04:17 +0100560static hda_nid_t stac925x_pin_nids[8] = {
561 0x07, 0x08, 0x0a, 0x0b,
562 0x0c, 0x0d, 0x10, 0x11,
563};
564
Matt2f2f4252005-04-13 14:45:30 +0200565static hda_nid_t stac922x_pin_nids[10] = {
566 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
567 0x0f, 0x10, 0x11, 0x15, 0x1b,
568};
569
Matthew Ranostaya7662642008-02-21 07:51:14 +0100570static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100571 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
572 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200573 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100574};
575
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500576static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200577 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500578 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200579};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500580
581#define STAC92HD71BXX_NUM_PINS 13
582static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
583 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
584 0x00, 0x14, 0x18, 0x19, 0x1e,
585 0x1f, 0x20, 0x27
586};
587static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100588 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
589 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500590 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100591};
592
Matt Porter3cc08dc2006-01-23 15:27:49 +0100593static hda_nid_t stac927x_pin_nids[14] = {
594 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
595 0x0f, 0x10, 0x11, 0x12, 0x13,
596 0x14, 0x21, 0x22, 0x23,
597};
598
Matt Porterf3302a52006-07-31 12:49:34 +0200599static hda_nid_t stac9205_pin_nids[12] = {
600 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
601 0x0f, 0x14, 0x16, 0x17, 0x18,
602 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200603};
604
Matthew Ranostay89385032008-09-11 09:49:39 -0400605#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
606
607static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
608 struct snd_ctl_elem_value *ucontrol)
609{
610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
611 struct sigmatel_spec *spec = codec->spec;
612 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
613
614 kcontrol->private_value ^= get_amp_nid(kcontrol);
615 kcontrol->private_value |= nid;
616
617 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
618}
619
620static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
621 struct snd_ctl_elem_value *ucontrol)
622{
623 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
624 struct sigmatel_spec *spec = codec->spec;
625 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
626
627 kcontrol->private_value ^= get_amp_nid(kcontrol);
628 kcontrol->private_value |= nid;
629
630 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
631}
632
Matt Porter8b657272006-10-26 17:12:59 +0200633static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
634 struct snd_ctl_elem_info *uinfo)
635{
636 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
637 struct sigmatel_spec *spec = codec->spec;
638 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
639}
640
641static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
642 struct snd_ctl_elem_value *ucontrol)
643{
644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
645 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100646 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200647
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100648 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200649 return 0;
650}
651
652static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
653 struct snd_ctl_elem_value *ucontrol)
654{
655 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
656 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100657 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200658
659 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100660 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200661}
662
Matthew Ranostayd9737752008-09-07 12:03:41 +0200663static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
664 struct snd_ctl_elem_info *uinfo)
665{
666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
667 struct sigmatel_spec *spec = codec->spec;
668 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
669}
670
671static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
672 struct snd_ctl_elem_value *ucontrol)
673{
674 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
675 struct sigmatel_spec *spec = codec->spec;
676 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
677
678 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
679 return 0;
680}
681
682static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
683 struct snd_ctl_elem_value *ucontrol)
684{
685 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
686 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400687 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200688 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400689 int err, val;
690 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200691
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400692 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200693 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400694 if (err < 0)
695 return err;
696
697 if (spec->spdif_mute) {
698 if (smux_idx == 0)
699 nid = spec->multiout.dig_out_nid;
700 else
701 nid = codec->slave_dig_outs[smux_idx - 1];
702 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100703 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400704 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100705 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400706 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100707 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
708 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400709 }
710 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200711}
712
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200713static unsigned int stac92xx_vref_set(struct hda_codec *codec,
714 hda_nid_t nid, unsigned int new_vref)
715{
Takashi Iwaib8621512009-06-22 08:00:10 +0200716 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200717 unsigned int pincfg;
718 pincfg = snd_hda_codec_read(codec, nid, 0,
719 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
720
721 pincfg &= 0xff;
722 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
723 pincfg |= new_vref;
724
725 if (new_vref == AC_PINCTL_VREF_HIZ)
726 pincfg |= AC_PINCTL_OUT_EN;
727 else
728 pincfg |= AC_PINCTL_IN_EN;
729
730 error = snd_hda_codec_write_cache(codec, nid, 0,
731 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
732 if (error < 0)
733 return error;
734 else
735 return 1;
736}
737
738static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
739{
740 unsigned int vref;
741 vref = snd_hda_codec_read(codec, nid, 0,
742 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
743 vref &= AC_PINCTL_VREFEN;
744 return vref;
745}
746
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100747static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200748{
749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
750 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200751 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200752}
753
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100754static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200755{
756 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
757 struct sigmatel_spec *spec = codec->spec;
758 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
759
760 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
761 return 0;
762}
763
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100764static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200765{
766 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
767 struct sigmatel_spec *spec = codec->spec;
768 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
769
Mattc7d4b2f2005-06-27 14:59:41 +0200770 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200771 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
772}
773
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100774static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
775 struct snd_ctl_elem_info *uinfo)
776{
777 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
778 struct sigmatel_spec *spec = codec->spec;
779 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
780}
781
782static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
783 struct snd_ctl_elem_value *ucontrol)
784{
785 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
786 struct sigmatel_spec *spec = codec->spec;
787
788 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
789 return 0;
790}
791
792static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
793 struct snd_ctl_elem_value *ucontrol)
794{
795 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
796 struct sigmatel_spec *spec = codec->spec;
797
798 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
799 spec->mono_nid, &spec->cur_mmux);
800}
801
Matthew Ranostay89385032008-09-11 09:49:39 -0400802static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
803 struct snd_ctl_elem_info *uinfo)
804{
805 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
806 struct sigmatel_spec *spec = codec->spec;
807 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
808}
809
810static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
811 struct snd_ctl_elem_value *ucontrol)
812{
813 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
814 struct sigmatel_spec *spec = codec->spec;
815
816 ucontrol->value.enumerated.item[0] = spec->cur_amux;
817 return 0;
818}
819
820static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
821 struct snd_ctl_elem_value *ucontrol)
822{
823 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
824 struct sigmatel_spec *spec = codec->spec;
825 struct snd_kcontrol *ctl =
826 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
827 if (!ctl)
828 return -EINVAL;
829
830 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
831 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
832
833 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
834 0, &spec->cur_amux);
835}
836
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200837#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
838
839static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
840 struct snd_ctl_elem_value *ucontrol)
841{
842 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100843 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200844 struct sigmatel_spec *spec = codec->spec;
845
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100846 ucontrol->value.integer.value[0] = !!(spec->aloopback &
847 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200848 return 0;
849}
850
851static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
852 struct snd_ctl_elem_value *ucontrol)
853{
854 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
855 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100856 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200857 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100858 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200859
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100860 idx_val = spec->aloopback_mask << idx;
861 if (ucontrol->value.integer.value[0])
862 val = spec->aloopback | idx_val;
863 else
864 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100865 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200866 return 0;
867
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100868 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200869
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100870 /* Only return the bits defined by the shift value of the
871 * first two bytes of the mask
872 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200873 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100874 kcontrol->private_value & 0xFFFF, 0x0);
875 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200876
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100877 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200878 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100879 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200880 } else {
881 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100882 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200883 }
884
885 snd_hda_codec_write_cache(codec, codec->afg, 0,
886 kcontrol->private_value >> 16, dac_mode);
887
888 return 1;
889}
890
Mattc7d4b2f2005-06-27 14:59:41 +0200891static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200892 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200893 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200894 {}
895};
896
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200897static struct hda_verb stac9200_eapd_init[] = {
898 /* set dac0mux for dac converter */
899 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
900 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
901 {}
902};
903
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100904static struct hda_verb stac92hd73xx_6ch_core_init[] = {
905 /* set master volume and direct control */
906 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100907 /* setup adcs to point to mixer */
908 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
909 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100910 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
911 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
912 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
913 /* setup import muxs */
914 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
915 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
916 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
917 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
918 {}
919};
920
Matthew Ranostayd654a662008-03-14 08:46:51 +0100921static struct hda_verb dell_eq_core_init[] = {
922 /* set master volume to max value without distortion
923 * and direct control */
924 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100925 /* setup adcs to point to mixer */
926 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
927 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
928 /* setup import muxs */
929 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
930 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
931 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
932 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
933 {}
934};
935
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100936static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500937 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100938 /* setup adcs to point to mixer */
939 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
940 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
941 /* setup import muxs */
942 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
943 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
944 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
945 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
946 {}
947};
948
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100949static struct hda_verb stac92hd73xx_8ch_core_init[] = {
950 /* set master volume and direct control */
951 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100952 /* setup adcs to point to mixer */
953 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
954 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100955 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
956 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
957 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
958 /* setup import muxs */
959 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
960 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
961 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
962 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
963 {}
964};
965
966static struct hda_verb stac92hd73xx_10ch_core_init[] = {
967 /* set master volume and direct control */
968 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100969 /* dac3 is connected to import3 mux */
970 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100971 /* setup adcs to point to mixer */
972 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
973 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100974 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
975 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
976 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
977 /* setup import muxs */
978 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
979 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
980 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
981 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
982 {}
983};
984
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200985static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500986 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
987 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
988 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200989
990 /* power state controls amps */
991 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200992 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200993};
994
Matthew Ranostaye035b842007-11-06 11:53:55 +0100995static struct hda_verb stac92hd71bxx_core_init[] = {
996 /* set master volume and direct control */
997 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200998 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100999};
1000
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05001001static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
1002 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
1003 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +01001004 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1005 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +01001006 {}
1007};
1008
Tobin Davis8e21c342007-01-08 11:04:17 +01001009static struct hda_verb stac925x_core_init[] = {
1010 /* set dac0mux for dac converter */
1011 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +01001012 /* mute the master volume */
1013 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +01001014 {}
1015};
1016
Mattc7d4b2f2005-06-27 14:59:41 +02001017static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +02001018 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +02001019 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +02001020 {}
1021};
1022
Tobin Davis93ed1502006-09-01 21:03:12 +02001023static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02001024 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +02001025 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +02001026 /* unmute node 0x1b */
1027 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1028 /* select node 0x03 as DAC */
1029 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
1030 {}
1031};
1032
Matt Porter3cc08dc2006-01-23 15:27:49 +01001033static struct hda_verb stac927x_core_init[] = {
1034 /* set master volume and direct control */
1035 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001036 /* enable analog pc beep path */
1037 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +01001038 {}
1039};
1040
Matt Porterf3302a52006-07-31 12:49:34 +02001041static struct hda_verb stac9205_core_init[] = {
1042 /* set master volume and direct control */
1043 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001044 /* enable analog pc beep path */
1045 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +02001046 {}
1047};
1048
Matthew Ranostayb22b4822008-01-22 12:32:30 +01001049#define STAC_MONO_MUX \
1050 { \
1051 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1052 .name = "Mono Mux", \
1053 .count = 1, \
1054 .info = stac92xx_mono_mux_enum_info, \
1055 .get = stac92xx_mono_mux_enum_get, \
1056 .put = stac92xx_mono_mux_enum_put, \
1057 }
1058
Matthew Ranostay89385032008-09-11 09:49:39 -04001059#define STAC_AMP_MUX \
1060 { \
1061 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1062 .name = "Amp Selector Capture Switch", \
1063 .count = 1, \
1064 .info = stac92xx_amp_mux_enum_info, \
1065 .get = stac92xx_amp_mux_enum_get, \
1066 .put = stac92xx_amp_mux_enum_put, \
1067 }
1068
1069#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
1070 { \
1071 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1072 .name = xname, \
1073 .index = 0, \
1074 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1075 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1076 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
1077 .info = stac92xx_amp_volume_info, \
1078 .get = stac92xx_amp_volume_get, \
1079 .put = stac92xx_amp_volume_put, \
1080 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
1081 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
1082 }
1083
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001084#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +02001085 { \
1086 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1087 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001088 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +02001089 .info = stac92xx_aloopback_info, \
1090 .get = stac92xx_aloopback_get, \
1091 .put = stac92xx_aloopback_put, \
1092 .private_value = verb_read | (verb_write << 16), \
1093 }
1094
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02001095#define DC_BIAS(xname, idx, nid) \
1096 { \
1097 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1098 .name = xname, \
1099 .index = idx, \
1100 .info = stac92xx_dc_bias_info, \
1101 .get = stac92xx_dc_bias_get, \
1102 .put = stac92xx_dc_bias_put, \
1103 .private_value = nid, \
1104 }
1105
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001106static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +02001107 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1108 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001109 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1110 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001111 { } /* end */
1112};
1113
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001114#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001115static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001116 /* start of config #1 */
1117 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1118 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1119
1120 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1121 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1122
1123 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1124 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1125
1126 /* start of config #2 */
1127 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1128 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1129
1130 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1131 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1132
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001133 { } /* end */
1134};
1135
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001136static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1137 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1138 {}
1139};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001140
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001141static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1142 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1143 {}
1144};
1145
1146static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1147 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1148 {}
1149};
1150
1151static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001152 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1153 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1154
1155 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1156 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1157
1158 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1159 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1160
1161 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1162 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1163
1164 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1165 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1166 { } /* end */
1167};
1168
1169static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001170 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1171 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1172
1173 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1174 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1175
1176 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1177 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1178
1179 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1180 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1181
1182 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1183 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1184 { } /* end */
1185};
1186
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001187
1188static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001189 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1190 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001191
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001192 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1193 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001194
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001195 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1196 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001197
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001198 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1199 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001200
1201 /*
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001202 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1203 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001204 */
1205 { } /* end */
1206};
1207
Matthew Ranostay541eee82007-12-14 12:08:04 +01001208static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostay687cb982008-10-11 13:52:43 -04001209 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1210 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001211
Matthew Ranostay687cb982008-10-11 13:52:43 -04001212 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1213 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001214
1215 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1216 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1217
1218 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1219 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001220 { } /* end */
1221};
1222
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001223static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1224 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1225};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001226
Tobin Davis8e21c342007-01-08 11:04:17 +01001227static struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwaic9280d62009-01-15 17:31:00 +01001228 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1229 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001230 { } /* end */
1231};
1232
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001233static struct snd_kcontrol_new stac9205_loopback[] = {
1234 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1235 {}
1236};
1237
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001238static struct snd_kcontrol_new stac927x_loopback[] = {
1239 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1240 {}
1241};
1242
Takashi Iwai1697055e2007-12-18 18:05:52 +01001243static struct snd_kcontrol_new stac_dmux_mixer = {
1244 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1245 .name = "Digital Input Source",
1246 /* count set later */
1247 .info = stac92xx_dmux_enum_info,
1248 .get = stac92xx_dmux_enum_get,
1249 .put = stac92xx_dmux_enum_put,
1250};
1251
Matthew Ranostayd9737752008-09-07 12:03:41 +02001252static struct snd_kcontrol_new stac_smux_mixer = {
1253 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001254 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001255 /* count set later */
1256 .info = stac92xx_smux_enum_info,
1257 .get = stac92xx_smux_enum_get,
1258 .put = stac92xx_smux_enum_put,
1259};
1260
Takashi Iwai2134ea42008-01-10 16:53:55 +01001261static const char *slave_vols[] = {
1262 "Front Playback Volume",
1263 "Surround Playback Volume",
1264 "Center Playback Volume",
1265 "LFE Playback Volume",
1266 "Side Playback Volume",
1267 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001268 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001269 NULL
1270};
1271
1272static const char *slave_sws[] = {
1273 "Front Playback Switch",
1274 "Surround Playback Switch",
1275 "Center Playback Switch",
1276 "LFE Playback Switch",
1277 "Side Playback Switch",
1278 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001279 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001280 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001281 NULL
1282};
1283
Takashi Iwai603c4012008-07-30 15:01:44 +02001284static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001285static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001286
Matt2f2f4252005-04-13 14:45:30 +02001287static int stac92xx_build_controls(struct hda_codec *codec)
1288{
1289 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001290 struct auto_pin_cfg *cfg = &spec->autocfg;
1291 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001292 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001293 int i;
Matt2f2f4252005-04-13 14:45:30 +02001294
Takashi Iwai6479c632009-07-28 18:20:25 +02001295 if (spec->mixer) {
1296 err = snd_hda_add_new_ctls(codec, spec->mixer);
1297 if (err < 0)
1298 return err;
1299 }
Mattc7d4b2f2005-06-27 14:59:41 +02001300
1301 for (i = 0; i < spec->num_mixers; i++) {
1302 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1303 if (err < 0)
1304 return err;
1305 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02001306 if (!spec->auto_mic && spec->num_dmuxes > 0) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001307 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001308 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001309 snd_ctl_new1(&stac_dmux_mixer, codec));
1310 if (err < 0)
1311 return err;
1312 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001313 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001314 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1315 struct hda_input_mux *smux = &spec->private_smux;
1316 /* check for mute support on SPDIF out */
1317 if (wcaps & AC_WCAP_OUT_AMP) {
1318 smux->items[smux->num_items].label = "Off";
1319 smux->items[smux->num_items].index = 0;
1320 smux->num_items++;
1321 spec->spdif_mute = 1;
1322 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001323 stac_smux_mixer.count = spec->num_smuxes;
Takashi Iwai4f2d23e2008-12-19 10:14:13 +01001324 err = snd_hda_ctl_add(codec,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001325 snd_ctl_new1(&stac_smux_mixer, codec));
1326 if (err < 0)
1327 return err;
1328 }
Mattc7d4b2f2005-06-27 14:59:41 +02001329
Mattdabbed62005-06-14 10:19:34 +02001330 if (spec->multiout.dig_out_nid) {
1331 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1332 if (err < 0)
1333 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001334 err = snd_hda_create_spdif_share_sw(codec,
1335 &spec->multiout);
1336 if (err < 0)
1337 return err;
1338 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001339 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001340 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001341 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1342 if (err < 0)
1343 return err;
1344 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001345
1346 /* if we have no master control, let's create it */
1347 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001348 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001349 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001350 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001351 /* correct volume offset */
1352 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001353 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001354 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001355 if (err < 0)
1356 return err;
1357 }
1358 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1359 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1360 NULL, slave_sws);
1361 if (err < 0)
1362 return err;
1363 }
1364
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001365 if (spec->aloopback_ctl &&
1366 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1367 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1368 if (err < 0)
1369 return err;
1370 }
1371
Takashi Iwai603c4012008-07-30 15:01:44 +02001372 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001373
1374 /* create jack input elements */
1375 if (spec->hp_detect) {
1376 for (i = 0; i < cfg->hp_outs; i++) {
1377 int type = SND_JACK_HEADPHONE;
1378 nid = cfg->hp_pins[i];
1379 /* jack detection */
1380 if (cfg->hp_outs == i)
1381 type |= SND_JACK_LINEOUT;
1382 err = stac92xx_add_jack(codec, nid, type);
1383 if (err < 0)
1384 return err;
1385 }
1386 }
1387 for (i = 0; i < cfg->line_outs; i++) {
1388 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1389 SND_JACK_LINEOUT);
1390 if (err < 0)
1391 return err;
1392 }
1393 for (i = 0; i < AUTO_PIN_LAST; i++) {
1394 nid = cfg->input_pins[i];
1395 if (nid) {
1396 err = stac92xx_add_jack(codec, nid,
1397 SND_JACK_MICROPHONE);
1398 if (err < 0)
1399 return err;
1400 }
1401 }
1402
Mattdabbed62005-06-14 10:19:34 +02001403 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001404}
1405
Matt Porter403d1942005-11-29 15:00:51 +01001406static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001407 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001408 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1409};
1410
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001411static unsigned int gateway9200_m4_pin_configs[8] = {
1412 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1413 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1414};
1415static unsigned int gateway9200_m4_2_pin_configs[8] = {
1416 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1417 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1418};
1419
1420/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001421 STAC 9200 pin configs for
1422 102801A8
1423 102801DE
1424 102801E8
1425*/
1426static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001427 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1428 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001429};
1430
1431/*
1432 STAC 9200 pin configs for
1433 102801C0
1434 102801C1
1435*/
1436static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001437 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1438 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001439};
1440
1441/*
1442 STAC 9200 pin configs for
1443 102801C4 (Dell Dimension E310)
1444 102801C5
1445 102801C7
1446 102801D9
1447 102801DA
1448 102801E3
1449*/
1450static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001451 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1452 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001453};
1454
1455
1456/*
1457 STAC 9200-32 pin configs for
1458 102801B5 (Dell Inspiron 630m)
1459 102801D8 (Dell Inspiron 640m)
1460*/
1461static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001462 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1463 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001464};
1465
1466/*
1467 STAC 9200-32 pin configs for
1468 102801C2 (Dell Latitude D620)
1469 102801C8
1470 102801CC (Dell Latitude D820)
1471 102801D4
1472 102801D6
1473*/
1474static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001475 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1476 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001477};
1478
1479/*
1480 STAC 9200-32 pin configs for
1481 102801CE (Dell XPS M1710)
1482 102801CF (Dell Precision M90)
1483*/
1484static unsigned int dell9200_m23_pin_configs[8] = {
1485 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1486 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1487};
1488
1489/*
1490 STAC 9200-32 pin configs for
1491 102801C9
1492 102801CA
1493 102801CB (Dell Latitude 120L)
1494 102801D3
1495*/
1496static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001497 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1498 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001499};
1500
1501/*
1502 STAC 9200-32 pin configs for
1503 102801BD (Dell Inspiron E1505n)
1504 102801EE
1505 102801EF
1506*/
1507static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001508 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1509 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001510};
1511
1512/*
1513 STAC 9200-32 pin configs for
1514 102801F5 (Dell Inspiron 1501)
1515 102801F6
1516*/
1517static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001518 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1519 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001520};
1521
1522/*
1523 STAC 9200-32
1524 102801CD (Dell Inspiron E1705/9400)
1525*/
1526static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001527 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1528 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001529};
1530
Tobin Davisbf277782008-02-03 20:31:47 +01001531static unsigned int oqo9200_pin_configs[8] = {
1532 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1533 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1534};
1535
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001536
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001537static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1538 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001539 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001540 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1541 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1542 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1543 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1544 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1545 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1546 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1547 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1548 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1549 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001550 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1551 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001552 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001553};
1554
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001555static const char *stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001556 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001557 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001558 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001559 [STAC_9200_DELL_D21] = "dell-d21",
1560 [STAC_9200_DELL_D22] = "dell-d22",
1561 [STAC_9200_DELL_D23] = "dell-d23",
1562 [STAC_9200_DELL_M21] = "dell-m21",
1563 [STAC_9200_DELL_M22] = "dell-m22",
1564 [STAC_9200_DELL_M23] = "dell-m23",
1565 [STAC_9200_DELL_M24] = "dell-m24",
1566 [STAC_9200_DELL_M25] = "dell-m25",
1567 [STAC_9200_DELL_M26] = "dell-m26",
1568 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001569 [STAC_9200_M4] = "gateway-m4",
1570 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001571 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001572};
1573
1574static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1575 /* SigmaTel reference board */
1576 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1577 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001578 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1579 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001580 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001581 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1582 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001583 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001584 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1585 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1586 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1587 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1588 "unknown Dell", STAC_9200_DELL_D22),
1589 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1590 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001591 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001592 "Dell Latitude D620", STAC_9200_DELL_M22),
1593 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1594 "unknown Dell", STAC_9200_DELL_D23),
1595 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1596 "unknown Dell", STAC_9200_DELL_D23),
1597 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1598 "unknown Dell", STAC_9200_DELL_M22),
1599 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1600 "unknown Dell", STAC_9200_DELL_M24),
1601 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1602 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001603 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001604 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001605 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001606 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001607 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001608 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001609 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001610 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001611 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001612 "Dell Precision M90", STAC_9200_DELL_M23),
1613 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1614 "unknown Dell", STAC_9200_DELL_M22),
1615 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1616 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001617 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001618 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001619 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001620 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1621 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1622 "unknown Dell", STAC_9200_DELL_D23),
1623 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1624 "unknown Dell", STAC_9200_DELL_D23),
1625 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1626 "unknown Dell", STAC_9200_DELL_D21),
1627 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1628 "unknown Dell", STAC_9200_DELL_D23),
1629 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1630 "unknown Dell", STAC_9200_DELL_D21),
1631 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1632 "unknown Dell", STAC_9200_DELL_M25),
1633 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1634 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001635 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001636 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1637 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1638 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001639 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001640 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001641 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001642 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1643 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1644 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001645 /* OQO Mobile */
1646 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001647 {} /* terminator */
1648};
1649
Tobin Davis8e21c342007-01-08 11:04:17 +01001650static unsigned int ref925x_pin_configs[8] = {
1651 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001652 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001653};
1654
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001655static unsigned int stac925xM1_pin_configs[8] = {
1656 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1657 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001658};
1659
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001660static unsigned int stac925xM1_2_pin_configs[8] = {
1661 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1662 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1663};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001664
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001665static unsigned int stac925xM2_pin_configs[8] = {
1666 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1667 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001668};
1669
Tobin Davis8e21c342007-01-08 11:04:17 +01001670static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001671 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1672 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1673};
1674
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001675static unsigned int stac925xM3_pin_configs[8] = {
1676 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1677 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1678};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001679
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001680static unsigned int stac925xM5_pin_configs[8] = {
1681 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1682 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1683};
1684
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001685static unsigned int stac925xM6_pin_configs[8] = {
1686 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1687 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001688};
1689
1690static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1691 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001692 [STAC_M1] = stac925xM1_pin_configs,
1693 [STAC_M1_2] = stac925xM1_2_pin_configs,
1694 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001695 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001696 [STAC_M3] = stac925xM3_pin_configs,
1697 [STAC_M5] = stac925xM5_pin_configs,
1698 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001699};
1700
1701static const char *stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001702 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001703 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001704 [STAC_M1] = "m1",
1705 [STAC_M1_2] = "m1-2",
1706 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001707 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001708 [STAC_M3] = "m3",
1709 [STAC_M5] = "m5",
1710 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001711};
1712
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001713static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001714 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1715 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1716 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1717 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001718 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001719 /* Not sure about the brand name for those */
1720 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1721 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1722 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1723 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001724 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001725};
1726
1727static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1728 /* SigmaTel reference board */
1729 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001730 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001731 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001732
1733 /* Default table for unknown ID */
1734 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1735
Tobin Davis8e21c342007-01-08 11:04:17 +01001736 {} /* terminator */
1737};
1738
Matthew Ranostaya7662642008-02-21 07:51:14 +01001739static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001740 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1741 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1742 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001743 0x01452050,
1744};
1745
1746static unsigned int dell_m6_pin_configs[13] = {
1747 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001748 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001749 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1750 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001751};
1752
1753static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001754 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001755 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1756 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1757 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001758 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001759};
1760
1761static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001762 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001763 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001764 [STAC_92HD73XX_REF] = "ref",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001765 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1766 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1767 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001768 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001769};
1770
1771static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1772 /* SigmaTel reference board */
1773 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001774 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001775 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1776 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001777 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001778 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001779 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001780 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001781 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001782 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001783 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001784 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001785 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001786 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001787 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001788 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001789 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001790 "unknown Dell", STAC_DELL_M6_DMIC),
1791 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1792 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001793 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001794 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001795 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1796 "Dell Studio 17", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001797 {} /* terminator */
1798};
1799
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001800static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001801 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1802 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001803 0x01451160, 0x98560170,
1804};
1805
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001806static unsigned int dell_s14_pin_configs[10] = {
1807 0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1808 0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1809 0x40f000f0, 0x40f000f0,
1810};
1811
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001812static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1813 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001814 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001815 [STAC_DELL_S14] = dell_s14_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001816};
1817
1818static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001819 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001820 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001821 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001822 [STAC_DELL_S14] = "dell-s14",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001823};
1824
1825static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1826 /* SigmaTel reference board */
1827 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001828 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001829 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1830 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001831 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1832 "unknown Dell", STAC_DELL_S14),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001833 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001834};
1835
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001836static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001837 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001838 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001839 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1840 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001841};
1842
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001843static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001844 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001845 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001846 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1847 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001848};
1849
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001850static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001851 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1852 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001853 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1854 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001855};
1856
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001857static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001858 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1859 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001860 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1861 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001862};
1863
Matthew Ranostaye035b842007-11-06 11:53:55 +01001864static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1865 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001866 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1867 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001868 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001869 [STAC_HP_M4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001870 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001871 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001872 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001873};
1874
1875static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001876 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001877 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001878 [STAC_DELL_M4_1] = "dell-m4-1",
1879 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001880 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001881 [STAC_HP_M4] = "hp-m4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001882 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001883 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001884 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001885};
1886
1887static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1888 /* SigmaTel reference board */
1889 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1890 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001891 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1892 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001893 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1894 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Takashi Iwai58d83952009-03-13 17:04:34 +01001895 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1896 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001897 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1898 "HP dv4-7", STAC_HP_DV5),
1899 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1900 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001901 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1902 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001903 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001904 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001905 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001906 "HP HDX", STAC_HP_HDX), /* HDX16 */
Matthew Ranostaya7662642008-02-21 07:51:14 +01001907 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1908 "unknown Dell", STAC_DELL_M4_1),
1909 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1910 "unknown Dell", STAC_DELL_M4_1),
1911 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1912 "unknown Dell", STAC_DELL_M4_1),
1913 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1914 "unknown Dell", STAC_DELL_M4_1),
1915 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1916 "unknown Dell", STAC_DELL_M4_1),
1917 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1918 "unknown Dell", STAC_DELL_M4_1),
1919 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1920 "unknown Dell", STAC_DELL_M4_1),
1921 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1922 "unknown Dell", STAC_DELL_M4_2),
1923 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1924 "unknown Dell", STAC_DELL_M4_2),
1925 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1926 "unknown Dell", STAC_DELL_M4_2),
1927 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1928 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001929 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1930 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001931 {} /* terminator */
1932};
1933
Matt Porter403d1942005-11-29 15:00:51 +01001934static unsigned int ref922x_pin_configs[10] = {
1935 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1936 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001937 0x40000100, 0x40000100,
1938};
1939
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001940/*
1941 STAC 922X pin configs for
1942 102801A7
1943 102801AB
1944 102801A9
1945 102801D1
1946 102801D2
1947*/
1948static unsigned int dell_922x_d81_pin_configs[10] = {
1949 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1950 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1951 0x01813122, 0x400001f2,
1952};
1953
1954/*
1955 STAC 922X pin configs for
1956 102801AC
1957 102801D0
1958*/
1959static unsigned int dell_922x_d82_pin_configs[10] = {
1960 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1961 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1962 0x01813122, 0x400001f1,
1963};
1964
1965/*
1966 STAC 922X pin configs for
1967 102801BF
1968*/
1969static unsigned int dell_922x_m81_pin_configs[10] = {
1970 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1971 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1972 0x40C003f1, 0x405003f0,
1973};
1974
1975/*
1976 STAC 9221 A1 pin configs for
1977 102801D7 (Dell XPS M1210)
1978*/
1979static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001980 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1981 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001982 0x508003f3, 0x405003f4,
1983};
1984
Matt Porter403d1942005-11-29 15:00:51 +01001985static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001986 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001987 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1988 0x02a19120, 0x40000100,
1989};
1990
1991static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001992 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1993 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001994 0x02a19320, 0x40000100,
1995};
1996
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001997static unsigned int intel_mac_v1_pin_configs[10] = {
1998 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1999 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002000 0x400000fc, 0x400000fb,
2001};
2002
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002003static unsigned int intel_mac_v2_pin_configs[10] = {
2004 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2005 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02002006 0x400000fc, 0x400000fb,
2007};
2008
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002009static unsigned int intel_mac_v3_pin_configs[10] = {
2010 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2011 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
2012 0x400000fc, 0x400000fb,
2013};
2014
2015static unsigned int intel_mac_v4_pin_configs[10] = {
2016 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2017 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2018 0x400000fc, 0x400000fb,
2019};
2020
2021static unsigned int intel_mac_v5_pin_configs[10] = {
2022 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2023 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2024 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002025};
2026
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002027static unsigned int ecs202_pin_configs[10] = {
2028 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
2029 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
2030 0x9037012e, 0x40e000f2,
2031};
Takashi Iwai76c08822007-06-19 12:17:42 +02002032
Takashi Iwai19039bd2006-06-28 15:52:16 +02002033static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002034 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002035 [STAC_D945GTP3] = d945gtp3_pin_configs,
2036 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002037 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
2038 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
2039 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
2040 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
2041 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002042 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002043 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002044 [STAC_MACMINI] = intel_mac_v3_pin_configs,
2045 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2046 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2047 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2048 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2049 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002050 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002051 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2052 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2053 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2054 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01002055};
2056
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002057static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002058 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002059 [STAC_D945_REF] = "ref",
2060 [STAC_D945GTP5] = "5stack",
2061 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002062 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2063 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2064 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2065 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2066 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08002067 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002068 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002069 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002070 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002071 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2072 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02002073 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002074 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002075 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002076 [STAC_922X_DELL_D81] = "dell-d81",
2077 [STAC_922X_DELL_D82] = "dell-d82",
2078 [STAC_922X_DELL_M81] = "dell-m81",
2079 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002080};
2081
2082static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2083 /* SigmaTel reference board */
2084 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2085 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002086 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2087 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002088 /* Intel 945G based systems */
2089 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2090 "Intel D945G", STAC_D945GTP3),
2091 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2092 "Intel D945G", STAC_D945GTP3),
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2094 "Intel D945G", STAC_D945GTP3),
2095 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2096 "Intel D945G", STAC_D945GTP3),
2097 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2098 "Intel D945G", STAC_D945GTP3),
2099 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2100 "Intel D945G", STAC_D945GTP3),
2101 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2102 "Intel D945G", STAC_D945GTP3),
2103 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2104 "Intel D945G", STAC_D945GTP3),
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2106 "Intel D945G", STAC_D945GTP3),
2107 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2108 "Intel D945G", STAC_D945GTP3),
2109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2110 "Intel D945G", STAC_D945GTP3),
2111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2112 "Intel D945G", STAC_D945GTP3),
2113 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2114 "Intel D945G", STAC_D945GTP3),
2115 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2116 "Intel D945G", STAC_D945GTP3),
2117 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2118 "Intel D945G", STAC_D945GTP3),
2119 /* Intel D945G 5-stack systems */
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2121 "Intel D945G", STAC_D945GTP5),
2122 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2123 "Intel D945G", STAC_D945GTP5),
2124 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2125 "Intel D945G", STAC_D945GTP5),
2126 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2127 "Intel D945G", STAC_D945GTP5),
2128 /* Intel 945P based systems */
2129 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2130 "Intel D945P", STAC_D945GTP3),
2131 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2132 "Intel D945P", STAC_D945GTP3),
2133 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2134 "Intel D945P", STAC_D945GTP3),
2135 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2136 "Intel D945P", STAC_D945GTP3),
2137 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2138 "Intel D945P", STAC_D945GTP3),
2139 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2140 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002141 /* other intel */
2142 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2143 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002144 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002145 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002146 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002147 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002148 /* Dell systems */
2149 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2150 "unknown Dell", STAC_922X_DELL_D81),
2151 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2152 "unknown Dell", STAC_922X_DELL_D81),
2153 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2154 "unknown Dell", STAC_922X_DELL_D81),
2155 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2156 "unknown Dell", STAC_922X_DELL_D82),
2157 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2158 "unknown Dell", STAC_922X_DELL_M81),
2159 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2160 "unknown Dell", STAC_922X_DELL_D82),
2161 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2162 "unknown Dell", STAC_922X_DELL_D81),
2163 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2164 "unknown Dell", STAC_922X_DELL_D81),
2165 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2166 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002167 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002168 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002169 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002170 {} /* terminator */
2171};
2172
Matt Porter3cc08dc2006-01-23 15:27:49 +01002173static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002174 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2175 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2176 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2177 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002178};
2179
Tobin Davis93ed1502006-09-01 21:03:12 +02002180static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002181 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2182 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2183 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2184 0x40000100, 0x40000100
2185};
2186
Tobin Davis93ed1502006-09-01 21:03:12 +02002187static unsigned int d965_5st_pin_configs[14] = {
2188 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2189 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2190 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2191 0x40000100, 0x40000100
2192};
2193
Takashi Iwai679d92e2009-05-24 19:00:08 +02002194static unsigned int d965_5st_no_fp_pin_configs[14] = {
2195 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2196 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2197 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2198 0x40000100, 0x40000100
2199};
2200
Tobin Davis4ff076e2007-08-07 11:48:12 +02002201static unsigned int dell_3st_pin_configs[14] = {
2202 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2203 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002204 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002205 0x40c003fc, 0x40000100
2206};
2207
Tobin Davis93ed1502006-09-01 21:03:12 +02002208static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002209 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002210 [STAC_D965_REF] = ref927x_pin_configs,
2211 [STAC_D965_3ST] = d965_3st_pin_configs,
2212 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002213 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002214 [STAC_DELL_3ST] = dell_3st_pin_configs,
2215 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002216};
2217
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002218static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002219 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002220 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002221 [STAC_D965_REF] = "ref",
2222 [STAC_D965_3ST] = "3stack",
2223 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002224 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002225 [STAC_DELL_3ST] = "dell-3stack",
2226 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002227};
2228
2229static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2230 /* SigmaTel reference board */
2231 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2232 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002233 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2234 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002235 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002236 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2237 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002238 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002239 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2240 "Intel D965", STAC_D965_3ST),
2241 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2242 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002243 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002244 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002245 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002246 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2247 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002248 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002249 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2250 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002251 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Takashi Iwai24918b62008-09-30 12:58:54 +02002252 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002253 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2254 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2255 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2256 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002257 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002258 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2259 "Intel D965", STAC_D965_5ST),
2260 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2261 "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002262 {} /* terminator */
2263};
2264
Matt Porterf3302a52006-07-31 12:49:34 +02002265static unsigned int ref9205_pin_configs[12] = {
2266 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002267 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002268 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002269};
2270
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002271/*
2272 STAC 9205 pin configs for
2273 102801F1
2274 102801F2
2275 102801FC
2276 102801FD
2277 10280204
2278 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002279 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002280*/
2281static unsigned int dell_9205_m42_pin_configs[12] = {
2282 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2283 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2284 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2285};
2286
2287/*
2288 STAC 9205 pin configs for
2289 102801F9
2290 102801FA
2291 102801FE
2292 102801FF (Dell Precision M4300)
2293 10280206
2294 10280200
2295 10280201
2296*/
2297static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002298 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2299 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2300 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2301};
2302
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002303static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002304 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2305 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2306 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2307};
2308
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002309static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002310 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002311 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2312 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2313 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002314 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002315};
2316
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002317static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002318 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002319 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002320 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002321 [STAC_9205_DELL_M43] = "dell-m43",
2322 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002323 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002324};
2325
2326static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2327 /* SigmaTel reference board */
2328 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2329 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002330 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2331 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002332 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2333 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002334 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002335 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2336 "unknown Dell", STAC_9205_DELL_M42),
2337 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2338 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002339 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002340 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002341 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2342 "Dell Precision", STAC_9205_DELL_M43),
2343 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2344 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002345 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2346 "unknown Dell", STAC_9205_DELL_M42),
2347 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2348 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002349 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2350 "Dell Precision", STAC_9205_DELL_M43),
2351 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002352 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002353 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2354 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002355 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2356 "Dell Precision", STAC_9205_DELL_M43),
2357 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2358 "Dell Precision", STAC_9205_DELL_M43),
2359 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2360 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002361 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2362 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002363 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2364 "Dell Vostro 1500", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002365 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002366 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002367 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002368 {} /* terminator */
2369};
2370
Takashi Iwai330ee992009-02-20 14:33:36 +01002371static void stac92xx_set_config_regs(struct hda_codec *codec,
2372 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002373{
2374 int i;
2375 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002376
Takashi Iwai330ee992009-02-20 14:33:36 +01002377 if (!pincfgs)
2378 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002379
Matthew Ranostay87d48362007-07-17 11:52:24 +02002380 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002381 if (spec->pin_nids[i] && pincfgs[i])
2382 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2383 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002384}
2385
Matt2f2f4252005-04-13 14:45:30 +02002386/*
2387 * Analog playback callbacks
2388 */
2389static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2390 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002391 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002392{
2393 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002394 if (spec->stream_delay)
2395 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002396 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2397 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002398}
2399
2400static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2401 struct hda_codec *codec,
2402 unsigned int stream_tag,
2403 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002404 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002405{
2406 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002407 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002408}
2409
2410static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2411 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002412 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002413{
2414 struct sigmatel_spec *spec = codec->spec;
2415 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2416}
2417
2418/*
Mattdabbed62005-06-14 10:19:34 +02002419 * Digital playback callbacks
2420 */
2421static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2422 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002423 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002424{
2425 struct sigmatel_spec *spec = codec->spec;
2426 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2427}
2428
2429static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2430 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002431 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002432{
2433 struct sigmatel_spec *spec = codec->spec;
2434 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2435}
2436
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002437static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2438 struct hda_codec *codec,
2439 unsigned int stream_tag,
2440 unsigned int format,
2441 struct snd_pcm_substream *substream)
2442{
2443 struct sigmatel_spec *spec = codec->spec;
2444 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2445 stream_tag, format, substream);
2446}
2447
Takashi Iwai9411e212009-02-13 11:32:28 +01002448static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2449 struct hda_codec *codec,
2450 struct snd_pcm_substream *substream)
2451{
2452 struct sigmatel_spec *spec = codec->spec;
2453 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2454}
2455
Mattdabbed62005-06-14 10:19:34 +02002456
2457/*
Matt2f2f4252005-04-13 14:45:30 +02002458 * Analog capture callbacks
2459 */
2460static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2461 struct hda_codec *codec,
2462 unsigned int stream_tag,
2463 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002464 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002465{
2466 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002467 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002468
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002469 if (spec->powerdown_adcs) {
2470 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002471 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002472 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2473 }
2474 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002475 return 0;
2476}
2477
2478static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2479 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002480 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002481{
2482 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002483 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002484
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002485 snd_hda_codec_cleanup_stream(codec, nid);
2486 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002487 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002488 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002489 return 0;
2490}
2491
Mattdabbed62005-06-14 10:19:34 +02002492static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2493 .substreams = 1,
2494 .channels_min = 2,
2495 .channels_max = 2,
2496 /* NID is set in stac92xx_build_pcms */
2497 .ops = {
2498 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002499 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002500 .prepare = stac92xx_dig_playback_pcm_prepare,
2501 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002502 },
2503};
2504
2505static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2506 .substreams = 1,
2507 .channels_min = 2,
2508 .channels_max = 2,
2509 /* NID is set in stac92xx_build_pcms */
2510};
2511
Matt2f2f4252005-04-13 14:45:30 +02002512static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2513 .substreams = 1,
2514 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002515 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002516 .nid = 0x02, /* NID to query formats and rates */
2517 .ops = {
2518 .open = stac92xx_playback_pcm_open,
2519 .prepare = stac92xx_playback_pcm_prepare,
2520 .cleanup = stac92xx_playback_pcm_cleanup
2521 },
2522};
2523
Matt Porter3cc08dc2006-01-23 15:27:49 +01002524static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2525 .substreams = 1,
2526 .channels_min = 2,
2527 .channels_max = 2,
2528 .nid = 0x06, /* NID to query formats and rates */
2529 .ops = {
2530 .open = stac92xx_playback_pcm_open,
2531 .prepare = stac92xx_playback_pcm_prepare,
2532 .cleanup = stac92xx_playback_pcm_cleanup
2533 },
2534};
2535
Matt2f2f4252005-04-13 14:45:30 +02002536static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002537 .channels_min = 2,
2538 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002539 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002540 .ops = {
2541 .prepare = stac92xx_capture_pcm_prepare,
2542 .cleanup = stac92xx_capture_pcm_cleanup
2543 },
2544};
2545
2546static int stac92xx_build_pcms(struct hda_codec *codec)
2547{
2548 struct sigmatel_spec *spec = codec->spec;
2549 struct hda_pcm *info = spec->pcm_rec;
2550
2551 codec->num_pcms = 1;
2552 codec->pcm_info = info;
2553
Mattc7d4b2f2005-06-27 14:59:41 +02002554 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002555 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002556 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2557 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002558 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002559 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002560 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002561
2562 if (spec->alt_switch) {
2563 codec->num_pcms++;
2564 info++;
2565 info->name = "STAC92xx Analog Alt";
2566 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2567 }
Matt2f2f4252005-04-13 14:45:30 +02002568
Mattdabbed62005-06-14 10:19:34 +02002569 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2570 codec->num_pcms++;
2571 info++;
2572 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002573 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002574 if (spec->multiout.dig_out_nid) {
2575 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2576 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2577 }
2578 if (spec->dig_in_nid) {
2579 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2580 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2581 }
2582 }
2583
Matt2f2f4252005-04-13 14:45:30 +02002584 return 0;
2585}
2586
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002587static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2588 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002589{
Takashi Iwai1327a322009-03-23 13:07:47 +01002590 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002591 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2592 if (pincap & AC_PINCAP_VREF_100)
2593 return AC_PINCTL_VREF_100;
2594 if (pincap & AC_PINCAP_VREF_80)
2595 return AC_PINCTL_VREF_80;
2596 if (pincap & AC_PINCAP_VREF_50)
2597 return AC_PINCTL_VREF_50;
2598 if (pincap & AC_PINCAP_VREF_GRD)
2599 return AC_PINCTL_VREF_GRD;
2600 return 0;
2601}
2602
Matt Porter403d1942005-11-29 15:00:51 +01002603static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2604
2605{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002606 snd_hda_codec_write_cache(codec, nid, 0,
2607 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002608}
2609
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002610#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2611
2612static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2613 struct snd_ctl_elem_value *ucontrol)
2614{
2615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2616 struct sigmatel_spec *spec = codec->spec;
2617
Takashi Iwaid7a89432008-11-12 09:48:04 +01002618 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002619 return 0;
2620}
2621
Takashi Iwai62558ce2009-07-29 14:23:09 +02002622static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002623
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002624static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2625 struct snd_ctl_elem_value *ucontrol)
2626{
2627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2628 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002629 int nid = kcontrol->private_value;
2630
2631 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002632
2633 /* check to be sure that the ports are upto date with
2634 * switch changes
2635 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002636 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002637
2638 return 1;
2639}
2640
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002641static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2642 struct snd_ctl_elem_info *uinfo)
2643{
2644 int i;
2645 static char *texts[] = {
2646 "Mic In", "Line In", "Line Out"
2647 };
2648
2649 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2650 struct sigmatel_spec *spec = codec->spec;
2651 hda_nid_t nid = kcontrol->private_value;
2652
2653 if (nid == spec->mic_switch || nid == spec->line_switch)
2654 i = 3;
2655 else
2656 i = 2;
2657
2658 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2659 uinfo->value.enumerated.items = i;
2660 uinfo->count = 1;
2661 if (uinfo->value.enumerated.item >= i)
2662 uinfo->value.enumerated.item = i-1;
2663 strcpy(uinfo->value.enumerated.name,
2664 texts[uinfo->value.enumerated.item]);
2665
2666 return 0;
2667}
2668
2669static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2670 struct snd_ctl_elem_value *ucontrol)
2671{
2672 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2673 hda_nid_t nid = kcontrol->private_value;
2674 unsigned int vref = stac92xx_vref_get(codec, nid);
2675
2676 if (vref == stac92xx_get_default_vref(codec, nid))
2677 ucontrol->value.enumerated.item[0] = 0;
2678 else if (vref == AC_PINCTL_VREF_GRD)
2679 ucontrol->value.enumerated.item[0] = 1;
2680 else if (vref == AC_PINCTL_VREF_HIZ)
2681 ucontrol->value.enumerated.item[0] = 2;
2682
2683 return 0;
2684}
2685
2686static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2687 struct snd_ctl_elem_value *ucontrol)
2688{
2689 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2690 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002691 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002692 hda_nid_t nid = kcontrol->private_value;
2693
2694 if (ucontrol->value.enumerated.item[0] == 0)
2695 new_vref = stac92xx_get_default_vref(codec, nid);
2696 else if (ucontrol->value.enumerated.item[0] == 1)
2697 new_vref = AC_PINCTL_VREF_GRD;
2698 else if (ucontrol->value.enumerated.item[0] == 2)
2699 new_vref = AC_PINCTL_VREF_HIZ;
2700 else
2701 return 0;
2702
2703 if (new_vref != stac92xx_vref_get(codec, nid)) {
2704 error = stac92xx_vref_set(codec, nid, new_vref);
2705 return error;
2706 }
2707
2708 return 0;
2709}
2710
2711static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2712 struct snd_ctl_elem_info *uinfo)
2713{
2714 static char *texts[2];
2715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2716 struct sigmatel_spec *spec = codec->spec;
2717
2718 if (kcontrol->private_value == spec->line_switch)
2719 texts[0] = "Line In";
2720 else
2721 texts[0] = "Mic In";
2722 texts[1] = "Line Out";
2723 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2724 uinfo->value.enumerated.items = 2;
2725 uinfo->count = 1;
2726
2727 if (uinfo->value.enumerated.item >= 2)
2728 uinfo->value.enumerated.item = 1;
2729 strcpy(uinfo->value.enumerated.name,
2730 texts[uinfo->value.enumerated.item]);
2731
2732 return 0;
2733}
Matt Porter403d1942005-11-29 15:00:51 +01002734
2735static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2736{
2737 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2738 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002739 hda_nid_t nid = kcontrol->private_value;
2740 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002741
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002742 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002743 return 0;
2744}
2745
2746static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2747{
2748 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2749 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002750 hda_nid_t nid = kcontrol->private_value;
2751 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2752 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002753
2754 spec->io_switch[io_idx] = val;
2755
2756 if (val)
2757 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002758 else {
2759 unsigned int pinctl = AC_PINCTL_IN_EN;
2760 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002761 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002762 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2763 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002764
2765 /* check the auto-mute again: we need to mute/unmute the speaker
2766 * appropriately according to the pin direction
2767 */
2768 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002769 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002770
Matt Porter403d1942005-11-29 15:00:51 +01002771 return 1;
2772}
2773
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002774#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2775
2776static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2777 struct snd_ctl_elem_value *ucontrol)
2778{
2779 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2780 struct sigmatel_spec *spec = codec->spec;
2781
2782 ucontrol->value.integer.value[0] = spec->clfe_swap;
2783 return 0;
2784}
2785
2786static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2787 struct snd_ctl_elem_value *ucontrol)
2788{
2789 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2790 struct sigmatel_spec *spec = codec->spec;
2791 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002792 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002793
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002794 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002795 return 0;
2796
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002797 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002798
2799 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2800 spec->clfe_swap ? 0x4 : 0x0);
2801
2802 return 1;
2803}
2804
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002805#define STAC_CODEC_HP_SWITCH(xname) \
2806 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2807 .name = xname, \
2808 .index = 0, \
2809 .info = stac92xx_hp_switch_info, \
2810 .get = stac92xx_hp_switch_get, \
2811 .put = stac92xx_hp_switch_put, \
2812 }
2813
Matt Porter403d1942005-11-29 15:00:51 +01002814#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2815 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2816 .name = xname, \
2817 .index = 0, \
2818 .info = stac92xx_io_switch_info, \
2819 .get = stac92xx_io_switch_get, \
2820 .put = stac92xx_io_switch_put, \
2821 .private_value = xpval, \
2822 }
2823
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002824#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2825 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2826 .name = xname, \
2827 .index = 0, \
2828 .info = stac92xx_clfe_switch_info, \
2829 .get = stac92xx_clfe_switch_get, \
2830 .put = stac92xx_clfe_switch_put, \
2831 .private_value = xpval, \
2832 }
Matt Porter403d1942005-11-29 15:00:51 +01002833
Mattc7d4b2f2005-06-27 14:59:41 +02002834enum {
2835 STAC_CTL_WIDGET_VOL,
2836 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002837 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002838 STAC_CTL_WIDGET_AMP_MUX,
2839 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002840 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002841 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002842 STAC_CTL_WIDGET_CLFE_SWITCH,
2843 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002844};
2845
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002846static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002847 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2848 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002849 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002850 STAC_AMP_MUX,
2851 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002852 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002853 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002854 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002855 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002856};
2857
2858/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002859static struct snd_kcontrol_new *
2860stac_control_new(struct sigmatel_spec *spec,
2861 struct snd_kcontrol_new *ktemp,
2862 const char *name)
Mattc7d4b2f2005-06-27 14:59:41 +02002863{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002864 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002865
Takashi Iwai603c4012008-07-30 15:01:44 +02002866 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2867 knew = snd_array_new(&spec->kctls);
2868 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002869 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002870 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002871 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002872 if (!knew->name) {
2873 /* roolback */
2874 memset(knew, 0, sizeof(*knew));
2875 spec->kctls.alloced--;
2876 return NULL;
2877 }
2878 return knew;
2879}
2880
2881static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2882 struct snd_kcontrol_new *ktemp,
2883 int idx, const char *name,
2884 unsigned long val)
2885{
2886 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2887 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002888 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002889 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002890 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002891 return 0;
2892}
2893
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002894static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2895 int type, int idx, const char *name,
2896 unsigned long val)
2897{
2898 return stac92xx_add_control_temp(spec,
2899 &stac92xx_control_templates[type],
2900 idx, name, val);
2901}
2902
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002903
2904/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002905static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2906 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002907{
2908 return stac92xx_add_control_idx(spec, type, 0, name, val);
2909}
2910
Takashi Iwaie3c75962009-01-23 11:57:22 +01002911static struct snd_kcontrol_new stac_input_src_temp = {
2912 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2913 .name = "Input Source",
2914 .info = stac92xx_mux_enum_info,
2915 .get = stac92xx_mux_enum_get,
2916 .put = stac92xx_mux_enum_put,
2917};
2918
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002919static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2920 hda_nid_t nid, int idx)
2921{
2922 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2923 int control = 0;
2924 struct sigmatel_spec *spec = codec->spec;
2925 char name[22];
2926
2927 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2928 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2929 && nid == spec->line_switch)
2930 control = STAC_CTL_WIDGET_IO_SWITCH;
2931 else if (snd_hda_query_pin_caps(codec, nid)
2932 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2933 control = STAC_CTL_WIDGET_DC_BIAS;
2934 else if (nid == spec->mic_switch)
2935 control = STAC_CTL_WIDGET_IO_SWITCH;
2936 }
2937
2938 if (control) {
2939 strcpy(name, auto_pin_cfg_labels[idx]);
2940 return stac92xx_add_control(codec->spec, control,
2941 strcat(name, " Jack Mode"), nid);
2942 }
2943
2944 return 0;
2945}
2946
Takashi Iwaie3c75962009-01-23 11:57:22 +01002947static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2948{
2949 struct snd_kcontrol_new *knew;
2950 struct hda_input_mux *imux = &spec->private_imux;
2951
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002952 if (spec->auto_mic)
2953 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002954 if (!spec->num_adcs || imux->num_items <= 1)
2955 return 0; /* no need for input source control */
2956 knew = stac_control_new(spec, &stac_input_src_temp,
2957 stac_input_src_temp.name);
2958 if (!knew)
2959 return -ENOMEM;
2960 knew->count = spec->num_adcs;
2961 return 0;
2962}
2963
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002964/* check whether the line-input can be used as line-out */
2965static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002966{
2967 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002968 struct auto_pin_cfg *cfg = &spec->autocfg;
2969 hda_nid_t nid;
2970 unsigned int pincap;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002971
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002972 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2973 return 0;
2974 nid = cfg->input_pins[AUTO_PIN_LINE];
Takashi Iwai1327a322009-03-23 13:07:47 +01002975 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002976 if (pincap & AC_PINCAP_OUT)
2977 return nid;
Matt Porter403d1942005-11-29 15:00:51 +01002978 return 0;
2979}
2980
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002981/* check whether the mic-input can be used as line-out */
2982static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2983{
2984 struct sigmatel_spec *spec = codec->spec;
2985 struct auto_pin_cfg *cfg = &spec->autocfg;
2986 unsigned int def_conf, pincap;
2987 unsigned int mic_pin;
2988
2989 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2990 return 0;
2991 mic_pin = AUTO_PIN_MIC;
2992 for (;;) {
2993 hda_nid_t nid = cfg->input_pins[mic_pin];
Takashi Iwai330ee992009-02-20 14:33:36 +01002994 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002995 /* some laptops have an internal analog microphone
2996 * which can't be used as a output */
2997 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai1327a322009-03-23 13:07:47 +01002998 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002999 if (pincap & AC_PINCAP_OUT)
3000 return nid;
3001 }
3002 if (mic_pin == AUTO_PIN_MIC)
3003 mic_pin = AUTO_PIN_FRONT_MIC;
3004 else
3005 break;
3006 }
3007 return 0;
3008}
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003009
3010static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3011{
3012 int i;
3013
3014 for (i = 0; i < spec->multiout.num_dacs; i++) {
3015 if (spec->multiout.dac_nids[i] == nid)
3016 return 1;
3017 }
3018
3019 return 0;
3020}
3021
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003022static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3023{
3024 int i;
3025 if (is_in_dac_nids(spec, nid))
3026 return 1;
3027 for (i = 0; i < spec->autocfg.hp_outs; i++)
3028 if (spec->hp_dacs[i] == nid)
3029 return 1;
3030 for (i = 0; i < spec->autocfg.speaker_outs; i++)
3031 if (spec->speaker_dacs[i] == nid)
3032 return 1;
3033 return 0;
3034}
3035
3036static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
3037{
3038 struct sigmatel_spec *spec = codec->spec;
3039 int j, conn_len;
3040 hda_nid_t conn[HDA_MAX_CONNECTIONS];
3041 unsigned int wcaps, wtype;
3042
3043 conn_len = snd_hda_get_connections(codec, nid, conn,
3044 HDA_MAX_CONNECTIONS);
3045 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01003046 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003047 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003048 /* we check only analog outputs */
3049 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3050 continue;
3051 /* if this route has a free DAC, assign it */
3052 if (!check_all_dac_nids(spec, conn[j])) {
3053 if (conn_len > 1) {
3054 /* select this DAC in the pin's input mux */
3055 snd_hda_codec_write_cache(codec, nid, 0,
3056 AC_VERB_SET_CONNECT_SEL, j);
3057 }
3058 return conn[j];
3059 }
3060 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003061 /* if all DACs are already assigned, connect to the primary DAC */
3062 if (conn_len > 1) {
3063 for (j = 0; j < conn_len; j++) {
3064 if (conn[j] == spec->multiout.dac_nids[0]) {
3065 snd_hda_codec_write_cache(codec, nid, 0,
3066 AC_VERB_SET_CONNECT_SEL, j);
3067 break;
3068 }
3069 }
3070 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003071 return 0;
3072}
3073
3074static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3075static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3076
Matt Porter3cc08dc2006-01-23 15:27:49 +01003077/*
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003078 * Fill in the dac_nids table from the parsed pin configuration
3079 * This function only works when every pin in line_out_pins[]
3080 * contains atleast one DAC in its connection list. Some 92xx
3081 * codecs are not connected directly to a DAC, such as the 9200
3082 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01003083 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003084static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003085{
3086 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003087 struct auto_pin_cfg *cfg = &spec->autocfg;
3088 int i;
3089 hda_nid_t nid, dac;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003090
Mattc7d4b2f2005-06-27 14:59:41 +02003091 for (i = 0; i < cfg->line_outs; i++) {
3092 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003093 dac = get_unassigned_dac(codec, nid);
3094 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003095 if (spec->multiout.num_dacs > 0) {
3096 /* we have already working output pins,
3097 * so let's drop the broken ones again
3098 */
3099 cfg->line_outs = spec->multiout.num_dacs;
3100 break;
3101 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003102 /* error out, no available DAC found */
3103 snd_printk(KERN_ERR
3104 "%s: No available DAC for pin 0x%x\n",
3105 __func__, nid);
3106 return -ENODEV;
3107 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003108 add_spec_dacs(spec, dac);
3109 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003110
Takashi Iwai139e0712009-03-06 12:10:41 +01003111 for (i = 0; i < cfg->hp_outs; i++) {
3112 nid = cfg->hp_pins[i];
3113 dac = get_unassigned_dac(codec, nid);
3114 if (dac) {
3115 if (!spec->multiout.hp_nid)
3116 spec->multiout.hp_nid = dac;
3117 else
3118 add_spec_extra_dacs(spec, dac);
3119 }
3120 spec->hp_dacs[i] = dac;
3121 }
3122
3123 for (i = 0; i < cfg->speaker_outs; i++) {
3124 nid = cfg->speaker_pins[i];
3125 dac = get_unassigned_dac(codec, nid);
3126 if (dac)
3127 add_spec_extra_dacs(spec, dac);
3128 spec->speaker_dacs[i] = dac;
3129 }
3130
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003131 /* add line-in as output */
3132 nid = check_line_out_switch(codec);
3133 if (nid) {
3134 dac = get_unassigned_dac(codec, nid);
3135 if (dac) {
3136 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3137 nid, cfg->line_outs);
3138 cfg->line_out_pins[cfg->line_outs] = nid;
3139 cfg->line_outs++;
3140 spec->line_switch = nid;
3141 add_spec_dacs(spec, dac);
3142 }
3143 }
3144 /* add mic as output */
3145 nid = check_mic_out_switch(codec);
3146 if (nid) {
3147 dac = get_unassigned_dac(codec, nid);
3148 if (dac) {
3149 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3150 nid, cfg->line_outs);
3151 cfg->line_out_pins[cfg->line_outs] = nid;
3152 cfg->line_outs++;
3153 spec->mic_switch = nid;
3154 add_spec_dacs(spec, dac);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003155 }
Mattc7d4b2f2005-06-27 14:59:41 +02003156 }
3157
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003158 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003159 spec->multiout.num_dacs,
3160 spec->multiout.dac_nids[0],
3161 spec->multiout.dac_nids[1],
3162 spec->multiout.dac_nids[2],
3163 spec->multiout.dac_nids[3],
3164 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003165
Mattc7d4b2f2005-06-27 14:59:41 +02003166 return 0;
3167}
3168
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003169/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003170static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3171 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003172{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003173 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003174 char name[32];
3175 int err;
3176
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003177 if (!spec->check_volume_offset) {
3178 unsigned int caps, step, nums, db_scale;
3179 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3180 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3181 AC_AMPCAP_STEP_SIZE_SHIFT;
3182 step = (step + 1) * 25; /* in .01dB unit */
3183 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3184 AC_AMPCAP_NUM_STEPS_SHIFT;
3185 db_scale = nums * step;
3186 /* if dB scale is over -64dB, and finer enough,
3187 * let's reduce it to half
3188 */
3189 if (db_scale > 6400 && nums >= 0x1f)
3190 spec->volume_offset = nums / 2;
3191 spec->check_volume_offset = 1;
3192 }
3193
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003194 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003195 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003196 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3197 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003198 if (err < 0)
3199 return err;
3200 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003201 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003202 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3203 if (err < 0)
3204 return err;
3205 return 0;
3206}
3207
Takashi Iwai668b9652009-03-06 10:13:24 +01003208#define create_controls(codec, pfx, nid, chs) \
3209 create_controls_idx(codec, pfx, 0, nid, chs)
3210
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003211static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3212{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003213 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003214 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3215 return 1;
3216 } else {
3217 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3218 spec->multiout.num_dacs++;
3219 }
3220 return 0;
3221}
3222
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003223static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003224{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003225 int i;
3226 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3227 if (!spec->multiout.extra_out_nid[i]) {
3228 spec->multiout.extra_out_nid[i] = nid;
3229 return 0;
3230 }
3231 }
3232 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3233 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003234}
3235
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003236/* Create output controls
3237 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3238 */
3239static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3240 const hda_nid_t *pins,
3241 const hda_nid_t *dac_nids,
3242 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003243{
Takashi Iwai76624532008-12-19 10:09:47 +01003244 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003245 static const char *chname[4] = {
3246 "Front", "Surround", NULL /*CLFE*/, "Side"
3247 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003248 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003249 int i, err;
3250 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003251
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003252 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003253 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3254 wid_caps = get_wcaps(codec, pins[i]);
3255 if (wid_caps & AC_WCAP_UNSOL_CAP)
3256 spec->hp_detect = 1;
3257 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003258 nid = dac_nids[i];
3259 if (!nid)
3260 continue;
3261 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003262 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003263 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003264 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003265 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003266 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003267 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003268 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003269
3270 wid_caps = get_wcaps(codec, nid);
3271
3272 if (wid_caps & AC_WCAP_LR_SWAP) {
3273 err = stac92xx_add_control(spec,
3274 STAC_CTL_WIDGET_CLFE_SWITCH,
3275 "Swap Center/LFE Playback Switch", nid);
3276
3277 if (err < 0)
3278 return err;
3279 }
3280
Mattc7d4b2f2005-06-27 14:59:41 +02003281 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003282 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003283 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003284 switch (type) {
3285 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003286 name = "Headphone";
3287 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003288 break;
3289 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003290 name = "Speaker";
3291 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003292 break;
3293 default:
3294 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003295 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003296 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003297 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003298 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003299 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003300 return err;
3301 }
3302 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003303 return 0;
3304}
3305
Takashi Iwai6479c632009-07-28 18:20:25 +02003306static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3307 unsigned long sw, int idx)
3308{
3309 int err;
3310 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003311 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003312 if (err < 0)
3313 return err;
3314 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003315 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003316 if (err < 0)
3317 return err;
3318 return 0;
3319}
3320
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003321/* add playback controls from the parsed DAC table */
3322static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3323 const struct auto_pin_cfg *cfg)
3324{
3325 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003326 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003327 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003328 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003329
3330 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3331 spec->multiout.dac_nids,
3332 cfg->line_out_type);
3333 if (err < 0)
3334 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003335
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003336 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003337 err = stac92xx_add_control(spec,
3338 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003339 "Headphone as Line Out Switch",
3340 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003341 if (err < 0)
3342 return err;
3343 }
3344
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003345 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3346 nid = cfg->input_pins[idx];
3347 if (nid) {
3348 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3349 if (err < 0)
3350 return err;
3351 }
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003352 }
Matt Porter403d1942005-11-29 15:00:51 +01003353
Mattc7d4b2f2005-06-27 14:59:41 +02003354 return 0;
3355}
3356
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003357/* add playback controls for Speaker and HP outputs */
3358static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3359 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003360{
3361 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003362 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003363
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003364 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3365 spec->hp_dacs, AUTO_PIN_HP_OUT);
3366 if (err < 0)
3367 return err;
3368
3369 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3370 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3371 if (err < 0)
3372 return err;
3373
Mattc7d4b2f2005-06-27 14:59:41 +02003374 return 0;
3375}
3376
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003377/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003378static const char *stac92xx_mono_labels[4] = {
3379 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003380};
3381
3382/* create mono mux for mono out on capable codecs */
3383static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3384{
3385 struct sigmatel_spec *spec = codec->spec;
3386 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3387 int i, num_cons;
3388 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3389
3390 num_cons = snd_hda_get_connections(codec,
3391 spec->mono_nid,
3392 con_lst,
3393 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003394 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003395 return -EINVAL;
3396
3397 for (i = 0; i < num_cons; i++) {
3398 mono_mux->items[mono_mux->num_items].label =
3399 stac92xx_mono_labels[i];
3400 mono_mux->items[mono_mux->num_items].index = i;
3401 mono_mux->num_items++;
3402 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003403
3404 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3405 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003406}
3407
Matthew Ranostay89385032008-09-11 09:49:39 -04003408/* labels for amp mux outputs */
3409static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003410 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003411};
3412
3413/* create amp out controls mux on capable codecs */
3414static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3415{
3416 struct sigmatel_spec *spec = codec->spec;
3417 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3418 int i, err;
3419
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003420 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003421 amp_mux->items[amp_mux->num_items].label =
3422 stac92xx_amp_labels[i];
3423 amp_mux->items[amp_mux->num_items].index = i;
3424 amp_mux->num_items++;
3425 }
3426
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003427 if (spec->num_amps > 1) {
3428 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3429 "Amp Selector Capture Switch", 0);
3430 if (err < 0)
3431 return err;
3432 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003433 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3434 "Amp Capture Volume",
3435 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3436}
3437
3438
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003439/* create PC beep volume controls */
3440static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3441 hda_nid_t nid)
3442{
3443 struct sigmatel_spec *spec = codec->spec;
3444 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3445 int err;
3446
3447 /* check for mute support for the the amp */
3448 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3449 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3450 "PC Beep Playback Switch",
3451 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3452 if (err < 0)
3453 return err;
3454 }
3455
3456 /* check to see if there is volume support for the amp */
3457 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3458 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3459 "PC Beep Playback Volume",
3460 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3461 if (err < 0)
3462 return err;
3463 }
3464 return 0;
3465}
3466
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003467#ifdef CONFIG_SND_HDA_INPUT_BEEP
3468#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3469
3470static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3471 struct snd_ctl_elem_value *ucontrol)
3472{
3473 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3474 ucontrol->value.integer.value[0] = codec->beep->enabled;
3475 return 0;
3476}
3477
3478static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3479 struct snd_ctl_elem_value *ucontrol)
3480{
3481 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3482 int enabled = !!ucontrol->value.integer.value[0];
3483 if (codec->beep->enabled != enabled) {
3484 codec->beep->enabled = enabled;
3485 return 1;
3486 }
3487 return 0;
3488}
3489
3490static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3491 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3492 .info = stac92xx_dig_beep_switch_info,
3493 .get = stac92xx_dig_beep_switch_get,
3494 .put = stac92xx_dig_beep_switch_put,
3495};
3496
3497static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3498{
3499 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3500 0, "PC Beep Playback Switch", 0);
3501}
3502#endif
3503
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003504static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3505{
3506 struct sigmatel_spec *spec = codec->spec;
3507 int wcaps, nid, i, err = 0;
3508
3509 for (i = 0; i < spec->num_muxes; i++) {
3510 nid = spec->mux_nids[i];
3511 wcaps = get_wcaps(codec, nid);
3512
3513 if (wcaps & AC_WCAP_OUT_AMP) {
3514 err = stac92xx_add_control_idx(spec,
3515 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3516 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3517 if (err < 0)
3518 return err;
3519 }
3520 }
3521 return 0;
3522};
3523
Matthew Ranostayd9737752008-09-07 12:03:41 +02003524static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003525 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003526};
3527
3528static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3529{
3530 struct sigmatel_spec *spec = codec->spec;
3531 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003532 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003533 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003534 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003535
3536 num_cons = snd_hda_get_connections(codec,
3537 spec->smux_nids[0],
3538 con_lst,
3539 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003540 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003541 return -EINVAL;
3542
Matthew Ranostay65973632008-09-16 10:39:37 -04003543 if (!labels)
3544 labels = stac92xx_spdif_labels;
3545
Matthew Ranostayd9737752008-09-07 12:03:41 +02003546 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003547 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003548 spdif_mux->items[spdif_mux->num_items].index = i;
3549 spdif_mux->num_items++;
3550 }
3551
3552 return 0;
3553}
3554
Matt Porter8b657272006-10-26 17:12:59 +02003555/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003556static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003557 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3558 "Digital Mic 3", "Digital Mic 4"
3559};
3560
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003561static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3562 hda_nid_t nid)
3563{
3564 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3565 int i, nums;
3566
3567 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3568 for (i = 0; i < nums; i++)
3569 if (conn[i] == nid)
3570 return i;
3571 return -1;
3572}
3573
Matt Porter8b657272006-10-26 17:12:59 +02003574/* create playback/capture controls for input pins on dmic capable codecs */
3575static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3576 const struct auto_pin_cfg *cfg)
3577{
3578 struct sigmatel_spec *spec = codec->spec;
3579 struct hda_input_mux *dimux = &spec->private_dimux;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003580 int err, i;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003581 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02003582
3583 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3584 dimux->items[dimux->num_items].index = 0;
3585 dimux->num_items++;
3586
3587 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003588 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003589 int index;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003590 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02003591 unsigned int def_conf;
3592
Takashi Iwai330ee992009-02-20 14:33:36 +01003593 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
Matt Porter8b657272006-10-26 17:12:59 +02003594 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3595 continue;
3596
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003597 nid = spec->dmic_nids[i];
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003598 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3599 if (index < 0)
3600 continue;
3601
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003602 wcaps = get_wcaps(codec, nid) &
3603 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003604
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003605 if (wcaps) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003606 sprintf(name, "%s Capture Volume",
3607 stac92xx_dmic_labels[dimux->num_items]);
3608
3609 err = stac92xx_add_control(spec,
3610 STAC_CTL_WIDGET_VOL,
3611 name,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003612 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3613 (wcaps & AC_WCAP_OUT_AMP) ?
3614 HDA_OUTPUT : HDA_INPUT));
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003615 if (err < 0)
3616 return err;
3617 }
3618
Matt Porter8b657272006-10-26 17:12:59 +02003619 dimux->items[dimux->num_items].label =
3620 stac92xx_dmic_labels[dimux->num_items];
3621 dimux->items[dimux->num_items].index = index;
3622 dimux->num_items++;
3623 }
3624
3625 return 0;
3626}
3627
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003628static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3629 hda_nid_t *fixed, hda_nid_t *ext)
3630{
3631 unsigned int cfg;
3632
3633 if (!nid)
3634 return 0;
3635 cfg = snd_hda_codec_get_pincfg(codec, nid);
3636 switch (get_defcfg_connect(cfg)) {
3637 case AC_JACK_PORT_FIXED:
3638 if (*fixed)
3639 return 1; /* already occupied */
3640 *fixed = nid;
3641 break;
3642 case AC_JACK_PORT_COMPLEX:
3643 if (*ext)
3644 return 1; /* already occupied */
3645 *ext = nid;
3646 break;
3647 }
3648 return 0;
3649}
3650
3651static int set_mic_route(struct hda_codec *codec,
3652 struct sigmatel_mic_route *mic,
3653 hda_nid_t pin)
3654{
3655 struct sigmatel_spec *spec = codec->spec;
3656 struct auto_pin_cfg *cfg = &spec->autocfg;
3657 int i;
3658
3659 mic->pin = pin;
3660 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3661 if (pin == cfg->input_pins[i])
3662 break;
3663 if (i <= AUTO_PIN_FRONT_MIC) {
3664 /* analog pin */
3665 mic->dmux_idx = 0;
3666 i = get_connection_index(codec, spec->mux_nids[0], pin);
3667 if (i < 0)
3668 return -1;
3669 mic->mux_idx = i;
3670 } else {
3671 /* digital pin */
3672 mic->mux_idx = 0;
3673 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3674 if (i < 0)
3675 return -1;
3676 mic->dmux_idx = i;
3677 }
3678 return 0;
3679}
3680
3681/* return non-zero if the device is for automatic mic switch */
3682static int stac_check_auto_mic(struct hda_codec *codec)
3683{
3684 struct sigmatel_spec *spec = codec->spec;
3685 struct auto_pin_cfg *cfg = &spec->autocfg;
3686 hda_nid_t fixed, ext;
3687 int i;
3688
3689 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3690 if (cfg->input_pins[i])
3691 return 0; /* must be exclusively mics */
3692 }
3693 fixed = ext = 0;
3694 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3695 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3696 return 0;
3697 for (i = 0; i < spec->num_dmics; i++)
3698 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3699 return 0;
3700 if (!fixed || !ext)
3701 return 0;
3702 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3703 return 0; /* no unsol support */
3704 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3705 set_mic_route(codec, &spec->int_mic, fixed))
3706 return 0; /* something is wrong */
3707 return 1;
3708}
3709
Mattc7d4b2f2005-06-27 14:59:41 +02003710/* create playback/capture controls for input pins */
3711static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3712{
3713 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003714 struct hda_input_mux *imux = &spec->private_imux;
3715 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3716 int i, j, k;
3717
3718 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003719 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02003720
Takashi Iwai314634b2006-09-21 11:56:18 +02003721 if (!cfg->input_pins[i])
3722 continue;
3723 index = -1;
3724 for (j = 0; j < spec->num_muxes; j++) {
3725 int num_cons;
3726 num_cons = snd_hda_get_connections(codec,
3727 spec->mux_nids[j],
3728 con_lst,
3729 HDA_MAX_NUM_INPUTS);
3730 for (k = 0; k < num_cons; k++)
3731 if (con_lst[k] == cfg->input_pins[i]) {
3732 index = k;
3733 goto found;
3734 }
Mattc7d4b2f2005-06-27 14:59:41 +02003735 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003736 continue;
3737 found:
3738 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3739 imux->items[imux->num_items].index = index;
3740 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003741 }
3742
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003743 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003744 /*
3745 * Set the current input for the muxes.
3746 * The STAC9221 has two input muxes with identical source
3747 * NID lists. Hopefully this won't get confused.
3748 */
3749 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003750 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3751 AC_VERB_SET_CONNECT_SEL,
3752 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003753 }
3754 }
3755
Mattc7d4b2f2005-06-27 14:59:41 +02003756 return 0;
3757}
3758
Mattc7d4b2f2005-06-27 14:59:41 +02003759static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3760{
3761 struct sigmatel_spec *spec = codec->spec;
3762 int i;
3763
3764 for (i = 0; i < spec->autocfg.line_outs; i++) {
3765 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3766 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3767 }
3768}
3769
3770static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3771{
3772 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003773 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003774
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003775 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3776 hda_nid_t pin;
3777 pin = spec->autocfg.hp_pins[i];
3778 if (pin) /* connect to front */
3779 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3780 }
3781 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3782 hda_nid_t pin;
3783 pin = spec->autocfg.speaker_pins[i];
3784 if (pin) /* connect to front */
3785 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3786 }
Mattc7d4b2f2005-06-27 14:59:41 +02003787}
3788
Matt Porter3cc08dc2006-01-23 15:27:49 +01003789static 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 +02003790{
3791 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003792 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003793 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003794
Matt Porter8b657272006-10-26 17:12:59 +02003795 if ((err = snd_hda_parse_pin_def_config(codec,
3796 &spec->autocfg,
3797 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003798 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003799 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003800 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003801
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003802 /* If we have no real line-out pin and multiple hp-outs, HPs should
3803 * be set up as multi-channel outputs.
3804 */
3805 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3806 spec->autocfg.hp_outs > 1) {
3807 /* Copy hp_outs to line_outs, backup line_outs in
3808 * speaker_outs so that the following routines can handle
3809 * HP pins as primary outputs.
3810 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003811 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003812 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3813 sizeof(spec->autocfg.line_out_pins));
3814 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3815 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3816 sizeof(spec->autocfg.hp_pins));
3817 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003818 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3819 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003820 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003821 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003822 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003823 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3824 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003825 u32 caps = query_amp_caps(codec,
3826 spec->autocfg.mono_out_pin, dir);
3827 hda_nid_t conn_list[1];
3828
3829 /* get the mixer node and then the mono mux if it exists */
3830 if (snd_hda_get_connections(codec,
3831 spec->autocfg.mono_out_pin, conn_list, 1) &&
3832 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003833 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003834
3835 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003836 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003837 /* LR swap check, some stac925x have a mux that
3838 * changes the DACs output path instead of the
3839 * mono-mux path.
3840 */
3841 if (wid_type == AC_WID_AUD_SEL &&
3842 !(wcaps & AC_WCAP_LR_SWAP))
3843 spec->mono_nid = conn_list[0];
3844 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003845 if (dir) {
3846 hda_nid_t nid = spec->autocfg.mono_out_pin;
3847
3848 /* most mono outs have a least a mute/unmute switch */
3849 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3850 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3851 "Mono Playback Switch",
3852 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003853 if (err < 0)
3854 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003855 /* check for volume support for the amp */
3856 if ((caps & AC_AMPCAP_NUM_STEPS)
3857 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3858 err = stac92xx_add_control(spec,
3859 STAC_CTL_WIDGET_VOL,
3860 "Mono Playback Volume",
3861 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3862 if (err < 0)
3863 return err;
3864 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003865 }
3866
3867 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3868 AC_PINCTL_OUT_EN);
3869 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003870
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003871 if (!spec->multiout.num_dacs) {
3872 err = stac92xx_auto_fill_dac_nids(codec);
3873 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003874 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003875 err = stac92xx_auto_create_multi_out_ctls(codec,
3876 &spec->autocfg);
3877 if (err < 0)
3878 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003879 }
Mattc7d4b2f2005-06-27 14:59:41 +02003880
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003881 /* setup analog beep controls */
3882 if (spec->anabeep_nid > 0) {
3883 err = stac92xx_auto_create_beep_ctls(codec,
3884 spec->anabeep_nid);
3885 if (err < 0)
3886 return err;
3887 }
3888
3889 /* setup digital beep controls and input device */
3890#ifdef CONFIG_SND_HDA_INPUT_BEEP
3891 if (spec->digbeep_nid > 0) {
3892 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003893 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003894
3895 err = stac92xx_auto_create_beep_ctls(codec, nid);
3896 if (err < 0)
3897 return err;
3898 err = snd_hda_attach_beep_device(codec, nid);
3899 if (err < 0)
3900 return err;
Takashi Iwaifa797962009-05-19 12:50:04 +02003901 /* IDT/STAC codecs have linear beep tone parameter */
3902 codec->beep->linear_tone = 1;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003903 /* if no beep switch is available, make its own one */
3904 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3905 if (codec->beep &&
3906 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3907 err = stac92xx_beep_switch_ctl(codec);
3908 if (err < 0)
3909 return err;
3910 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003911 }
3912#endif
3913
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003914 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003915 if (err < 0)
3916 return err;
3917
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003918 /* All output parsing done, now restore the swapped hp pins */
3919 if (hp_swap) {
3920 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3921 sizeof(spec->autocfg.hp_pins));
3922 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3923 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3924 spec->autocfg.line_outs = 0;
3925 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003926
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003927 if (stac_check_auto_mic(codec)) {
3928 spec->auto_mic = 1;
3929 /* only one capture for auto-mic */
3930 spec->num_adcs = 1;
3931 spec->num_caps = 1;
3932 spec->num_muxes = 1;
3933 }
3934
Takashi Iwai6479c632009-07-28 18:20:25 +02003935 for (i = 0; i < spec->num_caps; i++) {
3936 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3937 spec->capsws[i], i);
3938 if (err < 0)
3939 return err;
3940 }
3941
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003942 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003943 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003944 return err;
3945
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003946 if (spec->mono_nid > 0) {
3947 err = stac92xx_auto_create_mono_output_ctls(codec);
3948 if (err < 0)
3949 return err;
3950 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003951 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003952 err = stac92xx_auto_create_amp_output_ctls(codec);
3953 if (err < 0)
3954 return err;
3955 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003956 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003957 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3958 &spec->autocfg)) < 0)
3959 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003960 if (spec->num_muxes > 0) {
3961 err = stac92xx_auto_create_mux_input_ctls(codec);
3962 if (err < 0)
3963 return err;
3964 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003965 if (spec->num_smuxes > 0) {
3966 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3967 if (err < 0)
3968 return err;
3969 }
Matt Porter8b657272006-10-26 17:12:59 +02003970
Takashi Iwaie3c75962009-01-23 11:57:22 +01003971 err = stac92xx_add_input_source(spec);
3972 if (err < 0)
3973 return err;
3974
Mattc7d4b2f2005-06-27 14:59:41 +02003975 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003976 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003977 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003978
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003979 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003980 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003981 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003982 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003983
Takashi Iwai603c4012008-07-30 15:01:44 +02003984 if (spec->kctls.list)
3985 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003986
3987 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003988 if (!spec->dinput_mux)
3989 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003990 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003991 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04003992 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003993 return 1;
3994}
3995
Takashi Iwai82bc9552006-03-21 11:24:42 +01003996/* add playback controls for HP output */
3997static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3998 struct auto_pin_cfg *cfg)
3999{
4000 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004001 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01004002 unsigned int wid_caps;
4003
4004 if (! pin)
4005 return 0;
4006
4007 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02004008 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01004009 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004010
4011 return 0;
4012}
4013
Richard Fish160ea0d2006-09-06 13:58:25 +02004014/* add playback controls for LFE output */
4015static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4016 struct auto_pin_cfg *cfg)
4017{
4018 struct sigmatel_spec *spec = codec->spec;
4019 int err;
4020 hda_nid_t lfe_pin = 0x0;
4021 int i;
4022
4023 /*
4024 * search speaker outs and line outs for a mono speaker pin
4025 * with an amp. If one is found, add LFE controls
4026 * for it.
4027 */
4028 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4029 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004030 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004031 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4032 if (wcaps == AC_WCAP_OUT_AMP)
4033 /* found a mono speaker with an amp, must be lfe */
4034 lfe_pin = pin;
4035 }
4036
4037 /* if speaker_outs is 0, then speakers may be in line_outs */
4038 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4039 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4040 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004041 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004042 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004043 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004044 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004045 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4046 if (wcaps == AC_WCAP_OUT_AMP)
4047 /* found a mono speaker with an amp,
4048 must be lfe */
4049 lfe_pin = pin;
4050 }
4051 }
4052 }
4053
4054 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004055 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004056 if (err < 0)
4057 return err;
4058 }
4059
4060 return 0;
4061}
4062
Mattc7d4b2f2005-06-27 14:59:41 +02004063static int stac9200_parse_auto_config(struct hda_codec *codec)
4064{
4065 struct sigmatel_spec *spec = codec->spec;
4066 int err;
4067
Kailang Yangdf694da2005-12-05 19:42:22 +01004068 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004069 return err;
4070
4071 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4072 return err;
4073
Takashi Iwai82bc9552006-03-21 11:24:42 +01004074 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4075 return err;
4076
Richard Fish160ea0d2006-09-06 13:58:25 +02004077 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4078 return err;
4079
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004080 if (spec->num_muxes > 0) {
4081 err = stac92xx_auto_create_mux_input_ctls(codec);
4082 if (err < 0)
4083 return err;
4084 }
4085
Takashi Iwaie3c75962009-01-23 11:57:22 +01004086 err = stac92xx_add_input_source(spec);
4087 if (err < 0)
4088 return err;
4089
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004090 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004091 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004092 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004093 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004094
Takashi Iwai603c4012008-07-30 15:01:44 +02004095 if (spec->kctls.list)
4096 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004097
4098 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004099 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004100
4101 return 1;
4102}
4103
Sam Revitch62fe78e2006-05-10 15:09:17 +02004104/*
4105 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4106 * funky external mute control using GPIO pins.
4107 */
4108
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004109static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004110 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004111{
4112 unsigned int gpiostate, gpiomask, gpiodir;
4113
4114 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4115 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004116 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004117
4118 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4119 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004120 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004121
4122 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4123 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004124 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004125
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004126 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004127 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4128
4129 snd_hda_codec_write(codec, codec->afg, 0,
4130 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004131 snd_hda_codec_read(codec, codec->afg, 0,
4132 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004133
4134 msleep(1);
4135
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004136 snd_hda_codec_read(codec, codec->afg, 0,
4137 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004138}
4139
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004140#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +02004141static void stac92xx_free_jack_priv(struct snd_jack *jack)
4142{
4143 struct sigmatel_jack *jacks = jack->private_data;
4144 jacks->nid = 0;
4145 jacks->jack = NULL;
4146}
4147#endif
4148
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004149static int stac92xx_add_jack(struct hda_codec *codec,
4150 hda_nid_t nid, int type)
4151{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004152#ifdef CONFIG_SND_HDA_INPUT_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004153 struct sigmatel_spec *spec = codec->spec;
4154 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01004155 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004156 int connectivity = get_defcfg_connect(def_conf);
4157 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02004158 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004159
4160 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4161 return 0;
4162
4163 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4164 jack = snd_array_new(&spec->jacks);
4165 if (!jack)
4166 return -ENOMEM;
4167 jack->nid = nid;
4168 jack->type = type;
4169
Takashi Iwai86de7412009-07-22 16:02:46 +02004170 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004171 snd_hda_get_jack_type(def_conf),
4172 snd_hda_get_jack_connectivity(def_conf),
4173 snd_hda_get_jack_location(def_conf));
4174
Takashi Iwai95c09092009-04-14 16:15:29 +02004175 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4176 if (err < 0) {
4177 jack->nid = 0;
4178 return err;
4179 }
4180 jack->jack->private_data = jack;
4181 jack->jack->private_free = stac92xx_free_jack_priv;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004182#endif
Takashi Iwai95c09092009-04-14 16:15:29 +02004183 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004184}
4185
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004186static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4187 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004188{
4189 struct sigmatel_event *event;
4190
4191 snd_array_init(&spec->events, sizeof(*event), 32);
4192 event = snd_array_new(&spec->events);
4193 if (!event)
4194 return -ENOMEM;
4195 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004196 event->type = type;
4197 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004198 event->data = data;
4199
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004200 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004201}
4202
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004203static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004204 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004205{
4206 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004207 struct sigmatel_event *event = spec->events.list;
4208 int i;
4209
4210 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004211 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004212 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004213 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004214 return NULL;
4215}
4216
4217static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4218 unsigned char tag)
4219{
4220 struct sigmatel_spec *spec = codec->spec;
4221 struct sigmatel_event *event = spec->events.list;
4222 int i;
4223
4224 for (i = 0; i < spec->events.used; i++, event++) {
4225 if (event->tag == tag)
4226 return event;
4227 }
4228 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004229}
4230
Takashi Iwai62558ce2009-07-29 14:23:09 +02004231/* check if given nid is a valid pin and no other events are assigned
4232 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4233 * Otherwise, returns zero.
4234 */
4235static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4236 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004237{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004238 struct sigmatel_event *event;
4239 int tag;
4240
4241 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004242 return 0;
4243 event = stac_get_event(codec, nid);
4244 if (event) {
4245 if (event->type != type)
4246 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004247 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004248 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004249 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004250 if (tag < 0)
4251 return 0;
4252 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004253 snd_hda_codec_write_cache(codec, nid, 0,
4254 AC_VERB_SET_UNSOLICITED_ENABLE,
4255 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004256 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004257}
4258
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004259static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4260{
4261 int i;
4262 for (i = 0; i < cfg->hp_outs; i++)
4263 if (cfg->hp_pins[i] == nid)
4264 return 1; /* nid is a HP-Out */
4265
4266 return 0; /* nid is not a HP-Out */
4267};
4268
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004269static void stac92xx_power_down(struct hda_codec *codec)
4270{
4271 struct sigmatel_spec *spec = codec->spec;
4272
4273 /* power down inactive DACs */
4274 hda_nid_t *dac;
4275 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004276 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004277 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004278 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4279}
4280
Takashi Iwaif73d3582008-11-25 08:21:51 +01004281static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4282 int enable);
4283
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004284/* override some hints from the hwdep entry */
4285static void stac_store_hints(struct hda_codec *codec)
4286{
4287 struct sigmatel_spec *spec = codec->spec;
4288 const char *p;
4289 int val;
4290
4291 val = snd_hda_get_bool_hint(codec, "hp_detect");
4292 if (val >= 0)
4293 spec->hp_detect = val;
4294 p = snd_hda_get_hint(codec, "gpio_mask");
4295 if (p) {
4296 spec->gpio_mask = simple_strtoul(p, NULL, 0);
4297 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4298 spec->gpio_mask;
4299 }
4300 p = snd_hda_get_hint(codec, "gpio_dir");
4301 if (p)
4302 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4303 p = snd_hda_get_hint(codec, "gpio_data");
4304 if (p)
4305 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4306 p = snd_hda_get_hint(codec, "eapd_mask");
4307 if (p)
4308 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4309 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4310 if (val >= 0)
4311 spec->eapd_switch = val;
4312}
4313
Mattc7d4b2f2005-06-27 14:59:41 +02004314static int stac92xx_init(struct hda_codec *codec)
4315{
4316 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004317 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004318 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004319 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004320
Mattc7d4b2f2005-06-27 14:59:41 +02004321 snd_hda_sequence_write(codec, spec->init);
4322
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004323 /* power down adcs initially */
4324 if (spec->powerdown_adcs)
4325 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004326 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004327 spec->adc_nids[i], 0,
4328 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004329
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004330 /* override some hints */
4331 stac_store_hints(codec);
4332
Takashi Iwaif73d3582008-11-25 08:21:51 +01004333 /* set up GPIO */
4334 gpio = spec->gpio_data;
4335 /* turn on EAPD statically when spec->eapd_switch isn't set.
4336 * otherwise, unsol event will turn it on/off dynamically
4337 */
4338 if (!spec->eapd_switch)
4339 gpio |= spec->eapd_mask;
4340 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4341
Takashi Iwai82bc9552006-03-21 11:24:42 +01004342 /* set up pins */
4343 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004344 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004345 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004346 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004347 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004348 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004349 if (cfg->line_out_type == AUTO_PIN_LINE_OUT) {
4350 /* enable pin-detect for line-outs as well */
4351 for (i = 0; i < cfg->hp_outs; i++) {
4352 hda_nid_t nid = cfg->hp_pins[i];
4353 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4354 }
4355 }
4356
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004357 /* force to enable the first line-out; the others are set up
4358 * in unsol_event
4359 */
4360 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004361 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004362 /* fake event to set up pins */
Takashi Iwai62558ce2009-07-29 14:23:09 +02004363 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004364 } else {
4365 stac92xx_auto_init_multi_out(codec);
4366 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004367 for (i = 0; i < cfg->hp_outs; i++)
4368 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004369 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004370 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004371 /* initialize connection to analog input */
4372 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4373 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004374 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4375 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4376 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004377 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01004378 hda_nid_t nid = cfg->input_pins[i];
4379 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004380 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004381 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4382 /* for mic pins, force to initialize */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02004383 pinctl = stac92xx_get_default_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004384 pinctl |= AC_PINCTL_IN_EN;
4385 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004386 } else {
4387 pinctl = snd_hda_codec_read(codec, nid, 0,
4388 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4389 /* if PINCTL already set then skip */
Takashi Iwai5dd17cb2009-05-07 16:22:53 +02004390 /* Also, if both INPUT and OUTPUT are set,
4391 * it must be a BIOS bug; need to override, too
4392 */
4393 if (!(pinctl & AC_PINCTL_IN_EN) ||
4394 (pinctl & AC_PINCTL_OUT_EN)) {
4395 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004396 pinctl |= AC_PINCTL_IN_EN;
4397 stac92xx_auto_set_pinctl(codec, nid,
4398 pinctl);
4399 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004400 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004401 conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004402 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004403 if (enable_pin_detect(codec, nid,
4404 STAC_INSERT_EVENT))
4405 stac_issue_unsol_event(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004406 }
Takashi Iwaic960a032006-03-23 17:06:28 +01004407 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004408 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004409 for (i = 0; i < spec->num_dmics; i++)
4410 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4411 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004412 if (cfg->dig_out_pins[0])
4413 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004414 AC_PINCTL_OUT_EN);
4415 if (cfg->dig_in_pin)
4416 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4417 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004418 for (i = 0; i < spec->num_pwrs; i++) {
4419 hda_nid_t nid = spec->pwr_nids[i];
4420 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004421
Takashi Iwaieb632122008-12-19 16:39:48 +01004422 /* power on when no jack detection is available */
4423 if (!spec->hp_detect) {
4424 stac_toggle_power_map(codec, nid, 1);
4425 continue;
4426 }
4427
4428 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004429 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004430
Takashi Iwaif73d3582008-11-25 08:21:51 +01004431 pinctl = snd_hda_codec_read(codec, nid, 0,
4432 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4433 /* outputs are only ports capable of power management
4434 * any attempts on powering down a input port cause the
4435 * referenced VREF to act quirky.
4436 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004437 if (pinctl & AC_PINCTL_IN_EN) {
4438 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004439 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004440 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004441 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004442 def_conf = get_defcfg_connect(def_conf);
4443 /* skip any ports that don't have jacks since presence
4444 * detection is useless */
4445 if (def_conf != AC_JACK_PORT_COMPLEX) {
4446 if (def_conf != AC_JACK_PORT_NONE)
4447 stac_toggle_power_map(codec, nid, 1);
4448 continue;
4449 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004450 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4451 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004452 }
4453 if (spec->dac_list)
4454 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004455 return 0;
4456}
4457
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004458static void stac92xx_free_jacks(struct hda_codec *codec)
4459{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004460#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01004461 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004462 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01004463 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004464 struct sigmatel_jack *jacks = spec->jacks.list;
4465 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +02004466 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4467 if (jacks->jack)
4468 snd_device_free(codec->bus->card, jacks->jack);
4469 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004470 }
4471 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004472#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004473}
4474
Takashi Iwai603c4012008-07-30 15:01:44 +02004475static void stac92xx_free_kctls(struct hda_codec *codec)
4476{
4477 struct sigmatel_spec *spec = codec->spec;
4478
4479 if (spec->kctls.list) {
4480 struct snd_kcontrol_new *kctl = spec->kctls.list;
4481 int i;
4482 for (i = 0; i < spec->kctls.used; i++)
4483 kfree(kctl[i].name);
4484 }
4485 snd_array_free(&spec->kctls);
4486}
4487
Matt2f2f4252005-04-13 14:45:30 +02004488static void stac92xx_free(struct hda_codec *codec)
4489{
Mattc7d4b2f2005-06-27 14:59:41 +02004490 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004491
4492 if (! spec)
4493 return;
4494
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004495 stac92xx_free_jacks(codec);
4496 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004497
Mattc7d4b2f2005-06-27 14:59:41 +02004498 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004499 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004500}
4501
Matt4e550962005-07-04 17:51:39 +02004502static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4503 unsigned int flag)
4504{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004505 unsigned int old_ctl, pin_ctl;
4506
4507 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004508 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004509
Takashi Iwaif9acba42007-05-29 18:01:06 +02004510 if (pin_ctl & AC_PINCTL_IN_EN) {
4511 /*
4512 * we need to check the current set-up direction of
4513 * shared input pins since they can be switched via
4514 * "xxx as Output" mixer switch
4515 */
4516 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004517 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004518 return;
4519 }
4520
Takashi Iwai8ce84192009-01-22 16:59:20 +01004521 old_ctl = pin_ctl;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004522 /* if setting pin direction bits, clear the current
4523 direction bits first */
4524 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4525 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4526
Takashi Iwai8ce84192009-01-22 16:59:20 +01004527 pin_ctl |= flag;
4528 if (old_ctl != pin_ctl)
4529 snd_hda_codec_write_cache(codec, nid, 0,
4530 AC_VERB_SET_PIN_WIDGET_CONTROL,
4531 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004532}
4533
4534static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4535 unsigned int flag)
4536{
4537 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4538 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004539 if (pin_ctl & flag)
4540 snd_hda_codec_write_cache(codec, nid, 0,
4541 AC_VERB_SET_PIN_WIDGET_CONTROL,
4542 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004543}
4544
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004545static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004546{
4547 if (!nid)
4548 return 0;
4549 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004550 & (1 << 31))
4551 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004552 return 0;
4553}
4554
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004555static void stac92xx_line_out_detect(struct hda_codec *codec,
4556 int presence)
4557{
4558 struct sigmatel_spec *spec = codec->spec;
4559 struct auto_pin_cfg *cfg = &spec->autocfg;
4560 int i;
4561
4562 for (i = 0; i < cfg->line_outs; i++) {
4563 if (presence)
4564 break;
4565 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4566 if (presence) {
4567 unsigned int pinctl;
4568 pinctl = snd_hda_codec_read(codec,
4569 cfg->line_out_pins[i], 0,
4570 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4571 if (pinctl & AC_PINCTL_IN_EN)
4572 presence = 0; /* mic- or line-input */
4573 }
4574 }
4575
4576 if (presence) {
4577 /* disable speakers */
4578 for (i = 0; i < cfg->speaker_outs; i++)
4579 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4580 AC_PINCTL_OUT_EN);
4581 if (spec->eapd_mask && spec->eapd_switch)
4582 stac_gpio_set(codec, spec->gpio_mask,
4583 spec->gpio_dir, spec->gpio_data &
4584 ~spec->eapd_mask);
4585 } else {
4586 /* enable speakers */
4587 for (i = 0; i < cfg->speaker_outs; i++)
4588 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4589 AC_PINCTL_OUT_EN);
4590 if (spec->eapd_mask && spec->eapd_switch)
4591 stac_gpio_set(codec, spec->gpio_mask,
4592 spec->gpio_dir, spec->gpio_data |
4593 spec->eapd_mask);
4594 }
4595}
4596
Takashi Iwaid7a89432008-11-12 09:48:04 +01004597/* return non-zero if the hp-pin of the given array index isn't
4598 * a jack-detection target
4599 */
4600static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4601{
4602 struct auto_pin_cfg *cfg = &spec->autocfg;
4603
4604 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004605 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004606 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004607 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004608 return 1;
4609 /* ignore if the pin is set as line-out */
4610 if (cfg->hp_pins[i] == spec->hp_switch)
4611 return 1;
4612 return 0;
4613}
4614
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004615static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004616{
4617 struct sigmatel_spec *spec = codec->spec;
4618 struct auto_pin_cfg *cfg = &spec->autocfg;
4619 int i, presence;
4620
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004621 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004622 if (spec->gpio_mute)
4623 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4624 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4625
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004626 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004627 if (presence)
4628 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004629 if (no_hp_sensing(spec, i))
4630 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004631 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4632 if (presence) {
4633 unsigned int pinctl;
4634 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4635 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4636 if (pinctl & AC_PINCTL_IN_EN)
4637 presence = 0; /* mic- or line-input */
4638 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004639 }
Matt4e550962005-07-04 17:51:39 +02004640
4641 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004642 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004643 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004644 stac92xx_reset_pinctl(codec, spec->hp_switch,
4645 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004646 for (i = 0; i < cfg->line_outs; i++)
4647 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4648 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004649 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004650 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004651 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004652 stac92xx_set_pinctl(codec, spec->hp_switch,
4653 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004654 for (i = 0; i < cfg->line_outs; i++)
4655 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4656 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004657 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004658 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004659 /* toggle hp outs */
4660 for (i = 0; i < cfg->hp_outs; i++) {
4661 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4662 if (no_hp_sensing(spec, i))
4663 continue;
4664 if (presence)
4665 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004666#if 0 /* FIXME */
4667/* Resetting the pinctl like below may lead to (a sort of) regressions
4668 * on some devices since they use the HP pin actually for line/speaker
4669 * outs although the default pin config shows a different pin (that is
4670 * wrong and useless).
4671 *
4672 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4673 * But, disabling the code below just works around it, and I'm too tired of
4674 * bug reports with such devices...
4675 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004676 else
4677 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004678#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004679 }
Matt4e550962005-07-04 17:51:39 +02004680}
4681
Takashi Iwaif73d3582008-11-25 08:21:51 +01004682static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4683 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004684{
4685 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004686 unsigned int idx, val;
4687
4688 for (idx = 0; idx < spec->num_pwrs; idx++) {
4689 if (spec->pwr_nids[idx] == nid)
4690 break;
4691 }
4692 if (idx >= spec->num_pwrs)
4693 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004694
4695 /* several codecs have two power down bits */
4696 if (spec->pwr_mapping)
4697 idx = spec->pwr_mapping[idx];
4698 else
4699 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004700
Takashi Iwaif73d3582008-11-25 08:21:51 +01004701 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4702 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004703 val &= ~idx;
4704 else
4705 val |= idx;
4706
4707 /* power down unused output ports */
4708 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004709}
4710
Takashi Iwaif73d3582008-11-25 08:21:51 +01004711static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4712{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004713 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004714}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004715
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004716static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4717{
4718 struct sigmatel_spec *spec = codec->spec;
4719 struct sigmatel_jack *jacks = spec->jacks.list;
4720
4721 if (jacks) {
4722 int i;
4723 for (i = 0; i < spec->jacks.used; i++) {
4724 if (jacks->nid == nid) {
4725 unsigned int pin_ctl =
4726 snd_hda_codec_read(codec, nid,
4727 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4728 0x00);
4729 int type = jacks->type;
4730 if (type == (SND_JACK_LINEOUT
4731 | SND_JACK_HEADPHONE))
4732 type = (pin_ctl & AC_PINCTL_HP_EN)
4733 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4734 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004735 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004736 ? type : 0);
4737 }
4738 jacks++;
4739 }
4740 }
4741}
Matt2f2f4252005-04-13 14:45:30 +02004742
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004743static void stac92xx_mic_detect(struct hda_codec *codec)
4744{
4745 struct sigmatel_spec *spec = codec->spec;
4746 struct sigmatel_mic_route *mic;
4747
4748 if (get_pin_presence(codec, spec->ext_mic.pin))
4749 mic = &spec->ext_mic;
4750 else
4751 mic = &spec->int_mic;
4752 if (mic->dmux_idx)
4753 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4754 AC_VERB_SET_CONNECT_SEL,
4755 mic->dmux_idx);
4756 else
4757 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4758 AC_VERB_SET_CONNECT_SEL,
4759 mic->mux_idx);
4760}
4761
Takashi Iwai62558ce2009-07-29 14:23:09 +02004762static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004763{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004764 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004765 if (!event)
4766 return;
4767 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4768}
4769
Takashi Iwai314634b2006-09-21 11:56:18 +02004770static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4771{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004772 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004773 struct sigmatel_event *event;
4774 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004775
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004776 tag = (res >> 26) & 0x7f;
4777 event = stac_get_event_from_tag(codec, tag);
4778 if (!event)
4779 return;
4780
4781 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004782 case STAC_HP_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004783 stac92xx_hp_detect(codec);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004784 break;
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004785 case STAC_LO_EVENT:
4786 stac92xx_line_out_detect(codec, 0);
4787 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004788 case STAC_MIC_EVENT:
4789 stac92xx_mic_detect(codec);
4790 break;
4791 }
4792
4793 switch (event->type) {
4794 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004795 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004796 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004797 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004798 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004799 if (spec->num_pwrs > 0)
4800 stac92xx_pin_sense(codec, event->nid);
4801 stac92xx_report_jack(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004802
4803 switch (codec->subsystem_id) {
4804 case 0x103c308f:
4805 if (event->nid == 0xb) {
4806 int pin = AC_PINCTL_IN_EN;
4807
4808 if (get_pin_presence(codec, 0xa)
4809 && get_pin_presence(codec, 0xb))
4810 pin |= AC_PINCTL_VREF_80;
4811 if (!get_pin_presence(codec, 0xb))
4812 pin |= AC_PINCTL_VREF_80;
4813
4814 /* toggle VREF state based on mic + hp pin
4815 * status
4816 */
4817 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4818 }
4819 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004820 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004821 case STAC_VREF_EVENT:
4822 data = snd_hda_codec_read(codec, codec->afg, 0,
4823 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004824 /* toggle VREF state based on GPIOx status */
4825 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004826 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004827 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004828 }
4829}
4830
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004831#ifdef CONFIG_PROC_FS
4832static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4833 struct hda_codec *codec, hda_nid_t nid)
4834{
4835 if (nid == codec->afg)
4836 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4837 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4838}
4839
4840static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4841 struct hda_codec *codec,
4842 unsigned int verb)
4843{
4844 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4845 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4846}
4847
4848/* stac92hd71bxx, stac92hd73xx */
4849static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4850 struct hda_codec *codec, hda_nid_t nid)
4851{
4852 stac92hd_proc_hook(buffer, codec, nid);
4853 if (nid == codec->afg)
4854 analog_loop_proc_hook(buffer, codec, 0xfa0);
4855}
4856
4857static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4858 struct hda_codec *codec, hda_nid_t nid)
4859{
4860 if (nid == codec->afg)
4861 analog_loop_proc_hook(buffer, codec, 0xfe0);
4862}
4863
4864static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4865 struct hda_codec *codec, hda_nid_t nid)
4866{
4867 if (nid == codec->afg)
4868 analog_loop_proc_hook(buffer, codec, 0xfeb);
4869}
4870#else
4871#define stac92hd_proc_hook NULL
4872#define stac92hd7x_proc_hook NULL
4873#define stac9205_proc_hook NULL
4874#define stac927x_proc_hook NULL
4875#endif
4876
Takashi Iwaicb53c622007-08-10 17:21:45 +02004877#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004878static int stac92xx_resume(struct hda_codec *codec)
4879{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004880 struct sigmatel_spec *spec = codec->spec;
4881
Takashi Iwai2c885872008-11-18 09:36:55 +01004882 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004883 snd_hda_codec_resume_amp(codec);
4884 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004885 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004886 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02004887 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
Mattff6fdc32005-06-27 15:06:52 +02004888 return 0;
4889}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004890
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004891/*
James Gardiner514bf542009-05-03 04:00:44 -04004892 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004893 * check for mute state only on Speakers (nid = 0x10)
4894 *
4895 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4896 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004897 *
4898 * Changed name to reflect that it now works for any designated
4899 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004900 */
4901
4902#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004903static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004904 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004905{
4906 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004907
4908 if (nid == 0x10) {
4909 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004910 HDA_AMP_MUTE)
Takashi Iwai86d190e2009-05-26 15:18:58 +02004911 spec->gpio_data &= ~spec->gpio_led; /* orange */
Takashi Iwaiba84bfc2009-05-30 08:59:03 +02004912 else
4913 spec->gpio_data |= spec->gpio_led; /* white */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004914
4915 stac_gpio_set(codec, spec->gpio_mask,
4916 spec->gpio_dir,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004917 spec->gpio_data);
4918 }
4919
4920 return 0;
4921}
4922#endif
4923
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004924static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4925{
4926 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004927 int i;
4928 hda_nid_t nid;
4929
4930 /* reset each pin before powering down DAC/ADC to avoid click noise */
4931 nid = codec->start_nid;
4932 for (i = 0; i < codec->num_nodes; i++, nid++) {
4933 unsigned int wcaps = get_wcaps(codec, nid);
Takashi Iwaia22d5432009-07-27 12:54:26 +02004934 unsigned int wid_type = get_wcaps_type(wcaps);
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004935 if (wid_type == AC_WID_PIN)
4936 snd_hda_codec_read(codec, nid, 0,
4937 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4938 }
4939
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004940 if (spec->eapd_mask)
4941 stac_gpio_set(codec, spec->gpio_mask,
4942 spec->gpio_dir, spec->gpio_data &
4943 ~spec->eapd_mask);
4944 return 0;
4945}
Mattff6fdc32005-06-27 15:06:52 +02004946#endif
4947
Matt2f2f4252005-04-13 14:45:30 +02004948static struct hda_codec_ops stac92xx_patch_ops = {
4949 .build_controls = stac92xx_build_controls,
4950 .build_pcms = stac92xx_build_pcms,
4951 .init = stac92xx_init,
4952 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004953 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004954#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004955 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004956 .resume = stac92xx_resume,
4957#endif
Matt2f2f4252005-04-13 14:45:30 +02004958};
4959
4960static int patch_stac9200(struct hda_codec *codec)
4961{
4962 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004963 int err;
Matt2f2f4252005-04-13 14:45:30 +02004964
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004965 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004966 if (spec == NULL)
4967 return -ENOMEM;
4968
4969 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004970 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004971 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004972 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4973 stac9200_models,
4974 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01004975 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004976 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4977 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004978 else
4979 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004980 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02004981
4982 spec->multiout.max_channels = 2;
4983 spec->multiout.num_dacs = 1;
4984 spec->multiout.dac_nids = stac9200_dac_nids;
4985 spec->adc_nids = stac9200_adc_nids;
4986 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004987 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004988 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004989 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004990 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004991
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02004992 if (spec->board_config == STAC_9200_M4 ||
4993 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01004994 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004995 spec->init = stac9200_eapd_init;
4996 else
4997 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004998 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004999
Takashi Iwai117f2572008-03-18 09:53:23 +01005000 if (spec->board_config == STAC_9200_PANASONIC) {
5001 spec->gpio_mask = spec->gpio_dir = 0x09;
5002 spec->gpio_data = 0x00;
5003 }
5004
Mattc7d4b2f2005-06-27 14:59:41 +02005005 err = stac9200_parse_auto_config(codec);
5006 if (err < 0) {
5007 stac92xx_free(codec);
5008 return err;
5009 }
Matt2f2f4252005-04-13 14:45:30 +02005010
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005011 /* CF-74 has no headphone detection, and the driver should *NOT*
5012 * do detection and HP/speaker toggle because the hardware does it.
5013 */
5014 if (spec->board_config == STAC_9200_PANASONIC)
5015 spec->hp_detect = 0;
5016
Matt2f2f4252005-04-13 14:45:30 +02005017 codec->patch_ops = stac92xx_patch_ops;
5018
5019 return 0;
5020}
5021
Tobin Davis8e21c342007-01-08 11:04:17 +01005022static int patch_stac925x(struct hda_codec *codec)
5023{
5024 struct sigmatel_spec *spec;
5025 int err;
5026
5027 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5028 if (spec == NULL)
5029 return -ENOMEM;
5030
5031 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005032 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005033 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005034
5035 /* Check first for codec ID */
5036 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5037 STAC_925x_MODELS,
5038 stac925x_models,
5039 stac925x_codec_id_cfg_tbl);
5040
5041 /* Now checks for PCI ID, if codec ID is not found */
5042 if (spec->board_config < 0)
5043 spec->board_config = snd_hda_check_board_config(codec,
5044 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005045 stac925x_models,
5046 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005047 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005048 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005049 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5050 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005051 else
5052 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005053 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005054
5055 spec->multiout.max_channels = 2;
5056 spec->multiout.num_dacs = 1;
5057 spec->multiout.dac_nids = stac925x_dac_nids;
5058 spec->adc_nids = stac925x_adc_nids;
5059 spec->mux_nids = stac925x_mux_nids;
5060 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005061 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005062 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005063 switch (codec->vendor_id) {
5064 case 0x83847632: /* STAC9202 */
5065 case 0x83847633: /* STAC9202D */
5066 case 0x83847636: /* STAC9251 */
5067 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005068 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005069 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005070 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5071 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005072 break;
5073 default:
5074 spec->num_dmics = 0;
5075 break;
5076 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005077
5078 spec->init = stac925x_core_init;
5079 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005080 spec->num_caps = 1;
5081 spec->capvols = stac925x_capvols;
5082 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005083
5084 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005085 if (!err) {
5086 if (spec->board_config < 0) {
5087 printk(KERN_WARNING "hda_codec: No auto-config is "
5088 "available, default to model=ref\n");
5089 spec->board_config = STAC_925x_REF;
5090 goto again;
5091 }
5092 err = -EINVAL;
5093 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005094 if (err < 0) {
5095 stac92xx_free(codec);
5096 return err;
5097 }
5098
5099 codec->patch_ops = stac92xx_patch_ops;
5100
5101 return 0;
5102}
5103
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005104static struct hda_input_mux stac92hd73xx_dmux = {
5105 .num_items = 4,
5106 .items = {
5107 { "Analog Inputs", 0x0b },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005108 { "Digital Mic 1", 0x09 },
5109 { "Digital Mic 2", 0x0a },
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005110 { "CD", 0x08 },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005111 }
5112};
5113
5114static int patch_stac92hd73xx(struct hda_codec *codec)
5115{
5116 struct sigmatel_spec *spec;
5117 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5118 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005119 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005120
5121 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5122 if (spec == NULL)
5123 return -ENOMEM;
5124
5125 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005126 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005127 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5128 spec->pin_nids = stac92hd73xx_pin_nids;
5129 spec->board_config = snd_hda_check_board_config(codec,
5130 STAC_92HD73XX_MODELS,
5131 stac92hd73xx_models,
5132 stac92hd73xx_cfg_tbl);
5133again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005134 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005135 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5136 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005137 else
5138 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005139 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005140
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005141 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005142 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5143
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005144 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005145 printk(KERN_WARNING "hda_codec: Could not determine "
5146 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005147 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005148 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005149 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005150 case 0x3: /* 6 Channel */
5151 spec->mixer = stac92hd73xx_6ch_mixer;
5152 spec->init = stac92hd73xx_6ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005153 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005154 break;
5155 case 0x4: /* 8 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005156 spec->mixer = stac92hd73xx_8ch_mixer;
5157 spec->init = stac92hd73xx_8ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005158 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005159 break;
5160 case 0x5: /* 10 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005161 spec->mixer = stac92hd73xx_10ch_mixer;
5162 spec->init = stac92hd73xx_10ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005163 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5164 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005165 }
5166 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005167
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005168 spec->aloopback_mask = 0x01;
5169 spec->aloopback_shift = 8;
5170
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005171 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005172 spec->mux_nids = stac92hd73xx_mux_nids;
5173 spec->adc_nids = stac92hd73xx_adc_nids;
5174 spec->dmic_nids = stac92hd73xx_dmic_nids;
5175 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005176 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04005177 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005178 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005179
5180 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5181 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005182 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005183 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
5184 sizeof(stac92hd73xx_dmux));
5185
Takashi Iwai6479c632009-07-28 18:20:25 +02005186 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5187 spec->capvols = stac92hd73xx_capvols;
5188 spec->capsws = stac92hd73xx_capsws;
5189
Matthew Ranostaya7662642008-02-21 07:51:14 +01005190 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005191 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005192 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005193 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005194 case STAC_DELL_M6_AMIC:
5195 case STAC_DELL_M6_DMIC:
5196 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005197 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005198 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
5199 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005200 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005201 spec->num_amps = 1;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005202
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005203 if (spec->board_config != STAC_DELL_EQ)
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005204 spec->init = dell_m6_core_init;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005205 switch (spec->board_config) {
5206 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005207 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005208 spec->num_dmics = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005209 spec->private_dimux.num_items = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005210 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005211 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005212 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005213 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005214 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005215 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005216 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005217 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5218 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005219 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005220 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005221 break;
5222 }
5223 break;
5224 default:
5225 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005226 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005227 spec->eapd_switch = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005228 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005229 if (spec->board_config > STAC_92HD73XX_REF) {
5230 /* GPIO0 High = Enable EAPD */
5231 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5232 spec->gpio_data = 0x01;
5233 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005234 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005235
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005236 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5237 spec->pwr_nids = stac92hd73xx_pwr_nids;
5238
Matthew Ranostayd9737752008-09-07 12:03:41 +02005239 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005240
5241 if (!err) {
5242 if (spec->board_config < 0) {
5243 printk(KERN_WARNING "hda_codec: No auto-config is "
5244 "available, default to model=ref\n");
5245 spec->board_config = STAC_92HD73XX_REF;
5246 goto again;
5247 }
5248 err = -EINVAL;
5249 }
5250
5251 if (err < 0) {
5252 stac92xx_free(codec);
5253 return err;
5254 }
5255
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005256 if (spec->board_config == STAC_92HD73XX_NO_JD)
5257 spec->hp_detect = 0;
5258
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005259 codec->patch_ops = stac92xx_patch_ops;
5260
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005261 codec->proc_widget_hook = stac92hd7x_proc_hook;
5262
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005263 return 0;
5264}
5265
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005266static struct hda_input_mux stac92hd83xxx_dmux = {
5267 .num_items = 3,
5268 .items = {
5269 { "Analog Inputs", 0x03 },
5270 { "Digital Mic 1", 0x04 },
5271 { "Digital Mic 2", 0x05 },
5272 }
5273};
5274
5275static int patch_stac92hd83xxx(struct hda_codec *codec)
5276{
5277 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005278 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005279 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005280 int num_dacs;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005281 hda_nid_t nid;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005282
5283 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5284 if (spec == NULL)
5285 return -ENOMEM;
5286
5287 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005288 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005289 spec->mono_nid = 0x19;
5290 spec->digbeep_nid = 0x21;
5291 spec->dmic_nids = stac92hd83xxx_dmic_nids;
5292 spec->dmux_nids = stac92hd83xxx_dmux_nids;
5293 spec->adc_nids = stac92hd83xxx_adc_nids;
5294 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayc15c5062009-01-13 13:30:07 -05005295 spec->amp_nids = stac92hd83xxx_amp_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005296 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5297 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005298 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005299
5300 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005301 spec->mixer = stac92hd83xxx_mixer;
5302 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
5303 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
5304 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayc15c5062009-01-13 13:30:07 -05005305 spec->num_amps = ARRAY_SIZE(stac92hd83xxx_amp_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005306 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
5307 spec->dinput_mux = &stac92hd83xxx_dmux;
5308 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005309 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5310 spec->capvols = stac92hd83xxx_capvols;
5311 spec->capsws = stac92hd83xxx_capsws;
5312
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005313 spec->board_config = snd_hda_check_board_config(codec,
5314 STAC_92HD83XXX_MODELS,
5315 stac92hd83xxx_models,
5316 stac92hd83xxx_cfg_tbl);
5317again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005318 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005319 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5320 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005321 else
5322 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005323 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005324
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005325 switch (codec->vendor_id) {
5326 case 0x111d7604:
5327 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005328 case 0x111d76d5:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005329 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5330 break;
5331 spec->num_pwrs = 0;
5332 break;
5333 }
5334
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005335 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5336 if (!err) {
5337 if (spec->board_config < 0) {
5338 printk(KERN_WARNING "hda_codec: No auto-config is "
5339 "available, default to model=ref\n");
5340 spec->board_config = STAC_92HD83XXX_REF;
5341 goto again;
5342 }
5343 err = -EINVAL;
5344 }
5345
5346 if (err < 0) {
5347 stac92xx_free(codec);
5348 return err;
5349 }
5350
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005351 switch (spec->board_config) {
5352 case STAC_DELL_S14:
5353 nid = 0xf;
5354 break;
5355 default:
5356 nid = 0xe;
5357 break;
5358 }
5359
5360 num_dacs = snd_hda_get_connections(codec, nid,
5361 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02005362 if (num_dacs < 0)
5363 num_dacs = STAC92HD83_DAC_COUNT;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005364
5365 /* set port X to select the last DAC
5366 */
5367 snd_hda_codec_write_cache(codec, nid, 0,
5368 AC_VERB_SET_CONNECT_SEL, num_dacs);
5369
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005370 codec->patch_ops = stac92xx_patch_ops;
5371
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005372 codec->proc_widget_hook = stac92hd_proc_hook;
5373
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005374 return 0;
5375}
5376
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005377static struct hda_input_mux stac92hd71bxx_dmux_nomixer = {
5378 .num_items = 3,
5379 .items = {
5380 { "Analog Inputs", 0x00 },
5381 { "Digital Mic 1", 0x02 },
5382 { "Digital Mic 2", 0x03 },
5383 }
5384};
5385
5386static struct hda_input_mux stac92hd71bxx_dmux_amixer = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005387 .num_items = 4,
5388 .items = {
5389 { "Analog Inputs", 0x00 },
5390 { "Mixer", 0x01 },
5391 { "Digital Mic 1", 0x02 },
5392 { "Digital Mic 2", 0x03 },
5393 }
5394};
5395
Takashi Iwai330ee992009-02-20 14:33:36 +01005396/* get the pin connection (fixed, none, etc) */
5397static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5398{
5399 struct sigmatel_spec *spec = codec->spec;
5400 unsigned int cfg;
5401
5402 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5403 return get_defcfg_connect(cfg);
5404}
5405
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005406static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5407 hda_nid_t *nids, int num_nids)
5408{
5409 struct sigmatel_spec *spec = codec->spec;
5410 int idx, num;
5411 unsigned int def_conf;
5412
5413 for (num = 0; num < num_nids; num++) {
5414 for (idx = 0; idx < spec->num_pins; idx++)
5415 if (spec->pin_nids[idx] == nids[num])
5416 break;
5417 if (idx >= spec->num_pins)
5418 break;
Takashi Iwai330ee992009-02-20 14:33:36 +01005419 def_conf = stac_get_defcfg_connect(codec, idx);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005420 if (def_conf == AC_JACK_PORT_NONE)
5421 break;
5422 }
5423 return num;
5424}
5425
5426static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5427 hda_nid_t dig0pin)
5428{
5429 struct sigmatel_spec *spec = codec->spec;
5430 int idx;
5431
5432 for (idx = 0; idx < spec->num_pins; idx++)
5433 if (spec->pin_nids[idx] == dig0pin)
5434 break;
5435 if ((idx + 2) >= spec->num_pins)
5436 return 0;
5437
5438 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005439 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005440 return 2;
5441
5442 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005443 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005444 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005445 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005446 return 1;
5447 else
5448 return 0;
5449}
5450
Matthew Ranostaye035b842007-11-06 11:53:55 +01005451static int patch_stac92hd71bxx(struct hda_codec *codec)
5452{
5453 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005454 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005455 int err = 0;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005456 unsigned int ndmic_nids = 0;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005457
5458 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5459 if (spec == NULL)
5460 return -ENOMEM;
5461
5462 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005463 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005464 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5465 switch (codec->vendor_id) {
5466 case 0x111d76b6:
5467 case 0x111d76b7:
5468 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5469 break;
5470 case 0x111d7603:
5471 case 0x111d7608:
5472 /* On 92HD75Bx 0x27 isn't a pin nid */
5473 spec->num_pins--;
5474 /* fallthrough */
5475 default:
5476 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5477 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005478 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005479 spec->board_config = snd_hda_check_board_config(codec,
5480 STAC_92HD71BXX_MODELS,
5481 stac92hd71bxx_models,
5482 stac92hd71bxx_cfg_tbl);
5483again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005484 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005485 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5486 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005487 else
5488 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005489 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005490
Takashi Iwai41c3b642008-11-18 10:45:15 +01005491 if (spec->board_config > STAC_92HD71BXX_REF) {
5492 /* GPIO0 = EAPD */
5493 spec->gpio_mask = 0x01;
5494 spec->gpio_dir = 0x01;
5495 spec->gpio_data = 0x01;
5496 }
5497
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005498 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5499 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5500
Takashi Iwai6479c632009-07-28 18:20:25 +02005501 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5502 spec->capvols = stac92hd71bxx_capvols;
5503 spec->capsws = stac92hd71bxx_capsws;
5504
Matthew Ranostay541eee82007-12-14 12:08:04 +01005505 switch (codec->vendor_id) {
5506 case 0x111d76b6: /* 4 Port without Analog Mixer */
5507 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005508 unmute_init++;
5509 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005510 case 0x111d76b4: /* 6 Port without Analog Mixer */
5511 case 0x111d76b5:
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005512 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_nomixer,
5513 sizeof(stac92hd71bxx_dmux_nomixer));
Matthew Ranostay541eee82007-12-14 12:08:04 +01005514 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005515 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005516 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5517 stac92hd71bxx_dmic_nids,
5518 STAC92HD71BXX_NUM_DMICS);
5519 if (spec->num_dmics) {
5520 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5521 spec->dinput_mux = &spec->private_dimux;
5522 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5523 }
Matthew Ranostay541eee82007-12-14 12:08:04 +01005524 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005525 case 0x111d7608: /* 5 Port with Analog Mixer */
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005526 spec->private_dimux.num_items--;
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005527 switch (spec->board_config) {
5528 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005529 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005530 err = stac_add_event(spec, codec->afg,
5531 STAC_VREF_EVENT, 0x02);
5532 if (err < 0)
5533 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005534 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005535 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5536 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005537 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005538 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005539 spec->gpio_mask |= 0x02;
5540 break;
5541 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005542 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005543 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005544 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005545
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005546 /* no output amps */
5547 spec->num_pwrs = 0;
Takashi Iwai71443b02009-07-29 18:41:29 +02005548 if (snd_hda_get_bool_hint(codec, "analog_mixer") == 1) {
Takashi Iwai50c62f02009-07-28 18:25:29 +02005549 spec->mixer = stac92hd71bxx_analog_mixer;
Takashi Iwai71443b02009-07-29 18:41:29 +02005550 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5551 sizeof(stac92hd71bxx_dmux_amixer));
5552 } else {
5553 memcpy(&spec->private_dimux,
5554 &stac92hd71bxx_dmux_nomixer,
5555 sizeof(stac92hd71bxx_dmux_nomixer));
5556 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005557 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005558 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005559 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005560 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5561 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005562 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5563 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5564 stac92hd71bxx_dmic_nids,
5565 STAC92HD71BXX_NUM_DMICS - 1);
Takashi Iwai44179322009-07-28 17:03:49 +02005566 if (spec->num_dmics) {
5567 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5568 spec->dinput_mux = &spec->private_dimux;
5569 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 2;
5570 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005571 break;
5572 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005573 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005574 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005575
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005576 /* no output amps */
5577 spec->num_pwrs = 0;
5578 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005579 default:
Takashi Iwai71443b02009-07-29 18:41:29 +02005580 if (snd_hda_get_bool_hint(codec, "analog_mixer") == 1) {
Takashi Iwai50c62f02009-07-28 18:25:29 +02005581 spec->mixer = stac92hd71bxx_analog_mixer;
Takashi Iwai71443b02009-07-29 18:41:29 +02005582 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5583 sizeof(stac92hd71bxx_dmux_amixer));
5584 } else {
5585 memcpy(&spec->private_dimux,
5586 &stac92hd71bxx_dmux_nomixer,
5587 sizeof(stac92hd71bxx_dmux_nomixer));
5588 }
Takashi Iwai26a27982009-07-29 16:28:09 +02005589 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005590 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005591 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5592 stac92hd71bxx_dmic_nids,
5593 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai44179322009-07-28 17:03:49 +02005594 if (spec->num_dmics) {
5595 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5596 spec->dinput_mux = &spec->private_dimux;
5597 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5598 }
Matthew Ranostay541eee82007-12-14 12:08:04 +01005599 }
5600
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005601 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5602 snd_hda_sequence_write_cache(codec, unmute_init);
5603
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005604 /* Some HP machines seem to have unstable codec communications
5605 * especially with ATI fglrx driver. For recovering from the
5606 * CORB/RIRB stall, allow the BUS reset and keep always sync
5607 */
5608 if (spec->board_config == STAC_HP_DV5) {
5609 codec->bus->sync_write = 1;
5610 codec->bus->allow_bus_reset = 1;
5611 }
5612
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005613 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005614 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005615 spec->aloopback_shift = 0;
5616
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005617 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005618 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005619 spec->mux_nids = stac92hd71bxx_mux_nids;
5620 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005621 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005622 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005623
5624 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5625 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005626 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005627
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005628 switch (spec->board_config) {
5629 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005630 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005631 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005632 stac92xx_auto_set_pinctl(codec, 0x0e,
5633 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005634 /* fallthru */
5635 case STAC_DELL_M4_2:
5636 spec->num_dmics = 0;
5637 spec->num_smuxes = 0;
5638 spec->num_dmuxes = 0;
5639 break;
5640 case STAC_DELL_M4_1:
5641 case STAC_DELL_M4_3:
5642 spec->num_dmics = 1;
5643 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005644 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005645 break;
James Gardiner514bf542009-05-03 04:00:44 -04005646 case STAC_HP_DV4_1222NR:
5647 spec->num_dmics = 1;
5648 /* I don't know if it needs 1 or 2 smuxes - will wait for
5649 * bug reports to fix if needed
5650 */
5651 spec->num_smuxes = 1;
5652 spec->num_dmuxes = 1;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005653 spec->gpio_led = 0x01;
James Gardiner514bf542009-05-03 04:00:44 -04005654 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005655 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005656 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005657 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5658 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005659 case STAC_HP_HDX:
5660 spec->num_dmics = 1;
5661 spec->num_dmuxes = 1;
5662 spec->num_smuxes = 1;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005663 /* orange/white mute led on GPIO3, orange=0, white=1 */
Takashi Iwai86d190e2009-05-26 15:18:58 +02005664 spec->gpio_led = 0x08;
5665 break;
5666 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005667
Takashi Iwai86d190e2009-05-26 15:18:58 +02005668#ifdef CONFIG_SND_HDA_POWER_SAVE
5669 if (spec->gpio_led) {
5670 spec->gpio_mask |= spec->gpio_led;
5671 spec->gpio_dir |= spec->gpio_led;
5672 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005673 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005674 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005675 stac92xx_hp_check_power_status;
5676 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005677#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005678
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005679 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005680 if (spec->dinput_mux)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005681 spec->private_dimux.num_items += spec->num_dmics - ndmic_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005682
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005683 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005684 if (!err) {
5685 if (spec->board_config < 0) {
5686 printk(KERN_WARNING "hda_codec: No auto-config is "
5687 "available, default to model=ref\n");
5688 spec->board_config = STAC_92HD71BXX_REF;
5689 goto again;
5690 }
5691 err = -EINVAL;
5692 }
5693
5694 if (err < 0) {
5695 stac92xx_free(codec);
5696 return err;
5697 }
5698
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005699 codec->proc_widget_hook = stac92hd7x_proc_hook;
5700
Matthew Ranostaye035b842007-11-06 11:53:55 +01005701 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005702}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005703
Matt2f2f4252005-04-13 14:45:30 +02005704static int patch_stac922x(struct hda_codec *codec)
5705{
5706 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005707 int err;
Matt2f2f4252005-04-13 14:45:30 +02005708
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005709 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005710 if (spec == NULL)
5711 return -ENOMEM;
5712
5713 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005714 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005715 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005716 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5717 stac922x_models,
5718 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005719 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005720 spec->gpio_mask = spec->gpio_dir = 0x03;
5721 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005722 /* Intel Macs have all same PCI SSID, so we need to check
5723 * codec SSID to distinguish the exact models
5724 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005725 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005726 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005727
5728 case 0x106b0800:
5729 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005730 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005731 case 0x106b0600:
5732 case 0x106b0700:
5733 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005734 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005735 case 0x106b0e00:
5736 case 0x106b0f00:
5737 case 0x106b1600:
5738 case 0x106b1700:
5739 case 0x106b0200:
5740 case 0x106b1e00:
5741 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005742 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005743 case 0x106b1a00:
5744 case 0x00000100:
5745 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005746 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005747 case 0x106b0a00:
5748 case 0x106b2200:
5749 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005750 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005751 default:
5752 spec->board_config = STAC_INTEL_MAC_V3;
5753 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005754 }
5755 }
5756
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005757 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005758 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005759 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5760 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005761 else
5762 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005763 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005764
Matt2f2f4252005-04-13 14:45:30 +02005765 spec->adc_nids = stac922x_adc_nids;
5766 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005767 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005768 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005769 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005770 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005771
5772 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005773
5774 spec->num_caps = STAC922X_NUM_CAPS;
5775 spec->capvols = stac922x_capvols;
5776 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005777
5778 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005779
Matt Porter3cc08dc2006-01-23 15:27:49 +01005780 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005781 if (!err) {
5782 if (spec->board_config < 0) {
5783 printk(KERN_WARNING "hda_codec: No auto-config is "
5784 "available, default to model=ref\n");
5785 spec->board_config = STAC_D945_REF;
5786 goto again;
5787 }
5788 err = -EINVAL;
5789 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005790 if (err < 0) {
5791 stac92xx_free(codec);
5792 return err;
5793 }
5794
5795 codec->patch_ops = stac92xx_patch_ops;
5796
Takashi Iwai807a46362007-05-29 19:01:37 +02005797 /* Fix Mux capture level; max to 2 */
5798 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5799 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5800 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5801 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5802 (0 << AC_AMPCAP_MUTE_SHIFT));
5803
Matt Porter3cc08dc2006-01-23 15:27:49 +01005804 return 0;
5805}
5806
5807static int patch_stac927x(struct hda_codec *codec)
5808{
5809 struct sigmatel_spec *spec;
5810 int err;
5811
5812 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5813 if (spec == NULL)
5814 return -ENOMEM;
5815
5816 codec->spec = spec;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005817 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005818 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005819 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005820 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5821 stac927x_models,
5822 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005823 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005824 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005825 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5826 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005827 else
5828 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005829 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005830
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005831 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005832 spec->adc_nids = stac927x_adc_nids;
5833 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5834 spec->mux_nids = stac927x_mux_nids;
5835 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005836 spec->smux_nids = stac927x_smux_nids;
5837 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005838 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005839 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005840 spec->multiout.dac_nids = spec->dac_nids;
5841
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005842 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005843 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005844 case STAC_D965_5ST:
5845 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005846 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005847 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005848 spec->num_dmics = 0;
5849
Tobin Davis93ed1502006-09-01 21:03:12 +02005850 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005851 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005852 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005853 switch (codec->subsystem_id) {
5854 case 0x10280209:
5855 case 0x1028022e:
5856 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005857 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005858 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005859 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005860 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005861 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005862 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005863 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005864 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005865 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005866 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005867 case STAC_DELL_3ST:
5868 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005869 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005870 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005871 spec->dmic_nids = stac927x_dmic_nids;
5872 spec->num_dmics = STAC927X_NUM_DMICS;
5873
Tobin Davis93ed1502006-09-01 21:03:12 +02005874 spec->init = d965_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005875 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005876 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005877 break;
5878 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005879 if (spec->board_config > STAC_D965_REF) {
5880 /* GPIO0 High = Enable EAPD */
5881 spec->eapd_mask = spec->gpio_mask = 0x01;
5882 spec->gpio_dir = spec->gpio_data = 0x01;
5883 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005884 spec->num_dmics = 0;
5885
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005886 spec->init = stac927x_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005887 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005888
Takashi Iwai6479c632009-07-28 18:20:25 +02005889 spec->num_caps = STAC927X_NUM_CAPS;
5890 spec->capvols = stac927x_capvols;
5891 spec->capsws = stac927x_capsws;
5892
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005893 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005894 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005895 spec->aloopback_mask = 0x40;
5896 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005897 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005898
Matt Porter3cc08dc2006-01-23 15:27:49 +01005899 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005900 if (!err) {
5901 if (spec->board_config < 0) {
5902 printk(KERN_WARNING "hda_codec: No auto-config is "
5903 "available, default to model=ref\n");
5904 spec->board_config = STAC_D965_REF;
5905 goto again;
5906 }
5907 err = -EINVAL;
5908 }
Mattc7d4b2f2005-06-27 14:59:41 +02005909 if (err < 0) {
5910 stac92xx_free(codec);
5911 return err;
5912 }
Matt2f2f4252005-04-13 14:45:30 +02005913
5914 codec->patch_ops = stac92xx_patch_ops;
5915
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005916 codec->proc_widget_hook = stac927x_proc_hook;
5917
Takashi Iwai52987652008-01-16 16:09:47 +01005918 /*
5919 * !!FIXME!!
5920 * The STAC927x seem to require fairly long delays for certain
5921 * command sequences. With too short delays (even if the answer
5922 * is set to RIRB properly), it results in the silence output
5923 * on some hardwares like Dell.
5924 *
5925 * The below flag enables the longer delay (see get_response
5926 * in hda_intel.c).
5927 */
5928 codec->bus->needs_damn_long_delay = 1;
5929
Takashi Iwaie28d8322008-12-17 13:48:29 +01005930 /* no jack detecion for ref-no-jd model */
5931 if (spec->board_config == STAC_D965_REF_NO_JD)
5932 spec->hp_detect = 0;
5933
Matt2f2f4252005-04-13 14:45:30 +02005934 return 0;
5935}
5936
Matt Porterf3302a52006-07-31 12:49:34 +02005937static int patch_stac9205(struct hda_codec *codec)
5938{
5939 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005940 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005941
5942 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5943 if (spec == NULL)
5944 return -ENOMEM;
5945
5946 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005947 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005948 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005949 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5950 stac9205_models,
5951 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005952 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005953 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005954 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5955 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005956 else
5957 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005958 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02005959
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005960 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005961 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005962 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005963 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005964 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005965 spec->smux_nids = stac9205_smux_nids;
5966 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005967 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005968 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005969 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005970 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005971 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005972
5973 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005974 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02005975
Takashi Iwai6479c632009-07-28 18:20:25 +02005976 spec->num_caps = STAC9205_NUM_CAPS;
5977 spec->capvols = stac9205_capvols;
5978 spec->capsws = stac9205_capsws;
5979
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005980 spec->aloopback_mask = 0x40;
5981 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01005982 /* Turn on/off EAPD per HP plugging */
5983 if (spec->board_config != STAC_9205_EAPD)
5984 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005985 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005986
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005987 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005988 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005989 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005990 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5991 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005992
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005993 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005994 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5995 if (err < 0)
5996 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005997 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005998 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5999 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006000 AC_VERB_SET_UNSOLICITED_ENABLE,
6001 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006002
6003 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006004 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006005 spec->gpio_mask = 0x1b;
6006 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006007 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006008 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006009 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006010 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006011 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006012 case STAC_9205_REF:
6013 /* SPDIF-In enabled */
6014 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006015 default:
6016 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006017 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006018 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006019 break;
6020 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006021
Matt Porterf3302a52006-07-31 12:49:34 +02006022 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006023 if (!err) {
6024 if (spec->board_config < 0) {
6025 printk(KERN_WARNING "hda_codec: No auto-config is "
6026 "available, default to model=ref\n");
6027 spec->board_config = STAC_9205_REF;
6028 goto again;
6029 }
6030 err = -EINVAL;
6031 }
Matt Porterf3302a52006-07-31 12:49:34 +02006032 if (err < 0) {
6033 stac92xx_free(codec);
6034 return err;
6035 }
6036
6037 codec->patch_ops = stac92xx_patch_ops;
6038
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006039 codec->proc_widget_hook = stac9205_proc_hook;
6040
Matt Porterf3302a52006-07-31 12:49:34 +02006041 return 0;
6042}
6043
Matt2f2f4252005-04-13 14:45:30 +02006044/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006045 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006046 */
6047
Takashi Iwai1e137f92009-01-21 07:41:22 +01006048static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006049 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006050 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6051 {}
6052};
6053
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006054static hda_nid_t stac9872_pin_nids[] = {
6055 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6056 0x11, 0x13, 0x14,
6057};
6058
6059static hda_nid_t stac9872_adc_nids[] = {
6060 0x8 /*,0x6*/
6061};
6062
6063static hda_nid_t stac9872_mux_nids[] = {
6064 0x15
6065};
6066
Takashi Iwai6479c632009-07-28 18:20:25 +02006067static unsigned long stac9872_capvols[] = {
6068 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6069};
6070#define stac9872_capsws stac9872_capvols
6071
Takashi Iwai307282c2009-03-12 18:17:58 +01006072static unsigned int stac9872_vaio_pin_configs[9] = {
6073 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6074 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6075 0x90a7013e
6076};
6077
6078static const char *stac9872_models[STAC_9872_MODELS] = {
6079 [STAC_9872_AUTO] = "auto",
6080 [STAC_9872_VAIO] = "vaio",
6081};
6082
6083static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6084 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6085};
6086
6087static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006088 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6089 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006090 {} /* terminator */
6091};
6092
Guillaume Munch6d859062006-08-22 17:15:47 +02006093static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006094{
6095 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006096 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006097
Takashi Iwaidb064e52006-03-16 16:04:58 +01006098 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6099 if (spec == NULL)
6100 return -ENOMEM;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006101 codec->spec = spec;
Takashi Iwaib04add92009-07-20 08:01:36 +02006102 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6103 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006104
6105 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6106 stac9872_models,
6107 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006108 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006109 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6110 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006111 else
6112 stac92xx_set_config_regs(codec,
6113 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006114
Takashi Iwai1e137f92009-01-21 07:41:22 +01006115 spec->multiout.dac_nids = spec->dac_nids;
6116 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6117 spec->adc_nids = stac9872_adc_nids;
6118 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6119 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006120 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006121 spec->num_caps = 1;
6122 spec->capvols = stac9872_capvols;
6123 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006124
Takashi Iwai1e137f92009-01-21 07:41:22 +01006125 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6126 if (err < 0) {
6127 stac92xx_free(codec);
6128 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006129 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006130 spec->input_mux = &spec->private_imux;
6131 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006132 return 0;
6133}
6134
6135
6136/*
Matt2f2f4252005-04-13 14:45:30 +02006137 * patch entries
6138 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006139static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006140 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6141 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6142 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6143 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6144 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6145 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6146 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006147 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6148 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6149 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6150 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6151 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6152 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006153 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6154 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6155 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6156 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6157 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6158 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6159 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6160 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6161 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6162 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006163 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6164 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6165 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6166 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6167 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6168 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006169 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6170 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006171 /* The following does not take into account .id=0x83847661 when subsys =
6172 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6173 * currently not fully supported.
6174 */
6175 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6176 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6177 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006178 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006179 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6180 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6181 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6182 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6183 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6184 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6185 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6186 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006187 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006188 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
6189 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006190 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006191 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006192 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6193 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006194 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006195 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6196 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6197 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6198 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6199 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6200 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6201 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6202 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02006203 {} /* terminator */
6204};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006205
6206MODULE_ALIAS("snd-hda-codec-id:8384*");
6207MODULE_ALIAS("snd-hda-codec-id:111d*");
6208
6209MODULE_LICENSE("GPL");
6210MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6211
6212static struct hda_codec_preset_list sigmatel_list = {
6213 .preset = snd_hda_preset_sigmatel,
6214 .owner = THIS_MODULE,
6215};
6216
6217static int __init patch_sigmatel_init(void)
6218{
6219 return snd_hda_add_codec_preset(&sigmatel_list);
6220}
6221
6222static void __exit patch_sigmatel_exit(void)
6223{
6224 snd_hda_delete_codec_preset(&sigmatel_list);
6225}
6226
6227module_init(patch_sigmatel_init)
6228module_exit(patch_sigmatel_exit)