blob: 470f6f286e8144f4f7a8282b2dc126239c69f765 [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,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +010098 STAC_DELL_VOSTRO_3500,
Takashi Iwaib4e81872009-11-18 17:20:24 +010099 STAC_92HD83XXX_HP,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -0500100 STAC_92HD83XXX_HP_cNB11_INTQUAD,
Steven Eastland48315592010-08-06 15:07:35 -0600101 STAC_HP_DV7_4000,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200102 STAC_92HD83XXX_MODELS
103};
104
105enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100106 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100107 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100108 STAC_DELL_M4_1,
109 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500110 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400111 STAC_HP_M4,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +0200112 STAC_HP_DV4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100113 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100114 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400115 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100116 STAC_92HD71BXX_MODELS
117};
118
119enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100120 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100121 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200122 STAC_M1,
123 STAC_M1_2,
124 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100125 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200126 STAC_M3,
127 STAC_M5,
128 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100129 STAC_925x_MODELS
130};
131
132enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100133 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100134 STAC_D945_REF,
135 STAC_D945GTP3,
136 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200137 STAC_INTEL_MAC_V1,
138 STAC_INTEL_MAC_V2,
139 STAC_INTEL_MAC_V3,
140 STAC_INTEL_MAC_V4,
141 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800142 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
143 * is given, one of the above models will be
144 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200145 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100146 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100147 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100148 STAC_MACBOOK_PRO_V1,
149 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200150 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200151 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300152 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200153 STAC_922X_DELL_D81,
154 STAC_922X_DELL_D82,
155 STAC_922X_DELL_M81,
156 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100157 STAC_922X_MODELS
158};
159
160enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100161 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100162 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100163 STAC_D965_REF,
164 STAC_D965_3ST,
165 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200166 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200167 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100168 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200169 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100170 STAC_927X_MODELS
171};
Matt Porter403d1942005-11-29 15:00:51 +0100172
Takashi Iwai307282c2009-03-12 18:17:58 +0100173enum {
174 STAC_9872_AUTO,
175 STAC_9872_VAIO,
176 STAC_9872_MODELS
177};
178
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400179struct sigmatel_event {
180 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100181 unsigned char type;
182 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400183 int data;
184};
185
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200186struct sigmatel_mic_route {
187 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200188 signed char mux_idx;
189 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200190};
191
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600192#define MAX_PINS_NUM 16
193#define MAX_ADCS_NUM 4
194#define MAX_DMICS_NUM 4
195
Matt2f2f4252005-04-13 14:45:30 +0200196struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100197 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200198 unsigned int num_mixers;
199
Matt Porter403d1942005-11-29 15:00:51 +0100200 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500201 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200202 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100203 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100204 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400205 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100206 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200207 unsigned int auto_mic:1;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +0100208 unsigned int linear_tone_beep:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200209
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100210 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200211 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100212 unsigned int gpio_mask;
213 unsigned int gpio_dir;
214 unsigned int gpio_data;
215 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200216 unsigned int gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +0100217 unsigned int gpio_led_polarity;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500218 unsigned int vref_led;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100219
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200220 /* stream */
221 unsigned int stream_delay;
222
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100223 /* analog loopback */
Takashi Iwai2b635362011-05-02 12:33:43 +0200224 const struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100225 unsigned char aloopback_mask;
226 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200227
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100228 /* power management */
229 unsigned int num_pwrs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200230 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
Charles Chinafef2cf2011-11-11 08:05:28 +0100376static const hda_nid_t stac92hd83xxx_pwr_nids[7] = {
377 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
378 0x0f, 0x10
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200379};
380
Takashi Iwai2b635362011-05-02 12:33:43 +0200381static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400382 0x1e, 0,
383};
384
Takashi Iwai2b635362011-05-02 12:33:43 +0200385static const hda_nid_t stac92hd83xxx_dmic_nids[] = {
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600386 0x11, 0x20,
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +0200387};
388
Takashi Iwai2b635362011-05-02 12:33:43 +0200389static const hda_nid_t stac92hd71bxx_pwr_nids[3] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100390 0x0a, 0x0d, 0x0f
391};
392
Takashi Iwai2b635362011-05-02 12:33:43 +0200393static const hda_nid_t stac92hd71bxx_adc_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100394 0x12, 0x13,
395};
396
Takashi Iwai2b635362011-05-02 12:33:43 +0200397static const hda_nid_t stac92hd71bxx_mux_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100398 0x1a, 0x1b
399};
400
Takashi Iwai2b635362011-05-02 12:33:43 +0200401static const hda_nid_t stac92hd71bxx_dmux_nids[2] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400402 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100403};
404
Takashi Iwai2b635362011-05-02 12:33:43 +0200405static const hda_nid_t stac92hd71bxx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200406 0x24, 0x25,
407};
408
Matthew Ranostaye035b842007-11-06 11:53:55 +0100409#define STAC92HD71BXX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200410static const hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100411 0x18, 0x19, 0
412};
413
Takashi Iwai2b635362011-05-02 12:33:43 +0200414static const hda_nid_t stac92hd71bxx_dmic_5port_nids[STAC92HD71BXX_NUM_DMICS] = {
415 0x18, 0
416};
417
418static const hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400419 0x22, 0
420};
421
Takashi Iwai6479c632009-07-28 18:20:25 +0200422#define STAC92HD71BXX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200423static const unsigned long stac92hd71bxx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200424 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
425 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
426};
427#define stac92hd71bxx_capsws stac92hd71bxx_capvols
428
Takashi Iwai2b635362011-05-02 12:33:43 +0200429static const hda_nid_t stac925x_adc_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100430 0x03,
431};
432
Takashi Iwai2b635362011-05-02 12:33:43 +0200433static const hda_nid_t stac925x_mux_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100434 0x0f,
435};
436
Takashi Iwai2b635362011-05-02 12:33:43 +0200437static const hda_nid_t stac925x_dac_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100438 0x02,
439};
440
Takashi Iwaif6e98522007-10-16 14:27:04 +0200441#define STAC925X_NUM_DMICS 1
Takashi Iwai2b635362011-05-02 12:33:43 +0200442static const hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200443 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200444};
445
Takashi Iwai2b635362011-05-02 12:33:43 +0200446static const hda_nid_t stac925x_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100447 0x14,
448};
449
Takashi Iwai2b635362011-05-02 12:33:43 +0200450static const unsigned long stac925x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200451 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
452};
Takashi Iwai2b635362011-05-02 12:33:43 +0200453static const unsigned long stac925x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200454 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
455};
456
Takashi Iwai2b635362011-05-02 12:33:43 +0200457static const hda_nid_t stac922x_adc_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200458 0x06, 0x07,
459};
460
Takashi Iwai2b635362011-05-02 12:33:43 +0200461static const hda_nid_t stac922x_mux_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200462 0x12, 0x13,
463};
464
Takashi Iwai6479c632009-07-28 18:20:25 +0200465#define STAC922X_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200466static const unsigned long stac922x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200467 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
468 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
469};
470#define stac922x_capsws stac922x_capvols
471
Takashi Iwai2b635362011-05-02 12:33:43 +0200472static const hda_nid_t stac927x_slave_dig_outs[2] = {
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500473 0x1f, 0,
474};
475
Takashi Iwai2b635362011-05-02 12:33:43 +0200476static const hda_nid_t stac927x_adc_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100477 0x07, 0x08, 0x09
478};
479
Takashi Iwai2b635362011-05-02 12:33:43 +0200480static const hda_nid_t stac927x_mux_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100481 0x15, 0x16, 0x17
482};
483
Takashi Iwai2b635362011-05-02 12:33:43 +0200484static const hda_nid_t stac927x_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200485 0x21,
486};
487
Takashi Iwai2b635362011-05-02 12:33:43 +0200488static const hda_nid_t stac927x_dac_nids[6] = {
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100489 0x02, 0x03, 0x04, 0x05, 0x06, 0
490};
491
Takashi Iwai2b635362011-05-02 12:33:43 +0200492static const hda_nid_t stac927x_dmux_nids[1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100493 0x1b,
494};
495
Matthew Ranostay7f168592007-10-18 17:38:17 +0200496#define STAC927X_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200497static const hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
Matthew Ranostay7f168592007-10-18 17:38:17 +0200498 0x13, 0x14, 0
499};
500
Takashi Iwai6479c632009-07-28 18:20:25 +0200501#define STAC927X_NUM_CAPS 3
Takashi Iwai2b635362011-05-02 12:33:43 +0200502static const unsigned long stac927x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200503 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
504 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
505 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
506};
Takashi Iwai2b635362011-05-02 12:33:43 +0200507static const unsigned long stac927x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200508 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
509 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
510 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
511};
512
Takashi Iwaiea734962011-01-17 11:29:34 +0100513static const char * const stac927x_spdif_labels[5] = {
Matthew Ranostay65973632008-09-16 10:39:37 -0400514 "Digital Playback", "ADAT", "Analog Mux 1",
515 "Analog Mux 2", "Analog Mux 3"
516};
517
Takashi Iwai2b635362011-05-02 12:33:43 +0200518static const hda_nid_t stac9205_adc_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200519 0x12, 0x13
520};
521
Takashi Iwai2b635362011-05-02 12:33:43 +0200522static const hda_nid_t stac9205_mux_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200523 0x19, 0x1a
524};
525
Takashi Iwai2b635362011-05-02 12:33:43 +0200526static const hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100527 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100528};
529
Takashi Iwai2b635362011-05-02 12:33:43 +0200530static const hda_nid_t stac9205_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200531 0x21,
532};
533
Takashi Iwaif6e98522007-10-16 14:27:04 +0200534#define STAC9205_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200535static const hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200536 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200537};
538
Takashi Iwai6479c632009-07-28 18:20:25 +0200539#define STAC9205_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200540static const unsigned long stac9205_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200541 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
542 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
543};
Takashi Iwai2b635362011-05-02 12:33:43 +0200544static const unsigned long stac9205_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200545 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
546 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
547};
548
Takashi Iwai2b635362011-05-02 12:33:43 +0200549static const hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200550 0x08, 0x09, 0x0d, 0x0e,
551 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200552};
553
Takashi Iwai2b635362011-05-02 12:33:43 +0200554static const hda_nid_t stac925x_pin_nids[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100555 0x07, 0x08, 0x0a, 0x0b,
556 0x0c, 0x0d, 0x10, 0x11,
557};
558
Takashi Iwai2b635362011-05-02 12:33:43 +0200559static const hda_nid_t stac922x_pin_nids[10] = {
Matt2f2f4252005-04-13 14:45:30 +0200560 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
561 0x0f, 0x10, 0x11, 0x15, 0x1b,
562};
563
Takashi Iwai2b635362011-05-02 12:33:43 +0200564static const hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100565 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
566 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200567 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100568};
569
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500570#define STAC92HD71BXX_NUM_PINS 13
Takashi Iwai2b635362011-05-02 12:33:43 +0200571static const hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500572 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
573 0x00, 0x14, 0x18, 0x19, 0x1e,
574 0x1f, 0x20, 0x27
575};
Takashi Iwai2b635362011-05-02 12:33:43 +0200576static const hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100577 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
578 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500579 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100580};
581
Takashi Iwai2b635362011-05-02 12:33:43 +0200582static const hda_nid_t stac927x_pin_nids[14] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100583 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
584 0x0f, 0x10, 0x11, 0x12, 0x13,
585 0x14, 0x21, 0x22, 0x23,
586};
587
Takashi Iwai2b635362011-05-02 12:33:43 +0200588static const hda_nid_t stac9205_pin_nids[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200589 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
590 0x0f, 0x14, 0x16, 0x17, 0x18,
591 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200592};
593
Matt Porter8b657272006-10-26 17:12:59 +0200594static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
595 struct snd_ctl_elem_info *uinfo)
596{
597 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
598 struct sigmatel_spec *spec = codec->spec;
599 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
600}
601
602static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
603 struct snd_ctl_elem_value *ucontrol)
604{
605 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
606 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100607 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200608
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100609 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200610 return 0;
611}
612
613static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
614 struct snd_ctl_elem_value *ucontrol)
615{
616 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
617 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100618 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200619
620 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100621 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200622}
623
Matthew Ranostayd9737752008-09-07 12:03:41 +0200624static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
625 struct snd_ctl_elem_info *uinfo)
626{
627 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
628 struct sigmatel_spec *spec = codec->spec;
629 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
630}
631
632static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_value *ucontrol)
634{
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct sigmatel_spec *spec = codec->spec;
637 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
638
639 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
640 return 0;
641}
642
643static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
644 struct snd_ctl_elem_value *ucontrol)
645{
646 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
647 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400648 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200649 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400650 int err, val;
651 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200652
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400653 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200654 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400655 if (err < 0)
656 return err;
657
658 if (spec->spdif_mute) {
659 if (smux_idx == 0)
660 nid = spec->multiout.dig_out_nid;
661 else
662 nid = codec->slave_dig_outs[smux_idx - 1];
663 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100664 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400665 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100666 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400667 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100668 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
669 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400670 }
671 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200672}
673
Wang Shaoyan96b63592011-08-10 16:01:04 +0800674#ifdef CONFIG_SND_HDA_POWER_SAVE
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500675static int stac_vrefout_set(struct hda_codec *codec,
676 hda_nid_t nid, unsigned int new_vref)
677{
678 int error, pinctl;
679
680 snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
681 pinctl = snd_hda_codec_read(codec, nid, 0,
682 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
683
684 if (pinctl < 0)
685 return pinctl;
686
687 pinctl &= 0xff;
688 pinctl &= ~AC_PINCTL_VREFEN;
689 pinctl |= (new_vref & AC_PINCTL_VREFEN);
690
691 error = snd_hda_codec_write_cache(codec, nid, 0,
692 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
693 if (error < 0)
694 return error;
695
696 return 1;
697}
Wang Shaoyan96b63592011-08-10 16:01:04 +0800698#endif
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500699
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200700static unsigned int stac92xx_vref_set(struct hda_codec *codec,
701 hda_nid_t nid, unsigned int new_vref)
702{
Takashi Iwaib8621512009-06-22 08:00:10 +0200703 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200704 unsigned int pincfg;
705 pincfg = snd_hda_codec_read(codec, nid, 0,
706 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
707
708 pincfg &= 0xff;
709 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
710 pincfg |= new_vref;
711
712 if (new_vref == AC_PINCTL_VREF_HIZ)
713 pincfg |= AC_PINCTL_OUT_EN;
714 else
715 pincfg |= AC_PINCTL_IN_EN;
716
717 error = snd_hda_codec_write_cache(codec, nid, 0,
718 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
719 if (error < 0)
720 return error;
721 else
722 return 1;
723}
724
725static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
726{
727 unsigned int vref;
728 vref = snd_hda_codec_read(codec, nid, 0,
729 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
730 vref &= AC_PINCTL_VREFEN;
731 return vref;
732}
733
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100734static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200735{
736 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
737 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200738 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200739}
740
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100741static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200742{
743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
744 struct sigmatel_spec *spec = codec->spec;
745 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
746
747 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
748 return 0;
749}
750
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100751static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200752{
753 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
754 struct sigmatel_spec *spec = codec->spec;
755 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200756 const struct hda_input_mux *imux = spec->input_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600757 unsigned int idx, prev_idx, didx;
Matt2f2f4252005-04-13 14:45:30 +0200758
Takashi Iwai5207e102009-07-30 13:09:08 +0200759 idx = ucontrol->value.enumerated.item[0];
760 if (idx >= imux->num_items)
761 idx = imux->num_items - 1;
762 prev_idx = spec->cur_mux[adc_idx];
763 if (prev_idx == idx)
764 return 0;
765 if (idx < spec->num_analog_muxes) {
766 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
767 AC_VERB_SET_CONNECT_SEL,
768 imux->items[idx].index);
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600769 if (prev_idx >= spec->num_analog_muxes &&
770 spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
Takashi Iwai5207e102009-07-30 13:09:08 +0200771 imux = spec->dinput_mux;
772 /* 0 = analog */
773 snd_hda_codec_write_cache(codec,
774 spec->dmux_nids[adc_idx], 0,
775 AC_VERB_SET_CONNECT_SEL,
776 imux->items[0].index);
777 }
778 } else {
779 imux = spec->dinput_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600780 /* first dimux item is hardcoded to select analog imux,
781 * so lets skip it
782 */
783 didx = idx - spec->num_analog_muxes + 1;
Takashi Iwai5207e102009-07-30 13:09:08 +0200784 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
785 AC_VERB_SET_CONNECT_SEL,
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600786 imux->items[didx].index);
Takashi Iwai5207e102009-07-30 13:09:08 +0200787 }
788 spec->cur_mux[adc_idx] = idx;
789 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200790}
791
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100792static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
793 struct snd_ctl_elem_info *uinfo)
794{
795 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
796 struct sigmatel_spec *spec = codec->spec;
797 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
798}
799
800static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
801 struct snd_ctl_elem_value *ucontrol)
802{
803 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
804 struct sigmatel_spec *spec = codec->spec;
805
806 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
807 return 0;
808}
809
810static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
811 struct snd_ctl_elem_value *ucontrol)
812{
813 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
814 struct sigmatel_spec *spec = codec->spec;
815
816 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
817 spec->mono_nid, &spec->cur_mmux);
818}
819
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200820#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
821
822static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
823 struct snd_ctl_elem_value *ucontrol)
824{
825 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100826 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200827 struct sigmatel_spec *spec = codec->spec;
828
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100829 ucontrol->value.integer.value[0] = !!(spec->aloopback &
830 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200831 return 0;
832}
833
834static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
835 struct snd_ctl_elem_value *ucontrol)
836{
837 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
838 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100839 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200840 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100841 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200842
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100843 idx_val = spec->aloopback_mask << idx;
844 if (ucontrol->value.integer.value[0])
845 val = spec->aloopback | idx_val;
846 else
847 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100848 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200849 return 0;
850
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100851 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200852
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100853 /* Only return the bits defined by the shift value of the
854 * first two bytes of the mask
855 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200856 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100857 kcontrol->private_value & 0xFFFF, 0x0);
858 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200859
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100860 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200861 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100862 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200863 } else {
864 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100865 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200866 }
867
868 snd_hda_codec_write_cache(codec, codec->afg, 0,
869 kcontrol->private_value >> 16, dac_mode);
870
871 return 1;
872}
873
Takashi Iwai2b635362011-05-02 12:33:43 +0200874static const struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200875 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200876 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200877 {}
878};
879
Takashi Iwai2b635362011-05-02 12:33:43 +0200880static const struct hda_verb stac9200_eapd_init[] = {
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200881 /* set dac0mux for dac converter */
882 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
883 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
884 {}
885};
886
Takashi Iwai2b635362011-05-02 12:33:43 +0200887static const struct hda_verb dell_eq_core_init[] = {
Matthew Ranostayd654a662008-03-14 08:46:51 +0100888 /* set master volume to max value without distortion
889 * and direct control */
890 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100891 {}
892};
893
Takashi Iwai2b635362011-05-02 12:33:43 +0200894static const struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100895 /* set master volume and direct control */
896 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100897 {}
898};
899
Takashi Iwai2b635362011-05-02 12:33:43 +0200900static const struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200901 /* power state controls amps */
902 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200903 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200904};
905
Takashi Iwai2b635362011-05-02 12:33:43 +0200906static const struct hda_verb stac92hd71bxx_core_init[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100907 /* set master volume and direct control */
908 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200909 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100910};
911
Takashi Iwai2b635362011-05-02 12:33:43 +0200912static const struct hda_verb stac92hd71bxx_unmute_core_init[] = {
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500913 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
914 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100915 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
916 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100917 {}
918};
919
Takashi Iwai2b635362011-05-02 12:33:43 +0200920static const struct hda_verb stac925x_core_init[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100921 /* set dac0mux for dac converter */
922 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100923 /* mute the master volume */
924 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100925 {}
926};
927
Takashi Iwai2b635362011-05-02 12:33:43 +0200928static const struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200929 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200930 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200931 {}
932};
933
Takashi Iwai2b635362011-05-02 12:33:43 +0200934static const struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200935 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200936 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200937 /* unmute node 0x1b */
938 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
939 /* select node 0x03 as DAC */
940 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
941 {}
942};
943
Takashi Iwai2b635362011-05-02 12:33:43 +0200944static const struct hda_verb dell_3st_core_init[] = {
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200945 /* don't set delta bit */
946 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
947 /* unmute node 0x1b */
948 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
949 /* select node 0x03 as DAC */
950 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
951 {}
952};
953
Takashi Iwai2b635362011-05-02 12:33:43 +0200954static const struct hda_verb stac927x_core_init[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100955 /* set master volume and direct control */
956 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200957 /* enable analog pc beep path */
958 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100959 {}
960};
961
Takashi Iwai2b635362011-05-02 12:33:43 +0200962static const struct hda_verb stac927x_volknob_core_init[] = {
Takashi Iwai54930532009-10-11 17:38:29 +0200963 /* don't set delta bit */
964 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
965 /* enable analog pc beep path */
966 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
967 {}
968};
969
Takashi Iwai2b635362011-05-02 12:33:43 +0200970static const struct hda_verb stac9205_core_init[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200971 /* set master volume and direct control */
972 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200973 /* enable analog pc beep path */
974 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200975 {}
976};
977
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100978#define STAC_MONO_MUX \
979 { \
980 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
981 .name = "Mono Mux", \
982 .count = 1, \
983 .info = stac92xx_mono_mux_enum_info, \
984 .get = stac92xx_mono_mux_enum_get, \
985 .put = stac92xx_mono_mux_enum_put, \
986 }
987
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100988#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200989 { \
990 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
991 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100992 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200993 .info = stac92xx_aloopback_info, \
994 .get = stac92xx_aloopback_get, \
995 .put = stac92xx_aloopback_put, \
996 .private_value = verb_read | (verb_write << 16), \
997 }
998
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200999#define DC_BIAS(xname, idx, nid) \
1000 { \
1001 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1002 .name = xname, \
1003 .index = idx, \
1004 .info = stac92xx_dc_bias_info, \
1005 .get = stac92xx_dc_bias_get, \
1006 .put = stac92xx_dc_bias_put, \
1007 .private_value = nid, \
1008 }
1009
Takashi Iwai2b635362011-05-02 12:33:43 +02001010static const struct snd_kcontrol_new stac9200_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001011 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001012 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001013 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1014 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001015 { } /* end */
1016};
1017
Takashi Iwai2b635362011-05-02 12:33:43 +02001018static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001019 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1020 {}
1021};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001022
Takashi Iwai2b635362011-05-02 12:33:43 +02001023static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001024 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1025 {}
1026};
1027
Takashi Iwai2b635362011-05-02 12:33:43 +02001028static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001029 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1030 {}
1031};
1032
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001033
Takashi Iwai2b635362011-05-02 12:33:43 +02001034static const struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001035 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1036};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001037
Takashi Iwai2b635362011-05-02 12:33:43 +02001038static const struct snd_kcontrol_new stac925x_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001039 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
Takashi Iwaic9280d62009-01-15 17:31:00 +01001040 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001041 { } /* end */
1042};
1043
Takashi Iwai2b635362011-05-02 12:33:43 +02001044static const struct snd_kcontrol_new stac9205_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001045 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1046 {}
1047};
1048
Takashi Iwai2b635362011-05-02 12:33:43 +02001049static const struct snd_kcontrol_new stac927x_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001050 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1051 {}
1052};
1053
Takashi Iwai1697055e2007-12-18 18:05:52 +01001054static struct snd_kcontrol_new stac_dmux_mixer = {
1055 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1056 .name = "Digital Input Source",
1057 /* count set later */
1058 .info = stac92xx_dmux_enum_info,
1059 .get = stac92xx_dmux_enum_get,
1060 .put = stac92xx_dmux_enum_put,
1061};
1062
Matthew Ranostayd9737752008-09-07 12:03:41 +02001063static struct snd_kcontrol_new stac_smux_mixer = {
1064 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001065 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001066 /* count set later */
1067 .info = stac92xx_smux_enum_info,
1068 .get = stac92xx_smux_enum_get,
1069 .put = stac92xx_smux_enum_put,
1070};
1071
Takashi Iwaiea734962011-01-17 11:29:34 +01001072static const char * const slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001073 "Front Playback Volume",
1074 "Surround Playback Volume",
1075 "Center Playback Volume",
1076 "LFE Playback Volume",
1077 "Side Playback Volume",
1078 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001079 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001080 NULL
1081};
1082
Takashi Iwaiea734962011-01-17 11:29:34 +01001083static const char * const slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001084 "Front Playback Switch",
1085 "Surround Playback Switch",
1086 "Center Playback Switch",
1087 "LFE Playback Switch",
1088 "Side Playback Switch",
1089 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001090 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001091 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001092 NULL
1093};
1094
Takashi Iwai603c4012008-07-30 15:01:44 +02001095static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001096static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001097
Matt2f2f4252005-04-13 14:45:30 +02001098static int stac92xx_build_controls(struct hda_codec *codec)
1099{
1100 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001101 struct auto_pin_cfg *cfg = &spec->autocfg;
1102 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001103 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001104 int i;
Matt2f2f4252005-04-13 14:45:30 +02001105
Takashi Iwai6479c632009-07-28 18:20:25 +02001106 if (spec->mixer) {
1107 err = snd_hda_add_new_ctls(codec, spec->mixer);
1108 if (err < 0)
1109 return err;
1110 }
Mattc7d4b2f2005-06-27 14:59:41 +02001111
1112 for (i = 0; i < spec->num_mixers; i++) {
1113 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1114 if (err < 0)
1115 return err;
1116 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001117 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1118 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001119 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001120 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001121 snd_ctl_new1(&stac_dmux_mixer, codec));
1122 if (err < 0)
1123 return err;
1124 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001125 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001126 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1127 struct hda_input_mux *smux = &spec->private_smux;
1128 /* check for mute support on SPDIF out */
1129 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001130 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001131 spec->spdif_mute = 1;
1132 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001133 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001134 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001135 snd_ctl_new1(&stac_smux_mixer, codec));
1136 if (err < 0)
1137 return err;
1138 }
Mattc7d4b2f2005-06-27 14:59:41 +02001139
Mattdabbed62005-06-14 10:19:34 +02001140 if (spec->multiout.dig_out_nid) {
Stephen Warren74b654c2011-06-01 11:14:18 -06001141 err = snd_hda_create_spdif_out_ctls(codec,
1142 spec->multiout.dig_out_nid,
1143 spec->multiout.dig_out_nid);
Mattdabbed62005-06-14 10:19:34 +02001144 if (err < 0)
1145 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001146 err = snd_hda_create_spdif_share_sw(codec,
1147 &spec->multiout);
1148 if (err < 0)
1149 return err;
1150 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001151 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001152 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001153 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1154 if (err < 0)
1155 return err;
1156 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001157
1158 /* if we have no master control, let's create it */
1159 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001160 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001161 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001162 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001163 /* correct volume offset */
1164 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001165 /* minimum value is actually mute */
Clemens Ladischa74ccea2010-10-22 15:52:34 +02001166 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001167 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001168 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001169 if (err < 0)
1170 return err;
1171 }
1172 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1173 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1174 NULL, slave_sws);
1175 if (err < 0)
1176 return err;
1177 }
1178
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001179 if (spec->aloopback_ctl &&
1180 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1181 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1182 if (err < 0)
1183 return err;
1184 }
1185
Takashi Iwai603c4012008-07-30 15:01:44 +02001186 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001187
1188 /* create jack input elements */
1189 if (spec->hp_detect) {
1190 for (i = 0; i < cfg->hp_outs; i++) {
1191 int type = SND_JACK_HEADPHONE;
1192 nid = cfg->hp_pins[i];
1193 /* jack detection */
1194 if (cfg->hp_outs == i)
1195 type |= SND_JACK_LINEOUT;
1196 err = stac92xx_add_jack(codec, nid, type);
1197 if (err < 0)
1198 return err;
1199 }
1200 }
1201 for (i = 0; i < cfg->line_outs; i++) {
1202 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1203 SND_JACK_LINEOUT);
1204 if (err < 0)
1205 return err;
1206 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02001207 for (i = 0; i < cfg->num_inputs; i++) {
1208 nid = cfg->inputs[i].pin;
1209 err = stac92xx_add_jack(codec, nid, SND_JACK_MICROPHONE);
1210 if (err < 0)
1211 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001212 }
1213
Mattdabbed62005-06-14 10:19:34 +02001214 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001215}
1216
Takashi Iwai2b635362011-05-02 12:33:43 +02001217static const unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001218 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001219 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1220};
1221
Takashi Iwai2b635362011-05-02 12:33:43 +02001222static const unsigned int gateway9200_m4_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001223 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1224 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1225};
Takashi Iwai2b635362011-05-02 12:33:43 +02001226static const unsigned int gateway9200_m4_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001227 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1228 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1229};
1230
1231/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001232 STAC 9200 pin configs for
1233 102801A8
1234 102801DE
1235 102801E8
1236*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001237static const unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001238 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1239 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001240};
1241
1242/*
1243 STAC 9200 pin configs for
1244 102801C0
1245 102801C1
1246*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001247static const unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001248 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1249 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001250};
1251
1252/*
1253 STAC 9200 pin configs for
1254 102801C4 (Dell Dimension E310)
1255 102801C5
1256 102801C7
1257 102801D9
1258 102801DA
1259 102801E3
1260*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001261static const unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001262 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1263 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001264};
1265
1266
1267/*
1268 STAC 9200-32 pin configs for
1269 102801B5 (Dell Inspiron 630m)
1270 102801D8 (Dell Inspiron 640m)
1271*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001272static const unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001273 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1274 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001275};
1276
1277/*
1278 STAC 9200-32 pin configs for
1279 102801C2 (Dell Latitude D620)
1280 102801C8
1281 102801CC (Dell Latitude D820)
1282 102801D4
1283 102801D6
1284*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001285static const unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001286 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1287 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001288};
1289
1290/*
1291 STAC 9200-32 pin configs for
1292 102801CE (Dell XPS M1710)
1293 102801CF (Dell Precision M90)
1294*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001295static const unsigned int dell9200_m23_pin_configs[8] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001296 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1297 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1298};
1299
1300/*
1301 STAC 9200-32 pin configs for
1302 102801C9
1303 102801CA
1304 102801CB (Dell Latitude 120L)
1305 102801D3
1306*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001307static const unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001308 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1309 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001310};
1311
1312/*
1313 STAC 9200-32 pin configs for
1314 102801BD (Dell Inspiron E1505n)
1315 102801EE
1316 102801EF
1317*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001318static const unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001319 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1320 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001321};
1322
1323/*
1324 STAC 9200-32 pin configs for
1325 102801F5 (Dell Inspiron 1501)
1326 102801F6
1327*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001328static const unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001329 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1330 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001331};
1332
1333/*
1334 STAC 9200-32
1335 102801CD (Dell Inspiron E1705/9400)
1336*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001337static const unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001338 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1339 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001340};
1341
Takashi Iwai2b635362011-05-02 12:33:43 +02001342static const unsigned int oqo9200_pin_configs[8] = {
Tobin Davisbf277782008-02-03 20:31:47 +01001343 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1344 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1345};
1346
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001347
Takashi Iwai2b635362011-05-02 12:33:43 +02001348static const unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001349 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001350 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001351 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1352 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1353 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1354 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1355 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1356 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1357 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1358 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1359 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1360 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001361 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1362 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001363 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001364};
1365
Takashi Iwaiea734962011-01-17 11:29:34 +01001366static const char * const stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001367 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001368 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001369 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001370 [STAC_9200_DELL_D21] = "dell-d21",
1371 [STAC_9200_DELL_D22] = "dell-d22",
1372 [STAC_9200_DELL_D23] = "dell-d23",
1373 [STAC_9200_DELL_M21] = "dell-m21",
1374 [STAC_9200_DELL_M22] = "dell-m22",
1375 [STAC_9200_DELL_M23] = "dell-m23",
1376 [STAC_9200_DELL_M24] = "dell-m24",
1377 [STAC_9200_DELL_M25] = "dell-m25",
1378 [STAC_9200_DELL_M26] = "dell-m26",
1379 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001380 [STAC_9200_M4] = "gateway-m4",
1381 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001382 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001383};
1384
Takashi Iwai2b635362011-05-02 12:33:43 +02001385static const struct snd_pci_quirk stac9200_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001386 /* SigmaTel reference board */
1387 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1388 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001389 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1390 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001391 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001392 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1393 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001394 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001395 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1396 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1397 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1398 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1399 "unknown Dell", STAC_9200_DELL_D22),
1400 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1401 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001402 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001403 "Dell Latitude D620", STAC_9200_DELL_M22),
1404 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1405 "unknown Dell", STAC_9200_DELL_D23),
1406 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1407 "unknown Dell", STAC_9200_DELL_D23),
1408 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1409 "unknown Dell", STAC_9200_DELL_M22),
1410 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1411 "unknown Dell", STAC_9200_DELL_M24),
1412 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1413 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001414 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001415 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001416 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001417 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001418 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001419 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001420 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001421 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001422 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001423 "Dell Precision M90", STAC_9200_DELL_M23),
1424 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1425 "unknown Dell", STAC_9200_DELL_M22),
1426 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1427 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001428 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001429 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001430 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001431 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1432 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1433 "unknown Dell", STAC_9200_DELL_D23),
1434 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1435 "unknown Dell", STAC_9200_DELL_D23),
1436 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1437 "unknown Dell", STAC_9200_DELL_D21),
1438 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1439 "unknown Dell", STAC_9200_DELL_D23),
1440 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1441 "unknown Dell", STAC_9200_DELL_D21),
1442 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1443 "unknown Dell", STAC_9200_DELL_M25),
1444 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1445 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001446 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001447 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1448 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1449 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001450 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001451 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001452 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001453 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1454 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1455 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001456 /* OQO Mobile */
1457 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001458 {} /* terminator */
1459};
1460
Takashi Iwai2b635362011-05-02 12:33:43 +02001461static const unsigned int ref925x_pin_configs[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001462 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001463 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001464};
1465
Takashi Iwai2b635362011-05-02 12:33:43 +02001466static const unsigned int stac925xM1_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001467 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1468 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001469};
1470
Takashi Iwai2b635362011-05-02 12:33:43 +02001471static const unsigned int stac925xM1_2_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001472 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1473 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1474};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001475
Takashi Iwai2b635362011-05-02 12:33:43 +02001476static const unsigned int stac925xM2_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001477 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1478 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001479};
1480
Takashi Iwai2b635362011-05-02 12:33:43 +02001481static const unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001482 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1483 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1484};
1485
Takashi Iwai2b635362011-05-02 12:33:43 +02001486static const unsigned int stac925xM3_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001487 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1488 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1489};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001490
Takashi Iwai2b635362011-05-02 12:33:43 +02001491static const unsigned int stac925xM5_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001492 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1493 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1494};
1495
Takashi Iwai2b635362011-05-02 12:33:43 +02001496static const unsigned int stac925xM6_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001497 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1498 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001499};
1500
Takashi Iwai2b635362011-05-02 12:33:43 +02001501static const unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001502 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001503 [STAC_M1] = stac925xM1_pin_configs,
1504 [STAC_M1_2] = stac925xM1_2_pin_configs,
1505 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001506 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001507 [STAC_M3] = stac925xM3_pin_configs,
1508 [STAC_M5] = stac925xM5_pin_configs,
1509 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001510};
1511
Takashi Iwaiea734962011-01-17 11:29:34 +01001512static const char * const stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001513 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001514 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001515 [STAC_M1] = "m1",
1516 [STAC_M1_2] = "m1-2",
1517 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001518 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001519 [STAC_M3] = "m3",
1520 [STAC_M5] = "m5",
1521 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001522};
1523
Takashi Iwai2b635362011-05-02 12:33:43 +02001524static const struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001525 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1526 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1527 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1528 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001529 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001530 /* Not sure about the brand name for those */
1531 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1532 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1533 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1534 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001535 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001536};
1537
Takashi Iwai2b635362011-05-02 12:33:43 +02001538static const struct snd_pci_quirk stac925x_cfg_tbl[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001539 /* SigmaTel reference board */
1540 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001541 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001542 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001543
1544 /* Default table for unknown ID */
1545 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1546
Tobin Davis8e21c342007-01-08 11:04:17 +01001547 {} /* terminator */
1548};
1549
Takashi Iwai2b635362011-05-02 12:33:43 +02001550static const unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001551 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1552 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1553 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001554 0x01452050,
1555};
1556
Takashi Iwai2b635362011-05-02 12:33:43 +02001557static const unsigned int dell_m6_pin_configs[13] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001558 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001559 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001560 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1561 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001562};
1563
Takashi Iwai2b635362011-05-02 12:33:43 +02001564static const unsigned int alienware_m17x_pin_configs[13] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001565 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1566 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1567 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1568 0x904601b0,
1569};
1570
Takashi Iwai2b635362011-05-02 12:33:43 +02001571static const unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001572 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001573 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001574};
1575
Takashi Iwai2b635362011-05-02 12:33:43 +02001576static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001577 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001578 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1579 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1580 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001581 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001582 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001583 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001584};
1585
Takashi Iwaiea734962011-01-17 11:29:34 +01001586static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001587 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001588 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001589 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001590 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001591 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1592 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1593 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001594 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001595 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001596};
1597
Takashi Iwai2b635362011-05-02 12:33:43 +02001598static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001599 /* SigmaTel reference board */
1600 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001601 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001602 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1603 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001604 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1605 "Intel DG45ID", STAC_92HD73XX_INTEL),
1606 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1607 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001608 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001609 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001610 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001611 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001612 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001613 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001614 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001615 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001616 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001617 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001618 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001619 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001620 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001621 "unknown Dell", STAC_DELL_M6_DMIC),
1622 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1623 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001624 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001625 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001626 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1627 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001628 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1629 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001630 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1631 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001632 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1633 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001634 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
David Henningssone033ebf2011-05-16 12:09:29 +02001635 "Dell Studio 1558", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001636 {} /* terminator */
1637};
1638
Takashi Iwai2b635362011-05-02 12:33:43 +02001639static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001640 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1641 "Alienware M17x", STAC_ALIENWARE_M17X),
Daniel T Chen0defe092010-12-01 19:16:07 -05001642 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1643 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwai842ae632009-09-02 07:43:08 +02001644 {} /* terminator */
1645};
1646
Takashi Iwai2b635362011-05-02 12:33:43 +02001647static const unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001648 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1649 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001650 0x01451160, 0x98560170,
1651};
1652
Takashi Iwai2b635362011-05-02 12:33:43 +02001653static const unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001654 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1655 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001656 0x40f000f0, 0x40f000f0,
1657};
1658
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001659static const unsigned int dell_vostro_3500_pin_configs[10] = {
1660 0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
1661 0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
1662 0x400000f4, 0x400000f5,
1663};
1664
Takashi Iwai2b635362011-05-02 12:33:43 +02001665static const unsigned int hp_dv7_4000_pin_configs[10] = {
Steven Eastland48315592010-08-06 15:07:35 -06001666 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1667 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1668 0x40f000f0, 0x40f000f0,
1669};
1670
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001671static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
1672 0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
1673 0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
1674 0x40f000f0, 0x40f000f0,
1675};
1676
Takashi Iwai2b635362011-05-02 12:33:43 +02001677static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001678 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001679 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001680 [STAC_DELL_S14] = dell_s14_pin_configs,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001681 [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001682 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001683 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001684};
1685
Takashi Iwaiea734962011-01-17 11:29:34 +01001686static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001687 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001688 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001689 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001690 [STAC_DELL_S14] = "dell-s14",
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001691 [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
Takashi Iwaib4e81872009-11-18 17:20:24 +01001692 [STAC_92HD83XXX_HP] = "hp",
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001693 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
Steven Eastland48315592010-08-06 15:07:35 -06001694 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001695};
1696
Takashi Iwai2b635362011-05-02 12:33:43 +02001697static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001698 /* SigmaTel reference board */
1699 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001700 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001701 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1702 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001703 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1704 "unknown Dell", STAC_DELL_S14),
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001705 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
1706 "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
Takashi Iwaib4e81872009-11-18 17:20:24 +01001707 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001708 "HP", STAC_92HD83XXX_HP),
1709 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
1710 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1711 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
1712 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1713 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
1714 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1715 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
1716 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1717 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
1718 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1719 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1720 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1721 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1722 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1723 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
1724 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1725 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
1726 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1727 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
1728 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1729 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
1730 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1731 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
1732 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1733 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
1734 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1735 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
1736 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1737 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
1738 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1739 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
1740 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1741 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
1742 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1743 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
1744 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1745 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
1746 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1747 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
1748 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001749 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001750};
1751
Takashi Iwai2b635362011-05-02 12:33:43 +02001752static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001753 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001754 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001755 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1756 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001757};
1758
Takashi Iwai2b635362011-05-02 12:33:43 +02001759static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001760 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001761 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001762 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 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_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001767 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1768 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001769 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1770 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001771};
1772
Takashi Iwai2b635362011-05-02 12:33:43 +02001773static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001774 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1775 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001776 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1777 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001778};
1779
Takashi Iwai2b635362011-05-02 12:33:43 +02001780static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001781 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001782 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1783 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001784 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001785 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001786 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001787 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001788 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001789 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001790};
1791
Takashi Iwaiea734962011-01-17 11:29:34 +01001792static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001793 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001794 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001795 [STAC_DELL_M4_1] = "dell-m4-1",
1796 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001797 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001798 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001799 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001800 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001801 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001802 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001803};
1804
Takashi Iwai2b635362011-05-02 12:33:43 +02001805static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001806 /* SigmaTel reference board */
1807 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1808 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001809 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1810 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001811 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1812 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01001813 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1814 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01001815 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1816 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001817 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001818 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001819 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1820 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001821 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1822 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001823 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001824 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001825 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001826 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001827 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1828 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05301829 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1830 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11001831 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1832 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02001833 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1834 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001835 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1836 "unknown Dell", STAC_DELL_M4_1),
1837 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1838 "unknown Dell", STAC_DELL_M4_1),
1839 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1840 "unknown Dell", STAC_DELL_M4_1),
1841 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1842 "unknown Dell", STAC_DELL_M4_1),
1843 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1844 "unknown Dell", STAC_DELL_M4_1),
1845 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1846 "unknown Dell", STAC_DELL_M4_1),
1847 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1848 "unknown Dell", STAC_DELL_M4_1),
1849 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1850 "unknown Dell", STAC_DELL_M4_2),
1851 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1852 "unknown Dell", STAC_DELL_M4_2),
1853 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1854 "unknown Dell", STAC_DELL_M4_2),
1855 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1856 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001857 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1858 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001859 {} /* terminator */
1860};
1861
Takashi Iwai2b635362011-05-02 12:33:43 +02001862static const unsigned int ref922x_pin_configs[10] = {
Matt Porter403d1942005-11-29 15:00:51 +01001863 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1864 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001865 0x40000100, 0x40000100,
1866};
1867
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001868/*
1869 STAC 922X pin configs for
1870 102801A7
1871 102801AB
1872 102801A9
1873 102801D1
1874 102801D2
1875*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001876static const unsigned int dell_922x_d81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001877 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1878 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1879 0x01813122, 0x400001f2,
1880};
1881
1882/*
1883 STAC 922X pin configs for
1884 102801AC
1885 102801D0
1886*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001887static const unsigned int dell_922x_d82_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001888 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1889 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1890 0x01813122, 0x400001f1,
1891};
1892
1893/*
1894 STAC 922X pin configs for
1895 102801BF
1896*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001897static const unsigned int dell_922x_m81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001898 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1899 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1900 0x40C003f1, 0x405003f0,
1901};
1902
1903/*
1904 STAC 9221 A1 pin configs for
1905 102801D7 (Dell XPS M1210)
1906*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001907static const unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001908 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1909 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001910 0x508003f3, 0x405003f4,
1911};
1912
Takashi Iwai2b635362011-05-02 12:33:43 +02001913static const unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001914 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001915 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1916 0x02a19120, 0x40000100,
1917};
1918
Takashi Iwai2b635362011-05-02 12:33:43 +02001919static const unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001920 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1921 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001922 0x02a19320, 0x40000100,
1923};
1924
Takashi Iwai2b635362011-05-02 12:33:43 +02001925static const unsigned int intel_mac_v1_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001926 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1927 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001928 0x400000fc, 0x400000fb,
1929};
1930
Takashi Iwai2b635362011-05-02 12:33:43 +02001931static const unsigned int intel_mac_v2_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001932 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1933 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001934 0x400000fc, 0x400000fb,
1935};
1936
Takashi Iwai2b635362011-05-02 12:33:43 +02001937static const unsigned int intel_mac_v3_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001938 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1939 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1940 0x400000fc, 0x400000fb,
1941};
1942
Takashi Iwai2b635362011-05-02 12:33:43 +02001943static const unsigned int intel_mac_v4_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001944 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1945 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1946 0x400000fc, 0x400000fb,
1947};
1948
Takashi Iwai2b635362011-05-02 12:33:43 +02001949static const unsigned int intel_mac_v5_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001950 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1951 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1952 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001953};
1954
Takashi Iwai2b635362011-05-02 12:33:43 +02001955static const unsigned int ecs202_pin_configs[10] = {
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001956 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1957 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1958 0x9037012e, 0x40e000f2,
1959};
Takashi Iwai76c08822007-06-19 12:17:42 +02001960
Takashi Iwai2b635362011-05-02 12:33:43 +02001961static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001962 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001963 [STAC_D945GTP3] = d945gtp3_pin_configs,
1964 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001965 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1966 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1967 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1968 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1969 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001970 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001971 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001972 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1973 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1974 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1975 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1976 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1977 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001978 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001979 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1980 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1981 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1982 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001983};
1984
Takashi Iwaiea734962011-01-17 11:29:34 +01001985static const char * const stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001986 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001987 [STAC_D945_REF] = "ref",
1988 [STAC_D945GTP5] = "5stack",
1989 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001990 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1991 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1992 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1993 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1994 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001995 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001996 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001997 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001998 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001999 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2000 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02002001 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002002 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002003 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002004 [STAC_922X_DELL_D81] = "dell-d81",
2005 [STAC_922X_DELL_D82] = "dell-d82",
2006 [STAC_922X_DELL_M81] = "dell-m81",
2007 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002008};
2009
Takashi Iwai2b635362011-05-02 12:33:43 +02002010static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002011 /* SigmaTel reference board */
2012 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2013 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002014 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2015 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002016 /* Intel 945G based systems */
2017 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2018 "Intel D945G", STAC_D945GTP3),
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2020 "Intel D945G", STAC_D945GTP3),
2021 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2022 "Intel D945G", STAC_D945GTP3),
2023 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2024 "Intel D945G", STAC_D945GTP3),
2025 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2026 "Intel D945G", STAC_D945GTP3),
2027 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2028 "Intel D945G", STAC_D945GTP3),
2029 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2030 "Intel D945G", STAC_D945GTP3),
2031 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2032 "Intel D945G", STAC_D945GTP3),
2033 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2034 "Intel D945G", STAC_D945GTP3),
2035 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2036 "Intel D945G", STAC_D945GTP3),
2037 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2038 "Intel D945G", STAC_D945GTP3),
2039 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2040 "Intel D945G", STAC_D945GTP3),
2041 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2042 "Intel D945G", STAC_D945GTP3),
2043 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2044 "Intel D945G", STAC_D945GTP3),
2045 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2046 "Intel D945G", STAC_D945GTP3),
2047 /* Intel D945G 5-stack systems */
2048 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2049 "Intel D945G", STAC_D945GTP5),
2050 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2051 "Intel D945G", STAC_D945GTP5),
2052 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2053 "Intel D945G", STAC_D945GTP5),
2054 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2055 "Intel D945G", STAC_D945GTP5),
2056 /* Intel 945P based systems */
2057 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2058 "Intel D945P", STAC_D945GTP3),
2059 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2060 "Intel D945P", STAC_D945GTP3),
2061 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2062 "Intel D945P", STAC_D945GTP3),
2063 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2064 "Intel D945P", STAC_D945GTP3),
2065 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2066 "Intel D945P", STAC_D945GTP3),
2067 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2068 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002069 /* other intel */
2070 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2071 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002072 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002073 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002074 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002075 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002076 /* Dell systems */
2077 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2078 "unknown Dell", STAC_922X_DELL_D81),
2079 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2080 "unknown Dell", STAC_922X_DELL_D81),
2081 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2082 "unknown Dell", STAC_922X_DELL_D81),
2083 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2084 "unknown Dell", STAC_922X_DELL_D82),
2085 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2086 "unknown Dell", STAC_922X_DELL_M81),
2087 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2088 "unknown Dell", STAC_922X_DELL_D82),
2089 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2090 "unknown Dell", STAC_922X_DELL_D81),
2091 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2092 "unknown Dell", STAC_922X_DELL_D81),
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2094 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002095 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002096 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002097 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002098 {} /* terminator */
2099};
2100
Takashi Iwai2b635362011-05-02 12:33:43 +02002101static const unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002102 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2103 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2104 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2105 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002106};
2107
Takashi Iwai2b635362011-05-02 12:33:43 +02002108static const unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002109 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2110 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2111 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2112 0x40000100, 0x40000100
2113};
2114
Takashi Iwai2b635362011-05-02 12:33:43 +02002115static const unsigned int d965_5st_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002116 0x02214020, 0x02a19080, 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 d965_5st_no_fp_pin_configs[14] = {
Takashi Iwai679d92e2009-05-24 19:00:08 +02002123 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2124 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2125 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2126 0x40000100, 0x40000100
2127};
2128
Takashi Iwai2b635362011-05-02 12:33:43 +02002129static const unsigned int dell_3st_pin_configs[14] = {
Tobin Davis4ff076e2007-08-07 11:48:12 +02002130 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2131 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002132 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002133 0x40c003fc, 0x40000100
2134};
2135
Takashi Iwai2b635362011-05-02 12:33:43 +02002136static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002137 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002138 [STAC_D965_REF] = ref927x_pin_configs,
2139 [STAC_D965_3ST] = d965_3st_pin_configs,
2140 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002141 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002142 [STAC_DELL_3ST] = dell_3st_pin_configs,
2143 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002144 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002145};
2146
Takashi Iwaiea734962011-01-17 11:29:34 +01002147static const char * const stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002148 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002149 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002150 [STAC_D965_REF] = "ref",
2151 [STAC_D965_3ST] = "3stack",
2152 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002153 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002154 [STAC_DELL_3ST] = "dell-3stack",
2155 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002156 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002157};
2158
Takashi Iwai2b635362011-05-02 12:33:43 +02002159static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002160 /* SigmaTel reference board */
2161 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2162 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002163 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2164 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002165 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002166 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2167 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002168 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002169 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2170 "Intel D965", STAC_D965_3ST),
2171 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2172 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002173 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002174 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002175 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2176 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002177 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002178 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002179 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002180 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002181 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002182 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002183 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2184 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2185 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2186 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002187 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002188 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2189 "Intel D965", STAC_D965_5ST),
2190 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2191 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002192 /* volume-knob fixes */
2193 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002194 {} /* terminator */
2195};
2196
Takashi Iwai2b635362011-05-02 12:33:43 +02002197static const unsigned int ref9205_pin_configs[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +02002198 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002199 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002200 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002201};
2202
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002203/*
2204 STAC 9205 pin configs for
2205 102801F1
2206 102801F2
2207 102801FC
2208 102801FD
2209 10280204
2210 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002211 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002212 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002213*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002214static const unsigned int dell_9205_m42_pin_configs[12] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002215 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2216 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2217 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2218};
2219
2220/*
2221 STAC 9205 pin configs for
2222 102801F9
2223 102801FA
2224 102801FE
2225 102801FF (Dell Precision M4300)
2226 10280206
2227 10280200
2228 10280201
2229*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002230static const unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002231 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2232 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2233 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2234};
2235
Takashi Iwai2b635362011-05-02 12:33:43 +02002236static const unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002237 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2238 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2239 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2240};
2241
Takashi Iwai2b635362011-05-02 12:33:43 +02002242static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002243 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002244 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2245 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2246 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002247 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002248};
2249
Takashi Iwaiea734962011-01-17 11:29:34 +01002250static const char * const stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002251 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002252 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002253 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002254 [STAC_9205_DELL_M43] = "dell-m43",
2255 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002256 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002257};
2258
Takashi Iwai2b635362011-05-02 12:33:43 +02002259static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002260 /* SigmaTel reference board */
2261 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2262 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002263 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2264 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002265 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2266 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002267 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002268 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2269 "unknown Dell", STAC_9205_DELL_M42),
2270 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2271 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002272 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002273 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002274 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2275 "Dell Precision", STAC_9205_DELL_M43),
2276 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2277 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002278 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2279 "unknown Dell", STAC_9205_DELL_M42),
2280 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2281 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002282 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2283 "Dell Precision", STAC_9205_DELL_M43),
2284 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002285 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002286 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2287 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002288 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2289 "Dell Precision", STAC_9205_DELL_M43),
2290 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2291 "Dell Precision", STAC_9205_DELL_M43),
2292 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2293 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002294 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2295 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002296 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2297 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002298 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2299 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002300 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002301 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002302 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002303 {} /* terminator */
2304};
2305
Takashi Iwai330ee992009-02-20 14:33:36 +01002306static void stac92xx_set_config_regs(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002307 const unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002308{
2309 int i;
2310 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002311
Takashi Iwai330ee992009-02-20 14:33:36 +01002312 if (!pincfgs)
2313 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002314
Matthew Ranostay87d48362007-07-17 11:52:24 +02002315 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002316 if (spec->pin_nids[i] && pincfgs[i])
2317 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2318 pincfgs[i]);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002319}
2320
Matt2f2f4252005-04-13 14:45:30 +02002321/*
2322 * Analog playback callbacks
2323 */
2324static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2325 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002326 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002327{
2328 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002329 if (spec->stream_delay)
2330 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002331 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2332 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002333}
2334
2335static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2336 struct hda_codec *codec,
2337 unsigned int stream_tag,
2338 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002339 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002340{
2341 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002342 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002343}
2344
2345static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2346 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002347 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002348{
2349 struct sigmatel_spec *spec = codec->spec;
2350 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2351}
2352
2353/*
Mattdabbed62005-06-14 10:19:34 +02002354 * Digital playback callbacks
2355 */
2356static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2357 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002358 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002359{
2360 struct sigmatel_spec *spec = codec->spec;
2361 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2362}
2363
2364static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2365 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002366 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002367{
2368 struct sigmatel_spec *spec = codec->spec;
2369 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2370}
2371
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002372static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2373 struct hda_codec *codec,
2374 unsigned int stream_tag,
2375 unsigned int format,
2376 struct snd_pcm_substream *substream)
2377{
2378 struct sigmatel_spec *spec = codec->spec;
2379 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2380 stream_tag, format, substream);
2381}
2382
Takashi Iwai9411e212009-02-13 11:32:28 +01002383static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2384 struct hda_codec *codec,
2385 struct snd_pcm_substream *substream)
2386{
2387 struct sigmatel_spec *spec = codec->spec;
2388 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2389}
2390
Mattdabbed62005-06-14 10:19:34 +02002391
2392/*
Matt2f2f4252005-04-13 14:45:30 +02002393 * Analog capture callbacks
2394 */
2395static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2396 struct hda_codec *codec,
2397 unsigned int stream_tag,
2398 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002399 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002400{
2401 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002402 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002403
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002404 if (spec->powerdown_adcs) {
2405 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002406 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002407 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2408 }
2409 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002410 return 0;
2411}
2412
2413static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2414 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002415 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002416{
2417 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002418 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002419
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002420 snd_hda_codec_cleanup_stream(codec, nid);
2421 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002422 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002423 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002424 return 0;
2425}
2426
Takashi Iwai2b635362011-05-02 12:33:43 +02002427static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
Mattdabbed62005-06-14 10:19:34 +02002428 .substreams = 1,
2429 .channels_min = 2,
2430 .channels_max = 2,
2431 /* NID is set in stac92xx_build_pcms */
2432 .ops = {
2433 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002434 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002435 .prepare = stac92xx_dig_playback_pcm_prepare,
2436 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002437 },
2438};
2439
Takashi Iwai2b635362011-05-02 12:33:43 +02002440static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
Mattdabbed62005-06-14 10:19:34 +02002441 .substreams = 1,
2442 .channels_min = 2,
2443 .channels_max = 2,
2444 /* NID is set in stac92xx_build_pcms */
2445};
2446
Takashi Iwai2b635362011-05-02 12:33:43 +02002447static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
Matt2f2f4252005-04-13 14:45:30 +02002448 .substreams = 1,
2449 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002450 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002451 .nid = 0x02, /* NID to query formats and rates */
2452 .ops = {
2453 .open = stac92xx_playback_pcm_open,
2454 .prepare = stac92xx_playback_pcm_prepare,
2455 .cleanup = stac92xx_playback_pcm_cleanup
2456 },
2457};
2458
Takashi Iwai2b635362011-05-02 12:33:43 +02002459static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002460 .substreams = 1,
2461 .channels_min = 2,
2462 .channels_max = 2,
2463 .nid = 0x06, /* NID to query formats and rates */
2464 .ops = {
2465 .open = stac92xx_playback_pcm_open,
2466 .prepare = stac92xx_playback_pcm_prepare,
2467 .cleanup = stac92xx_playback_pcm_cleanup
2468 },
2469};
2470
Takashi Iwai2b635362011-05-02 12:33:43 +02002471static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002472 .channels_min = 2,
2473 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002474 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002475 .ops = {
2476 .prepare = stac92xx_capture_pcm_prepare,
2477 .cleanup = stac92xx_capture_pcm_cleanup
2478 },
2479};
2480
2481static int stac92xx_build_pcms(struct hda_codec *codec)
2482{
2483 struct sigmatel_spec *spec = codec->spec;
2484 struct hda_pcm *info = spec->pcm_rec;
2485
2486 codec->num_pcms = 1;
2487 codec->pcm_info = info;
2488
Mattc7d4b2f2005-06-27 14:59:41 +02002489 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002490 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002491 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2492 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002493 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002494 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002495 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002496
2497 if (spec->alt_switch) {
2498 codec->num_pcms++;
2499 info++;
2500 info->name = "STAC92xx Analog Alt";
2501 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2502 }
Matt2f2f4252005-04-13 14:45:30 +02002503
Mattdabbed62005-06-14 10:19:34 +02002504 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2505 codec->num_pcms++;
2506 info++;
2507 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002508 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002509 if (spec->multiout.dig_out_nid) {
2510 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2511 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2512 }
2513 if (spec->dig_in_nid) {
2514 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2515 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2516 }
2517 }
2518
Matt2f2f4252005-04-13 14:45:30 +02002519 return 0;
2520}
2521
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002522static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2523 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002524{
Takashi Iwai1327a322009-03-23 13:07:47 +01002525 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002526 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2527 if (pincap & AC_PINCAP_VREF_100)
2528 return AC_PINCTL_VREF_100;
2529 if (pincap & AC_PINCAP_VREF_80)
2530 return AC_PINCTL_VREF_80;
2531 if (pincap & AC_PINCAP_VREF_50)
2532 return AC_PINCTL_VREF_50;
2533 if (pincap & AC_PINCAP_VREF_GRD)
2534 return AC_PINCTL_VREF_GRD;
2535 return 0;
2536}
2537
Matt Porter403d1942005-11-29 15:00:51 +01002538static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2539
2540{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002541 snd_hda_codec_write_cache(codec, nid, 0,
2542 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002543}
2544
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002545#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2546
2547static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2548 struct snd_ctl_elem_value *ucontrol)
2549{
2550 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2551 struct sigmatel_spec *spec = codec->spec;
2552
Takashi Iwaid7a89432008-11-12 09:48:04 +01002553 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002554 return 0;
2555}
2556
Takashi Iwai62558ce2009-07-29 14:23:09 +02002557static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002558
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002559static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2560 struct snd_ctl_elem_value *ucontrol)
2561{
2562 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2563 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002564 int nid = kcontrol->private_value;
2565
2566 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002567
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002568 /* check to be sure that the ports are up to date with
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002569 * switch changes
2570 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002571 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002572
2573 return 1;
2574}
2575
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002576static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2577 struct snd_ctl_elem_info *uinfo)
2578{
2579 int i;
Takashi Iwai2b635362011-05-02 12:33:43 +02002580 static const char * const texts[] = {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002581 "Mic In", "Line In", "Line Out"
2582 };
2583
2584 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2585 struct sigmatel_spec *spec = codec->spec;
2586 hda_nid_t nid = kcontrol->private_value;
2587
2588 if (nid == spec->mic_switch || nid == spec->line_switch)
2589 i = 3;
2590 else
2591 i = 2;
2592
2593 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2594 uinfo->value.enumerated.items = i;
2595 uinfo->count = 1;
2596 if (uinfo->value.enumerated.item >= i)
2597 uinfo->value.enumerated.item = i-1;
2598 strcpy(uinfo->value.enumerated.name,
2599 texts[uinfo->value.enumerated.item]);
2600
2601 return 0;
2602}
2603
2604static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2605 struct snd_ctl_elem_value *ucontrol)
2606{
2607 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2608 hda_nid_t nid = kcontrol->private_value;
2609 unsigned int vref = stac92xx_vref_get(codec, nid);
2610
2611 if (vref == stac92xx_get_default_vref(codec, nid))
2612 ucontrol->value.enumerated.item[0] = 0;
2613 else if (vref == AC_PINCTL_VREF_GRD)
2614 ucontrol->value.enumerated.item[0] = 1;
2615 else if (vref == AC_PINCTL_VREF_HIZ)
2616 ucontrol->value.enumerated.item[0] = 2;
2617
2618 return 0;
2619}
2620
2621static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2622 struct snd_ctl_elem_value *ucontrol)
2623{
2624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2625 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002626 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002627 hda_nid_t nid = kcontrol->private_value;
2628
2629 if (ucontrol->value.enumerated.item[0] == 0)
2630 new_vref = stac92xx_get_default_vref(codec, nid);
2631 else if (ucontrol->value.enumerated.item[0] == 1)
2632 new_vref = AC_PINCTL_VREF_GRD;
2633 else if (ucontrol->value.enumerated.item[0] == 2)
2634 new_vref = AC_PINCTL_VREF_HIZ;
2635 else
2636 return 0;
2637
2638 if (new_vref != stac92xx_vref_get(codec, nid)) {
2639 error = stac92xx_vref_set(codec, nid, new_vref);
2640 return error;
2641 }
2642
2643 return 0;
2644}
2645
2646static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2647 struct snd_ctl_elem_info *uinfo)
2648{
Takashi Iwai2b635362011-05-02 12:33:43 +02002649 char *texts[2];
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2651 struct sigmatel_spec *spec = codec->spec;
2652
2653 if (kcontrol->private_value == spec->line_switch)
2654 texts[0] = "Line In";
2655 else
2656 texts[0] = "Mic In";
2657 texts[1] = "Line Out";
2658 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2659 uinfo->value.enumerated.items = 2;
2660 uinfo->count = 1;
2661
2662 if (uinfo->value.enumerated.item >= 2)
2663 uinfo->value.enumerated.item = 1;
2664 strcpy(uinfo->value.enumerated.name,
2665 texts[uinfo->value.enumerated.item]);
2666
2667 return 0;
2668}
Matt Porter403d1942005-11-29 15:00:51 +01002669
2670static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2671{
2672 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2673 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002674 hda_nid_t nid = kcontrol->private_value;
2675 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002676
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002677 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002678 return 0;
2679}
2680
2681static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2682{
2683 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2684 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002685 hda_nid_t nid = kcontrol->private_value;
2686 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2687 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002688
2689 spec->io_switch[io_idx] = val;
2690
2691 if (val)
2692 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002693 else {
2694 unsigned int pinctl = AC_PINCTL_IN_EN;
2695 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002696 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002697 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2698 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002699
2700 /* check the auto-mute again: we need to mute/unmute the speaker
2701 * appropriately according to the pin direction
2702 */
2703 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002704 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002705
Matt Porter403d1942005-11-29 15:00:51 +01002706 return 1;
2707}
2708
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002709#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2710
2711static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2712 struct snd_ctl_elem_value *ucontrol)
2713{
2714 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2715 struct sigmatel_spec *spec = codec->spec;
2716
2717 ucontrol->value.integer.value[0] = spec->clfe_swap;
2718 return 0;
2719}
2720
2721static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2722 struct snd_ctl_elem_value *ucontrol)
2723{
2724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2725 struct sigmatel_spec *spec = codec->spec;
2726 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002727 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002728
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002729 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002730 return 0;
2731
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002732 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002733
2734 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2735 spec->clfe_swap ? 0x4 : 0x0);
2736
2737 return 1;
2738}
2739
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002740#define STAC_CODEC_HP_SWITCH(xname) \
2741 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2742 .name = xname, \
2743 .index = 0, \
2744 .info = stac92xx_hp_switch_info, \
2745 .get = stac92xx_hp_switch_get, \
2746 .put = stac92xx_hp_switch_put, \
2747 }
2748
Matt Porter403d1942005-11-29 15:00:51 +01002749#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2750 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2751 .name = xname, \
2752 .index = 0, \
2753 .info = stac92xx_io_switch_info, \
2754 .get = stac92xx_io_switch_get, \
2755 .put = stac92xx_io_switch_put, \
2756 .private_value = xpval, \
2757 }
2758
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002759#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2760 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2761 .name = xname, \
2762 .index = 0, \
2763 .info = stac92xx_clfe_switch_info, \
2764 .get = stac92xx_clfe_switch_get, \
2765 .put = stac92xx_clfe_switch_put, \
2766 .private_value = xpval, \
2767 }
Matt Porter403d1942005-11-29 15:00:51 +01002768
Mattc7d4b2f2005-06-27 14:59:41 +02002769enum {
2770 STAC_CTL_WIDGET_VOL,
2771 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002772 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002773 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002774 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002775 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002776 STAC_CTL_WIDGET_CLFE_SWITCH,
2777 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002778};
2779
Takashi Iwai2b635362011-05-02 12:33:43 +02002780static const struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002781 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2782 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002783 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002784 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002785 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002786 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002787 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002788 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002789};
2790
2791/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002792static struct snd_kcontrol_new *
2793stac_control_new(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002794 const struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002795 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002796 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002797{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002798 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002799
Takashi Iwai603c4012008-07-30 15:01:44 +02002800 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2801 knew = snd_array_new(&spec->kctls);
2802 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002803 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002804 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002805 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002806 if (!knew->name) {
2807 /* roolback */
2808 memset(knew, 0, sizeof(*knew));
2809 spec->kctls.alloced--;
2810 return NULL;
2811 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002812 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002813 return knew;
2814}
2815
2816static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002817 const struct snd_kcontrol_new *ktemp,
Takashi Iwaie3c75962009-01-23 11:57:22 +01002818 int idx, const char *name,
2819 unsigned long val)
2820{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002821 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002822 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002823 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002824 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002825 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002826 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002827 return 0;
2828}
2829
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002830static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2831 int type, int idx, const char *name,
2832 unsigned long val)
2833{
2834 return stac92xx_add_control_temp(spec,
2835 &stac92xx_control_templates[type],
2836 idx, name, val);
2837}
2838
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002839
2840/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002841static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2842 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002843{
2844 return stac92xx_add_control_idx(spec, type, 0, name, val);
2845}
2846
Takashi Iwai2b635362011-05-02 12:33:43 +02002847static const struct snd_kcontrol_new stac_input_src_temp = {
Takashi Iwaie3c75962009-01-23 11:57:22 +01002848 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2849 .name = "Input Source",
2850 .info = stac92xx_mux_enum_info,
2851 .get = stac92xx_mux_enum_get,
2852 .put = stac92xx_mux_enum_put,
2853};
2854
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002855static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2856 hda_nid_t nid, int idx)
2857{
2858 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2859 int control = 0;
2860 struct sigmatel_spec *spec = codec->spec;
2861 char name[22];
2862
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002863 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002864 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2865 && nid == spec->line_switch)
2866 control = STAC_CTL_WIDGET_IO_SWITCH;
2867 else if (snd_hda_query_pin_caps(codec, nid)
2868 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2869 control = STAC_CTL_WIDGET_DC_BIAS;
2870 else if (nid == spec->mic_switch)
2871 control = STAC_CTL_WIDGET_IO_SWITCH;
2872 }
2873
2874 if (control) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002875 strcpy(name, hda_get_input_pin_label(codec, nid, 1));
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002876 return stac92xx_add_control(codec->spec, control,
2877 strcat(name, " Jack Mode"), nid);
2878 }
2879
2880 return 0;
2881}
2882
Takashi Iwaie3c75962009-01-23 11:57:22 +01002883static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2884{
2885 struct snd_kcontrol_new *knew;
2886 struct hda_input_mux *imux = &spec->private_imux;
2887
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002888 if (spec->auto_mic)
2889 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002890 if (!spec->num_adcs || imux->num_items <= 1)
2891 return 0; /* no need for input source control */
2892 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002893 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002894 if (!knew)
2895 return -ENOMEM;
2896 knew->count = spec->num_adcs;
2897 return 0;
2898}
2899
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002900/* check whether the line-input can be used as line-out */
2901static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002902{
2903 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002904 struct auto_pin_cfg *cfg = &spec->autocfg;
2905 hda_nid_t nid;
2906 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002907 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002908
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002909 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2910 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002911 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02002912 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002913 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01002914 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002915 if (pincap & AC_PINCAP_OUT)
2916 return nid;
2917 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002918 }
Matt Porter403d1942005-11-29 15:00:51 +01002919 return 0;
2920}
2921
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002922static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2923
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002924/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002925static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002926{
2927 struct sigmatel_spec *spec = codec->spec;
2928 struct auto_pin_cfg *cfg = &spec->autocfg;
2929 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02002930 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002931
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002932 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002933 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2934 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002935 for (i = 0; i < cfg->num_inputs; i++) {
2936 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02002937 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002938 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002939 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2940 /* some laptops have an internal analog microphone
2941 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002942 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002943 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002944 if (pincap & AC_PINCAP_OUT) {
2945 *dac = get_unassigned_dac(codec, nid);
2946 if (*dac)
2947 return nid;
2948 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002949 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002950 }
2951 return 0;
2952}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002953
2954static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2955{
2956 int i;
2957
2958 for (i = 0; i < spec->multiout.num_dacs; i++) {
2959 if (spec->multiout.dac_nids[i] == nid)
2960 return 1;
2961 }
2962
2963 return 0;
2964}
2965
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002966static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2967{
2968 int i;
2969 if (is_in_dac_nids(spec, nid))
2970 return 1;
2971 for (i = 0; i < spec->autocfg.hp_outs; i++)
2972 if (spec->hp_dacs[i] == nid)
2973 return 1;
2974 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2975 if (spec->speaker_dacs[i] == nid)
2976 return 1;
2977 return 0;
2978}
2979
2980static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2981{
2982 struct sigmatel_spec *spec = codec->spec;
David Henningsson48718ea2011-10-05 09:49:05 +02002983 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002984 int j, conn_len;
David Henningsson48718ea2011-10-05 09:49:05 +02002985 hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002986 unsigned int wcaps, wtype;
2987
2988 conn_len = snd_hda_get_connections(codec, nid, conn,
2989 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002990 /* 92HD88: trace back up the link of nids to find the DAC */
2991 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2992 != AC_WID_AUD_OUT)) {
2993 nid = conn[0];
2994 conn_len = snd_hda_get_connections(codec, nid, conn,
2995 HDA_MAX_CONNECTIONS);
2996 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002997 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002998 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002999 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003000 /* we check only analog outputs */
3001 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3002 continue;
3003 /* if this route has a free DAC, assign it */
3004 if (!check_all_dac_nids(spec, conn[j])) {
3005 if (conn_len > 1) {
3006 /* select this DAC in the pin's input mux */
3007 snd_hda_codec_write_cache(codec, nid, 0,
3008 AC_VERB_SET_CONNECT_SEL, j);
3009 }
3010 return conn[j];
3011 }
3012 }
David Henningsson48718ea2011-10-05 09:49:05 +02003013
3014 /* if all DACs are already assigned, connect to the primary DAC,
3015 unless we're assigning a secondary headphone */
3016 fallback_dac = spec->multiout.dac_nids[0];
3017 if (spec->multiout.hp_nid) {
3018 for (j = 0; j < cfg->hp_outs; j++)
3019 if (cfg->hp_pins[j] == nid) {
3020 fallback_dac = spec->multiout.hp_nid;
3021 break;
3022 }
3023 }
3024
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003025 if (conn_len > 1) {
3026 for (j = 0; j < conn_len; j++) {
David Henningsson48718ea2011-10-05 09:49:05 +02003027 if (conn[j] == fallback_dac) {
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003028 snd_hda_codec_write_cache(codec, nid, 0,
3029 AC_VERB_SET_CONNECT_SEL, j);
3030 break;
3031 }
3032 }
3033 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003034 return 0;
3035}
3036
3037static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3038static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3039
Matt Porter3cc08dc2006-01-23 15:27:49 +01003040/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02003041 * Fill in the dac_nids table from the parsed pin configuration
3042 * This function only works when every pin in line_out_pins[]
3043 * contains atleast one DAC in its connection list. Some 92xx
3044 * codecs are not connected directly to a DAC, such as the 9200
3045 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01003046 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003047static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003048{
3049 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003050 struct auto_pin_cfg *cfg = &spec->autocfg;
3051 int i;
3052 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02003053
Mattc7d4b2f2005-06-27 14:59:41 +02003054 for (i = 0; i < cfg->line_outs; i++) {
3055 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003056 dac = get_unassigned_dac(codec, nid);
3057 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003058 if (spec->multiout.num_dacs > 0) {
3059 /* we have already working output pins,
3060 * so let's drop the broken ones again
3061 */
3062 cfg->line_outs = spec->multiout.num_dacs;
3063 break;
3064 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003065 /* error out, no available DAC found */
3066 snd_printk(KERN_ERR
3067 "%s: No available DAC for pin 0x%x\n",
3068 __func__, nid);
3069 return -ENODEV;
3070 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003071 add_spec_dacs(spec, dac);
3072 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003073
Takashi Iwai139e0712009-03-06 12:10:41 +01003074 for (i = 0; i < cfg->hp_outs; i++) {
3075 nid = cfg->hp_pins[i];
3076 dac = get_unassigned_dac(codec, nid);
3077 if (dac) {
3078 if (!spec->multiout.hp_nid)
3079 spec->multiout.hp_nid = dac;
3080 else
3081 add_spec_extra_dacs(spec, dac);
3082 }
3083 spec->hp_dacs[i] = dac;
3084 }
3085
3086 for (i = 0; i < cfg->speaker_outs; i++) {
3087 nid = cfg->speaker_pins[i];
3088 dac = get_unassigned_dac(codec, nid);
3089 if (dac)
3090 add_spec_extra_dacs(spec, dac);
3091 spec->speaker_dacs[i] = dac;
3092 }
3093
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003094 /* add line-in as output */
3095 nid = check_line_out_switch(codec);
3096 if (nid) {
3097 dac = get_unassigned_dac(codec, nid);
3098 if (dac) {
3099 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3100 nid, cfg->line_outs);
3101 cfg->line_out_pins[cfg->line_outs] = nid;
3102 cfg->line_outs++;
3103 spec->line_switch = nid;
3104 add_spec_dacs(spec, dac);
3105 }
3106 }
3107 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003108 nid = check_mic_out_switch(codec, &dac);
3109 if (nid && dac) {
3110 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3111 nid, cfg->line_outs);
3112 cfg->line_out_pins[cfg->line_outs] = nid;
3113 cfg->line_outs++;
3114 spec->mic_switch = nid;
3115 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003116 }
3117
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003118 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003119 spec->multiout.num_dacs,
3120 spec->multiout.dac_nids[0],
3121 spec->multiout.dac_nids[1],
3122 spec->multiout.dac_nids[2],
3123 spec->multiout.dac_nids[3],
3124 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003125
Mattc7d4b2f2005-06-27 14:59:41 +02003126 return 0;
3127}
3128
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003129/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003130static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3131 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003132{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003133 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003134 char name[32];
3135 int err;
3136
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003137 if (!spec->check_volume_offset) {
3138 unsigned int caps, step, nums, db_scale;
3139 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3140 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3141 AC_AMPCAP_STEP_SIZE_SHIFT;
3142 step = (step + 1) * 25; /* in .01dB unit */
3143 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3144 AC_AMPCAP_NUM_STEPS_SHIFT;
3145 db_scale = nums * step;
3146 /* if dB scale is over -64dB, and finer enough,
3147 * let's reduce it to half
3148 */
3149 if (db_scale > 6400 && nums >= 0x1f)
3150 spec->volume_offset = nums / 2;
3151 spec->check_volume_offset = 1;
3152 }
3153
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003154 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003155 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003156 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3157 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003158 if (err < 0)
3159 return err;
3160 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003161 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003162 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3163 if (err < 0)
3164 return err;
3165 return 0;
3166}
3167
Takashi Iwai668b9652009-03-06 10:13:24 +01003168#define create_controls(codec, pfx, nid, chs) \
3169 create_controls_idx(codec, pfx, 0, nid, chs)
3170
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003171static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3172{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003173 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003174 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3175 return 1;
3176 } else {
Takashi Iwaidda14412011-05-02 11:29:30 +02003177 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3178 spec->dac_nids[spec->multiout.num_dacs] = nid;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003179 spec->multiout.num_dacs++;
3180 }
3181 return 0;
3182}
3183
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003184static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003185{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003186 int i;
3187 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3188 if (!spec->multiout.extra_out_nid[i]) {
3189 spec->multiout.extra_out_nid[i] = nid;
3190 return 0;
3191 }
3192 }
3193 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3194 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003195}
3196
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003197/* Create output controls
3198 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3199 */
3200static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3201 const hda_nid_t *pins,
3202 const hda_nid_t *dac_nids,
3203 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003204{
Takashi Iwai76624532008-12-19 10:09:47 +01003205 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaiea734962011-01-17 11:29:34 +01003206 static const char * const chname[4] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02003207 "Front", "Surround", NULL /*CLFE*/, "Side"
3208 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003209 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003210 int i, err;
3211 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003212
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003213 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003214 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003215 if (is_jack_detectable(codec, pins[i]))
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003216 spec->hp_detect = 1;
3217 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003218 nid = dac_nids[i];
3219 if (!nid)
3220 continue;
3221 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003222 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003223 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003224 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003225 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003226 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003227 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003228 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003229
3230 wid_caps = get_wcaps(codec, nid);
3231
3232 if (wid_caps & AC_WCAP_LR_SWAP) {
3233 err = stac92xx_add_control(spec,
3234 STAC_CTL_WIDGET_CLFE_SWITCH,
3235 "Swap Center/LFE Playback Switch", nid);
3236
3237 if (err < 0)
3238 return err;
3239 }
3240
Mattc7d4b2f2005-06-27 14:59:41 +02003241 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003242 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003243 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003244 switch (type) {
3245 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003246 name = "Headphone";
3247 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003248 break;
3249 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003250 name = "Speaker";
3251 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003252 break;
3253 default:
3254 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003255 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003256 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003257 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003258 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003259 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003260 return err;
3261 }
3262 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003263 return 0;
3264}
3265
Takashi Iwai6479c632009-07-28 18:20:25 +02003266static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3267 unsigned long sw, int idx)
3268{
3269 int err;
3270 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003271 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003272 if (err < 0)
3273 return err;
3274 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003275 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003276 if (err < 0)
3277 return err;
3278 return 0;
3279}
3280
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003281/* add playback controls from the parsed DAC table */
3282static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3283 const struct auto_pin_cfg *cfg)
3284{
3285 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003286 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003287 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003288 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003289
3290 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3291 spec->multiout.dac_nids,
3292 cfg->line_out_type);
3293 if (err < 0)
3294 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003295
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003296 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003297 err = stac92xx_add_control(spec,
3298 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003299 "Headphone as Line Out Switch",
3300 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003301 if (err < 0)
3302 return err;
3303 }
3304
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003305 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003306 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003307 break;
3308 nid = cfg->inputs[idx].pin;
3309 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3310 if (err < 0)
3311 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003312 }
Matt Porter403d1942005-11-29 15:00:51 +01003313
Mattc7d4b2f2005-06-27 14:59:41 +02003314 return 0;
3315}
3316
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003317/* add playback controls for Speaker and HP outputs */
3318static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3319 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003320{
3321 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003322 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003323
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003324 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3325 spec->hp_dacs, AUTO_PIN_HP_OUT);
3326 if (err < 0)
3327 return err;
3328
3329 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3330 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3331 if (err < 0)
3332 return err;
3333
Mattc7d4b2f2005-06-27 14:59:41 +02003334 return 0;
3335}
3336
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003337/* labels for mono mux outputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003338static const char * const stac92xx_mono_labels[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003339 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003340};
3341
3342/* create mono mux for mono out on capable codecs */
3343static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3344{
3345 struct sigmatel_spec *spec = codec->spec;
3346 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3347 int i, num_cons;
3348 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3349
3350 num_cons = snd_hda_get_connections(codec,
3351 spec->mono_nid,
3352 con_lst,
3353 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003354 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003355 return -EINVAL;
3356
Takashi Iwai10a20af2010-09-09 16:28:02 +02003357 for (i = 0; i < num_cons; i++)
3358 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3359 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003360
3361 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3362 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003363}
3364
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003365/* create PC beep volume controls */
3366static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3367 hda_nid_t nid)
3368{
3369 struct sigmatel_spec *spec = codec->spec;
3370 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003371 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3372
3373 if (spec->anabeep_nid == nid)
3374 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003375
3376 /* check for mute support for the the amp */
3377 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003378 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003379 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003380 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3381 if (err < 0)
3382 return err;
3383 }
3384
3385 /* check to see if there is volume support for the amp */
3386 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3387 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003388 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003389 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3390 if (err < 0)
3391 return err;
3392 }
3393 return 0;
3394}
3395
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003396#ifdef CONFIG_SND_HDA_INPUT_BEEP
3397#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3398
3399static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3400 struct snd_ctl_elem_value *ucontrol)
3401{
3402 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3403 ucontrol->value.integer.value[0] = codec->beep->enabled;
3404 return 0;
3405}
3406
3407static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3408 struct snd_ctl_elem_value *ucontrol)
3409{
3410 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003411 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003412}
3413
Takashi Iwai2b635362011-05-02 12:33:43 +02003414static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003415 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3416 .info = stac92xx_dig_beep_switch_info,
3417 .get = stac92xx_dig_beep_switch_get,
3418 .put = stac92xx_dig_beep_switch_put,
3419};
3420
3421static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3422{
3423 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003424 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003425}
3426#endif
3427
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003428static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3429{
3430 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003431 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003432
3433 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003434 hda_nid_t nid;
3435 unsigned int wcaps;
3436 unsigned long val;
3437
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003438 nid = spec->mux_nids[i];
3439 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003440 if (!(wcaps & AC_WCAP_OUT_AMP))
3441 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003442
Takashi Iwai667067d2009-08-13 18:14:42 +02003443 /* check whether already the same control was created as
3444 * normal Capture Volume.
3445 */
3446 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3447 for (j = 0; j < spec->num_caps; j++) {
3448 if (spec->capvols[j] == val)
3449 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003450 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003451 if (j < spec->num_caps)
3452 continue;
3453
3454 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3455 "Mux Capture Volume", val);
3456 if (err < 0)
3457 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003458 }
3459 return 0;
3460};
3461
Takashi Iwaiea734962011-01-17 11:29:34 +01003462static const char * const stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003463 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003464};
3465
3466static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3467{
3468 struct sigmatel_spec *spec = codec->spec;
3469 struct hda_input_mux *spdif_mux = &spec->private_smux;
Takashi Iwaiea734962011-01-17 11:29:34 +01003470 const char * const *labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003471 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003472 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003473
3474 num_cons = snd_hda_get_connections(codec,
3475 spec->smux_nids[0],
3476 con_lst,
3477 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003478 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003479 return -EINVAL;
3480
Matthew Ranostay65973632008-09-16 10:39:37 -04003481 if (!labels)
3482 labels = stac92xx_spdif_labels;
3483
Takashi Iwai10a20af2010-09-09 16:28:02 +02003484 for (i = 0; i < num_cons; i++)
3485 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003486
3487 return 0;
3488}
3489
Matt Porter8b657272006-10-26 17:12:59 +02003490/* labels for dmic mux inputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003491static const char * const stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003492 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3493 "Digital Mic 3", "Digital Mic 4"
3494};
3495
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003496static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3497 int idx)
3498{
3499 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3500 int nums;
3501 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3502 if (idx >= 0 && idx < nums)
3503 return conn[idx];
3504 return 0;
3505}
3506
Takashi Iwai8d087c72011-06-28 12:45:47 +02003507/* look for NID recursively */
3508#define get_connection_index(codec, mux, nid) \
3509 snd_hda_get_conn_index(codec, mux, nid, 1)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003510
Takashi Iwai667067d2009-08-13 18:14:42 +02003511/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003512/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003513static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003514 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003515{
3516 unsigned int caps, nums;
3517 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003518 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003519
Takashi Iwai96f845d2009-08-29 00:49:36 +02003520 if (direction == HDA_OUTPUT)
3521 caps = AC_WCAP_OUT_AMP;
3522 else
3523 caps = AC_WCAP_IN_AMP;
3524 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003525 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003526 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003527 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3528 if (!nums)
3529 return 0;
3530 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003531 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3532 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003533 if (err < 0)
3534 return err;
3535 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003536}
3537
Matt Porter8b657272006-10-26 17:12:59 +02003538/* create playback/capture controls for input pins on dmic capable codecs */
3539static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3540 const struct auto_pin_cfg *cfg)
3541{
3542 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003543 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003544 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003545 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003546 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003547
Takashi Iwai10a20af2010-09-09 16:28:02 +02003548 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003549
Matt Porter8b657272006-10-26 17:12:59 +02003550 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003551 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003552 int index, type_idx;
Takashi Iwai5207e102009-07-30 13:09:08 +02003553 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003554
Takashi Iwai667067d2009-08-13 18:14:42 +02003555 nid = spec->dmic_nids[i];
3556 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3557 continue;
3558 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003559 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3560 continue;
3561
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003562 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3563 if (index < 0)
3564 continue;
3565
Takashi Iwai10a20af2010-09-09 16:28:02 +02003566 label = hda_get_input_pin_label(codec, nid, 1);
3567 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai2d7ec122010-12-23 10:16:05 +01003568 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3569 snd_hda_add_imux_item(imux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003570
Takashi Iwai10a20af2010-09-09 16:28:02 +02003571 err = create_elem_capture_vol(codec, nid, label, type_idx,
3572 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003573 if (err < 0)
3574 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003575 if (!err) {
3576 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003577 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003578 if (err < 0)
3579 return err;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003580 if (!err) {
3581 nid = get_connected_node(codec,
3582 spec->dmux_nids[0], index);
3583 if (nid)
3584 err = create_elem_capture_vol(codec,
3585 nid, label,
3586 type_idx, HDA_INPUT);
3587 if (err < 0)
3588 return err;
3589 }
Takashi Iwai96f845d2009-08-29 00:49:36 +02003590 }
Matt Porter8b657272006-10-26 17:12:59 +02003591 }
3592
3593 return 0;
3594}
3595
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003596static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003597 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003598{
3599 unsigned int cfg;
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003600 unsigned int type;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003601
3602 if (!nid)
3603 return 0;
3604 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003605 type = get_defcfg_device(cfg);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003606 switch (snd_hda_get_input_pin_attr(cfg)) {
3607 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003608 if (*fixed)
3609 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003610 if (type != AC_JACK_MIC_IN)
3611 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003612 *fixed = nid;
3613 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003614 case INPUT_PIN_ATTR_UNUSED:
3615 break;
3616 case INPUT_PIN_ATTR_DOCK:
3617 if (*dock)
3618 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003619 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
3620 return 1; /* invalid type */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003621 *dock = nid;
3622 break;
3623 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003624 if (*ext)
3625 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003626 if (type != AC_JACK_MIC_IN)
3627 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003628 *ext = nid;
3629 break;
3630 }
3631 return 0;
3632}
3633
3634static int set_mic_route(struct hda_codec *codec,
3635 struct sigmatel_mic_route *mic,
3636 hda_nid_t pin)
3637{
3638 struct sigmatel_spec *spec = codec->spec;
3639 struct auto_pin_cfg *cfg = &spec->autocfg;
3640 int i;
3641
3642 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003643 if (pin == 0)
3644 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003645 for (i = 0; i < cfg->num_inputs; i++) {
3646 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003647 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003648 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003649 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003650 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003651 i = get_connection_index(codec, spec->mux_nids[0], pin);
3652 if (i < 0)
3653 return -1;
3654 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003655 mic->dmux_idx = -1;
3656 if (spec->dmux_nids)
3657 mic->dmux_idx = get_connection_index(codec,
3658 spec->dmux_nids[0],
3659 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003660 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003661 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003662 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3663 if (i < 0)
3664 return -1;
3665 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003666 mic->mux_idx = -1;
3667 if (spec->mux_nids)
3668 mic->mux_idx = get_connection_index(codec,
3669 spec->mux_nids[0],
3670 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003671 }
3672 return 0;
3673}
3674
3675/* return non-zero if the device is for automatic mic switch */
3676static int stac_check_auto_mic(struct hda_codec *codec)
3677{
3678 struct sigmatel_spec *spec = codec->spec;
3679 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02003680 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003681 int i;
3682
Charles Chin99077902010-09-17 10:22:32 +02003683 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003684 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02003685 if (check_mic_pin(codec, cfg->inputs[i].pin,
3686 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003687 return 0;
3688 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02003689 if (check_mic_pin(codec, spec->dmic_nids[i],
3690 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003691 return 0;
Takashi Iwai80c67852011-01-13 08:08:08 +01003692 if (!fixed || (!ext && !dock))
Charles Chin99077902010-09-17 10:22:32 +02003693 return 0; /* no input to switch */
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003694 if (!is_jack_detectable(codec, ext))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003695 return 0; /* no unsol support */
3696 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02003697 set_mic_route(codec, &spec->int_mic, fixed) ||
3698 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003699 return 0; /* something is wrong */
3700 return 1;
3701}
3702
Mattc7d4b2f2005-06-27 14:59:41 +02003703/* create playback/capture controls for input pins */
3704static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3705{
3706 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003707 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003708 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003709 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02003710
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003711 for (i = 0; i < cfg->num_inputs; i++) {
3712 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003713 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02003714
Takashi Iwai314634b2006-09-21 11:56:18 +02003715 index = -1;
3716 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003717 index = get_connection_index(codec, spec->mux_nids[j],
3718 nid);
3719 if (index >= 0)
3720 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003721 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003722 if (index < 0)
3723 continue;
3724
Takashi Iwai10a20af2010-09-09 16:28:02 +02003725 label = hda_get_autocfg_input_label(codec, cfg, i);
3726 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003727
Takashi Iwai667067d2009-08-13 18:14:42 +02003728 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003729 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003730 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003731 if (err < 0)
3732 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003733 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003734 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003735
Steve Longerbeam7b043892007-05-03 20:50:03 +02003736 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003737 /*
3738 * Set the current input for the muxes.
3739 * The STAC9221 has two input muxes with identical source
3740 * NID lists. Hopefully this won't get confused.
3741 */
3742 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003743 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3744 AC_VERB_SET_CONNECT_SEL,
3745 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003746 }
3747 }
3748
Mattc7d4b2f2005-06-27 14:59:41 +02003749 return 0;
3750}
3751
Mattc7d4b2f2005-06-27 14:59:41 +02003752static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3753{
3754 struct sigmatel_spec *spec = codec->spec;
3755 int i;
3756
3757 for (i = 0; i < spec->autocfg.line_outs; i++) {
3758 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3759 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3760 }
3761}
3762
3763static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3764{
3765 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003766 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003767
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003768 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3769 hda_nid_t pin;
3770 pin = spec->autocfg.hp_pins[i];
3771 if (pin) /* connect to front */
3772 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3773 }
3774 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3775 hda_nid_t pin;
3776 pin = spec->autocfg.speaker_pins[i];
3777 if (pin) /* connect to front */
3778 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3779 }
Mattc7d4b2f2005-06-27 14:59:41 +02003780}
3781
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003782static int is_dual_headphones(struct hda_codec *codec)
3783{
3784 struct sigmatel_spec *spec = codec->spec;
3785 int i, valid_hps;
3786
3787 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3788 spec->autocfg.hp_outs <= 1)
3789 return 0;
3790 valid_hps = 0;
3791 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3792 hda_nid_t nid = spec->autocfg.hp_pins[i];
3793 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3794 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3795 continue;
3796 valid_hps++;
3797 }
3798 return (valid_hps > 1);
3799}
3800
3801
Charles Chin9009b0e2011-11-03 10:27:27 +01003802static int stac92xx_parse_auto_config(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003803{
3804 struct sigmatel_spec *spec = codec->spec;
Charles Chin9009b0e2011-11-03 10:27:27 +01003805 hda_nid_t dig_out = 0, dig_in = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003806 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003807 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003808
Matt Porter8b657272006-10-26 17:12:59 +02003809 if ((err = snd_hda_parse_pin_def_config(codec,
3810 &spec->autocfg,
3811 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003812 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003813 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003814 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003815
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003816 /* If we have no real line-out pin and multiple hp-outs, HPs should
3817 * be set up as multi-channel outputs.
3818 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003819 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003820 /* Copy hp_outs to line_outs, backup line_outs in
3821 * speaker_outs so that the following routines can handle
3822 * HP pins as primary outputs.
3823 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003824 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003825 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3826 sizeof(spec->autocfg.line_out_pins));
3827 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3828 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3829 sizeof(spec->autocfg.hp_pins));
3830 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003831 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3832 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003833 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003834 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003835 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003836 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3837 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003838 u32 caps = query_amp_caps(codec,
3839 spec->autocfg.mono_out_pin, dir);
3840 hda_nid_t conn_list[1];
3841
3842 /* get the mixer node and then the mono mux if it exists */
3843 if (snd_hda_get_connections(codec,
3844 spec->autocfg.mono_out_pin, conn_list, 1) &&
3845 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003846 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003847
3848 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003849 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003850 /* LR swap check, some stac925x have a mux that
3851 * changes the DACs output path instead of the
3852 * mono-mux path.
3853 */
3854 if (wid_type == AC_WID_AUD_SEL &&
3855 !(wcaps & AC_WCAP_LR_SWAP))
3856 spec->mono_nid = conn_list[0];
3857 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003858 if (dir) {
3859 hda_nid_t nid = spec->autocfg.mono_out_pin;
3860
3861 /* most mono outs have a least a mute/unmute switch */
3862 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3863 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3864 "Mono Playback Switch",
3865 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003866 if (err < 0)
3867 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003868 /* check for volume support for the amp */
3869 if ((caps & AC_AMPCAP_NUM_STEPS)
3870 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3871 err = stac92xx_add_control(spec,
3872 STAC_CTL_WIDGET_VOL,
3873 "Mono Playback Volume",
3874 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3875 if (err < 0)
3876 return err;
3877 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003878 }
3879
3880 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3881 AC_PINCTL_OUT_EN);
3882 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003883
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003884 if (!spec->multiout.num_dacs) {
3885 err = stac92xx_auto_fill_dac_nids(codec);
3886 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003887 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003888 err = stac92xx_auto_create_multi_out_ctls(codec,
3889 &spec->autocfg);
3890 if (err < 0)
3891 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003892 }
Mattc7d4b2f2005-06-27 14:59:41 +02003893
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003894 /* setup analog beep controls */
3895 if (spec->anabeep_nid > 0) {
3896 err = stac92xx_auto_create_beep_ctls(codec,
3897 spec->anabeep_nid);
3898 if (err < 0)
3899 return err;
3900 }
3901
3902 /* setup digital beep controls and input device */
3903#ifdef CONFIG_SND_HDA_INPUT_BEEP
3904 if (spec->digbeep_nid > 0) {
3905 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003906 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003907
3908 err = stac92xx_auto_create_beep_ctls(codec, nid);
3909 if (err < 0)
3910 return err;
3911 err = snd_hda_attach_beep_device(codec, nid);
3912 if (err < 0)
3913 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003914 if (codec->beep) {
3915 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01003916 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003917 /* if no beep switch is available, make its own one */
3918 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3919 if (!(caps & AC_AMPCAP_MUTE)) {
3920 err = stac92xx_beep_switch_ctl(codec);
3921 if (err < 0)
3922 return err;
3923 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003924 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003925 }
3926#endif
3927
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003928 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003929 if (err < 0)
3930 return err;
3931
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003932 /* All output parsing done, now restore the swapped hp pins */
3933 if (hp_swap) {
3934 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3935 sizeof(spec->autocfg.hp_pins));
3936 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3937 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3938 spec->autocfg.line_outs = 0;
3939 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003940
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003941 if (stac_check_auto_mic(codec)) {
3942 spec->auto_mic = 1;
3943 /* only one capture for auto-mic */
3944 spec->num_adcs = 1;
3945 spec->num_caps = 1;
3946 spec->num_muxes = 1;
3947 }
3948
Takashi Iwai6479c632009-07-28 18:20:25 +02003949 for (i = 0; i < spec->num_caps; i++) {
3950 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3951 spec->capsws[i], i);
3952 if (err < 0)
3953 return err;
3954 }
3955
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003956 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003957 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003958 return err;
3959
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003960 if (spec->mono_nid > 0) {
3961 err = stac92xx_auto_create_mono_output_ctls(codec);
3962 if (err < 0)
3963 return err;
3964 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003965 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003966 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3967 &spec->autocfg)) < 0)
3968 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003969 if (spec->num_muxes > 0) {
3970 err = stac92xx_auto_create_mux_input_ctls(codec);
3971 if (err < 0)
3972 return err;
3973 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003974 if (spec->num_smuxes > 0) {
3975 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3976 if (err < 0)
3977 return err;
3978 }
Matt Porter8b657272006-10-26 17:12:59 +02003979
Takashi Iwaie3c75962009-01-23 11:57:22 +01003980 err = stac92xx_add_input_source(spec);
3981 if (err < 0)
3982 return err;
3983
Mattc7d4b2f2005-06-27 14:59:41 +02003984 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003985 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003986 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003987
Charles Chin9009b0e2011-11-03 10:27:27 +01003988 /* find digital out and in converters */
3989 for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
3990 unsigned int wid_caps = get_wcaps(codec, i);
3991 if (wid_caps & AC_WCAP_DIGITAL) {
3992 switch (get_wcaps_type(wid_caps)) {
3993 case AC_WID_AUD_OUT:
3994 if (!dig_out)
3995 dig_out = i;
3996 break;
3997 case AC_WID_AUD_IN:
3998 if (!dig_in)
3999 dig_in = i;
4000 break;
4001 }
4002 }
4003 }
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004004 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004005 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004006 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004007 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02004008
Takashi Iwai603c4012008-07-30 15:01:44 +02004009 if (spec->kctls.list)
4010 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004011
4012 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05004013 if (!spec->dinput_mux)
4014 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004015 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01004016 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02004017 return 1;
4018}
4019
Takashi Iwai82bc9552006-03-21 11:24:42 +01004020/* add playback controls for HP output */
4021static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4022 struct auto_pin_cfg *cfg)
4023{
4024 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004025 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01004026
4027 if (! pin)
4028 return 0;
4029
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004030 if (is_jack_detectable(codec, pin))
Takashi Iwai82bc9552006-03-21 11:24:42 +01004031 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004032
4033 return 0;
4034}
4035
Richard Fish160ea0d2006-09-06 13:58:25 +02004036/* add playback controls for LFE output */
4037static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4038 struct auto_pin_cfg *cfg)
4039{
4040 struct sigmatel_spec *spec = codec->spec;
4041 int err;
4042 hda_nid_t lfe_pin = 0x0;
4043 int i;
4044
4045 /*
4046 * search speaker outs and line outs for a mono speaker pin
4047 * with an amp. If one is found, add LFE controls
4048 * for it.
4049 */
4050 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4051 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004052 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004053 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4054 if (wcaps == AC_WCAP_OUT_AMP)
4055 /* found a mono speaker with an amp, must be lfe */
4056 lfe_pin = pin;
4057 }
4058
4059 /* if speaker_outs is 0, then speakers may be in line_outs */
4060 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4061 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4062 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004063 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004064 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004065 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004066 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004067 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4068 if (wcaps == AC_WCAP_OUT_AMP)
4069 /* found a mono speaker with an amp,
4070 must be lfe */
4071 lfe_pin = pin;
4072 }
4073 }
4074 }
4075
4076 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004077 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004078 if (err < 0)
4079 return err;
4080 }
4081
4082 return 0;
4083}
4084
Mattc7d4b2f2005-06-27 14:59:41 +02004085static int stac9200_parse_auto_config(struct hda_codec *codec)
4086{
4087 struct sigmatel_spec *spec = codec->spec;
4088 int err;
4089
Kailang Yangdf694da2005-12-05 19:42:22 +01004090 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004091 return err;
4092
4093 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4094 return err;
4095
Takashi Iwai82bc9552006-03-21 11:24:42 +01004096 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4097 return err;
4098
Richard Fish160ea0d2006-09-06 13:58:25 +02004099 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4100 return err;
4101
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004102 if (spec->num_muxes > 0) {
4103 err = stac92xx_auto_create_mux_input_ctls(codec);
4104 if (err < 0)
4105 return err;
4106 }
4107
Takashi Iwaie3c75962009-01-23 11:57:22 +01004108 err = stac92xx_add_input_source(spec);
4109 if (err < 0)
4110 return err;
4111
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004112 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004113 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004114 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004115 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004116
Takashi Iwai603c4012008-07-30 15:01:44 +02004117 if (spec->kctls.list)
4118 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004119
4120 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004121 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004122
4123 return 1;
4124}
4125
Sam Revitch62fe78e2006-05-10 15:09:17 +02004126/*
4127 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4128 * funky external mute control using GPIO pins.
4129 */
4130
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004131static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004132 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004133{
4134 unsigned int gpiostate, gpiomask, gpiodir;
4135
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004136 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4137
Sam Revitch62fe78e2006-05-10 15:09:17 +02004138 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4139 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004140 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004141
4142 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4143 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004144 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004145
4146 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4147 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004148 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004149
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004150 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004151 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4152
4153 snd_hda_codec_write(codec, codec->afg, 0,
4154 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004155 snd_hda_codec_read(codec, codec->afg, 0,
4156 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004157
4158 msleep(1);
4159
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004160 snd_hda_codec_read(codec, codec->afg, 0,
4161 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004162}
4163
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004164static int stac92xx_add_jack(struct hda_codec *codec,
4165 hda_nid_t nid, int type)
4166{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004167#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai330ee992009-02-20 14:33:36 +01004168 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004169 int connectivity = get_defcfg_connect(def_conf);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004170
4171 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4172 return 0;
4173
David Henningssoneb335a42011-10-03 16:25:42 +02004174 return snd_hda_input_jack_add(codec, nid, type, NULL);
4175#else
Takashi Iwai95c09092009-04-14 16:15:29 +02004176 return 0;
David Henningssoneb335a42011-10-03 16:25:42 +02004177#endif /* CONFIG_SND_HDA_INPUT_JACK */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004178}
4179
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004180static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4181 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004182{
4183 struct sigmatel_event *event;
4184
4185 snd_array_init(&spec->events, sizeof(*event), 32);
4186 event = snd_array_new(&spec->events);
4187 if (!event)
4188 return -ENOMEM;
4189 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004190 event->type = type;
4191 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004192 event->data = data;
4193
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004194 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004195}
4196
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004197static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004198 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004199{
4200 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004201 struct sigmatel_event *event = spec->events.list;
4202 int i;
4203
4204 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004205 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004206 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004207 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004208 return NULL;
4209}
4210
4211static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4212 unsigned char tag)
4213{
4214 struct sigmatel_spec *spec = codec->spec;
4215 struct sigmatel_event *event = spec->events.list;
4216 int i;
4217
4218 for (i = 0; i < spec->events.used; i++, event++) {
4219 if (event->tag == tag)
4220 return event;
4221 }
4222 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004223}
4224
Takashi Iwai62558ce2009-07-29 14:23:09 +02004225/* check if given nid is a valid pin and no other events are assigned
4226 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4227 * Otherwise, returns zero.
4228 */
4229static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4230 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004231{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004232 struct sigmatel_event *event;
4233 int tag;
4234
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004235 if (!is_jack_detectable(codec, nid))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004236 return 0;
4237 event = stac_get_event(codec, nid);
4238 if (event) {
4239 if (event->type != type)
4240 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004241 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004242 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004243 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004244 if (tag < 0)
4245 return 0;
4246 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004247 snd_hda_codec_write_cache(codec, nid, 0,
4248 AC_VERB_SET_UNSOLICITED_ENABLE,
4249 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004250 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004251}
4252
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004253static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4254{
4255 int i;
4256 for (i = 0; i < cfg->hp_outs; i++)
4257 if (cfg->hp_pins[i] == nid)
4258 return 1; /* nid is a HP-Out */
4259
4260 return 0; /* nid is not a HP-Out */
4261};
4262
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004263static void stac92xx_power_down(struct hda_codec *codec)
4264{
4265 struct sigmatel_spec *spec = codec->spec;
4266
4267 /* power down inactive DACs */
Takashi Iwai2b635362011-05-02 12:33:43 +02004268 const hda_nid_t *dac;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004269 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004270 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004271 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004272 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4273}
4274
Takashi Iwaif73d3582008-11-25 08:21:51 +01004275static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4276 int enable);
4277
Takashi Iwai014c41f2009-12-27 13:53:24 +01004278static inline int get_int_hint(struct hda_codec *codec, const char *key,
4279 int *valp)
4280{
4281 const char *p;
4282 p = snd_hda_get_hint(codec, key);
4283 if (p) {
4284 unsigned long val;
4285 if (!strict_strtoul(p, 0, &val)) {
4286 *valp = val;
4287 return 1;
4288 }
4289 }
4290 return 0;
4291}
4292
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004293/* override some hints from the hwdep entry */
4294static void stac_store_hints(struct hda_codec *codec)
4295{
4296 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004297 int val;
4298
4299 val = snd_hda_get_bool_hint(codec, "hp_detect");
4300 if (val >= 0)
4301 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004302 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004303 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4304 spec->gpio_mask;
4305 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004306 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4307 spec->gpio_mask &= spec->gpio_mask;
4308 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4309 spec->gpio_dir &= spec->gpio_mask;
4310 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4311 spec->eapd_mask &= spec->gpio_mask;
4312 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4313 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004314 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4315 if (val >= 0)
4316 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004317 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4318 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004319 if (spec->gpio_led <= 8) {
4320 spec->gpio_mask |= spec->gpio_led;
4321 spec->gpio_dir |= spec->gpio_led;
4322 if (spec->gpio_led_polarity)
4323 spec->gpio_data |= spec->gpio_led;
4324 }
Takashi Iwai043958e2009-12-26 10:36:12 +01004325 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004326}
4327
Mattc7d4b2f2005-06-27 14:59:41 +02004328static int stac92xx_init(struct hda_codec *codec)
4329{
4330 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004331 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004332 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004333 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004334
Mattc7d4b2f2005-06-27 14:59:41 +02004335 snd_hda_sequence_write(codec, spec->init);
4336
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004337 /* power down adcs initially */
4338 if (spec->powerdown_adcs)
4339 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004340 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004341 spec->adc_nids[i], 0,
4342 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004343
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004344 /* override some hints */
4345 stac_store_hints(codec);
4346
Takashi Iwaif73d3582008-11-25 08:21:51 +01004347 /* set up GPIO */
4348 gpio = spec->gpio_data;
4349 /* turn on EAPD statically when spec->eapd_switch isn't set.
4350 * otherwise, unsol event will turn it on/off dynamically
4351 */
4352 if (!spec->eapd_switch)
4353 gpio |= spec->eapd_mask;
4354 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4355
Takashi Iwai82bc9552006-03-21 11:24:42 +01004356 /* set up pins */
4357 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004358 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004359 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004360 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004361 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004362 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004363 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4364 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004365 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004366 for (i = 0; i < cfg->line_outs; i++) {
4367 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004368 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4369 }
4370 }
4371
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004372 /* force to enable the first line-out; the others are set up
4373 * in unsol_event
4374 */
4375 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004376 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004377 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004378 if (cfg->hp_pins[0])
4379 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4380 else if (cfg->line_out_pins[0])
4381 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004382 } else {
4383 stac92xx_auto_init_multi_out(codec);
4384 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004385 for (i = 0; i < cfg->hp_outs; i++)
4386 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004387 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004388 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004389 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004390 if (spec->dmux_nids)
4391 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004392 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004393 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4394 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004395 if (enable_pin_detect(codec, spec->dock_mic.pin,
4396 STAC_MIC_EVENT))
4397 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004398 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004399 for (i = 0; i < cfg->num_inputs; i++) {
4400 hda_nid_t nid = cfg->inputs[i].pin;
4401 int type = cfg->inputs[i].type;
4402 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004403 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004404 /* for mic pins, force to initialize */
4405 pinctl = stac92xx_get_default_vref(codec, nid);
4406 pinctl |= AC_PINCTL_IN_EN;
4407 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4408 } else {
4409 pinctl = snd_hda_codec_read(codec, nid, 0,
4410 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4411 /* if PINCTL already set then skip */
4412 /* Also, if both INPUT and OUTPUT are set,
4413 * it must be a BIOS bug; need to override, too
4414 */
4415 if (!(pinctl & AC_PINCTL_IN_EN) ||
4416 (pinctl & AC_PINCTL_OUT_EN)) {
4417 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004418 pinctl |= AC_PINCTL_IN_EN;
4419 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004420 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004421 }
4422 conf = snd_hda_codec_get_pincfg(codec, nid);
4423 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4424 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4425 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004426 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004427 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004428 for (i = 0; i < spec->num_dmics; i++)
4429 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4430 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004431 if (cfg->dig_out_pins[0])
4432 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004433 AC_PINCTL_OUT_EN);
4434 if (cfg->dig_in_pin)
4435 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4436 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004437 for (i = 0; i < spec->num_pwrs; i++) {
4438 hda_nid_t nid = spec->pwr_nids[i];
4439 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004440
Takashi Iwaieb632122008-12-19 16:39:48 +01004441 /* power on when no jack detection is available */
4442 if (!spec->hp_detect) {
4443 stac_toggle_power_map(codec, nid, 1);
4444 continue;
4445 }
4446
4447 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004448 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004449
Takashi Iwaif73d3582008-11-25 08:21:51 +01004450 pinctl = snd_hda_codec_read(codec, nid, 0,
4451 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4452 /* outputs are only ports capable of power management
4453 * any attempts on powering down a input port cause the
4454 * referenced VREF to act quirky.
4455 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004456 if (pinctl & AC_PINCTL_IN_EN) {
4457 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004458 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004459 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004460 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004461 def_conf = get_defcfg_connect(def_conf);
4462 /* skip any ports that don't have jacks since presence
4463 * detection is useless */
4464 if (def_conf != AC_JACK_PORT_COMPLEX) {
4465 if (def_conf != AC_JACK_PORT_NONE)
4466 stac_toggle_power_map(codec, nid, 1);
4467 continue;
4468 }
Charles Chinafef2cf2011-11-11 08:05:28 +01004469 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004470 stac_issue_unsol_event(codec, nid);
Charles Chinafef2cf2011-11-11 08:05:28 +01004471 continue;
4472 }
4473 /* none of the above, turn the port OFF */
4474 stac_toggle_power_map(codec, nid, 0);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004475 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004476
Takashi Iwaic21bd022010-02-08 15:16:08 +01004477 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004478 if (spec->gpio_led)
4479 hda_call_check_power_status(codec, 0x01);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004480 if (spec->dac_list)
4481 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004482 return 0;
4483}
4484
Takashi Iwai603c4012008-07-30 15:01:44 +02004485static void stac92xx_free_kctls(struct hda_codec *codec)
4486{
4487 struct sigmatel_spec *spec = codec->spec;
4488
4489 if (spec->kctls.list) {
4490 struct snd_kcontrol_new *kctl = spec->kctls.list;
4491 int i;
4492 for (i = 0; i < spec->kctls.used; i++)
4493 kfree(kctl[i].name);
4494 }
4495 snd_array_free(&spec->kctls);
4496}
4497
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004498static void stac92xx_shutup_pins(struct hda_codec *codec)
4499{
4500 unsigned int i, def_conf;
4501
4502 if (codec->bus->shutdown)
4503 return;
4504 for (i = 0; i < codec->init_pins.used; i++) {
4505 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4506 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4507 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
4508 snd_hda_codec_write(codec, pin->nid, 0,
4509 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4510 }
4511}
4512
Takashi Iwai167eae52009-11-06 15:47:50 +01004513static void stac92xx_shutup(struct hda_codec *codec)
4514{
4515 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004516
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004517 stac92xx_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004518
4519 if (spec->eapd_mask)
4520 stac_gpio_set(codec, spec->gpio_mask,
4521 spec->gpio_dir, spec->gpio_data &
4522 ~spec->eapd_mask);
4523}
4524
Matt2f2f4252005-04-13 14:45:30 +02004525static void stac92xx_free(struct hda_codec *codec)
4526{
Mattc7d4b2f2005-06-27 14:59:41 +02004527 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004528
4529 if (! spec)
4530 return;
4531
Takashi Iwai167eae52009-11-06 15:47:50 +01004532 stac92xx_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004533 snd_hda_input_jack_free(codec);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004534 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004535
Mattc7d4b2f2005-06-27 14:59:41 +02004536 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004537 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004538}
4539
Matt4e550962005-07-04 17:51:39 +02004540static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4541 unsigned int flag)
4542{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004543 unsigned int old_ctl, pin_ctl;
4544
4545 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004546 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004547
Takashi Iwaif9acba42007-05-29 18:01:06 +02004548 if (pin_ctl & AC_PINCTL_IN_EN) {
4549 /*
4550 * we need to check the current set-up direction of
4551 * shared input pins since they can be switched via
4552 * "xxx as Output" mixer switch
4553 */
4554 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004555 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004556 return;
4557 }
4558
Takashi Iwai8ce84192009-01-22 16:59:20 +01004559 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004560 /* if setting pin direction bits, clear the current
4561 direction bits first */
4562 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4563 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4564
Takashi Iwai8ce84192009-01-22 16:59:20 +01004565 pin_ctl |= flag;
4566 if (old_ctl != pin_ctl)
4567 snd_hda_codec_write_cache(codec, nid, 0,
4568 AC_VERB_SET_PIN_WIDGET_CONTROL,
4569 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004570}
4571
4572static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4573 unsigned int flag)
4574{
4575 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4576 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004577 if (pin_ctl & flag)
4578 snd_hda_codec_write_cache(codec, nid, 0,
4579 AC_VERB_SET_PIN_WIDGET_CONTROL,
4580 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004581}
4582
Takashi Iwaid56757a2009-11-18 08:00:14 +01004583static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004584{
4585 if (!nid)
4586 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004587 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004588}
4589
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004590static void stac92xx_line_out_detect(struct hda_codec *codec,
4591 int presence)
4592{
4593 struct sigmatel_spec *spec = codec->spec;
4594 struct auto_pin_cfg *cfg = &spec->autocfg;
4595 int i;
4596
4597 for (i = 0; i < cfg->line_outs; i++) {
4598 if (presence)
4599 break;
4600 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4601 if (presence) {
4602 unsigned int pinctl;
4603 pinctl = snd_hda_codec_read(codec,
4604 cfg->line_out_pins[i], 0,
4605 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4606 if (pinctl & AC_PINCTL_IN_EN)
4607 presence = 0; /* mic- or line-input */
4608 }
4609 }
4610
4611 if (presence) {
4612 /* disable speakers */
4613 for (i = 0; i < cfg->speaker_outs; i++)
4614 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4615 AC_PINCTL_OUT_EN);
4616 if (spec->eapd_mask && spec->eapd_switch)
4617 stac_gpio_set(codec, spec->gpio_mask,
4618 spec->gpio_dir, spec->gpio_data &
4619 ~spec->eapd_mask);
4620 } else {
4621 /* enable speakers */
4622 for (i = 0; i < cfg->speaker_outs; i++)
4623 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4624 AC_PINCTL_OUT_EN);
4625 if (spec->eapd_mask && spec->eapd_switch)
4626 stac_gpio_set(codec, spec->gpio_mask,
4627 spec->gpio_dir, spec->gpio_data |
4628 spec->eapd_mask);
4629 }
4630}
4631
Takashi Iwaid7a89432008-11-12 09:48:04 +01004632/* return non-zero if the hp-pin of the given array index isn't
4633 * a jack-detection target
4634 */
4635static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4636{
4637 struct auto_pin_cfg *cfg = &spec->autocfg;
4638
4639 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004640 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004641 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004642 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004643 return 1;
4644 /* ignore if the pin is set as line-out */
4645 if (cfg->hp_pins[i] == spec->hp_switch)
4646 return 1;
4647 return 0;
4648}
4649
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004650static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004651{
4652 struct sigmatel_spec *spec = codec->spec;
4653 struct auto_pin_cfg *cfg = &spec->autocfg;
4654 int i, presence;
4655
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004656 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004657 if (spec->gpio_mute)
4658 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4659 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4660
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004661 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004662 if (presence)
4663 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004664 if (no_hp_sensing(spec, i))
4665 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004666 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4667 if (presence) {
4668 unsigned int pinctl;
4669 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4670 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4671 if (pinctl & AC_PINCTL_IN_EN)
4672 presence = 0; /* mic- or line-input */
4673 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004674 }
Matt4e550962005-07-04 17:51:39 +02004675
4676 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004677 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004678 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004679 stac92xx_reset_pinctl(codec, spec->hp_switch,
4680 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004681 for (i = 0; i < cfg->line_outs; i++)
4682 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4683 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004684 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004685 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004686 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004687 stac92xx_set_pinctl(codec, spec->hp_switch,
4688 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004689 for (i = 0; i < cfg->line_outs; i++)
4690 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4691 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004692 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004693 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004694 /* toggle hp outs */
4695 for (i = 0; i < cfg->hp_outs; i++) {
4696 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4697 if (no_hp_sensing(spec, i))
4698 continue;
4699 if (presence)
4700 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004701#if 0 /* FIXME */
4702/* Resetting the pinctl like below may lead to (a sort of) regressions
4703 * on some devices since they use the HP pin actually for line/speaker
4704 * outs although the default pin config shows a different pin (that is
4705 * wrong and useless).
4706 *
4707 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4708 * But, disabling the code below just works around it, and I'm too tired of
4709 * bug reports with such devices...
4710 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004711 else
4712 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004713#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004714 }
Matt4e550962005-07-04 17:51:39 +02004715}
4716
Takashi Iwaif73d3582008-11-25 08:21:51 +01004717static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4718 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004719{
4720 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004721 unsigned int idx, val;
4722
4723 for (idx = 0; idx < spec->num_pwrs; idx++) {
4724 if (spec->pwr_nids[idx] == nid)
4725 break;
4726 }
4727 if (idx >= spec->num_pwrs)
4728 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004729
Charles Chinafef2cf2011-11-11 08:05:28 +01004730 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004731
Takashi Iwaif73d3582008-11-25 08:21:51 +01004732 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4733 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004734 val &= ~idx;
4735 else
4736 val |= idx;
4737
4738 /* power down unused output ports */
4739 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004740}
4741
Takashi Iwaif73d3582008-11-25 08:21:51 +01004742static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4743{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004744 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004745}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004746
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004747/* get the pin connection (fixed, none, etc) */
4748static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4749{
4750 struct sigmatel_spec *spec = codec->spec;
4751 unsigned int cfg;
4752
4753 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4754 return get_defcfg_connect(cfg);
4755}
4756
4757static int stac92xx_connected_ports(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02004758 const hda_nid_t *nids, int num_nids)
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004759{
4760 struct sigmatel_spec *spec = codec->spec;
4761 int idx, num;
4762 unsigned int def_conf;
4763
4764 for (num = 0; num < num_nids; num++) {
4765 for (idx = 0; idx < spec->num_pins; idx++)
4766 if (spec->pin_nids[idx] == nids[num])
4767 break;
4768 if (idx >= spec->num_pins)
4769 break;
4770 def_conf = stac_get_defcfg_connect(codec, idx);
4771 if (def_conf == AC_JACK_PORT_NONE)
4772 break;
4773 }
4774 return num;
4775}
4776
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004777static void stac92xx_mic_detect(struct hda_codec *codec)
4778{
4779 struct sigmatel_spec *spec = codec->spec;
4780 struct sigmatel_mic_route *mic;
4781
4782 if (get_pin_presence(codec, spec->ext_mic.pin))
4783 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02004784 else if (get_pin_presence(codec, spec->dock_mic.pin))
4785 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004786 else
4787 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004788 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004789 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4790 AC_VERB_SET_CONNECT_SEL,
4791 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004792 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004793 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4794 AC_VERB_SET_CONNECT_SEL,
4795 mic->mux_idx);
4796}
4797
Takashi Iwai62558ce2009-07-29 14:23:09 +02004798static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004799{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004800 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004801 if (!event)
4802 return;
4803 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4804}
4805
Takashi Iwai314634b2006-09-21 11:56:18 +02004806static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4807{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004808 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004809 struct sigmatel_event *event;
4810 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004811
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004812 tag = (res >> 26) & 0x7f;
4813 event = stac_get_event_from_tag(codec, tag);
4814 if (!event)
4815 return;
4816
4817 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004818 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004819 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004820 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004821 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004822 case STAC_MIC_EVENT:
4823 stac92xx_mic_detect(codec);
4824 break;
4825 }
4826
4827 switch (event->type) {
4828 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004829 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004830 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004831 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004832 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004833 if (spec->num_pwrs > 0)
4834 stac92xx_pin_sense(codec, event->nid);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004835 snd_hda_input_jack_report(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004836
4837 switch (codec->subsystem_id) {
4838 case 0x103c308f:
4839 if (event->nid == 0xb) {
4840 int pin = AC_PINCTL_IN_EN;
4841
4842 if (get_pin_presence(codec, 0xa)
4843 && get_pin_presence(codec, 0xb))
4844 pin |= AC_PINCTL_VREF_80;
4845 if (!get_pin_presence(codec, 0xb))
4846 pin |= AC_PINCTL_VREF_80;
4847
4848 /* toggle VREF state based on mic + hp pin
4849 * status
4850 */
4851 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4852 }
4853 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004854 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004855 case STAC_VREF_EVENT:
4856 data = snd_hda_codec_read(codec, codec->afg, 0,
4857 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004858 /* toggle VREF state based on GPIOx status */
4859 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004860 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004861 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004862 }
4863}
4864
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304865static int hp_blike_system(u32 subsystem_id);
4866
4867static void set_hp_led_gpio(struct hda_codec *codec)
4868{
4869 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004870 unsigned int gpio;
4871
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004872 if (spec->gpio_led)
4873 return;
4874
Takashi Iwai07f80442010-02-08 15:06:13 +01004875 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4876 gpio &= AC_GPIO_IO_COUNT;
4877 if (gpio > 3)
4878 spec->gpio_led = 0x08; /* GPIO 3 */
4879 else
4880 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304881}
4882
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004883/*
4884 * This method searches for the mute LED GPIO configuration
4885 * provided as OEM string in SMBIOS. The format of that string
4886 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4887 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4888 * that corresponds to the NOT muted state of the master volume
4889 * and G is the index of the GPIO to use as the mute LED control (0..9)
4890 * If _G portion is missing it is assigned based on the codec ID
4891 *
4892 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4893 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304894 *
4895 *
4896 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4897 * SMBIOS - at least the ones I have seen do not have them - which include
4898 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4899 * HP Pavilion dv9500t CTO.
4900 * Need more information on whether it is true across the entire series.
4901 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004902 */
Takashi Iwaidce17d42010-02-09 09:25:26 +01004903static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004904{
4905 struct sigmatel_spec *spec = codec->spec;
4906 const struct dmi_device *dev = NULL;
4907
4908 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4909 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4910 NULL, dev))) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004911 if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304912 &spec->gpio_led_polarity,
4913 &spec->gpio_led) == 2) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004914 if (spec->gpio_led < 4)
4915 spec->gpio_led = 1 << spec->gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004916 return 1;
4917 }
4918 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304919 &spec->gpio_led_polarity) == 1) {
4920 set_hp_led_gpio(codec);
4921 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004922 }
4923 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304924
4925 /*
4926 * Fallback case - if we don't find the DMI strings,
4927 * we statically set the GPIO - if not a B-series system.
4928 */
4929 if (!hp_blike_system(codec->subsystem_id)) {
4930 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004931 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304932 return 1;
4933 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004934 }
4935 return 0;
4936}
4937
4938static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004939{
4940 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004941 case 0x103c1520:
4942 case 0x103c1521:
4943 case 0x103c1523:
4944 case 0x103c1524:
4945 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004946 case 0x103c1722:
4947 case 0x103c1723:
4948 case 0x103c1724:
4949 case 0x103c1725:
4950 case 0x103c1726:
4951 case 0x103c1727:
4952 case 0x103c1728:
4953 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004954 case 0x103c172a:
4955 case 0x103c172b:
4956 case 0x103c307e:
4957 case 0x103c307f:
4958 case 0x103c3080:
4959 case 0x103c3081:
4960 case 0x103c7007:
4961 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004962 return 1;
4963 }
4964 return 0;
4965}
4966
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004967#ifdef CONFIG_PROC_FS
4968static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4969 struct hda_codec *codec, hda_nid_t nid)
4970{
4971 if (nid == codec->afg)
4972 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4973 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4974}
4975
4976static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4977 struct hda_codec *codec,
4978 unsigned int verb)
4979{
4980 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4981 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4982}
4983
4984/* stac92hd71bxx, stac92hd73xx */
4985static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4986 struct hda_codec *codec, hda_nid_t nid)
4987{
4988 stac92hd_proc_hook(buffer, codec, nid);
4989 if (nid == codec->afg)
4990 analog_loop_proc_hook(buffer, codec, 0xfa0);
4991}
4992
4993static void stac9205_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, 0xfe0);
4998}
4999
5000static void stac927x_proc_hook(struct snd_info_buffer *buffer,
5001 struct hda_codec *codec, hda_nid_t nid)
5002{
5003 if (nid == codec->afg)
5004 analog_loop_proc_hook(buffer, codec, 0xfeb);
5005}
5006#else
5007#define stac92hd_proc_hook NULL
5008#define stac92hd7x_proc_hook NULL
5009#define stac9205_proc_hook NULL
5010#define stac927x_proc_hook NULL
5011#endif
5012
Takashi Iwai2a439522011-07-26 09:52:50 +02005013#ifdef CONFIG_PM
Mattff6fdc32005-06-27 15:06:52 +02005014static int stac92xx_resume(struct hda_codec *codec)
5015{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02005016 struct sigmatel_spec *spec = codec->spec;
5017
Takashi Iwai2c885872008-11-18 09:36:55 +01005018 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02005019 snd_hda_codec_resume_amp(codec);
5020 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01005021 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02005022 if (spec->hp_detect) {
5023 if (spec->autocfg.hp_pins[0])
5024 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
5025 else if (spec->autocfg.line_out_pins[0])
5026 stac_issue_unsol_event(codec,
5027 spec->autocfg.line_out_pins[0]);
5028 }
Mattff6fdc32005-06-27 15:06:52 +02005029 return 0;
5030}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005031
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005032static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
5033{
5034 stac92xx_shutup(codec);
5035 return 0;
5036}
5037
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005038#ifdef CONFIG_SND_HDA_POWER_SAVE
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005039static int stac92xx_pre_resume(struct hda_codec *codec)
5040{
5041 struct sigmatel_spec *spec = codec->spec;
5042
5043 /* sync mute LED */
5044 if (spec->gpio_led) {
5045 if (spec->gpio_led <= 8) {
5046 stac_gpio_set(codec, spec->gpio_mask,
5047 spec->gpio_dir, spec->gpio_data);
5048 } else {
5049 stac_vrefout_set(codec,
5050 spec->gpio_led, spec->vref_led);
5051 }
5052 }
5053 return 0;
5054}
5055
5056static int stac92xx_post_suspend(struct hda_codec *codec)
5057{
5058 struct sigmatel_spec *spec = codec->spec;
5059 if (spec->gpio_led > 8) {
5060 /* with vref-out pin used for mute led control
5061 * codec AFG is prevented from D3 state, but on
5062 * system suspend it can (and should) be used
5063 */
5064 snd_hda_codec_read(codec, codec->afg, 0,
5065 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5066 }
5067 return 0;
5068}
5069
5070static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5071 unsigned int power_state)
5072{
5073 unsigned int afg_power_state = power_state;
5074 struct sigmatel_spec *spec = codec->spec;
5075
5076 if (power_state == AC_PWRST_D3) {
5077 if (spec->gpio_led > 8) {
5078 /* with vref-out pin used for mute led control
5079 * codec AFG is prevented from D3 state
5080 */
5081 afg_power_state = AC_PWRST_D1;
5082 }
5083 /* this delay seems necessary to avoid click noise at power-down */
5084 msleep(100);
5085 }
5086 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5087 afg_power_state);
5088 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
5089}
5090
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005091/*
5092 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed
5093 * as mute LED state is updated in check_power_status hook
5094 */
5095static int stac92xx_update_led_status(struct hda_codec *codec)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005096{
5097 struct sigmatel_spec *spec = codec->spec;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005098 int i, num_ext_dacs, muted = 1;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005099 unsigned int muted_lvl, notmtd_lvl;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005100 hda_nid_t nid;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005101
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005102 if (!spec->gpio_led)
5103 return 0;
5104
Takashi Iwaic21bd022010-02-08 15:16:08 +01005105 for (i = 0; i < spec->multiout.num_dacs; i++) {
5106 nid = spec->multiout.dac_nids[i];
5107 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5108 HDA_AMP_MUTE)) {
5109 muted = 0; /* something heard */
5110 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005111 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01005112 }
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005113 if (muted && spec->multiout.hp_nid)
5114 if (!(snd_hda_codec_amp_read(codec,
5115 spec->multiout.hp_nid, 0, HDA_OUTPUT, 0) &
5116 HDA_AMP_MUTE)) {
5117 muted = 0; /* HP is not muted */
5118 }
5119 num_ext_dacs = ARRAY_SIZE(spec->multiout.extra_out_nid);
5120 for (i = 0; muted && i < num_ext_dacs; i++) {
5121 nid = spec->multiout.extra_out_nid[i];
5122 if (nid == 0)
5123 break;
5124 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5125 HDA_AMP_MUTE)) {
5126 muted = 0; /* extra output is not muted */
5127 }
5128 }
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005129 /*polarity defines *not* muted state level*/
5130 if (spec->gpio_led <= 8) {
5131 if (muted)
5132 spec->gpio_data &= ~spec->gpio_led; /* orange */
5133 else
5134 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005135
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005136 if (!spec->gpio_led_polarity) {
5137 /* LED state is inverted on these systems */
5138 spec->gpio_data ^= spec->gpio_led;
5139 }
5140 stac_gpio_set(codec, spec->gpio_mask,
5141 spec->gpio_dir, spec->gpio_data);
5142 } else {
5143 notmtd_lvl = spec->gpio_led_polarity ?
5144 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_GRD;
5145 muted_lvl = spec->gpio_led_polarity ?
5146 AC_PINCTL_VREF_GRD : AC_PINCTL_VREF_HIZ;
5147 spec->vref_led = muted ? muted_lvl : notmtd_lvl;
5148 stac_vrefout_set(codec, spec->gpio_led, spec->vref_led);
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005149 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005150 return 0;
5151}
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005152
5153/*
5154 * use power check for controlling mute led of HP notebooks
5155 */
5156static int stac92xx_check_power_status(struct hda_codec *codec,
5157 hda_nid_t nid)
5158{
5159 stac92xx_update_led_status(codec);
5160
5161 return 0;
5162}
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005163#endif /* CONFIG_SND_HDA_POWER_SAVE */
Takashi Iwai2a439522011-07-26 09:52:50 +02005164#endif /* CONFIG_PM */
Mattff6fdc32005-06-27 15:06:52 +02005165
Takashi Iwai2b635362011-05-02 12:33:43 +02005166static const struct hda_codec_ops stac92xx_patch_ops = {
Matt2f2f4252005-04-13 14:45:30 +02005167 .build_controls = stac92xx_build_controls,
5168 .build_pcms = stac92xx_build_pcms,
5169 .init = stac92xx_init,
5170 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02005171 .unsol_event = stac92xx_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02005172#ifdef CONFIG_PM
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005173 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005174 .resume = stac92xx_resume,
5175#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005176 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005177};
5178
5179static int patch_stac9200(struct hda_codec *codec)
5180{
5181 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005182 int err;
Matt2f2f4252005-04-13 14:45:30 +02005183
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005184 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005185 if (spec == NULL)
5186 return -ENOMEM;
5187
Takashi Iwaia252c812009-12-25 22:56:20 +01005188 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005189 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005190 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005191 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005192 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005193 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5194 stac9200_models,
5195 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005196 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005197 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5198 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005199 else
5200 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005201 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005202
5203 spec->multiout.max_channels = 2;
5204 spec->multiout.num_dacs = 1;
5205 spec->multiout.dac_nids = stac9200_dac_nids;
5206 spec->adc_nids = stac9200_adc_nids;
5207 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005208 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005209 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005210 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005211 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005212
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005213 if (spec->board_config == STAC_9200_M4 ||
5214 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005215 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005216 spec->init = stac9200_eapd_init;
5217 else
5218 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005219 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005220
Takashi Iwai117f2572008-03-18 09:53:23 +01005221 if (spec->board_config == STAC_9200_PANASONIC) {
5222 spec->gpio_mask = spec->gpio_dir = 0x09;
5223 spec->gpio_data = 0x00;
5224 }
5225
Mattc7d4b2f2005-06-27 14:59:41 +02005226 err = stac9200_parse_auto_config(codec);
5227 if (err < 0) {
5228 stac92xx_free(codec);
5229 return err;
5230 }
Matt2f2f4252005-04-13 14:45:30 +02005231
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005232 /* CF-74 has no headphone detection, and the driver should *NOT*
5233 * do detection and HP/speaker toggle because the hardware does it.
5234 */
5235 if (spec->board_config == STAC_9200_PANASONIC)
5236 spec->hp_detect = 0;
5237
Matt2f2f4252005-04-13 14:45:30 +02005238 codec->patch_ops = stac92xx_patch_ops;
5239
5240 return 0;
5241}
5242
Tobin Davis8e21c342007-01-08 11:04:17 +01005243static int patch_stac925x(struct hda_codec *codec)
5244{
5245 struct sigmatel_spec *spec;
5246 int err;
5247
5248 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5249 if (spec == NULL)
5250 return -ENOMEM;
5251
Takashi Iwaia252c812009-12-25 22:56:20 +01005252 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005253 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005254 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005255 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005256 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005257
5258 /* Check first for codec ID */
5259 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5260 STAC_925x_MODELS,
5261 stac925x_models,
5262 stac925x_codec_id_cfg_tbl);
5263
5264 /* Now checks for PCI ID, if codec ID is not found */
5265 if (spec->board_config < 0)
5266 spec->board_config = snd_hda_check_board_config(codec,
5267 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005268 stac925x_models,
5269 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005270 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005271 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005272 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5273 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005274 else
5275 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005276 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005277
5278 spec->multiout.max_channels = 2;
5279 spec->multiout.num_dacs = 1;
5280 spec->multiout.dac_nids = stac925x_dac_nids;
5281 spec->adc_nids = stac925x_adc_nids;
5282 spec->mux_nids = stac925x_mux_nids;
5283 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005284 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005285 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005286 switch (codec->vendor_id) {
5287 case 0x83847632: /* STAC9202 */
5288 case 0x83847633: /* STAC9202D */
5289 case 0x83847636: /* STAC9251 */
5290 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005291 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005292 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005293 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5294 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005295 break;
5296 default:
5297 spec->num_dmics = 0;
5298 break;
5299 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005300
5301 spec->init = stac925x_core_init;
5302 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005303 spec->num_caps = 1;
5304 spec->capvols = stac925x_capvols;
5305 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005306
Charles Chin9009b0e2011-11-03 10:27:27 +01005307 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005308 if (!err) {
5309 if (spec->board_config < 0) {
5310 printk(KERN_WARNING "hda_codec: No auto-config is "
5311 "available, default to model=ref\n");
5312 spec->board_config = STAC_925x_REF;
5313 goto again;
5314 }
5315 err = -EINVAL;
5316 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005317 if (err < 0) {
5318 stac92xx_free(codec);
5319 return err;
5320 }
5321
5322 codec->patch_ops = stac92xx_patch_ops;
5323
5324 return 0;
5325}
5326
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005327static int patch_stac92hd73xx(struct hda_codec *codec)
5328{
5329 struct sigmatel_spec *spec;
5330 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5331 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005332 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005333
5334 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5335 if (spec == NULL)
5336 return -ENOMEM;
5337
Takashi Iwaia252c812009-12-25 22:56:20 +01005338 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005339 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005340 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005341 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005342 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5343 spec->pin_nids = stac92hd73xx_pin_nids;
5344 spec->board_config = snd_hda_check_board_config(codec,
5345 STAC_92HD73XX_MODELS,
5346 stac92hd73xx_models,
5347 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005348 /* check codec subsystem id if not found */
5349 if (spec->board_config < 0)
5350 spec->board_config =
5351 snd_hda_check_board_codec_sid_config(codec,
5352 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5353 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005354again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005355 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005356 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5357 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005358 else
5359 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005360 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005361
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005362 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005363 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5364
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005365 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005366 printk(KERN_WARNING "hda_codec: Could not determine "
5367 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005368 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005369 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005370 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005371 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005372 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005373 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005374 break;
5375 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005376 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005377 break;
5378 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005379 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5380 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005381 }
5382 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005383
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005384 spec->aloopback_mask = 0x01;
5385 spec->aloopback_shift = 8;
5386
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005387 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005388 spec->mux_nids = stac92hd73xx_mux_nids;
5389 spec->adc_nids = stac92hd73xx_adc_nids;
5390 spec->dmic_nids = stac92hd73xx_dmic_nids;
5391 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005392 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005393
5394 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5395 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005396 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005397
Takashi Iwai6479c632009-07-28 18:20:25 +02005398 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5399 spec->capvols = stac92hd73xx_capvols;
5400 spec->capsws = stac92hd73xx_capsws;
5401
Matthew Ranostaya7662642008-02-21 07:51:14 +01005402 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005403 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005404 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005405 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005406 case STAC_DELL_M6_AMIC:
5407 case STAC_DELL_M6_DMIC:
5408 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005409 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005410 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005411
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005412 switch (spec->board_config) {
5413 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005414 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005415 spec->num_dmics = 0;
5416 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005417 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005418 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005419 spec->num_dmics = 1;
5420 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005421 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005422 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5423 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005424 spec->num_dmics = 1;
5425 break;
5426 }
5427 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005428 case STAC_ALIENWARE_M17X:
5429 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5430 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5431 spec->eapd_switch = 0;
5432 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005433 default:
5434 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005435 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005436 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005437 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005438 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005439 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005440 /* GPIO0 High = Enable EAPD */
5441 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5442 spec->gpio_data = 0x01;
5443 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005444
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005445 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5446 spec->pwr_nids = stac92hd73xx_pwr_nids;
5447
Charles Chin9009b0e2011-11-03 10:27:27 +01005448 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005449
5450 if (!err) {
5451 if (spec->board_config < 0) {
5452 printk(KERN_WARNING "hda_codec: No auto-config is "
5453 "available, default to model=ref\n");
5454 spec->board_config = STAC_92HD73XX_REF;
5455 goto again;
5456 }
5457 err = -EINVAL;
5458 }
5459
5460 if (err < 0) {
5461 stac92xx_free(codec);
5462 return err;
5463 }
5464
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005465 if (spec->board_config == STAC_92HD73XX_NO_JD)
5466 spec->hp_detect = 0;
5467
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005468 codec->patch_ops = stac92xx_patch_ops;
5469
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005470 codec->proc_widget_hook = stac92hd7x_proc_hook;
5471
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005472 return 0;
5473}
5474
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005475static int hp_bnb2011_with_dock(struct hda_codec *codec)
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005476{
5477 if (codec->vendor_id != 0x111d7605 &&
5478 codec->vendor_id != 0x111d76d1)
5479 return 0;
5480
5481 switch (codec->subsystem_id) {
5482 case 0x103c1618:
5483 case 0x103c1619:
5484 case 0x103c161a:
5485 case 0x103c161b:
5486 case 0x103c161c:
5487 case 0x103c161d:
5488 case 0x103c161e:
5489 case 0x103c161f:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005490
5491 case 0x103c162a:
5492 case 0x103c162b:
5493
5494 case 0x103c1630:
5495 case 0x103c1631:
5496
5497 case 0x103c1633:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005498 case 0x103c1634:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005499 case 0x103c1635:
5500
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005501 case 0x103c3587:
5502 case 0x103c3588:
5503 case 0x103c3589:
5504 case 0x103c358a:
5505
5506 case 0x103c3667:
5507 case 0x103c3668:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005508 case 0x103c3669:
5509
5510 return 1;
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005511 }
5512 return 0;
5513}
5514
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005515static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
5516{
5517 struct sigmatel_spec *spec = codec->spec;
5518 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5519 int i;
5520
5521 spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5522 spec->auto_pin_cnt++;
5523
5524 if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5525 get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5526 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5527 if (nid == stac92hd83xxx_dmic_nids[i]) {
5528 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5529 spec->auto_dmic_cnt++;
5530 }
5531 }
5532 }
5533}
5534
5535static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5536{
5537 struct sigmatel_spec *spec = codec->spec;
5538
5539 spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5540 spec->auto_adc_cnt++;
5541}
5542
5543static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5544{
5545 int i, j;
5546 struct sigmatel_spec *spec = codec->spec;
5547
5548 for (i = 0; i < spec->auto_adc_cnt; i++) {
5549 if (get_connection_index(codec,
5550 spec->auto_adc_nids[i], nid) >= 0) {
5551 /* mux and volume for adc_nids[i] */
5552 if (!spec->auto_mux_nids[i]) {
5553 spec->auto_mux_nids[i] = nid;
5554 /* 92hd codecs capture volume is in mux */
5555 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
5556 3, 0, HDA_OUTPUT);
5557 }
5558 for (j = 0; j < spec->auto_dmic_cnt; j++) {
5559 if (get_connection_index(codec, nid,
5560 spec->auto_dmic_nids[j]) >= 0) {
5561 /* dmux for adc_nids[i] */
5562 if (!spec->auto_dmux_nids[i])
5563 spec->auto_dmux_nids[i] = nid;
5564 break;
5565 }
5566 }
5567 break;
5568 }
5569 }
5570}
5571
5572static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5573{
5574 hda_nid_t nid, end_nid;
5575 unsigned int wid_caps, wid_type;
5576 struct sigmatel_spec *spec = codec->spec;
5577
5578 end_nid = codec->start_nid + codec->num_nodes;
5579
5580 for (nid = codec->start_nid; nid < end_nid; nid++) {
5581 wid_caps = get_wcaps(codec, nid);
5582 wid_type = get_wcaps_type(wid_caps);
5583
5584 if (wid_type == AC_WID_PIN)
5585 stac92hd8x_add_pin(codec, nid);
5586
5587 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5588 stac92hd8x_add_adc(codec, nid);
5589 }
5590
5591 for (nid = codec->start_nid; nid < end_nid; nid++) {
5592 wid_caps = get_wcaps(codec, nid);
5593 wid_type = get_wcaps_type(wid_caps);
5594
5595 if (wid_type == AC_WID_AUD_SEL)
5596 stac92hd8x_add_mux(codec, nid);
5597 }
5598
5599 spec->pin_nids = spec->auto_pin_nids;
5600 spec->num_pins = spec->auto_pin_cnt;
5601 spec->adc_nids = spec->auto_adc_nids;
5602 spec->num_adcs = spec->auto_adc_cnt;
5603 spec->capvols = spec->auto_capvols;
5604 spec->capsws = spec->auto_capvols;
5605 spec->num_caps = spec->auto_adc_cnt;
5606 spec->mux_nids = spec->auto_mux_nids;
5607 spec->num_muxes = spec->auto_adc_cnt;
5608 spec->dmux_nids = spec->auto_dmux_nids;
5609 spec->num_dmuxes = spec->auto_adc_cnt;
5610 spec->dmic_nids = spec->auto_dmic_nids;
5611 spec->num_dmics = spec->auto_dmic_cnt;
5612}
5613
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005614static int patch_stac92hd83xxx(struct hda_codec *codec)
5615{
5616 struct sigmatel_spec *spec;
5617 int err;
5618
5619 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5620 if (spec == NULL)
5621 return -ENOMEM;
5622
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005623 if (hp_bnb2011_with_dock(codec)) {
5624 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5625 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5626 }
5627
Takashi Iwaia252c812009-12-25 22:56:20 +01005628 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005629 codec->spec = spec;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005630
5631 stac92hd8x_fill_auto_spec(codec);
5632
Takashi Iwai1db7ccdb2010-12-03 15:19:14 +01005633 spec->linear_tone_beep = 0;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005634 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005635 spec->digbeep_nid = 0x21;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005636 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005637 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005638 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005639 spec->init = stac92hd83xxx_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005640
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005641 spec->board_config = snd_hda_check_board_config(codec,
5642 STAC_92HD83XXX_MODELS,
5643 stac92hd83xxx_models,
5644 stac92hd83xxx_cfg_tbl);
5645again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005646 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005647 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5648 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005649 else
5650 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005651 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005652
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 Iwaiaf9f3412008-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 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005862 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005863 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005864 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5865 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Takashi Iwai2b635362011-05-02 12:33:43 +02005866 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005867 spec->num_dmics = stac92xx_connected_ports(codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02005868 stac92hd71bxx_dmic_5port_nids,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005869 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005870 break;
5871 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005872 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005873 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005874
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005875 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005876 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005877 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005878 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005879 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005880 stac92hd71bxx_dmic_nids,
5881 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005882 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005883 }
5884
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005885 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5886 snd_hda_sequence_write_cache(codec, unmute_init);
5887
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005888 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005889 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005890 spec->aloopback_shift = 0;
5891
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005892 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005893 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005894 spec->mux_nids = stac92hd71bxx_mux_nids;
5895 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005896 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005897 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005898
5899 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5900 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005901 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005902 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005903
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305904 snd_printdd("Found board config: %d\n", spec->board_config);
5905
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005906 switch (spec->board_config) {
5907 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005908 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005909 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005910 stac92xx_auto_set_pinctl(codec, 0x0e,
5911 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005912 /* fallthru */
5913 case STAC_DELL_M4_2:
5914 spec->num_dmics = 0;
5915 spec->num_smuxes = 0;
5916 spec->num_dmuxes = 0;
5917 break;
5918 case STAC_DELL_M4_1:
5919 case STAC_DELL_M4_3:
5920 spec->num_dmics = 1;
5921 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005922 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005923 break;
James Gardiner514bf542009-05-03 04:00:44 -04005924 case STAC_HP_DV4_1222NR:
5925 spec->num_dmics = 1;
5926 /* I don't know if it needs 1 or 2 smuxes - will wait for
5927 * bug reports to fix if needed
5928 */
5929 spec->num_smuxes = 1;
5930 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005931 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005932 case STAC_HP_DV4:
5933 spec->gpio_led = 0x01;
5934 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005935 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005936 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005937 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005938 /* HP dv6 gives the headphone pin as a line-out. Thus we
5939 * need to set hp_detect flag here to force to enable HP
5940 * detection.
5941 */
5942 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005943 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005944 case STAC_HP_HDX:
5945 spec->num_dmics = 1;
5946 spec->num_dmuxes = 1;
5947 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005948 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005949 break;
5950 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005951
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005952 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005953 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5954 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5955 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5956 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5957 /* It was changed in the BIOS to just satisfy MS DTM.
5958 * Lets turn it back into slaved HP
5959 */
5960 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5961 | (AC_JACK_HP_OUT <<
5962 AC_DEFCFG_DEVICE_SHIFT);
5963 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5964 | AC_DEFCFG_SEQUENCE)))
5965 | 0x1f;
5966 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5967 }
5968 }
5969
Takashi Iwaidce17d42010-02-09 09:25:26 +01005970 if (find_mute_led_gpio(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005971 snd_printd("mute LED gpio %d polarity %d\n",
5972 spec->gpio_led,
5973 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005974
Takashi Iwai86d190e2009-05-26 15:18:58 +02005975#ifdef CONFIG_SND_HDA_POWER_SAVE
5976 if (spec->gpio_led) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005977 if (spec->gpio_led <= 8) {
5978 spec->gpio_mask |= spec->gpio_led;
5979 spec->gpio_dir |= spec->gpio_led;
5980 spec->gpio_data |= spec->gpio_led;
5981 } else {
5982 codec->patch_ops.set_power_state =
5983 stac92xx_set_power_state;
5984 codec->patch_ops.post_suspend =
5985 stac92xx_post_suspend;
5986 }
5987 codec->patch_ops.pre_resume = stac92xx_pre_resume;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005988 codec->patch_ops.check_power_status =
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005989 stac92xx_check_power_status;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005990 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005991#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005992
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005993 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005994
Charles Chin9009b0e2011-11-03 10:27:27 +01005995 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005996 if (!err) {
5997 if (spec->board_config < 0) {
5998 printk(KERN_WARNING "hda_codec: No auto-config is "
5999 "available, default to model=ref\n");
6000 spec->board_config = STAC_92HD71BXX_REF;
6001 goto again;
6002 }
6003 err = -EINVAL;
6004 }
6005
6006 if (err < 0) {
6007 stac92xx_free(codec);
6008 return err;
6009 }
6010
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006011 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02006012 if (spec->board_config == STAC_HP_DV4 ||
6013 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006014 unsigned int cap;
6015 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
6016 cap &= AC_GPIO_IO_COUNT;
6017 if (cap >= 6)
6018 stac_add_hp_bass_switch(codec);
6019 }
6020
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006021 codec->proc_widget_hook = stac92hd7x_proc_hook;
6022
Matthew Ranostaye035b842007-11-06 11:53:55 +01006023 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006024}
Matthew Ranostaye035b842007-11-06 11:53:55 +01006025
Matt2f2f4252005-04-13 14:45:30 +02006026static int patch_stac922x(struct hda_codec *codec)
6027{
6028 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02006029 int err;
Matt2f2f4252005-04-13 14:45:30 +02006030
Takashi Iwaie560d8d2005-09-09 14:21:46 +02006031 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02006032 if (spec == NULL)
6033 return -ENOMEM;
6034
Takashi Iwaia252c812009-12-25 22:56:20 +01006035 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02006036 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006037 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006038 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006039 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006040 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
6041 stac922x_models,
6042 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08006043 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006044 spec->gpio_mask = spec->gpio_dir = 0x03;
6045 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006046 /* Intel Macs have all same PCI SSID, so we need to check
6047 * codec SSID to distinguish the exact models
6048 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006049 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006050 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006051
6052 case 0x106b0800:
6053 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02006054 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006055 case 0x106b0600:
6056 case 0x106b0700:
6057 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006058 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006059 case 0x106b0e00:
6060 case 0x106b0f00:
6061 case 0x106b1600:
6062 case 0x106b1700:
6063 case 0x106b0200:
6064 case 0x106b1e00:
6065 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006066 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006067 case 0x106b1a00:
6068 case 0x00000100:
6069 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02006070 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006071 case 0x106b0a00:
6072 case 0x106b2200:
6073 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02006074 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08006075 default:
6076 spec->board_config = STAC_INTEL_MAC_V3;
6077 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006078 }
6079 }
6080
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006081 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006082 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006083 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6084 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006085 else
6086 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006087 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02006088
Matt2f2f4252005-04-13 14:45:30 +02006089 spec->adc_nids = stac922x_adc_nids;
6090 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006091 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006092 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006093 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006094 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02006095
6096 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006097
6098 spec->num_caps = STAC922X_NUM_CAPS;
6099 spec->capvols = stac922x_capvols;
6100 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02006101
6102 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02006103
Charles Chin9009b0e2011-11-03 10:27:27 +01006104 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006105 if (!err) {
6106 if (spec->board_config < 0) {
6107 printk(KERN_WARNING "hda_codec: No auto-config is "
6108 "available, default to model=ref\n");
6109 spec->board_config = STAC_D945_REF;
6110 goto again;
6111 }
6112 err = -EINVAL;
6113 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006114 if (err < 0) {
6115 stac92xx_free(codec);
6116 return err;
6117 }
6118
6119 codec->patch_ops = stac92xx_patch_ops;
6120
Takashi Iwai807a46362007-05-29 19:01:37 +02006121 /* Fix Mux capture level; max to 2 */
6122 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
6123 (0 << AC_AMPCAP_OFFSET_SHIFT) |
6124 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
6125 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6126 (0 << AC_AMPCAP_MUTE_SHIFT));
6127
Matt Porter3cc08dc2006-01-23 15:27:49 +01006128 return 0;
6129}
6130
6131static int patch_stac927x(struct hda_codec *codec)
6132{
6133 struct sigmatel_spec *spec;
6134 int err;
6135
6136 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6137 if (spec == NULL)
6138 return -ENOMEM;
6139
Takashi Iwaia252c812009-12-25 22:56:20 +01006140 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01006141 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006142 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05006143 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006144 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006145 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006146 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
6147 stac927x_models,
6148 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006149 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006150 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006151 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6152 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006153 else
6154 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006155 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01006156
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006157 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006158 spec->adc_nids = stac927x_adc_nids;
6159 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6160 spec->mux_nids = stac927x_mux_nids;
6161 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006162 spec->smux_nids = stac927x_smux_nids;
6163 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04006164 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01006165 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006166 spec->multiout.dac_nids = spec->dac_nids;
6167
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006168 if (spec->board_config != STAC_D965_REF) {
6169 /* GPIO0 High = Enable EAPD */
6170 spec->eapd_mask = spec->gpio_mask = 0x01;
6171 spec->gpio_dir = spec->gpio_data = 0x01;
6172 }
6173
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006174 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02006175 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006176 case STAC_D965_5ST:
6177 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006178 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02006179 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006180 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006181 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006182 switch (codec->subsystem_id) {
6183 case 0x10280209:
6184 case 0x1028022e:
6185 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006186 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006187 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006188 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01006189 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01006190 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01006191 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006192 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006193 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01006194 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006195 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006196 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006197 if (codec->subsystem_id != 0x1028022f) {
6198 /* GPIO2 High = Enable EAPD */
6199 spec->eapd_mask = spec->gpio_mask = 0x04;
6200 spec->gpio_dir = spec->gpio_data = 0x04;
6201 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006202 spec->dmic_nids = stac927x_dmic_nids;
6203 spec->num_dmics = STAC927X_NUM_DMICS;
6204
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02006205 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006206 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006207 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006208 break;
Takashi Iwai54930532009-10-11 17:38:29 +02006209 case STAC_927X_VOLKNOB:
6210 spec->num_dmics = 0;
6211 spec->init = stac927x_volknob_core_init;
6212 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006213 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006214 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006215 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006216 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006217 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006218
Takashi Iwai6479c632009-07-28 18:20:25 +02006219 spec->num_caps = STAC927X_NUM_CAPS;
6220 spec->capvols = stac927x_capvols;
6221 spec->capsws = stac927x_capsws;
6222
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006223 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006224 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006225 spec->aloopback_mask = 0x40;
6226 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05006227 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006228
Charles Chin9009b0e2011-11-03 10:27:27 +01006229 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006230 if (!err) {
6231 if (spec->board_config < 0) {
6232 printk(KERN_WARNING "hda_codec: No auto-config is "
6233 "available, default to model=ref\n");
6234 spec->board_config = STAC_D965_REF;
6235 goto again;
6236 }
6237 err = -EINVAL;
6238 }
Mattc7d4b2f2005-06-27 14:59:41 +02006239 if (err < 0) {
6240 stac92xx_free(codec);
6241 return err;
6242 }
Matt2f2f4252005-04-13 14:45:30 +02006243
6244 codec->patch_ops = stac92xx_patch_ops;
6245
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006246 codec->proc_widget_hook = stac927x_proc_hook;
6247
Takashi Iwai52987652008-01-16 16:09:47 +01006248 /*
6249 * !!FIXME!!
6250 * The STAC927x seem to require fairly long delays for certain
6251 * command sequences. With too short delays (even if the answer
6252 * is set to RIRB properly), it results in the silence output
6253 * on some hardwares like Dell.
6254 *
6255 * The below flag enables the longer delay (see get_response
6256 * in hda_intel.c).
6257 */
6258 codec->bus->needs_damn_long_delay = 1;
6259
Takashi Iwaie28d8322008-12-17 13:48:29 +01006260 /* no jack detecion for ref-no-jd model */
6261 if (spec->board_config == STAC_D965_REF_NO_JD)
6262 spec->hp_detect = 0;
6263
Matt2f2f4252005-04-13 14:45:30 +02006264 return 0;
6265}
6266
Matt Porterf3302a52006-07-31 12:49:34 +02006267static int patch_stac9205(struct hda_codec *codec)
6268{
6269 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006270 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006271
6272 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6273 if (spec == NULL)
6274 return -ENOMEM;
6275
Takashi Iwaia252c812009-12-25 22:56:20 +01006276 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006277 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006278 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006279 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006280 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006281 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6282 stac9205_models,
6283 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006284 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006285 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006286 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6287 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006288 else
6289 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006290 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006291
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006292 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006293 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006294 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006295 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006296 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006297 spec->smux_nids = stac9205_smux_nids;
6298 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006299 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006300 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006301 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006302 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006303 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006304
6305 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006306 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006307
Takashi Iwai6479c632009-07-28 18:20:25 +02006308 spec->num_caps = STAC9205_NUM_CAPS;
6309 spec->capvols = stac9205_capvols;
6310 spec->capsws = stac9205_capsws;
6311
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006312 spec->aloopback_mask = 0x40;
6313 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006314 /* Turn on/off EAPD per HP plugging */
6315 if (spec->board_config != STAC_9205_EAPD)
6316 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006317 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006318
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006319 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006320 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006321 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006322 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6323 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006324
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006325 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006326 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6327 if (err < 0)
6328 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006329 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006330 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6331 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006332 AC_VERB_SET_UNSOLICITED_ENABLE,
6333 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006334
6335 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006336 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006337 spec->gpio_mask = 0x1b;
6338 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006339 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006340 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006341 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006342 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006343 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006344 case STAC_9205_REF:
6345 /* SPDIF-In enabled */
6346 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006347 default:
6348 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006349 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006350 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006351 break;
6352 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006353
Charles Chin9009b0e2011-11-03 10:27:27 +01006354 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006355 if (!err) {
6356 if (spec->board_config < 0) {
6357 printk(KERN_WARNING "hda_codec: No auto-config is "
6358 "available, default to model=ref\n");
6359 spec->board_config = STAC_9205_REF;
6360 goto again;
6361 }
6362 err = -EINVAL;
6363 }
Matt Porterf3302a52006-07-31 12:49:34 +02006364 if (err < 0) {
6365 stac92xx_free(codec);
6366 return err;
6367 }
6368
6369 codec->patch_ops = stac92xx_patch_ops;
6370
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006371 codec->proc_widget_hook = stac9205_proc_hook;
6372
Matt Porterf3302a52006-07-31 12:49:34 +02006373 return 0;
6374}
6375
Matt2f2f4252005-04-13 14:45:30 +02006376/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006377 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006378 */
6379
Takashi Iwai2b635362011-05-02 12:33:43 +02006380static const struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006381 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006382 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6383 {}
6384};
6385
Takashi Iwai2b635362011-05-02 12:33:43 +02006386static const hda_nid_t stac9872_pin_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006387 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6388 0x11, 0x13, 0x14,
6389};
6390
Takashi Iwai2b635362011-05-02 12:33:43 +02006391static const hda_nid_t stac9872_adc_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006392 0x8 /*,0x6*/
6393};
6394
Takashi Iwai2b635362011-05-02 12:33:43 +02006395static const hda_nid_t stac9872_mux_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006396 0x15
6397};
6398
Takashi Iwai2b635362011-05-02 12:33:43 +02006399static const unsigned long stac9872_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +02006400 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6401};
6402#define stac9872_capsws stac9872_capvols
6403
Takashi Iwai2b635362011-05-02 12:33:43 +02006404static const unsigned int stac9872_vaio_pin_configs[9] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006405 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6406 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6407 0x90a7013e
6408};
6409
Takashi Iwaiea734962011-01-17 11:29:34 +01006410static const char * const stac9872_models[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006411 [STAC_9872_AUTO] = "auto",
6412 [STAC_9872_VAIO] = "vaio",
6413};
6414
Takashi Iwai2b635362011-05-02 12:33:43 +02006415static const unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006416 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6417};
6418
Takashi Iwai2b635362011-05-02 12:33:43 +02006419static const struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006420 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6421 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006422 {} /* terminator */
6423};
6424
Guillaume Munch6d859062006-08-22 17:15:47 +02006425static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006426{
6427 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006428 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006429
Takashi Iwaidb064e52006-03-16 16:04:58 +01006430 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6431 if (spec == NULL)
6432 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006433 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006434 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006435 spec->linear_tone_beep = 1;
Takashi Iwaib04add92009-07-20 08:01:36 +02006436 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6437 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006438
6439 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6440 stac9872_models,
6441 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006442 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006443 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6444 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006445 else
6446 stac92xx_set_config_regs(codec,
6447 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006448
Takashi Iwai1e137f92009-01-21 07:41:22 +01006449 spec->multiout.dac_nids = spec->dac_nids;
6450 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6451 spec->adc_nids = stac9872_adc_nids;
6452 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6453 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006454 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006455 spec->num_caps = 1;
6456 spec->capvols = stac9872_capvols;
6457 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006458
Charles Chin9009b0e2011-11-03 10:27:27 +01006459 err = stac92xx_parse_auto_config(codec);
Takashi Iwai1e137f92009-01-21 07:41:22 +01006460 if (err < 0) {
6461 stac92xx_free(codec);
6462 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006463 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006464 spec->input_mux = &spec->private_imux;
6465 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006466 return 0;
6467}
6468
6469
6470/*
Matt2f2f4252005-04-13 14:45:30 +02006471 * patch entries
6472 */
Takashi Iwai2b635362011-05-02 12:33:43 +02006473static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006474 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6475 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6476 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6477 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6478 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6479 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6480 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006481 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6482 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6483 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6484 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6485 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6486 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006487 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6488 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6489 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6490 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6491 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6492 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6493 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6494 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6495 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6496 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006497 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6498 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6499 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6500 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6501 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6502 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006503 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6504 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006505 /* The following does not take into account .id=0x83847661 when subsys =
6506 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6507 * currently not fully supported.
6508 */
6509 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6510 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6511 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006512 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006513 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6514 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6515 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6516 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6517 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6518 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6519 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6520 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006521 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006522 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006523 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006524 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006525 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006526 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6527 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006528 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6529 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6530 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6531 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006532 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006533 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6534 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006535 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006536 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6537 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6538 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6539 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6540 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6541 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6542 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6543 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006544 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6545 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6546 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6547 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6548 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6549 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6550 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6551 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6552 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6553 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6554 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6555 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6556 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6557 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6558 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
David Henningsson46724c22011-09-20 09:02:22 +02006559 { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006560 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06006561 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6562 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006563 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Charles Chinad5d8752011-11-02 07:56:58 +01006564 { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6565 { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6566 { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6567 { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6568 { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6569 { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6570 { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6571 { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6572 { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6573 { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6574 { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6575 { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006576 {} /* terminator */
6577};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006578
6579MODULE_ALIAS("snd-hda-codec-id:8384*");
6580MODULE_ALIAS("snd-hda-codec-id:111d*");
6581
6582MODULE_LICENSE("GPL");
6583MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6584
6585static struct hda_codec_preset_list sigmatel_list = {
6586 .preset = snd_hda_preset_sigmatel,
6587 .owner = THIS_MODULE,
6588};
6589
6590static int __init patch_sigmatel_init(void)
6591{
6592 return snd_hda_add_codec_preset(&sigmatel_list);
6593}
6594
6595static void __exit patch_sigmatel_exit(void)
6596{
6597 snd_hda_delete_codec_preset(&sigmatel_list);
6598}
6599
6600module_init(patch_sigmatel_init)
6601module_exit(patch_sigmatel_exit)