blob: 4e715fefebefb1b0ae5c9e43fe73000447d11664 [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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040032#include <linux/module.h>
Matt2f2f4252005-04-13 14:45:30 +020033#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020034#include <sound/asoundef.h>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040035#include <sound/jack.h>
Clemens Ladischa74ccea2010-10-22 15:52:34 +020036#include <sound/tlv.h>
Matt2f2f4252005-04-13 14:45:30 +020037#include "hda_codec.h"
38#include "hda_local.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020039#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020040
Takashi Iwaic6e4c662008-11-25 11:58:19 +010041enum {
42 STAC_VREF_EVENT = 1,
43 STAC_INSERT_EVENT,
44 STAC_PWR_EVENT,
45 STAC_HP_EVENT,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020046 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020047 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010048};
Matt4e550962005-07-04 17:51:39 +020049
Takashi Iwaif5fcc132006-11-24 17:07:44 +010050enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010051 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010052 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010053 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020054 STAC_9200_DELL_D21,
55 STAC_9200_DELL_D22,
56 STAC_9200_DELL_D23,
57 STAC_9200_DELL_M21,
58 STAC_9200_DELL_M22,
59 STAC_9200_DELL_M23,
60 STAC_9200_DELL_M24,
61 STAC_9200_DELL_M25,
62 STAC_9200_DELL_M26,
63 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020064 STAC_9200_M4,
65 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010066 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010067 STAC_9200_MODELS
68};
69
70enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010071 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010072 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020073 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020074 STAC_9205_DELL_M43,
75 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010076 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010077 STAC_9205_MODELS
78};
79
80enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010081 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010082 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010083 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080084 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010085 STAC_DELL_M6_AMIC,
86 STAC_DELL_M6_DMIC,
87 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050088 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020089 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010090 STAC_92HD73XX_MODELS
91};
92
93enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010094 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020095 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050096 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050097 STAC_DELL_S14,
Takashi Iwaib4e81872009-11-18 17:20:24 +010098 STAC_92HD83XXX_HP,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -050099 STAC_92HD83XXX_HP_cNB11_INTQUAD,
Steven Eastland48315592010-08-06 15:07:35 -0600100 STAC_HP_DV7_4000,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200101 STAC_92HD83XXX_MODELS
102};
103
104enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100105 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100106 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100107 STAC_DELL_M4_1,
108 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500109 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400110 STAC_HP_M4,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +0200111 STAC_HP_DV4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100112 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100113 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400114 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100115 STAC_92HD71BXX_MODELS
116};
117
118enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100119 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100120 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200121 STAC_M1,
122 STAC_M1_2,
123 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100124 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200125 STAC_M3,
126 STAC_M5,
127 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100128 STAC_925x_MODELS
129};
130
131enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100132 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100133 STAC_D945_REF,
134 STAC_D945GTP3,
135 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200136 STAC_INTEL_MAC_V1,
137 STAC_INTEL_MAC_V2,
138 STAC_INTEL_MAC_V3,
139 STAC_INTEL_MAC_V4,
140 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800141 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
142 * is given, one of the above models will be
143 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200144 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100145 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100146 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100147 STAC_MACBOOK_PRO_V1,
148 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200149 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200150 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300151 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200152 STAC_922X_DELL_D81,
153 STAC_922X_DELL_D82,
154 STAC_922X_DELL_M81,
155 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100156 STAC_922X_MODELS
157};
158
159enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100160 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100161 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100162 STAC_D965_REF,
163 STAC_D965_3ST,
164 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200165 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200166 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100167 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200168 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100169 STAC_927X_MODELS
170};
Matt Porter403d1942005-11-29 15:00:51 +0100171
Takashi Iwai307282c2009-03-12 18:17:58 +0100172enum {
173 STAC_9872_AUTO,
174 STAC_9872_VAIO,
175 STAC_9872_MODELS
176};
177
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400178struct sigmatel_event {
179 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100180 unsigned char type;
181 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400182 int data;
183};
184
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200185struct sigmatel_mic_route {
186 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200187 signed char mux_idx;
188 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200189};
190
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600191#define MAX_PINS_NUM 16
192#define MAX_ADCS_NUM 4
193#define MAX_DMICS_NUM 4
194
Matt2f2f4252005-04-13 14:45:30 +0200195struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100196 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200197 unsigned int num_mixers;
198
Matt Porter403d1942005-11-29 15:00:51 +0100199 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500200 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200201 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100202 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100203 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400204 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100205 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200206 unsigned int auto_mic:1;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +0100207 unsigned int linear_tone_beep:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200208
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100209 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200210 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100211 unsigned int gpio_mask;
212 unsigned int gpio_dir;
213 unsigned int gpio_data;
214 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200215 unsigned int gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +0100216 unsigned int gpio_led_polarity;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500217 unsigned int vref_led;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100218
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200219 /* stream */
220 unsigned int stream_delay;
221
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100222 /* analog loopback */
Takashi Iwai2b635362011-05-02 12:33:43 +0200223 const struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100224 unsigned char aloopback_mask;
225 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200226
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100227 /* power management */
228 unsigned int num_pwrs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200229 const unsigned int *pwr_mapping;
230 const hda_nid_t *pwr_nids;
231 const hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100232
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400233 /* events */
234 struct snd_array events;
235
Matt2f2f4252005-04-13 14:45:30 +0200236 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100237 struct hda_input_mux *mono_mux;
238 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200239 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100240 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100241 hda_nid_t hp_dacs[5];
242 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200243
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100244 int volume_offset;
245
Matt2f2f4252005-04-13 14:45:30 +0200246 /* capture */
Takashi Iwai2b635362011-05-02 12:33:43 +0200247 const hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200248 unsigned int num_adcs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200249 const hda_nid_t *mux_nids;
Mattdabbed62005-06-14 10:19:34 +0200250 unsigned int num_muxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200251 const hda_nid_t *dmic_nids;
Matt Porter8b657272006-10-26 17:12:59 +0200252 unsigned int num_dmics;
Takashi Iwai2b635362011-05-02 12:33:43 +0200253 const hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100254 unsigned int num_dmuxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200255 const hda_nid_t *smux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200256 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200257 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200258
Takashi Iwai2b635362011-05-02 12:33:43 +0200259 const unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
260 const unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
Takashi Iwai6479c632009-07-28 18:20:25 +0200261 unsigned int num_caps; /* number of capture volume/switch elements */
262
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200263 struct sigmatel_mic_route ext_mic;
264 struct sigmatel_mic_route int_mic;
Charles Chin99077902010-09-17 10:22:32 +0200265 struct sigmatel_mic_route dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200266
Takashi Iwaiea734962011-01-17 11:29:34 +0100267 const char * const *spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200268
Mattdabbed62005-06-14 10:19:34 +0200269 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100270 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200271 hda_nid_t anabeep_nid;
272 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200273
Matt2f2f4252005-04-13 14:45:30 +0200274 /* pin widgets */
Takashi Iwai2b635362011-05-02 12:33:43 +0200275 const hda_nid_t *pin_nids;
Matt2f2f4252005-04-13 14:45:30 +0200276 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200277
278 /* codec specific stuff */
Takashi Iwai2b635362011-05-02 12:33:43 +0200279 const struct hda_verb *init;
280 const struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200281
282 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200283 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100284 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200285 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100286 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200287 struct hda_input_mux *sinput_mux;
288 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400289 unsigned int cur_amux;
290 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200291 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200292
Matt Porter403d1942005-11-29 15:00:51 +0100293 /* i/o switches */
294 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200295 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100296 hda_nid_t line_switch; /* shared line-in for input and output */
297 hda_nid_t mic_switch; /* shared mic-in for input and output */
298 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200299 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200300
Mattc7d4b2f2005-06-27 14:59:41 +0200301 struct hda_pcm pcm_rec[2]; /* PCM information */
302
303 /* dynamic controls and input_mux */
304 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200305 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200306 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200307 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200308 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100309 struct hda_input_mux private_mono_mux;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600310
311 /* auto spec */
312 unsigned auto_pin_cnt;
313 hda_nid_t auto_pin_nids[MAX_PINS_NUM];
314 unsigned auto_adc_cnt;
315 hda_nid_t auto_adc_nids[MAX_ADCS_NUM];
316 hda_nid_t auto_mux_nids[MAX_ADCS_NUM];
317 hda_nid_t auto_dmux_nids[MAX_ADCS_NUM];
318 unsigned long auto_capvols[MAX_ADCS_NUM];
319 unsigned auto_dmic_cnt;
320 hda_nid_t auto_dmic_nids[MAX_DMICS_NUM];
Matt2f2f4252005-04-13 14:45:30 +0200321};
322
Takashi Iwai2b635362011-05-02 12:33:43 +0200323static const hda_nid_t stac9200_adc_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200324 0x03,
325};
326
Takashi Iwai2b635362011-05-02 12:33:43 +0200327static const hda_nid_t stac9200_mux_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200328 0x0c,
329};
330
Takashi Iwai2b635362011-05-02 12:33:43 +0200331static const hda_nid_t stac9200_dac_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200332 0x02,
333};
334
Takashi Iwai2b635362011-05-02 12:33:43 +0200335static const hda_nid_t stac92hd73xx_pwr_nids[8] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100336 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
337 0x0f, 0x10, 0x11
338};
339
Takashi Iwai2b635362011-05-02 12:33:43 +0200340static const hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400341 0x26, 0,
342};
343
Takashi Iwai2b635362011-05-02 12:33:43 +0200344static const hda_nid_t stac92hd73xx_adc_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100345 0x1a, 0x1b
346};
347
348#define STAC92HD73XX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200349static const hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100350 0x13, 0x14, 0
351};
352
353#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100354
Takashi Iwai2b635362011-05-02 12:33:43 +0200355static const hda_nid_t stac92hd73xx_mux_nids[2] = {
Takashi Iwaie2aec172009-09-02 01:00:05 +0200356 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100357};
358
Takashi Iwai2b635362011-05-02 12:33:43 +0200359static const hda_nid_t stac92hd73xx_dmux_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100360 0x20, 0x21,
361};
362
Takashi Iwai2b635362011-05-02 12:33:43 +0200363static const hda_nid_t stac92hd73xx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200364 0x22, 0x23,
365};
366
Takashi Iwai6479c632009-07-28 18:20:25 +0200367#define STAC92HD73XX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200368static const unsigned long stac92hd73xx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200369 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
370 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
371};
372#define stac92hd73xx_capsws stac92hd73xx_capvols
373
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200374#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200375
Takashi Iwai2b635362011-05-02 12:33:43 +0200376static const hda_nid_t stac92hd83xxx_pwr_nids[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200377 0xa, 0xb, 0xd, 0xe,
378};
379
Takashi Iwai2b635362011-05-02 12:33:43 +0200380static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400381 0x1e, 0,
382};
383
Takashi Iwai2b635362011-05-02 12:33:43 +0200384static const unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500385 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200386};
387
Takashi Iwai2b635362011-05-02 12:33:43 +0200388static const hda_nid_t stac92hd83xxx_dmic_nids[] = {
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600389 0x11, 0x20,
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +0200390};
391
Takashi Iwai2b635362011-05-02 12:33:43 +0200392static const hda_nid_t stac92hd71bxx_pwr_nids[3] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100393 0x0a, 0x0d, 0x0f
394};
395
Takashi Iwai2b635362011-05-02 12:33:43 +0200396static const hda_nid_t stac92hd71bxx_adc_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100397 0x12, 0x13,
398};
399
Takashi Iwai2b635362011-05-02 12:33:43 +0200400static const hda_nid_t stac92hd71bxx_mux_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100401 0x1a, 0x1b
402};
403
Takashi Iwai2b635362011-05-02 12:33:43 +0200404static const hda_nid_t stac92hd71bxx_dmux_nids[2] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400405 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100406};
407
Takashi Iwai2b635362011-05-02 12:33:43 +0200408static const hda_nid_t stac92hd71bxx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200409 0x24, 0x25,
410};
411
Matthew Ranostaye035b842007-11-06 11:53:55 +0100412#define STAC92HD71BXX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200413static const hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100414 0x18, 0x19, 0
415};
416
Takashi Iwai2b635362011-05-02 12:33:43 +0200417static const hda_nid_t stac92hd71bxx_dmic_5port_nids[STAC92HD71BXX_NUM_DMICS] = {
418 0x18, 0
419};
420
421static const hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400422 0x22, 0
423};
424
Takashi Iwai6479c632009-07-28 18:20:25 +0200425#define STAC92HD71BXX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200426static const unsigned long stac92hd71bxx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200427 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
428 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
429};
430#define stac92hd71bxx_capsws stac92hd71bxx_capvols
431
Takashi Iwai2b635362011-05-02 12:33:43 +0200432static const hda_nid_t stac925x_adc_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100433 0x03,
434};
435
Takashi Iwai2b635362011-05-02 12:33:43 +0200436static const hda_nid_t stac925x_mux_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100437 0x0f,
438};
439
Takashi Iwai2b635362011-05-02 12:33:43 +0200440static const hda_nid_t stac925x_dac_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100441 0x02,
442};
443
Takashi Iwaif6e98522007-10-16 14:27:04 +0200444#define STAC925X_NUM_DMICS 1
Takashi Iwai2b635362011-05-02 12:33:43 +0200445static const hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200446 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200447};
448
Takashi Iwai2b635362011-05-02 12:33:43 +0200449static const hda_nid_t stac925x_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100450 0x14,
451};
452
Takashi Iwai2b635362011-05-02 12:33:43 +0200453static const unsigned long stac925x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200454 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
455};
Takashi Iwai2b635362011-05-02 12:33:43 +0200456static const unsigned long stac925x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200457 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
458};
459
Takashi Iwai2b635362011-05-02 12:33:43 +0200460static const hda_nid_t stac922x_adc_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200461 0x06, 0x07,
462};
463
Takashi Iwai2b635362011-05-02 12:33:43 +0200464static const hda_nid_t stac922x_mux_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200465 0x12, 0x13,
466};
467
Takashi Iwai6479c632009-07-28 18:20:25 +0200468#define STAC922X_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200469static const unsigned long stac922x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200470 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
471 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
472};
473#define stac922x_capsws stac922x_capvols
474
Takashi Iwai2b635362011-05-02 12:33:43 +0200475static const hda_nid_t stac927x_slave_dig_outs[2] = {
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500476 0x1f, 0,
477};
478
Takashi Iwai2b635362011-05-02 12:33:43 +0200479static const hda_nid_t stac927x_adc_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100480 0x07, 0x08, 0x09
481};
482
Takashi Iwai2b635362011-05-02 12:33:43 +0200483static const hda_nid_t stac927x_mux_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100484 0x15, 0x16, 0x17
485};
486
Takashi Iwai2b635362011-05-02 12:33:43 +0200487static const hda_nid_t stac927x_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200488 0x21,
489};
490
Takashi Iwai2b635362011-05-02 12:33:43 +0200491static const hda_nid_t stac927x_dac_nids[6] = {
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100492 0x02, 0x03, 0x04, 0x05, 0x06, 0
493};
494
Takashi Iwai2b635362011-05-02 12:33:43 +0200495static const hda_nid_t stac927x_dmux_nids[1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100496 0x1b,
497};
498
Matthew Ranostay7f168592007-10-18 17:38:17 +0200499#define STAC927X_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200500static const hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
Matthew Ranostay7f168592007-10-18 17:38:17 +0200501 0x13, 0x14, 0
502};
503
Takashi Iwai6479c632009-07-28 18:20:25 +0200504#define STAC927X_NUM_CAPS 3
Takashi Iwai2b635362011-05-02 12:33:43 +0200505static const unsigned long stac927x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200506 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
507 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
508 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
509};
Takashi Iwai2b635362011-05-02 12:33:43 +0200510static const unsigned long stac927x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200511 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
512 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
513 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
514};
515
Takashi Iwaiea734962011-01-17 11:29:34 +0100516static const char * const stac927x_spdif_labels[5] = {
Matthew Ranostay65973632008-09-16 10:39:37 -0400517 "Digital Playback", "ADAT", "Analog Mux 1",
518 "Analog Mux 2", "Analog Mux 3"
519};
520
Takashi Iwai2b635362011-05-02 12:33:43 +0200521static const hda_nid_t stac9205_adc_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200522 0x12, 0x13
523};
524
Takashi Iwai2b635362011-05-02 12:33:43 +0200525static const hda_nid_t stac9205_mux_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200526 0x19, 0x1a
527};
528
Takashi Iwai2b635362011-05-02 12:33:43 +0200529static const hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100530 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100531};
532
Takashi Iwai2b635362011-05-02 12:33:43 +0200533static const hda_nid_t stac9205_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200534 0x21,
535};
536
Takashi Iwaif6e98522007-10-16 14:27:04 +0200537#define STAC9205_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200538static const hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200539 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200540};
541
Takashi Iwai6479c632009-07-28 18:20:25 +0200542#define STAC9205_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200543static const unsigned long stac9205_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200544 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
545 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
546};
Takashi Iwai2b635362011-05-02 12:33:43 +0200547static const unsigned long stac9205_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200548 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
549 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
550};
551
Takashi Iwai2b635362011-05-02 12:33:43 +0200552static const hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200553 0x08, 0x09, 0x0d, 0x0e,
554 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200555};
556
Takashi Iwai2b635362011-05-02 12:33:43 +0200557static const hda_nid_t stac925x_pin_nids[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100558 0x07, 0x08, 0x0a, 0x0b,
559 0x0c, 0x0d, 0x10, 0x11,
560};
561
Takashi Iwai2b635362011-05-02 12:33:43 +0200562static const hda_nid_t stac922x_pin_nids[10] = {
Matt2f2f4252005-04-13 14:45:30 +0200563 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
564 0x0f, 0x10, 0x11, 0x15, 0x1b,
565};
566
Takashi Iwai2b635362011-05-02 12:33:43 +0200567static const hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100568 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
569 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200570 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100571};
572
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500573#define STAC92HD71BXX_NUM_PINS 13
Takashi Iwai2b635362011-05-02 12:33:43 +0200574static const hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500575 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
576 0x00, 0x14, 0x18, 0x19, 0x1e,
577 0x1f, 0x20, 0x27
578};
Takashi Iwai2b635362011-05-02 12:33:43 +0200579static const hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100580 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
581 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500582 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100583};
584
Takashi Iwai2b635362011-05-02 12:33:43 +0200585static const hda_nid_t stac927x_pin_nids[14] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100586 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
587 0x0f, 0x10, 0x11, 0x12, 0x13,
588 0x14, 0x21, 0x22, 0x23,
589};
590
Takashi Iwai2b635362011-05-02 12:33:43 +0200591static const hda_nid_t stac9205_pin_nids[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200592 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
593 0x0f, 0x14, 0x16, 0x17, 0x18,
594 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200595};
596
Matt Porter8b657272006-10-26 17:12:59 +0200597static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
598 struct snd_ctl_elem_info *uinfo)
599{
600 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
601 struct sigmatel_spec *spec = codec->spec;
602 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
603}
604
605static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
606 struct snd_ctl_elem_value *ucontrol)
607{
608 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
609 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100610 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200611
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100612 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200613 return 0;
614}
615
616static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
617 struct snd_ctl_elem_value *ucontrol)
618{
619 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
620 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100621 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200622
623 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100624 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200625}
626
Matthew Ranostayd9737752008-09-07 12:03:41 +0200627static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
628 struct snd_ctl_elem_info *uinfo)
629{
630 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
631 struct sigmatel_spec *spec = codec->spec;
632 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
633}
634
635static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
636 struct snd_ctl_elem_value *ucontrol)
637{
638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
639 struct sigmatel_spec *spec = codec->spec;
640 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
641
642 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
643 return 0;
644}
645
646static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
647 struct snd_ctl_elem_value *ucontrol)
648{
649 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
650 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400651 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200652 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400653 int err, val;
654 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200655
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400656 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200657 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400658 if (err < 0)
659 return err;
660
661 if (spec->spdif_mute) {
662 if (smux_idx == 0)
663 nid = spec->multiout.dig_out_nid;
664 else
665 nid = codec->slave_dig_outs[smux_idx - 1];
666 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100667 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400668 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100669 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400670 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100671 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
672 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400673 }
674 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200675}
676
Wang Shaoyan96b63592011-08-10 16:01:04 +0800677#ifdef CONFIG_SND_HDA_POWER_SAVE
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500678static int stac_vrefout_set(struct hda_codec *codec,
679 hda_nid_t nid, unsigned int new_vref)
680{
681 int error, pinctl;
682
683 snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
684 pinctl = snd_hda_codec_read(codec, nid, 0,
685 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
686
687 if (pinctl < 0)
688 return pinctl;
689
690 pinctl &= 0xff;
691 pinctl &= ~AC_PINCTL_VREFEN;
692 pinctl |= (new_vref & AC_PINCTL_VREFEN);
693
694 error = snd_hda_codec_write_cache(codec, nid, 0,
695 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
696 if (error < 0)
697 return error;
698
699 return 1;
700}
Wang Shaoyan96b63592011-08-10 16:01:04 +0800701#endif
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500702
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200703static unsigned int stac92xx_vref_set(struct hda_codec *codec,
704 hda_nid_t nid, unsigned int new_vref)
705{
Takashi Iwaib8621512009-06-22 08:00:10 +0200706 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200707 unsigned int pincfg;
708 pincfg = snd_hda_codec_read(codec, nid, 0,
709 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
710
711 pincfg &= 0xff;
712 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
713 pincfg |= new_vref;
714
715 if (new_vref == AC_PINCTL_VREF_HIZ)
716 pincfg |= AC_PINCTL_OUT_EN;
717 else
718 pincfg |= AC_PINCTL_IN_EN;
719
720 error = snd_hda_codec_write_cache(codec, nid, 0,
721 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
722 if (error < 0)
723 return error;
724 else
725 return 1;
726}
727
728static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
729{
730 unsigned int vref;
731 vref = snd_hda_codec_read(codec, nid, 0,
732 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
733 vref &= AC_PINCTL_VREFEN;
734 return vref;
735}
736
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100737static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200738{
739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
740 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200741 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200742}
743
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100744static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200745{
746 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
747 struct sigmatel_spec *spec = codec->spec;
748 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
749
750 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
751 return 0;
752}
753
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100754static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200755{
756 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
757 struct sigmatel_spec *spec = codec->spec;
758 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200759 const struct hda_input_mux *imux = spec->input_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600760 unsigned int idx, prev_idx, didx;
Matt2f2f4252005-04-13 14:45:30 +0200761
Takashi Iwai5207e102009-07-30 13:09:08 +0200762 idx = ucontrol->value.enumerated.item[0];
763 if (idx >= imux->num_items)
764 idx = imux->num_items - 1;
765 prev_idx = spec->cur_mux[adc_idx];
766 if (prev_idx == idx)
767 return 0;
768 if (idx < spec->num_analog_muxes) {
769 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
770 AC_VERB_SET_CONNECT_SEL,
771 imux->items[idx].index);
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600772 if (prev_idx >= spec->num_analog_muxes &&
773 spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
Takashi Iwai5207e102009-07-30 13:09:08 +0200774 imux = spec->dinput_mux;
775 /* 0 = analog */
776 snd_hda_codec_write_cache(codec,
777 spec->dmux_nids[adc_idx], 0,
778 AC_VERB_SET_CONNECT_SEL,
779 imux->items[0].index);
780 }
781 } else {
782 imux = spec->dinput_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600783 /* first dimux item is hardcoded to select analog imux,
784 * so lets skip it
785 */
786 didx = idx - spec->num_analog_muxes + 1;
Takashi Iwai5207e102009-07-30 13:09:08 +0200787 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
788 AC_VERB_SET_CONNECT_SEL,
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600789 imux->items[didx].index);
Takashi Iwai5207e102009-07-30 13:09:08 +0200790 }
791 spec->cur_mux[adc_idx] = idx;
792 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200793}
794
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100795static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
796 struct snd_ctl_elem_info *uinfo)
797{
798 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
799 struct sigmatel_spec *spec = codec->spec;
800 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
801}
802
803static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
804 struct snd_ctl_elem_value *ucontrol)
805{
806 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
807 struct sigmatel_spec *spec = codec->spec;
808
809 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
810 return 0;
811}
812
813static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_value *ucontrol)
815{
816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
817 struct sigmatel_spec *spec = codec->spec;
818
819 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
820 spec->mono_nid, &spec->cur_mmux);
821}
822
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200823#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
824
825static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
826 struct snd_ctl_elem_value *ucontrol)
827{
828 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100829 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200830 struct sigmatel_spec *spec = codec->spec;
831
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100832 ucontrol->value.integer.value[0] = !!(spec->aloopback &
833 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200834 return 0;
835}
836
837static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
838 struct snd_ctl_elem_value *ucontrol)
839{
840 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
841 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100842 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200843 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100844 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200845
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100846 idx_val = spec->aloopback_mask << idx;
847 if (ucontrol->value.integer.value[0])
848 val = spec->aloopback | idx_val;
849 else
850 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100851 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200852 return 0;
853
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100854 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200855
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100856 /* Only return the bits defined by the shift value of the
857 * first two bytes of the mask
858 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200859 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100860 kcontrol->private_value & 0xFFFF, 0x0);
861 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200862
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100863 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200864 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100865 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200866 } else {
867 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100868 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200869 }
870
871 snd_hda_codec_write_cache(codec, codec->afg, 0,
872 kcontrol->private_value >> 16, dac_mode);
873
874 return 1;
875}
876
Takashi Iwai2b635362011-05-02 12:33:43 +0200877static const struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200878 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200879 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200880 {}
881};
882
Takashi Iwai2b635362011-05-02 12:33:43 +0200883static const struct hda_verb stac9200_eapd_init[] = {
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200884 /* set dac0mux for dac converter */
885 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
886 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
887 {}
888};
889
Takashi Iwai2b635362011-05-02 12:33:43 +0200890static const struct hda_verb dell_eq_core_init[] = {
Matthew Ranostayd654a662008-03-14 08:46:51 +0100891 /* set master volume to max value without distortion
892 * and direct control */
893 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100894 {}
895};
896
Takashi Iwai2b635362011-05-02 12:33:43 +0200897static const struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100898 /* set master volume and direct control */
899 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100900 {}
901};
902
Takashi Iwai2b635362011-05-02 12:33:43 +0200903static const struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200904 /* power state controls amps */
905 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200906 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200907};
908
Takashi Iwai2b635362011-05-02 12:33:43 +0200909static const struct hda_verb stac92hd71bxx_core_init[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100910 /* set master volume and direct control */
911 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200912 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100913};
914
Takashi Iwai2b635362011-05-02 12:33:43 +0200915static const struct hda_verb stac92hd71bxx_unmute_core_init[] = {
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500916 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
917 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100918 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
919 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100920 {}
921};
922
Takashi Iwai2b635362011-05-02 12:33:43 +0200923static const struct hda_verb stac925x_core_init[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100924 /* set dac0mux for dac converter */
925 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100926 /* mute the master volume */
927 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100928 {}
929};
930
Takashi Iwai2b635362011-05-02 12:33:43 +0200931static const struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200932 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200933 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200934 {}
935};
936
Takashi Iwai2b635362011-05-02 12:33:43 +0200937static const struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200938 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200939 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200940 /* unmute node 0x1b */
941 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
942 /* select node 0x03 as DAC */
943 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
944 {}
945};
946
Takashi Iwai2b635362011-05-02 12:33:43 +0200947static const struct hda_verb dell_3st_core_init[] = {
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200948 /* don't set delta bit */
949 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
950 /* unmute node 0x1b */
951 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
952 /* select node 0x03 as DAC */
953 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
954 {}
955};
956
Takashi Iwai2b635362011-05-02 12:33:43 +0200957static const struct hda_verb stac927x_core_init[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100958 /* set master volume and direct control */
959 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200960 /* enable analog pc beep path */
961 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100962 {}
963};
964
Takashi Iwai2b635362011-05-02 12:33:43 +0200965static const struct hda_verb stac927x_volknob_core_init[] = {
Takashi Iwai54930532009-10-11 17:38:29 +0200966 /* don't set delta bit */
967 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
968 /* enable analog pc beep path */
969 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
970 {}
971};
972
Takashi Iwai2b635362011-05-02 12:33:43 +0200973static const struct hda_verb stac9205_core_init[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200974 /* set master volume and direct control */
975 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200976 /* enable analog pc beep path */
977 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200978 {}
979};
980
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100981#define STAC_MONO_MUX \
982 { \
983 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
984 .name = "Mono Mux", \
985 .count = 1, \
986 .info = stac92xx_mono_mux_enum_info, \
987 .get = stac92xx_mono_mux_enum_get, \
988 .put = stac92xx_mono_mux_enum_put, \
989 }
990
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100991#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200992 { \
993 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
994 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100995 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200996 .info = stac92xx_aloopback_info, \
997 .get = stac92xx_aloopback_get, \
998 .put = stac92xx_aloopback_put, \
999 .private_value = verb_read | (verb_write << 16), \
1000 }
1001
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02001002#define DC_BIAS(xname, idx, nid) \
1003 { \
1004 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1005 .name = xname, \
1006 .index = idx, \
1007 .info = stac92xx_dc_bias_info, \
1008 .get = stac92xx_dc_bias_get, \
1009 .put = stac92xx_dc_bias_put, \
1010 .private_value = nid, \
1011 }
1012
Takashi Iwai2b635362011-05-02 12:33:43 +02001013static const struct snd_kcontrol_new stac9200_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001014 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001015 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001016 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1017 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001018 { } /* end */
1019};
1020
Takashi Iwai2b635362011-05-02 12:33:43 +02001021static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001022 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1023 {}
1024};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001025
Takashi Iwai2b635362011-05-02 12:33:43 +02001026static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001027 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1028 {}
1029};
1030
Takashi Iwai2b635362011-05-02 12:33:43 +02001031static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001032 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1033 {}
1034};
1035
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001036
Takashi Iwai2b635362011-05-02 12:33:43 +02001037static const struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001038 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1039};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001040
Takashi Iwai2b635362011-05-02 12:33:43 +02001041static const struct snd_kcontrol_new stac925x_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001042 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
Takashi Iwaic9280d62009-01-15 17:31:00 +01001043 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001044 { } /* end */
1045};
1046
Takashi Iwai2b635362011-05-02 12:33:43 +02001047static const struct snd_kcontrol_new stac9205_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001048 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1049 {}
1050};
1051
Takashi Iwai2b635362011-05-02 12:33:43 +02001052static const struct snd_kcontrol_new stac927x_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001053 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1054 {}
1055};
1056
Takashi Iwai1697055e2007-12-18 18:05:52 +01001057static struct snd_kcontrol_new stac_dmux_mixer = {
1058 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1059 .name = "Digital Input Source",
1060 /* count set later */
1061 .info = stac92xx_dmux_enum_info,
1062 .get = stac92xx_dmux_enum_get,
1063 .put = stac92xx_dmux_enum_put,
1064};
1065
Matthew Ranostayd9737752008-09-07 12:03:41 +02001066static struct snd_kcontrol_new stac_smux_mixer = {
1067 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001068 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001069 /* count set later */
1070 .info = stac92xx_smux_enum_info,
1071 .get = stac92xx_smux_enum_get,
1072 .put = stac92xx_smux_enum_put,
1073};
1074
Takashi Iwaiea734962011-01-17 11:29:34 +01001075static const char * const slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001076 "Front Playback Volume",
1077 "Surround Playback Volume",
1078 "Center Playback Volume",
1079 "LFE Playback Volume",
1080 "Side Playback Volume",
1081 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001082 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001083 NULL
1084};
1085
Takashi Iwaiea734962011-01-17 11:29:34 +01001086static const char * const slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001087 "Front Playback Switch",
1088 "Surround Playback Switch",
1089 "Center Playback Switch",
1090 "LFE Playback Switch",
1091 "Side Playback Switch",
1092 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001093 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001094 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001095 NULL
1096};
1097
Takashi Iwai603c4012008-07-30 15:01:44 +02001098static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001099static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001100
Matt2f2f4252005-04-13 14:45:30 +02001101static int stac92xx_build_controls(struct hda_codec *codec)
1102{
1103 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001104 struct auto_pin_cfg *cfg = &spec->autocfg;
1105 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001106 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001107 int i;
Matt2f2f4252005-04-13 14:45:30 +02001108
Takashi Iwai6479c632009-07-28 18:20:25 +02001109 if (spec->mixer) {
1110 err = snd_hda_add_new_ctls(codec, spec->mixer);
1111 if (err < 0)
1112 return err;
1113 }
Mattc7d4b2f2005-06-27 14:59:41 +02001114
1115 for (i = 0; i < spec->num_mixers; i++) {
1116 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1117 if (err < 0)
1118 return err;
1119 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001120 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1121 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001122 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001123 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001124 snd_ctl_new1(&stac_dmux_mixer, codec));
1125 if (err < 0)
1126 return err;
1127 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001128 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001129 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1130 struct hda_input_mux *smux = &spec->private_smux;
1131 /* check for mute support on SPDIF out */
1132 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001133 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001134 spec->spdif_mute = 1;
1135 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001136 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001137 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001138 snd_ctl_new1(&stac_smux_mixer, codec));
1139 if (err < 0)
1140 return err;
1141 }
Mattc7d4b2f2005-06-27 14:59:41 +02001142
Mattdabbed62005-06-14 10:19:34 +02001143 if (spec->multiout.dig_out_nid) {
Stephen Warren74b654c2011-06-01 11:14:18 -06001144 err = snd_hda_create_spdif_out_ctls(codec,
1145 spec->multiout.dig_out_nid,
1146 spec->multiout.dig_out_nid);
Mattdabbed62005-06-14 10:19:34 +02001147 if (err < 0)
1148 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001149 err = snd_hda_create_spdif_share_sw(codec,
1150 &spec->multiout);
1151 if (err < 0)
1152 return err;
1153 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001154 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001155 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001156 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1157 if (err < 0)
1158 return err;
1159 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001160
1161 /* if we have no master control, let's create it */
1162 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001163 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001164 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001165 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001166 /* correct volume offset */
1167 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001168 /* minimum value is actually mute */
Clemens Ladischa74ccea2010-10-22 15:52:34 +02001169 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001170 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001171 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001172 if (err < 0)
1173 return err;
1174 }
1175 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1176 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1177 NULL, slave_sws);
1178 if (err < 0)
1179 return err;
1180 }
1181
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001182 if (spec->aloopback_ctl &&
1183 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1184 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1185 if (err < 0)
1186 return err;
1187 }
1188
Takashi Iwai603c4012008-07-30 15:01:44 +02001189 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001190
1191 /* create jack input elements */
1192 if (spec->hp_detect) {
1193 for (i = 0; i < cfg->hp_outs; i++) {
1194 int type = SND_JACK_HEADPHONE;
1195 nid = cfg->hp_pins[i];
1196 /* jack detection */
1197 if (cfg->hp_outs == i)
1198 type |= SND_JACK_LINEOUT;
1199 err = stac92xx_add_jack(codec, nid, type);
1200 if (err < 0)
1201 return err;
1202 }
1203 }
1204 for (i = 0; i < cfg->line_outs; i++) {
1205 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1206 SND_JACK_LINEOUT);
1207 if (err < 0)
1208 return err;
1209 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02001210 for (i = 0; i < cfg->num_inputs; i++) {
1211 nid = cfg->inputs[i].pin;
1212 err = stac92xx_add_jack(codec, nid, SND_JACK_MICROPHONE);
1213 if (err < 0)
1214 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001215 }
1216
Mattdabbed62005-06-14 10:19:34 +02001217 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001218}
1219
Takashi Iwai2b635362011-05-02 12:33:43 +02001220static const unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001221 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001222 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1223};
1224
Takashi Iwai2b635362011-05-02 12:33:43 +02001225static const unsigned int gateway9200_m4_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001226 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1227 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1228};
Takashi Iwai2b635362011-05-02 12:33:43 +02001229static const unsigned int gateway9200_m4_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001230 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1231 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1232};
1233
1234/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001235 STAC 9200 pin configs for
1236 102801A8
1237 102801DE
1238 102801E8
1239*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001240static const unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001241 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1242 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001243};
1244
1245/*
1246 STAC 9200 pin configs for
1247 102801C0
1248 102801C1
1249*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001250static const unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001251 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1252 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001253};
1254
1255/*
1256 STAC 9200 pin configs for
1257 102801C4 (Dell Dimension E310)
1258 102801C5
1259 102801C7
1260 102801D9
1261 102801DA
1262 102801E3
1263*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001264static const unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001265 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1266 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001267};
1268
1269
1270/*
1271 STAC 9200-32 pin configs for
1272 102801B5 (Dell Inspiron 630m)
1273 102801D8 (Dell Inspiron 640m)
1274*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001275static const unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001276 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1277 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001278};
1279
1280/*
1281 STAC 9200-32 pin configs for
1282 102801C2 (Dell Latitude D620)
1283 102801C8
1284 102801CC (Dell Latitude D820)
1285 102801D4
1286 102801D6
1287*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001288static const unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001289 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1290 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001291};
1292
1293/*
1294 STAC 9200-32 pin configs for
1295 102801CE (Dell XPS M1710)
1296 102801CF (Dell Precision M90)
1297*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001298static const unsigned int dell9200_m23_pin_configs[8] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001299 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1300 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1301};
1302
1303/*
1304 STAC 9200-32 pin configs for
1305 102801C9
1306 102801CA
1307 102801CB (Dell Latitude 120L)
1308 102801D3
1309*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001310static const unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001311 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1312 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001313};
1314
1315/*
1316 STAC 9200-32 pin configs for
1317 102801BD (Dell Inspiron E1505n)
1318 102801EE
1319 102801EF
1320*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001321static const unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001322 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1323 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001324};
1325
1326/*
1327 STAC 9200-32 pin configs for
1328 102801F5 (Dell Inspiron 1501)
1329 102801F6
1330*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001331static const unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001332 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1333 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001334};
1335
1336/*
1337 STAC 9200-32
1338 102801CD (Dell Inspiron E1705/9400)
1339*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001340static const unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001341 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1342 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001343};
1344
Takashi Iwai2b635362011-05-02 12:33:43 +02001345static const unsigned int oqo9200_pin_configs[8] = {
Tobin Davisbf277782008-02-03 20:31:47 +01001346 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1347 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1348};
1349
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001350
Takashi Iwai2b635362011-05-02 12:33:43 +02001351static const unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001352 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001353 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001354 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1355 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1356 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1357 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1358 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1359 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1360 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1361 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1362 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1363 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001364 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1365 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001366 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001367};
1368
Takashi Iwaiea734962011-01-17 11:29:34 +01001369static const char * const stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001370 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001371 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001372 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001373 [STAC_9200_DELL_D21] = "dell-d21",
1374 [STAC_9200_DELL_D22] = "dell-d22",
1375 [STAC_9200_DELL_D23] = "dell-d23",
1376 [STAC_9200_DELL_M21] = "dell-m21",
1377 [STAC_9200_DELL_M22] = "dell-m22",
1378 [STAC_9200_DELL_M23] = "dell-m23",
1379 [STAC_9200_DELL_M24] = "dell-m24",
1380 [STAC_9200_DELL_M25] = "dell-m25",
1381 [STAC_9200_DELL_M26] = "dell-m26",
1382 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001383 [STAC_9200_M4] = "gateway-m4",
1384 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001385 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001386};
1387
Takashi Iwai2b635362011-05-02 12:33:43 +02001388static const struct snd_pci_quirk stac9200_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001389 /* SigmaTel reference board */
1390 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1391 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001392 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1393 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001394 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001395 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1396 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001397 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001398 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1399 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1400 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1401 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1402 "unknown Dell", STAC_9200_DELL_D22),
1403 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1404 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001405 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001406 "Dell Latitude D620", STAC_9200_DELL_M22),
1407 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1408 "unknown Dell", STAC_9200_DELL_D23),
1409 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1410 "unknown Dell", STAC_9200_DELL_D23),
1411 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1412 "unknown Dell", STAC_9200_DELL_M22),
1413 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1414 "unknown Dell", STAC_9200_DELL_M24),
1415 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1416 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001417 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001418 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001419 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001420 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001421 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001422 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001423 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001424 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001425 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001426 "Dell Precision M90", STAC_9200_DELL_M23),
1427 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1428 "unknown Dell", STAC_9200_DELL_M22),
1429 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1430 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001431 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001432 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001433 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001434 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1435 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1436 "unknown Dell", STAC_9200_DELL_D23),
1437 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1438 "unknown Dell", STAC_9200_DELL_D23),
1439 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1440 "unknown Dell", STAC_9200_DELL_D21),
1441 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1442 "unknown Dell", STAC_9200_DELL_D23),
1443 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1444 "unknown Dell", STAC_9200_DELL_D21),
1445 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1446 "unknown Dell", STAC_9200_DELL_M25),
1447 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1448 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001449 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001450 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1451 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1452 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001453 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001454 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001455 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001456 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1457 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1458 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001459 /* OQO Mobile */
1460 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001461 {} /* terminator */
1462};
1463
Takashi Iwai2b635362011-05-02 12:33:43 +02001464static const unsigned int ref925x_pin_configs[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001465 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001466 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001467};
1468
Takashi Iwai2b635362011-05-02 12:33:43 +02001469static const unsigned int stac925xM1_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001470 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1471 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001472};
1473
Takashi Iwai2b635362011-05-02 12:33:43 +02001474static const unsigned int stac925xM1_2_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001475 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1476 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1477};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001478
Takashi Iwai2b635362011-05-02 12:33:43 +02001479static const unsigned int stac925xM2_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001480 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1481 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001482};
1483
Takashi Iwai2b635362011-05-02 12:33:43 +02001484static const unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001485 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1486 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1487};
1488
Takashi Iwai2b635362011-05-02 12:33:43 +02001489static const unsigned int stac925xM3_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001490 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1491 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1492};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001493
Takashi Iwai2b635362011-05-02 12:33:43 +02001494static const unsigned int stac925xM5_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001495 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1496 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1497};
1498
Takashi Iwai2b635362011-05-02 12:33:43 +02001499static const unsigned int stac925xM6_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001500 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1501 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001502};
1503
Takashi Iwai2b635362011-05-02 12:33:43 +02001504static const unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001505 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001506 [STAC_M1] = stac925xM1_pin_configs,
1507 [STAC_M1_2] = stac925xM1_2_pin_configs,
1508 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001509 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001510 [STAC_M3] = stac925xM3_pin_configs,
1511 [STAC_M5] = stac925xM5_pin_configs,
1512 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001513};
1514
Takashi Iwaiea734962011-01-17 11:29:34 +01001515static const char * const stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001516 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001517 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001518 [STAC_M1] = "m1",
1519 [STAC_M1_2] = "m1-2",
1520 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001521 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001522 [STAC_M3] = "m3",
1523 [STAC_M5] = "m5",
1524 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001525};
1526
Takashi Iwai2b635362011-05-02 12:33:43 +02001527static const struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001528 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1529 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1530 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1531 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001532 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001533 /* Not sure about the brand name for those */
1534 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1535 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1536 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1537 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001538 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001539};
1540
Takashi Iwai2b635362011-05-02 12:33:43 +02001541static const struct snd_pci_quirk stac925x_cfg_tbl[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001542 /* SigmaTel reference board */
1543 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001544 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001545 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001546
1547 /* Default table for unknown ID */
1548 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1549
Tobin Davis8e21c342007-01-08 11:04:17 +01001550 {} /* terminator */
1551};
1552
Takashi Iwai2b635362011-05-02 12:33:43 +02001553static const unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001554 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1555 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1556 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001557 0x01452050,
1558};
1559
Takashi Iwai2b635362011-05-02 12:33:43 +02001560static const unsigned int dell_m6_pin_configs[13] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001561 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001562 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001563 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1564 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001565};
1566
Takashi Iwai2b635362011-05-02 12:33:43 +02001567static const unsigned int alienware_m17x_pin_configs[13] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001568 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1569 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1570 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1571 0x904601b0,
1572};
1573
Takashi Iwai2b635362011-05-02 12:33:43 +02001574static const unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001575 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001576 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001577};
1578
Takashi Iwai2b635362011-05-02 12:33:43 +02001579static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001580 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001581 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1582 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1583 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001584 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001585 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001586 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001587};
1588
Takashi Iwaiea734962011-01-17 11:29:34 +01001589static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001590 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001591 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001592 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001593 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001594 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1595 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1596 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001597 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001598 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001599};
1600
Takashi Iwai2b635362011-05-02 12:33:43 +02001601static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001602 /* SigmaTel reference board */
1603 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001604 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001605 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1606 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001607 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1608 "Intel DG45ID", STAC_92HD73XX_INTEL),
1609 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1610 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001611 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001612 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001613 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001614 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001615 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001616 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001617 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001618 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001619 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001620 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001621 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001622 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001623 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001624 "unknown Dell", STAC_DELL_M6_DMIC),
1625 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1626 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001627 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001628 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001629 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1630 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001631 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1632 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001633 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1634 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001635 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1636 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001637 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
David Henningssone033ebf2011-05-16 12:09:29 +02001638 "Dell Studio 1558", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001639 {} /* terminator */
1640};
1641
Takashi Iwai2b635362011-05-02 12:33:43 +02001642static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001643 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1644 "Alienware M17x", STAC_ALIENWARE_M17X),
Daniel T Chen0defe092010-12-01 19:16:07 -05001645 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1646 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwai842ae632009-09-02 07:43:08 +02001647 {} /* terminator */
1648};
1649
Takashi Iwai2b635362011-05-02 12:33:43 +02001650static const unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001651 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1652 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001653 0x01451160, 0x98560170,
1654};
1655
Takashi Iwai2b635362011-05-02 12:33:43 +02001656static const unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001657 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1658 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001659 0x40f000f0, 0x40f000f0,
1660};
1661
Takashi Iwai2b635362011-05-02 12:33:43 +02001662static const unsigned int hp_dv7_4000_pin_configs[10] = {
Steven Eastland48315592010-08-06 15:07:35 -06001663 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1664 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1665 0x40f000f0, 0x40f000f0,
1666};
1667
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001668static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
1669 0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
1670 0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
1671 0x40f000f0, 0x40f000f0,
1672};
1673
Takashi Iwai2b635362011-05-02 12:33:43 +02001674static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001675 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001676 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001677 [STAC_DELL_S14] = dell_s14_pin_configs,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001678 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001679 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001680};
1681
Takashi Iwaiea734962011-01-17 11:29:34 +01001682static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001683 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001684 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001685 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001686 [STAC_DELL_S14] = "dell-s14",
Takashi Iwaib4e81872009-11-18 17:20:24 +01001687 [STAC_92HD83XXX_HP] = "hp",
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001688 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
Steven Eastland48315592010-08-06 15:07:35 -06001689 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001690};
1691
Takashi Iwai2b635362011-05-02 12:33:43 +02001692static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001693 /* SigmaTel reference board */
1694 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001695 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001696 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1697 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001698 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1699 "unknown Dell", STAC_DELL_S14),
Takashi Iwaib4e81872009-11-18 17:20:24 +01001700 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001701 "HP", STAC_92HD83XXX_HP),
1702 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
1703 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1704 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
1705 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1706 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
1707 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1708 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
1709 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1710 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
1711 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1712 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1713 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1714 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1715 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1716 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
1717 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1718 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
1719 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1720 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
1721 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1722 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
1723 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1724 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
1725 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1726 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
1727 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1728 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
1729 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1730 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
1731 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1732 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
1733 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1734 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
1735 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1736 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
1737 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1738 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
1739 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1740 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
1741 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001742 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001743};
1744
Takashi Iwai2b635362011-05-02 12:33:43 +02001745static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001746 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001747 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001748 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1749 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001750};
1751
Takashi Iwai2b635362011-05-02 12:33:43 +02001752static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001753 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001754 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001755 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1756 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001757};
1758
Takashi Iwai2b635362011-05-02 12:33:43 +02001759static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001760 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1761 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001762 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1763 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001764};
1765
Takashi Iwai2b635362011-05-02 12:33:43 +02001766static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001767 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1768 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001769 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1770 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001771};
1772
Takashi Iwai2b635362011-05-02 12:33:43 +02001773static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001774 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001775 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1776 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001777 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001778 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001779 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001780 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001781 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001782 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001783};
1784
Takashi Iwaiea734962011-01-17 11:29:34 +01001785static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001786 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001787 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001788 [STAC_DELL_M4_1] = "dell-m4-1",
1789 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001790 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001791 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001792 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001793 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001794 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001795 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001796};
1797
Takashi Iwai2b635362011-05-02 12:33:43 +02001798static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001799 /* SigmaTel reference board */
1800 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1801 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001802 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1803 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001804 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1805 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01001806 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1807 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01001808 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1809 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001810 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001811 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001812 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1813 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001814 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1815 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001816 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001817 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001818 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001819 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001820 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1821 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05301822 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1823 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11001824 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1825 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02001826 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1827 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001828 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1829 "unknown Dell", STAC_DELL_M4_1),
1830 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1831 "unknown Dell", STAC_DELL_M4_1),
1832 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1833 "unknown Dell", STAC_DELL_M4_1),
1834 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1835 "unknown Dell", STAC_DELL_M4_1),
1836 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1837 "unknown Dell", STAC_DELL_M4_1),
1838 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1839 "unknown Dell", STAC_DELL_M4_1),
1840 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1841 "unknown Dell", STAC_DELL_M4_1),
1842 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1843 "unknown Dell", STAC_DELL_M4_2),
1844 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1845 "unknown Dell", STAC_DELL_M4_2),
1846 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1847 "unknown Dell", STAC_DELL_M4_2),
1848 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1849 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001850 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1851 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001852 {} /* terminator */
1853};
1854
Takashi Iwai2b635362011-05-02 12:33:43 +02001855static const unsigned int ref922x_pin_configs[10] = {
Matt Porter403d1942005-11-29 15:00:51 +01001856 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1857 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001858 0x40000100, 0x40000100,
1859};
1860
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001861/*
1862 STAC 922X pin configs for
1863 102801A7
1864 102801AB
1865 102801A9
1866 102801D1
1867 102801D2
1868*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001869static const unsigned int dell_922x_d81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001870 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1871 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1872 0x01813122, 0x400001f2,
1873};
1874
1875/*
1876 STAC 922X pin configs for
1877 102801AC
1878 102801D0
1879*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001880static const unsigned int dell_922x_d82_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001881 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1882 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1883 0x01813122, 0x400001f1,
1884};
1885
1886/*
1887 STAC 922X pin configs for
1888 102801BF
1889*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001890static const unsigned int dell_922x_m81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001891 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1892 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1893 0x40C003f1, 0x405003f0,
1894};
1895
1896/*
1897 STAC 9221 A1 pin configs for
1898 102801D7 (Dell XPS M1210)
1899*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001900static const unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001901 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1902 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001903 0x508003f3, 0x405003f4,
1904};
1905
Takashi Iwai2b635362011-05-02 12:33:43 +02001906static const unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001907 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001908 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1909 0x02a19120, 0x40000100,
1910};
1911
Takashi Iwai2b635362011-05-02 12:33:43 +02001912static const unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001913 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1914 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001915 0x02a19320, 0x40000100,
1916};
1917
Takashi Iwai2b635362011-05-02 12:33:43 +02001918static const unsigned int intel_mac_v1_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001919 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1920 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001921 0x400000fc, 0x400000fb,
1922};
1923
Takashi Iwai2b635362011-05-02 12:33:43 +02001924static const unsigned int intel_mac_v2_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001925 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1926 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001927 0x400000fc, 0x400000fb,
1928};
1929
Takashi Iwai2b635362011-05-02 12:33:43 +02001930static const unsigned int intel_mac_v3_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001931 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1932 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1933 0x400000fc, 0x400000fb,
1934};
1935
Takashi Iwai2b635362011-05-02 12:33:43 +02001936static const unsigned int intel_mac_v4_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001937 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1938 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1939 0x400000fc, 0x400000fb,
1940};
1941
Takashi Iwai2b635362011-05-02 12:33:43 +02001942static const unsigned int intel_mac_v5_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001943 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1944 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1945 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001946};
1947
Takashi Iwai2b635362011-05-02 12:33:43 +02001948static const unsigned int ecs202_pin_configs[10] = {
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001949 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1950 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1951 0x9037012e, 0x40e000f2,
1952};
Takashi Iwai76c08822007-06-19 12:17:42 +02001953
Takashi Iwai2b635362011-05-02 12:33:43 +02001954static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001955 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001956 [STAC_D945GTP3] = d945gtp3_pin_configs,
1957 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001958 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1959 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1960 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1961 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1962 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001963 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001964 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001965 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1966 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1967 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1968 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1969 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1970 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001971 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001972 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1973 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1974 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1975 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001976};
1977
Takashi Iwaiea734962011-01-17 11:29:34 +01001978static const char * const stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001979 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001980 [STAC_D945_REF] = "ref",
1981 [STAC_D945GTP5] = "5stack",
1982 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001983 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1984 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1985 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1986 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1987 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001988 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001989 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001990 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001991 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001992 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1993 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001994 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001995 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001996 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001997 [STAC_922X_DELL_D81] = "dell-d81",
1998 [STAC_922X_DELL_D82] = "dell-d82",
1999 [STAC_922X_DELL_M81] = "dell-m81",
2000 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002001};
2002
Takashi Iwai2b635362011-05-02 12:33:43 +02002003static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002004 /* SigmaTel reference board */
2005 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2006 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002007 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2008 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002009 /* Intel 945G based systems */
2010 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2011 "Intel D945G", STAC_D945GTP3),
2012 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2013 "Intel D945G", STAC_D945GTP3),
2014 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2015 "Intel D945G", STAC_D945GTP3),
2016 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2017 "Intel D945G", STAC_D945GTP3),
2018 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2019 "Intel D945G", STAC_D945GTP3),
2020 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2021 "Intel D945G", STAC_D945GTP3),
2022 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2023 "Intel D945G", STAC_D945GTP3),
2024 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2025 "Intel D945G", STAC_D945GTP3),
2026 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2027 "Intel D945G", STAC_D945GTP3),
2028 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2029 "Intel D945G", STAC_D945GTP3),
2030 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2031 "Intel D945G", STAC_D945GTP3),
2032 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2033 "Intel D945G", STAC_D945GTP3),
2034 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2035 "Intel D945G", STAC_D945GTP3),
2036 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2037 "Intel D945G", STAC_D945GTP3),
2038 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2039 "Intel D945G", STAC_D945GTP3),
2040 /* Intel D945G 5-stack systems */
2041 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2042 "Intel D945G", STAC_D945GTP5),
2043 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2044 "Intel D945G", STAC_D945GTP5),
2045 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2046 "Intel D945G", STAC_D945GTP5),
2047 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2048 "Intel D945G", STAC_D945GTP5),
2049 /* Intel 945P based systems */
2050 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2051 "Intel D945P", STAC_D945GTP3),
2052 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2053 "Intel D945P", STAC_D945GTP3),
2054 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2055 "Intel D945P", STAC_D945GTP3),
2056 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2057 "Intel D945P", STAC_D945GTP3),
2058 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2059 "Intel D945P", STAC_D945GTP3),
2060 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2061 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002062 /* other intel */
2063 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2064 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002065 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002066 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002067 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002068 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002069 /* Dell systems */
2070 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2071 "unknown Dell", STAC_922X_DELL_D81),
2072 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2073 "unknown Dell", STAC_922X_DELL_D81),
2074 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2075 "unknown Dell", STAC_922X_DELL_D81),
2076 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2077 "unknown Dell", STAC_922X_DELL_D82),
2078 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2079 "unknown Dell", STAC_922X_DELL_M81),
2080 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2081 "unknown Dell", STAC_922X_DELL_D82),
2082 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2083 "unknown Dell", STAC_922X_DELL_D81),
2084 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2085 "unknown Dell", STAC_922X_DELL_D81),
2086 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2087 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002088 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002089 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002090 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002091 {} /* terminator */
2092};
2093
Takashi Iwai2b635362011-05-02 12:33:43 +02002094static const unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002095 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2096 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2097 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2098 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002099};
2100
Takashi Iwai2b635362011-05-02 12:33:43 +02002101static const unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002102 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2103 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2104 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2105 0x40000100, 0x40000100
2106};
2107
Takashi Iwai2b635362011-05-02 12:33:43 +02002108static const unsigned int d965_5st_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002109 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2110 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2111 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2112 0x40000100, 0x40000100
2113};
2114
Takashi Iwai2b635362011-05-02 12:33:43 +02002115static const unsigned int d965_5st_no_fp_pin_configs[14] = {
Takashi Iwai679d92e2009-05-24 19:00:08 +02002116 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2117 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2118 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2119 0x40000100, 0x40000100
2120};
2121
Takashi Iwai2b635362011-05-02 12:33:43 +02002122static const unsigned int dell_3st_pin_configs[14] = {
Tobin Davis4ff076e2007-08-07 11:48:12 +02002123 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2124 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002125 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002126 0x40c003fc, 0x40000100
2127};
2128
Takashi Iwai2b635362011-05-02 12:33:43 +02002129static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002130 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002131 [STAC_D965_REF] = ref927x_pin_configs,
2132 [STAC_D965_3ST] = d965_3st_pin_configs,
2133 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002134 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002135 [STAC_DELL_3ST] = dell_3st_pin_configs,
2136 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002137 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002138};
2139
Takashi Iwaiea734962011-01-17 11:29:34 +01002140static const char * const stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002141 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002142 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002143 [STAC_D965_REF] = "ref",
2144 [STAC_D965_3ST] = "3stack",
2145 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002146 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002147 [STAC_DELL_3ST] = "dell-3stack",
2148 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002149 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002150};
2151
Takashi Iwai2b635362011-05-02 12:33:43 +02002152static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002153 /* SigmaTel reference board */
2154 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2155 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002156 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2157 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002158 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002159 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2160 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002161 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002162 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2163 "Intel D965", STAC_D965_3ST),
2164 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2165 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002166 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002167 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002168 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2169 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002170 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002171 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002172 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002173 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002174 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002175 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002176 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2177 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2178 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2179 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002180 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002181 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2182 "Intel D965", STAC_D965_5ST),
2183 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2184 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002185 /* volume-knob fixes */
2186 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002187 {} /* terminator */
2188};
2189
Takashi Iwai2b635362011-05-02 12:33:43 +02002190static const unsigned int ref9205_pin_configs[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +02002191 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002192 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002193 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002194};
2195
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002196/*
2197 STAC 9205 pin configs for
2198 102801F1
2199 102801F2
2200 102801FC
2201 102801FD
2202 10280204
2203 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002204 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002205 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002206*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002207static const unsigned int dell_9205_m42_pin_configs[12] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002208 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2209 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2210 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2211};
2212
2213/*
2214 STAC 9205 pin configs for
2215 102801F9
2216 102801FA
2217 102801FE
2218 102801FF (Dell Precision M4300)
2219 10280206
2220 10280200
2221 10280201
2222*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002223static const unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002224 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2225 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2226 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2227};
2228
Takashi Iwai2b635362011-05-02 12:33:43 +02002229static const unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002230 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2231 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2232 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2233};
2234
Takashi Iwai2b635362011-05-02 12:33:43 +02002235static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002236 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002237 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2238 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2239 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002240 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002241};
2242
Takashi Iwaiea734962011-01-17 11:29:34 +01002243static const char * const stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002244 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002245 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002246 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002247 [STAC_9205_DELL_M43] = "dell-m43",
2248 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002249 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002250};
2251
Takashi Iwai2b635362011-05-02 12:33:43 +02002252static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002253 /* SigmaTel reference board */
2254 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2255 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002256 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2257 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002258 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2259 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002260 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002261 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2262 "unknown Dell", STAC_9205_DELL_M42),
2263 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2264 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002265 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002266 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002267 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2268 "Dell Precision", STAC_9205_DELL_M43),
2269 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2270 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002271 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2272 "unknown Dell", STAC_9205_DELL_M42),
2273 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2274 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002275 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2276 "Dell Precision", STAC_9205_DELL_M43),
2277 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002278 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002279 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2280 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002281 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2282 "Dell Precision", STAC_9205_DELL_M43),
2283 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2284 "Dell Precision", STAC_9205_DELL_M43),
2285 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2286 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002287 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2288 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002289 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2290 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002291 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2292 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002293 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002294 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002295 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002296 {} /* terminator */
2297};
2298
Takashi Iwai330ee992009-02-20 14:33:36 +01002299static void stac92xx_set_config_regs(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002300 const unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002301{
2302 int i;
2303 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002304
Takashi Iwai330ee992009-02-20 14:33:36 +01002305 if (!pincfgs)
2306 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002307
Matthew Ranostay87d48362007-07-17 11:52:24 +02002308 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002309 if (spec->pin_nids[i] && pincfgs[i])
2310 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2311 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002312}
2313
Matt2f2f4252005-04-13 14:45:30 +02002314/*
2315 * Analog playback callbacks
2316 */
2317static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2318 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002319 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002320{
2321 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002322 if (spec->stream_delay)
2323 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002324 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2325 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002326}
2327
2328static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2329 struct hda_codec *codec,
2330 unsigned int stream_tag,
2331 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002332 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002333{
2334 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002335 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002336}
2337
2338static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2339 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002340 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002341{
2342 struct sigmatel_spec *spec = codec->spec;
2343 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2344}
2345
2346/*
Mattdabbed62005-06-14 10:19:34 +02002347 * Digital playback callbacks
2348 */
2349static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2350 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002351 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002352{
2353 struct sigmatel_spec *spec = codec->spec;
2354 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2355}
2356
2357static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2358 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002359 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002360{
2361 struct sigmatel_spec *spec = codec->spec;
2362 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2363}
2364
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002365static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2366 struct hda_codec *codec,
2367 unsigned int stream_tag,
2368 unsigned int format,
2369 struct snd_pcm_substream *substream)
2370{
2371 struct sigmatel_spec *spec = codec->spec;
2372 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2373 stream_tag, format, substream);
2374}
2375
Takashi Iwai9411e212009-02-13 11:32:28 +01002376static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2377 struct hda_codec *codec,
2378 struct snd_pcm_substream *substream)
2379{
2380 struct sigmatel_spec *spec = codec->spec;
2381 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2382}
2383
Mattdabbed62005-06-14 10:19:34 +02002384
2385/*
Matt2f2f4252005-04-13 14:45:30 +02002386 * Analog capture callbacks
2387 */
2388static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2389 struct hda_codec *codec,
2390 unsigned int stream_tag,
2391 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002392 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002393{
2394 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002395 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002396
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002397 if (spec->powerdown_adcs) {
2398 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002399 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002400 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2401 }
2402 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002403 return 0;
2404}
2405
2406static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2407 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002408 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002409{
2410 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002411 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002412
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002413 snd_hda_codec_cleanup_stream(codec, nid);
2414 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002415 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002416 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002417 return 0;
2418}
2419
Takashi Iwai2b635362011-05-02 12:33:43 +02002420static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
Mattdabbed62005-06-14 10:19:34 +02002421 .substreams = 1,
2422 .channels_min = 2,
2423 .channels_max = 2,
2424 /* NID is set in stac92xx_build_pcms */
2425 .ops = {
2426 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002427 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002428 .prepare = stac92xx_dig_playback_pcm_prepare,
2429 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002430 },
2431};
2432
Takashi Iwai2b635362011-05-02 12:33:43 +02002433static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
Mattdabbed62005-06-14 10:19:34 +02002434 .substreams = 1,
2435 .channels_min = 2,
2436 .channels_max = 2,
2437 /* NID is set in stac92xx_build_pcms */
2438};
2439
Takashi Iwai2b635362011-05-02 12:33:43 +02002440static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
Matt2f2f4252005-04-13 14:45:30 +02002441 .substreams = 1,
2442 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002443 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002444 .nid = 0x02, /* NID to query formats and rates */
2445 .ops = {
2446 .open = stac92xx_playback_pcm_open,
2447 .prepare = stac92xx_playback_pcm_prepare,
2448 .cleanup = stac92xx_playback_pcm_cleanup
2449 },
2450};
2451
Takashi Iwai2b635362011-05-02 12:33:43 +02002452static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002453 .substreams = 1,
2454 .channels_min = 2,
2455 .channels_max = 2,
2456 .nid = 0x06, /* NID to query formats and rates */
2457 .ops = {
2458 .open = stac92xx_playback_pcm_open,
2459 .prepare = stac92xx_playback_pcm_prepare,
2460 .cleanup = stac92xx_playback_pcm_cleanup
2461 },
2462};
2463
Takashi Iwai2b635362011-05-02 12:33:43 +02002464static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002465 .channels_min = 2,
2466 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002467 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002468 .ops = {
2469 .prepare = stac92xx_capture_pcm_prepare,
2470 .cleanup = stac92xx_capture_pcm_cleanup
2471 },
2472};
2473
2474static int stac92xx_build_pcms(struct hda_codec *codec)
2475{
2476 struct sigmatel_spec *spec = codec->spec;
2477 struct hda_pcm *info = spec->pcm_rec;
2478
2479 codec->num_pcms = 1;
2480 codec->pcm_info = info;
2481
Mattc7d4b2f2005-06-27 14:59:41 +02002482 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002483 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002484 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2485 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002486 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002487 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002488 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002489
2490 if (spec->alt_switch) {
2491 codec->num_pcms++;
2492 info++;
2493 info->name = "STAC92xx Analog Alt";
2494 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2495 }
Matt2f2f4252005-04-13 14:45:30 +02002496
Mattdabbed62005-06-14 10:19:34 +02002497 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2498 codec->num_pcms++;
2499 info++;
2500 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002501 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002502 if (spec->multiout.dig_out_nid) {
2503 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2504 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2505 }
2506 if (spec->dig_in_nid) {
2507 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2508 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2509 }
2510 }
2511
Matt2f2f4252005-04-13 14:45:30 +02002512 return 0;
2513}
2514
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002515static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2516 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002517{
Takashi Iwai1327a322009-03-23 13:07:47 +01002518 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002519 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2520 if (pincap & AC_PINCAP_VREF_100)
2521 return AC_PINCTL_VREF_100;
2522 if (pincap & AC_PINCAP_VREF_80)
2523 return AC_PINCTL_VREF_80;
2524 if (pincap & AC_PINCAP_VREF_50)
2525 return AC_PINCTL_VREF_50;
2526 if (pincap & AC_PINCAP_VREF_GRD)
2527 return AC_PINCTL_VREF_GRD;
2528 return 0;
2529}
2530
Matt Porter403d1942005-11-29 15:00:51 +01002531static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2532
2533{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002534 snd_hda_codec_write_cache(codec, nid, 0,
2535 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002536}
2537
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002538#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2539
2540static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2541 struct snd_ctl_elem_value *ucontrol)
2542{
2543 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2544 struct sigmatel_spec *spec = codec->spec;
2545
Takashi Iwaid7a89432008-11-12 09:48:04 +01002546 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002547 return 0;
2548}
2549
Takashi Iwai62558ce2009-07-29 14:23:09 +02002550static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002551
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002552static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2553 struct snd_ctl_elem_value *ucontrol)
2554{
2555 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2556 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002557 int nid = kcontrol->private_value;
2558
2559 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002560
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002561 /* check to be sure that the ports are up to date with
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002562 * switch changes
2563 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002564 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002565
2566 return 1;
2567}
2568
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002569static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2570 struct snd_ctl_elem_info *uinfo)
2571{
2572 int i;
Takashi Iwai2b635362011-05-02 12:33:43 +02002573 static const char * const texts[] = {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002574 "Mic In", "Line In", "Line Out"
2575 };
2576
2577 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2578 struct sigmatel_spec *spec = codec->spec;
2579 hda_nid_t nid = kcontrol->private_value;
2580
2581 if (nid == spec->mic_switch || nid == spec->line_switch)
2582 i = 3;
2583 else
2584 i = 2;
2585
2586 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2587 uinfo->value.enumerated.items = i;
2588 uinfo->count = 1;
2589 if (uinfo->value.enumerated.item >= i)
2590 uinfo->value.enumerated.item = i-1;
2591 strcpy(uinfo->value.enumerated.name,
2592 texts[uinfo->value.enumerated.item]);
2593
2594 return 0;
2595}
2596
2597static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2598 struct snd_ctl_elem_value *ucontrol)
2599{
2600 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2601 hda_nid_t nid = kcontrol->private_value;
2602 unsigned int vref = stac92xx_vref_get(codec, nid);
2603
2604 if (vref == stac92xx_get_default_vref(codec, nid))
2605 ucontrol->value.enumerated.item[0] = 0;
2606 else if (vref == AC_PINCTL_VREF_GRD)
2607 ucontrol->value.enumerated.item[0] = 1;
2608 else if (vref == AC_PINCTL_VREF_HIZ)
2609 ucontrol->value.enumerated.item[0] = 2;
2610
2611 return 0;
2612}
2613
2614static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2615 struct snd_ctl_elem_value *ucontrol)
2616{
2617 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2618 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002619 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002620 hda_nid_t nid = kcontrol->private_value;
2621
2622 if (ucontrol->value.enumerated.item[0] == 0)
2623 new_vref = stac92xx_get_default_vref(codec, nid);
2624 else if (ucontrol->value.enumerated.item[0] == 1)
2625 new_vref = AC_PINCTL_VREF_GRD;
2626 else if (ucontrol->value.enumerated.item[0] == 2)
2627 new_vref = AC_PINCTL_VREF_HIZ;
2628 else
2629 return 0;
2630
2631 if (new_vref != stac92xx_vref_get(codec, nid)) {
2632 error = stac92xx_vref_set(codec, nid, new_vref);
2633 return error;
2634 }
2635
2636 return 0;
2637}
2638
2639static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2640 struct snd_ctl_elem_info *uinfo)
2641{
Takashi Iwai2b635362011-05-02 12:33:43 +02002642 char *texts[2];
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2644 struct sigmatel_spec *spec = codec->spec;
2645
2646 if (kcontrol->private_value == spec->line_switch)
2647 texts[0] = "Line In";
2648 else
2649 texts[0] = "Mic In";
2650 texts[1] = "Line Out";
2651 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2652 uinfo->value.enumerated.items = 2;
2653 uinfo->count = 1;
2654
2655 if (uinfo->value.enumerated.item >= 2)
2656 uinfo->value.enumerated.item = 1;
2657 strcpy(uinfo->value.enumerated.name,
2658 texts[uinfo->value.enumerated.item]);
2659
2660 return 0;
2661}
Matt Porter403d1942005-11-29 15:00:51 +01002662
2663static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2664{
2665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2666 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002667 hda_nid_t nid = kcontrol->private_value;
2668 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002669
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002670 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002671 return 0;
2672}
2673
2674static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2675{
2676 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2677 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002678 hda_nid_t nid = kcontrol->private_value;
2679 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2680 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002681
2682 spec->io_switch[io_idx] = val;
2683
2684 if (val)
2685 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002686 else {
2687 unsigned int pinctl = AC_PINCTL_IN_EN;
2688 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002689 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002690 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2691 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002692
2693 /* check the auto-mute again: we need to mute/unmute the speaker
2694 * appropriately according to the pin direction
2695 */
2696 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002697 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002698
Matt Porter403d1942005-11-29 15:00:51 +01002699 return 1;
2700}
2701
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002702#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2703
2704static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2705 struct snd_ctl_elem_value *ucontrol)
2706{
2707 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2708 struct sigmatel_spec *spec = codec->spec;
2709
2710 ucontrol->value.integer.value[0] = spec->clfe_swap;
2711 return 0;
2712}
2713
2714static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2715 struct snd_ctl_elem_value *ucontrol)
2716{
2717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2718 struct sigmatel_spec *spec = codec->spec;
2719 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002720 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002721
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002722 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002723 return 0;
2724
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002725 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002726
2727 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2728 spec->clfe_swap ? 0x4 : 0x0);
2729
2730 return 1;
2731}
2732
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002733#define STAC_CODEC_HP_SWITCH(xname) \
2734 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2735 .name = xname, \
2736 .index = 0, \
2737 .info = stac92xx_hp_switch_info, \
2738 .get = stac92xx_hp_switch_get, \
2739 .put = stac92xx_hp_switch_put, \
2740 }
2741
Matt Porter403d1942005-11-29 15:00:51 +01002742#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2743 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2744 .name = xname, \
2745 .index = 0, \
2746 .info = stac92xx_io_switch_info, \
2747 .get = stac92xx_io_switch_get, \
2748 .put = stac92xx_io_switch_put, \
2749 .private_value = xpval, \
2750 }
2751
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002752#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2753 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2754 .name = xname, \
2755 .index = 0, \
2756 .info = stac92xx_clfe_switch_info, \
2757 .get = stac92xx_clfe_switch_get, \
2758 .put = stac92xx_clfe_switch_put, \
2759 .private_value = xpval, \
2760 }
Matt Porter403d1942005-11-29 15:00:51 +01002761
Mattc7d4b2f2005-06-27 14:59:41 +02002762enum {
2763 STAC_CTL_WIDGET_VOL,
2764 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002765 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002766 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002767 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002768 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002769 STAC_CTL_WIDGET_CLFE_SWITCH,
2770 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002771};
2772
Takashi Iwai2b635362011-05-02 12:33:43 +02002773static const struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002774 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2775 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002776 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002777 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002778 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002779 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002780 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002781 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002782};
2783
2784/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002785static struct snd_kcontrol_new *
2786stac_control_new(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002787 const struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002788 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002789 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002790{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002791 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002792
Takashi Iwai603c4012008-07-30 15:01:44 +02002793 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2794 knew = snd_array_new(&spec->kctls);
2795 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002796 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002797 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002798 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002799 if (!knew->name) {
2800 /* roolback */
2801 memset(knew, 0, sizeof(*knew));
2802 spec->kctls.alloced--;
2803 return NULL;
2804 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002805 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002806 return knew;
2807}
2808
2809static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002810 const struct snd_kcontrol_new *ktemp,
Takashi Iwaie3c75962009-01-23 11:57:22 +01002811 int idx, const char *name,
2812 unsigned long val)
2813{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002814 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002815 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002816 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002817 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002818 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002819 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002820 return 0;
2821}
2822
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002823static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2824 int type, int idx, const char *name,
2825 unsigned long val)
2826{
2827 return stac92xx_add_control_temp(spec,
2828 &stac92xx_control_templates[type],
2829 idx, name, val);
2830}
2831
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002832
2833/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002834static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2835 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002836{
2837 return stac92xx_add_control_idx(spec, type, 0, name, val);
2838}
2839
Takashi Iwai2b635362011-05-02 12:33:43 +02002840static const struct snd_kcontrol_new stac_input_src_temp = {
Takashi Iwaie3c75962009-01-23 11:57:22 +01002841 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2842 .name = "Input Source",
2843 .info = stac92xx_mux_enum_info,
2844 .get = stac92xx_mux_enum_get,
2845 .put = stac92xx_mux_enum_put,
2846};
2847
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002848static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2849 hda_nid_t nid, int idx)
2850{
2851 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2852 int control = 0;
2853 struct sigmatel_spec *spec = codec->spec;
2854 char name[22];
2855
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002856 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002857 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2858 && nid == spec->line_switch)
2859 control = STAC_CTL_WIDGET_IO_SWITCH;
2860 else if (snd_hda_query_pin_caps(codec, nid)
2861 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2862 control = STAC_CTL_WIDGET_DC_BIAS;
2863 else if (nid == spec->mic_switch)
2864 control = STAC_CTL_WIDGET_IO_SWITCH;
2865 }
2866
2867 if (control) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002868 strcpy(name, hda_get_input_pin_label(codec, nid, 1));
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002869 return stac92xx_add_control(codec->spec, control,
2870 strcat(name, " Jack Mode"), nid);
2871 }
2872
2873 return 0;
2874}
2875
Takashi Iwaie3c75962009-01-23 11:57:22 +01002876static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2877{
2878 struct snd_kcontrol_new *knew;
2879 struct hda_input_mux *imux = &spec->private_imux;
2880
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002881 if (spec->auto_mic)
2882 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002883 if (!spec->num_adcs || imux->num_items <= 1)
2884 return 0; /* no need for input source control */
2885 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002886 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002887 if (!knew)
2888 return -ENOMEM;
2889 knew->count = spec->num_adcs;
2890 return 0;
2891}
2892
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002893/* check whether the line-input can be used as line-out */
2894static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002895{
2896 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002897 struct auto_pin_cfg *cfg = &spec->autocfg;
2898 hda_nid_t nid;
2899 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002900 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002901
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002902 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2903 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002904 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02002905 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002906 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01002907 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002908 if (pincap & AC_PINCAP_OUT)
2909 return nid;
2910 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002911 }
Matt Porter403d1942005-11-29 15:00:51 +01002912 return 0;
2913}
2914
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002915static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2916
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002917/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002918static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002919{
2920 struct sigmatel_spec *spec = codec->spec;
2921 struct auto_pin_cfg *cfg = &spec->autocfg;
2922 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02002923 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002924
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002925 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002926 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2927 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002928 for (i = 0; i < cfg->num_inputs; i++) {
2929 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02002930 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002931 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002932 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2933 /* some laptops have an internal analog microphone
2934 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002935 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002936 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002937 if (pincap & AC_PINCAP_OUT) {
2938 *dac = get_unassigned_dac(codec, nid);
2939 if (*dac)
2940 return nid;
2941 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002942 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002943 }
2944 return 0;
2945}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002946
2947static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2948{
2949 int i;
2950
2951 for (i = 0; i < spec->multiout.num_dacs; i++) {
2952 if (spec->multiout.dac_nids[i] == nid)
2953 return 1;
2954 }
2955
2956 return 0;
2957}
2958
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002959static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2960{
2961 int i;
2962 if (is_in_dac_nids(spec, nid))
2963 return 1;
2964 for (i = 0; i < spec->autocfg.hp_outs; i++)
2965 if (spec->hp_dacs[i] == nid)
2966 return 1;
2967 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2968 if (spec->speaker_dacs[i] == nid)
2969 return 1;
2970 return 0;
2971}
2972
2973static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2974{
2975 struct sigmatel_spec *spec = codec->spec;
David Henningsson48718ea2011-10-05 09:49:05 +02002976 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002977 int j, conn_len;
David Henningsson48718ea2011-10-05 09:49:05 +02002978 hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002979 unsigned int wcaps, wtype;
2980
2981 conn_len = snd_hda_get_connections(codec, nid, conn,
2982 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002983 /* 92HD88: trace back up the link of nids to find the DAC */
2984 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2985 != AC_WID_AUD_OUT)) {
2986 nid = conn[0];
2987 conn_len = snd_hda_get_connections(codec, nid, conn,
2988 HDA_MAX_CONNECTIONS);
2989 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002990 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002991 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002992 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002993 /* we check only analog outputs */
2994 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2995 continue;
2996 /* if this route has a free DAC, assign it */
2997 if (!check_all_dac_nids(spec, conn[j])) {
2998 if (conn_len > 1) {
2999 /* select this DAC in the pin's input mux */
3000 snd_hda_codec_write_cache(codec, nid, 0,
3001 AC_VERB_SET_CONNECT_SEL, j);
3002 }
3003 return conn[j];
3004 }
3005 }
David Henningsson48718ea2011-10-05 09:49:05 +02003006
3007 /* if all DACs are already assigned, connect to the primary DAC,
3008 unless we're assigning a secondary headphone */
3009 fallback_dac = spec->multiout.dac_nids[0];
3010 if (spec->multiout.hp_nid) {
3011 for (j = 0; j < cfg->hp_outs; j++)
3012 if (cfg->hp_pins[j] == nid) {
3013 fallback_dac = spec->multiout.hp_nid;
3014 break;
3015 }
3016 }
3017
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003018 if (conn_len > 1) {
3019 for (j = 0; j < conn_len; j++) {
David Henningsson48718ea2011-10-05 09:49:05 +02003020 if (conn[j] == fallback_dac) {
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003021 snd_hda_codec_write_cache(codec, nid, 0,
3022 AC_VERB_SET_CONNECT_SEL, j);
3023 break;
3024 }
3025 }
3026 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003027 return 0;
3028}
3029
3030static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3031static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3032
Matt Porter3cc08dc2006-01-23 15:27:49 +01003033/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02003034 * Fill in the dac_nids table from the parsed pin configuration
3035 * This function only works when every pin in line_out_pins[]
3036 * contains atleast one DAC in its connection list. Some 92xx
3037 * codecs are not connected directly to a DAC, such as the 9200
3038 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01003039 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003040static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003041{
3042 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003043 struct auto_pin_cfg *cfg = &spec->autocfg;
3044 int i;
3045 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02003046
Mattc7d4b2f2005-06-27 14:59:41 +02003047 for (i = 0; i < cfg->line_outs; i++) {
3048 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003049 dac = get_unassigned_dac(codec, nid);
3050 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003051 if (spec->multiout.num_dacs > 0) {
3052 /* we have already working output pins,
3053 * so let's drop the broken ones again
3054 */
3055 cfg->line_outs = spec->multiout.num_dacs;
3056 break;
3057 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003058 /* error out, no available DAC found */
3059 snd_printk(KERN_ERR
3060 "%s: No available DAC for pin 0x%x\n",
3061 __func__, nid);
3062 return -ENODEV;
3063 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003064 add_spec_dacs(spec, dac);
3065 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003066
Takashi Iwai139e0712009-03-06 12:10:41 +01003067 for (i = 0; i < cfg->hp_outs; i++) {
3068 nid = cfg->hp_pins[i];
3069 dac = get_unassigned_dac(codec, nid);
3070 if (dac) {
3071 if (!spec->multiout.hp_nid)
3072 spec->multiout.hp_nid = dac;
3073 else
3074 add_spec_extra_dacs(spec, dac);
3075 }
3076 spec->hp_dacs[i] = dac;
3077 }
3078
3079 for (i = 0; i < cfg->speaker_outs; i++) {
3080 nid = cfg->speaker_pins[i];
3081 dac = get_unassigned_dac(codec, nid);
3082 if (dac)
3083 add_spec_extra_dacs(spec, dac);
3084 spec->speaker_dacs[i] = dac;
3085 }
3086
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003087 /* add line-in as output */
3088 nid = check_line_out_switch(codec);
3089 if (nid) {
3090 dac = get_unassigned_dac(codec, nid);
3091 if (dac) {
3092 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3093 nid, cfg->line_outs);
3094 cfg->line_out_pins[cfg->line_outs] = nid;
3095 cfg->line_outs++;
3096 spec->line_switch = nid;
3097 add_spec_dacs(spec, dac);
3098 }
3099 }
3100 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003101 nid = check_mic_out_switch(codec, &dac);
3102 if (nid && dac) {
3103 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3104 nid, cfg->line_outs);
3105 cfg->line_out_pins[cfg->line_outs] = nid;
3106 cfg->line_outs++;
3107 spec->mic_switch = nid;
3108 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003109 }
3110
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003111 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003112 spec->multiout.num_dacs,
3113 spec->multiout.dac_nids[0],
3114 spec->multiout.dac_nids[1],
3115 spec->multiout.dac_nids[2],
3116 spec->multiout.dac_nids[3],
3117 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003118
Mattc7d4b2f2005-06-27 14:59:41 +02003119 return 0;
3120}
3121
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003122/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003123static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3124 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003125{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003126 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003127 char name[32];
3128 int err;
3129
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003130 if (!spec->check_volume_offset) {
3131 unsigned int caps, step, nums, db_scale;
3132 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3133 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3134 AC_AMPCAP_STEP_SIZE_SHIFT;
3135 step = (step + 1) * 25; /* in .01dB unit */
3136 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3137 AC_AMPCAP_NUM_STEPS_SHIFT;
3138 db_scale = nums * step;
3139 /* if dB scale is over -64dB, and finer enough,
3140 * let's reduce it to half
3141 */
3142 if (db_scale > 6400 && nums >= 0x1f)
3143 spec->volume_offset = nums / 2;
3144 spec->check_volume_offset = 1;
3145 }
3146
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003147 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003148 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003149 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3150 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003151 if (err < 0)
3152 return err;
3153 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003154 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003155 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3156 if (err < 0)
3157 return err;
3158 return 0;
3159}
3160
Takashi Iwai668b9652009-03-06 10:13:24 +01003161#define create_controls(codec, pfx, nid, chs) \
3162 create_controls_idx(codec, pfx, 0, nid, chs)
3163
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003164static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3165{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003166 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003167 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3168 return 1;
3169 } else {
Takashi Iwaidda14412011-05-02 11:29:30 +02003170 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3171 spec->dac_nids[spec->multiout.num_dacs] = nid;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003172 spec->multiout.num_dacs++;
3173 }
3174 return 0;
3175}
3176
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003177static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003178{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003179 int i;
3180 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3181 if (!spec->multiout.extra_out_nid[i]) {
3182 spec->multiout.extra_out_nid[i] = nid;
3183 return 0;
3184 }
3185 }
3186 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3187 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003188}
3189
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003190/* Create output controls
3191 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3192 */
3193static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3194 const hda_nid_t *pins,
3195 const hda_nid_t *dac_nids,
3196 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003197{
Takashi Iwai76624532008-12-19 10:09:47 +01003198 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaiea734962011-01-17 11:29:34 +01003199 static const char * const chname[4] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02003200 "Front", "Surround", NULL /*CLFE*/, "Side"
3201 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003202 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003203 int i, err;
3204 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003205
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003206 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003207 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003208 if (is_jack_detectable(codec, pins[i]))
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003209 spec->hp_detect = 1;
3210 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003211 nid = dac_nids[i];
3212 if (!nid)
3213 continue;
3214 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003215 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003216 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003217 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003218 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003219 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003220 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003221 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003222
3223 wid_caps = get_wcaps(codec, nid);
3224
3225 if (wid_caps & AC_WCAP_LR_SWAP) {
3226 err = stac92xx_add_control(spec,
3227 STAC_CTL_WIDGET_CLFE_SWITCH,
3228 "Swap Center/LFE Playback Switch", nid);
3229
3230 if (err < 0)
3231 return err;
3232 }
3233
Mattc7d4b2f2005-06-27 14:59:41 +02003234 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003235 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003236 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003237 switch (type) {
3238 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003239 name = "Headphone";
3240 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003241 break;
3242 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003243 name = "Speaker";
3244 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003245 break;
3246 default:
3247 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003248 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003249 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003250 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003251 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003252 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003253 return err;
3254 }
3255 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003256 return 0;
3257}
3258
Takashi Iwai6479c632009-07-28 18:20:25 +02003259static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3260 unsigned long sw, int idx)
3261{
3262 int err;
3263 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003264 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003265 if (err < 0)
3266 return err;
3267 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003268 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003269 if (err < 0)
3270 return err;
3271 return 0;
3272}
3273
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003274/* add playback controls from the parsed DAC table */
3275static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3276 const struct auto_pin_cfg *cfg)
3277{
3278 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003279 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003280 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003281 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003282
3283 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3284 spec->multiout.dac_nids,
3285 cfg->line_out_type);
3286 if (err < 0)
3287 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003288
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003289 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003290 err = stac92xx_add_control(spec,
3291 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003292 "Headphone as Line Out Switch",
3293 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003294 if (err < 0)
3295 return err;
3296 }
3297
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003298 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003299 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003300 break;
3301 nid = cfg->inputs[idx].pin;
3302 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3303 if (err < 0)
3304 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003305 }
Matt Porter403d1942005-11-29 15:00:51 +01003306
Mattc7d4b2f2005-06-27 14:59:41 +02003307 return 0;
3308}
3309
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003310/* add playback controls for Speaker and HP outputs */
3311static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3312 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003313{
3314 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003315 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003316
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003317 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3318 spec->hp_dacs, AUTO_PIN_HP_OUT);
3319 if (err < 0)
3320 return err;
3321
3322 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3323 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3324 if (err < 0)
3325 return err;
3326
Mattc7d4b2f2005-06-27 14:59:41 +02003327 return 0;
3328}
3329
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003330/* labels for mono mux outputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003331static const char * const stac92xx_mono_labels[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003332 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003333};
3334
3335/* create mono mux for mono out on capable codecs */
3336static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3337{
3338 struct sigmatel_spec *spec = codec->spec;
3339 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3340 int i, num_cons;
3341 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3342
3343 num_cons = snd_hda_get_connections(codec,
3344 spec->mono_nid,
3345 con_lst,
3346 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003347 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003348 return -EINVAL;
3349
Takashi Iwai10a20af2010-09-09 16:28:02 +02003350 for (i = 0; i < num_cons; i++)
3351 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3352 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003353
3354 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3355 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003356}
3357
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003358/* create PC beep volume controls */
3359static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3360 hda_nid_t nid)
3361{
3362 struct sigmatel_spec *spec = codec->spec;
3363 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003364 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3365
3366 if (spec->anabeep_nid == nid)
3367 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003368
3369 /* check for mute support for the the amp */
3370 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003371 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003372 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003373 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3374 if (err < 0)
3375 return err;
3376 }
3377
3378 /* check to see if there is volume support for the amp */
3379 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3380 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003381 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003382 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3383 if (err < 0)
3384 return err;
3385 }
3386 return 0;
3387}
3388
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003389#ifdef CONFIG_SND_HDA_INPUT_BEEP
3390#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3391
3392static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3393 struct snd_ctl_elem_value *ucontrol)
3394{
3395 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3396 ucontrol->value.integer.value[0] = codec->beep->enabled;
3397 return 0;
3398}
3399
3400static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3401 struct snd_ctl_elem_value *ucontrol)
3402{
3403 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003404 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003405}
3406
Takashi Iwai2b635362011-05-02 12:33:43 +02003407static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003408 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3409 .info = stac92xx_dig_beep_switch_info,
3410 .get = stac92xx_dig_beep_switch_get,
3411 .put = stac92xx_dig_beep_switch_put,
3412};
3413
3414static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3415{
3416 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003417 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003418}
3419#endif
3420
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003421static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3422{
3423 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003424 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003425
3426 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003427 hda_nid_t nid;
3428 unsigned int wcaps;
3429 unsigned long val;
3430
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003431 nid = spec->mux_nids[i];
3432 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003433 if (!(wcaps & AC_WCAP_OUT_AMP))
3434 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003435
Takashi Iwai667067d2009-08-13 18:14:42 +02003436 /* check whether already the same control was created as
3437 * normal Capture Volume.
3438 */
3439 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3440 for (j = 0; j < spec->num_caps; j++) {
3441 if (spec->capvols[j] == val)
3442 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003443 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003444 if (j < spec->num_caps)
3445 continue;
3446
3447 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3448 "Mux Capture Volume", val);
3449 if (err < 0)
3450 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003451 }
3452 return 0;
3453};
3454
Takashi Iwaiea734962011-01-17 11:29:34 +01003455static const char * const stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003456 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003457};
3458
3459static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3460{
3461 struct sigmatel_spec *spec = codec->spec;
3462 struct hda_input_mux *spdif_mux = &spec->private_smux;
Takashi Iwaiea734962011-01-17 11:29:34 +01003463 const char * const *labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003464 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003465 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003466
3467 num_cons = snd_hda_get_connections(codec,
3468 spec->smux_nids[0],
3469 con_lst,
3470 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003471 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003472 return -EINVAL;
3473
Matthew Ranostay65973632008-09-16 10:39:37 -04003474 if (!labels)
3475 labels = stac92xx_spdif_labels;
3476
Takashi Iwai10a20af2010-09-09 16:28:02 +02003477 for (i = 0; i < num_cons; i++)
3478 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003479
3480 return 0;
3481}
3482
Matt Porter8b657272006-10-26 17:12:59 +02003483/* labels for dmic mux inputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003484static const char * const stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003485 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3486 "Digital Mic 3", "Digital Mic 4"
3487};
3488
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003489static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3490 int idx)
3491{
3492 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3493 int nums;
3494 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3495 if (idx >= 0 && idx < nums)
3496 return conn[idx];
3497 return 0;
3498}
3499
Takashi Iwai8d087c72011-06-28 12:45:47 +02003500/* look for NID recursively */
3501#define get_connection_index(codec, mux, nid) \
3502 snd_hda_get_conn_index(codec, mux, nid, 1)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003503
Takashi Iwai667067d2009-08-13 18:14:42 +02003504/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003505/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003506static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003507 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003508{
3509 unsigned int caps, nums;
3510 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003511 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003512
Takashi Iwai96f845d2009-08-29 00:49:36 +02003513 if (direction == HDA_OUTPUT)
3514 caps = AC_WCAP_OUT_AMP;
3515 else
3516 caps = AC_WCAP_IN_AMP;
3517 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003518 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003519 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003520 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3521 if (!nums)
3522 return 0;
3523 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003524 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3525 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003526 if (err < 0)
3527 return err;
3528 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003529}
3530
Matt Porter8b657272006-10-26 17:12:59 +02003531/* create playback/capture controls for input pins on dmic capable codecs */
3532static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3533 const struct auto_pin_cfg *cfg)
3534{
3535 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003536 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003537 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003538 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003539 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003540
Takashi Iwai10a20af2010-09-09 16:28:02 +02003541 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003542
Matt Porter8b657272006-10-26 17:12:59 +02003543 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003544 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003545 int index, type_idx;
Takashi Iwai5207e102009-07-30 13:09:08 +02003546 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003547
Takashi Iwai667067d2009-08-13 18:14:42 +02003548 nid = spec->dmic_nids[i];
3549 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3550 continue;
3551 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003552 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3553 continue;
3554
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003555 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3556 if (index < 0)
3557 continue;
3558
Takashi Iwai10a20af2010-09-09 16:28:02 +02003559 label = hda_get_input_pin_label(codec, nid, 1);
3560 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai2d7ec122010-12-23 10:16:05 +01003561 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3562 snd_hda_add_imux_item(imux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003563
Takashi Iwai10a20af2010-09-09 16:28:02 +02003564 err = create_elem_capture_vol(codec, nid, label, type_idx,
3565 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003566 if (err < 0)
3567 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003568 if (!err) {
3569 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003570 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003571 if (err < 0)
3572 return err;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003573 if (!err) {
3574 nid = get_connected_node(codec,
3575 spec->dmux_nids[0], index);
3576 if (nid)
3577 err = create_elem_capture_vol(codec,
3578 nid, label,
3579 type_idx, HDA_INPUT);
3580 if (err < 0)
3581 return err;
3582 }
Takashi Iwai96f845d2009-08-29 00:49:36 +02003583 }
Matt Porter8b657272006-10-26 17:12:59 +02003584 }
3585
3586 return 0;
3587}
3588
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003589static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003590 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003591{
3592 unsigned int cfg;
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003593 unsigned int type;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003594
3595 if (!nid)
3596 return 0;
3597 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003598 type = get_defcfg_device(cfg);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003599 switch (snd_hda_get_input_pin_attr(cfg)) {
3600 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003601 if (*fixed)
3602 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003603 if (type != AC_JACK_MIC_IN)
3604 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003605 *fixed = nid;
3606 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003607 case INPUT_PIN_ATTR_UNUSED:
3608 break;
3609 case INPUT_PIN_ATTR_DOCK:
3610 if (*dock)
3611 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003612 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
3613 return 1; /* invalid type */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003614 *dock = nid;
3615 break;
3616 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003617 if (*ext)
3618 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003619 if (type != AC_JACK_MIC_IN)
3620 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003621 *ext = nid;
3622 break;
3623 }
3624 return 0;
3625}
3626
3627static int set_mic_route(struct hda_codec *codec,
3628 struct sigmatel_mic_route *mic,
3629 hda_nid_t pin)
3630{
3631 struct sigmatel_spec *spec = codec->spec;
3632 struct auto_pin_cfg *cfg = &spec->autocfg;
3633 int i;
3634
3635 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003636 if (pin == 0)
3637 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003638 for (i = 0; i < cfg->num_inputs; i++) {
3639 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003640 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003641 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003642 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003643 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003644 i = get_connection_index(codec, spec->mux_nids[0], pin);
3645 if (i < 0)
3646 return -1;
3647 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003648 mic->dmux_idx = -1;
3649 if (spec->dmux_nids)
3650 mic->dmux_idx = get_connection_index(codec,
3651 spec->dmux_nids[0],
3652 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003653 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003654 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003655 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3656 if (i < 0)
3657 return -1;
3658 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003659 mic->mux_idx = -1;
3660 if (spec->mux_nids)
3661 mic->mux_idx = get_connection_index(codec,
3662 spec->mux_nids[0],
3663 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003664 }
3665 return 0;
3666}
3667
3668/* return non-zero if the device is for automatic mic switch */
3669static int stac_check_auto_mic(struct hda_codec *codec)
3670{
3671 struct sigmatel_spec *spec = codec->spec;
3672 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02003673 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003674 int i;
3675
Charles Chin99077902010-09-17 10:22:32 +02003676 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003677 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02003678 if (check_mic_pin(codec, cfg->inputs[i].pin,
3679 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003680 return 0;
3681 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02003682 if (check_mic_pin(codec, spec->dmic_nids[i],
3683 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003684 return 0;
Takashi Iwai80c67852011-01-13 08:08:08 +01003685 if (!fixed || (!ext && !dock))
Charles Chin99077902010-09-17 10:22:32 +02003686 return 0; /* no input to switch */
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003687 if (!is_jack_detectable(codec, ext))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003688 return 0; /* no unsol support */
3689 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02003690 set_mic_route(codec, &spec->int_mic, fixed) ||
3691 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003692 return 0; /* something is wrong */
3693 return 1;
3694}
3695
Mattc7d4b2f2005-06-27 14:59:41 +02003696/* create playback/capture controls for input pins */
3697static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3698{
3699 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003700 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003701 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003702 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02003703
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003704 for (i = 0; i < cfg->num_inputs; i++) {
3705 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003706 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02003707
Takashi Iwai314634b2006-09-21 11:56:18 +02003708 index = -1;
3709 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003710 index = get_connection_index(codec, spec->mux_nids[j],
3711 nid);
3712 if (index >= 0)
3713 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003714 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003715 if (index < 0)
3716 continue;
3717
Takashi Iwai10a20af2010-09-09 16:28:02 +02003718 label = hda_get_autocfg_input_label(codec, cfg, i);
3719 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003720
Takashi Iwai667067d2009-08-13 18:14:42 +02003721 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003722 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003723 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003724 if (err < 0)
3725 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003726 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003727 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003728
Steve Longerbeam7b043892007-05-03 20:50:03 +02003729 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003730 /*
3731 * Set the current input for the muxes.
3732 * The STAC9221 has two input muxes with identical source
3733 * NID lists. Hopefully this won't get confused.
3734 */
3735 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003736 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3737 AC_VERB_SET_CONNECT_SEL,
3738 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003739 }
3740 }
3741
Mattc7d4b2f2005-06-27 14:59:41 +02003742 return 0;
3743}
3744
Mattc7d4b2f2005-06-27 14:59:41 +02003745static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3746{
3747 struct sigmatel_spec *spec = codec->spec;
3748 int i;
3749
3750 for (i = 0; i < spec->autocfg.line_outs; i++) {
3751 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3752 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3753 }
3754}
3755
3756static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3757{
3758 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003759 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003760
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003761 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3762 hda_nid_t pin;
3763 pin = spec->autocfg.hp_pins[i];
3764 if (pin) /* connect to front */
3765 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3766 }
3767 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3768 hda_nid_t pin;
3769 pin = spec->autocfg.speaker_pins[i];
3770 if (pin) /* connect to front */
3771 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3772 }
Mattc7d4b2f2005-06-27 14:59:41 +02003773}
3774
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003775static int is_dual_headphones(struct hda_codec *codec)
3776{
3777 struct sigmatel_spec *spec = codec->spec;
3778 int i, valid_hps;
3779
3780 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3781 spec->autocfg.hp_outs <= 1)
3782 return 0;
3783 valid_hps = 0;
3784 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3785 hda_nid_t nid = spec->autocfg.hp_pins[i];
3786 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3787 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3788 continue;
3789 valid_hps++;
3790 }
3791 return (valid_hps > 1);
3792}
3793
3794
Charles Chin9009b0e2011-11-03 10:27:27 +01003795static int stac92xx_parse_auto_config(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003796{
3797 struct sigmatel_spec *spec = codec->spec;
Charles Chin9009b0e2011-11-03 10:27:27 +01003798 hda_nid_t dig_out = 0, dig_in = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003799 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003800 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003801
Matt Porter8b657272006-10-26 17:12:59 +02003802 if ((err = snd_hda_parse_pin_def_config(codec,
3803 &spec->autocfg,
3804 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003805 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003806 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003807 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003808
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003809 /* If we have no real line-out pin and multiple hp-outs, HPs should
3810 * be set up as multi-channel outputs.
3811 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003812 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003813 /* Copy hp_outs to line_outs, backup line_outs in
3814 * speaker_outs so that the following routines can handle
3815 * HP pins as primary outputs.
3816 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003817 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003818 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3819 sizeof(spec->autocfg.line_out_pins));
3820 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3821 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3822 sizeof(spec->autocfg.hp_pins));
3823 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003824 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3825 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003826 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003827 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003828 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003829 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3830 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003831 u32 caps = query_amp_caps(codec,
3832 spec->autocfg.mono_out_pin, dir);
3833 hda_nid_t conn_list[1];
3834
3835 /* get the mixer node and then the mono mux if it exists */
3836 if (snd_hda_get_connections(codec,
3837 spec->autocfg.mono_out_pin, conn_list, 1) &&
3838 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003839 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003840
3841 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003842 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003843 /* LR swap check, some stac925x have a mux that
3844 * changes the DACs output path instead of the
3845 * mono-mux path.
3846 */
3847 if (wid_type == AC_WID_AUD_SEL &&
3848 !(wcaps & AC_WCAP_LR_SWAP))
3849 spec->mono_nid = conn_list[0];
3850 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003851 if (dir) {
3852 hda_nid_t nid = spec->autocfg.mono_out_pin;
3853
3854 /* most mono outs have a least a mute/unmute switch */
3855 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3856 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3857 "Mono Playback Switch",
3858 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003859 if (err < 0)
3860 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003861 /* check for volume support for the amp */
3862 if ((caps & AC_AMPCAP_NUM_STEPS)
3863 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3864 err = stac92xx_add_control(spec,
3865 STAC_CTL_WIDGET_VOL,
3866 "Mono Playback Volume",
3867 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3868 if (err < 0)
3869 return err;
3870 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003871 }
3872
3873 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3874 AC_PINCTL_OUT_EN);
3875 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003876
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003877 if (!spec->multiout.num_dacs) {
3878 err = stac92xx_auto_fill_dac_nids(codec);
3879 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003880 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003881 err = stac92xx_auto_create_multi_out_ctls(codec,
3882 &spec->autocfg);
3883 if (err < 0)
3884 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003885 }
Mattc7d4b2f2005-06-27 14:59:41 +02003886
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003887 /* setup analog beep controls */
3888 if (spec->anabeep_nid > 0) {
3889 err = stac92xx_auto_create_beep_ctls(codec,
3890 spec->anabeep_nid);
3891 if (err < 0)
3892 return err;
3893 }
3894
3895 /* setup digital beep controls and input device */
3896#ifdef CONFIG_SND_HDA_INPUT_BEEP
3897 if (spec->digbeep_nid > 0) {
3898 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003899 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003900
3901 err = stac92xx_auto_create_beep_ctls(codec, nid);
3902 if (err < 0)
3903 return err;
3904 err = snd_hda_attach_beep_device(codec, nid);
3905 if (err < 0)
3906 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003907 if (codec->beep) {
3908 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01003909 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003910 /* if no beep switch is available, make its own one */
3911 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3912 if (!(caps & AC_AMPCAP_MUTE)) {
3913 err = stac92xx_beep_switch_ctl(codec);
3914 if (err < 0)
3915 return err;
3916 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003917 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003918 }
3919#endif
3920
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003921 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003922 if (err < 0)
3923 return err;
3924
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003925 /* All output parsing done, now restore the swapped hp pins */
3926 if (hp_swap) {
3927 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3928 sizeof(spec->autocfg.hp_pins));
3929 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3930 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3931 spec->autocfg.line_outs = 0;
3932 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003933
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003934 if (stac_check_auto_mic(codec)) {
3935 spec->auto_mic = 1;
3936 /* only one capture for auto-mic */
3937 spec->num_adcs = 1;
3938 spec->num_caps = 1;
3939 spec->num_muxes = 1;
3940 }
3941
Takashi Iwai6479c632009-07-28 18:20:25 +02003942 for (i = 0; i < spec->num_caps; i++) {
3943 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3944 spec->capsws[i], i);
3945 if (err < 0)
3946 return err;
3947 }
3948
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003949 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003950 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003951 return err;
3952
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003953 if (spec->mono_nid > 0) {
3954 err = stac92xx_auto_create_mono_output_ctls(codec);
3955 if (err < 0)
3956 return err;
3957 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003958 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003959 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3960 &spec->autocfg)) < 0)
3961 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003962 if (spec->num_muxes > 0) {
3963 err = stac92xx_auto_create_mux_input_ctls(codec);
3964 if (err < 0)
3965 return err;
3966 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003967 if (spec->num_smuxes > 0) {
3968 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3969 if (err < 0)
3970 return err;
3971 }
Matt Porter8b657272006-10-26 17:12:59 +02003972
Takashi Iwaie3c75962009-01-23 11:57:22 +01003973 err = stac92xx_add_input_source(spec);
3974 if (err < 0)
3975 return err;
3976
Mattc7d4b2f2005-06-27 14:59:41 +02003977 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003978 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003979 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003980
Charles Chin9009b0e2011-11-03 10:27:27 +01003981 /* find digital out and in converters */
3982 for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
3983 unsigned int wid_caps = get_wcaps(codec, i);
3984 if (wid_caps & AC_WCAP_DIGITAL) {
3985 switch (get_wcaps_type(wid_caps)) {
3986 case AC_WID_AUD_OUT:
3987 if (!dig_out)
3988 dig_out = i;
3989 break;
3990 case AC_WID_AUD_IN:
3991 if (!dig_in)
3992 dig_in = i;
3993 break;
3994 }
3995 }
3996 }
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003997 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003998 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003999 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004000 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02004001
Takashi Iwai603c4012008-07-30 15:01:44 +02004002 if (spec->kctls.list)
4003 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004004
4005 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05004006 if (!spec->dinput_mux)
4007 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004008 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01004009 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02004010 return 1;
4011}
4012
Takashi Iwai82bc9552006-03-21 11:24:42 +01004013/* add playback controls for HP output */
4014static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4015 struct auto_pin_cfg *cfg)
4016{
4017 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004018 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01004019
4020 if (! pin)
4021 return 0;
4022
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004023 if (is_jack_detectable(codec, pin))
Takashi Iwai82bc9552006-03-21 11:24:42 +01004024 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004025
4026 return 0;
4027}
4028
Richard Fish160ea0d2006-09-06 13:58:25 +02004029/* add playback controls for LFE output */
4030static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4031 struct auto_pin_cfg *cfg)
4032{
4033 struct sigmatel_spec *spec = codec->spec;
4034 int err;
4035 hda_nid_t lfe_pin = 0x0;
4036 int i;
4037
4038 /*
4039 * search speaker outs and line outs for a mono speaker pin
4040 * with an amp. If one is found, add LFE controls
4041 * for it.
4042 */
4043 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4044 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004045 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004046 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4047 if (wcaps == AC_WCAP_OUT_AMP)
4048 /* found a mono speaker with an amp, must be lfe */
4049 lfe_pin = pin;
4050 }
4051
4052 /* if speaker_outs is 0, then speakers may be in line_outs */
4053 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4054 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4055 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004056 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004057 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004058 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004059 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004060 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4061 if (wcaps == AC_WCAP_OUT_AMP)
4062 /* found a mono speaker with an amp,
4063 must be lfe */
4064 lfe_pin = pin;
4065 }
4066 }
4067 }
4068
4069 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004070 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004071 if (err < 0)
4072 return err;
4073 }
4074
4075 return 0;
4076}
4077
Mattc7d4b2f2005-06-27 14:59:41 +02004078static int stac9200_parse_auto_config(struct hda_codec *codec)
4079{
4080 struct sigmatel_spec *spec = codec->spec;
4081 int err;
4082
Kailang Yangdf694da2005-12-05 19:42:22 +01004083 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004084 return err;
4085
4086 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4087 return err;
4088
Takashi Iwai82bc9552006-03-21 11:24:42 +01004089 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4090 return err;
4091
Richard Fish160ea0d2006-09-06 13:58:25 +02004092 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4093 return err;
4094
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004095 if (spec->num_muxes > 0) {
4096 err = stac92xx_auto_create_mux_input_ctls(codec);
4097 if (err < 0)
4098 return err;
4099 }
4100
Takashi Iwaie3c75962009-01-23 11:57:22 +01004101 err = stac92xx_add_input_source(spec);
4102 if (err < 0)
4103 return err;
4104
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004105 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004106 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004107 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004108 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004109
Takashi Iwai603c4012008-07-30 15:01:44 +02004110 if (spec->kctls.list)
4111 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004112
4113 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004114 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004115
4116 return 1;
4117}
4118
Sam Revitch62fe78e2006-05-10 15:09:17 +02004119/*
4120 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4121 * funky external mute control using GPIO pins.
4122 */
4123
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004124static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004125 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004126{
4127 unsigned int gpiostate, gpiomask, gpiodir;
4128
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004129 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4130
Sam Revitch62fe78e2006-05-10 15:09:17 +02004131 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4132 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004133 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004134
4135 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4136 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004137 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004138
4139 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4140 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004141 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004142
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004143 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004144 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4145
4146 snd_hda_codec_write(codec, codec->afg, 0,
4147 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004148 snd_hda_codec_read(codec, codec->afg, 0,
4149 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004150
4151 msleep(1);
4152
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004153 snd_hda_codec_read(codec, codec->afg, 0,
4154 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004155}
4156
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004157static int stac92xx_add_jack(struct hda_codec *codec,
4158 hda_nid_t nid, int type)
4159{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004160#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai330ee992009-02-20 14:33:36 +01004161 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004162 int connectivity = get_defcfg_connect(def_conf);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004163
4164 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4165 return 0;
4166
David Henningssoneb335a42011-10-03 16:25:42 +02004167 return snd_hda_input_jack_add(codec, nid, type, NULL);
4168#else
Takashi Iwai95c09092009-04-14 16:15:29 +02004169 return 0;
David Henningssoneb335a42011-10-03 16:25:42 +02004170#endif /* CONFIG_SND_HDA_INPUT_JACK */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004171}
4172
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004173static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4174 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004175{
4176 struct sigmatel_event *event;
4177
4178 snd_array_init(&spec->events, sizeof(*event), 32);
4179 event = snd_array_new(&spec->events);
4180 if (!event)
4181 return -ENOMEM;
4182 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004183 event->type = type;
4184 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004185 event->data = data;
4186
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004187 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004188}
4189
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004190static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004191 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004192{
4193 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004194 struct sigmatel_event *event = spec->events.list;
4195 int i;
4196
4197 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004198 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004199 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004200 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004201 return NULL;
4202}
4203
4204static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4205 unsigned char tag)
4206{
4207 struct sigmatel_spec *spec = codec->spec;
4208 struct sigmatel_event *event = spec->events.list;
4209 int i;
4210
4211 for (i = 0; i < spec->events.used; i++, event++) {
4212 if (event->tag == tag)
4213 return event;
4214 }
4215 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004216}
4217
Takashi Iwai62558ce2009-07-29 14:23:09 +02004218/* check if given nid is a valid pin and no other events are assigned
4219 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4220 * Otherwise, returns zero.
4221 */
4222static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4223 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004224{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004225 struct sigmatel_event *event;
4226 int tag;
4227
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004228 if (!is_jack_detectable(codec, nid))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004229 return 0;
4230 event = stac_get_event(codec, nid);
4231 if (event) {
4232 if (event->type != type)
4233 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004234 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004235 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004236 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004237 if (tag < 0)
4238 return 0;
4239 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004240 snd_hda_codec_write_cache(codec, nid, 0,
4241 AC_VERB_SET_UNSOLICITED_ENABLE,
4242 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004243 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004244}
4245
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004246static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4247{
4248 int i;
4249 for (i = 0; i < cfg->hp_outs; i++)
4250 if (cfg->hp_pins[i] == nid)
4251 return 1; /* nid is a HP-Out */
4252
4253 return 0; /* nid is not a HP-Out */
4254};
4255
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004256static void stac92xx_power_down(struct hda_codec *codec)
4257{
4258 struct sigmatel_spec *spec = codec->spec;
4259
4260 /* power down inactive DACs */
Takashi Iwai2b635362011-05-02 12:33:43 +02004261 const hda_nid_t *dac;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004262 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004263 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004264 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004265 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4266}
4267
Takashi Iwaif73d3582008-11-25 08:21:51 +01004268static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4269 int enable);
4270
Takashi Iwai014c41f2009-12-27 13:53:24 +01004271static inline int get_int_hint(struct hda_codec *codec, const char *key,
4272 int *valp)
4273{
4274 const char *p;
4275 p = snd_hda_get_hint(codec, key);
4276 if (p) {
4277 unsigned long val;
4278 if (!strict_strtoul(p, 0, &val)) {
4279 *valp = val;
4280 return 1;
4281 }
4282 }
4283 return 0;
4284}
4285
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004286/* override some hints from the hwdep entry */
4287static void stac_store_hints(struct hda_codec *codec)
4288{
4289 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004290 int val;
4291
4292 val = snd_hda_get_bool_hint(codec, "hp_detect");
4293 if (val >= 0)
4294 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004295 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004296 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4297 spec->gpio_mask;
4298 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004299 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4300 spec->gpio_mask &= spec->gpio_mask;
4301 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4302 spec->gpio_dir &= spec->gpio_mask;
4303 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4304 spec->eapd_mask &= spec->gpio_mask;
4305 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4306 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004307 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4308 if (val >= 0)
4309 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004310 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4311 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004312 if (spec->gpio_led <= 8) {
4313 spec->gpio_mask |= spec->gpio_led;
4314 spec->gpio_dir |= spec->gpio_led;
4315 if (spec->gpio_led_polarity)
4316 spec->gpio_data |= spec->gpio_led;
4317 }
Takashi Iwai043958e2009-12-26 10:36:12 +01004318 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004319}
4320
Mattc7d4b2f2005-06-27 14:59:41 +02004321static int stac92xx_init(struct hda_codec *codec)
4322{
4323 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004324 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004325 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004326 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004327
Mattc7d4b2f2005-06-27 14:59:41 +02004328 snd_hda_sequence_write(codec, spec->init);
4329
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004330 /* power down adcs initially */
4331 if (spec->powerdown_adcs)
4332 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004333 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004334 spec->adc_nids[i], 0,
4335 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004336
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004337 /* override some hints */
4338 stac_store_hints(codec);
4339
Takashi Iwaif73d3582008-11-25 08:21:51 +01004340 /* set up GPIO */
4341 gpio = spec->gpio_data;
4342 /* turn on EAPD statically when spec->eapd_switch isn't set.
4343 * otherwise, unsol event will turn it on/off dynamically
4344 */
4345 if (!spec->eapd_switch)
4346 gpio |= spec->eapd_mask;
4347 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4348
Takashi Iwai82bc9552006-03-21 11:24:42 +01004349 /* set up pins */
4350 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004351 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004352 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004353 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004354 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004355 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004356 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4357 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004358 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004359 for (i = 0; i < cfg->line_outs; i++) {
4360 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004361 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4362 }
4363 }
4364
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004365 /* force to enable the first line-out; the others are set up
4366 * in unsol_event
4367 */
4368 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004369 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004370 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004371 if (cfg->hp_pins[0])
4372 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4373 else if (cfg->line_out_pins[0])
4374 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004375 } else {
4376 stac92xx_auto_init_multi_out(codec);
4377 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004378 for (i = 0; i < cfg->hp_outs; i++)
4379 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004380 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004381 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004382 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004383 if (spec->dmux_nids)
4384 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004385 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004386 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4387 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004388 if (enable_pin_detect(codec, spec->dock_mic.pin,
4389 STAC_MIC_EVENT))
4390 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004391 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004392 for (i = 0; i < cfg->num_inputs; i++) {
4393 hda_nid_t nid = cfg->inputs[i].pin;
4394 int type = cfg->inputs[i].type;
4395 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004396 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004397 /* for mic pins, force to initialize */
4398 pinctl = stac92xx_get_default_vref(codec, nid);
4399 pinctl |= AC_PINCTL_IN_EN;
4400 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4401 } else {
4402 pinctl = snd_hda_codec_read(codec, nid, 0,
4403 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4404 /* if PINCTL already set then skip */
4405 /* Also, if both INPUT and OUTPUT are set,
4406 * it must be a BIOS bug; need to override, too
4407 */
4408 if (!(pinctl & AC_PINCTL_IN_EN) ||
4409 (pinctl & AC_PINCTL_OUT_EN)) {
4410 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004411 pinctl |= AC_PINCTL_IN_EN;
4412 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004413 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004414 }
4415 conf = snd_hda_codec_get_pincfg(codec, nid);
4416 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4417 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4418 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004419 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004420 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004421 for (i = 0; i < spec->num_dmics; i++)
4422 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4423 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004424 if (cfg->dig_out_pins[0])
4425 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004426 AC_PINCTL_OUT_EN);
4427 if (cfg->dig_in_pin)
4428 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4429 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004430 for (i = 0; i < spec->num_pwrs; i++) {
4431 hda_nid_t nid = spec->pwr_nids[i];
4432 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004433
Takashi Iwaieb632122008-12-19 16:39:48 +01004434 /* power on when no jack detection is available */
4435 if (!spec->hp_detect) {
4436 stac_toggle_power_map(codec, nid, 1);
4437 continue;
4438 }
4439
4440 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004441 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004442
Takashi Iwaif73d3582008-11-25 08:21:51 +01004443 pinctl = snd_hda_codec_read(codec, nid, 0,
4444 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4445 /* outputs are only ports capable of power management
4446 * any attempts on powering down a input port cause the
4447 * referenced VREF to act quirky.
4448 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004449 if (pinctl & AC_PINCTL_IN_EN) {
4450 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004451 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004452 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004453 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004454 def_conf = get_defcfg_connect(def_conf);
4455 /* skip any ports that don't have jacks since presence
4456 * detection is useless */
4457 if (def_conf != AC_JACK_PORT_COMPLEX) {
4458 if (def_conf != AC_JACK_PORT_NONE)
4459 stac_toggle_power_map(codec, nid, 1);
4460 continue;
4461 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004462 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4463 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004464 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004465
Takashi Iwaic21bd022010-02-08 15:16:08 +01004466 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004467 if (spec->gpio_led)
4468 hda_call_check_power_status(codec, 0x01);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004469 if (spec->dac_list)
4470 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004471 return 0;
4472}
4473
Takashi Iwai603c4012008-07-30 15:01:44 +02004474static void stac92xx_free_kctls(struct hda_codec *codec)
4475{
4476 struct sigmatel_spec *spec = codec->spec;
4477
4478 if (spec->kctls.list) {
4479 struct snd_kcontrol_new *kctl = spec->kctls.list;
4480 int i;
4481 for (i = 0; i < spec->kctls.used; i++)
4482 kfree(kctl[i].name);
4483 }
4484 snd_array_free(&spec->kctls);
4485}
4486
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004487static void stac92xx_shutup_pins(struct hda_codec *codec)
4488{
4489 unsigned int i, def_conf;
4490
4491 if (codec->bus->shutdown)
4492 return;
4493 for (i = 0; i < codec->init_pins.used; i++) {
4494 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4495 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4496 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
4497 snd_hda_codec_write(codec, pin->nid, 0,
4498 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4499 }
4500}
4501
Takashi Iwai167eae52009-11-06 15:47:50 +01004502static void stac92xx_shutup(struct hda_codec *codec)
4503{
4504 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004505
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004506 stac92xx_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004507
4508 if (spec->eapd_mask)
4509 stac_gpio_set(codec, spec->gpio_mask,
4510 spec->gpio_dir, spec->gpio_data &
4511 ~spec->eapd_mask);
4512}
4513
Matt2f2f4252005-04-13 14:45:30 +02004514static void stac92xx_free(struct hda_codec *codec)
4515{
Mattc7d4b2f2005-06-27 14:59:41 +02004516 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004517
4518 if (! spec)
4519 return;
4520
Takashi Iwai167eae52009-11-06 15:47:50 +01004521 stac92xx_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004522 snd_hda_input_jack_free(codec);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004523 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004524
Mattc7d4b2f2005-06-27 14:59:41 +02004525 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004526 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004527}
4528
Matt4e550962005-07-04 17:51:39 +02004529static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4530 unsigned int flag)
4531{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004532 unsigned int old_ctl, pin_ctl;
4533
4534 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004535 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004536
Takashi Iwaif9acba42007-05-29 18:01:06 +02004537 if (pin_ctl & AC_PINCTL_IN_EN) {
4538 /*
4539 * we need to check the current set-up direction of
4540 * shared input pins since they can be switched via
4541 * "xxx as Output" mixer switch
4542 */
4543 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004544 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004545 return;
4546 }
4547
Takashi Iwai8ce84192009-01-22 16:59:20 +01004548 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004549 /* if setting pin direction bits, clear the current
4550 direction bits first */
4551 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4552 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4553
Takashi Iwai8ce84192009-01-22 16:59:20 +01004554 pin_ctl |= flag;
4555 if (old_ctl != pin_ctl)
4556 snd_hda_codec_write_cache(codec, nid, 0,
4557 AC_VERB_SET_PIN_WIDGET_CONTROL,
4558 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004559}
4560
4561static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4562 unsigned int flag)
4563{
4564 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4565 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004566 if (pin_ctl & flag)
4567 snd_hda_codec_write_cache(codec, nid, 0,
4568 AC_VERB_SET_PIN_WIDGET_CONTROL,
4569 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004570}
4571
Takashi Iwaid56757a2009-11-18 08:00:14 +01004572static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004573{
4574 if (!nid)
4575 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004576 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004577}
4578
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004579static void stac92xx_line_out_detect(struct hda_codec *codec,
4580 int presence)
4581{
4582 struct sigmatel_spec *spec = codec->spec;
4583 struct auto_pin_cfg *cfg = &spec->autocfg;
4584 int i;
4585
4586 for (i = 0; i < cfg->line_outs; i++) {
4587 if (presence)
4588 break;
4589 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4590 if (presence) {
4591 unsigned int pinctl;
4592 pinctl = snd_hda_codec_read(codec,
4593 cfg->line_out_pins[i], 0,
4594 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4595 if (pinctl & AC_PINCTL_IN_EN)
4596 presence = 0; /* mic- or line-input */
4597 }
4598 }
4599
4600 if (presence) {
4601 /* disable speakers */
4602 for (i = 0; i < cfg->speaker_outs; i++)
4603 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4604 AC_PINCTL_OUT_EN);
4605 if (spec->eapd_mask && spec->eapd_switch)
4606 stac_gpio_set(codec, spec->gpio_mask,
4607 spec->gpio_dir, spec->gpio_data &
4608 ~spec->eapd_mask);
4609 } else {
4610 /* enable speakers */
4611 for (i = 0; i < cfg->speaker_outs; i++)
4612 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4613 AC_PINCTL_OUT_EN);
4614 if (spec->eapd_mask && spec->eapd_switch)
4615 stac_gpio_set(codec, spec->gpio_mask,
4616 spec->gpio_dir, spec->gpio_data |
4617 spec->eapd_mask);
4618 }
4619}
4620
Takashi Iwaid7a89432008-11-12 09:48:04 +01004621/* return non-zero if the hp-pin of the given array index isn't
4622 * a jack-detection target
4623 */
4624static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4625{
4626 struct auto_pin_cfg *cfg = &spec->autocfg;
4627
4628 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004629 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004630 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004631 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004632 return 1;
4633 /* ignore if the pin is set as line-out */
4634 if (cfg->hp_pins[i] == spec->hp_switch)
4635 return 1;
4636 return 0;
4637}
4638
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004639static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004640{
4641 struct sigmatel_spec *spec = codec->spec;
4642 struct auto_pin_cfg *cfg = &spec->autocfg;
4643 int i, presence;
4644
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004645 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004646 if (spec->gpio_mute)
4647 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4648 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4649
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004650 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004651 if (presence)
4652 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004653 if (no_hp_sensing(spec, i))
4654 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004655 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4656 if (presence) {
4657 unsigned int pinctl;
4658 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4659 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4660 if (pinctl & AC_PINCTL_IN_EN)
4661 presence = 0; /* mic- or line-input */
4662 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004663 }
Matt4e550962005-07-04 17:51:39 +02004664
4665 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004666 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004667 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004668 stac92xx_reset_pinctl(codec, spec->hp_switch,
4669 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004670 for (i = 0; i < cfg->line_outs; i++)
4671 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4672 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004673 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004674 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004675 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004676 stac92xx_set_pinctl(codec, spec->hp_switch,
4677 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004678 for (i = 0; i < cfg->line_outs; i++)
4679 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4680 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004681 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004682 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004683 /* toggle hp outs */
4684 for (i = 0; i < cfg->hp_outs; i++) {
4685 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4686 if (no_hp_sensing(spec, i))
4687 continue;
4688 if (presence)
4689 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004690#if 0 /* FIXME */
4691/* Resetting the pinctl like below may lead to (a sort of) regressions
4692 * on some devices since they use the HP pin actually for line/speaker
4693 * outs although the default pin config shows a different pin (that is
4694 * wrong and useless).
4695 *
4696 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4697 * But, disabling the code below just works around it, and I'm too tired of
4698 * bug reports with such devices...
4699 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004700 else
4701 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004702#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004703 }
Matt4e550962005-07-04 17:51:39 +02004704}
4705
Takashi Iwaif73d3582008-11-25 08:21:51 +01004706static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4707 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004708{
4709 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004710 unsigned int idx, val;
4711
4712 for (idx = 0; idx < spec->num_pwrs; idx++) {
4713 if (spec->pwr_nids[idx] == nid)
4714 break;
4715 }
4716 if (idx >= spec->num_pwrs)
4717 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004718
4719 /* several codecs have two power down bits */
4720 if (spec->pwr_mapping)
4721 idx = spec->pwr_mapping[idx];
4722 else
4723 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004724
Takashi Iwaif73d3582008-11-25 08:21:51 +01004725 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4726 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004727 val &= ~idx;
4728 else
4729 val |= idx;
4730
4731 /* power down unused output ports */
4732 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004733}
4734
Takashi Iwaif73d3582008-11-25 08:21:51 +01004735static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4736{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004737 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004738}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004739
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004740/* get the pin connection (fixed, none, etc) */
4741static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4742{
4743 struct sigmatel_spec *spec = codec->spec;
4744 unsigned int cfg;
4745
4746 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4747 return get_defcfg_connect(cfg);
4748}
4749
4750static int stac92xx_connected_ports(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02004751 const hda_nid_t *nids, int num_nids)
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004752{
4753 struct sigmatel_spec *spec = codec->spec;
4754 int idx, num;
4755 unsigned int def_conf;
4756
4757 for (num = 0; num < num_nids; num++) {
4758 for (idx = 0; idx < spec->num_pins; idx++)
4759 if (spec->pin_nids[idx] == nids[num])
4760 break;
4761 if (idx >= spec->num_pins)
4762 break;
4763 def_conf = stac_get_defcfg_connect(codec, idx);
4764 if (def_conf == AC_JACK_PORT_NONE)
4765 break;
4766 }
4767 return num;
4768}
4769
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004770static void stac92xx_mic_detect(struct hda_codec *codec)
4771{
4772 struct sigmatel_spec *spec = codec->spec;
4773 struct sigmatel_mic_route *mic;
4774
4775 if (get_pin_presence(codec, spec->ext_mic.pin))
4776 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02004777 else if (get_pin_presence(codec, spec->dock_mic.pin))
4778 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004779 else
4780 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004781 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004782 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4783 AC_VERB_SET_CONNECT_SEL,
4784 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004785 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004786 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4787 AC_VERB_SET_CONNECT_SEL,
4788 mic->mux_idx);
4789}
4790
Takashi Iwai62558ce2009-07-29 14:23:09 +02004791static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004792{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004793 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004794 if (!event)
4795 return;
4796 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4797}
4798
Takashi Iwai314634b2006-09-21 11:56:18 +02004799static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4800{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004801 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004802 struct sigmatel_event *event;
4803 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004804
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004805 tag = (res >> 26) & 0x7f;
4806 event = stac_get_event_from_tag(codec, tag);
4807 if (!event)
4808 return;
4809
4810 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004811 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004812 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004813 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004814 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004815 case STAC_MIC_EVENT:
4816 stac92xx_mic_detect(codec);
4817 break;
4818 }
4819
4820 switch (event->type) {
4821 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004822 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004823 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004824 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004825 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004826 if (spec->num_pwrs > 0)
4827 stac92xx_pin_sense(codec, event->nid);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004828 snd_hda_input_jack_report(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004829
4830 switch (codec->subsystem_id) {
4831 case 0x103c308f:
4832 if (event->nid == 0xb) {
4833 int pin = AC_PINCTL_IN_EN;
4834
4835 if (get_pin_presence(codec, 0xa)
4836 && get_pin_presence(codec, 0xb))
4837 pin |= AC_PINCTL_VREF_80;
4838 if (!get_pin_presence(codec, 0xb))
4839 pin |= AC_PINCTL_VREF_80;
4840
4841 /* toggle VREF state based on mic + hp pin
4842 * status
4843 */
4844 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4845 }
4846 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004847 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004848 case STAC_VREF_EVENT:
4849 data = snd_hda_codec_read(codec, codec->afg, 0,
4850 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004851 /* toggle VREF state based on GPIOx status */
4852 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004853 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004854 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004855 }
4856}
4857
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304858static int hp_blike_system(u32 subsystem_id);
4859
4860static void set_hp_led_gpio(struct hda_codec *codec)
4861{
4862 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004863 unsigned int gpio;
4864
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004865 if (spec->gpio_led)
4866 return;
4867
Takashi Iwai07f80442010-02-08 15:06:13 +01004868 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4869 gpio &= AC_GPIO_IO_COUNT;
4870 if (gpio > 3)
4871 spec->gpio_led = 0x08; /* GPIO 3 */
4872 else
4873 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304874}
4875
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004876/*
4877 * This method searches for the mute LED GPIO configuration
4878 * provided as OEM string in SMBIOS. The format of that string
4879 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4880 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4881 * that corresponds to the NOT muted state of the master volume
4882 * and G is the index of the GPIO to use as the mute LED control (0..9)
4883 * If _G portion is missing it is assigned based on the codec ID
4884 *
4885 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4886 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304887 *
4888 *
4889 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4890 * SMBIOS - at least the ones I have seen do not have them - which include
4891 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4892 * HP Pavilion dv9500t CTO.
4893 * Need more information on whether it is true across the entire series.
4894 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004895 */
Takashi Iwaidce17d42010-02-09 09:25:26 +01004896static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004897{
4898 struct sigmatel_spec *spec = codec->spec;
4899 const struct dmi_device *dev = NULL;
4900
4901 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4902 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4903 NULL, dev))) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004904 if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304905 &spec->gpio_led_polarity,
4906 &spec->gpio_led) == 2) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004907 if (spec->gpio_led < 4)
4908 spec->gpio_led = 1 << spec->gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004909 return 1;
4910 }
4911 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304912 &spec->gpio_led_polarity) == 1) {
4913 set_hp_led_gpio(codec);
4914 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004915 }
4916 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304917
4918 /*
4919 * Fallback case - if we don't find the DMI strings,
4920 * we statically set the GPIO - if not a B-series system.
4921 */
4922 if (!hp_blike_system(codec->subsystem_id)) {
4923 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004924 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304925 return 1;
4926 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004927 }
4928 return 0;
4929}
4930
4931static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004932{
4933 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004934 case 0x103c1520:
4935 case 0x103c1521:
4936 case 0x103c1523:
4937 case 0x103c1524:
4938 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004939 case 0x103c1722:
4940 case 0x103c1723:
4941 case 0x103c1724:
4942 case 0x103c1725:
4943 case 0x103c1726:
4944 case 0x103c1727:
4945 case 0x103c1728:
4946 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004947 case 0x103c172a:
4948 case 0x103c172b:
4949 case 0x103c307e:
4950 case 0x103c307f:
4951 case 0x103c3080:
4952 case 0x103c3081:
4953 case 0x103c7007:
4954 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004955 return 1;
4956 }
4957 return 0;
4958}
4959
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004960#ifdef CONFIG_PROC_FS
4961static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4962 struct hda_codec *codec, hda_nid_t nid)
4963{
4964 if (nid == codec->afg)
4965 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4966 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4967}
4968
4969static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4970 struct hda_codec *codec,
4971 unsigned int verb)
4972{
4973 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4974 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4975}
4976
4977/* stac92hd71bxx, stac92hd73xx */
4978static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4979 struct hda_codec *codec, hda_nid_t nid)
4980{
4981 stac92hd_proc_hook(buffer, codec, nid);
4982 if (nid == codec->afg)
4983 analog_loop_proc_hook(buffer, codec, 0xfa0);
4984}
4985
4986static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4987 struct hda_codec *codec, hda_nid_t nid)
4988{
4989 if (nid == codec->afg)
4990 analog_loop_proc_hook(buffer, codec, 0xfe0);
4991}
4992
4993static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4994 struct hda_codec *codec, hda_nid_t nid)
4995{
4996 if (nid == codec->afg)
4997 analog_loop_proc_hook(buffer, codec, 0xfeb);
4998}
4999#else
5000#define stac92hd_proc_hook NULL
5001#define stac92hd7x_proc_hook NULL
5002#define stac9205_proc_hook NULL
5003#define stac927x_proc_hook NULL
5004#endif
5005
Takashi Iwai2a439522011-07-26 09:52:50 +02005006#ifdef CONFIG_PM
Mattff6fdc32005-06-27 15:06:52 +02005007static int stac92xx_resume(struct hda_codec *codec)
5008{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02005009 struct sigmatel_spec *spec = codec->spec;
5010
Takashi Iwai2c885872008-11-18 09:36:55 +01005011 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02005012 snd_hda_codec_resume_amp(codec);
5013 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01005014 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02005015 if (spec->hp_detect) {
5016 if (spec->autocfg.hp_pins[0])
5017 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
5018 else if (spec->autocfg.line_out_pins[0])
5019 stac_issue_unsol_event(codec,
5020 spec->autocfg.line_out_pins[0]);
5021 }
Mattff6fdc32005-06-27 15:06:52 +02005022 return 0;
5023}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005024
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005025static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
5026{
5027 stac92xx_shutup(codec);
5028 return 0;
5029}
5030
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005031#ifdef CONFIG_SND_HDA_POWER_SAVE
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005032static int stac92xx_pre_resume(struct hda_codec *codec)
5033{
5034 struct sigmatel_spec *spec = codec->spec;
5035
5036 /* sync mute LED */
5037 if (spec->gpio_led) {
5038 if (spec->gpio_led <= 8) {
5039 stac_gpio_set(codec, spec->gpio_mask,
5040 spec->gpio_dir, spec->gpio_data);
5041 } else {
5042 stac_vrefout_set(codec,
5043 spec->gpio_led, spec->vref_led);
5044 }
5045 }
5046 return 0;
5047}
5048
5049static int stac92xx_post_suspend(struct hda_codec *codec)
5050{
5051 struct sigmatel_spec *spec = codec->spec;
5052 if (spec->gpio_led > 8) {
5053 /* with vref-out pin used for mute led control
5054 * codec AFG is prevented from D3 state, but on
5055 * system suspend it can (and should) be used
5056 */
5057 snd_hda_codec_read(codec, codec->afg, 0,
5058 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5059 }
5060 return 0;
5061}
5062
5063static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5064 unsigned int power_state)
5065{
5066 unsigned int afg_power_state = power_state;
5067 struct sigmatel_spec *spec = codec->spec;
5068
5069 if (power_state == AC_PWRST_D3) {
5070 if (spec->gpio_led > 8) {
5071 /* with vref-out pin used for mute led control
5072 * codec AFG is prevented from D3 state
5073 */
5074 afg_power_state = AC_PWRST_D1;
5075 }
5076 /* this delay seems necessary to avoid click noise at power-down */
5077 msleep(100);
5078 }
5079 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5080 afg_power_state);
5081 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
5082}
5083
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005084/*
5085 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed
5086 * as mute LED state is updated in check_power_status hook
5087 */
5088static int stac92xx_update_led_status(struct hda_codec *codec)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005089{
5090 struct sigmatel_spec *spec = codec->spec;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005091 int i, num_ext_dacs, muted = 1;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005092 unsigned int muted_lvl, notmtd_lvl;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005093 hda_nid_t nid;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005094
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005095 if (!spec->gpio_led)
5096 return 0;
5097
Takashi Iwaic21bd022010-02-08 15:16:08 +01005098 for (i = 0; i < spec->multiout.num_dacs; i++) {
5099 nid = spec->multiout.dac_nids[i];
5100 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5101 HDA_AMP_MUTE)) {
5102 muted = 0; /* something heard */
5103 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005104 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01005105 }
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005106 if (muted && spec->multiout.hp_nid)
5107 if (!(snd_hda_codec_amp_read(codec,
5108 spec->multiout.hp_nid, 0, HDA_OUTPUT, 0) &
5109 HDA_AMP_MUTE)) {
5110 muted = 0; /* HP is not muted */
5111 }
5112 num_ext_dacs = ARRAY_SIZE(spec->multiout.extra_out_nid);
5113 for (i = 0; muted && i < num_ext_dacs; i++) {
5114 nid = spec->multiout.extra_out_nid[i];
5115 if (nid == 0)
5116 break;
5117 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5118 HDA_AMP_MUTE)) {
5119 muted = 0; /* extra output is not muted */
5120 }
5121 }
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005122 /*polarity defines *not* muted state level*/
5123 if (spec->gpio_led <= 8) {
5124 if (muted)
5125 spec->gpio_data &= ~spec->gpio_led; /* orange */
5126 else
5127 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005128
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005129 if (!spec->gpio_led_polarity) {
5130 /* LED state is inverted on these systems */
5131 spec->gpio_data ^= spec->gpio_led;
5132 }
5133 stac_gpio_set(codec, spec->gpio_mask,
5134 spec->gpio_dir, spec->gpio_data);
5135 } else {
5136 notmtd_lvl = spec->gpio_led_polarity ?
5137 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_GRD;
5138 muted_lvl = spec->gpio_led_polarity ?
5139 AC_PINCTL_VREF_GRD : AC_PINCTL_VREF_HIZ;
5140 spec->vref_led = muted ? muted_lvl : notmtd_lvl;
5141 stac_vrefout_set(codec, spec->gpio_led, spec->vref_led);
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005142 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005143 return 0;
5144}
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005145
5146/*
5147 * use power check for controlling mute led of HP notebooks
5148 */
5149static int stac92xx_check_power_status(struct hda_codec *codec,
5150 hda_nid_t nid)
5151{
5152 stac92xx_update_led_status(codec);
5153
5154 return 0;
5155}
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005156#endif /* CONFIG_SND_HDA_POWER_SAVE */
Takashi Iwai2a439522011-07-26 09:52:50 +02005157#endif /* CONFIG_PM */
Mattff6fdc32005-06-27 15:06:52 +02005158
Takashi Iwai2b635362011-05-02 12:33:43 +02005159static const struct hda_codec_ops stac92xx_patch_ops = {
Matt2f2f4252005-04-13 14:45:30 +02005160 .build_controls = stac92xx_build_controls,
5161 .build_pcms = stac92xx_build_pcms,
5162 .init = stac92xx_init,
5163 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02005164 .unsol_event = stac92xx_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02005165#ifdef CONFIG_PM
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005166 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005167 .resume = stac92xx_resume,
5168#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005169 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005170};
5171
5172static int patch_stac9200(struct hda_codec *codec)
5173{
5174 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005175 int err;
Matt2f2f4252005-04-13 14:45:30 +02005176
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005177 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005178 if (spec == NULL)
5179 return -ENOMEM;
5180
Takashi Iwaia252c812009-12-25 22:56:20 +01005181 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005182 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005183 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005184 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005185 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005186 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5187 stac9200_models,
5188 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005189 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005190 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5191 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005192 else
5193 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005194 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005195
5196 spec->multiout.max_channels = 2;
5197 spec->multiout.num_dacs = 1;
5198 spec->multiout.dac_nids = stac9200_dac_nids;
5199 spec->adc_nids = stac9200_adc_nids;
5200 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005201 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005202 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005203 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005204 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005205
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005206 if (spec->board_config == STAC_9200_M4 ||
5207 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005208 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005209 spec->init = stac9200_eapd_init;
5210 else
5211 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005212 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005213
Takashi Iwai117f2572008-03-18 09:53:23 +01005214 if (spec->board_config == STAC_9200_PANASONIC) {
5215 spec->gpio_mask = spec->gpio_dir = 0x09;
5216 spec->gpio_data = 0x00;
5217 }
5218
Mattc7d4b2f2005-06-27 14:59:41 +02005219 err = stac9200_parse_auto_config(codec);
5220 if (err < 0) {
5221 stac92xx_free(codec);
5222 return err;
5223 }
Matt2f2f4252005-04-13 14:45:30 +02005224
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005225 /* CF-74 has no headphone detection, and the driver should *NOT*
5226 * do detection and HP/speaker toggle because the hardware does it.
5227 */
5228 if (spec->board_config == STAC_9200_PANASONIC)
5229 spec->hp_detect = 0;
5230
Matt2f2f4252005-04-13 14:45:30 +02005231 codec->patch_ops = stac92xx_patch_ops;
5232
5233 return 0;
5234}
5235
Tobin Davis8e21c342007-01-08 11:04:17 +01005236static int patch_stac925x(struct hda_codec *codec)
5237{
5238 struct sigmatel_spec *spec;
5239 int err;
5240
5241 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5242 if (spec == NULL)
5243 return -ENOMEM;
5244
Takashi Iwaia252c812009-12-25 22:56:20 +01005245 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005246 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005247 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005248 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005249 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005250
5251 /* Check first for codec ID */
5252 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5253 STAC_925x_MODELS,
5254 stac925x_models,
5255 stac925x_codec_id_cfg_tbl);
5256
5257 /* Now checks for PCI ID, if codec ID is not found */
5258 if (spec->board_config < 0)
5259 spec->board_config = snd_hda_check_board_config(codec,
5260 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005261 stac925x_models,
5262 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005263 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005264 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005265 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5266 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005267 else
5268 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005269 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005270
5271 spec->multiout.max_channels = 2;
5272 spec->multiout.num_dacs = 1;
5273 spec->multiout.dac_nids = stac925x_dac_nids;
5274 spec->adc_nids = stac925x_adc_nids;
5275 spec->mux_nids = stac925x_mux_nids;
5276 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005277 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005278 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005279 switch (codec->vendor_id) {
5280 case 0x83847632: /* STAC9202 */
5281 case 0x83847633: /* STAC9202D */
5282 case 0x83847636: /* STAC9251 */
5283 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005284 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005285 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005286 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5287 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005288 break;
5289 default:
5290 spec->num_dmics = 0;
5291 break;
5292 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005293
5294 spec->init = stac925x_core_init;
5295 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005296 spec->num_caps = 1;
5297 spec->capvols = stac925x_capvols;
5298 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005299
Charles Chin9009b0e2011-11-03 10:27:27 +01005300 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005301 if (!err) {
5302 if (spec->board_config < 0) {
5303 printk(KERN_WARNING "hda_codec: No auto-config is "
5304 "available, default to model=ref\n");
5305 spec->board_config = STAC_925x_REF;
5306 goto again;
5307 }
5308 err = -EINVAL;
5309 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005310 if (err < 0) {
5311 stac92xx_free(codec);
5312 return err;
5313 }
5314
5315 codec->patch_ops = stac92xx_patch_ops;
5316
5317 return 0;
5318}
5319
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005320static int patch_stac92hd73xx(struct hda_codec *codec)
5321{
5322 struct sigmatel_spec *spec;
5323 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5324 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005325 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005326
5327 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5328 if (spec == NULL)
5329 return -ENOMEM;
5330
Takashi Iwaia252c812009-12-25 22:56:20 +01005331 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005332 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005333 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005334 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005335 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5336 spec->pin_nids = stac92hd73xx_pin_nids;
5337 spec->board_config = snd_hda_check_board_config(codec,
5338 STAC_92HD73XX_MODELS,
5339 stac92hd73xx_models,
5340 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005341 /* check codec subsystem id if not found */
5342 if (spec->board_config < 0)
5343 spec->board_config =
5344 snd_hda_check_board_codec_sid_config(codec,
5345 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5346 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005347again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005348 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005349 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5350 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005351 else
5352 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005353 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005354
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005355 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005356 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5357
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005358 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005359 printk(KERN_WARNING "hda_codec: Could not determine "
5360 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005361 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005362 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005363 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005364 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005365 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005366 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005367 break;
5368 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005369 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005370 break;
5371 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005372 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5373 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005374 }
5375 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005376
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005377 spec->aloopback_mask = 0x01;
5378 spec->aloopback_shift = 8;
5379
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005380 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005381 spec->mux_nids = stac92hd73xx_mux_nids;
5382 spec->adc_nids = stac92hd73xx_adc_nids;
5383 spec->dmic_nids = stac92hd73xx_dmic_nids;
5384 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005385 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005386
5387 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5388 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005389 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005390
Takashi Iwai6479c632009-07-28 18:20:25 +02005391 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5392 spec->capvols = stac92hd73xx_capvols;
5393 spec->capsws = stac92hd73xx_capsws;
5394
Matthew Ranostaya7662642008-02-21 07:51:14 +01005395 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005396 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005397 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005398 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005399 case STAC_DELL_M6_AMIC:
5400 case STAC_DELL_M6_DMIC:
5401 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005402 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005403 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005404
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005405 switch (spec->board_config) {
5406 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005407 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005408 spec->num_dmics = 0;
5409 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005410 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005411 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005412 spec->num_dmics = 1;
5413 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005414 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005415 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5416 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005417 spec->num_dmics = 1;
5418 break;
5419 }
5420 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005421 case STAC_ALIENWARE_M17X:
5422 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5423 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5424 spec->eapd_switch = 0;
5425 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005426 default:
5427 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005428 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005429 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005430 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005431 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005432 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005433 /* GPIO0 High = Enable EAPD */
5434 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5435 spec->gpio_data = 0x01;
5436 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005437
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005438 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5439 spec->pwr_nids = stac92hd73xx_pwr_nids;
5440
Charles Chin9009b0e2011-11-03 10:27:27 +01005441 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005442
5443 if (!err) {
5444 if (spec->board_config < 0) {
5445 printk(KERN_WARNING "hda_codec: No auto-config is "
5446 "available, default to model=ref\n");
5447 spec->board_config = STAC_92HD73XX_REF;
5448 goto again;
5449 }
5450 err = -EINVAL;
5451 }
5452
5453 if (err < 0) {
5454 stac92xx_free(codec);
5455 return err;
5456 }
5457
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005458 if (spec->board_config == STAC_92HD73XX_NO_JD)
5459 spec->hp_detect = 0;
5460
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005461 codec->patch_ops = stac92xx_patch_ops;
5462
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005463 codec->proc_widget_hook = stac92hd7x_proc_hook;
5464
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005465 return 0;
5466}
5467
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005468static int hp_bnb2011_with_dock(struct hda_codec *codec)
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005469{
5470 if (codec->vendor_id != 0x111d7605 &&
5471 codec->vendor_id != 0x111d76d1)
5472 return 0;
5473
5474 switch (codec->subsystem_id) {
5475 case 0x103c1618:
5476 case 0x103c1619:
5477 case 0x103c161a:
5478 case 0x103c161b:
5479 case 0x103c161c:
5480 case 0x103c161d:
5481 case 0x103c161e:
5482 case 0x103c161f:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005483
5484 case 0x103c162a:
5485 case 0x103c162b:
5486
5487 case 0x103c1630:
5488 case 0x103c1631:
5489
5490 case 0x103c1633:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005491 case 0x103c1634:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005492 case 0x103c1635:
5493
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005494 case 0x103c3587:
5495 case 0x103c3588:
5496 case 0x103c3589:
5497 case 0x103c358a:
5498
5499 case 0x103c3667:
5500 case 0x103c3668:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005501 case 0x103c3669:
5502
5503 return 1;
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005504 }
5505 return 0;
5506}
5507
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005508static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
5509{
5510 struct sigmatel_spec *spec = codec->spec;
5511 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5512 int i;
5513
5514 spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5515 spec->auto_pin_cnt++;
5516
5517 if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5518 get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5519 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5520 if (nid == stac92hd83xxx_dmic_nids[i]) {
5521 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5522 spec->auto_dmic_cnt++;
5523 }
5524 }
5525 }
5526}
5527
5528static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5529{
5530 struct sigmatel_spec *spec = codec->spec;
5531
5532 spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5533 spec->auto_adc_cnt++;
5534}
5535
5536static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5537{
5538 int i, j;
5539 struct sigmatel_spec *spec = codec->spec;
5540
5541 for (i = 0; i < spec->auto_adc_cnt; i++) {
5542 if (get_connection_index(codec,
5543 spec->auto_adc_nids[i], nid) >= 0) {
5544 /* mux and volume for adc_nids[i] */
5545 if (!spec->auto_mux_nids[i]) {
5546 spec->auto_mux_nids[i] = nid;
5547 /* 92hd codecs capture volume is in mux */
5548 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
5549 3, 0, HDA_OUTPUT);
5550 }
5551 for (j = 0; j < spec->auto_dmic_cnt; j++) {
5552 if (get_connection_index(codec, nid,
5553 spec->auto_dmic_nids[j]) >= 0) {
5554 /* dmux for adc_nids[i] */
5555 if (!spec->auto_dmux_nids[i])
5556 spec->auto_dmux_nids[i] = nid;
5557 break;
5558 }
5559 }
5560 break;
5561 }
5562 }
5563}
5564
5565static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5566{
5567 hda_nid_t nid, end_nid;
5568 unsigned int wid_caps, wid_type;
5569 struct sigmatel_spec *spec = codec->spec;
5570
5571 end_nid = codec->start_nid + codec->num_nodes;
5572
5573 for (nid = codec->start_nid; nid < end_nid; nid++) {
5574 wid_caps = get_wcaps(codec, nid);
5575 wid_type = get_wcaps_type(wid_caps);
5576
5577 if (wid_type == AC_WID_PIN)
5578 stac92hd8x_add_pin(codec, nid);
5579
5580 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5581 stac92hd8x_add_adc(codec, nid);
5582 }
5583
5584 for (nid = codec->start_nid; nid < end_nid; nid++) {
5585 wid_caps = get_wcaps(codec, nid);
5586 wid_type = get_wcaps_type(wid_caps);
5587
5588 if (wid_type == AC_WID_AUD_SEL)
5589 stac92hd8x_add_mux(codec, nid);
5590 }
5591
5592 spec->pin_nids = spec->auto_pin_nids;
5593 spec->num_pins = spec->auto_pin_cnt;
5594 spec->adc_nids = spec->auto_adc_nids;
5595 spec->num_adcs = spec->auto_adc_cnt;
5596 spec->capvols = spec->auto_capvols;
5597 spec->capsws = spec->auto_capvols;
5598 spec->num_caps = spec->auto_adc_cnt;
5599 spec->mux_nids = spec->auto_mux_nids;
5600 spec->num_muxes = spec->auto_adc_cnt;
5601 spec->dmux_nids = spec->auto_dmux_nids;
5602 spec->num_dmuxes = spec->auto_adc_cnt;
5603 spec->dmic_nids = spec->auto_dmic_nids;
5604 spec->num_dmics = spec->auto_dmic_cnt;
5605}
5606
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005607static int patch_stac92hd83xxx(struct hda_codec *codec)
5608{
5609 struct sigmatel_spec *spec;
5610 int err;
5611
5612 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5613 if (spec == NULL)
5614 return -ENOMEM;
5615
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005616 if (hp_bnb2011_with_dock(codec)) {
5617 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5618 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5619 }
5620
Charles1cc9e8f2010-10-18 16:22:00 +08005621 /* reset pin power-down; Windows may leave these bits after reboot */
5622 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7EC, 0);
5623 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7ED, 0);
Takashi Iwaia252c812009-12-25 22:56:20 +01005624 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005625 codec->spec = spec;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005626
5627 stac92hd8x_fill_auto_spec(codec);
5628
Takashi Iwai1db7ccdb2010-12-03 15:19:14 +01005629 spec->linear_tone_beep = 0;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005630 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005631 spec->digbeep_nid = 0x21;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005632 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5633 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5634 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005635 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005636 spec->init = stac92hd83xxx_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005637
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005638 spec->board_config = snd_hda_check_board_config(codec,
5639 STAC_92HD83XXX_MODELS,
5640 stac92hd83xxx_models,
5641 stac92hd83xxx_cfg_tbl);
5642again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005643 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005644 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5645 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005646 else
5647 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005648 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005649
Charles Chin35c11772011-11-02 07:53:30 +01005650 if (spec->board_config != STAC_92HD83XXX_PWR_REF)
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005651 spec->num_pwrs = 0;
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005652
Takashi Iwaib4e81872009-11-18 17:20:24 +01005653 codec->patch_ops = stac92xx_patch_ops;
5654
Takashi Iwaidce17d42010-02-09 09:25:26 +01005655 if (find_mute_led_gpio(codec, 0))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005656 snd_printd("mute LED gpio %d polarity %d\n",
5657 spec->gpio_led,
5658 spec->gpio_led_polarity);
5659
Takashi Iwaib4e81872009-11-18 17:20:24 +01005660#ifdef CONFIG_SND_HDA_POWER_SAVE
5661 if (spec->gpio_led) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005662 if (spec->gpio_led <= 8) {
5663 spec->gpio_mask |= spec->gpio_led;
5664 spec->gpio_dir |= spec->gpio_led;
5665 spec->gpio_data |= spec->gpio_led;
5666 } else {
5667 codec->patch_ops.set_power_state =
5668 stac92xx_set_power_state;
5669 codec->patch_ops.post_suspend =
5670 stac92xx_post_suspend;
5671 }
5672 codec->patch_ops.pre_resume = stac92xx_pre_resume;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005673 codec->patch_ops.check_power_status =
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005674 stac92xx_check_power_status;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005675 }
5676#endif
5677
Charles Chin9009b0e2011-11-03 10:27:27 +01005678 err = stac92xx_parse_auto_config(codec);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005679 if (!err) {
5680 if (spec->board_config < 0) {
5681 printk(KERN_WARNING "hda_codec: No auto-config is "
5682 "available, default to model=ref\n");
5683 spec->board_config = STAC_92HD83XXX_REF;
5684 goto again;
5685 }
5686 err = -EINVAL;
5687 }
5688
5689 if (err < 0) {
5690 stac92xx_free(codec);
5691 return err;
5692 }
5693
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005694 codec->proc_widget_hook = stac92hd_proc_hook;
5695
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005696 return 0;
5697}
5698
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005699static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5700 hda_nid_t dig0pin)
5701{
5702 struct sigmatel_spec *spec = codec->spec;
5703 int idx;
5704
5705 for (idx = 0; idx < spec->num_pins; idx++)
5706 if (spec->pin_nids[idx] == dig0pin)
5707 break;
5708 if ((idx + 2) >= spec->num_pins)
5709 return 0;
5710
5711 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005712 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005713 return 2;
5714
5715 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005716 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005717 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005718 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005719 return 1;
5720 else
5721 return 0;
5722}
5723
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005724/* HP dv7 bass switch - GPIO5 */
5725#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5726static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5727 struct snd_ctl_elem_value *ucontrol)
5728{
5729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5730 struct sigmatel_spec *spec = codec->spec;
5731 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5732 return 0;
5733}
5734
5735static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5736 struct snd_ctl_elem_value *ucontrol)
5737{
5738 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5739 struct sigmatel_spec *spec = codec->spec;
5740 unsigned int gpio_data;
5741
5742 gpio_data = (spec->gpio_data & ~0x20) |
5743 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5744 if (gpio_data == spec->gpio_data)
5745 return 0;
5746 spec->gpio_data = gpio_data;
5747 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5748 return 1;
5749}
5750
Takashi Iwai2b635362011-05-02 12:33:43 +02005751static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005752 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5753 .info = stac_hp_bass_gpio_info,
5754 .get = stac_hp_bass_gpio_get,
5755 .put = stac_hp_bass_gpio_put,
5756};
5757
5758static int stac_add_hp_bass_switch(struct hda_codec *codec)
5759{
5760 struct sigmatel_spec *spec = codec->spec;
5761
5762 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5763 "Bass Speaker Playback Switch", 0))
5764 return -ENOMEM;
5765
5766 spec->gpio_mask |= 0x20;
5767 spec->gpio_dir |= 0x20;
5768 spec->gpio_data |= 0x20;
5769 return 0;
5770}
5771
Matthew Ranostaye035b842007-11-06 11:53:55 +01005772static int patch_stac92hd71bxx(struct hda_codec *codec)
5773{
5774 struct sigmatel_spec *spec;
Takashi Iwai2b635362011-05-02 12:33:43 +02005775 const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005776 unsigned int pin_cfg;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005777 int err = 0;
5778
5779 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5780 if (spec == NULL)
5781 return -ENOMEM;
5782
Takashi Iwaia252c812009-12-25 22:56:20 +01005783 codec->no_trigger_sense = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005784 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005785 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005786 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005787 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5788 switch (codec->vendor_id) {
5789 case 0x111d76b6:
5790 case 0x111d76b7:
5791 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5792 break;
5793 case 0x111d7603:
5794 case 0x111d7608:
5795 /* On 92HD75Bx 0x27 isn't a pin nid */
5796 spec->num_pins--;
5797 /* fallthrough */
5798 default:
5799 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5800 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005801 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005802 spec->board_config = snd_hda_check_board_config(codec,
5803 STAC_92HD71BXX_MODELS,
5804 stac92hd71bxx_models,
5805 stac92hd71bxx_cfg_tbl);
5806again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005807 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005808 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5809 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005810 else
5811 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005812 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005813
Takashi Iwaifc64b262009-09-14 15:33:01 +02005814 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005815 /* GPIO0 = EAPD */
5816 spec->gpio_mask = 0x01;
5817 spec->gpio_dir = 0x01;
5818 spec->gpio_data = 0x01;
5819 }
5820
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005821 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5822 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5823
Takashi Iwai6479c632009-07-28 18:20:25 +02005824 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5825 spec->capvols = stac92hd71bxx_capvols;
5826 spec->capsws = stac92hd71bxx_capsws;
5827
Matthew Ranostay541eee82007-12-14 12:08:04 +01005828 switch (codec->vendor_id) {
5829 case 0x111d76b6: /* 4 Port without Analog Mixer */
5830 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005831 unmute_init++;
5832 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005833 case 0x111d76b4: /* 6 Port without Analog Mixer */
5834 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005835 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005836 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005837 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005838 stac92hd71bxx_dmic_nids,
5839 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005840 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005841 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005842 switch (spec->board_config) {
5843 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005844 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005845 err = stac_add_event(spec, codec->afg,
5846 STAC_VREF_EVENT, 0x02);
5847 if (err < 0)
5848 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005849 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005850 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5851 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005852 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005853 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005854 spec->gpio_mask |= 0x02;
5855 break;
5856 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005857 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005858 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005859 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005860
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005861 /* no output amps */
5862 spec->num_pwrs = 0;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005863 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005864 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005865 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005866 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5867 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Takashi Iwai2b635362011-05-02 12:33:43 +02005868 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005869 spec->num_dmics = stac92xx_connected_ports(codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02005870 stac92hd71bxx_dmic_5port_nids,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005871 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005872 break;
5873 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005874 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005875 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005876
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005877 /* no output amps */
5878 spec->num_pwrs = 0;
5879 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005880 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005881 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005882 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005883 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005884 stac92hd71bxx_dmic_nids,
5885 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005886 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005887 }
5888
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005889 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5890 snd_hda_sequence_write_cache(codec, unmute_init);
5891
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005892 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005893 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005894 spec->aloopback_shift = 0;
5895
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005896 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005897 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005898 spec->mux_nids = stac92hd71bxx_mux_nids;
5899 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005900 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005901 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005902
5903 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5904 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005905 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005906 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005907
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305908 snd_printdd("Found board config: %d\n", spec->board_config);
5909
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005910 switch (spec->board_config) {
5911 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005912 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005913 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005914 stac92xx_auto_set_pinctl(codec, 0x0e,
5915 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005916 /* fallthru */
5917 case STAC_DELL_M4_2:
5918 spec->num_dmics = 0;
5919 spec->num_smuxes = 0;
5920 spec->num_dmuxes = 0;
5921 break;
5922 case STAC_DELL_M4_1:
5923 case STAC_DELL_M4_3:
5924 spec->num_dmics = 1;
5925 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005926 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005927 break;
James Gardiner514bf542009-05-03 04:00:44 -04005928 case STAC_HP_DV4_1222NR:
5929 spec->num_dmics = 1;
5930 /* I don't know if it needs 1 or 2 smuxes - will wait for
5931 * bug reports to fix if needed
5932 */
5933 spec->num_smuxes = 1;
5934 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005935 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005936 case STAC_HP_DV4:
5937 spec->gpio_led = 0x01;
5938 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005939 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005940 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005941 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005942 /* HP dv6 gives the headphone pin as a line-out. Thus we
5943 * need to set hp_detect flag here to force to enable HP
5944 * detection.
5945 */
5946 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005947 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005948 case STAC_HP_HDX:
5949 spec->num_dmics = 1;
5950 spec->num_dmuxes = 1;
5951 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005952 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005953 break;
5954 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005955
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005956 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005957 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5958 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5959 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5960 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5961 /* It was changed in the BIOS to just satisfy MS DTM.
5962 * Lets turn it back into slaved HP
5963 */
5964 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5965 | (AC_JACK_HP_OUT <<
5966 AC_DEFCFG_DEVICE_SHIFT);
5967 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5968 | AC_DEFCFG_SEQUENCE)))
5969 | 0x1f;
5970 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5971 }
5972 }
5973
Takashi Iwaidce17d42010-02-09 09:25:26 +01005974 if (find_mute_led_gpio(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005975 snd_printd("mute LED gpio %d polarity %d\n",
5976 spec->gpio_led,
5977 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005978
Takashi Iwai86d190e2009-05-26 15:18:58 +02005979#ifdef CONFIG_SND_HDA_POWER_SAVE
5980 if (spec->gpio_led) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005981 if (spec->gpio_led <= 8) {
5982 spec->gpio_mask |= spec->gpio_led;
5983 spec->gpio_dir |= spec->gpio_led;
5984 spec->gpio_data |= spec->gpio_led;
5985 } else {
5986 codec->patch_ops.set_power_state =
5987 stac92xx_set_power_state;
5988 codec->patch_ops.post_suspend =
5989 stac92xx_post_suspend;
5990 }
5991 codec->patch_ops.pre_resume = stac92xx_pre_resume;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005992 codec->patch_ops.check_power_status =
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005993 stac92xx_check_power_status;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005994 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005995#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005996
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005997 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005998
Charles Chin9009b0e2011-11-03 10:27:27 +01005999 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006000 if (!err) {
6001 if (spec->board_config < 0) {
6002 printk(KERN_WARNING "hda_codec: No auto-config is "
6003 "available, default to model=ref\n");
6004 spec->board_config = STAC_92HD71BXX_REF;
6005 goto again;
6006 }
6007 err = -EINVAL;
6008 }
6009
6010 if (err < 0) {
6011 stac92xx_free(codec);
6012 return err;
6013 }
6014
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006015 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02006016 if (spec->board_config == STAC_HP_DV4 ||
6017 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006018 unsigned int cap;
6019 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
6020 cap &= AC_GPIO_IO_COUNT;
6021 if (cap >= 6)
6022 stac_add_hp_bass_switch(codec);
6023 }
6024
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006025 codec->proc_widget_hook = stac92hd7x_proc_hook;
6026
Matthew Ranostaye035b842007-11-06 11:53:55 +01006027 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006028}
Matthew Ranostaye035b842007-11-06 11:53:55 +01006029
Matt2f2f4252005-04-13 14:45:30 +02006030static int patch_stac922x(struct hda_codec *codec)
6031{
6032 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02006033 int err;
Matt2f2f4252005-04-13 14:45:30 +02006034
Takashi Iwaie560d8d2005-09-09 14:21:46 +02006035 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02006036 if (spec == NULL)
6037 return -ENOMEM;
6038
Takashi Iwaia252c812009-12-25 22:56:20 +01006039 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02006040 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006041 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006042 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006043 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006044 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
6045 stac922x_models,
6046 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08006047 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006048 spec->gpio_mask = spec->gpio_dir = 0x03;
6049 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006050 /* Intel Macs have all same PCI SSID, so we need to check
6051 * codec SSID to distinguish the exact models
6052 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006053 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006054 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006055
6056 case 0x106b0800:
6057 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02006058 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006059 case 0x106b0600:
6060 case 0x106b0700:
6061 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006062 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006063 case 0x106b0e00:
6064 case 0x106b0f00:
6065 case 0x106b1600:
6066 case 0x106b1700:
6067 case 0x106b0200:
6068 case 0x106b1e00:
6069 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006070 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006071 case 0x106b1a00:
6072 case 0x00000100:
6073 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02006074 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006075 case 0x106b0a00:
6076 case 0x106b2200:
6077 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02006078 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08006079 default:
6080 spec->board_config = STAC_INTEL_MAC_V3;
6081 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006082 }
6083 }
6084
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006085 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006086 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006087 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6088 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006089 else
6090 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006091 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02006092
Matt2f2f4252005-04-13 14:45:30 +02006093 spec->adc_nids = stac922x_adc_nids;
6094 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006095 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006096 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006097 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006098 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02006099
6100 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006101
6102 spec->num_caps = STAC922X_NUM_CAPS;
6103 spec->capvols = stac922x_capvols;
6104 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02006105
6106 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02006107
Charles Chin9009b0e2011-11-03 10:27:27 +01006108 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006109 if (!err) {
6110 if (spec->board_config < 0) {
6111 printk(KERN_WARNING "hda_codec: No auto-config is "
6112 "available, default to model=ref\n");
6113 spec->board_config = STAC_D945_REF;
6114 goto again;
6115 }
6116 err = -EINVAL;
6117 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006118 if (err < 0) {
6119 stac92xx_free(codec);
6120 return err;
6121 }
6122
6123 codec->patch_ops = stac92xx_patch_ops;
6124
Takashi Iwai807a46362007-05-29 19:01:37 +02006125 /* Fix Mux capture level; max to 2 */
6126 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
6127 (0 << AC_AMPCAP_OFFSET_SHIFT) |
6128 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
6129 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6130 (0 << AC_AMPCAP_MUTE_SHIFT));
6131
Matt Porter3cc08dc2006-01-23 15:27:49 +01006132 return 0;
6133}
6134
6135static int patch_stac927x(struct hda_codec *codec)
6136{
6137 struct sigmatel_spec *spec;
6138 int err;
6139
6140 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6141 if (spec == NULL)
6142 return -ENOMEM;
6143
Takashi Iwaia252c812009-12-25 22:56:20 +01006144 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01006145 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006146 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05006147 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006148 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006149 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006150 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
6151 stac927x_models,
6152 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006153 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006154 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006155 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6156 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006157 else
6158 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006159 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01006160
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006161 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006162 spec->adc_nids = stac927x_adc_nids;
6163 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6164 spec->mux_nids = stac927x_mux_nids;
6165 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006166 spec->smux_nids = stac927x_smux_nids;
6167 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04006168 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01006169 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006170 spec->multiout.dac_nids = spec->dac_nids;
6171
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006172 if (spec->board_config != STAC_D965_REF) {
6173 /* GPIO0 High = Enable EAPD */
6174 spec->eapd_mask = spec->gpio_mask = 0x01;
6175 spec->gpio_dir = spec->gpio_data = 0x01;
6176 }
6177
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006178 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02006179 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006180 case STAC_D965_5ST:
6181 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006182 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02006183 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006184 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006185 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006186 switch (codec->subsystem_id) {
6187 case 0x10280209:
6188 case 0x1028022e:
6189 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006190 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006191 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006192 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01006193 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01006194 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01006195 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006196 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006197 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01006198 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006199 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006200 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006201 if (codec->subsystem_id != 0x1028022f) {
6202 /* GPIO2 High = Enable EAPD */
6203 spec->eapd_mask = spec->gpio_mask = 0x04;
6204 spec->gpio_dir = spec->gpio_data = 0x04;
6205 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006206 spec->dmic_nids = stac927x_dmic_nids;
6207 spec->num_dmics = STAC927X_NUM_DMICS;
6208
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02006209 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006210 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006211 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006212 break;
Takashi Iwai54930532009-10-11 17:38:29 +02006213 case STAC_927X_VOLKNOB:
6214 spec->num_dmics = 0;
6215 spec->init = stac927x_volknob_core_init;
6216 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006217 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006218 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006219 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006220 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006221 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006222
Takashi Iwai6479c632009-07-28 18:20:25 +02006223 spec->num_caps = STAC927X_NUM_CAPS;
6224 spec->capvols = stac927x_capvols;
6225 spec->capsws = stac927x_capsws;
6226
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006227 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006228 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006229 spec->aloopback_mask = 0x40;
6230 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05006231 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006232
Charles Chin9009b0e2011-11-03 10:27:27 +01006233 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006234 if (!err) {
6235 if (spec->board_config < 0) {
6236 printk(KERN_WARNING "hda_codec: No auto-config is "
6237 "available, default to model=ref\n");
6238 spec->board_config = STAC_D965_REF;
6239 goto again;
6240 }
6241 err = -EINVAL;
6242 }
Mattc7d4b2f2005-06-27 14:59:41 +02006243 if (err < 0) {
6244 stac92xx_free(codec);
6245 return err;
6246 }
Matt2f2f4252005-04-13 14:45:30 +02006247
6248 codec->patch_ops = stac92xx_patch_ops;
6249
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006250 codec->proc_widget_hook = stac927x_proc_hook;
6251
Takashi Iwai52987652008-01-16 16:09:47 +01006252 /*
6253 * !!FIXME!!
6254 * The STAC927x seem to require fairly long delays for certain
6255 * command sequences. With too short delays (even if the answer
6256 * is set to RIRB properly), it results in the silence output
6257 * on some hardwares like Dell.
6258 *
6259 * The below flag enables the longer delay (see get_response
6260 * in hda_intel.c).
6261 */
6262 codec->bus->needs_damn_long_delay = 1;
6263
Takashi Iwaie28d8322008-12-17 13:48:29 +01006264 /* no jack detecion for ref-no-jd model */
6265 if (spec->board_config == STAC_D965_REF_NO_JD)
6266 spec->hp_detect = 0;
6267
Matt2f2f4252005-04-13 14:45:30 +02006268 return 0;
6269}
6270
Matt Porterf3302a52006-07-31 12:49:34 +02006271static int patch_stac9205(struct hda_codec *codec)
6272{
6273 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006274 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006275
6276 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6277 if (spec == NULL)
6278 return -ENOMEM;
6279
Takashi Iwaia252c812009-12-25 22:56:20 +01006280 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006281 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006282 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006283 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006284 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006285 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6286 stac9205_models,
6287 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006288 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006289 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006290 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6291 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006292 else
6293 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006294 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006295
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006296 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006297 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006298 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006299 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006300 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006301 spec->smux_nids = stac9205_smux_nids;
6302 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006303 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006304 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006305 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006306 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006307 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006308
6309 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006310 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006311
Takashi Iwai6479c632009-07-28 18:20:25 +02006312 spec->num_caps = STAC9205_NUM_CAPS;
6313 spec->capvols = stac9205_capvols;
6314 spec->capsws = stac9205_capsws;
6315
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006316 spec->aloopback_mask = 0x40;
6317 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006318 /* Turn on/off EAPD per HP plugging */
6319 if (spec->board_config != STAC_9205_EAPD)
6320 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006321 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006322
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006323 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006324 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006325 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006326 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6327 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006328
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006329 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006330 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6331 if (err < 0)
6332 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006333 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006334 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6335 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006336 AC_VERB_SET_UNSOLICITED_ENABLE,
6337 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006338
6339 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006340 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006341 spec->gpio_mask = 0x1b;
6342 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006343 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006344 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006345 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006346 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006347 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006348 case STAC_9205_REF:
6349 /* SPDIF-In enabled */
6350 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006351 default:
6352 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006353 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006354 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006355 break;
6356 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006357
Charles Chin9009b0e2011-11-03 10:27:27 +01006358 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006359 if (!err) {
6360 if (spec->board_config < 0) {
6361 printk(KERN_WARNING "hda_codec: No auto-config is "
6362 "available, default to model=ref\n");
6363 spec->board_config = STAC_9205_REF;
6364 goto again;
6365 }
6366 err = -EINVAL;
6367 }
Matt Porterf3302a52006-07-31 12:49:34 +02006368 if (err < 0) {
6369 stac92xx_free(codec);
6370 return err;
6371 }
6372
6373 codec->patch_ops = stac92xx_patch_ops;
6374
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006375 codec->proc_widget_hook = stac9205_proc_hook;
6376
Matt Porterf3302a52006-07-31 12:49:34 +02006377 return 0;
6378}
6379
Matt2f2f4252005-04-13 14:45:30 +02006380/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006381 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006382 */
6383
Takashi Iwai2b635362011-05-02 12:33:43 +02006384static const struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006385 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006386 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6387 {}
6388};
6389
Takashi Iwai2b635362011-05-02 12:33:43 +02006390static const hda_nid_t stac9872_pin_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006391 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6392 0x11, 0x13, 0x14,
6393};
6394
Takashi Iwai2b635362011-05-02 12:33:43 +02006395static const hda_nid_t stac9872_adc_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006396 0x8 /*,0x6*/
6397};
6398
Takashi Iwai2b635362011-05-02 12:33:43 +02006399static const hda_nid_t stac9872_mux_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006400 0x15
6401};
6402
Takashi Iwai2b635362011-05-02 12:33:43 +02006403static const unsigned long stac9872_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +02006404 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6405};
6406#define stac9872_capsws stac9872_capvols
6407
Takashi Iwai2b635362011-05-02 12:33:43 +02006408static const unsigned int stac9872_vaio_pin_configs[9] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006409 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6410 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6411 0x90a7013e
6412};
6413
Takashi Iwaiea734962011-01-17 11:29:34 +01006414static const char * const stac9872_models[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006415 [STAC_9872_AUTO] = "auto",
6416 [STAC_9872_VAIO] = "vaio",
6417};
6418
Takashi Iwai2b635362011-05-02 12:33:43 +02006419static const unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006420 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6421};
6422
Takashi Iwai2b635362011-05-02 12:33:43 +02006423static const struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006424 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6425 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006426 {} /* terminator */
6427};
6428
Guillaume Munch6d859062006-08-22 17:15:47 +02006429static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006430{
6431 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006432 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006433
Takashi Iwaidb064e52006-03-16 16:04:58 +01006434 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6435 if (spec == NULL)
6436 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006437 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006438 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006439 spec->linear_tone_beep = 1;
Takashi Iwaib04add92009-07-20 08:01:36 +02006440 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6441 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006442
6443 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6444 stac9872_models,
6445 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006446 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006447 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6448 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006449 else
6450 stac92xx_set_config_regs(codec,
6451 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006452
Takashi Iwai1e137f92009-01-21 07:41:22 +01006453 spec->multiout.dac_nids = spec->dac_nids;
6454 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6455 spec->adc_nids = stac9872_adc_nids;
6456 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6457 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006458 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006459 spec->num_caps = 1;
6460 spec->capvols = stac9872_capvols;
6461 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006462
Charles Chin9009b0e2011-11-03 10:27:27 +01006463 err = stac92xx_parse_auto_config(codec);
Takashi Iwai1e137f92009-01-21 07:41:22 +01006464 if (err < 0) {
6465 stac92xx_free(codec);
6466 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006467 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006468 spec->input_mux = &spec->private_imux;
6469 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006470 return 0;
6471}
6472
6473
6474/*
Matt2f2f4252005-04-13 14:45:30 +02006475 * patch entries
6476 */
Takashi Iwai2b635362011-05-02 12:33:43 +02006477static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006478 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6479 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6480 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6481 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6482 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6483 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6484 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006485 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6486 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6487 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6488 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6489 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6490 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006491 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6492 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6493 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6494 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6495 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6496 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6497 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6498 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6499 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6500 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006501 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6502 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6503 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6504 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6505 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6506 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006507 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6508 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006509 /* The following does not take into account .id=0x83847661 when subsys =
6510 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6511 * currently not fully supported.
6512 */
6513 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6514 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6515 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006516 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006517 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6518 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6519 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6520 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6521 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6522 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6523 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6524 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006525 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006526 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006527 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006528 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006529 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006530 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6531 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006532 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6533 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6534 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6535 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006536 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006537 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6538 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006539 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006540 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6541 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6542 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6543 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6544 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6545 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6546 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6547 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006548 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6549 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6550 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6551 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6552 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6553 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6554 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6555 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6556 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6557 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6558 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6559 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6560 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6561 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6562 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
David Henningsson46724c22011-09-20 09:02:22 +02006563 { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006564 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06006565 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6566 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006567 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Charles Chinad5d8752011-11-02 07:56:58 +01006568 { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6569 { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6570 { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6571 { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6572 { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6573 { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6574 { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6575 { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6576 { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6577 { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6578 { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6579 { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006580 {} /* terminator */
6581};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006582
6583MODULE_ALIAS("snd-hda-codec-id:8384*");
6584MODULE_ALIAS("snd-hda-codec-id:111d*");
6585
6586MODULE_LICENSE("GPL");
6587MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6588
6589static struct hda_codec_preset_list sigmatel_list = {
6590 .preset = snd_hda_preset_sigmatel,
6591 .owner = THIS_MODULE,
6592};
6593
6594static int __init patch_sigmatel_init(void)
6595{
6596 return snd_hda_add_codec_preset(&sigmatel_list);
6597}
6598
6599static void __exit patch_sigmatel_exit(void)
6600{
6601 snd_hda_delete_codec_preset(&sigmatel_list);
6602}
6603
6604module_init(patch_sigmatel_init)
6605module_exit(patch_sigmatel_exit)