blob: a0e06d82da1f8c27d50d8a2b1fd5d75927db4ca9 [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>
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +010031#include <linux/dmi.h>
Matt2f2f4252005-04-13 14:45:30 +020032#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020033#include <sound/asoundef.h>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040034#include <sound/jack.h>
Matt2f2f4252005-04-13 14:45:30 +020035#include "hda_codec.h"
36#include "hda_local.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020037#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020038
Takashi Iwaic6e4c662008-11-25 11:58:19 +010039enum {
40 STAC_VREF_EVENT = 1,
41 STAC_INSERT_EVENT,
42 STAC_PWR_EVENT,
43 STAC_HP_EVENT,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020044 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020045 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010046};
Matt4e550962005-07-04 17:51:39 +020047
Takashi Iwaif5fcc132006-11-24 17:07:44 +010048enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010049 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010050 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010051 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020052 STAC_9200_DELL_D21,
53 STAC_9200_DELL_D22,
54 STAC_9200_DELL_D23,
55 STAC_9200_DELL_M21,
56 STAC_9200_DELL_M22,
57 STAC_9200_DELL_M23,
58 STAC_9200_DELL_M24,
59 STAC_9200_DELL_M25,
60 STAC_9200_DELL_M26,
61 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020062 STAC_9200_M4,
63 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010064 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010065 STAC_9200_MODELS
66};
67
68enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010069 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010070 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020071 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020072 STAC_9205_DELL_M43,
73 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010074 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010075 STAC_9205_MODELS
76};
77
78enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010079 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010080 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010081 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080082 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010083 STAC_DELL_M6_AMIC,
84 STAC_DELL_M6_DMIC,
85 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050086 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020087 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010088 STAC_92HD73XX_MODELS
89};
90
91enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010092 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020093 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050094 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050095 STAC_DELL_S14,
Takashi Iwaib4e81872009-11-18 17:20:24 +010096 STAC_92HD83XXX_HP,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020097 STAC_92HD83XXX_MODELS
98};
99
100enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100101 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100102 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100103 STAC_DELL_M4_1,
104 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500105 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400106 STAC_HP_M4,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +0200107 STAC_HP_DV4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100108 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100109 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400110 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100111 STAC_92HD71BXX_MODELS
112};
113
114enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100115 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100116 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200117 STAC_M1,
118 STAC_M1_2,
119 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100120 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200121 STAC_M3,
122 STAC_M5,
123 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100124 STAC_925x_MODELS
125};
126
127enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100128 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100129 STAC_D945_REF,
130 STAC_D945GTP3,
131 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200132 STAC_INTEL_MAC_V1,
133 STAC_INTEL_MAC_V2,
134 STAC_INTEL_MAC_V3,
135 STAC_INTEL_MAC_V4,
136 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800137 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
138 * is given, one of the above models will be
139 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200140 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100141 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100142 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100143 STAC_MACBOOK_PRO_V1,
144 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200145 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200146 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300147 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200148 STAC_922X_DELL_D81,
149 STAC_922X_DELL_D82,
150 STAC_922X_DELL_M81,
151 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100152 STAC_922X_MODELS
153};
154
155enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100156 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100157 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100158 STAC_D965_REF,
159 STAC_D965_3ST,
160 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200161 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200162 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100163 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200164 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100165 STAC_927X_MODELS
166};
Matt Porter403d1942005-11-29 15:00:51 +0100167
Takashi Iwai307282c2009-03-12 18:17:58 +0100168enum {
169 STAC_9872_AUTO,
170 STAC_9872_VAIO,
171 STAC_9872_MODELS
172};
173
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400174struct sigmatel_event {
175 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100176 unsigned char type;
177 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400178 int data;
179};
180
181struct sigmatel_jack {
182 hda_nid_t nid;
183 int type;
184 struct snd_jack *jack;
185};
186
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200187struct sigmatel_mic_route {
188 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200189 signed char mux_idx;
190 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200191};
192
Matt2f2f4252005-04-13 14:45:30 +0200193struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100194 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200195 unsigned int num_mixers;
196
Matt Porter403d1942005-11-29 15:00:51 +0100197 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500198 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200199 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100200 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100201 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400202 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100203 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200204 unsigned int auto_mic:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200205
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100206 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200207 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100208 unsigned int gpio_mask;
209 unsigned int gpio_dir;
210 unsigned int gpio_data;
211 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200212 unsigned int gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +0100213 unsigned int gpio_led_polarity;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100214
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200215 /* stream */
216 unsigned int stream_delay;
217
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100218 /* analog loopback */
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100219 struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100220 unsigned char aloopback_mask;
221 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200222
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100223 /* power management */
224 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200225 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100226 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100227 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100228
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400229 /* jack detection */
230 struct snd_array jacks;
231
232 /* events */
233 struct snd_array events;
234
Matt2f2f4252005-04-13 14:45:30 +0200235 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100236 struct hda_input_mux *mono_mux;
237 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200238 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100239 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100240 hda_nid_t hp_dacs[5];
241 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200242
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100243 int volume_offset;
244
Matt2f2f4252005-04-13 14:45:30 +0200245 /* capture */
246 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200247 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200248 hda_nid_t *mux_nids;
249 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200250 hda_nid_t *dmic_nids;
251 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100252 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100253 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200254 hda_nid_t *smux_nids;
255 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200256 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200257
258 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
259 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
260 unsigned int num_caps; /* number of capture volume/switch elements */
261
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200262 struct sigmatel_mic_route ext_mic;
263 struct sigmatel_mic_route int_mic;
264
Matthew Ranostay65973632008-09-16 10:39:37 -0400265 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200266
Mattdabbed62005-06-14 10:19:34 +0200267 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100268 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200269 hda_nid_t anabeep_nid;
270 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200271
Matt2f2f4252005-04-13 14:45:30 +0200272 /* pin widgets */
273 hda_nid_t *pin_nids;
274 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200275
276 /* codec specific stuff */
277 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100278 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200279
280 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200281 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100282 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200283 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100284 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200285 struct hda_input_mux *sinput_mux;
286 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400287 unsigned int cur_amux;
288 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200289 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200290
Matt Porter403d1942005-11-29 15:00:51 +0100291 /* i/o switches */
292 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200293 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100294 hda_nid_t line_switch; /* shared line-in for input and output */
295 hda_nid_t mic_switch; /* shared mic-in for input and output */
296 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200297 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200298
Mattc7d4b2f2005-06-27 14:59:41 +0200299 struct hda_pcm pcm_rec[2]; /* PCM information */
300
301 /* dynamic controls and input_mux */
302 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200303 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200304 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200305 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200306 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100307 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200308};
309
310static hda_nid_t stac9200_adc_nids[1] = {
311 0x03,
312};
313
314static hda_nid_t stac9200_mux_nids[1] = {
315 0x0c,
316};
317
318static hda_nid_t stac9200_dac_nids[1] = {
319 0x02,
320};
321
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100322static hda_nid_t stac92hd73xx_pwr_nids[8] = {
323 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
324 0x0f, 0x10, 0x11
325};
326
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400327static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
328 0x26, 0,
329};
330
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100331static hda_nid_t stac92hd73xx_adc_nids[2] = {
332 0x1a, 0x1b
333};
334
335#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
Takashi Iwaie2aec172009-09-02 01:00:05 +0200342static hda_nid_t stac92hd73xx_mux_nids[2] = {
343 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100344};
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 STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200362
Takashi Iwai667067d2009-08-13 18:14:42 +0200363static hda_nid_t stac92hd83xxx_mux_nids[2] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200364 0x17, 0x18,
365};
366
367static hda_nid_t stac92hd83xxx_adc_nids[2] = {
368 0x15, 0x16,
369};
370
371static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
372 0xa, 0xb, 0xd, 0xe,
373};
374
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400375static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
376 0x1e, 0,
377};
378
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200379static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500380 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200381};
382
Takashi Iwai6479c632009-07-28 18:20:25 +0200383#define STAC92HD83XXX_NUM_CAPS 2
384static unsigned long stac92hd83xxx_capvols[] = {
385 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
386 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
387};
388#define stac92hd83xxx_capsws stac92hd83xxx_capvols
389
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100390static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
391 0x0a, 0x0d, 0x0f
392};
393
Matthew Ranostaye035b842007-11-06 11:53:55 +0100394static hda_nid_t stac92hd71bxx_adc_nids[2] = {
395 0x12, 0x13,
396};
397
398static hda_nid_t stac92hd71bxx_mux_nids[2] = {
399 0x1a, 0x1b
400};
401
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400402static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
403 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100404};
405
Matthew Ranostayd9737752008-09-07 12:03:41 +0200406static hda_nid_t stac92hd71bxx_smux_nids[2] = {
407 0x24, 0x25,
408};
409
Matthew Ranostaye035b842007-11-06 11:53:55 +0100410#define STAC92HD71BXX_NUM_DMICS 2
411static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
412 0x18, 0x19, 0
413};
414
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400415static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
416 0x22, 0
417};
418
Takashi Iwai6479c632009-07-28 18:20:25 +0200419#define STAC92HD71BXX_NUM_CAPS 2
420static unsigned long stac92hd71bxx_capvols[] = {
421 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
422 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
423};
424#define stac92hd71bxx_capsws stac92hd71bxx_capvols
425
Tobin Davis8e21c342007-01-08 11:04:17 +0100426static hda_nid_t stac925x_adc_nids[1] = {
427 0x03,
428};
429
430static hda_nid_t stac925x_mux_nids[1] = {
431 0x0f,
432};
433
434static hda_nid_t stac925x_dac_nids[1] = {
435 0x02,
436};
437
Takashi Iwaif6e98522007-10-16 14:27:04 +0200438#define STAC925X_NUM_DMICS 1
439static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
440 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200441};
442
Takashi Iwai1697055e2007-12-18 18:05:52 +0100443static hda_nid_t stac925x_dmux_nids[1] = {
444 0x14,
445};
446
Takashi Iwai6479c632009-07-28 18:20:25 +0200447static unsigned long stac925x_capvols[] = {
448 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
449};
450static unsigned long stac925x_capsws[] = {
451 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
452};
453
Matt2f2f4252005-04-13 14:45:30 +0200454static hda_nid_t stac922x_adc_nids[2] = {
455 0x06, 0x07,
456};
457
458static hda_nid_t stac922x_mux_nids[2] = {
459 0x12, 0x13,
460};
461
Takashi Iwai6479c632009-07-28 18:20:25 +0200462#define STAC922X_NUM_CAPS 2
463static unsigned long stac922x_capvols[] = {
464 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
465 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
466};
467#define stac922x_capsws stac922x_capvols
468
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500469static hda_nid_t stac927x_slave_dig_outs[2] = {
470 0x1f, 0,
471};
472
Matt Porter3cc08dc2006-01-23 15:27:49 +0100473static hda_nid_t stac927x_adc_nids[3] = {
474 0x07, 0x08, 0x09
475};
476
477static hda_nid_t stac927x_mux_nids[3] = {
478 0x15, 0x16, 0x17
479};
480
Matthew Ranostayd9737752008-09-07 12:03:41 +0200481static hda_nid_t stac927x_smux_nids[1] = {
482 0x21,
483};
484
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100485static hda_nid_t stac927x_dac_nids[6] = {
486 0x02, 0x03, 0x04, 0x05, 0x06, 0
487};
488
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100489static hda_nid_t stac927x_dmux_nids[1] = {
490 0x1b,
491};
492
Matthew Ranostay7f168592007-10-18 17:38:17 +0200493#define STAC927X_NUM_DMICS 2
494static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
495 0x13, 0x14, 0
496};
497
Takashi Iwai6479c632009-07-28 18:20:25 +0200498#define STAC927X_NUM_CAPS 3
499static unsigned long stac927x_capvols[] = {
500 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
501 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
502 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
503};
504static unsigned long stac927x_capsws[] = {
505 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
506 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
507 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
508};
509
Matthew Ranostay65973632008-09-16 10:39:37 -0400510static const char *stac927x_spdif_labels[5] = {
511 "Digital Playback", "ADAT", "Analog Mux 1",
512 "Analog Mux 2", "Analog Mux 3"
513};
514
Matt Porterf3302a52006-07-31 12:49:34 +0200515static hda_nid_t stac9205_adc_nids[2] = {
516 0x12, 0x13
517};
518
519static hda_nid_t stac9205_mux_nids[2] = {
520 0x19, 0x1a
521};
522
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100523static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100524 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100525};
526
Matthew Ranostayd9737752008-09-07 12:03:41 +0200527static hda_nid_t stac9205_smux_nids[1] = {
528 0x21,
529};
530
Takashi Iwaif6e98522007-10-16 14:27:04 +0200531#define STAC9205_NUM_DMICS 2
532static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
533 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200534};
535
Takashi Iwai6479c632009-07-28 18:20:25 +0200536#define STAC9205_NUM_CAPS 2
537static unsigned long stac9205_capvols[] = {
538 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
539 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
540};
541static unsigned long stac9205_capsws[] = {
542 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
543 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
544};
545
Mattc7d4b2f2005-06-27 14:59:41 +0200546static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200547 0x08, 0x09, 0x0d, 0x0e,
548 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200549};
550
Tobin Davis8e21c342007-01-08 11:04:17 +0100551static hda_nid_t stac925x_pin_nids[8] = {
552 0x07, 0x08, 0x0a, 0x0b,
553 0x0c, 0x0d, 0x10, 0x11,
554};
555
Matt2f2f4252005-04-13 14:45:30 +0200556static hda_nid_t stac922x_pin_nids[10] = {
557 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
558 0x0f, 0x10, 0x11, 0x15, 0x1b,
559};
560
Matthew Ranostaya7662642008-02-21 07:51:14 +0100561static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100562 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
563 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200564 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100565};
566
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500567static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200568 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500569 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200570};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500571
Charles Chin36706002010-01-29 12:05:51 +0100572static hda_nid_t stac92hd88xxx_pin_nids[10] = {
573 0x0a, 0x0b, 0x0c, 0x0d,
574 0x0f, 0x11, 0x1f, 0x20,
575};
576
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500577#define STAC92HD71BXX_NUM_PINS 13
578static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
579 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
580 0x00, 0x14, 0x18, 0x19, 0x1e,
581 0x1f, 0x20, 0x27
582};
583static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100584 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
585 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500586 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100587};
588
Matt Porter3cc08dc2006-01-23 15:27:49 +0100589static hda_nid_t stac927x_pin_nids[14] = {
590 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
591 0x0f, 0x10, 0x11, 0x12, 0x13,
592 0x14, 0x21, 0x22, 0x23,
593};
594
Matt Porterf3302a52006-07-31 12:49:34 +0200595static hda_nid_t stac9205_pin_nids[12] = {
596 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
597 0x0f, 0x14, 0x16, 0x17, 0x18,
598 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200599};
600
Matt Porter8b657272006-10-26 17:12:59 +0200601static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
602 struct snd_ctl_elem_info *uinfo)
603{
604 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
605 struct sigmatel_spec *spec = codec->spec;
606 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
607}
608
609static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
610 struct snd_ctl_elem_value *ucontrol)
611{
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100614 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200615
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100616 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200617 return 0;
618}
619
620static int stac92xx_dmux_enum_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;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100625 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200626
627 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100628 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200629}
630
Matthew Ranostayd9737752008-09-07 12:03:41 +0200631static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
632 struct snd_ctl_elem_info *uinfo)
633{
634 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
635 struct sigmatel_spec *spec = codec->spec;
636 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
637}
638
639static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
640 struct snd_ctl_elem_value *ucontrol)
641{
642 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
643 struct sigmatel_spec *spec = codec->spec;
644 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
645
646 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
647 return 0;
648}
649
650static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
651 struct snd_ctl_elem_value *ucontrol)
652{
653 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
654 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400655 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200656 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400657 int err, val;
658 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200659
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400660 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200661 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400662 if (err < 0)
663 return err;
664
665 if (spec->spdif_mute) {
666 if (smux_idx == 0)
667 nid = spec->multiout.dig_out_nid;
668 else
669 nid = codec->slave_dig_outs[smux_idx - 1];
670 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100671 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400672 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100673 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400674 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100675 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
676 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400677 }
678 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200679}
680
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200681static unsigned int stac92xx_vref_set(struct hda_codec *codec,
682 hda_nid_t nid, unsigned int new_vref)
683{
Takashi Iwaib8621512009-06-22 08:00:10 +0200684 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200685 unsigned int pincfg;
686 pincfg = snd_hda_codec_read(codec, nid, 0,
687 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
688
689 pincfg &= 0xff;
690 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
691 pincfg |= new_vref;
692
693 if (new_vref == AC_PINCTL_VREF_HIZ)
694 pincfg |= AC_PINCTL_OUT_EN;
695 else
696 pincfg |= AC_PINCTL_IN_EN;
697
698 error = snd_hda_codec_write_cache(codec, nid, 0,
699 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
700 if (error < 0)
701 return error;
702 else
703 return 1;
704}
705
706static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
707{
708 unsigned int vref;
709 vref = snd_hda_codec_read(codec, nid, 0,
710 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
711 vref &= AC_PINCTL_VREFEN;
712 return vref;
713}
714
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100715static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200716{
717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200719 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200720}
721
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100722static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200723{
724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
725 struct sigmatel_spec *spec = codec->spec;
726 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
727
728 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
729 return 0;
730}
731
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100732static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200733{
734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
735 struct sigmatel_spec *spec = codec->spec;
736 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200737 const struct hda_input_mux *imux = spec->input_mux;
738 unsigned int idx, prev_idx;
Matt2f2f4252005-04-13 14:45:30 +0200739
Takashi Iwai5207e102009-07-30 13:09:08 +0200740 idx = ucontrol->value.enumerated.item[0];
741 if (idx >= imux->num_items)
742 idx = imux->num_items - 1;
743 prev_idx = spec->cur_mux[adc_idx];
744 if (prev_idx == idx)
745 return 0;
746 if (idx < spec->num_analog_muxes) {
747 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
748 AC_VERB_SET_CONNECT_SEL,
749 imux->items[idx].index);
750 if (prev_idx >= spec->num_analog_muxes) {
751 imux = spec->dinput_mux;
752 /* 0 = analog */
753 snd_hda_codec_write_cache(codec,
754 spec->dmux_nids[adc_idx], 0,
755 AC_VERB_SET_CONNECT_SEL,
756 imux->items[0].index);
757 }
758 } else {
759 imux = spec->dinput_mux;
760 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
761 AC_VERB_SET_CONNECT_SEL,
762 imux->items[idx - 1].index);
763 }
764 spec->cur_mux[adc_idx] = idx;
765 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200766}
767
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100768static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
769 struct snd_ctl_elem_info *uinfo)
770{
771 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
772 struct sigmatel_spec *spec = codec->spec;
773 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
774}
775
776static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
777 struct snd_ctl_elem_value *ucontrol)
778{
779 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
780 struct sigmatel_spec *spec = codec->spec;
781
782 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
783 return 0;
784}
785
786static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
787 struct snd_ctl_elem_value *ucontrol)
788{
789 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
790 struct sigmatel_spec *spec = codec->spec;
791
792 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
793 spec->mono_nid, &spec->cur_mmux);
794}
795
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200796#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
797
798static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
799 struct snd_ctl_elem_value *ucontrol)
800{
801 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100802 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200803 struct sigmatel_spec *spec = codec->spec;
804
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100805 ucontrol->value.integer.value[0] = !!(spec->aloopback &
806 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200807 return 0;
808}
809
810static int stac92xx_aloopback_put(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;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100815 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200816 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100817 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200818
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100819 idx_val = spec->aloopback_mask << idx;
820 if (ucontrol->value.integer.value[0])
821 val = spec->aloopback | idx_val;
822 else
823 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100824 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200825 return 0;
826
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100827 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200828
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100829 /* Only return the bits defined by the shift value of the
830 * first two bytes of the mask
831 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200832 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100833 kcontrol->private_value & 0xFFFF, 0x0);
834 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200835
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100836 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200837 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100838 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200839 } else {
840 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100841 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200842 }
843
844 snd_hda_codec_write_cache(codec, codec->afg, 0,
845 kcontrol->private_value >> 16, dac_mode);
846
847 return 1;
848}
849
Mattc7d4b2f2005-06-27 14:59:41 +0200850static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200851 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200852 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200853 {}
854};
855
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200856static struct hda_verb stac9200_eapd_init[] = {
857 /* set dac0mux for dac converter */
858 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
859 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
860 {}
861};
862
Matthew Ranostayd654a662008-03-14 08:46:51 +0100863static struct hda_verb dell_eq_core_init[] = {
864 /* set master volume to max value without distortion
865 * and direct control */
866 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100867 {}
868};
869
Takashi Iwaie2aec172009-09-02 01:00:05 +0200870static struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100871 /* set master volume and direct control */
872 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100873 {}
874};
875
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200876static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200877 /* power state controls amps */
878 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200879 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200880};
881
Matthew Ranostaye035b842007-11-06 11:53:55 +0100882static struct hda_verb stac92hd71bxx_core_init[] = {
883 /* set master volume and direct control */
884 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200885 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100886};
887
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500888static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
889 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
890 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100891 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
892 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100893 {}
894};
895
Tobin Davis8e21c342007-01-08 11:04:17 +0100896static struct hda_verb stac925x_core_init[] = {
897 /* set dac0mux for dac converter */
898 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100899 /* mute the master volume */
900 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100901 {}
902};
903
Mattc7d4b2f2005-06-27 14:59:41 +0200904static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200905 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200906 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200907 {}
908};
909
Tobin Davis93ed1502006-09-01 21:03:12 +0200910static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200911 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200912 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200913 /* unmute node 0x1b */
914 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
915 /* select node 0x03 as DAC */
916 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
917 {}
918};
919
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200920static struct hda_verb dell_3st_core_init[] = {
921 /* don't set delta bit */
922 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
923 /* unmute node 0x1b */
924 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
925 /* select node 0x03 as DAC */
926 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
927 {}
928};
929
Matt Porter3cc08dc2006-01-23 15:27:49 +0100930static struct hda_verb stac927x_core_init[] = {
931 /* set master volume and direct control */
932 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200933 /* enable analog pc beep path */
934 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100935 {}
936};
937
Takashi Iwai54930532009-10-11 17:38:29 +0200938static struct hda_verb stac927x_volknob_core_init[] = {
939 /* don't set delta bit */
940 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
941 /* enable analog pc beep path */
942 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
943 {}
944};
945
Matt Porterf3302a52006-07-31 12:49:34 +0200946static struct hda_verb stac9205_core_init[] = {
947 /* set master volume and direct control */
948 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200949 /* enable analog pc beep path */
950 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200951 {}
952};
953
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100954#define STAC_MONO_MUX \
955 { \
956 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
957 .name = "Mono Mux", \
958 .count = 1, \
959 .info = stac92xx_mono_mux_enum_info, \
960 .get = stac92xx_mono_mux_enum_get, \
961 .put = stac92xx_mono_mux_enum_put, \
962 }
963
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100964#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200965 { \
966 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
967 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100968 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200969 .info = stac92xx_aloopback_info, \
970 .get = stac92xx_aloopback_get, \
971 .put = stac92xx_aloopback_put, \
972 .private_value = verb_read | (verb_write << 16), \
973 }
974
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200975#define DC_BIAS(xname, idx, nid) \
976 { \
977 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
978 .name = xname, \
979 .index = idx, \
980 .info = stac92xx_dc_bias_info, \
981 .get = stac92xx_dc_bias_get, \
982 .put = stac92xx_dc_bias_put, \
983 .private_value = nid, \
984 }
985
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100986static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200987 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
988 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200989 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
990 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200991 { } /* end */
992};
993
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100994static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
995 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
996 {}
997};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100998
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100999static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1000 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1001 {}
1002};
1003
1004static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1005 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1006 {}
1007};
1008
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001009
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001010static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1011 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1012};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001013
Tobin Davis8e21c342007-01-08 11:04:17 +01001014static struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwaic9280d62009-01-15 17:31:00 +01001015 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1016 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001017 { } /* end */
1018};
1019
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001020static struct snd_kcontrol_new stac9205_loopback[] = {
1021 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1022 {}
1023};
1024
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001025static struct snd_kcontrol_new stac927x_loopback[] = {
1026 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1027 {}
1028};
1029
Takashi Iwai1697055e2007-12-18 18:05:52 +01001030static struct snd_kcontrol_new stac_dmux_mixer = {
1031 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1032 .name = "Digital Input Source",
1033 /* count set later */
1034 .info = stac92xx_dmux_enum_info,
1035 .get = stac92xx_dmux_enum_get,
1036 .put = stac92xx_dmux_enum_put,
1037};
1038
Matthew Ranostayd9737752008-09-07 12:03:41 +02001039static struct snd_kcontrol_new stac_smux_mixer = {
1040 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001041 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001042 /* count set later */
1043 .info = stac92xx_smux_enum_info,
1044 .get = stac92xx_smux_enum_get,
1045 .put = stac92xx_smux_enum_put,
1046};
1047
Takashi Iwai2134ea42008-01-10 16:53:55 +01001048static const char *slave_vols[] = {
1049 "Front Playback Volume",
1050 "Surround Playback Volume",
1051 "Center Playback Volume",
1052 "LFE Playback Volume",
1053 "Side Playback Volume",
1054 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001055 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001056 NULL
1057};
1058
1059static const char *slave_sws[] = {
1060 "Front Playback Switch",
1061 "Surround Playback Switch",
1062 "Center Playback Switch",
1063 "LFE Playback Switch",
1064 "Side Playback Switch",
1065 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001066 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001067 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001068 NULL
1069};
1070
Takashi Iwai603c4012008-07-30 15:01:44 +02001071static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001072static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001073
Matt2f2f4252005-04-13 14:45:30 +02001074static int stac92xx_build_controls(struct hda_codec *codec)
1075{
1076 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001077 struct auto_pin_cfg *cfg = &spec->autocfg;
1078 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001079 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001080 int i;
Matt2f2f4252005-04-13 14:45:30 +02001081
Takashi Iwai6479c632009-07-28 18:20:25 +02001082 if (spec->mixer) {
1083 err = snd_hda_add_new_ctls(codec, spec->mixer);
1084 if (err < 0)
1085 return err;
1086 }
Mattc7d4b2f2005-06-27 14:59:41 +02001087
1088 for (i = 0; i < spec->num_mixers; i++) {
1089 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1090 if (err < 0)
1091 return err;
1092 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001093 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1094 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001095 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001096 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001097 snd_ctl_new1(&stac_dmux_mixer, codec));
1098 if (err < 0)
1099 return err;
1100 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001101 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001102 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1103 struct hda_input_mux *smux = &spec->private_smux;
1104 /* check for mute support on SPDIF out */
1105 if (wcaps & AC_WCAP_OUT_AMP) {
1106 smux->items[smux->num_items].label = "Off";
1107 smux->items[smux->num_items].index = 0;
1108 smux->num_items++;
1109 spec->spdif_mute = 1;
1110 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001111 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001112 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001113 snd_ctl_new1(&stac_smux_mixer, codec));
1114 if (err < 0)
1115 return err;
1116 }
Mattc7d4b2f2005-06-27 14:59:41 +02001117
Mattdabbed62005-06-14 10:19:34 +02001118 if (spec->multiout.dig_out_nid) {
1119 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1120 if (err < 0)
1121 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001122 err = snd_hda_create_spdif_share_sw(codec,
1123 &spec->multiout);
1124 if (err < 0)
1125 return err;
1126 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001127 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001128 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001129 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1130 if (err < 0)
1131 return err;
1132 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001133
1134 /* if we have no master control, let's create it */
1135 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001136 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001137 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001138 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001139 /* correct volume offset */
1140 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001141 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001142 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001143 if (err < 0)
1144 return err;
1145 }
1146 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1147 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1148 NULL, slave_sws);
1149 if (err < 0)
1150 return err;
1151 }
1152
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001153 if (spec->aloopback_ctl &&
1154 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1155 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1156 if (err < 0)
1157 return err;
1158 }
1159
Takashi Iwai603c4012008-07-30 15:01:44 +02001160 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001161
1162 /* create jack input elements */
1163 if (spec->hp_detect) {
1164 for (i = 0; i < cfg->hp_outs; i++) {
1165 int type = SND_JACK_HEADPHONE;
1166 nid = cfg->hp_pins[i];
1167 /* jack detection */
1168 if (cfg->hp_outs == i)
1169 type |= SND_JACK_LINEOUT;
1170 err = stac92xx_add_jack(codec, nid, type);
1171 if (err < 0)
1172 return err;
1173 }
1174 }
1175 for (i = 0; i < cfg->line_outs; i++) {
1176 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1177 SND_JACK_LINEOUT);
1178 if (err < 0)
1179 return err;
1180 }
1181 for (i = 0; i < AUTO_PIN_LAST; i++) {
1182 nid = cfg->input_pins[i];
1183 if (nid) {
1184 err = stac92xx_add_jack(codec, nid,
1185 SND_JACK_MICROPHONE);
1186 if (err < 0)
1187 return err;
1188 }
1189 }
1190
Mattdabbed62005-06-14 10:19:34 +02001191 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001192}
1193
Matt Porter403d1942005-11-29 15:00:51 +01001194static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001195 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001196 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1197};
1198
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001199static unsigned int gateway9200_m4_pin_configs[8] = {
1200 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1201 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1202};
1203static unsigned int gateway9200_m4_2_pin_configs[8] = {
1204 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1205 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1206};
1207
1208/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001209 STAC 9200 pin configs for
1210 102801A8
1211 102801DE
1212 102801E8
1213*/
1214static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001215 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1216 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001217};
1218
1219/*
1220 STAC 9200 pin configs for
1221 102801C0
1222 102801C1
1223*/
1224static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001225 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1226 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001227};
1228
1229/*
1230 STAC 9200 pin configs for
1231 102801C4 (Dell Dimension E310)
1232 102801C5
1233 102801C7
1234 102801D9
1235 102801DA
1236 102801E3
1237*/
1238static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001239 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1240 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001241};
1242
1243
1244/*
1245 STAC 9200-32 pin configs for
1246 102801B5 (Dell Inspiron 630m)
1247 102801D8 (Dell Inspiron 640m)
1248*/
1249static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001250 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1251 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001252};
1253
1254/*
1255 STAC 9200-32 pin configs for
1256 102801C2 (Dell Latitude D620)
1257 102801C8
1258 102801CC (Dell Latitude D820)
1259 102801D4
1260 102801D6
1261*/
1262static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001263 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1264 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001265};
1266
1267/*
1268 STAC 9200-32 pin configs for
1269 102801CE (Dell XPS M1710)
1270 102801CF (Dell Precision M90)
1271*/
1272static unsigned int dell9200_m23_pin_configs[8] = {
1273 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1274 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1275};
1276
1277/*
1278 STAC 9200-32 pin configs for
1279 102801C9
1280 102801CA
1281 102801CB (Dell Latitude 120L)
1282 102801D3
1283*/
1284static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001285 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1286 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001287};
1288
1289/*
1290 STAC 9200-32 pin configs for
1291 102801BD (Dell Inspiron E1505n)
1292 102801EE
1293 102801EF
1294*/
1295static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001296 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1297 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001298};
1299
1300/*
1301 STAC 9200-32 pin configs for
1302 102801F5 (Dell Inspiron 1501)
1303 102801F6
1304*/
1305static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001306 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1307 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001308};
1309
1310/*
1311 STAC 9200-32
1312 102801CD (Dell Inspiron E1705/9400)
1313*/
1314static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001315 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1316 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001317};
1318
Tobin Davisbf277782008-02-03 20:31:47 +01001319static unsigned int oqo9200_pin_configs[8] = {
1320 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1321 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1322};
1323
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001324
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001325static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1326 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001327 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001328 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1329 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1330 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1331 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1332 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1333 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1334 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1335 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1336 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1337 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001338 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1339 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001340 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001341};
1342
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001343static const char *stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001344 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001345 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001346 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001347 [STAC_9200_DELL_D21] = "dell-d21",
1348 [STAC_9200_DELL_D22] = "dell-d22",
1349 [STAC_9200_DELL_D23] = "dell-d23",
1350 [STAC_9200_DELL_M21] = "dell-m21",
1351 [STAC_9200_DELL_M22] = "dell-m22",
1352 [STAC_9200_DELL_M23] = "dell-m23",
1353 [STAC_9200_DELL_M24] = "dell-m24",
1354 [STAC_9200_DELL_M25] = "dell-m25",
1355 [STAC_9200_DELL_M26] = "dell-m26",
1356 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001357 [STAC_9200_M4] = "gateway-m4",
1358 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001359 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001360};
1361
1362static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1363 /* SigmaTel reference board */
1364 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1365 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001366 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1367 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001368 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001369 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1370 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001371 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001372 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1373 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1374 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1375 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1376 "unknown Dell", STAC_9200_DELL_D22),
1377 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1378 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001379 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001380 "Dell Latitude D620", STAC_9200_DELL_M22),
1381 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1382 "unknown Dell", STAC_9200_DELL_D23),
1383 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1384 "unknown Dell", STAC_9200_DELL_D23),
1385 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1386 "unknown Dell", STAC_9200_DELL_M22),
1387 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1388 "unknown Dell", STAC_9200_DELL_M24),
1389 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1390 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001391 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001392 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001393 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001394 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001395 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001396 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001397 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001398 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001399 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001400 "Dell Precision M90", STAC_9200_DELL_M23),
1401 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1402 "unknown Dell", STAC_9200_DELL_M22),
1403 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1404 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001405 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001406 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001407 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001408 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1409 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1410 "unknown Dell", STAC_9200_DELL_D23),
1411 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1412 "unknown Dell", STAC_9200_DELL_D23),
1413 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1414 "unknown Dell", STAC_9200_DELL_D21),
1415 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1416 "unknown Dell", STAC_9200_DELL_D23),
1417 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1418 "unknown Dell", STAC_9200_DELL_D21),
1419 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1420 "unknown Dell", STAC_9200_DELL_M25),
1421 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1422 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001423 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001424 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1425 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1426 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001427 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001428 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001429 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001430 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1431 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1432 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001433 /* OQO Mobile */
1434 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001435 {} /* terminator */
1436};
1437
Tobin Davis8e21c342007-01-08 11:04:17 +01001438static unsigned int ref925x_pin_configs[8] = {
1439 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001440 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001441};
1442
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001443static unsigned int stac925xM1_pin_configs[8] = {
1444 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1445 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001446};
1447
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001448static unsigned int stac925xM1_2_pin_configs[8] = {
1449 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1450 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1451};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001452
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001453static unsigned int stac925xM2_pin_configs[8] = {
1454 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1455 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001456};
1457
Tobin Davis8e21c342007-01-08 11:04:17 +01001458static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001459 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1460 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1461};
1462
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001463static unsigned int stac925xM3_pin_configs[8] = {
1464 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1465 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1466};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001467
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001468static unsigned int stac925xM5_pin_configs[8] = {
1469 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1470 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1471};
1472
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001473static unsigned int stac925xM6_pin_configs[8] = {
1474 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1475 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001476};
1477
1478static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1479 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001480 [STAC_M1] = stac925xM1_pin_configs,
1481 [STAC_M1_2] = stac925xM1_2_pin_configs,
1482 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001483 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001484 [STAC_M3] = stac925xM3_pin_configs,
1485 [STAC_M5] = stac925xM5_pin_configs,
1486 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001487};
1488
1489static const char *stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001490 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001491 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001492 [STAC_M1] = "m1",
1493 [STAC_M1_2] = "m1-2",
1494 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001495 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001496 [STAC_M3] = "m3",
1497 [STAC_M5] = "m5",
1498 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001499};
1500
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001501static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001502 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1503 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1504 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1505 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001506 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001507 /* Not sure about the brand name for those */
1508 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1509 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1510 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1511 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001512 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001513};
1514
1515static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1516 /* SigmaTel reference board */
1517 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001518 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001519 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001520
1521 /* Default table for unknown ID */
1522 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1523
Tobin Davis8e21c342007-01-08 11:04:17 +01001524 {} /* terminator */
1525};
1526
Matthew Ranostaya7662642008-02-21 07:51:14 +01001527static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001528 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1529 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1530 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001531 0x01452050,
1532};
1533
1534static unsigned int dell_m6_pin_configs[13] = {
1535 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001536 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001537 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1538 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001539};
1540
Takashi Iwai842ae632009-09-02 07:43:08 +02001541static unsigned int alienware_m17x_pin_configs[13] = {
1542 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1543 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1544 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1545 0x904601b0,
1546};
1547
Wu Fengguang4d26f442010-05-07 08:47:54 +08001548static unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001549 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001550 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001551};
1552
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001553static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001554 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001555 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1556 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1557 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001558 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001559 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001560 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001561};
1562
1563static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001564 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001565 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001566 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001567 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001568 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1569 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1570 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001571 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001572 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001573};
1574
1575static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1576 /* SigmaTel reference board */
1577 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001578 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001579 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1580 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001581 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1582 "Intel DG45ID", STAC_92HD73XX_INTEL),
1583 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1584 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001585 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001586 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001587 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001588 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001589 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001590 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001591 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001592 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001593 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001594 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001595 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001596 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001597 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001598 "unknown Dell", STAC_DELL_M6_DMIC),
1599 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1600 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001601 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001602 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001603 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1604 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001605 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1606 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001607 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1608 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001609 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1610 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001611 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1612 "Dell Studio 1558", STAC_DELL_M6_BOTH),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001613 {} /* terminator */
1614};
1615
Takashi Iwai842ae632009-09-02 07:43:08 +02001616static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1617 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1618 "Alienware M17x", STAC_ALIENWARE_M17X),
1619 {} /* terminator */
1620};
1621
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001622static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001623 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1624 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001625 0x01451160, 0x98560170,
1626};
1627
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001628static unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001629 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1630 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001631 0x40f000f0, 0x40f000f0,
1632};
1633
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001634static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1635 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001636 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001637 [STAC_DELL_S14] = dell_s14_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001638};
1639
1640static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001641 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001642 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001643 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001644 [STAC_DELL_S14] = "dell-s14",
Takashi Iwaib4e81872009-11-18 17:20:24 +01001645 [STAC_92HD83XXX_HP] = "hp",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001646};
1647
1648static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1649 /* SigmaTel reference board */
1650 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001651 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001652 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1653 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001654 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1655 "unknown Dell", STAC_DELL_S14),
Takashi Iwaib4e81872009-11-18 17:20:24 +01001656 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1657 "HP", STAC_92HD83XXX_HP),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001658 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001659};
1660
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001661static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001662 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001663 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001664 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1665 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001666};
1667
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001668static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001669 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001670 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001671 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1672 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001673};
1674
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001675static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001676 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1677 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001678 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1679 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001680};
1681
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001682static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001683 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1684 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001685 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1686 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001687};
1688
Matthew Ranostaye035b842007-11-06 11:53:55 +01001689static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1690 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001691 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1692 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001693 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001694 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001695 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001696 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001697 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001698 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001699};
1700
1701static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001702 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001703 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001704 [STAC_DELL_M4_1] = "dell-m4-1",
1705 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001706 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001707 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001708 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001709 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001710 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001711 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001712};
1713
1714static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1715 /* SigmaTel reference board */
1716 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1717 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001718 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1719 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001720 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1721 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01001722 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1723 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01001724 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1725 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001726 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001727 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001728 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1729 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001730 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1731 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001732 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001733 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001734 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001735 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001736 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1737 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05301738 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1739 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Takashi Iwai1972d022009-08-06 08:44:43 +02001740 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1741 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001742 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1743 "unknown Dell", STAC_DELL_M4_1),
1744 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1745 "unknown Dell", STAC_DELL_M4_1),
1746 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1747 "unknown Dell", STAC_DELL_M4_1),
1748 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1749 "unknown Dell", STAC_DELL_M4_1),
1750 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1751 "unknown Dell", STAC_DELL_M4_1),
1752 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1753 "unknown Dell", STAC_DELL_M4_1),
1754 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1755 "unknown Dell", STAC_DELL_M4_1),
1756 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1757 "unknown Dell", STAC_DELL_M4_2),
1758 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1759 "unknown Dell", STAC_DELL_M4_2),
1760 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1761 "unknown Dell", STAC_DELL_M4_2),
1762 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1763 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001764 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1765 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001766 {} /* terminator */
1767};
1768
Matt Porter403d1942005-11-29 15:00:51 +01001769static unsigned int ref922x_pin_configs[10] = {
1770 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1771 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001772 0x40000100, 0x40000100,
1773};
1774
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001775/*
1776 STAC 922X pin configs for
1777 102801A7
1778 102801AB
1779 102801A9
1780 102801D1
1781 102801D2
1782*/
1783static unsigned int dell_922x_d81_pin_configs[10] = {
1784 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1785 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1786 0x01813122, 0x400001f2,
1787};
1788
1789/*
1790 STAC 922X pin configs for
1791 102801AC
1792 102801D0
1793*/
1794static unsigned int dell_922x_d82_pin_configs[10] = {
1795 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1796 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1797 0x01813122, 0x400001f1,
1798};
1799
1800/*
1801 STAC 922X pin configs for
1802 102801BF
1803*/
1804static unsigned int dell_922x_m81_pin_configs[10] = {
1805 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1806 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1807 0x40C003f1, 0x405003f0,
1808};
1809
1810/*
1811 STAC 9221 A1 pin configs for
1812 102801D7 (Dell XPS M1210)
1813*/
1814static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001815 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1816 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001817 0x508003f3, 0x405003f4,
1818};
1819
Matt Porter403d1942005-11-29 15:00:51 +01001820static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001821 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001822 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1823 0x02a19120, 0x40000100,
1824};
1825
1826static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001827 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1828 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001829 0x02a19320, 0x40000100,
1830};
1831
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001832static unsigned int intel_mac_v1_pin_configs[10] = {
1833 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1834 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001835 0x400000fc, 0x400000fb,
1836};
1837
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001838static unsigned int intel_mac_v2_pin_configs[10] = {
1839 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1840 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001841 0x400000fc, 0x400000fb,
1842};
1843
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001844static unsigned int intel_mac_v3_pin_configs[10] = {
1845 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1846 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1847 0x400000fc, 0x400000fb,
1848};
1849
1850static unsigned int intel_mac_v4_pin_configs[10] = {
1851 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1852 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1853 0x400000fc, 0x400000fb,
1854};
1855
1856static unsigned int intel_mac_v5_pin_configs[10] = {
1857 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1858 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1859 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001860};
1861
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001862static unsigned int ecs202_pin_configs[10] = {
1863 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1864 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1865 0x9037012e, 0x40e000f2,
1866};
Takashi Iwai76c08822007-06-19 12:17:42 +02001867
Takashi Iwai19039bd2006-06-28 15:52:16 +02001868static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001869 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001870 [STAC_D945GTP3] = d945gtp3_pin_configs,
1871 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001872 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1873 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1874 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1875 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1876 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001877 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001878 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001879 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1880 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1881 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1882 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1883 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1884 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001885 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001886 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1887 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1888 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1889 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001890};
1891
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001892static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001893 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001894 [STAC_D945_REF] = "ref",
1895 [STAC_D945GTP5] = "5stack",
1896 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001897 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1898 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1899 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1900 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1901 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001902 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001903 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001904 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001905 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001906 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1907 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001908 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001909 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001910 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001911 [STAC_922X_DELL_D81] = "dell-d81",
1912 [STAC_922X_DELL_D82] = "dell-d82",
1913 [STAC_922X_DELL_M81] = "dell-m81",
1914 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001915};
1916
1917static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1918 /* SigmaTel reference board */
1919 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1920 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001921 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1922 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001923 /* Intel 945G based systems */
1924 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1925 "Intel D945G", STAC_D945GTP3),
1926 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1927 "Intel D945G", STAC_D945GTP3),
1928 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1929 "Intel D945G", STAC_D945GTP3),
1930 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1931 "Intel D945G", STAC_D945GTP3),
1932 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1933 "Intel D945G", STAC_D945GTP3),
1934 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1935 "Intel D945G", STAC_D945GTP3),
1936 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1937 "Intel D945G", STAC_D945GTP3),
1938 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1939 "Intel D945G", STAC_D945GTP3),
1940 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1941 "Intel D945G", STAC_D945GTP3),
1942 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1943 "Intel D945G", STAC_D945GTP3),
1944 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1945 "Intel D945G", STAC_D945GTP3),
1946 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1947 "Intel D945G", STAC_D945GTP3),
1948 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1949 "Intel D945G", STAC_D945GTP3),
1950 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1951 "Intel D945G", STAC_D945GTP3),
1952 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1953 "Intel D945G", STAC_D945GTP3),
1954 /* Intel D945G 5-stack systems */
1955 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1956 "Intel D945G", STAC_D945GTP5),
1957 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1958 "Intel D945G", STAC_D945GTP5),
1959 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1960 "Intel D945G", STAC_D945GTP5),
1961 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1962 "Intel D945G", STAC_D945GTP5),
1963 /* Intel 945P based systems */
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1965 "Intel D945P", STAC_D945GTP3),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1967 "Intel D945P", STAC_D945GTP3),
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1969 "Intel D945P", STAC_D945GTP3),
1970 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1971 "Intel D945P", STAC_D945GTP3),
1972 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1973 "Intel D945P", STAC_D945GTP3),
1974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1975 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01001976 /* other intel */
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
1978 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001979 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08001980 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001981 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001982 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001983 /* Dell systems */
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1985 "unknown Dell", STAC_922X_DELL_D81),
1986 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1987 "unknown Dell", STAC_922X_DELL_D81),
1988 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1989 "unknown Dell", STAC_922X_DELL_D81),
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1991 "unknown Dell", STAC_922X_DELL_D82),
1992 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1993 "unknown Dell", STAC_922X_DELL_M81),
1994 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1995 "unknown Dell", STAC_922X_DELL_D82),
1996 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1997 "unknown Dell", STAC_922X_DELL_D81),
1998 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1999 "unknown Dell", STAC_922X_DELL_D81),
2000 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2001 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002002 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002003 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002004 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002005 {} /* terminator */
2006};
2007
Matt Porter3cc08dc2006-01-23 15:27:49 +01002008static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002009 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2010 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2011 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2012 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002013};
2014
Tobin Davis93ed1502006-09-01 21:03:12 +02002015static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002016 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2017 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2018 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2019 0x40000100, 0x40000100
2020};
2021
Tobin Davis93ed1502006-09-01 21:03:12 +02002022static unsigned int d965_5st_pin_configs[14] = {
2023 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2024 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2025 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2026 0x40000100, 0x40000100
2027};
2028
Takashi Iwai679d92e2009-05-24 19:00:08 +02002029static unsigned int d965_5st_no_fp_pin_configs[14] = {
2030 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2031 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2032 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2033 0x40000100, 0x40000100
2034};
2035
Tobin Davis4ff076e2007-08-07 11:48:12 +02002036static unsigned int dell_3st_pin_configs[14] = {
2037 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2038 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002039 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002040 0x40c003fc, 0x40000100
2041};
2042
Tobin Davis93ed1502006-09-01 21:03:12 +02002043static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002044 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002045 [STAC_D965_REF] = ref927x_pin_configs,
2046 [STAC_D965_3ST] = d965_3st_pin_configs,
2047 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002048 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002049 [STAC_DELL_3ST] = dell_3st_pin_configs,
2050 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002051 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002052};
2053
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002054static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002055 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002056 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002057 [STAC_D965_REF] = "ref",
2058 [STAC_D965_3ST] = "3stack",
2059 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002060 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002061 [STAC_DELL_3ST] = "dell-3stack",
2062 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002063 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002064};
2065
2066static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2067 /* SigmaTel reference board */
2068 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2069 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002070 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2071 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002072 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002073 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2074 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002075 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002076 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2077 "Intel D965", STAC_D965_3ST),
2078 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2079 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002080 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002081 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002082 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002083 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2084 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002085 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002086 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2087 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002088 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002089 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002090 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2091 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2092 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002094 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002095 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2096 "Intel D965", STAC_D965_5ST),
2097 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2098 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002099 /* volume-knob fixes */
2100 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002101 {} /* terminator */
2102};
2103
Matt Porterf3302a52006-07-31 12:49:34 +02002104static unsigned int ref9205_pin_configs[12] = {
2105 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002106 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002107 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002108};
2109
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002110/*
2111 STAC 9205 pin configs for
2112 102801F1
2113 102801F2
2114 102801FC
2115 102801FD
2116 10280204
2117 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002118 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002119 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002120*/
2121static unsigned int dell_9205_m42_pin_configs[12] = {
2122 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2123 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2124 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2125};
2126
2127/*
2128 STAC 9205 pin configs for
2129 102801F9
2130 102801FA
2131 102801FE
2132 102801FF (Dell Precision M4300)
2133 10280206
2134 10280200
2135 10280201
2136*/
2137static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002138 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2139 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2140 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2141};
2142
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002143static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002144 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2145 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2146 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2147};
2148
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002149static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002150 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002151 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2152 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2153 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002154 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002155};
2156
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002157static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002158 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002159 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002160 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002161 [STAC_9205_DELL_M43] = "dell-m43",
2162 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002163 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002164};
2165
2166static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2167 /* SigmaTel reference board */
2168 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2169 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002170 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2171 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002172 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2173 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002174 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002175 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2176 "unknown Dell", STAC_9205_DELL_M42),
2177 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2178 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002179 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002180 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002181 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2182 "Dell Precision", STAC_9205_DELL_M43),
2183 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2184 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002185 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2186 "unknown Dell", STAC_9205_DELL_M42),
2187 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2188 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002189 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2190 "Dell Precision", STAC_9205_DELL_M43),
2191 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002192 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002193 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2194 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002195 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2196 "Dell Precision", STAC_9205_DELL_M43),
2197 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2198 "Dell Precision", STAC_9205_DELL_M43),
2199 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2200 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002201 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2202 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002203 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2204 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002205 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2206 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002207 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002208 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002209 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002210 {} /* terminator */
2211};
2212
Takashi Iwai330ee992009-02-20 14:33:36 +01002213static void stac92xx_set_config_regs(struct hda_codec *codec,
2214 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002215{
2216 int i;
2217 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002218
Takashi Iwai330ee992009-02-20 14:33:36 +01002219 if (!pincfgs)
2220 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002221
Matthew Ranostay87d48362007-07-17 11:52:24 +02002222 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002223 if (spec->pin_nids[i] && pincfgs[i])
2224 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2225 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002226}
2227
Matt2f2f4252005-04-13 14:45:30 +02002228/*
2229 * Analog playback callbacks
2230 */
2231static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2232 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002233 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002234{
2235 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002236 if (spec->stream_delay)
2237 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002238 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2239 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002240}
2241
2242static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2243 struct hda_codec *codec,
2244 unsigned int stream_tag,
2245 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002246 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002247{
2248 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002249 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002250}
2251
2252static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2253 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002254 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002255{
2256 struct sigmatel_spec *spec = codec->spec;
2257 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2258}
2259
2260/*
Mattdabbed62005-06-14 10:19:34 +02002261 * Digital playback callbacks
2262 */
2263static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2264 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002265 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002266{
2267 struct sigmatel_spec *spec = codec->spec;
2268 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2269}
2270
2271static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2272 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002273 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002274{
2275 struct sigmatel_spec *spec = codec->spec;
2276 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2277}
2278
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002279static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2280 struct hda_codec *codec,
2281 unsigned int stream_tag,
2282 unsigned int format,
2283 struct snd_pcm_substream *substream)
2284{
2285 struct sigmatel_spec *spec = codec->spec;
2286 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2287 stream_tag, format, substream);
2288}
2289
Takashi Iwai9411e212009-02-13 11:32:28 +01002290static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2291 struct hda_codec *codec,
2292 struct snd_pcm_substream *substream)
2293{
2294 struct sigmatel_spec *spec = codec->spec;
2295 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2296}
2297
Mattdabbed62005-06-14 10:19:34 +02002298
2299/*
Matt2f2f4252005-04-13 14:45:30 +02002300 * Analog capture callbacks
2301 */
2302static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2303 struct hda_codec *codec,
2304 unsigned int stream_tag,
2305 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002306 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002307{
2308 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002309 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002310
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002311 if (spec->powerdown_adcs) {
2312 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002313 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002314 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2315 }
2316 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002317 return 0;
2318}
2319
2320static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2321 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002322 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002323{
2324 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002325 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002326
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002327 snd_hda_codec_cleanup_stream(codec, nid);
2328 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002329 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002330 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002331 return 0;
2332}
2333
Mattdabbed62005-06-14 10:19:34 +02002334static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2335 .substreams = 1,
2336 .channels_min = 2,
2337 .channels_max = 2,
2338 /* NID is set in stac92xx_build_pcms */
2339 .ops = {
2340 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002341 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002342 .prepare = stac92xx_dig_playback_pcm_prepare,
2343 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002344 },
2345};
2346
2347static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2348 .substreams = 1,
2349 .channels_min = 2,
2350 .channels_max = 2,
2351 /* NID is set in stac92xx_build_pcms */
2352};
2353
Matt2f2f4252005-04-13 14:45:30 +02002354static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2355 .substreams = 1,
2356 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002357 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002358 .nid = 0x02, /* NID to query formats and rates */
2359 .ops = {
2360 .open = stac92xx_playback_pcm_open,
2361 .prepare = stac92xx_playback_pcm_prepare,
2362 .cleanup = stac92xx_playback_pcm_cleanup
2363 },
2364};
2365
Matt Porter3cc08dc2006-01-23 15:27:49 +01002366static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2367 .substreams = 1,
2368 .channels_min = 2,
2369 .channels_max = 2,
2370 .nid = 0x06, /* NID to query formats and rates */
2371 .ops = {
2372 .open = stac92xx_playback_pcm_open,
2373 .prepare = stac92xx_playback_pcm_prepare,
2374 .cleanup = stac92xx_playback_pcm_cleanup
2375 },
2376};
2377
Matt2f2f4252005-04-13 14:45:30 +02002378static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002379 .channels_min = 2,
2380 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002381 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002382 .ops = {
2383 .prepare = stac92xx_capture_pcm_prepare,
2384 .cleanup = stac92xx_capture_pcm_cleanup
2385 },
2386};
2387
2388static int stac92xx_build_pcms(struct hda_codec *codec)
2389{
2390 struct sigmatel_spec *spec = codec->spec;
2391 struct hda_pcm *info = spec->pcm_rec;
2392
2393 codec->num_pcms = 1;
2394 codec->pcm_info = info;
2395
Mattc7d4b2f2005-06-27 14:59:41 +02002396 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002397 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002398 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2399 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002400 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002401 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002402 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002403
2404 if (spec->alt_switch) {
2405 codec->num_pcms++;
2406 info++;
2407 info->name = "STAC92xx Analog Alt";
2408 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2409 }
Matt2f2f4252005-04-13 14:45:30 +02002410
Mattdabbed62005-06-14 10:19:34 +02002411 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2412 codec->num_pcms++;
2413 info++;
2414 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002415 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002416 if (spec->multiout.dig_out_nid) {
2417 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2418 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2419 }
2420 if (spec->dig_in_nid) {
2421 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2422 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2423 }
2424 }
2425
Matt2f2f4252005-04-13 14:45:30 +02002426 return 0;
2427}
2428
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002429static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2430 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002431{
Takashi Iwai1327a322009-03-23 13:07:47 +01002432 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002433 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2434 if (pincap & AC_PINCAP_VREF_100)
2435 return AC_PINCTL_VREF_100;
2436 if (pincap & AC_PINCAP_VREF_80)
2437 return AC_PINCTL_VREF_80;
2438 if (pincap & AC_PINCAP_VREF_50)
2439 return AC_PINCTL_VREF_50;
2440 if (pincap & AC_PINCAP_VREF_GRD)
2441 return AC_PINCTL_VREF_GRD;
2442 return 0;
2443}
2444
Matt Porter403d1942005-11-29 15:00:51 +01002445static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2446
2447{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002448 snd_hda_codec_write_cache(codec, nid, 0,
2449 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002450}
2451
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002452#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2453
2454static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2455 struct snd_ctl_elem_value *ucontrol)
2456{
2457 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2458 struct sigmatel_spec *spec = codec->spec;
2459
Takashi Iwaid7a89432008-11-12 09:48:04 +01002460 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002461 return 0;
2462}
2463
Takashi Iwai62558ce2009-07-29 14:23:09 +02002464static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002465
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002466static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2467 struct snd_ctl_elem_value *ucontrol)
2468{
2469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2470 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002471 int nid = kcontrol->private_value;
2472
2473 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002474
2475 /* check to be sure that the ports are upto date with
2476 * switch changes
2477 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002478 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002479
2480 return 1;
2481}
2482
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002483static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2484 struct snd_ctl_elem_info *uinfo)
2485{
2486 int i;
2487 static char *texts[] = {
2488 "Mic In", "Line In", "Line Out"
2489 };
2490
2491 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2492 struct sigmatel_spec *spec = codec->spec;
2493 hda_nid_t nid = kcontrol->private_value;
2494
2495 if (nid == spec->mic_switch || nid == spec->line_switch)
2496 i = 3;
2497 else
2498 i = 2;
2499
2500 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2501 uinfo->value.enumerated.items = i;
2502 uinfo->count = 1;
2503 if (uinfo->value.enumerated.item >= i)
2504 uinfo->value.enumerated.item = i-1;
2505 strcpy(uinfo->value.enumerated.name,
2506 texts[uinfo->value.enumerated.item]);
2507
2508 return 0;
2509}
2510
2511static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2512 struct snd_ctl_elem_value *ucontrol)
2513{
2514 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2515 hda_nid_t nid = kcontrol->private_value;
2516 unsigned int vref = stac92xx_vref_get(codec, nid);
2517
2518 if (vref == stac92xx_get_default_vref(codec, nid))
2519 ucontrol->value.enumerated.item[0] = 0;
2520 else if (vref == AC_PINCTL_VREF_GRD)
2521 ucontrol->value.enumerated.item[0] = 1;
2522 else if (vref == AC_PINCTL_VREF_HIZ)
2523 ucontrol->value.enumerated.item[0] = 2;
2524
2525 return 0;
2526}
2527
2528static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2529 struct snd_ctl_elem_value *ucontrol)
2530{
2531 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2532 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002533 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002534 hda_nid_t nid = kcontrol->private_value;
2535
2536 if (ucontrol->value.enumerated.item[0] == 0)
2537 new_vref = stac92xx_get_default_vref(codec, nid);
2538 else if (ucontrol->value.enumerated.item[0] == 1)
2539 new_vref = AC_PINCTL_VREF_GRD;
2540 else if (ucontrol->value.enumerated.item[0] == 2)
2541 new_vref = AC_PINCTL_VREF_HIZ;
2542 else
2543 return 0;
2544
2545 if (new_vref != stac92xx_vref_get(codec, nid)) {
2546 error = stac92xx_vref_set(codec, nid, new_vref);
2547 return error;
2548 }
2549
2550 return 0;
2551}
2552
2553static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2554 struct snd_ctl_elem_info *uinfo)
2555{
2556 static char *texts[2];
2557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2558 struct sigmatel_spec *spec = codec->spec;
2559
2560 if (kcontrol->private_value == spec->line_switch)
2561 texts[0] = "Line In";
2562 else
2563 texts[0] = "Mic In";
2564 texts[1] = "Line Out";
2565 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2566 uinfo->value.enumerated.items = 2;
2567 uinfo->count = 1;
2568
2569 if (uinfo->value.enumerated.item >= 2)
2570 uinfo->value.enumerated.item = 1;
2571 strcpy(uinfo->value.enumerated.name,
2572 texts[uinfo->value.enumerated.item]);
2573
2574 return 0;
2575}
Matt Porter403d1942005-11-29 15:00:51 +01002576
2577static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2578{
2579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2580 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002581 hda_nid_t nid = kcontrol->private_value;
2582 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002583
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002584 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002585 return 0;
2586}
2587
2588static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2589{
2590 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2591 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002592 hda_nid_t nid = kcontrol->private_value;
2593 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2594 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002595
2596 spec->io_switch[io_idx] = val;
2597
2598 if (val)
2599 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002600 else {
2601 unsigned int pinctl = AC_PINCTL_IN_EN;
2602 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002603 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002604 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2605 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002606
2607 /* check the auto-mute again: we need to mute/unmute the speaker
2608 * appropriately according to the pin direction
2609 */
2610 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002611 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002612
Matt Porter403d1942005-11-29 15:00:51 +01002613 return 1;
2614}
2615
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002616#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2617
2618static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2619 struct snd_ctl_elem_value *ucontrol)
2620{
2621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2622 struct sigmatel_spec *spec = codec->spec;
2623
2624 ucontrol->value.integer.value[0] = spec->clfe_swap;
2625 return 0;
2626}
2627
2628static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2629 struct snd_ctl_elem_value *ucontrol)
2630{
2631 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2632 struct sigmatel_spec *spec = codec->spec;
2633 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002634 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002635
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002636 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002637 return 0;
2638
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002639 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002640
2641 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2642 spec->clfe_swap ? 0x4 : 0x0);
2643
2644 return 1;
2645}
2646
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002647#define STAC_CODEC_HP_SWITCH(xname) \
2648 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2649 .name = xname, \
2650 .index = 0, \
2651 .info = stac92xx_hp_switch_info, \
2652 .get = stac92xx_hp_switch_get, \
2653 .put = stac92xx_hp_switch_put, \
2654 }
2655
Matt Porter403d1942005-11-29 15:00:51 +01002656#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2657 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2658 .name = xname, \
2659 .index = 0, \
2660 .info = stac92xx_io_switch_info, \
2661 .get = stac92xx_io_switch_get, \
2662 .put = stac92xx_io_switch_put, \
2663 .private_value = xpval, \
2664 }
2665
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002666#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2667 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2668 .name = xname, \
2669 .index = 0, \
2670 .info = stac92xx_clfe_switch_info, \
2671 .get = stac92xx_clfe_switch_get, \
2672 .put = stac92xx_clfe_switch_put, \
2673 .private_value = xpval, \
2674 }
Matt Porter403d1942005-11-29 15:00:51 +01002675
Mattc7d4b2f2005-06-27 14:59:41 +02002676enum {
2677 STAC_CTL_WIDGET_VOL,
2678 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002679 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002680 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002681 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002682 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002683 STAC_CTL_WIDGET_CLFE_SWITCH,
2684 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002685};
2686
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002687static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002688 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2689 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002690 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002691 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002692 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002693 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002694 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002695 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002696};
2697
2698/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002699static struct snd_kcontrol_new *
2700stac_control_new(struct sigmatel_spec *spec,
2701 struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002702 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002703 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002704{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002705 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002706
Takashi Iwai603c4012008-07-30 15:01:44 +02002707 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2708 knew = snd_array_new(&spec->kctls);
2709 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002710 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002711 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002712 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002713 if (!knew->name) {
2714 /* roolback */
2715 memset(knew, 0, sizeof(*knew));
2716 spec->kctls.alloced--;
2717 return NULL;
2718 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002719 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002720 return knew;
2721}
2722
2723static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2724 struct snd_kcontrol_new *ktemp,
2725 int idx, const char *name,
2726 unsigned long val)
2727{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002728 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002729 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002730 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002731 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002732 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002733 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002734 return 0;
2735}
2736
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002737static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2738 int type, int idx, const char *name,
2739 unsigned long val)
2740{
2741 return stac92xx_add_control_temp(spec,
2742 &stac92xx_control_templates[type],
2743 idx, name, val);
2744}
2745
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002746
2747/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002748static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2749 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002750{
2751 return stac92xx_add_control_idx(spec, type, 0, name, val);
2752}
2753
Takashi Iwaie3c75962009-01-23 11:57:22 +01002754static struct snd_kcontrol_new stac_input_src_temp = {
2755 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2756 .name = "Input Source",
2757 .info = stac92xx_mux_enum_info,
2758 .get = stac92xx_mux_enum_get,
2759 .put = stac92xx_mux_enum_put,
2760};
2761
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002762static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2763 hda_nid_t nid, int idx)
2764{
2765 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2766 int control = 0;
2767 struct sigmatel_spec *spec = codec->spec;
2768 char name[22];
2769
2770 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2771 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2772 && nid == spec->line_switch)
2773 control = STAC_CTL_WIDGET_IO_SWITCH;
2774 else if (snd_hda_query_pin_caps(codec, nid)
2775 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2776 control = STAC_CTL_WIDGET_DC_BIAS;
2777 else if (nid == spec->mic_switch)
2778 control = STAC_CTL_WIDGET_IO_SWITCH;
2779 }
2780
2781 if (control) {
2782 strcpy(name, auto_pin_cfg_labels[idx]);
2783 return stac92xx_add_control(codec->spec, control,
2784 strcat(name, " Jack Mode"), nid);
2785 }
2786
2787 return 0;
2788}
2789
Takashi Iwaie3c75962009-01-23 11:57:22 +01002790static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2791{
2792 struct snd_kcontrol_new *knew;
2793 struct hda_input_mux *imux = &spec->private_imux;
2794
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002795 if (spec->auto_mic)
2796 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002797 if (!spec->num_adcs || imux->num_items <= 1)
2798 return 0; /* no need for input source control */
2799 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002800 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002801 if (!knew)
2802 return -ENOMEM;
2803 knew->count = spec->num_adcs;
2804 return 0;
2805}
2806
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002807/* check whether the line-input can be used as line-out */
2808static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002809{
2810 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002811 struct auto_pin_cfg *cfg = &spec->autocfg;
2812 hda_nid_t nid;
2813 unsigned int pincap;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002814
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002815 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2816 return 0;
2817 nid = cfg->input_pins[AUTO_PIN_LINE];
Takashi Iwai1327a322009-03-23 13:07:47 +01002818 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002819 if (pincap & AC_PINCAP_OUT)
2820 return nid;
Matt Porter403d1942005-11-29 15:00:51 +01002821 return 0;
2822}
2823
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002824/* check whether the mic-input can be used as line-out */
2825static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2826{
2827 struct sigmatel_spec *spec = codec->spec;
2828 struct auto_pin_cfg *cfg = &spec->autocfg;
2829 unsigned int def_conf, pincap;
2830 unsigned int mic_pin;
2831
2832 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2833 return 0;
2834 mic_pin = AUTO_PIN_MIC;
2835 for (;;) {
2836 hda_nid_t nid = cfg->input_pins[mic_pin];
Takashi Iwai330ee992009-02-20 14:33:36 +01002837 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002838 /* some laptops have an internal analog microphone
2839 * which can't be used as a output */
2840 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai1327a322009-03-23 13:07:47 +01002841 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002842 if (pincap & AC_PINCAP_OUT)
2843 return nid;
2844 }
2845 if (mic_pin == AUTO_PIN_MIC)
2846 mic_pin = AUTO_PIN_FRONT_MIC;
2847 else
2848 break;
2849 }
2850 return 0;
2851}
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002852
2853static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2854{
2855 int i;
2856
2857 for (i = 0; i < spec->multiout.num_dacs; i++) {
2858 if (spec->multiout.dac_nids[i] == nid)
2859 return 1;
2860 }
2861
2862 return 0;
2863}
2864
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002865static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2866{
2867 int i;
2868 if (is_in_dac_nids(spec, nid))
2869 return 1;
2870 for (i = 0; i < spec->autocfg.hp_outs; i++)
2871 if (spec->hp_dacs[i] == nid)
2872 return 1;
2873 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2874 if (spec->speaker_dacs[i] == nid)
2875 return 1;
2876 return 0;
2877}
2878
2879static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2880{
2881 struct sigmatel_spec *spec = codec->spec;
2882 int j, conn_len;
2883 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2884 unsigned int wcaps, wtype;
2885
2886 conn_len = snd_hda_get_connections(codec, nid, conn,
2887 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002888 /* 92HD88: trace back up the link of nids to find the DAC */
2889 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2890 != AC_WID_AUD_OUT)) {
2891 nid = conn[0];
2892 conn_len = snd_hda_get_connections(codec, nid, conn,
2893 HDA_MAX_CONNECTIONS);
2894 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002895 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002896 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002897 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002898 /* we check only analog outputs */
2899 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2900 continue;
2901 /* if this route has a free DAC, assign it */
2902 if (!check_all_dac_nids(spec, conn[j])) {
2903 if (conn_len > 1) {
2904 /* select this DAC in the pin's input mux */
2905 snd_hda_codec_write_cache(codec, nid, 0,
2906 AC_VERB_SET_CONNECT_SEL, j);
2907 }
2908 return conn[j];
2909 }
2910 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002911 /* if all DACs are already assigned, connect to the primary DAC */
2912 if (conn_len > 1) {
2913 for (j = 0; j < conn_len; j++) {
2914 if (conn[j] == spec->multiout.dac_nids[0]) {
2915 snd_hda_codec_write_cache(codec, nid, 0,
2916 AC_VERB_SET_CONNECT_SEL, j);
2917 break;
2918 }
2919 }
2920 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002921 return 0;
2922}
2923
2924static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2925static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2926
Matt Porter3cc08dc2006-01-23 15:27:49 +01002927/*
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002928 * Fill in the dac_nids table from the parsed pin configuration
2929 * This function only works when every pin in line_out_pins[]
2930 * contains atleast one DAC in its connection list. Some 92xx
2931 * codecs are not connected directly to a DAC, such as the 9200
2932 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002933 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002934static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002935{
2936 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002937 struct auto_pin_cfg *cfg = &spec->autocfg;
2938 int i;
2939 hda_nid_t nid, dac;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002940
Mattc7d4b2f2005-06-27 14:59:41 +02002941 for (i = 0; i < cfg->line_outs; i++) {
2942 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002943 dac = get_unassigned_dac(codec, nid);
2944 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002945 if (spec->multiout.num_dacs > 0) {
2946 /* we have already working output pins,
2947 * so let's drop the broken ones again
2948 */
2949 cfg->line_outs = spec->multiout.num_dacs;
2950 break;
2951 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002952 /* error out, no available DAC found */
2953 snd_printk(KERN_ERR
2954 "%s: No available DAC for pin 0x%x\n",
2955 __func__, nid);
2956 return -ENODEV;
2957 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002958 add_spec_dacs(spec, dac);
2959 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02002960
Takashi Iwai139e0712009-03-06 12:10:41 +01002961 for (i = 0; i < cfg->hp_outs; i++) {
2962 nid = cfg->hp_pins[i];
2963 dac = get_unassigned_dac(codec, nid);
2964 if (dac) {
2965 if (!spec->multiout.hp_nid)
2966 spec->multiout.hp_nid = dac;
2967 else
2968 add_spec_extra_dacs(spec, dac);
2969 }
2970 spec->hp_dacs[i] = dac;
2971 }
2972
2973 for (i = 0; i < cfg->speaker_outs; i++) {
2974 nid = cfg->speaker_pins[i];
2975 dac = get_unassigned_dac(codec, nid);
2976 if (dac)
2977 add_spec_extra_dacs(spec, dac);
2978 spec->speaker_dacs[i] = dac;
2979 }
2980
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002981 /* add line-in as output */
2982 nid = check_line_out_switch(codec);
2983 if (nid) {
2984 dac = get_unassigned_dac(codec, nid);
2985 if (dac) {
2986 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2987 nid, cfg->line_outs);
2988 cfg->line_out_pins[cfg->line_outs] = nid;
2989 cfg->line_outs++;
2990 spec->line_switch = nid;
2991 add_spec_dacs(spec, dac);
2992 }
2993 }
2994 /* add mic as output */
2995 nid = check_mic_out_switch(codec);
2996 if (nid) {
2997 dac = get_unassigned_dac(codec, nid);
2998 if (dac) {
2999 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3000 nid, cfg->line_outs);
3001 cfg->line_out_pins[cfg->line_outs] = nid;
3002 cfg->line_outs++;
3003 spec->mic_switch = nid;
3004 add_spec_dacs(spec, dac);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003005 }
Mattc7d4b2f2005-06-27 14:59:41 +02003006 }
3007
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003008 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003009 spec->multiout.num_dacs,
3010 spec->multiout.dac_nids[0],
3011 spec->multiout.dac_nids[1],
3012 spec->multiout.dac_nids[2],
3013 spec->multiout.dac_nids[3],
3014 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003015
Mattc7d4b2f2005-06-27 14:59:41 +02003016 return 0;
3017}
3018
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003019/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003020static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3021 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003022{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003023 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003024 char name[32];
3025 int err;
3026
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003027 if (!spec->check_volume_offset) {
3028 unsigned int caps, step, nums, db_scale;
3029 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3030 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3031 AC_AMPCAP_STEP_SIZE_SHIFT;
3032 step = (step + 1) * 25; /* in .01dB unit */
3033 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3034 AC_AMPCAP_NUM_STEPS_SHIFT;
3035 db_scale = nums * step;
3036 /* if dB scale is over -64dB, and finer enough,
3037 * let's reduce it to half
3038 */
3039 if (db_scale > 6400 && nums >= 0x1f)
3040 spec->volume_offset = nums / 2;
3041 spec->check_volume_offset = 1;
3042 }
3043
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003044 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003045 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003046 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3047 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003048 if (err < 0)
3049 return err;
3050 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003051 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003052 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3053 if (err < 0)
3054 return err;
3055 return 0;
3056}
3057
Takashi Iwai668b9652009-03-06 10:13:24 +01003058#define create_controls(codec, pfx, nid, chs) \
3059 create_controls_idx(codec, pfx, 0, nid, chs)
3060
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003061static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3062{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003063 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003064 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3065 return 1;
3066 } else {
3067 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3068 spec->multiout.num_dacs++;
3069 }
3070 return 0;
3071}
3072
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003073static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003074{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003075 int i;
3076 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3077 if (!spec->multiout.extra_out_nid[i]) {
3078 spec->multiout.extra_out_nid[i] = nid;
3079 return 0;
3080 }
3081 }
3082 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3083 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003084}
3085
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003086/* Create output controls
3087 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3088 */
3089static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3090 const hda_nid_t *pins,
3091 const hda_nid_t *dac_nids,
3092 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003093{
Takashi Iwai76624532008-12-19 10:09:47 +01003094 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003095 static const char *chname[4] = {
3096 "Front", "Surround", NULL /*CLFE*/, "Side"
3097 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003098 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003099 int i, err;
3100 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003101
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003102 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003103 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3104 wid_caps = get_wcaps(codec, pins[i]);
3105 if (wid_caps & AC_WCAP_UNSOL_CAP)
3106 spec->hp_detect = 1;
3107 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003108 nid = dac_nids[i];
3109 if (!nid)
3110 continue;
3111 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003112 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003113 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003114 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003115 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003116 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003117 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003118 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003119
3120 wid_caps = get_wcaps(codec, nid);
3121
3122 if (wid_caps & AC_WCAP_LR_SWAP) {
3123 err = stac92xx_add_control(spec,
3124 STAC_CTL_WIDGET_CLFE_SWITCH,
3125 "Swap Center/LFE Playback Switch", nid);
3126
3127 if (err < 0)
3128 return err;
3129 }
3130
Mattc7d4b2f2005-06-27 14:59:41 +02003131 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003132 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003133 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003134 switch (type) {
3135 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003136 name = "Headphone";
3137 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003138 break;
3139 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003140 name = "Speaker";
3141 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003142 break;
3143 default:
3144 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003145 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003146 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003147 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003148 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003149 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003150 return err;
3151 }
3152 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003153 return 0;
3154}
3155
Takashi Iwai6479c632009-07-28 18:20:25 +02003156static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3157 unsigned long sw, int idx)
3158{
3159 int err;
3160 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003161 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003162 if (err < 0)
3163 return err;
3164 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003165 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003166 if (err < 0)
3167 return err;
3168 return 0;
3169}
3170
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003171/* add playback controls from the parsed DAC table */
3172static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3173 const struct auto_pin_cfg *cfg)
3174{
3175 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003176 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003177 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003178 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003179
3180 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3181 spec->multiout.dac_nids,
3182 cfg->line_out_type);
3183 if (err < 0)
3184 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003185
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003186 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003187 err = stac92xx_add_control(spec,
3188 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003189 "Headphone as Line Out Switch",
3190 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003191 if (err < 0)
3192 return err;
3193 }
3194
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003195 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3196 nid = cfg->input_pins[idx];
3197 if (nid) {
3198 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3199 if (err < 0)
3200 return err;
3201 }
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003202 }
Matt Porter403d1942005-11-29 15:00:51 +01003203
Mattc7d4b2f2005-06-27 14:59:41 +02003204 return 0;
3205}
3206
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003207/* add playback controls for Speaker and HP outputs */
3208static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3209 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003210{
3211 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003212 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003213
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003214 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3215 spec->hp_dacs, AUTO_PIN_HP_OUT);
3216 if (err < 0)
3217 return err;
3218
3219 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3220 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3221 if (err < 0)
3222 return err;
3223
Mattc7d4b2f2005-06-27 14:59:41 +02003224 return 0;
3225}
3226
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003227/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003228static const char *stac92xx_mono_labels[4] = {
3229 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003230};
3231
3232/* create mono mux for mono out on capable codecs */
3233static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3234{
3235 struct sigmatel_spec *spec = codec->spec;
3236 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3237 int i, num_cons;
3238 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3239
3240 num_cons = snd_hda_get_connections(codec,
3241 spec->mono_nid,
3242 con_lst,
3243 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003244 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003245 return -EINVAL;
3246
3247 for (i = 0; i < num_cons; i++) {
3248 mono_mux->items[mono_mux->num_items].label =
3249 stac92xx_mono_labels[i];
3250 mono_mux->items[mono_mux->num_items].index = i;
3251 mono_mux->num_items++;
3252 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003253
3254 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3255 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003256}
3257
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003258/* create PC beep volume controls */
3259static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3260 hda_nid_t nid)
3261{
3262 struct sigmatel_spec *spec = codec->spec;
3263 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003264 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3265
3266 if (spec->anabeep_nid == nid)
3267 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003268
3269 /* check for mute support for the the amp */
3270 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003271 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003272 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003273 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3274 if (err < 0)
3275 return err;
3276 }
3277
3278 /* check to see if there is volume support for the amp */
3279 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3280 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003281 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003282 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3283 if (err < 0)
3284 return err;
3285 }
3286 return 0;
3287}
3288
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003289#ifdef CONFIG_SND_HDA_INPUT_BEEP
3290#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3291
3292static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3293 struct snd_ctl_elem_value *ucontrol)
3294{
3295 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3296 ucontrol->value.integer.value[0] = codec->beep->enabled;
3297 return 0;
3298}
3299
3300static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3301 struct snd_ctl_elem_value *ucontrol)
3302{
3303 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003304 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003305}
3306
3307static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3308 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3309 .info = stac92xx_dig_beep_switch_info,
3310 .get = stac92xx_dig_beep_switch_get,
3311 .put = stac92xx_dig_beep_switch_put,
3312};
3313
3314static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3315{
3316 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003317 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003318}
3319#endif
3320
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003321static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3322{
3323 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003324 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003325
3326 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003327 hda_nid_t nid;
3328 unsigned int wcaps;
3329 unsigned long val;
3330
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003331 nid = spec->mux_nids[i];
3332 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003333 if (!(wcaps & AC_WCAP_OUT_AMP))
3334 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003335
Takashi Iwai667067d2009-08-13 18:14:42 +02003336 /* check whether already the same control was created as
3337 * normal Capture Volume.
3338 */
3339 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3340 for (j = 0; j < spec->num_caps; j++) {
3341 if (spec->capvols[j] == val)
3342 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003343 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003344 if (j < spec->num_caps)
3345 continue;
3346
3347 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3348 "Mux Capture Volume", val);
3349 if (err < 0)
3350 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003351 }
3352 return 0;
3353};
3354
Matthew Ranostayd9737752008-09-07 12:03:41 +02003355static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003356 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003357};
3358
3359static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3360{
3361 struct sigmatel_spec *spec = codec->spec;
3362 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003363 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003364 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003365 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003366
3367 num_cons = snd_hda_get_connections(codec,
3368 spec->smux_nids[0],
3369 con_lst,
3370 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003371 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003372 return -EINVAL;
3373
Matthew Ranostay65973632008-09-16 10:39:37 -04003374 if (!labels)
3375 labels = stac92xx_spdif_labels;
3376
Matthew Ranostayd9737752008-09-07 12:03:41 +02003377 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003378 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003379 spdif_mux->items[spdif_mux->num_items].index = i;
3380 spdif_mux->num_items++;
3381 }
3382
3383 return 0;
3384}
3385
Matt Porter8b657272006-10-26 17:12:59 +02003386/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003387static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003388 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3389 "Digital Mic 3", "Digital Mic 4"
3390};
3391
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003392static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3393 hda_nid_t nid)
3394{
3395 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3396 int i, nums;
3397
3398 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3399 for (i = 0; i < nums; i++)
3400 if (conn[i] == nid)
3401 return i;
3402 return -1;
3403}
3404
Takashi Iwai667067d2009-08-13 18:14:42 +02003405/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003406/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003407static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003408 const char *label, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003409{
3410 unsigned int caps, nums;
3411 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003412 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003413
Takashi Iwai96f845d2009-08-29 00:49:36 +02003414 if (direction == HDA_OUTPUT)
3415 caps = AC_WCAP_OUT_AMP;
3416 else
3417 caps = AC_WCAP_IN_AMP;
3418 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003419 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003420 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003421 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3422 if (!nums)
3423 return 0;
3424 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003425 err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3426 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3427 if (err < 0)
3428 return err;
3429 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003430}
3431
Matt Porter8b657272006-10-26 17:12:59 +02003432/* create playback/capture controls for input pins on dmic capable codecs */
3433static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3434 const struct auto_pin_cfg *cfg)
3435{
3436 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003437 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003438 struct hda_input_mux *dimux = &spec->private_dimux;
Takashi Iwai5207e102009-07-30 13:09:08 +02003439 int err, i, active_mics;
3440 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003441
3442 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3443 dimux->items[dimux->num_items].index = 0;
3444 dimux->num_items++;
3445
Takashi Iwai5207e102009-07-30 13:09:08 +02003446 active_mics = 0;
3447 for (i = 0; i < spec->num_dmics; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003448 /* check the validity: sometimes it's a dead vendor-spec node */
3449 if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3450 != AC_WID_PIN)
3451 continue;
Takashi Iwai5207e102009-07-30 13:09:08 +02003452 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3453 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3454 active_mics++;
3455 }
3456
Matt Porter8b657272006-10-26 17:12:59 +02003457 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003458 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003459 int index;
Takashi Iwai5207e102009-07-30 13:09:08 +02003460 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003461
Takashi Iwai667067d2009-08-13 18:14:42 +02003462 nid = spec->dmic_nids[i];
3463 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3464 continue;
3465 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003466 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3467 continue;
3468
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003469 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3470 if (index < 0)
3471 continue;
3472
Takashi Iwai5207e102009-07-30 13:09:08 +02003473 if (active_mics == 1)
3474 label = "Digital Mic";
3475 else
3476 label = stac92xx_dmic_labels[dimux->num_items];
3477
Takashi Iwai96f845d2009-08-29 00:49:36 +02003478 err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003479 if (err < 0)
3480 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003481 if (!err) {
3482 err = create_elem_capture_vol(codec, nid, label,
3483 HDA_OUTPUT);
3484 if (err < 0)
3485 return err;
3486 }
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003487
Takashi Iwai5207e102009-07-30 13:09:08 +02003488 dimux->items[dimux->num_items].label = label;
Matt Porter8b657272006-10-26 17:12:59 +02003489 dimux->items[dimux->num_items].index = index;
3490 dimux->num_items++;
Takashi Iwai5207e102009-07-30 13:09:08 +02003491 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3492 imux->items[imux->num_items].label = label;
3493 imux->items[imux->num_items].index = index;
3494 imux->num_items++;
3495 }
Matt Porter8b657272006-10-26 17:12:59 +02003496 }
3497
3498 return 0;
3499}
3500
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003501static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3502 hda_nid_t *fixed, hda_nid_t *ext)
3503{
3504 unsigned int cfg;
3505
3506 if (!nid)
3507 return 0;
3508 cfg = snd_hda_codec_get_pincfg(codec, nid);
3509 switch (get_defcfg_connect(cfg)) {
3510 case AC_JACK_PORT_FIXED:
3511 if (*fixed)
3512 return 1; /* already occupied */
3513 *fixed = nid;
3514 break;
3515 case AC_JACK_PORT_COMPLEX:
3516 if (*ext)
3517 return 1; /* already occupied */
3518 *ext = nid;
3519 break;
3520 }
3521 return 0;
3522}
3523
3524static int set_mic_route(struct hda_codec *codec,
3525 struct sigmatel_mic_route *mic,
3526 hda_nid_t pin)
3527{
3528 struct sigmatel_spec *spec = codec->spec;
3529 struct auto_pin_cfg *cfg = &spec->autocfg;
3530 int i;
3531
3532 mic->pin = pin;
3533 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3534 if (pin == cfg->input_pins[i])
3535 break;
3536 if (i <= AUTO_PIN_FRONT_MIC) {
3537 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003538 i = get_connection_index(codec, spec->mux_nids[0], pin);
3539 if (i < 0)
3540 return -1;
3541 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003542 mic->dmux_idx = -1;
3543 if (spec->dmux_nids)
3544 mic->dmux_idx = get_connection_index(codec,
3545 spec->dmux_nids[0],
3546 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003547 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003548 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003549 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3550 if (i < 0)
3551 return -1;
3552 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003553 mic->mux_idx = -1;
3554 if (spec->mux_nids)
3555 mic->mux_idx = get_connection_index(codec,
3556 spec->mux_nids[0],
3557 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003558 }
3559 return 0;
3560}
3561
3562/* return non-zero if the device is for automatic mic switch */
3563static int stac_check_auto_mic(struct hda_codec *codec)
3564{
3565 struct sigmatel_spec *spec = codec->spec;
3566 struct auto_pin_cfg *cfg = &spec->autocfg;
3567 hda_nid_t fixed, ext;
3568 int i;
3569
3570 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3571 if (cfg->input_pins[i])
3572 return 0; /* must be exclusively mics */
3573 }
3574 fixed = ext = 0;
3575 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3576 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3577 return 0;
3578 for (i = 0; i < spec->num_dmics; i++)
3579 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3580 return 0;
3581 if (!fixed || !ext)
3582 return 0;
3583 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3584 return 0; /* no unsol support */
3585 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3586 set_mic_route(codec, &spec->int_mic, fixed))
3587 return 0; /* something is wrong */
3588 return 1;
3589}
3590
Mattc7d4b2f2005-06-27 14:59:41 +02003591/* create playback/capture controls for input pins */
3592static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3593{
3594 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003595 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003596 int i, j;
Mattc7d4b2f2005-06-27 14:59:41 +02003597
3598 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003599 hda_nid_t nid = cfg->input_pins[i];
3600 int index, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003601
Takashi Iwai667067d2009-08-13 18:14:42 +02003602 if (!nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02003603 continue;
3604 index = -1;
3605 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003606 index = get_connection_index(codec, spec->mux_nids[j],
3607 nid);
3608 if (index >= 0)
3609 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003610 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003611 if (index < 0)
3612 continue;
3613
3614 err = create_elem_capture_vol(codec, nid,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003615 auto_pin_cfg_labels[i],
3616 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003617 if (err < 0)
3618 return err;
3619
Takashi Iwai314634b2006-09-21 11:56:18 +02003620 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3621 imux->items[imux->num_items].index = index;
3622 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003623 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003624 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003625
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003626 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003627 /*
3628 * Set the current input for the muxes.
3629 * The STAC9221 has two input muxes with identical source
3630 * NID lists. Hopefully this won't get confused.
3631 */
3632 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003633 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3634 AC_VERB_SET_CONNECT_SEL,
3635 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003636 }
3637 }
3638
Mattc7d4b2f2005-06-27 14:59:41 +02003639 return 0;
3640}
3641
Mattc7d4b2f2005-06-27 14:59:41 +02003642static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3643{
3644 struct sigmatel_spec *spec = codec->spec;
3645 int i;
3646
3647 for (i = 0; i < spec->autocfg.line_outs; i++) {
3648 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3649 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3650 }
3651}
3652
3653static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3654{
3655 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003656 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003657
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003658 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3659 hda_nid_t pin;
3660 pin = spec->autocfg.hp_pins[i];
3661 if (pin) /* connect to front */
3662 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3663 }
3664 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3665 hda_nid_t pin;
3666 pin = spec->autocfg.speaker_pins[i];
3667 if (pin) /* connect to front */
3668 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3669 }
Mattc7d4b2f2005-06-27 14:59:41 +02003670}
3671
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003672static int is_dual_headphones(struct hda_codec *codec)
3673{
3674 struct sigmatel_spec *spec = codec->spec;
3675 int i, valid_hps;
3676
3677 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3678 spec->autocfg.hp_outs <= 1)
3679 return 0;
3680 valid_hps = 0;
3681 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3682 hda_nid_t nid = spec->autocfg.hp_pins[i];
3683 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3684 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3685 continue;
3686 valid_hps++;
3687 }
3688 return (valid_hps > 1);
3689}
3690
3691
Matt Porter3cc08dc2006-01-23 15:27:49 +01003692static 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 +02003693{
3694 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003695 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003696 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003697
Matt Porter8b657272006-10-26 17:12:59 +02003698 if ((err = snd_hda_parse_pin_def_config(codec,
3699 &spec->autocfg,
3700 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003701 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003702 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003703 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003704
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003705 /* If we have no real line-out pin and multiple hp-outs, HPs should
3706 * be set up as multi-channel outputs.
3707 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003708 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003709 /* Copy hp_outs to line_outs, backup line_outs in
3710 * speaker_outs so that the following routines can handle
3711 * HP pins as primary outputs.
3712 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003713 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003714 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3715 sizeof(spec->autocfg.line_out_pins));
3716 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3717 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3718 sizeof(spec->autocfg.hp_pins));
3719 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003720 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3721 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003722 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003723 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003724 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003725 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3726 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003727 u32 caps = query_amp_caps(codec,
3728 spec->autocfg.mono_out_pin, dir);
3729 hda_nid_t conn_list[1];
3730
3731 /* get the mixer node and then the mono mux if it exists */
3732 if (snd_hda_get_connections(codec,
3733 spec->autocfg.mono_out_pin, conn_list, 1) &&
3734 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003735 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003736
3737 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003738 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003739 /* LR swap check, some stac925x have a mux that
3740 * changes the DACs output path instead of the
3741 * mono-mux path.
3742 */
3743 if (wid_type == AC_WID_AUD_SEL &&
3744 !(wcaps & AC_WCAP_LR_SWAP))
3745 spec->mono_nid = conn_list[0];
3746 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003747 if (dir) {
3748 hda_nid_t nid = spec->autocfg.mono_out_pin;
3749
3750 /* most mono outs have a least a mute/unmute switch */
3751 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3752 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3753 "Mono Playback Switch",
3754 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003755 if (err < 0)
3756 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003757 /* check for volume support for the amp */
3758 if ((caps & AC_AMPCAP_NUM_STEPS)
3759 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3760 err = stac92xx_add_control(spec,
3761 STAC_CTL_WIDGET_VOL,
3762 "Mono Playback Volume",
3763 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3764 if (err < 0)
3765 return err;
3766 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003767 }
3768
3769 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3770 AC_PINCTL_OUT_EN);
3771 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003772
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003773 if (!spec->multiout.num_dacs) {
3774 err = stac92xx_auto_fill_dac_nids(codec);
3775 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003776 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003777 err = stac92xx_auto_create_multi_out_ctls(codec,
3778 &spec->autocfg);
3779 if (err < 0)
3780 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003781 }
Mattc7d4b2f2005-06-27 14:59:41 +02003782
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003783 /* setup analog beep controls */
3784 if (spec->anabeep_nid > 0) {
3785 err = stac92xx_auto_create_beep_ctls(codec,
3786 spec->anabeep_nid);
3787 if (err < 0)
3788 return err;
3789 }
3790
3791 /* setup digital beep controls and input device */
3792#ifdef CONFIG_SND_HDA_INPUT_BEEP
3793 if (spec->digbeep_nid > 0) {
3794 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003795 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003796
3797 err = stac92xx_auto_create_beep_ctls(codec, nid);
3798 if (err < 0)
3799 return err;
3800 err = snd_hda_attach_beep_device(codec, nid);
3801 if (err < 0)
3802 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003803 if (codec->beep) {
3804 /* IDT/STAC codecs have linear beep tone parameter */
3805 codec->beep->linear_tone = 1;
3806 /* if no beep switch is available, make its own one */
3807 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3808 if (!(caps & AC_AMPCAP_MUTE)) {
3809 err = stac92xx_beep_switch_ctl(codec);
3810 if (err < 0)
3811 return err;
3812 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003813 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003814 }
3815#endif
3816
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003817 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003818 if (err < 0)
3819 return err;
3820
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003821 /* All output parsing done, now restore the swapped hp pins */
3822 if (hp_swap) {
3823 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3824 sizeof(spec->autocfg.hp_pins));
3825 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3826 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3827 spec->autocfg.line_outs = 0;
3828 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003829
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003830 if (stac_check_auto_mic(codec)) {
3831 spec->auto_mic = 1;
3832 /* only one capture for auto-mic */
3833 spec->num_adcs = 1;
3834 spec->num_caps = 1;
3835 spec->num_muxes = 1;
3836 }
3837
Takashi Iwai6479c632009-07-28 18:20:25 +02003838 for (i = 0; i < spec->num_caps; i++) {
3839 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3840 spec->capsws[i], i);
3841 if (err < 0)
3842 return err;
3843 }
3844
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003845 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003846 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003847 return err;
3848
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003849 if (spec->mono_nid > 0) {
3850 err = stac92xx_auto_create_mono_output_ctls(codec);
3851 if (err < 0)
3852 return err;
3853 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003854 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003855 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3856 &spec->autocfg)) < 0)
3857 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003858 if (spec->num_muxes > 0) {
3859 err = stac92xx_auto_create_mux_input_ctls(codec);
3860 if (err < 0)
3861 return err;
3862 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003863 if (spec->num_smuxes > 0) {
3864 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3865 if (err < 0)
3866 return err;
3867 }
Matt Porter8b657272006-10-26 17:12:59 +02003868
Takashi Iwaie3c75962009-01-23 11:57:22 +01003869 err = stac92xx_add_input_source(spec);
3870 if (err < 0)
3871 return err;
3872
Mattc7d4b2f2005-06-27 14:59:41 +02003873 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003874 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003875 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003876
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003877 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003878 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003879 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003880 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003881
Takashi Iwai603c4012008-07-30 15:01:44 +02003882 if (spec->kctls.list)
3883 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003884
3885 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003886 if (!spec->dinput_mux)
3887 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003888 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003889 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003890 return 1;
3891}
3892
Takashi Iwai82bc9552006-03-21 11:24:42 +01003893/* add playback controls for HP output */
3894static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3895 struct auto_pin_cfg *cfg)
3896{
3897 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003898 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003899 unsigned int wid_caps;
3900
3901 if (! pin)
3902 return 0;
3903
3904 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003905 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003906 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003907
3908 return 0;
3909}
3910
Richard Fish160ea0d2006-09-06 13:58:25 +02003911/* add playback controls for LFE output */
3912static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3913 struct auto_pin_cfg *cfg)
3914{
3915 struct sigmatel_spec *spec = codec->spec;
3916 int err;
3917 hda_nid_t lfe_pin = 0x0;
3918 int i;
3919
3920 /*
3921 * search speaker outs and line outs for a mono speaker pin
3922 * with an amp. If one is found, add LFE controls
3923 * for it.
3924 */
3925 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3926 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003927 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003928 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3929 if (wcaps == AC_WCAP_OUT_AMP)
3930 /* found a mono speaker with an amp, must be lfe */
3931 lfe_pin = pin;
3932 }
3933
3934 /* if speaker_outs is 0, then speakers may be in line_outs */
3935 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3936 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3937 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003938 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01003939 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01003940 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003941 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003942 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3943 if (wcaps == AC_WCAP_OUT_AMP)
3944 /* found a mono speaker with an amp,
3945 must be lfe */
3946 lfe_pin = pin;
3947 }
3948 }
3949 }
3950
3951 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003952 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003953 if (err < 0)
3954 return err;
3955 }
3956
3957 return 0;
3958}
3959
Mattc7d4b2f2005-06-27 14:59:41 +02003960static int stac9200_parse_auto_config(struct hda_codec *codec)
3961{
3962 struct sigmatel_spec *spec = codec->spec;
3963 int err;
3964
Kailang Yangdf694da2005-12-05 19:42:22 +01003965 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003966 return err;
3967
3968 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3969 return err;
3970
Takashi Iwai82bc9552006-03-21 11:24:42 +01003971 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3972 return err;
3973
Richard Fish160ea0d2006-09-06 13:58:25 +02003974 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3975 return err;
3976
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003977 if (spec->num_muxes > 0) {
3978 err = stac92xx_auto_create_mux_input_ctls(codec);
3979 if (err < 0)
3980 return err;
3981 }
3982
Takashi Iwaie3c75962009-01-23 11:57:22 +01003983 err = stac92xx_add_input_source(spec);
3984 if (err < 0)
3985 return err;
3986
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003987 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02003988 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003989 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003990 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003991
Takashi Iwai603c4012008-07-30 15:01:44 +02003992 if (spec->kctls.list)
3993 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003994
3995 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003996 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003997
3998 return 1;
3999}
4000
Sam Revitch62fe78e2006-05-10 15:09:17 +02004001/*
4002 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4003 * funky external mute control using GPIO pins.
4004 */
4005
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004006static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004007 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004008{
4009 unsigned int gpiostate, gpiomask, gpiodir;
4010
4011 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4012 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004013 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004014
4015 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4016 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004017 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004018
4019 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4020 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004021 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004022
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004023 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004024 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4025
4026 snd_hda_codec_write(codec, codec->afg, 0,
4027 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004028 snd_hda_codec_read(codec, codec->afg, 0,
4029 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004030
4031 msleep(1);
4032
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004033 snd_hda_codec_read(codec, codec->afg, 0,
4034 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004035}
4036
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004037#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +02004038static void stac92xx_free_jack_priv(struct snd_jack *jack)
4039{
4040 struct sigmatel_jack *jacks = jack->private_data;
4041 jacks->nid = 0;
4042 jacks->jack = NULL;
4043}
4044#endif
4045
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004046static int stac92xx_add_jack(struct hda_codec *codec,
4047 hda_nid_t nid, int type)
4048{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004049#ifdef CONFIG_SND_HDA_INPUT_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004050 struct sigmatel_spec *spec = codec->spec;
4051 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01004052 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004053 int connectivity = get_defcfg_connect(def_conf);
4054 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02004055 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004056
4057 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4058 return 0;
4059
4060 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4061 jack = snd_array_new(&spec->jacks);
4062 if (!jack)
4063 return -ENOMEM;
4064 jack->nid = nid;
4065 jack->type = type;
4066
Takashi Iwai86de7412009-07-22 16:02:46 +02004067 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004068 snd_hda_get_jack_type(def_conf),
4069 snd_hda_get_jack_connectivity(def_conf),
4070 snd_hda_get_jack_location(def_conf));
4071
Takashi Iwai95c09092009-04-14 16:15:29 +02004072 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4073 if (err < 0) {
4074 jack->nid = 0;
4075 return err;
4076 }
4077 jack->jack->private_data = jack;
4078 jack->jack->private_free = stac92xx_free_jack_priv;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004079#endif
Takashi Iwai95c09092009-04-14 16:15:29 +02004080 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004081}
4082
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004083static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4084 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004085{
4086 struct sigmatel_event *event;
4087
4088 snd_array_init(&spec->events, sizeof(*event), 32);
4089 event = snd_array_new(&spec->events);
4090 if (!event)
4091 return -ENOMEM;
4092 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004093 event->type = type;
4094 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004095 event->data = data;
4096
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004097 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004098}
4099
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004100static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004101 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004102{
4103 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004104 struct sigmatel_event *event = spec->events.list;
4105 int i;
4106
4107 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004108 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004109 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004110 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004111 return NULL;
4112}
4113
4114static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4115 unsigned char tag)
4116{
4117 struct sigmatel_spec *spec = codec->spec;
4118 struct sigmatel_event *event = spec->events.list;
4119 int i;
4120
4121 for (i = 0; i < spec->events.used; i++, event++) {
4122 if (event->tag == tag)
4123 return event;
4124 }
4125 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004126}
4127
Takashi Iwai62558ce2009-07-29 14:23:09 +02004128/* check if given nid is a valid pin and no other events are assigned
4129 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4130 * Otherwise, returns zero.
4131 */
4132static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4133 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004134{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004135 struct sigmatel_event *event;
4136 int tag;
4137
4138 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004139 return 0;
4140 event = stac_get_event(codec, nid);
4141 if (event) {
4142 if (event->type != type)
4143 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004144 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004145 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004146 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004147 if (tag < 0)
4148 return 0;
4149 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004150 snd_hda_codec_write_cache(codec, nid, 0,
4151 AC_VERB_SET_UNSOLICITED_ENABLE,
4152 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004153 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004154}
4155
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004156static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4157{
4158 int i;
4159 for (i = 0; i < cfg->hp_outs; i++)
4160 if (cfg->hp_pins[i] == nid)
4161 return 1; /* nid is a HP-Out */
4162
4163 return 0; /* nid is not a HP-Out */
4164};
4165
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004166static void stac92xx_power_down(struct hda_codec *codec)
4167{
4168 struct sigmatel_spec *spec = codec->spec;
4169
4170 /* power down inactive DACs */
4171 hda_nid_t *dac;
4172 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004173 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004174 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004175 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4176}
4177
Takashi Iwaif73d3582008-11-25 08:21:51 +01004178static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4179 int enable);
4180
Takashi Iwai014c41f2009-12-27 13:53:24 +01004181static inline int get_int_hint(struct hda_codec *codec, const char *key,
4182 int *valp)
4183{
4184 const char *p;
4185 p = snd_hda_get_hint(codec, key);
4186 if (p) {
4187 unsigned long val;
4188 if (!strict_strtoul(p, 0, &val)) {
4189 *valp = val;
4190 return 1;
4191 }
4192 }
4193 return 0;
4194}
4195
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004196/* override some hints from the hwdep entry */
4197static void stac_store_hints(struct hda_codec *codec)
4198{
4199 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004200 int val;
4201
4202 val = snd_hda_get_bool_hint(codec, "hp_detect");
4203 if (val >= 0)
4204 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004205 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004206 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4207 spec->gpio_mask;
4208 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004209 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4210 spec->gpio_mask &= spec->gpio_mask;
4211 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4212 spec->gpio_dir &= spec->gpio_mask;
4213 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4214 spec->eapd_mask &= spec->gpio_mask;
4215 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4216 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004217 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4218 if (val >= 0)
4219 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004220 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4221 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Takashi Iwai043958e2009-12-26 10:36:12 +01004222 spec->gpio_mask |= spec->gpio_led;
4223 spec->gpio_dir |= spec->gpio_led;
4224 if (spec->gpio_led_polarity)
4225 spec->gpio_data |= spec->gpio_led;
4226 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004227}
4228
Mattc7d4b2f2005-06-27 14:59:41 +02004229static int stac92xx_init(struct hda_codec *codec)
4230{
4231 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004232 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004233 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004234 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004235
Mattc7d4b2f2005-06-27 14:59:41 +02004236 snd_hda_sequence_write(codec, spec->init);
4237
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004238 /* power down adcs initially */
4239 if (spec->powerdown_adcs)
4240 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004241 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004242 spec->adc_nids[i], 0,
4243 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004244
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004245 /* override some hints */
4246 stac_store_hints(codec);
4247
Takashi Iwaif73d3582008-11-25 08:21:51 +01004248 /* set up GPIO */
4249 gpio = spec->gpio_data;
4250 /* turn on EAPD statically when spec->eapd_switch isn't set.
4251 * otherwise, unsol event will turn it on/off dynamically
4252 */
4253 if (!spec->eapd_switch)
4254 gpio |= spec->eapd_mask;
4255 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4256
Takashi Iwai82bc9552006-03-21 11:24:42 +01004257 /* set up pins */
4258 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004259 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004260 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004261 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004262 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004263 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004264 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4265 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004266 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004267 for (i = 0; i < cfg->line_outs; i++) {
4268 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004269 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4270 }
4271 }
4272
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004273 /* force to enable the first line-out; the others are set up
4274 * in unsol_event
4275 */
4276 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004277 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004278 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004279 if (cfg->hp_pins[0])
4280 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4281 else if (cfg->line_out_pins[0])
4282 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004283 } else {
4284 stac92xx_auto_init_multi_out(codec);
4285 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004286 for (i = 0; i < cfg->hp_outs; i++)
4287 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004288 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004289 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004290 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004291 if (spec->dmux_nids)
4292 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004293 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004294 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4295 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4296 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004297 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01004298 hda_nid_t nid = cfg->input_pins[i];
4299 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004300 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004301 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4302 /* for mic pins, force to initialize */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02004303 pinctl = stac92xx_get_default_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004304 pinctl |= AC_PINCTL_IN_EN;
4305 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004306 } else {
4307 pinctl = snd_hda_codec_read(codec, nid, 0,
4308 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4309 /* if PINCTL already set then skip */
Takashi Iwai5dd17cb2009-05-07 16:22:53 +02004310 /* Also, if both INPUT and OUTPUT are set,
4311 * it must be a BIOS bug; need to override, too
4312 */
4313 if (!(pinctl & AC_PINCTL_IN_EN) ||
4314 (pinctl & AC_PINCTL_OUT_EN)) {
4315 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004316 pinctl |= AC_PINCTL_IN_EN;
4317 stac92xx_auto_set_pinctl(codec, nid,
4318 pinctl);
4319 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004320 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004321 conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004322 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004323 if (enable_pin_detect(codec, nid,
4324 STAC_INSERT_EVENT))
4325 stac_issue_unsol_event(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004326 }
Takashi Iwaic960a032006-03-23 17:06:28 +01004327 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004328 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004329 for (i = 0; i < spec->num_dmics; i++)
4330 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4331 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004332 if (cfg->dig_out_pins[0])
4333 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004334 AC_PINCTL_OUT_EN);
4335 if (cfg->dig_in_pin)
4336 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4337 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004338 for (i = 0; i < spec->num_pwrs; i++) {
4339 hda_nid_t nid = spec->pwr_nids[i];
4340 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004341
Takashi Iwaieb632122008-12-19 16:39:48 +01004342 /* power on when no jack detection is available */
4343 if (!spec->hp_detect) {
4344 stac_toggle_power_map(codec, nid, 1);
4345 continue;
4346 }
4347
4348 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004349 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004350
Takashi Iwaif73d3582008-11-25 08:21:51 +01004351 pinctl = snd_hda_codec_read(codec, nid, 0,
4352 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4353 /* outputs are only ports capable of power management
4354 * any attempts on powering down a input port cause the
4355 * referenced VREF to act quirky.
4356 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004357 if (pinctl & AC_PINCTL_IN_EN) {
4358 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004359 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004360 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004361 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004362 def_conf = get_defcfg_connect(def_conf);
4363 /* skip any ports that don't have jacks since presence
4364 * detection is useless */
4365 if (def_conf != AC_JACK_PORT_COMPLEX) {
4366 if (def_conf != AC_JACK_PORT_NONE)
4367 stac_toggle_power_map(codec, nid, 1);
4368 continue;
4369 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004370 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4371 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004372 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004373
4374#ifdef CONFIG_SND_HDA_POWER_SAVE
4375 /* sync mute LED */
4376 if (spec->gpio_led && codec->patch_ops.check_power_status)
4377 codec->patch_ops.check_power_status(codec, 0x01);
4378#endif
Takashi Iwaif73d3582008-11-25 08:21:51 +01004379 if (spec->dac_list)
4380 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004381 return 0;
4382}
4383
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004384static void stac92xx_free_jacks(struct hda_codec *codec)
4385{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004386#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01004387 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004388 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01004389 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004390 struct sigmatel_jack *jacks = spec->jacks.list;
4391 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +02004392 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4393 if (jacks->jack)
4394 snd_device_free(codec->bus->card, jacks->jack);
4395 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004396 }
4397 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004398#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004399}
4400
Takashi Iwai603c4012008-07-30 15:01:44 +02004401static void stac92xx_free_kctls(struct hda_codec *codec)
4402{
4403 struct sigmatel_spec *spec = codec->spec;
4404
4405 if (spec->kctls.list) {
4406 struct snd_kcontrol_new *kctl = spec->kctls.list;
4407 int i;
4408 for (i = 0; i < spec->kctls.used; i++)
4409 kfree(kctl[i].name);
4410 }
4411 snd_array_free(&spec->kctls);
4412}
4413
Takashi Iwai167eae52009-11-06 15:47:50 +01004414static void stac92xx_shutup(struct hda_codec *codec)
4415{
4416 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004417
Takashi Iwai92ee6162009-12-27 11:18:59 +01004418 snd_hda_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004419
4420 if (spec->eapd_mask)
4421 stac_gpio_set(codec, spec->gpio_mask,
4422 spec->gpio_dir, spec->gpio_data &
4423 ~spec->eapd_mask);
4424}
4425
Matt2f2f4252005-04-13 14:45:30 +02004426static void stac92xx_free(struct hda_codec *codec)
4427{
Mattc7d4b2f2005-06-27 14:59:41 +02004428 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004429
4430 if (! spec)
4431 return;
4432
Takashi Iwai167eae52009-11-06 15:47:50 +01004433 stac92xx_shutup(codec);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004434 stac92xx_free_jacks(codec);
4435 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004436
Mattc7d4b2f2005-06-27 14:59:41 +02004437 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004438 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004439}
4440
Matt4e550962005-07-04 17:51:39 +02004441static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4442 unsigned int flag)
4443{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004444 unsigned int old_ctl, pin_ctl;
4445
4446 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004447 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004448
Takashi Iwaif9acba42007-05-29 18:01:06 +02004449 if (pin_ctl & AC_PINCTL_IN_EN) {
4450 /*
4451 * we need to check the current set-up direction of
4452 * shared input pins since they can be switched via
4453 * "xxx as Output" mixer switch
4454 */
4455 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004456 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004457 return;
4458 }
4459
Takashi Iwai8ce84192009-01-22 16:59:20 +01004460 old_ctl = pin_ctl;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004461 /* if setting pin direction bits, clear the current
4462 direction bits first */
4463 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4464 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4465
Takashi Iwai8ce84192009-01-22 16:59:20 +01004466 pin_ctl |= flag;
4467 if (old_ctl != pin_ctl)
4468 snd_hda_codec_write_cache(codec, nid, 0,
4469 AC_VERB_SET_PIN_WIDGET_CONTROL,
4470 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004471}
4472
4473static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4474 unsigned int flag)
4475{
4476 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4477 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004478 if (pin_ctl & flag)
4479 snd_hda_codec_write_cache(codec, nid, 0,
4480 AC_VERB_SET_PIN_WIDGET_CONTROL,
4481 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004482}
4483
Takashi Iwaid56757a2009-11-18 08:00:14 +01004484static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004485{
4486 if (!nid)
4487 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004488 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004489}
4490
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004491static void stac92xx_line_out_detect(struct hda_codec *codec,
4492 int presence)
4493{
4494 struct sigmatel_spec *spec = codec->spec;
4495 struct auto_pin_cfg *cfg = &spec->autocfg;
4496 int i;
4497
4498 for (i = 0; i < cfg->line_outs; i++) {
4499 if (presence)
4500 break;
4501 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4502 if (presence) {
4503 unsigned int pinctl;
4504 pinctl = snd_hda_codec_read(codec,
4505 cfg->line_out_pins[i], 0,
4506 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4507 if (pinctl & AC_PINCTL_IN_EN)
4508 presence = 0; /* mic- or line-input */
4509 }
4510 }
4511
4512 if (presence) {
4513 /* disable speakers */
4514 for (i = 0; i < cfg->speaker_outs; i++)
4515 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4516 AC_PINCTL_OUT_EN);
4517 if (spec->eapd_mask && spec->eapd_switch)
4518 stac_gpio_set(codec, spec->gpio_mask,
4519 spec->gpio_dir, spec->gpio_data &
4520 ~spec->eapd_mask);
4521 } else {
4522 /* enable speakers */
4523 for (i = 0; i < cfg->speaker_outs; i++)
4524 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4525 AC_PINCTL_OUT_EN);
4526 if (spec->eapd_mask && spec->eapd_switch)
4527 stac_gpio_set(codec, spec->gpio_mask,
4528 spec->gpio_dir, spec->gpio_data |
4529 spec->eapd_mask);
4530 }
4531}
4532
Takashi Iwaid7a89432008-11-12 09:48:04 +01004533/* return non-zero if the hp-pin of the given array index isn't
4534 * a jack-detection target
4535 */
4536static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4537{
4538 struct auto_pin_cfg *cfg = &spec->autocfg;
4539
4540 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004541 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004542 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004543 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004544 return 1;
4545 /* ignore if the pin is set as line-out */
4546 if (cfg->hp_pins[i] == spec->hp_switch)
4547 return 1;
4548 return 0;
4549}
4550
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004551static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004552{
4553 struct sigmatel_spec *spec = codec->spec;
4554 struct auto_pin_cfg *cfg = &spec->autocfg;
4555 int i, presence;
4556
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004557 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004558 if (spec->gpio_mute)
4559 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4560 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4561
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004562 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004563 if (presence)
4564 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004565 if (no_hp_sensing(spec, i))
4566 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004567 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4568 if (presence) {
4569 unsigned int pinctl;
4570 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4571 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4572 if (pinctl & AC_PINCTL_IN_EN)
4573 presence = 0; /* mic- or line-input */
4574 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004575 }
Matt4e550962005-07-04 17:51:39 +02004576
4577 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004578 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004579 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004580 stac92xx_reset_pinctl(codec, spec->hp_switch,
4581 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004582 for (i = 0; i < cfg->line_outs; i++)
4583 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4584 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004585 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004586 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004587 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004588 stac92xx_set_pinctl(codec, spec->hp_switch,
4589 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004590 for (i = 0; i < cfg->line_outs; i++)
4591 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4592 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004593 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004594 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004595 /* toggle hp outs */
4596 for (i = 0; i < cfg->hp_outs; i++) {
4597 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4598 if (no_hp_sensing(spec, i))
4599 continue;
4600 if (presence)
4601 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004602#if 0 /* FIXME */
4603/* Resetting the pinctl like below may lead to (a sort of) regressions
4604 * on some devices since they use the HP pin actually for line/speaker
4605 * outs although the default pin config shows a different pin (that is
4606 * wrong and useless).
4607 *
4608 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4609 * But, disabling the code below just works around it, and I'm too tired of
4610 * bug reports with such devices...
4611 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004612 else
4613 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004614#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004615 }
Matt4e550962005-07-04 17:51:39 +02004616}
4617
Takashi Iwaif73d3582008-11-25 08:21:51 +01004618static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4619 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004620{
4621 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004622 unsigned int idx, val;
4623
4624 for (idx = 0; idx < spec->num_pwrs; idx++) {
4625 if (spec->pwr_nids[idx] == nid)
4626 break;
4627 }
4628 if (idx >= spec->num_pwrs)
4629 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004630
4631 /* several codecs have two power down bits */
4632 if (spec->pwr_mapping)
4633 idx = spec->pwr_mapping[idx];
4634 else
4635 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004636
Takashi Iwaif73d3582008-11-25 08:21:51 +01004637 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4638 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004639 val &= ~idx;
4640 else
4641 val |= idx;
4642
4643 /* power down unused output ports */
4644 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004645}
4646
Takashi Iwaif73d3582008-11-25 08:21:51 +01004647static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4648{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004649 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004650}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004651
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004652static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4653{
4654 struct sigmatel_spec *spec = codec->spec;
4655 struct sigmatel_jack *jacks = spec->jacks.list;
4656
4657 if (jacks) {
4658 int i;
4659 for (i = 0; i < spec->jacks.used; i++) {
4660 if (jacks->nid == nid) {
4661 unsigned int pin_ctl =
4662 snd_hda_codec_read(codec, nid,
4663 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4664 0x00);
4665 int type = jacks->type;
4666 if (type == (SND_JACK_LINEOUT
4667 | SND_JACK_HEADPHONE))
4668 type = (pin_ctl & AC_PINCTL_HP_EN)
4669 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4670 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004671 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004672 ? type : 0);
4673 }
4674 jacks++;
4675 }
4676 }
4677}
Matt2f2f4252005-04-13 14:45:30 +02004678
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004679static void stac92xx_mic_detect(struct hda_codec *codec)
4680{
4681 struct sigmatel_spec *spec = codec->spec;
4682 struct sigmatel_mic_route *mic;
4683
4684 if (get_pin_presence(codec, spec->ext_mic.pin))
4685 mic = &spec->ext_mic;
4686 else
4687 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004688 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004689 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4690 AC_VERB_SET_CONNECT_SEL,
4691 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004692 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004693 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4694 AC_VERB_SET_CONNECT_SEL,
4695 mic->mux_idx);
4696}
4697
Takashi Iwai62558ce2009-07-29 14:23:09 +02004698static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004699{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004700 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004701 if (!event)
4702 return;
4703 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4704}
4705
Takashi Iwai314634b2006-09-21 11:56:18 +02004706static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4707{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004708 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004709 struct sigmatel_event *event;
4710 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004711
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004712 tag = (res >> 26) & 0x7f;
4713 event = stac_get_event_from_tag(codec, tag);
4714 if (!event)
4715 return;
4716
4717 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004718 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004719 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004720 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004721 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004722 case STAC_MIC_EVENT:
4723 stac92xx_mic_detect(codec);
4724 break;
4725 }
4726
4727 switch (event->type) {
4728 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004729 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004730 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004731 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004732 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004733 if (spec->num_pwrs > 0)
4734 stac92xx_pin_sense(codec, event->nid);
4735 stac92xx_report_jack(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004736
4737 switch (codec->subsystem_id) {
4738 case 0x103c308f:
4739 if (event->nid == 0xb) {
4740 int pin = AC_PINCTL_IN_EN;
4741
4742 if (get_pin_presence(codec, 0xa)
4743 && get_pin_presence(codec, 0xb))
4744 pin |= AC_PINCTL_VREF_80;
4745 if (!get_pin_presence(codec, 0xb))
4746 pin |= AC_PINCTL_VREF_80;
4747
4748 /* toggle VREF state based on mic + hp pin
4749 * status
4750 */
4751 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4752 }
4753 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004754 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004755 case STAC_VREF_EVENT:
4756 data = snd_hda_codec_read(codec, codec->afg, 0,
4757 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004758 /* toggle VREF state based on GPIOx status */
4759 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004760 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004761 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004762 }
4763}
4764
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304765static int hp_blike_system(u32 subsystem_id);
4766
4767static void set_hp_led_gpio(struct hda_codec *codec)
4768{
4769 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004770 unsigned int gpio;
4771
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004772 if (spec->gpio_led)
4773 return;
4774
Takashi Iwai07f80442010-02-08 15:06:13 +01004775 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4776 gpio &= AC_GPIO_IO_COUNT;
4777 if (gpio > 3)
4778 spec->gpio_led = 0x08; /* GPIO 3 */
4779 else
4780 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304781}
4782
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004783/*
4784 * This method searches for the mute LED GPIO configuration
4785 * provided as OEM string in SMBIOS. The format of that string
4786 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4787 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4788 * that corresponds to the NOT muted state of the master volume
4789 * and G is the index of the GPIO to use as the mute LED control (0..9)
4790 * If _G portion is missing it is assigned based on the codec ID
4791 *
4792 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4793 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304794 *
4795 *
4796 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4797 * SMBIOS - at least the ones I have seen do not have them - which include
4798 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4799 * HP Pavilion dv9500t CTO.
4800 * Need more information on whether it is true across the entire series.
4801 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004802 */
Takashi Iwaidce17d42010-02-09 09:25:26 +01004803static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004804{
4805 struct sigmatel_spec *spec = codec->spec;
4806 const struct dmi_device *dev = NULL;
4807
4808 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4809 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4810 NULL, dev))) {
4811 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304812 &spec->gpio_led_polarity,
4813 &spec->gpio_led) == 2) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004814 spec->gpio_led = 1 << spec->gpio_led;
4815 return 1;
4816 }
4817 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304818 &spec->gpio_led_polarity) == 1) {
4819 set_hp_led_gpio(codec);
4820 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004821 }
4822 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304823
4824 /*
4825 * Fallback case - if we don't find the DMI strings,
4826 * we statically set the GPIO - if not a B-series system.
4827 */
4828 if (!hp_blike_system(codec->subsystem_id)) {
4829 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004830 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304831 return 1;
4832 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004833 }
4834 return 0;
4835}
4836
4837static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004838{
4839 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004840 case 0x103c1520:
4841 case 0x103c1521:
4842 case 0x103c1523:
4843 case 0x103c1524:
4844 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004845 case 0x103c1722:
4846 case 0x103c1723:
4847 case 0x103c1724:
4848 case 0x103c1725:
4849 case 0x103c1726:
4850 case 0x103c1727:
4851 case 0x103c1728:
4852 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004853 case 0x103c172a:
4854 case 0x103c172b:
4855 case 0x103c307e:
4856 case 0x103c307f:
4857 case 0x103c3080:
4858 case 0x103c3081:
4859 case 0x103c7007:
4860 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004861 return 1;
4862 }
4863 return 0;
4864}
4865
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004866#ifdef CONFIG_PROC_FS
4867static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4868 struct hda_codec *codec, hda_nid_t nid)
4869{
4870 if (nid == codec->afg)
4871 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4872 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4873}
4874
4875static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4876 struct hda_codec *codec,
4877 unsigned int verb)
4878{
4879 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4880 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4881}
4882
4883/* stac92hd71bxx, stac92hd73xx */
4884static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4885 struct hda_codec *codec, hda_nid_t nid)
4886{
4887 stac92hd_proc_hook(buffer, codec, nid);
4888 if (nid == codec->afg)
4889 analog_loop_proc_hook(buffer, codec, 0xfa0);
4890}
4891
4892static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4893 struct hda_codec *codec, hda_nid_t nid)
4894{
4895 if (nid == codec->afg)
4896 analog_loop_proc_hook(buffer, codec, 0xfe0);
4897}
4898
4899static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4900 struct hda_codec *codec, hda_nid_t nid)
4901{
4902 if (nid == codec->afg)
4903 analog_loop_proc_hook(buffer, codec, 0xfeb);
4904}
4905#else
4906#define stac92hd_proc_hook NULL
4907#define stac92hd7x_proc_hook NULL
4908#define stac9205_proc_hook NULL
4909#define stac927x_proc_hook NULL
4910#endif
4911
Takashi Iwaicb53c622007-08-10 17:21:45 +02004912#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004913static int stac92xx_resume(struct hda_codec *codec)
4914{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004915 struct sigmatel_spec *spec = codec->spec;
4916
Takashi Iwai2c885872008-11-18 09:36:55 +01004917 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004918 snd_hda_codec_resume_amp(codec);
4919 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004920 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004921 if (spec->hp_detect) {
4922 if (spec->autocfg.hp_pins[0])
4923 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4924 else if (spec->autocfg.line_out_pins[0])
4925 stac_issue_unsol_event(codec,
4926 spec->autocfg.line_out_pins[0]);
4927 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004928#ifdef CONFIG_SND_HDA_POWER_SAVE
4929 /* sync mute LED */
4930 if (spec->gpio_led && codec->patch_ops.check_power_status)
4931 codec->patch_ops.check_power_status(codec, 0x01);
4932#endif
Mattff6fdc32005-06-27 15:06:52 +02004933 return 0;
4934}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004935
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004936/*
James Gardiner514bf542009-05-03 04:00:44 -04004937 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004938 * check for mute state only on Speakers (nid = 0x10)
4939 *
4940 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4941 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004942 *
4943 * Changed name to reflect that it now works for any designated
4944 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004945 */
4946
4947#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004948static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004949 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004950{
4951 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21bd022010-02-08 15:16:08 +01004952 int i, muted = 1;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004953
Takashi Iwaic21bd022010-02-08 15:16:08 +01004954 for (i = 0; i < spec->multiout.num_dacs; i++) {
4955 nid = spec->multiout.dac_nids[i];
4956 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4957 HDA_AMP_MUTE)) {
4958 muted = 0; /* something heard */
4959 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01004960 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004961 }
4962 if (muted)
4963 spec->gpio_data &= ~spec->gpio_led; /* orange */
4964 else
4965 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01004966
Takashi Iwaic21bd022010-02-08 15:16:08 +01004967 if (!spec->gpio_led_polarity) {
4968 /* LED state is inverted on these systems */
4969 spec->gpio_data ^= spec->gpio_led;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004970 }
4971
Takashi Iwaib4e81872009-11-18 17:20:24 +01004972 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
Takashi Iwaib4e81872009-11-18 17:20:24 +01004973 return 0;
4974}
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004975#endif
4976
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004977static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4978{
Takashi Iwai167eae52009-11-06 15:47:50 +01004979 stac92xx_shutup(codec);
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004980 return 0;
4981}
Mattff6fdc32005-06-27 15:06:52 +02004982#endif
4983
Matt2f2f4252005-04-13 14:45:30 +02004984static struct hda_codec_ops stac92xx_patch_ops = {
4985 .build_controls = stac92xx_build_controls,
4986 .build_pcms = stac92xx_build_pcms,
4987 .init = stac92xx_init,
4988 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004989 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004990#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004991 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004992 .resume = stac92xx_resume,
4993#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01004994 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02004995};
4996
4997static int patch_stac9200(struct hda_codec *codec)
4998{
4999 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005000 int err;
Matt2f2f4252005-04-13 14:45:30 +02005001
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005002 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005003 if (spec == NULL)
5004 return -ENOMEM;
5005
Takashi Iwaia252c812009-12-25 22:56:20 +01005006 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005007 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005008 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005009 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005010 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5011 stac9200_models,
5012 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005013 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005014 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5015 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005016 else
5017 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005018 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005019
5020 spec->multiout.max_channels = 2;
5021 spec->multiout.num_dacs = 1;
5022 spec->multiout.dac_nids = stac9200_dac_nids;
5023 spec->adc_nids = stac9200_adc_nids;
5024 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005025 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005026 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005027 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005028 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005029
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005030 if (spec->board_config == STAC_9200_M4 ||
5031 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005032 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005033 spec->init = stac9200_eapd_init;
5034 else
5035 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005036 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005037
Takashi Iwai117f2572008-03-18 09:53:23 +01005038 if (spec->board_config == STAC_9200_PANASONIC) {
5039 spec->gpio_mask = spec->gpio_dir = 0x09;
5040 spec->gpio_data = 0x00;
5041 }
5042
Mattc7d4b2f2005-06-27 14:59:41 +02005043 err = stac9200_parse_auto_config(codec);
5044 if (err < 0) {
5045 stac92xx_free(codec);
5046 return err;
5047 }
Matt2f2f4252005-04-13 14:45:30 +02005048
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005049 /* CF-74 has no headphone detection, and the driver should *NOT*
5050 * do detection and HP/speaker toggle because the hardware does it.
5051 */
5052 if (spec->board_config == STAC_9200_PANASONIC)
5053 spec->hp_detect = 0;
5054
Matt2f2f4252005-04-13 14:45:30 +02005055 codec->patch_ops = stac92xx_patch_ops;
5056
5057 return 0;
5058}
5059
Tobin Davis8e21c342007-01-08 11:04:17 +01005060static int patch_stac925x(struct hda_codec *codec)
5061{
5062 struct sigmatel_spec *spec;
5063 int err;
5064
5065 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5066 if (spec == NULL)
5067 return -ENOMEM;
5068
Takashi Iwaia252c812009-12-25 22:56:20 +01005069 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005070 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005071 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005072 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005073
5074 /* Check first for codec ID */
5075 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5076 STAC_925x_MODELS,
5077 stac925x_models,
5078 stac925x_codec_id_cfg_tbl);
5079
5080 /* Now checks for PCI ID, if codec ID is not found */
5081 if (spec->board_config < 0)
5082 spec->board_config = snd_hda_check_board_config(codec,
5083 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005084 stac925x_models,
5085 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005086 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005087 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005088 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5089 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005090 else
5091 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005092 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005093
5094 spec->multiout.max_channels = 2;
5095 spec->multiout.num_dacs = 1;
5096 spec->multiout.dac_nids = stac925x_dac_nids;
5097 spec->adc_nids = stac925x_adc_nids;
5098 spec->mux_nids = stac925x_mux_nids;
5099 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005100 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005101 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005102 switch (codec->vendor_id) {
5103 case 0x83847632: /* STAC9202 */
5104 case 0x83847633: /* STAC9202D */
5105 case 0x83847636: /* STAC9251 */
5106 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005107 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005108 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005109 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5110 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005111 break;
5112 default:
5113 spec->num_dmics = 0;
5114 break;
5115 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005116
5117 spec->init = stac925x_core_init;
5118 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005119 spec->num_caps = 1;
5120 spec->capvols = stac925x_capvols;
5121 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005122
5123 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005124 if (!err) {
5125 if (spec->board_config < 0) {
5126 printk(KERN_WARNING "hda_codec: No auto-config is "
5127 "available, default to model=ref\n");
5128 spec->board_config = STAC_925x_REF;
5129 goto again;
5130 }
5131 err = -EINVAL;
5132 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005133 if (err < 0) {
5134 stac92xx_free(codec);
5135 return err;
5136 }
5137
5138 codec->patch_ops = stac92xx_patch_ops;
5139
5140 return 0;
5141}
5142
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005143static int patch_stac92hd73xx(struct hda_codec *codec)
5144{
5145 struct sigmatel_spec *spec;
5146 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5147 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005148 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005149
5150 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5151 if (spec == NULL)
5152 return -ENOMEM;
5153
Takashi Iwaia252c812009-12-25 22:56:20 +01005154 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005155 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005156 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005157 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5158 spec->pin_nids = stac92hd73xx_pin_nids;
5159 spec->board_config = snd_hda_check_board_config(codec,
5160 STAC_92HD73XX_MODELS,
5161 stac92hd73xx_models,
5162 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005163 /* check codec subsystem id if not found */
5164 if (spec->board_config < 0)
5165 spec->board_config =
5166 snd_hda_check_board_codec_sid_config(codec,
5167 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5168 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005169again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005170 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005171 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5172 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005173 else
5174 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005175 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005176
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005177 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005178 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5179
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005180 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005181 printk(KERN_WARNING "hda_codec: Could not determine "
5182 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005183 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005184 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005185 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005186 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005187 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005188 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005189 break;
5190 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005191 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005192 break;
5193 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005194 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5195 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005196 }
5197 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005198
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005199 spec->aloopback_mask = 0x01;
5200 spec->aloopback_shift = 8;
5201
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005202 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005203 spec->mux_nids = stac92hd73xx_mux_nids;
5204 spec->adc_nids = stac92hd73xx_adc_nids;
5205 spec->dmic_nids = stac92hd73xx_dmic_nids;
5206 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005207 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005208
5209 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5210 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005211 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005212
Takashi Iwai6479c632009-07-28 18:20:25 +02005213 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5214 spec->capvols = stac92hd73xx_capvols;
5215 spec->capsws = stac92hd73xx_capsws;
5216
Matthew Ranostaya7662642008-02-21 07:51:14 +01005217 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005218 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005219 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005220 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005221 case STAC_DELL_M6_AMIC:
5222 case STAC_DELL_M6_DMIC:
5223 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005224 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005225 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005226
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005227 switch (spec->board_config) {
5228 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005229 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005230 spec->num_dmics = 0;
5231 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005232 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005233 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005234 spec->num_dmics = 1;
5235 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005236 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005237 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5238 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005239 spec->num_dmics = 1;
5240 break;
5241 }
5242 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005243 case STAC_ALIENWARE_M17X:
5244 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5245 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5246 spec->eapd_switch = 0;
5247 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005248 default:
5249 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005250 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005251 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005252 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005253 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005254 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005255 /* GPIO0 High = Enable EAPD */
5256 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5257 spec->gpio_data = 0x01;
5258 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005259
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005260 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5261 spec->pwr_nids = stac92hd73xx_pwr_nids;
5262
Matthew Ranostayd9737752008-09-07 12:03:41 +02005263 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005264
5265 if (!err) {
5266 if (spec->board_config < 0) {
5267 printk(KERN_WARNING "hda_codec: No auto-config is "
5268 "available, default to model=ref\n");
5269 spec->board_config = STAC_92HD73XX_REF;
5270 goto again;
5271 }
5272 err = -EINVAL;
5273 }
5274
5275 if (err < 0) {
5276 stac92xx_free(codec);
5277 return err;
5278 }
5279
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005280 if (spec->board_config == STAC_92HD73XX_NO_JD)
5281 spec->hp_detect = 0;
5282
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005283 codec->patch_ops = stac92xx_patch_ops;
5284
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005285 codec->proc_widget_hook = stac92hd7x_proc_hook;
5286
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005287 return 0;
5288}
5289
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005290static int patch_stac92hd83xxx(struct hda_codec *codec)
5291{
5292 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005293 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005294 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005295 int num_dacs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005296
5297 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5298 if (spec == NULL)
5299 return -ENOMEM;
5300
Takashi Iwaia252c812009-12-25 22:56:20 +01005301 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005302 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005303 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005304 spec->digbeep_nid = 0x21;
Takashi Iwai667067d2009-08-13 18:14:42 +02005305 spec->mux_nids = stac92hd83xxx_mux_nids;
5306 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005307 spec->adc_nids = stac92hd83xxx_adc_nids;
Takashi Iwai7570ef12009-08-15 11:57:53 +02005308 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005309 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5310 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5311 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005312 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005313
5314 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005315 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005316 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005317 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5318 spec->capvols = stac92hd83xxx_capvols;
5319 spec->capsws = stac92hd83xxx_capsws;
5320
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005321 spec->board_config = snd_hda_check_board_config(codec,
5322 STAC_92HD83XXX_MODELS,
5323 stac92hd83xxx_models,
5324 stac92hd83xxx_cfg_tbl);
5325again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005326 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005327 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5328 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005329 else
5330 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005331 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005332
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005333 switch (codec->vendor_id) {
Charles Chin36706002010-01-29 12:05:51 +01005334 case 0x111d7666:
5335 case 0x111d7667:
5336 case 0x111d7668:
5337 case 0x111d7669:
5338 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5339 spec->pin_nids = stac92hd88xxx_pin_nids;
5340 spec->mono_nid = 0;
5341 spec->digbeep_nid = 0;
5342 spec->num_pwrs = 0;
5343 break;
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005344 case 0x111d7604:
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01005345 case 0x111d76d4:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005346 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005347 case 0x111d76d5:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005348 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5349 break;
5350 spec->num_pwrs = 0;
5351 break;
5352 }
5353
Takashi Iwaib4e81872009-11-18 17:20:24 +01005354 codec->patch_ops = stac92xx_patch_ops;
5355
Takashi Iwaidce17d42010-02-09 09:25:26 +01005356 if (find_mute_led_gpio(codec, 0))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005357 snd_printd("mute LED gpio %d polarity %d\n",
5358 spec->gpio_led,
5359 spec->gpio_led_polarity);
5360
Takashi Iwaib4e81872009-11-18 17:20:24 +01005361#ifdef CONFIG_SND_HDA_POWER_SAVE
5362 if (spec->gpio_led) {
5363 spec->gpio_mask |= spec->gpio_led;
5364 spec->gpio_dir |= spec->gpio_led;
5365 spec->gpio_data |= spec->gpio_led;
5366 /* register check_power_status callback. */
5367 codec->patch_ops.check_power_status =
Takashi Iwaic21bd022010-02-08 15:16:08 +01005368 stac92xx_hp_check_power_status;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005369 }
5370#endif
5371
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005372 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5373 if (!err) {
5374 if (spec->board_config < 0) {
5375 printk(KERN_WARNING "hda_codec: No auto-config is "
5376 "available, default to model=ref\n");
5377 spec->board_config = STAC_92HD83XXX_REF;
5378 goto again;
5379 }
5380 err = -EINVAL;
5381 }
5382
5383 if (err < 0) {
5384 stac92xx_free(codec);
5385 return err;
5386 }
5387
Charles Chin04b5efe2010-02-04 10:28:02 +01005388 /* docking output support */
5389 num_dacs = snd_hda_get_connections(codec, 0xF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005390 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Charles Chin04b5efe2010-02-04 10:28:02 +01005391 /* skip non-DAC connections */
5392 while (num_dacs >= 0 &&
5393 (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5394 != AC_WID_AUD_OUT))
5395 num_dacs--;
5396 /* set port E and F to select the last DAC */
5397 if (num_dacs >= 0) {
5398 snd_hda_codec_write_cache(codec, 0xE, 0,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005399 AC_VERB_SET_CONNECT_SEL, num_dacs);
Charles Chin04b5efe2010-02-04 10:28:02 +01005400 snd_hda_codec_write_cache(codec, 0xF, 0,
5401 AC_VERB_SET_CONNECT_SEL, num_dacs);
5402 }
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005403
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005404 codec->proc_widget_hook = stac92hd_proc_hook;
5405
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005406 return 0;
5407}
5408
Takashi Iwai330ee992009-02-20 14:33:36 +01005409/* get the pin connection (fixed, none, etc) */
5410static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5411{
5412 struct sigmatel_spec *spec = codec->spec;
5413 unsigned int cfg;
5414
5415 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5416 return get_defcfg_connect(cfg);
5417}
5418
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005419static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5420 hda_nid_t *nids, int num_nids)
5421{
5422 struct sigmatel_spec *spec = codec->spec;
5423 int idx, num;
5424 unsigned int def_conf;
5425
5426 for (num = 0; num < num_nids; num++) {
5427 for (idx = 0; idx < spec->num_pins; idx++)
5428 if (spec->pin_nids[idx] == nids[num])
5429 break;
5430 if (idx >= spec->num_pins)
5431 break;
Takashi Iwai330ee992009-02-20 14:33:36 +01005432 def_conf = stac_get_defcfg_connect(codec, idx);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005433 if (def_conf == AC_JACK_PORT_NONE)
5434 break;
5435 }
5436 return num;
5437}
5438
5439static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5440 hda_nid_t dig0pin)
5441{
5442 struct sigmatel_spec *spec = codec->spec;
5443 int idx;
5444
5445 for (idx = 0; idx < spec->num_pins; idx++)
5446 if (spec->pin_nids[idx] == dig0pin)
5447 break;
5448 if ((idx + 2) >= spec->num_pins)
5449 return 0;
5450
5451 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005452 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005453 return 2;
5454
5455 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005456 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005457 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005458 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005459 return 1;
5460 else
5461 return 0;
5462}
5463
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005464/* HP dv7 bass switch - GPIO5 */
5465#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5466static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5467 struct snd_ctl_elem_value *ucontrol)
5468{
5469 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5470 struct sigmatel_spec *spec = codec->spec;
5471 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5472 return 0;
5473}
5474
5475static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5476 struct snd_ctl_elem_value *ucontrol)
5477{
5478 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5479 struct sigmatel_spec *spec = codec->spec;
5480 unsigned int gpio_data;
5481
5482 gpio_data = (spec->gpio_data & ~0x20) |
5483 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5484 if (gpio_data == spec->gpio_data)
5485 return 0;
5486 spec->gpio_data = gpio_data;
5487 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5488 return 1;
5489}
5490
5491static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5492 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5493 .info = stac_hp_bass_gpio_info,
5494 .get = stac_hp_bass_gpio_get,
5495 .put = stac_hp_bass_gpio_put,
5496};
5497
5498static int stac_add_hp_bass_switch(struct hda_codec *codec)
5499{
5500 struct sigmatel_spec *spec = codec->spec;
5501
5502 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5503 "Bass Speaker Playback Switch", 0))
5504 return -ENOMEM;
5505
5506 spec->gpio_mask |= 0x20;
5507 spec->gpio_dir |= 0x20;
5508 spec->gpio_data |= 0x20;
5509 return 0;
5510}
5511
Matthew Ranostaye035b842007-11-06 11:53:55 +01005512static int patch_stac92hd71bxx(struct hda_codec *codec)
5513{
5514 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005515 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005516 unsigned int pin_cfg;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005517 int err = 0;
5518
5519 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5520 if (spec == NULL)
5521 return -ENOMEM;
5522
Takashi Iwaia252c812009-12-25 22:56:20 +01005523 codec->no_trigger_sense = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005524 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005525 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005526 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5527 switch (codec->vendor_id) {
5528 case 0x111d76b6:
5529 case 0x111d76b7:
5530 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5531 break;
5532 case 0x111d7603:
5533 case 0x111d7608:
5534 /* On 92HD75Bx 0x27 isn't a pin nid */
5535 spec->num_pins--;
5536 /* fallthrough */
5537 default:
5538 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5539 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005540 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005541 spec->board_config = snd_hda_check_board_config(codec,
5542 STAC_92HD71BXX_MODELS,
5543 stac92hd71bxx_models,
5544 stac92hd71bxx_cfg_tbl);
5545again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005546 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005547 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5548 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005549 else
5550 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005551 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005552
Takashi Iwaifc64b262009-09-14 15:33:01 +02005553 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005554 /* GPIO0 = EAPD */
5555 spec->gpio_mask = 0x01;
5556 spec->gpio_dir = 0x01;
5557 spec->gpio_data = 0x01;
5558 }
5559
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005560 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5561 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5562
Takashi Iwai6479c632009-07-28 18:20:25 +02005563 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5564 spec->capvols = stac92hd71bxx_capvols;
5565 spec->capsws = stac92hd71bxx_capsws;
5566
Matthew Ranostay541eee82007-12-14 12:08:04 +01005567 switch (codec->vendor_id) {
5568 case 0x111d76b6: /* 4 Port without Analog Mixer */
5569 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005570 unmute_init++;
5571 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005572 case 0x111d76b4: /* 6 Port without Analog Mixer */
5573 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005574 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005575 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005576 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5577 stac92hd71bxx_dmic_nids,
5578 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005579 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005580 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005581 switch (spec->board_config) {
5582 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005583 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005584 err = stac_add_event(spec, codec->afg,
5585 STAC_VREF_EVENT, 0x02);
5586 if (err < 0)
5587 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005588 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005589 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5590 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005591 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005592 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005593 spec->gpio_mask |= 0x02;
5594 break;
5595 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005596 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005597 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005598 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005599
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005600 /* no output amps */
5601 spec->num_pwrs = 0;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005602 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005603 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005604 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005605 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5606 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005607 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5608 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5609 stac92hd71bxx_dmic_nids,
5610 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005611 break;
5612 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005613 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005614 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005615
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005616 /* no output amps */
5617 spec->num_pwrs = 0;
5618 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005619 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005620 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005621 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005622 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5623 stac92hd71bxx_dmic_nids,
5624 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005625 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005626 }
5627
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005628 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5629 snd_hda_sequence_write_cache(codec, unmute_init);
5630
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005631 /* Some HP machines seem to have unstable codec communications
5632 * especially with ATI fglrx driver. For recovering from the
5633 * CORB/RIRB stall, allow the BUS reset and keep always sync
5634 */
5635 if (spec->board_config == STAC_HP_DV5) {
5636 codec->bus->sync_write = 1;
5637 codec->bus->allow_bus_reset = 1;
5638 }
5639
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005640 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005641 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005642 spec->aloopback_shift = 0;
5643
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005644 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005645 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005646 spec->mux_nids = stac92hd71bxx_mux_nids;
5647 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005648 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005649 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005650
5651 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5652 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005653 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005654 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005655
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305656 snd_printdd("Found board config: %d\n", spec->board_config);
5657
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005658 switch (spec->board_config) {
5659 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005660 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005661 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005662 stac92xx_auto_set_pinctl(codec, 0x0e,
5663 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005664 /* fallthru */
5665 case STAC_DELL_M4_2:
5666 spec->num_dmics = 0;
5667 spec->num_smuxes = 0;
5668 spec->num_dmuxes = 0;
5669 break;
5670 case STAC_DELL_M4_1:
5671 case STAC_DELL_M4_3:
5672 spec->num_dmics = 1;
5673 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005674 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005675 break;
James Gardiner514bf542009-05-03 04:00:44 -04005676 case STAC_HP_DV4_1222NR:
5677 spec->num_dmics = 1;
5678 /* I don't know if it needs 1 or 2 smuxes - will wait for
5679 * bug reports to fix if needed
5680 */
5681 spec->num_smuxes = 1;
5682 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005683 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005684 case STAC_HP_DV4:
5685 spec->gpio_led = 0x01;
5686 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005687 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005688 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005689 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005690 /* HP dv6 gives the headphone pin as a line-out. Thus we
5691 * need to set hp_detect flag here to force to enable HP
5692 * detection.
5693 */
5694 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005695 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005696 case STAC_HP_HDX:
5697 spec->num_dmics = 1;
5698 spec->num_dmuxes = 1;
5699 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005700 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005701 break;
5702 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005703
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005704 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005705 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5706 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5707 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5708 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5709 /* It was changed in the BIOS to just satisfy MS DTM.
5710 * Lets turn it back into slaved HP
5711 */
5712 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5713 | (AC_JACK_HP_OUT <<
5714 AC_DEFCFG_DEVICE_SHIFT);
5715 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5716 | AC_DEFCFG_SEQUENCE)))
5717 | 0x1f;
5718 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5719 }
5720 }
5721
Takashi Iwaidce17d42010-02-09 09:25:26 +01005722 if (find_mute_led_gpio(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005723 snd_printd("mute LED gpio %d polarity %d\n",
5724 spec->gpio_led,
5725 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005726
Takashi Iwai86d190e2009-05-26 15:18:58 +02005727#ifdef CONFIG_SND_HDA_POWER_SAVE
5728 if (spec->gpio_led) {
5729 spec->gpio_mask |= spec->gpio_led;
5730 spec->gpio_dir |= spec->gpio_led;
5731 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005732 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005733 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005734 stac92xx_hp_check_power_status;
5735 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005736#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005737
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005738 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005739
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005740 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005741 if (!err) {
5742 if (spec->board_config < 0) {
5743 printk(KERN_WARNING "hda_codec: No auto-config is "
5744 "available, default to model=ref\n");
5745 spec->board_config = STAC_92HD71BXX_REF;
5746 goto again;
5747 }
5748 err = -EINVAL;
5749 }
5750
5751 if (err < 0) {
5752 stac92xx_free(codec);
5753 return err;
5754 }
5755
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005756 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005757 if (spec->board_config == STAC_HP_DV4 ||
5758 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005759 unsigned int cap;
5760 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5761 cap &= AC_GPIO_IO_COUNT;
5762 if (cap >= 6)
5763 stac_add_hp_bass_switch(codec);
5764 }
5765
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005766 codec->proc_widget_hook = stac92hd7x_proc_hook;
5767
Matthew Ranostaye035b842007-11-06 11:53:55 +01005768 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005769}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005770
Matt2f2f4252005-04-13 14:45:30 +02005771static int patch_stac922x(struct hda_codec *codec)
5772{
5773 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005774 int err;
Matt2f2f4252005-04-13 14:45:30 +02005775
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005776 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005777 if (spec == NULL)
5778 return -ENOMEM;
5779
Takashi Iwaia252c812009-12-25 22:56:20 +01005780 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005781 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005782 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005783 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005784 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5785 stac922x_models,
5786 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005787 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005788 spec->gpio_mask = spec->gpio_dir = 0x03;
5789 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005790 /* Intel Macs have all same PCI SSID, so we need to check
5791 * codec SSID to distinguish the exact models
5792 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005793 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005794 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005795
5796 case 0x106b0800:
5797 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005798 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005799 case 0x106b0600:
5800 case 0x106b0700:
5801 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005802 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005803 case 0x106b0e00:
5804 case 0x106b0f00:
5805 case 0x106b1600:
5806 case 0x106b1700:
5807 case 0x106b0200:
5808 case 0x106b1e00:
5809 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005810 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005811 case 0x106b1a00:
5812 case 0x00000100:
5813 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005814 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005815 case 0x106b0a00:
5816 case 0x106b2200:
5817 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005818 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005819 default:
5820 spec->board_config = STAC_INTEL_MAC_V3;
5821 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005822 }
5823 }
5824
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005825 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005826 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005827 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5828 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005829 else
5830 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005831 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005832
Matt2f2f4252005-04-13 14:45:30 +02005833 spec->adc_nids = stac922x_adc_nids;
5834 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005835 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005836 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005837 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005838 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005839
5840 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005841
5842 spec->num_caps = STAC922X_NUM_CAPS;
5843 spec->capvols = stac922x_capvols;
5844 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005845
5846 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005847
Matt Porter3cc08dc2006-01-23 15:27:49 +01005848 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005849 if (!err) {
5850 if (spec->board_config < 0) {
5851 printk(KERN_WARNING "hda_codec: No auto-config is "
5852 "available, default to model=ref\n");
5853 spec->board_config = STAC_D945_REF;
5854 goto again;
5855 }
5856 err = -EINVAL;
5857 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005858 if (err < 0) {
5859 stac92xx_free(codec);
5860 return err;
5861 }
5862
5863 codec->patch_ops = stac92xx_patch_ops;
5864
Takashi Iwai807a46362007-05-29 19:01:37 +02005865 /* Fix Mux capture level; max to 2 */
5866 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5867 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5868 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5869 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5870 (0 << AC_AMPCAP_MUTE_SHIFT));
5871
Matt Porter3cc08dc2006-01-23 15:27:49 +01005872 return 0;
5873}
5874
5875static int patch_stac927x(struct hda_codec *codec)
5876{
5877 struct sigmatel_spec *spec;
5878 int err;
5879
5880 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5881 if (spec == NULL)
5882 return -ENOMEM;
5883
Takashi Iwaia252c812009-12-25 22:56:20 +01005884 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005885 codec->spec = spec;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005886 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005887 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005888 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005889 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5890 stac927x_models,
5891 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005892 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005893 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005894 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5895 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005896 else
5897 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005898 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005899
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005900 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005901 spec->adc_nids = stac927x_adc_nids;
5902 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5903 spec->mux_nids = stac927x_mux_nids;
5904 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005905 spec->smux_nids = stac927x_smux_nids;
5906 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005907 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005908 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005909 spec->multiout.dac_nids = spec->dac_nids;
5910
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005911 if (spec->board_config != STAC_D965_REF) {
5912 /* GPIO0 High = Enable EAPD */
5913 spec->eapd_mask = spec->gpio_mask = 0x01;
5914 spec->gpio_dir = spec->gpio_data = 0x01;
5915 }
5916
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005917 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005918 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005919 case STAC_D965_5ST:
5920 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005921 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02005922 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005923 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005924 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005925 switch (codec->subsystem_id) {
5926 case 0x10280209:
5927 case 0x1028022e:
5928 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005929 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005930 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005931 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005932 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005933 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005934 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005935 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005936 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005937 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005938 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005939 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005940 if (codec->subsystem_id != 0x1028022f) {
5941 /* GPIO2 High = Enable EAPD */
5942 spec->eapd_mask = spec->gpio_mask = 0x04;
5943 spec->gpio_dir = spec->gpio_data = 0x04;
5944 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005945 spec->dmic_nids = stac927x_dmic_nids;
5946 spec->num_dmics = STAC927X_NUM_DMICS;
5947
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02005948 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005949 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005950 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005951 break;
Takashi Iwai54930532009-10-11 17:38:29 +02005952 case STAC_927X_VOLKNOB:
5953 spec->num_dmics = 0;
5954 spec->init = stac927x_volknob_core_init;
5955 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005956 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005957 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005958 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005959 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005960 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005961
Takashi Iwai6479c632009-07-28 18:20:25 +02005962 spec->num_caps = STAC927X_NUM_CAPS;
5963 spec->capvols = stac927x_capvols;
5964 spec->capsws = stac927x_capsws;
5965
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005966 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005967 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005968 spec->aloopback_mask = 0x40;
5969 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005970 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005971
Matt Porter3cc08dc2006-01-23 15:27:49 +01005972 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005973 if (!err) {
5974 if (spec->board_config < 0) {
5975 printk(KERN_WARNING "hda_codec: No auto-config is "
5976 "available, default to model=ref\n");
5977 spec->board_config = STAC_D965_REF;
5978 goto again;
5979 }
5980 err = -EINVAL;
5981 }
Mattc7d4b2f2005-06-27 14:59:41 +02005982 if (err < 0) {
5983 stac92xx_free(codec);
5984 return err;
5985 }
Matt2f2f4252005-04-13 14:45:30 +02005986
5987 codec->patch_ops = stac92xx_patch_ops;
5988
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005989 codec->proc_widget_hook = stac927x_proc_hook;
5990
Takashi Iwai52987652008-01-16 16:09:47 +01005991 /*
5992 * !!FIXME!!
5993 * The STAC927x seem to require fairly long delays for certain
5994 * command sequences. With too short delays (even if the answer
5995 * is set to RIRB properly), it results in the silence output
5996 * on some hardwares like Dell.
5997 *
5998 * The below flag enables the longer delay (see get_response
5999 * in hda_intel.c).
6000 */
6001 codec->bus->needs_damn_long_delay = 1;
6002
Takashi Iwaie28d8322008-12-17 13:48:29 +01006003 /* no jack detecion for ref-no-jd model */
6004 if (spec->board_config == STAC_D965_REF_NO_JD)
6005 spec->hp_detect = 0;
6006
Matt2f2f4252005-04-13 14:45:30 +02006007 return 0;
6008}
6009
Matt Porterf3302a52006-07-31 12:49:34 +02006010static int patch_stac9205(struct hda_codec *codec)
6011{
6012 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006013 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006014
6015 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6016 if (spec == NULL)
6017 return -ENOMEM;
6018
Takashi Iwaia252c812009-12-25 22:56:20 +01006019 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006020 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006021 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006022 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006023 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6024 stac9205_models,
6025 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006026 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006027 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006028 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6029 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006030 else
6031 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006032 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006033
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006034 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006035 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006036 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006037 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006038 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006039 spec->smux_nids = stac9205_smux_nids;
6040 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006041 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006042 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006043 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006044 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006045 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006046
6047 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006048 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006049
Takashi Iwai6479c632009-07-28 18:20:25 +02006050 spec->num_caps = STAC9205_NUM_CAPS;
6051 spec->capvols = stac9205_capvols;
6052 spec->capsws = stac9205_capsws;
6053
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006054 spec->aloopback_mask = 0x40;
6055 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006056 /* Turn on/off EAPD per HP plugging */
6057 if (spec->board_config != STAC_9205_EAPD)
6058 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006059 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006060
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006061 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006062 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006063 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006064 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6065 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006066
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006067 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006068 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6069 if (err < 0)
6070 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006071 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006072 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6073 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006074 AC_VERB_SET_UNSOLICITED_ENABLE,
6075 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006076
6077 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006078 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006079 spec->gpio_mask = 0x1b;
6080 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006081 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006082 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006083 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006084 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006085 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006086 case STAC_9205_REF:
6087 /* SPDIF-In enabled */
6088 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006089 default:
6090 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006091 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006092 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006093 break;
6094 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006095
Matt Porterf3302a52006-07-31 12:49:34 +02006096 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006097 if (!err) {
6098 if (spec->board_config < 0) {
6099 printk(KERN_WARNING "hda_codec: No auto-config is "
6100 "available, default to model=ref\n");
6101 spec->board_config = STAC_9205_REF;
6102 goto again;
6103 }
6104 err = -EINVAL;
6105 }
Matt Porterf3302a52006-07-31 12:49:34 +02006106 if (err < 0) {
6107 stac92xx_free(codec);
6108 return err;
6109 }
6110
6111 codec->patch_ops = stac92xx_patch_ops;
6112
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006113 codec->proc_widget_hook = stac9205_proc_hook;
6114
Matt Porterf3302a52006-07-31 12:49:34 +02006115 return 0;
6116}
6117
Matt2f2f4252005-04-13 14:45:30 +02006118/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006119 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006120 */
6121
Takashi Iwai1e137f92009-01-21 07:41:22 +01006122static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006123 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006124 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6125 {}
6126};
6127
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006128static hda_nid_t stac9872_pin_nids[] = {
6129 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6130 0x11, 0x13, 0x14,
6131};
6132
6133static hda_nid_t stac9872_adc_nids[] = {
6134 0x8 /*,0x6*/
6135};
6136
6137static hda_nid_t stac9872_mux_nids[] = {
6138 0x15
6139};
6140
Takashi Iwai6479c632009-07-28 18:20:25 +02006141static unsigned long stac9872_capvols[] = {
6142 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6143};
6144#define stac9872_capsws stac9872_capvols
6145
Takashi Iwai307282c2009-03-12 18:17:58 +01006146static unsigned int stac9872_vaio_pin_configs[9] = {
6147 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6148 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6149 0x90a7013e
6150};
6151
6152static const char *stac9872_models[STAC_9872_MODELS] = {
6153 [STAC_9872_AUTO] = "auto",
6154 [STAC_9872_VAIO] = "vaio",
6155};
6156
6157static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6158 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6159};
6160
6161static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006162 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6163 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006164 {} /* terminator */
6165};
6166
Guillaume Munch6d859062006-08-22 17:15:47 +02006167static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006168{
6169 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006170 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006171
Takashi Iwaidb064e52006-03-16 16:04:58 +01006172 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6173 if (spec == NULL)
6174 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006175 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006176 codec->spec = spec;
Takashi Iwaib04add92009-07-20 08:01:36 +02006177 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6178 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006179
6180 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6181 stac9872_models,
6182 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006183 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006184 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6185 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006186 else
6187 stac92xx_set_config_regs(codec,
6188 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006189
Takashi Iwai1e137f92009-01-21 07:41:22 +01006190 spec->multiout.dac_nids = spec->dac_nids;
6191 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6192 spec->adc_nids = stac9872_adc_nids;
6193 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6194 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006195 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006196 spec->num_caps = 1;
6197 spec->capvols = stac9872_capvols;
6198 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006199
Takashi Iwai1e137f92009-01-21 07:41:22 +01006200 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6201 if (err < 0) {
6202 stac92xx_free(codec);
6203 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006204 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006205 spec->input_mux = &spec->private_imux;
6206 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006207 return 0;
6208}
6209
6210
6211/*
Matt2f2f4252005-04-13 14:45:30 +02006212 * patch entries
6213 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006214static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006215 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6216 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6217 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6218 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6219 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6220 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6221 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006222 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6223 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6224 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6225 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6226 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6227 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006228 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6229 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6230 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6231 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6232 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6233 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6234 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6235 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6236 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6237 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006238 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6239 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6240 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6241 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6242 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6243 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006244 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6245 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006246 /* The following does not take into account .id=0x83847661 when subsys =
6247 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6248 * currently not fully supported.
6249 */
6250 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6251 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6252 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006253 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006254 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6255 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6256 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6257 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6258 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6259 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6260 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6261 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006262 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006263 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006264 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006265 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006266 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006267 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6268 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6269 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6270 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006271 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006272 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6273 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006274 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006275 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6276 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6277 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6278 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6279 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6280 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6281 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6282 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02006283 {} /* terminator */
6284};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006285
6286MODULE_ALIAS("snd-hda-codec-id:8384*");
6287MODULE_ALIAS("snd-hda-codec-id:111d*");
6288
6289MODULE_LICENSE("GPL");
6290MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6291
6292static struct hda_codec_preset_list sigmatel_list = {
6293 .preset = snd_hda_preset_sigmatel,
6294 .owner = THIS_MODULE,
6295};
6296
6297static int __init patch_sigmatel_init(void)
6298{
6299 return snd_hda_add_codec_preset(&sigmatel_list);
6300}
6301
6302static void __exit patch_sigmatel_exit(void)
6303{
6304 snd_hda_delete_codec_preset(&sigmatel_list);
6305}
6306
6307module_init(patch_sigmatel_init)
6308module_exit(patch_sigmatel_exit)