blob: f3658658548e35179c70069cb31a498cabc155f7 [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 Iwaidbd1b542011-11-19 11:41:30 +01001644 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490,
1645 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwai842ae632009-09-02 07:43:08 +02001646 {} /* terminator */
1647};
1648
Takashi Iwai2b635362011-05-02 12:33:43 +02001649static const unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001650 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1651 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001652 0x01451160, 0x98560170,
1653};
1654
Takashi Iwai2b635362011-05-02 12:33:43 +02001655static const unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001656 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1657 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001658 0x40f000f0, 0x40f000f0,
1659};
1660
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001661static const unsigned int dell_vostro_3500_pin_configs[10] = {
1662 0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
1663 0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
1664 0x400000f4, 0x400000f5,
1665};
1666
Takashi Iwai2b635362011-05-02 12:33:43 +02001667static const unsigned int hp_dv7_4000_pin_configs[10] = {
Steven Eastland48315592010-08-06 15:07:35 -06001668 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1669 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1670 0x40f000f0, 0x40f000f0,
1671};
1672
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001673static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
1674 0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
1675 0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
1676 0x40f000f0, 0x40f000f0,
1677};
1678
Takashi Iwai2b635362011-05-02 12:33:43 +02001679static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001680 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001681 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001682 [STAC_DELL_S14] = dell_s14_pin_configs,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001683 [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001684 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001685 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001686};
1687
Takashi Iwaiea734962011-01-17 11:29:34 +01001688static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001689 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001690 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001691 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001692 [STAC_DELL_S14] = "dell-s14",
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001693 [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
Takashi Iwaib4e81872009-11-18 17:20:24 +01001694 [STAC_92HD83XXX_HP] = "hp",
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001695 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
Steven Eastland48315592010-08-06 15:07:35 -06001696 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001697};
1698
Takashi Iwai2b635362011-05-02 12:33:43 +02001699static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001700 /* SigmaTel reference board */
1701 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001702 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001703 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1704 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001705 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1706 "unknown Dell", STAC_DELL_S14),
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001707 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
1708 "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
Takashi Iwaib4e81872009-11-18 17:20:24 +01001709 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001710 "HP", STAC_92HD83XXX_HP),
1711 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
1712 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1713 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
1714 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1715 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
1716 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1717 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
1718 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1719 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
1720 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1721 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1722 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1723 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1724 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1725 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
1726 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1727 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
1728 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1729 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
1730 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1731 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
1732 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1733 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
1734 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1735 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
1736 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1737 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
1738 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1739 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
1740 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1741 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
1742 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1743 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
1744 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1745 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
1746 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1747 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
1748 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1749 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
1750 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001751 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001752};
1753
Takashi Iwai2b635362011-05-02 12:33:43 +02001754static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001755 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001756 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001757 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1758 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001759};
1760
Takashi Iwai2b635362011-05-02 12:33:43 +02001761static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001762 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001763 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001764 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1765 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001766};
1767
Takashi Iwai2b635362011-05-02 12:33:43 +02001768static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001769 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1770 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001771 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1772 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001773};
1774
Takashi Iwai2b635362011-05-02 12:33:43 +02001775static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001776 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1777 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001778 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1779 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001780};
1781
Takashi Iwai2b635362011-05-02 12:33:43 +02001782static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001783 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001784 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1785 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001786 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001787 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001788 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001789 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001790 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001791 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001792};
1793
Takashi Iwaiea734962011-01-17 11:29:34 +01001794static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001795 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001796 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001797 [STAC_DELL_M4_1] = "dell-m4-1",
1798 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001799 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001800 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001801 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001802 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001803 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001804 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001805};
1806
Takashi Iwai2b635362011-05-02 12:33:43 +02001807static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001808 /* SigmaTel reference board */
1809 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1810 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001811 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1812 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001813 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1814 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01001815 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1816 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01001817 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1818 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001819 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001820 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001821 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1822 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001823 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1824 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001825 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001826 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001827 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001828 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001829 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1830 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05301831 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1832 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11001833 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1834 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02001835 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1836 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001837 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1838 "unknown Dell", STAC_DELL_M4_1),
1839 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1840 "unknown Dell", STAC_DELL_M4_1),
1841 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1842 "unknown Dell", STAC_DELL_M4_1),
1843 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1844 "unknown Dell", STAC_DELL_M4_1),
1845 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1846 "unknown Dell", STAC_DELL_M4_1),
1847 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1848 "unknown Dell", STAC_DELL_M4_1),
1849 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1850 "unknown Dell", STAC_DELL_M4_1),
1851 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1852 "unknown Dell", STAC_DELL_M4_2),
1853 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1854 "unknown Dell", STAC_DELL_M4_2),
1855 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1856 "unknown Dell", STAC_DELL_M4_2),
1857 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1858 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001859 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1860 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001861 {} /* terminator */
1862};
1863
Takashi Iwai2b635362011-05-02 12:33:43 +02001864static const unsigned int ref922x_pin_configs[10] = {
Matt Porter403d1942005-11-29 15:00:51 +01001865 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1866 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001867 0x40000100, 0x40000100,
1868};
1869
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001870/*
1871 STAC 922X pin configs for
1872 102801A7
1873 102801AB
1874 102801A9
1875 102801D1
1876 102801D2
1877*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001878static const unsigned int dell_922x_d81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001879 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1880 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1881 0x01813122, 0x400001f2,
1882};
1883
1884/*
1885 STAC 922X pin configs for
1886 102801AC
1887 102801D0
1888*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001889static const unsigned int dell_922x_d82_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001890 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1891 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1892 0x01813122, 0x400001f1,
1893};
1894
1895/*
1896 STAC 922X pin configs for
1897 102801BF
1898*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001899static const unsigned int dell_922x_m81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001900 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1901 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1902 0x40C003f1, 0x405003f0,
1903};
1904
1905/*
1906 STAC 9221 A1 pin configs for
1907 102801D7 (Dell XPS M1210)
1908*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001909static const unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001910 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1911 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001912 0x508003f3, 0x405003f4,
1913};
1914
Takashi Iwai2b635362011-05-02 12:33:43 +02001915static const unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001916 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001917 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1918 0x02a19120, 0x40000100,
1919};
1920
Takashi Iwai2b635362011-05-02 12:33:43 +02001921static const unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001922 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1923 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001924 0x02a19320, 0x40000100,
1925};
1926
Takashi Iwai2b635362011-05-02 12:33:43 +02001927static const unsigned int intel_mac_v1_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001928 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1929 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001930 0x400000fc, 0x400000fb,
1931};
1932
Takashi Iwai2b635362011-05-02 12:33:43 +02001933static const unsigned int intel_mac_v2_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001934 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1935 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001936 0x400000fc, 0x400000fb,
1937};
1938
Takashi Iwai2b635362011-05-02 12:33:43 +02001939static const unsigned int intel_mac_v3_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001940 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1941 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1942 0x400000fc, 0x400000fb,
1943};
1944
Takashi Iwai2b635362011-05-02 12:33:43 +02001945static const unsigned int intel_mac_v4_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001946 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1947 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1948 0x400000fc, 0x400000fb,
1949};
1950
Takashi Iwai2b635362011-05-02 12:33:43 +02001951static const unsigned int intel_mac_v5_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001952 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1953 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1954 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001955};
1956
Takashi Iwai2b635362011-05-02 12:33:43 +02001957static const unsigned int ecs202_pin_configs[10] = {
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001958 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1959 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1960 0x9037012e, 0x40e000f2,
1961};
Takashi Iwai76c08822007-06-19 12:17:42 +02001962
Takashi Iwai2b635362011-05-02 12:33:43 +02001963static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001964 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001965 [STAC_D945GTP3] = d945gtp3_pin_configs,
1966 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001967 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1968 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1969 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1970 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1971 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001972 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001973 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001974 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1975 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1976 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1977 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1978 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1979 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001980 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001981 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1982 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1983 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1984 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001985};
1986
Takashi Iwaiea734962011-01-17 11:29:34 +01001987static const char * const stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001988 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001989 [STAC_D945_REF] = "ref",
1990 [STAC_D945GTP5] = "5stack",
1991 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001992 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1993 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1994 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1995 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1996 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001997 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001998 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001999 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002000 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002001 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2002 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02002003 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002004 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002005 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002006 [STAC_922X_DELL_D81] = "dell-d81",
2007 [STAC_922X_DELL_D82] = "dell-d82",
2008 [STAC_922X_DELL_M81] = "dell-m81",
2009 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002010};
2011
Takashi Iwai2b635362011-05-02 12:33:43 +02002012static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002013 /* SigmaTel reference board */
2014 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2015 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002016 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2017 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002018 /* Intel 945G based systems */
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2020 "Intel D945G", STAC_D945GTP3),
2021 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2022 "Intel D945G", STAC_D945GTP3),
2023 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2024 "Intel D945G", STAC_D945GTP3),
2025 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2026 "Intel D945G", STAC_D945GTP3),
2027 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2028 "Intel D945G", STAC_D945GTP3),
2029 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2030 "Intel D945G", STAC_D945GTP3),
2031 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2032 "Intel D945G", STAC_D945GTP3),
2033 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2034 "Intel D945G", STAC_D945GTP3),
2035 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2036 "Intel D945G", STAC_D945GTP3),
2037 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2038 "Intel D945G", STAC_D945GTP3),
2039 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2040 "Intel D945G", STAC_D945GTP3),
2041 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2042 "Intel D945G", STAC_D945GTP3),
2043 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2044 "Intel D945G", STAC_D945GTP3),
2045 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2046 "Intel D945G", STAC_D945GTP3),
2047 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2048 "Intel D945G", STAC_D945GTP3),
2049 /* Intel D945G 5-stack systems */
2050 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2051 "Intel D945G", STAC_D945GTP5),
2052 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2053 "Intel D945G", STAC_D945GTP5),
2054 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2055 "Intel D945G", STAC_D945GTP5),
2056 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2057 "Intel D945G", STAC_D945GTP5),
2058 /* Intel 945P based systems */
2059 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2060 "Intel D945P", STAC_D945GTP3),
2061 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2062 "Intel D945P", STAC_D945GTP3),
2063 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2064 "Intel D945P", STAC_D945GTP3),
2065 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2066 "Intel D945P", STAC_D945GTP3),
2067 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2068 "Intel D945P", STAC_D945GTP3),
2069 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2070 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002071 /* other intel */
2072 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2073 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002074 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002075 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002076 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002077 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002078 /* Dell systems */
2079 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2080 "unknown Dell", STAC_922X_DELL_D81),
2081 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2082 "unknown Dell", STAC_922X_DELL_D81),
2083 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2084 "unknown Dell", STAC_922X_DELL_D81),
2085 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2086 "unknown Dell", STAC_922X_DELL_D82),
2087 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2088 "unknown Dell", STAC_922X_DELL_M81),
2089 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2090 "unknown Dell", STAC_922X_DELL_D82),
2091 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2092 "unknown Dell", STAC_922X_DELL_D81),
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2094 "unknown Dell", STAC_922X_DELL_D81),
2095 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2096 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002097 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002098 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002099 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002100 {} /* terminator */
2101};
2102
Takashi Iwai2b635362011-05-02 12:33:43 +02002103static const unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002104 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2105 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2106 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2107 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002108};
2109
Takashi Iwai2b635362011-05-02 12:33:43 +02002110static const unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002111 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2112 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2113 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2114 0x40000100, 0x40000100
2115};
2116
Takashi Iwai2b635362011-05-02 12:33:43 +02002117static const unsigned int d965_5st_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002118 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2119 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2120 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2121 0x40000100, 0x40000100
2122};
2123
Takashi Iwai2b635362011-05-02 12:33:43 +02002124static const unsigned int d965_5st_no_fp_pin_configs[14] = {
Takashi Iwai679d92e2009-05-24 19:00:08 +02002125 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2126 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2127 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2128 0x40000100, 0x40000100
2129};
2130
Takashi Iwai2b635362011-05-02 12:33:43 +02002131static const unsigned int dell_3st_pin_configs[14] = {
Tobin Davis4ff076e2007-08-07 11:48:12 +02002132 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2133 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002134 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002135 0x40c003fc, 0x40000100
2136};
2137
Takashi Iwai2b635362011-05-02 12:33:43 +02002138static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002139 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002140 [STAC_D965_REF] = ref927x_pin_configs,
2141 [STAC_D965_3ST] = d965_3st_pin_configs,
2142 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002143 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002144 [STAC_DELL_3ST] = dell_3st_pin_configs,
2145 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002146 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002147};
2148
Takashi Iwaiea734962011-01-17 11:29:34 +01002149static const char * const stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002150 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002151 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002152 [STAC_D965_REF] = "ref",
2153 [STAC_D965_3ST] = "3stack",
2154 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002155 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002156 [STAC_DELL_3ST] = "dell-3stack",
2157 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002158 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002159};
2160
Takashi Iwai2b635362011-05-02 12:33:43 +02002161static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002162 /* SigmaTel reference board */
2163 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2164 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002165 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2166 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002167 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002168 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2169 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002170 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002171 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2172 "Intel D965", STAC_D965_3ST),
2173 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2174 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002175 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002176 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002177 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2178 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002179 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002180 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002181 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002182 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002183 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002184 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002185 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2186 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2187 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2188 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002189 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002190 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2191 "Intel D965", STAC_D965_5ST),
2192 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2193 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002194 /* volume-knob fixes */
2195 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002196 {} /* terminator */
2197};
2198
Takashi Iwai2b635362011-05-02 12:33:43 +02002199static const unsigned int ref9205_pin_configs[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +02002200 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002201 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002202 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002203};
2204
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002205/*
2206 STAC 9205 pin configs for
2207 102801F1
2208 102801F2
2209 102801FC
2210 102801FD
2211 10280204
2212 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002213 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002214 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002215*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002216static const unsigned int dell_9205_m42_pin_configs[12] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002217 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2218 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2219 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2220};
2221
2222/*
2223 STAC 9205 pin configs for
2224 102801F9
2225 102801FA
2226 102801FE
2227 102801FF (Dell Precision M4300)
2228 10280206
2229 10280200
2230 10280201
2231*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002232static const unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002233 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2234 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2235 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2236};
2237
Takashi Iwai2b635362011-05-02 12:33:43 +02002238static const unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002239 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2240 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2241 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2242};
2243
Takashi Iwai2b635362011-05-02 12:33:43 +02002244static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002245 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002246 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2247 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2248 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002249 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002250};
2251
Takashi Iwaiea734962011-01-17 11:29:34 +01002252static const char * const stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002253 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002254 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002255 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002256 [STAC_9205_DELL_M43] = "dell-m43",
2257 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002258 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002259};
2260
Takashi Iwai2b635362011-05-02 12:33:43 +02002261static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002262 /* SigmaTel reference board */
2263 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2264 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002265 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2266 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002267 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2268 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002269 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002270 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2271 "unknown Dell", STAC_9205_DELL_M42),
2272 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2273 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002274 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002275 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002276 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2277 "Dell Precision", STAC_9205_DELL_M43),
2278 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2279 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002280 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2281 "unknown Dell", STAC_9205_DELL_M42),
2282 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2283 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002284 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2285 "Dell Precision", STAC_9205_DELL_M43),
2286 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002287 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002288 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2289 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002290 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2291 "Dell Precision", STAC_9205_DELL_M43),
2292 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2293 "Dell Precision", STAC_9205_DELL_M43),
2294 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2295 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002296 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2297 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002298 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2299 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002300 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2301 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002302 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002303 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002304 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002305 {} /* terminator */
2306};
2307
Takashi Iwai330ee992009-02-20 14:33:36 +01002308static void stac92xx_set_config_regs(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002309 const unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002310{
2311 int i;
2312 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002313
Takashi Iwai330ee992009-02-20 14:33:36 +01002314 if (!pincfgs)
2315 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002316
Matthew Ranostay87d48362007-07-17 11:52:24 +02002317 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002318 if (spec->pin_nids[i] && pincfgs[i])
2319 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2320 pincfgs[i]);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002321}
2322
Matt2f2f4252005-04-13 14:45:30 +02002323/*
2324 * Analog playback callbacks
2325 */
2326static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2327 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002328 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002329{
2330 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002331 if (spec->stream_delay)
2332 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002333 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2334 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002335}
2336
2337static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2338 struct hda_codec *codec,
2339 unsigned int stream_tag,
2340 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002341 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002342{
2343 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002344 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002345}
2346
2347static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2348 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002349 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002350{
2351 struct sigmatel_spec *spec = codec->spec;
2352 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2353}
2354
2355/*
Mattdabbed62005-06-14 10:19:34 +02002356 * Digital playback callbacks
2357 */
2358static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2359 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002360 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002361{
2362 struct sigmatel_spec *spec = codec->spec;
2363 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2364}
2365
2366static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2367 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002368 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002369{
2370 struct sigmatel_spec *spec = codec->spec;
2371 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2372}
2373
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002374static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2375 struct hda_codec *codec,
2376 unsigned int stream_tag,
2377 unsigned int format,
2378 struct snd_pcm_substream *substream)
2379{
2380 struct sigmatel_spec *spec = codec->spec;
2381 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2382 stream_tag, format, substream);
2383}
2384
Takashi Iwai9411e212009-02-13 11:32:28 +01002385static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2386 struct hda_codec *codec,
2387 struct snd_pcm_substream *substream)
2388{
2389 struct sigmatel_spec *spec = codec->spec;
2390 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2391}
2392
Mattdabbed62005-06-14 10:19:34 +02002393
2394/*
Matt2f2f4252005-04-13 14:45:30 +02002395 * Analog capture callbacks
2396 */
2397static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2398 struct hda_codec *codec,
2399 unsigned int stream_tag,
2400 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002401 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002402{
2403 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002404 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002405
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002406 if (spec->powerdown_adcs) {
2407 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002408 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002409 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2410 }
2411 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002412 return 0;
2413}
2414
2415static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2416 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002417 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002418{
2419 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002420 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002421
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002422 snd_hda_codec_cleanup_stream(codec, nid);
2423 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002424 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002425 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002426 return 0;
2427}
2428
Takashi Iwai2b635362011-05-02 12:33:43 +02002429static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
Mattdabbed62005-06-14 10:19:34 +02002430 .substreams = 1,
2431 .channels_min = 2,
2432 .channels_max = 2,
2433 /* NID is set in stac92xx_build_pcms */
2434 .ops = {
2435 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002436 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002437 .prepare = stac92xx_dig_playback_pcm_prepare,
2438 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002439 },
2440};
2441
Takashi Iwai2b635362011-05-02 12:33:43 +02002442static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
Mattdabbed62005-06-14 10:19:34 +02002443 .substreams = 1,
2444 .channels_min = 2,
2445 .channels_max = 2,
2446 /* NID is set in stac92xx_build_pcms */
2447};
2448
Takashi Iwai2b635362011-05-02 12:33:43 +02002449static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
Matt2f2f4252005-04-13 14:45:30 +02002450 .substreams = 1,
2451 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002452 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002453 .nid = 0x02, /* NID to query formats and rates */
2454 .ops = {
2455 .open = stac92xx_playback_pcm_open,
2456 .prepare = stac92xx_playback_pcm_prepare,
2457 .cleanup = stac92xx_playback_pcm_cleanup
2458 },
2459};
2460
Takashi Iwai2b635362011-05-02 12:33:43 +02002461static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002462 .substreams = 1,
2463 .channels_min = 2,
2464 .channels_max = 2,
2465 .nid = 0x06, /* NID to query formats and rates */
2466 .ops = {
2467 .open = stac92xx_playback_pcm_open,
2468 .prepare = stac92xx_playback_pcm_prepare,
2469 .cleanup = stac92xx_playback_pcm_cleanup
2470 },
2471};
2472
Takashi Iwai2b635362011-05-02 12:33:43 +02002473static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002474 .channels_min = 2,
2475 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002476 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002477 .ops = {
2478 .prepare = stac92xx_capture_pcm_prepare,
2479 .cleanup = stac92xx_capture_pcm_cleanup
2480 },
2481};
2482
2483static int stac92xx_build_pcms(struct hda_codec *codec)
2484{
2485 struct sigmatel_spec *spec = codec->spec;
2486 struct hda_pcm *info = spec->pcm_rec;
2487
2488 codec->num_pcms = 1;
2489 codec->pcm_info = info;
2490
Mattc7d4b2f2005-06-27 14:59:41 +02002491 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002492 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002493 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2494 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002495 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002496 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002497 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002498
2499 if (spec->alt_switch) {
2500 codec->num_pcms++;
2501 info++;
2502 info->name = "STAC92xx Analog Alt";
2503 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2504 }
Matt2f2f4252005-04-13 14:45:30 +02002505
Mattdabbed62005-06-14 10:19:34 +02002506 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2507 codec->num_pcms++;
2508 info++;
2509 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002510 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002511 if (spec->multiout.dig_out_nid) {
2512 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2513 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2514 }
2515 if (spec->dig_in_nid) {
2516 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2517 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2518 }
2519 }
2520
Matt2f2f4252005-04-13 14:45:30 +02002521 return 0;
2522}
2523
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002524static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2525 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002526{
Takashi Iwai1327a322009-03-23 13:07:47 +01002527 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002528 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2529 if (pincap & AC_PINCAP_VREF_100)
2530 return AC_PINCTL_VREF_100;
2531 if (pincap & AC_PINCAP_VREF_80)
2532 return AC_PINCTL_VREF_80;
2533 if (pincap & AC_PINCAP_VREF_50)
2534 return AC_PINCTL_VREF_50;
2535 if (pincap & AC_PINCAP_VREF_GRD)
2536 return AC_PINCTL_VREF_GRD;
2537 return 0;
2538}
2539
Matt Porter403d1942005-11-29 15:00:51 +01002540static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2541
2542{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002543 snd_hda_codec_write_cache(codec, nid, 0,
2544 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002545}
2546
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002547#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2548
2549static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2550 struct snd_ctl_elem_value *ucontrol)
2551{
2552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2553 struct sigmatel_spec *spec = codec->spec;
2554
Takashi Iwaid7a89432008-11-12 09:48:04 +01002555 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002556 return 0;
2557}
2558
Takashi Iwai62558ce2009-07-29 14:23:09 +02002559static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002560
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002561static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2562 struct snd_ctl_elem_value *ucontrol)
2563{
2564 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2565 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002566 int nid = kcontrol->private_value;
2567
2568 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002569
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002570 /* check to be sure that the ports are up to date with
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002571 * switch changes
2572 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002573 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002574
2575 return 1;
2576}
2577
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002578static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2579 struct snd_ctl_elem_info *uinfo)
2580{
2581 int i;
Takashi Iwai2b635362011-05-02 12:33:43 +02002582 static const char * const texts[] = {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002583 "Mic In", "Line In", "Line Out"
2584 };
2585
2586 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2587 struct sigmatel_spec *spec = codec->spec;
2588 hda_nid_t nid = kcontrol->private_value;
2589
2590 if (nid == spec->mic_switch || nid == spec->line_switch)
2591 i = 3;
2592 else
2593 i = 2;
2594
2595 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2596 uinfo->value.enumerated.items = i;
2597 uinfo->count = 1;
2598 if (uinfo->value.enumerated.item >= i)
2599 uinfo->value.enumerated.item = i-1;
2600 strcpy(uinfo->value.enumerated.name,
2601 texts[uinfo->value.enumerated.item]);
2602
2603 return 0;
2604}
2605
2606static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2607 struct snd_ctl_elem_value *ucontrol)
2608{
2609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2610 hda_nid_t nid = kcontrol->private_value;
2611 unsigned int vref = stac92xx_vref_get(codec, nid);
2612
2613 if (vref == stac92xx_get_default_vref(codec, nid))
2614 ucontrol->value.enumerated.item[0] = 0;
2615 else if (vref == AC_PINCTL_VREF_GRD)
2616 ucontrol->value.enumerated.item[0] = 1;
2617 else if (vref == AC_PINCTL_VREF_HIZ)
2618 ucontrol->value.enumerated.item[0] = 2;
2619
2620 return 0;
2621}
2622
2623static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2624 struct snd_ctl_elem_value *ucontrol)
2625{
2626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2627 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002628 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002629 hda_nid_t nid = kcontrol->private_value;
2630
2631 if (ucontrol->value.enumerated.item[0] == 0)
2632 new_vref = stac92xx_get_default_vref(codec, nid);
2633 else if (ucontrol->value.enumerated.item[0] == 1)
2634 new_vref = AC_PINCTL_VREF_GRD;
2635 else if (ucontrol->value.enumerated.item[0] == 2)
2636 new_vref = AC_PINCTL_VREF_HIZ;
2637 else
2638 return 0;
2639
2640 if (new_vref != stac92xx_vref_get(codec, nid)) {
2641 error = stac92xx_vref_set(codec, nid, new_vref);
2642 return error;
2643 }
2644
2645 return 0;
2646}
2647
2648static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2649 struct snd_ctl_elem_info *uinfo)
2650{
Takashi Iwai2b635362011-05-02 12:33:43 +02002651 char *texts[2];
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002652 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2653 struct sigmatel_spec *spec = codec->spec;
2654
2655 if (kcontrol->private_value == spec->line_switch)
2656 texts[0] = "Line In";
2657 else
2658 texts[0] = "Mic In";
2659 texts[1] = "Line Out";
2660 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2661 uinfo->value.enumerated.items = 2;
2662 uinfo->count = 1;
2663
2664 if (uinfo->value.enumerated.item >= 2)
2665 uinfo->value.enumerated.item = 1;
2666 strcpy(uinfo->value.enumerated.name,
2667 texts[uinfo->value.enumerated.item]);
2668
2669 return 0;
2670}
Matt Porter403d1942005-11-29 15:00:51 +01002671
2672static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2673{
2674 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2675 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002676 hda_nid_t nid = kcontrol->private_value;
2677 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002678
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002679 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002680 return 0;
2681}
2682
2683static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2684{
2685 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2686 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002687 hda_nid_t nid = kcontrol->private_value;
2688 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2689 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002690
2691 spec->io_switch[io_idx] = val;
2692
2693 if (val)
2694 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002695 else {
2696 unsigned int pinctl = AC_PINCTL_IN_EN;
2697 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002698 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002699 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2700 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002701
2702 /* check the auto-mute again: we need to mute/unmute the speaker
2703 * appropriately according to the pin direction
2704 */
2705 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002706 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002707
Matt Porter403d1942005-11-29 15:00:51 +01002708 return 1;
2709}
2710
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002711#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2712
2713static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2714 struct snd_ctl_elem_value *ucontrol)
2715{
2716 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2717 struct sigmatel_spec *spec = codec->spec;
2718
2719 ucontrol->value.integer.value[0] = spec->clfe_swap;
2720 return 0;
2721}
2722
2723static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2724 struct snd_ctl_elem_value *ucontrol)
2725{
2726 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2727 struct sigmatel_spec *spec = codec->spec;
2728 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002729 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002730
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002731 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002732 return 0;
2733
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002734 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002735
2736 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2737 spec->clfe_swap ? 0x4 : 0x0);
2738
2739 return 1;
2740}
2741
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002742#define STAC_CODEC_HP_SWITCH(xname) \
2743 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2744 .name = xname, \
2745 .index = 0, \
2746 .info = stac92xx_hp_switch_info, \
2747 .get = stac92xx_hp_switch_get, \
2748 .put = stac92xx_hp_switch_put, \
2749 }
2750
Matt Porter403d1942005-11-29 15:00:51 +01002751#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2752 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2753 .name = xname, \
2754 .index = 0, \
2755 .info = stac92xx_io_switch_info, \
2756 .get = stac92xx_io_switch_get, \
2757 .put = stac92xx_io_switch_put, \
2758 .private_value = xpval, \
2759 }
2760
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002761#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2762 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2763 .name = xname, \
2764 .index = 0, \
2765 .info = stac92xx_clfe_switch_info, \
2766 .get = stac92xx_clfe_switch_get, \
2767 .put = stac92xx_clfe_switch_put, \
2768 .private_value = xpval, \
2769 }
Matt Porter403d1942005-11-29 15:00:51 +01002770
Mattc7d4b2f2005-06-27 14:59:41 +02002771enum {
2772 STAC_CTL_WIDGET_VOL,
2773 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002774 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002775 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002776 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002777 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002778 STAC_CTL_WIDGET_CLFE_SWITCH,
2779 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002780};
2781
Takashi Iwai2b635362011-05-02 12:33:43 +02002782static const struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002783 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2784 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002785 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002786 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002787 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002788 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002789 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002790 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002791};
2792
2793/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002794static struct snd_kcontrol_new *
2795stac_control_new(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002796 const struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002797 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002798 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002799{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002800 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002801
Takashi Iwai603c4012008-07-30 15:01:44 +02002802 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2803 knew = snd_array_new(&spec->kctls);
2804 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002805 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002806 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002807 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002808 if (!knew->name) {
2809 /* roolback */
2810 memset(knew, 0, sizeof(*knew));
2811 spec->kctls.alloced--;
2812 return NULL;
2813 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002814 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002815 return knew;
2816}
2817
2818static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002819 const struct snd_kcontrol_new *ktemp,
Takashi Iwaie3c75962009-01-23 11:57:22 +01002820 int idx, const char *name,
2821 unsigned long val)
2822{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002823 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002824 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002825 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002826 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002827 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002828 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002829 return 0;
2830}
2831
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002832static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2833 int type, int idx, const char *name,
2834 unsigned long val)
2835{
2836 return stac92xx_add_control_temp(spec,
2837 &stac92xx_control_templates[type],
2838 idx, name, val);
2839}
2840
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002841
2842/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002843static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2844 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002845{
2846 return stac92xx_add_control_idx(spec, type, 0, name, val);
2847}
2848
Takashi Iwai2b635362011-05-02 12:33:43 +02002849static const struct snd_kcontrol_new stac_input_src_temp = {
Takashi Iwaie3c75962009-01-23 11:57:22 +01002850 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2851 .name = "Input Source",
2852 .info = stac92xx_mux_enum_info,
2853 .get = stac92xx_mux_enum_get,
2854 .put = stac92xx_mux_enum_put,
2855};
2856
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002857static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2858 hda_nid_t nid, int idx)
2859{
2860 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2861 int control = 0;
2862 struct sigmatel_spec *spec = codec->spec;
2863 char name[22];
2864
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002865 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002866 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2867 && nid == spec->line_switch)
2868 control = STAC_CTL_WIDGET_IO_SWITCH;
2869 else if (snd_hda_query_pin_caps(codec, nid)
2870 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2871 control = STAC_CTL_WIDGET_DC_BIAS;
2872 else if (nid == spec->mic_switch)
2873 control = STAC_CTL_WIDGET_IO_SWITCH;
2874 }
2875
2876 if (control) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002877 strcpy(name, hda_get_input_pin_label(codec, nid, 1));
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002878 return stac92xx_add_control(codec->spec, control,
2879 strcat(name, " Jack Mode"), nid);
2880 }
2881
2882 return 0;
2883}
2884
Takashi Iwaie3c75962009-01-23 11:57:22 +01002885static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2886{
2887 struct snd_kcontrol_new *knew;
2888 struct hda_input_mux *imux = &spec->private_imux;
2889
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002890 if (spec->auto_mic)
2891 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002892 if (!spec->num_adcs || imux->num_items <= 1)
2893 return 0; /* no need for input source control */
2894 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002895 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002896 if (!knew)
2897 return -ENOMEM;
2898 knew->count = spec->num_adcs;
2899 return 0;
2900}
2901
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002902/* check whether the line-input can be used as line-out */
2903static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002904{
2905 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002906 struct auto_pin_cfg *cfg = &spec->autocfg;
2907 hda_nid_t nid;
2908 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002909 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002910
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002911 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2912 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002913 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02002914 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002915 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01002916 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002917 if (pincap & AC_PINCAP_OUT)
2918 return nid;
2919 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002920 }
Matt Porter403d1942005-11-29 15:00:51 +01002921 return 0;
2922}
2923
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002924static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2925
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002926/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002927static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002928{
2929 struct sigmatel_spec *spec = codec->spec;
2930 struct auto_pin_cfg *cfg = &spec->autocfg;
2931 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02002932 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002933
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002934 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002935 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2936 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002937 for (i = 0; i < cfg->num_inputs; i++) {
2938 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02002939 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002940 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002941 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2942 /* some laptops have an internal analog microphone
2943 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002944 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002945 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002946 if (pincap & AC_PINCAP_OUT) {
2947 *dac = get_unassigned_dac(codec, nid);
2948 if (*dac)
2949 return nid;
2950 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002951 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002952 }
2953 return 0;
2954}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002955
2956static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2957{
2958 int i;
2959
2960 for (i = 0; i < spec->multiout.num_dacs; i++) {
2961 if (spec->multiout.dac_nids[i] == nid)
2962 return 1;
2963 }
2964
2965 return 0;
2966}
2967
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002968static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2969{
2970 int i;
2971 if (is_in_dac_nids(spec, nid))
2972 return 1;
2973 for (i = 0; i < spec->autocfg.hp_outs; i++)
2974 if (spec->hp_dacs[i] == nid)
2975 return 1;
2976 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2977 if (spec->speaker_dacs[i] == nid)
2978 return 1;
2979 return 0;
2980}
2981
2982static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2983{
2984 struct sigmatel_spec *spec = codec->spec;
David Henningsson48718ea2011-10-05 09:49:05 +02002985 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002986 int j, conn_len;
David Henningsson48718ea2011-10-05 09:49:05 +02002987 hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002988 unsigned int wcaps, wtype;
2989
2990 conn_len = snd_hda_get_connections(codec, nid, conn,
2991 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002992 /* 92HD88: trace back up the link of nids to find the DAC */
2993 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2994 != AC_WID_AUD_OUT)) {
2995 nid = conn[0];
2996 conn_len = snd_hda_get_connections(codec, nid, conn,
2997 HDA_MAX_CONNECTIONS);
2998 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002999 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01003000 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003001 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003002 /* we check only analog outputs */
3003 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3004 continue;
3005 /* if this route has a free DAC, assign it */
3006 if (!check_all_dac_nids(spec, conn[j])) {
3007 if (conn_len > 1) {
3008 /* select this DAC in the pin's input mux */
3009 snd_hda_codec_write_cache(codec, nid, 0,
3010 AC_VERB_SET_CONNECT_SEL, j);
3011 }
3012 return conn[j];
3013 }
3014 }
David Henningsson48718ea2011-10-05 09:49:05 +02003015
3016 /* if all DACs are already assigned, connect to the primary DAC,
3017 unless we're assigning a secondary headphone */
3018 fallback_dac = spec->multiout.dac_nids[0];
3019 if (spec->multiout.hp_nid) {
3020 for (j = 0; j < cfg->hp_outs; j++)
3021 if (cfg->hp_pins[j] == nid) {
3022 fallback_dac = spec->multiout.hp_nid;
3023 break;
3024 }
3025 }
3026
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003027 if (conn_len > 1) {
3028 for (j = 0; j < conn_len; j++) {
David Henningsson48718ea2011-10-05 09:49:05 +02003029 if (conn[j] == fallback_dac) {
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003030 snd_hda_codec_write_cache(codec, nid, 0,
3031 AC_VERB_SET_CONNECT_SEL, j);
3032 break;
3033 }
3034 }
3035 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003036 return 0;
3037}
3038
3039static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3040static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3041
Matt Porter3cc08dc2006-01-23 15:27:49 +01003042/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02003043 * Fill in the dac_nids table from the parsed pin configuration
3044 * This function only works when every pin in line_out_pins[]
3045 * contains atleast one DAC in its connection list. Some 92xx
3046 * codecs are not connected directly to a DAC, such as the 9200
3047 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01003048 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003049static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003050{
3051 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003052 struct auto_pin_cfg *cfg = &spec->autocfg;
3053 int i;
3054 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02003055
Mattc7d4b2f2005-06-27 14:59:41 +02003056 for (i = 0; i < cfg->line_outs; i++) {
3057 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003058 dac = get_unassigned_dac(codec, nid);
3059 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003060 if (spec->multiout.num_dacs > 0) {
3061 /* we have already working output pins,
3062 * so let's drop the broken ones again
3063 */
3064 cfg->line_outs = spec->multiout.num_dacs;
3065 break;
3066 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003067 /* error out, no available DAC found */
3068 snd_printk(KERN_ERR
3069 "%s: No available DAC for pin 0x%x\n",
3070 __func__, nid);
3071 return -ENODEV;
3072 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003073 add_spec_dacs(spec, dac);
3074 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003075
Takashi Iwai139e0712009-03-06 12:10:41 +01003076 for (i = 0; i < cfg->hp_outs; i++) {
3077 nid = cfg->hp_pins[i];
3078 dac = get_unassigned_dac(codec, nid);
3079 if (dac) {
3080 if (!spec->multiout.hp_nid)
3081 spec->multiout.hp_nid = dac;
3082 else
3083 add_spec_extra_dacs(spec, dac);
3084 }
3085 spec->hp_dacs[i] = dac;
3086 }
3087
3088 for (i = 0; i < cfg->speaker_outs; i++) {
3089 nid = cfg->speaker_pins[i];
3090 dac = get_unassigned_dac(codec, nid);
3091 if (dac)
3092 add_spec_extra_dacs(spec, dac);
3093 spec->speaker_dacs[i] = dac;
3094 }
3095
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003096 /* add line-in as output */
3097 nid = check_line_out_switch(codec);
3098 if (nid) {
3099 dac = get_unassigned_dac(codec, nid);
3100 if (dac) {
3101 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3102 nid, cfg->line_outs);
3103 cfg->line_out_pins[cfg->line_outs] = nid;
3104 cfg->line_outs++;
3105 spec->line_switch = nid;
3106 add_spec_dacs(spec, dac);
3107 }
3108 }
3109 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003110 nid = check_mic_out_switch(codec, &dac);
3111 if (nid && dac) {
3112 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3113 nid, cfg->line_outs);
3114 cfg->line_out_pins[cfg->line_outs] = nid;
3115 cfg->line_outs++;
3116 spec->mic_switch = nid;
3117 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003118 }
3119
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003120 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003121 spec->multiout.num_dacs,
3122 spec->multiout.dac_nids[0],
3123 spec->multiout.dac_nids[1],
3124 spec->multiout.dac_nids[2],
3125 spec->multiout.dac_nids[3],
3126 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003127
Mattc7d4b2f2005-06-27 14:59:41 +02003128 return 0;
3129}
3130
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003131/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003132static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3133 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003134{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003135 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003136 char name[32];
3137 int err;
3138
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003139 if (!spec->check_volume_offset) {
3140 unsigned int caps, step, nums, db_scale;
3141 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3142 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3143 AC_AMPCAP_STEP_SIZE_SHIFT;
3144 step = (step + 1) * 25; /* in .01dB unit */
3145 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3146 AC_AMPCAP_NUM_STEPS_SHIFT;
3147 db_scale = nums * step;
3148 /* if dB scale is over -64dB, and finer enough,
3149 * let's reduce it to half
3150 */
3151 if (db_scale > 6400 && nums >= 0x1f)
3152 spec->volume_offset = nums / 2;
3153 spec->check_volume_offset = 1;
3154 }
3155
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003156 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003157 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003158 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3159 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003160 if (err < 0)
3161 return err;
3162 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003163 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003164 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3165 if (err < 0)
3166 return err;
3167 return 0;
3168}
3169
Takashi Iwai668b9652009-03-06 10:13:24 +01003170#define create_controls(codec, pfx, nid, chs) \
3171 create_controls_idx(codec, pfx, 0, nid, chs)
3172
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003173static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3174{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003175 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003176 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3177 return 1;
3178 } else {
Takashi Iwaidda14412011-05-02 11:29:30 +02003179 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3180 spec->dac_nids[spec->multiout.num_dacs] = nid;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003181 spec->multiout.num_dacs++;
3182 }
3183 return 0;
3184}
3185
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003186static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003187{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003188 int i;
3189 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3190 if (!spec->multiout.extra_out_nid[i]) {
3191 spec->multiout.extra_out_nid[i] = nid;
3192 return 0;
3193 }
3194 }
3195 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3196 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003197}
3198
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003199/* Create output controls
3200 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3201 */
3202static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3203 const hda_nid_t *pins,
3204 const hda_nid_t *dac_nids,
3205 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003206{
Takashi Iwai76624532008-12-19 10:09:47 +01003207 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaiea734962011-01-17 11:29:34 +01003208 static const char * const chname[4] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02003209 "Front", "Surround", NULL /*CLFE*/, "Side"
3210 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003211 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003212 int i, err;
3213 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003214
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003215 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003216 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003217 if (is_jack_detectable(codec, pins[i]))
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003218 spec->hp_detect = 1;
3219 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003220 nid = dac_nids[i];
3221 if (!nid)
3222 continue;
3223 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003224 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003225 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003226 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003227 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003228 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003229 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003230 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003231
3232 wid_caps = get_wcaps(codec, nid);
3233
3234 if (wid_caps & AC_WCAP_LR_SWAP) {
3235 err = stac92xx_add_control(spec,
3236 STAC_CTL_WIDGET_CLFE_SWITCH,
3237 "Swap Center/LFE Playback Switch", nid);
3238
3239 if (err < 0)
3240 return err;
3241 }
3242
Mattc7d4b2f2005-06-27 14:59:41 +02003243 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003244 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003245 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003246 switch (type) {
3247 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003248 name = "Headphone";
3249 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003250 break;
3251 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003252 name = "Speaker";
3253 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003254 break;
3255 default:
3256 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003257 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003258 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003259 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003260 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003261 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003262 return err;
3263 }
3264 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003265 return 0;
3266}
3267
Takashi Iwai6479c632009-07-28 18:20:25 +02003268static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3269 unsigned long sw, int idx)
3270{
3271 int err;
3272 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003273 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003274 if (err < 0)
3275 return err;
3276 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003277 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003278 if (err < 0)
3279 return err;
3280 return 0;
3281}
3282
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003283/* add playback controls from the parsed DAC table */
3284static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3285 const struct auto_pin_cfg *cfg)
3286{
3287 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003288 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003289 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003290 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003291
3292 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3293 spec->multiout.dac_nids,
3294 cfg->line_out_type);
3295 if (err < 0)
3296 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003297
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003298 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003299 err = stac92xx_add_control(spec,
3300 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003301 "Headphone as Line Out Switch",
3302 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003303 if (err < 0)
3304 return err;
3305 }
3306
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003307 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003308 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003309 break;
3310 nid = cfg->inputs[idx].pin;
3311 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3312 if (err < 0)
3313 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003314 }
Matt Porter403d1942005-11-29 15:00:51 +01003315
Mattc7d4b2f2005-06-27 14:59:41 +02003316 return 0;
3317}
3318
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003319/* add playback controls for Speaker and HP outputs */
3320static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3321 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003322{
3323 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003324 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003325
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003326 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3327 spec->hp_dacs, AUTO_PIN_HP_OUT);
3328 if (err < 0)
3329 return err;
3330
3331 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3332 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3333 if (err < 0)
3334 return err;
3335
Mattc7d4b2f2005-06-27 14:59:41 +02003336 return 0;
3337}
3338
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003339/* labels for mono mux outputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003340static const char * const stac92xx_mono_labels[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003341 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003342};
3343
3344/* create mono mux for mono out on capable codecs */
3345static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3346{
3347 struct sigmatel_spec *spec = codec->spec;
3348 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3349 int i, num_cons;
3350 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3351
3352 num_cons = snd_hda_get_connections(codec,
3353 spec->mono_nid,
3354 con_lst,
3355 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003356 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003357 return -EINVAL;
3358
Takashi Iwai10a20af2010-09-09 16:28:02 +02003359 for (i = 0; i < num_cons; i++)
3360 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3361 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003362
3363 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3364 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003365}
3366
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003367/* create PC beep volume controls */
3368static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3369 hda_nid_t nid)
3370{
3371 struct sigmatel_spec *spec = codec->spec;
3372 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003373 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3374
3375 if (spec->anabeep_nid == nid)
3376 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003377
3378 /* check for mute support for the the amp */
3379 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003380 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003381 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003382 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3383 if (err < 0)
3384 return err;
3385 }
3386
3387 /* check to see if there is volume support for the amp */
3388 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3389 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003390 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003391 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3392 if (err < 0)
3393 return err;
3394 }
3395 return 0;
3396}
3397
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003398#ifdef CONFIG_SND_HDA_INPUT_BEEP
3399#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3400
3401static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3402 struct snd_ctl_elem_value *ucontrol)
3403{
3404 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3405 ucontrol->value.integer.value[0] = codec->beep->enabled;
3406 return 0;
3407}
3408
3409static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3410 struct snd_ctl_elem_value *ucontrol)
3411{
3412 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003413 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003414}
3415
Takashi Iwai2b635362011-05-02 12:33:43 +02003416static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003417 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3418 .info = stac92xx_dig_beep_switch_info,
3419 .get = stac92xx_dig_beep_switch_get,
3420 .put = stac92xx_dig_beep_switch_put,
3421};
3422
3423static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3424{
3425 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003426 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003427}
3428#endif
3429
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003430static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3431{
3432 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003433 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003434
3435 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003436 hda_nid_t nid;
3437 unsigned int wcaps;
3438 unsigned long val;
3439
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003440 nid = spec->mux_nids[i];
3441 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003442 if (!(wcaps & AC_WCAP_OUT_AMP))
3443 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003444
Takashi Iwai667067d2009-08-13 18:14:42 +02003445 /* check whether already the same control was created as
3446 * normal Capture Volume.
3447 */
3448 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3449 for (j = 0; j < spec->num_caps; j++) {
3450 if (spec->capvols[j] == val)
3451 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003452 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003453 if (j < spec->num_caps)
3454 continue;
3455
3456 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3457 "Mux Capture Volume", val);
3458 if (err < 0)
3459 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003460 }
3461 return 0;
3462};
3463
Takashi Iwaiea734962011-01-17 11:29:34 +01003464static const char * const stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003465 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003466};
3467
3468static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3469{
3470 struct sigmatel_spec *spec = codec->spec;
3471 struct hda_input_mux *spdif_mux = &spec->private_smux;
Takashi Iwaiea734962011-01-17 11:29:34 +01003472 const char * const *labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003473 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003474 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003475
3476 num_cons = snd_hda_get_connections(codec,
3477 spec->smux_nids[0],
3478 con_lst,
3479 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003480 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003481 return -EINVAL;
3482
Matthew Ranostay65973632008-09-16 10:39:37 -04003483 if (!labels)
3484 labels = stac92xx_spdif_labels;
3485
Takashi Iwai10a20af2010-09-09 16:28:02 +02003486 for (i = 0; i < num_cons; i++)
3487 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003488
3489 return 0;
3490}
3491
Matt Porter8b657272006-10-26 17:12:59 +02003492/* labels for dmic mux inputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003493static const char * const stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003494 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3495 "Digital Mic 3", "Digital Mic 4"
3496};
3497
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003498static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3499 int idx)
3500{
3501 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3502 int nums;
3503 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3504 if (idx >= 0 && idx < nums)
3505 return conn[idx];
3506 return 0;
3507}
3508
Takashi Iwai8d087c72011-06-28 12:45:47 +02003509/* look for NID recursively */
3510#define get_connection_index(codec, mux, nid) \
3511 snd_hda_get_conn_index(codec, mux, nid, 1)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003512
Takashi Iwai667067d2009-08-13 18:14:42 +02003513/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003514/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003515static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003516 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003517{
3518 unsigned int caps, nums;
3519 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003520 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003521
Takashi Iwai96f845d2009-08-29 00:49:36 +02003522 if (direction == HDA_OUTPUT)
3523 caps = AC_WCAP_OUT_AMP;
3524 else
3525 caps = AC_WCAP_IN_AMP;
3526 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003527 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003528 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003529 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3530 if (!nums)
3531 return 0;
3532 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003533 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3534 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003535 if (err < 0)
3536 return err;
3537 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003538}
3539
Matt Porter8b657272006-10-26 17:12:59 +02003540/* create playback/capture controls for input pins on dmic capable codecs */
3541static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3542 const struct auto_pin_cfg *cfg)
3543{
3544 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003545 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003546 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003547 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003548 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003549
Takashi Iwai10a20af2010-09-09 16:28:02 +02003550 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003551
Matt Porter8b657272006-10-26 17:12:59 +02003552 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003553 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003554 int index, type_idx;
Takashi Iwai5207e102009-07-30 13:09:08 +02003555 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003556
Takashi Iwai667067d2009-08-13 18:14:42 +02003557 nid = spec->dmic_nids[i];
3558 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3559 continue;
3560 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003561 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3562 continue;
3563
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003564 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3565 if (index < 0)
3566 continue;
3567
Takashi Iwai10a20af2010-09-09 16:28:02 +02003568 label = hda_get_input_pin_label(codec, nid, 1);
3569 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai2d7ec122010-12-23 10:16:05 +01003570 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3571 snd_hda_add_imux_item(imux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003572
Takashi Iwai10a20af2010-09-09 16:28:02 +02003573 err = create_elem_capture_vol(codec, nid, label, type_idx,
3574 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003575 if (err < 0)
3576 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003577 if (!err) {
3578 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003579 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003580 if (err < 0)
3581 return err;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003582 if (!err) {
3583 nid = get_connected_node(codec,
3584 spec->dmux_nids[0], index);
3585 if (nid)
3586 err = create_elem_capture_vol(codec,
3587 nid, label,
3588 type_idx, HDA_INPUT);
3589 if (err < 0)
3590 return err;
3591 }
Takashi Iwai96f845d2009-08-29 00:49:36 +02003592 }
Matt Porter8b657272006-10-26 17:12:59 +02003593 }
3594
3595 return 0;
3596}
3597
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003598static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003599 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003600{
3601 unsigned int cfg;
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003602 unsigned int type;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003603
3604 if (!nid)
3605 return 0;
3606 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003607 type = get_defcfg_device(cfg);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003608 switch (snd_hda_get_input_pin_attr(cfg)) {
3609 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003610 if (*fixed)
3611 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003612 if (type != AC_JACK_MIC_IN)
3613 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003614 *fixed = nid;
3615 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003616 case INPUT_PIN_ATTR_UNUSED:
3617 break;
3618 case INPUT_PIN_ATTR_DOCK:
3619 if (*dock)
3620 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003621 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
3622 return 1; /* invalid type */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003623 *dock = nid;
3624 break;
3625 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003626 if (*ext)
3627 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003628 if (type != AC_JACK_MIC_IN)
3629 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003630 *ext = nid;
3631 break;
3632 }
3633 return 0;
3634}
3635
3636static int set_mic_route(struct hda_codec *codec,
3637 struct sigmatel_mic_route *mic,
3638 hda_nid_t pin)
3639{
3640 struct sigmatel_spec *spec = codec->spec;
3641 struct auto_pin_cfg *cfg = &spec->autocfg;
3642 int i;
3643
3644 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003645 if (pin == 0)
3646 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003647 for (i = 0; i < cfg->num_inputs; i++) {
3648 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003649 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003650 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003651 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003652 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003653 i = get_connection_index(codec, spec->mux_nids[0], pin);
3654 if (i < 0)
3655 return -1;
3656 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003657 mic->dmux_idx = -1;
3658 if (spec->dmux_nids)
3659 mic->dmux_idx = get_connection_index(codec,
3660 spec->dmux_nids[0],
3661 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003662 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003663 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003664 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3665 if (i < 0)
3666 return -1;
3667 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003668 mic->mux_idx = -1;
3669 if (spec->mux_nids)
3670 mic->mux_idx = get_connection_index(codec,
3671 spec->mux_nids[0],
3672 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003673 }
3674 return 0;
3675}
3676
3677/* return non-zero if the device is for automatic mic switch */
3678static int stac_check_auto_mic(struct hda_codec *codec)
3679{
3680 struct sigmatel_spec *spec = codec->spec;
3681 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02003682 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003683 int i;
3684
Charles Chin99077902010-09-17 10:22:32 +02003685 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003686 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02003687 if (check_mic_pin(codec, cfg->inputs[i].pin,
3688 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003689 return 0;
3690 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02003691 if (check_mic_pin(codec, spec->dmic_nids[i],
3692 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003693 return 0;
Takashi Iwai80c67852011-01-13 08:08:08 +01003694 if (!fixed || (!ext && !dock))
Charles Chin99077902010-09-17 10:22:32 +02003695 return 0; /* no input to switch */
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003696 if (!is_jack_detectable(codec, ext))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003697 return 0; /* no unsol support */
3698 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02003699 set_mic_route(codec, &spec->int_mic, fixed) ||
3700 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003701 return 0; /* something is wrong */
3702 return 1;
3703}
3704
Mattc7d4b2f2005-06-27 14:59:41 +02003705/* create playback/capture controls for input pins */
3706static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3707{
3708 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003709 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003710 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003711 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02003712
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003713 for (i = 0; i < cfg->num_inputs; i++) {
3714 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003715 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02003716
Takashi Iwai314634b2006-09-21 11:56:18 +02003717 index = -1;
3718 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003719 index = get_connection_index(codec, spec->mux_nids[j],
3720 nid);
3721 if (index >= 0)
3722 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003723 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003724 if (index < 0)
3725 continue;
3726
Takashi Iwai10a20af2010-09-09 16:28:02 +02003727 label = hda_get_autocfg_input_label(codec, cfg, i);
3728 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003729
Takashi Iwai667067d2009-08-13 18:14:42 +02003730 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003731 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003732 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003733 if (err < 0)
3734 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003735 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003736 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003737
Steve Longerbeam7b043892007-05-03 20:50:03 +02003738 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003739 /*
3740 * Set the current input for the muxes.
3741 * The STAC9221 has two input muxes with identical source
3742 * NID lists. Hopefully this won't get confused.
3743 */
3744 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003745 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3746 AC_VERB_SET_CONNECT_SEL,
3747 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003748 }
3749 }
3750
Mattc7d4b2f2005-06-27 14:59:41 +02003751 return 0;
3752}
3753
Mattc7d4b2f2005-06-27 14:59:41 +02003754static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3755{
3756 struct sigmatel_spec *spec = codec->spec;
3757 int i;
3758
3759 for (i = 0; i < spec->autocfg.line_outs; i++) {
3760 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3761 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3762 }
3763}
3764
3765static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3766{
3767 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003768 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003769
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003770 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3771 hda_nid_t pin;
3772 pin = spec->autocfg.hp_pins[i];
3773 if (pin) /* connect to front */
3774 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3775 }
3776 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3777 hda_nid_t pin;
3778 pin = spec->autocfg.speaker_pins[i];
3779 if (pin) /* connect to front */
3780 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3781 }
Mattc7d4b2f2005-06-27 14:59:41 +02003782}
3783
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003784static int is_dual_headphones(struct hda_codec *codec)
3785{
3786 struct sigmatel_spec *spec = codec->spec;
3787 int i, valid_hps;
3788
3789 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3790 spec->autocfg.hp_outs <= 1)
3791 return 0;
3792 valid_hps = 0;
3793 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3794 hda_nid_t nid = spec->autocfg.hp_pins[i];
3795 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3796 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3797 continue;
3798 valid_hps++;
3799 }
3800 return (valid_hps > 1);
3801}
3802
3803
Charles Chin9009b0e2011-11-03 10:27:27 +01003804static int stac92xx_parse_auto_config(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003805{
3806 struct sigmatel_spec *spec = codec->spec;
Charles Chin9009b0e2011-11-03 10:27:27 +01003807 hda_nid_t dig_out = 0, dig_in = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003808 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003809 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003810
Matt Porter8b657272006-10-26 17:12:59 +02003811 if ((err = snd_hda_parse_pin_def_config(codec,
3812 &spec->autocfg,
3813 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003814 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003815 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003816 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003817
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003818 /* If we have no real line-out pin and multiple hp-outs, HPs should
3819 * be set up as multi-channel outputs.
3820 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003821 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003822 /* Copy hp_outs to line_outs, backup line_outs in
3823 * speaker_outs so that the following routines can handle
3824 * HP pins as primary outputs.
3825 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003826 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003827 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3828 sizeof(spec->autocfg.line_out_pins));
3829 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3830 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3831 sizeof(spec->autocfg.hp_pins));
3832 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003833 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3834 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003835 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003836 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003837 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003838 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3839 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003840 u32 caps = query_amp_caps(codec,
3841 spec->autocfg.mono_out_pin, dir);
3842 hda_nid_t conn_list[1];
3843
3844 /* get the mixer node and then the mono mux if it exists */
3845 if (snd_hda_get_connections(codec,
3846 spec->autocfg.mono_out_pin, conn_list, 1) &&
3847 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003848 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003849
3850 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003851 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003852 /* LR swap check, some stac925x have a mux that
3853 * changes the DACs output path instead of the
3854 * mono-mux path.
3855 */
3856 if (wid_type == AC_WID_AUD_SEL &&
3857 !(wcaps & AC_WCAP_LR_SWAP))
3858 spec->mono_nid = conn_list[0];
3859 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003860 if (dir) {
3861 hda_nid_t nid = spec->autocfg.mono_out_pin;
3862
3863 /* most mono outs have a least a mute/unmute switch */
3864 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3865 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3866 "Mono Playback Switch",
3867 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003868 if (err < 0)
3869 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003870 /* check for volume support for the amp */
3871 if ((caps & AC_AMPCAP_NUM_STEPS)
3872 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3873 err = stac92xx_add_control(spec,
3874 STAC_CTL_WIDGET_VOL,
3875 "Mono Playback Volume",
3876 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3877 if (err < 0)
3878 return err;
3879 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003880 }
3881
3882 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3883 AC_PINCTL_OUT_EN);
3884 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003885
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003886 if (!spec->multiout.num_dacs) {
3887 err = stac92xx_auto_fill_dac_nids(codec);
3888 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003889 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003890 err = stac92xx_auto_create_multi_out_ctls(codec,
3891 &spec->autocfg);
3892 if (err < 0)
3893 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003894 }
Mattc7d4b2f2005-06-27 14:59:41 +02003895
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003896 /* setup analog beep controls */
3897 if (spec->anabeep_nid > 0) {
3898 err = stac92xx_auto_create_beep_ctls(codec,
3899 spec->anabeep_nid);
3900 if (err < 0)
3901 return err;
3902 }
3903
3904 /* setup digital beep controls and input device */
3905#ifdef CONFIG_SND_HDA_INPUT_BEEP
3906 if (spec->digbeep_nid > 0) {
3907 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003908 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003909
3910 err = stac92xx_auto_create_beep_ctls(codec, nid);
3911 if (err < 0)
3912 return err;
3913 err = snd_hda_attach_beep_device(codec, nid);
3914 if (err < 0)
3915 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003916 if (codec->beep) {
3917 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01003918 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003919 /* if no beep switch is available, make its own one */
3920 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3921 if (!(caps & AC_AMPCAP_MUTE)) {
3922 err = stac92xx_beep_switch_ctl(codec);
3923 if (err < 0)
3924 return err;
3925 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003926 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003927 }
3928#endif
3929
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003930 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003931 if (err < 0)
3932 return err;
3933
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003934 /* All output parsing done, now restore the swapped hp pins */
3935 if (hp_swap) {
3936 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3937 sizeof(spec->autocfg.hp_pins));
3938 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3939 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3940 spec->autocfg.line_outs = 0;
3941 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003942
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003943 if (stac_check_auto_mic(codec)) {
3944 spec->auto_mic = 1;
3945 /* only one capture for auto-mic */
3946 spec->num_adcs = 1;
3947 spec->num_caps = 1;
3948 spec->num_muxes = 1;
3949 }
3950
Takashi Iwai6479c632009-07-28 18:20:25 +02003951 for (i = 0; i < spec->num_caps; i++) {
3952 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3953 spec->capsws[i], i);
3954 if (err < 0)
3955 return err;
3956 }
3957
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003958 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003959 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003960 return err;
3961
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003962 if (spec->mono_nid > 0) {
3963 err = stac92xx_auto_create_mono_output_ctls(codec);
3964 if (err < 0)
3965 return err;
3966 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003967 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003968 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3969 &spec->autocfg)) < 0)
3970 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003971 if (spec->num_muxes > 0) {
3972 err = stac92xx_auto_create_mux_input_ctls(codec);
3973 if (err < 0)
3974 return err;
3975 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003976 if (spec->num_smuxes > 0) {
3977 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3978 if (err < 0)
3979 return err;
3980 }
Matt Porter8b657272006-10-26 17:12:59 +02003981
Takashi Iwaie3c75962009-01-23 11:57:22 +01003982 err = stac92xx_add_input_source(spec);
3983 if (err < 0)
3984 return err;
3985
Mattc7d4b2f2005-06-27 14:59:41 +02003986 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003987 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003988 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003989
Charles Chin9009b0e2011-11-03 10:27:27 +01003990 /* find digital out and in converters */
3991 for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
3992 unsigned int wid_caps = get_wcaps(codec, i);
3993 if (wid_caps & AC_WCAP_DIGITAL) {
3994 switch (get_wcaps_type(wid_caps)) {
3995 case AC_WID_AUD_OUT:
3996 if (!dig_out)
3997 dig_out = i;
3998 break;
3999 case AC_WID_AUD_IN:
4000 if (!dig_in)
4001 dig_in = i;
4002 break;
4003 }
4004 }
4005 }
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004006 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004007 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004008 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004009 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02004010
Takashi Iwai603c4012008-07-30 15:01:44 +02004011 if (spec->kctls.list)
4012 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004013
4014 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05004015 if (!spec->dinput_mux)
4016 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004017 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01004018 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02004019 return 1;
4020}
4021
Takashi Iwai82bc9552006-03-21 11:24:42 +01004022/* add playback controls for HP output */
4023static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4024 struct auto_pin_cfg *cfg)
4025{
4026 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004027 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01004028
4029 if (! pin)
4030 return 0;
4031
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004032 if (is_jack_detectable(codec, pin))
Takashi Iwai82bc9552006-03-21 11:24:42 +01004033 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004034
4035 return 0;
4036}
4037
Richard Fish160ea0d2006-09-06 13:58:25 +02004038/* add playback controls for LFE output */
4039static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4040 struct auto_pin_cfg *cfg)
4041{
4042 struct sigmatel_spec *spec = codec->spec;
4043 int err;
4044 hda_nid_t lfe_pin = 0x0;
4045 int i;
4046
4047 /*
4048 * search speaker outs and line outs for a mono speaker pin
4049 * with an amp. If one is found, add LFE controls
4050 * for it.
4051 */
4052 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4053 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004054 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004055 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4056 if (wcaps == AC_WCAP_OUT_AMP)
4057 /* found a mono speaker with an amp, must be lfe */
4058 lfe_pin = pin;
4059 }
4060
4061 /* if speaker_outs is 0, then speakers may be in line_outs */
4062 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4063 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4064 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004065 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004066 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004067 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004068 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004069 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4070 if (wcaps == AC_WCAP_OUT_AMP)
4071 /* found a mono speaker with an amp,
4072 must be lfe */
4073 lfe_pin = pin;
4074 }
4075 }
4076 }
4077
4078 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004079 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004080 if (err < 0)
4081 return err;
4082 }
4083
4084 return 0;
4085}
4086
Mattc7d4b2f2005-06-27 14:59:41 +02004087static int stac9200_parse_auto_config(struct hda_codec *codec)
4088{
4089 struct sigmatel_spec *spec = codec->spec;
4090 int err;
4091
Kailang Yangdf694da2005-12-05 19:42:22 +01004092 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004093 return err;
4094
4095 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4096 return err;
4097
Takashi Iwai82bc9552006-03-21 11:24:42 +01004098 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4099 return err;
4100
Richard Fish160ea0d2006-09-06 13:58:25 +02004101 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4102 return err;
4103
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004104 if (spec->num_muxes > 0) {
4105 err = stac92xx_auto_create_mux_input_ctls(codec);
4106 if (err < 0)
4107 return err;
4108 }
4109
Takashi Iwaie3c75962009-01-23 11:57:22 +01004110 err = stac92xx_add_input_source(spec);
4111 if (err < 0)
4112 return err;
4113
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004114 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004115 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004116 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004117 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004118
Takashi Iwai603c4012008-07-30 15:01:44 +02004119 if (spec->kctls.list)
4120 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004121
4122 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004123 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004124
4125 return 1;
4126}
4127
Sam Revitch62fe78e2006-05-10 15:09:17 +02004128/*
4129 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4130 * funky external mute control using GPIO pins.
4131 */
4132
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004133static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004134 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004135{
4136 unsigned int gpiostate, gpiomask, gpiodir;
4137
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004138 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4139
Sam Revitch62fe78e2006-05-10 15:09:17 +02004140 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4141 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004142 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004143
4144 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4145 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004146 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004147
4148 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4149 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004150 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004151
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004152 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004153 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4154
4155 snd_hda_codec_write(codec, codec->afg, 0,
4156 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004157 snd_hda_codec_read(codec, codec->afg, 0,
4158 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004159
4160 msleep(1);
4161
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004162 snd_hda_codec_read(codec, codec->afg, 0,
4163 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004164}
4165
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004166static int stac92xx_add_jack(struct hda_codec *codec,
4167 hda_nid_t nid, int type)
4168{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004169#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai330ee992009-02-20 14:33:36 +01004170 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004171 int connectivity = get_defcfg_connect(def_conf);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004172
4173 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4174 return 0;
4175
David Henningssoneb335a42011-10-03 16:25:42 +02004176 return snd_hda_input_jack_add(codec, nid, type, NULL);
4177#else
Takashi Iwai95c09092009-04-14 16:15:29 +02004178 return 0;
David Henningssoneb335a42011-10-03 16:25:42 +02004179#endif /* CONFIG_SND_HDA_INPUT_JACK */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004180}
4181
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004182static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4183 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004184{
4185 struct sigmatel_event *event;
4186
4187 snd_array_init(&spec->events, sizeof(*event), 32);
4188 event = snd_array_new(&spec->events);
4189 if (!event)
4190 return -ENOMEM;
4191 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004192 event->type = type;
4193 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004194 event->data = data;
4195
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004196 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004197}
4198
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004199static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004200 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004201{
4202 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004203 struct sigmatel_event *event = spec->events.list;
4204 int i;
4205
4206 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004207 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004208 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004209 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004210 return NULL;
4211}
4212
4213static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4214 unsigned char tag)
4215{
4216 struct sigmatel_spec *spec = codec->spec;
4217 struct sigmatel_event *event = spec->events.list;
4218 int i;
4219
4220 for (i = 0; i < spec->events.used; i++, event++) {
4221 if (event->tag == tag)
4222 return event;
4223 }
4224 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004225}
4226
Takashi Iwai62558ce2009-07-29 14:23:09 +02004227/* check if given nid is a valid pin and no other events are assigned
4228 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4229 * Otherwise, returns zero.
4230 */
4231static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4232 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004233{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004234 struct sigmatel_event *event;
4235 int tag;
4236
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004237 if (!is_jack_detectable(codec, nid))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004238 return 0;
4239 event = stac_get_event(codec, nid);
4240 if (event) {
4241 if (event->type != type)
4242 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004243 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004244 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004245 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004246 if (tag < 0)
4247 return 0;
4248 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004249 snd_hda_codec_write_cache(codec, nid, 0,
4250 AC_VERB_SET_UNSOLICITED_ENABLE,
4251 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004252 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004253}
4254
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004255static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4256{
4257 int i;
4258 for (i = 0; i < cfg->hp_outs; i++)
4259 if (cfg->hp_pins[i] == nid)
4260 return 1; /* nid is a HP-Out */
4261
4262 return 0; /* nid is not a HP-Out */
4263};
4264
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004265static void stac92xx_power_down(struct hda_codec *codec)
4266{
4267 struct sigmatel_spec *spec = codec->spec;
4268
4269 /* power down inactive DACs */
Takashi Iwai2b635362011-05-02 12:33:43 +02004270 const hda_nid_t *dac;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004271 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004272 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004273 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004274 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4275}
4276
Takashi Iwaif73d3582008-11-25 08:21:51 +01004277static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4278 int enable);
4279
Takashi Iwai014c41f2009-12-27 13:53:24 +01004280static inline int get_int_hint(struct hda_codec *codec, const char *key,
4281 int *valp)
4282{
4283 const char *p;
4284 p = snd_hda_get_hint(codec, key);
4285 if (p) {
4286 unsigned long val;
4287 if (!strict_strtoul(p, 0, &val)) {
4288 *valp = val;
4289 return 1;
4290 }
4291 }
4292 return 0;
4293}
4294
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004295/* override some hints from the hwdep entry */
4296static void stac_store_hints(struct hda_codec *codec)
4297{
4298 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004299 int val;
4300
4301 val = snd_hda_get_bool_hint(codec, "hp_detect");
4302 if (val >= 0)
4303 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004304 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004305 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4306 spec->gpio_mask;
4307 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004308 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4309 spec->gpio_mask &= spec->gpio_mask;
4310 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4311 spec->gpio_dir &= spec->gpio_mask;
4312 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4313 spec->eapd_mask &= spec->gpio_mask;
4314 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4315 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004316 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4317 if (val >= 0)
4318 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004319 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4320 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004321 if (spec->gpio_led <= 8) {
4322 spec->gpio_mask |= spec->gpio_led;
4323 spec->gpio_dir |= spec->gpio_led;
4324 if (spec->gpio_led_polarity)
4325 spec->gpio_data |= spec->gpio_led;
4326 }
Takashi Iwai043958e2009-12-26 10:36:12 +01004327 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004328}
4329
Mattc7d4b2f2005-06-27 14:59:41 +02004330static int stac92xx_init(struct hda_codec *codec)
4331{
4332 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004333 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004334 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004335 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004336
Mattc7d4b2f2005-06-27 14:59:41 +02004337 snd_hda_sequence_write(codec, spec->init);
4338
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004339 /* power down adcs initially */
4340 if (spec->powerdown_adcs)
4341 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004342 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004343 spec->adc_nids[i], 0,
4344 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004345
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004346 /* override some hints */
4347 stac_store_hints(codec);
4348
Takashi Iwaif73d3582008-11-25 08:21:51 +01004349 /* set up GPIO */
4350 gpio = spec->gpio_data;
4351 /* turn on EAPD statically when spec->eapd_switch isn't set.
4352 * otherwise, unsol event will turn it on/off dynamically
4353 */
4354 if (!spec->eapd_switch)
4355 gpio |= spec->eapd_mask;
4356 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4357
Takashi Iwai82bc9552006-03-21 11:24:42 +01004358 /* set up pins */
4359 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004360 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004361 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004362 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004363 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004364 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004365 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4366 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004367 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004368 for (i = 0; i < cfg->line_outs; i++) {
4369 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004370 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4371 }
4372 }
4373
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004374 /* force to enable the first line-out; the others are set up
4375 * in unsol_event
4376 */
4377 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004378 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004379 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004380 if (cfg->hp_pins[0])
4381 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4382 else if (cfg->line_out_pins[0])
4383 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004384 } else {
4385 stac92xx_auto_init_multi_out(codec);
4386 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004387 for (i = 0; i < cfg->hp_outs; i++)
4388 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004389 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004390 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004391 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004392 if (spec->dmux_nids)
4393 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004394 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004395 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4396 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004397 if (enable_pin_detect(codec, spec->dock_mic.pin,
4398 STAC_MIC_EVENT))
4399 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004400 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004401 for (i = 0; i < cfg->num_inputs; i++) {
4402 hda_nid_t nid = cfg->inputs[i].pin;
4403 int type = cfg->inputs[i].type;
4404 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004405 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004406 /* for mic pins, force to initialize */
4407 pinctl = stac92xx_get_default_vref(codec, nid);
4408 pinctl |= AC_PINCTL_IN_EN;
4409 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4410 } else {
4411 pinctl = snd_hda_codec_read(codec, nid, 0,
4412 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4413 /* if PINCTL already set then skip */
4414 /* Also, if both INPUT and OUTPUT are set,
4415 * it must be a BIOS bug; need to override, too
4416 */
4417 if (!(pinctl & AC_PINCTL_IN_EN) ||
4418 (pinctl & AC_PINCTL_OUT_EN)) {
4419 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004420 pinctl |= AC_PINCTL_IN_EN;
4421 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004422 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004423 }
4424 conf = snd_hda_codec_get_pincfg(codec, nid);
4425 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4426 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4427 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004428 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004429 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004430 for (i = 0; i < spec->num_dmics; i++)
4431 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4432 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004433 if (cfg->dig_out_pins[0])
4434 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004435 AC_PINCTL_OUT_EN);
4436 if (cfg->dig_in_pin)
4437 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4438 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004439 for (i = 0; i < spec->num_pwrs; i++) {
4440 hda_nid_t nid = spec->pwr_nids[i];
4441 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004442
Takashi Iwaieb632122008-12-19 16:39:48 +01004443 /* power on when no jack detection is available */
4444 if (!spec->hp_detect) {
4445 stac_toggle_power_map(codec, nid, 1);
4446 continue;
4447 }
4448
4449 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004450 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004451
Takashi Iwaif73d3582008-11-25 08:21:51 +01004452 pinctl = snd_hda_codec_read(codec, nid, 0,
4453 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4454 /* outputs are only ports capable of power management
4455 * any attempts on powering down a input port cause the
4456 * referenced VREF to act quirky.
4457 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004458 if (pinctl & AC_PINCTL_IN_EN) {
4459 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004460 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004461 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004462 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004463 def_conf = get_defcfg_connect(def_conf);
4464 /* skip any ports that don't have jacks since presence
4465 * detection is useless */
4466 if (def_conf != AC_JACK_PORT_COMPLEX) {
4467 if (def_conf != AC_JACK_PORT_NONE)
4468 stac_toggle_power_map(codec, nid, 1);
4469 continue;
4470 }
Charles Chinafef2cf2011-11-11 08:05:28 +01004471 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004472 stac_issue_unsol_event(codec, nid);
Charles Chinafef2cf2011-11-11 08:05:28 +01004473 continue;
4474 }
4475 /* none of the above, turn the port OFF */
4476 stac_toggle_power_map(codec, nid, 0);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004477 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004478
Takashi Iwaic21bd022010-02-08 15:16:08 +01004479 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004480 if (spec->gpio_led)
4481 hda_call_check_power_status(codec, 0x01);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004482 if (spec->dac_list)
4483 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004484 return 0;
4485}
4486
Takashi Iwai603c4012008-07-30 15:01:44 +02004487static void stac92xx_free_kctls(struct hda_codec *codec)
4488{
4489 struct sigmatel_spec *spec = codec->spec;
4490
4491 if (spec->kctls.list) {
4492 struct snd_kcontrol_new *kctl = spec->kctls.list;
4493 int i;
4494 for (i = 0; i < spec->kctls.used; i++)
4495 kfree(kctl[i].name);
4496 }
4497 snd_array_free(&spec->kctls);
4498}
4499
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004500static void stac92xx_shutup_pins(struct hda_codec *codec)
4501{
4502 unsigned int i, def_conf;
4503
4504 if (codec->bus->shutdown)
4505 return;
4506 for (i = 0; i < codec->init_pins.used; i++) {
4507 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4508 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4509 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
4510 snd_hda_codec_write(codec, pin->nid, 0,
4511 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4512 }
4513}
4514
Takashi Iwai167eae52009-11-06 15:47:50 +01004515static void stac92xx_shutup(struct hda_codec *codec)
4516{
4517 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004518
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004519 stac92xx_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004520
4521 if (spec->eapd_mask)
4522 stac_gpio_set(codec, spec->gpio_mask,
4523 spec->gpio_dir, spec->gpio_data &
4524 ~spec->eapd_mask);
4525}
4526
Matt2f2f4252005-04-13 14:45:30 +02004527static void stac92xx_free(struct hda_codec *codec)
4528{
Mattc7d4b2f2005-06-27 14:59:41 +02004529 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004530
4531 if (! spec)
4532 return;
4533
Takashi Iwai167eae52009-11-06 15:47:50 +01004534 stac92xx_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004535 snd_hda_input_jack_free(codec);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004536 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004537
Mattc7d4b2f2005-06-27 14:59:41 +02004538 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004539 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004540}
4541
Matt4e550962005-07-04 17:51:39 +02004542static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4543 unsigned int flag)
4544{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004545 unsigned int old_ctl, pin_ctl;
4546
4547 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004548 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004549
Takashi Iwaif9acba42007-05-29 18:01:06 +02004550 if (pin_ctl & AC_PINCTL_IN_EN) {
4551 /*
4552 * we need to check the current set-up direction of
4553 * shared input pins since they can be switched via
4554 * "xxx as Output" mixer switch
4555 */
4556 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004557 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004558 return;
4559 }
4560
Takashi Iwai8ce84192009-01-22 16:59:20 +01004561 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004562 /* if setting pin direction bits, clear the current
4563 direction bits first */
4564 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4565 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4566
Takashi Iwai8ce84192009-01-22 16:59:20 +01004567 pin_ctl |= flag;
4568 if (old_ctl != pin_ctl)
4569 snd_hda_codec_write_cache(codec, nid, 0,
4570 AC_VERB_SET_PIN_WIDGET_CONTROL,
4571 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004572}
4573
4574static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4575 unsigned int flag)
4576{
4577 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4578 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004579 if (pin_ctl & flag)
4580 snd_hda_codec_write_cache(codec, nid, 0,
4581 AC_VERB_SET_PIN_WIDGET_CONTROL,
4582 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004583}
4584
Takashi Iwaid56757a2009-11-18 08:00:14 +01004585static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004586{
4587 if (!nid)
4588 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004589 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004590}
4591
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004592static void stac92xx_line_out_detect(struct hda_codec *codec,
4593 int presence)
4594{
4595 struct sigmatel_spec *spec = codec->spec;
4596 struct auto_pin_cfg *cfg = &spec->autocfg;
4597 int i;
4598
4599 for (i = 0; i < cfg->line_outs; i++) {
4600 if (presence)
4601 break;
4602 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4603 if (presence) {
4604 unsigned int pinctl;
4605 pinctl = snd_hda_codec_read(codec,
4606 cfg->line_out_pins[i], 0,
4607 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4608 if (pinctl & AC_PINCTL_IN_EN)
4609 presence = 0; /* mic- or line-input */
4610 }
4611 }
4612
4613 if (presence) {
4614 /* disable speakers */
4615 for (i = 0; i < cfg->speaker_outs; i++)
4616 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4617 AC_PINCTL_OUT_EN);
4618 if (spec->eapd_mask && spec->eapd_switch)
4619 stac_gpio_set(codec, spec->gpio_mask,
4620 spec->gpio_dir, spec->gpio_data &
4621 ~spec->eapd_mask);
4622 } else {
4623 /* enable speakers */
4624 for (i = 0; i < cfg->speaker_outs; i++)
4625 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4626 AC_PINCTL_OUT_EN);
4627 if (spec->eapd_mask && spec->eapd_switch)
4628 stac_gpio_set(codec, spec->gpio_mask,
4629 spec->gpio_dir, spec->gpio_data |
4630 spec->eapd_mask);
4631 }
4632}
4633
Takashi Iwaid7a89432008-11-12 09:48:04 +01004634/* return non-zero if the hp-pin of the given array index isn't
4635 * a jack-detection target
4636 */
4637static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4638{
4639 struct auto_pin_cfg *cfg = &spec->autocfg;
4640
4641 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004642 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004643 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004644 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004645 return 1;
4646 /* ignore if the pin is set as line-out */
4647 if (cfg->hp_pins[i] == spec->hp_switch)
4648 return 1;
4649 return 0;
4650}
4651
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004652static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004653{
4654 struct sigmatel_spec *spec = codec->spec;
4655 struct auto_pin_cfg *cfg = &spec->autocfg;
4656 int i, presence;
4657
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004658 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004659 if (spec->gpio_mute)
4660 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4661 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4662
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004663 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004664 if (presence)
4665 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004666 if (no_hp_sensing(spec, i))
4667 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004668 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4669 if (presence) {
4670 unsigned int pinctl;
4671 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4672 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4673 if (pinctl & AC_PINCTL_IN_EN)
4674 presence = 0; /* mic- or line-input */
4675 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004676 }
Matt4e550962005-07-04 17:51:39 +02004677
4678 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004679 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004680 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004681 stac92xx_reset_pinctl(codec, spec->hp_switch,
4682 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004683 for (i = 0; i < cfg->line_outs; i++)
4684 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4685 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004686 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004687 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004688 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004689 stac92xx_set_pinctl(codec, spec->hp_switch,
4690 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004691 for (i = 0; i < cfg->line_outs; i++)
4692 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4693 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004694 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004695 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004696 /* toggle hp outs */
4697 for (i = 0; i < cfg->hp_outs; i++) {
4698 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4699 if (no_hp_sensing(spec, i))
4700 continue;
4701 if (presence)
4702 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004703#if 0 /* FIXME */
4704/* Resetting the pinctl like below may lead to (a sort of) regressions
4705 * on some devices since they use the HP pin actually for line/speaker
4706 * outs although the default pin config shows a different pin (that is
4707 * wrong and useless).
4708 *
4709 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4710 * But, disabling the code below just works around it, and I'm too tired of
4711 * bug reports with such devices...
4712 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004713 else
4714 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004715#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004716 }
Matt4e550962005-07-04 17:51:39 +02004717}
4718
Takashi Iwaif73d3582008-11-25 08:21:51 +01004719static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4720 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004721{
4722 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004723 unsigned int idx, val;
4724
4725 for (idx = 0; idx < spec->num_pwrs; idx++) {
4726 if (spec->pwr_nids[idx] == nid)
4727 break;
4728 }
4729 if (idx >= spec->num_pwrs)
4730 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004731
Charles Chinafef2cf2011-11-11 08:05:28 +01004732 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004733
Takashi Iwaif73d3582008-11-25 08:21:51 +01004734 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4735 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004736 val &= ~idx;
4737 else
4738 val |= idx;
4739
4740 /* power down unused output ports */
4741 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004742}
4743
Takashi Iwaif73d3582008-11-25 08:21:51 +01004744static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4745{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004746 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004747}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004748
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004749/* get the pin connection (fixed, none, etc) */
4750static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4751{
4752 struct sigmatel_spec *spec = codec->spec;
4753 unsigned int cfg;
4754
4755 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4756 return get_defcfg_connect(cfg);
4757}
4758
4759static int stac92xx_connected_ports(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02004760 const hda_nid_t *nids, int num_nids)
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004761{
4762 struct sigmatel_spec *spec = codec->spec;
4763 int idx, num;
4764 unsigned int def_conf;
4765
4766 for (num = 0; num < num_nids; num++) {
4767 for (idx = 0; idx < spec->num_pins; idx++)
4768 if (spec->pin_nids[idx] == nids[num])
4769 break;
4770 if (idx >= spec->num_pins)
4771 break;
4772 def_conf = stac_get_defcfg_connect(codec, idx);
4773 if (def_conf == AC_JACK_PORT_NONE)
4774 break;
4775 }
4776 return num;
4777}
4778
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004779static void stac92xx_mic_detect(struct hda_codec *codec)
4780{
4781 struct sigmatel_spec *spec = codec->spec;
4782 struct sigmatel_mic_route *mic;
4783
4784 if (get_pin_presence(codec, spec->ext_mic.pin))
4785 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02004786 else if (get_pin_presence(codec, spec->dock_mic.pin))
4787 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004788 else
4789 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004790 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004791 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4792 AC_VERB_SET_CONNECT_SEL,
4793 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004794 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004795 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4796 AC_VERB_SET_CONNECT_SEL,
4797 mic->mux_idx);
4798}
4799
Takashi Iwai62558ce2009-07-29 14:23:09 +02004800static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004801{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004802 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004803 if (!event)
4804 return;
4805 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4806}
4807
Takashi Iwai314634b2006-09-21 11:56:18 +02004808static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4809{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004810 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004811 struct sigmatel_event *event;
4812 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004813
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004814 tag = (res >> 26) & 0x7f;
4815 event = stac_get_event_from_tag(codec, tag);
4816 if (!event)
4817 return;
4818
4819 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004820 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004821 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004822 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004823 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004824 case STAC_MIC_EVENT:
4825 stac92xx_mic_detect(codec);
4826 break;
4827 }
4828
4829 switch (event->type) {
4830 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004831 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004832 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004833 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004834 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004835 if (spec->num_pwrs > 0)
4836 stac92xx_pin_sense(codec, event->nid);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01004837 snd_hda_input_jack_report(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004838
4839 switch (codec->subsystem_id) {
4840 case 0x103c308f:
4841 if (event->nid == 0xb) {
4842 int pin = AC_PINCTL_IN_EN;
4843
4844 if (get_pin_presence(codec, 0xa)
4845 && get_pin_presence(codec, 0xb))
4846 pin |= AC_PINCTL_VREF_80;
4847 if (!get_pin_presence(codec, 0xb))
4848 pin |= AC_PINCTL_VREF_80;
4849
4850 /* toggle VREF state based on mic + hp pin
4851 * status
4852 */
4853 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4854 }
4855 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004856 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004857 case STAC_VREF_EVENT:
4858 data = snd_hda_codec_read(codec, codec->afg, 0,
4859 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004860 /* toggle VREF state based on GPIOx status */
4861 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004862 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004863 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004864 }
4865}
4866
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304867static int hp_blike_system(u32 subsystem_id);
4868
4869static void set_hp_led_gpio(struct hda_codec *codec)
4870{
4871 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004872 unsigned int gpio;
4873
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004874 if (spec->gpio_led)
4875 return;
4876
Takashi Iwai07f80442010-02-08 15:06:13 +01004877 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4878 gpio &= AC_GPIO_IO_COUNT;
4879 if (gpio > 3)
4880 spec->gpio_led = 0x08; /* GPIO 3 */
4881 else
4882 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304883}
4884
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004885/*
4886 * This method searches for the mute LED GPIO configuration
4887 * provided as OEM string in SMBIOS. The format of that string
4888 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4889 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4890 * that corresponds to the NOT muted state of the master volume
4891 * and G is the index of the GPIO to use as the mute LED control (0..9)
4892 * If _G portion is missing it is assigned based on the codec ID
4893 *
4894 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4895 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304896 *
4897 *
4898 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4899 * SMBIOS - at least the ones I have seen do not have them - which include
4900 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4901 * HP Pavilion dv9500t CTO.
4902 * Need more information on whether it is true across the entire series.
4903 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004904 */
Takashi Iwaidce17d42010-02-09 09:25:26 +01004905static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004906{
4907 struct sigmatel_spec *spec = codec->spec;
4908 const struct dmi_device *dev = NULL;
4909
4910 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4911 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4912 NULL, dev))) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004913 if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304914 &spec->gpio_led_polarity,
4915 &spec->gpio_led) == 2) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004916 if (spec->gpio_led < 4)
4917 spec->gpio_led = 1 << spec->gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004918 return 1;
4919 }
4920 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304921 &spec->gpio_led_polarity) == 1) {
4922 set_hp_led_gpio(codec);
4923 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004924 }
4925 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304926
4927 /*
4928 * Fallback case - if we don't find the DMI strings,
4929 * we statically set the GPIO - if not a B-series system.
4930 */
4931 if (!hp_blike_system(codec->subsystem_id)) {
4932 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004933 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304934 return 1;
4935 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004936 }
4937 return 0;
4938}
4939
4940static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004941{
4942 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004943 case 0x103c1520:
4944 case 0x103c1521:
4945 case 0x103c1523:
4946 case 0x103c1524:
4947 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004948 case 0x103c1722:
4949 case 0x103c1723:
4950 case 0x103c1724:
4951 case 0x103c1725:
4952 case 0x103c1726:
4953 case 0x103c1727:
4954 case 0x103c1728:
4955 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004956 case 0x103c172a:
4957 case 0x103c172b:
4958 case 0x103c307e:
4959 case 0x103c307f:
4960 case 0x103c3080:
4961 case 0x103c3081:
4962 case 0x103c7007:
4963 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004964 return 1;
4965 }
4966 return 0;
4967}
4968
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004969#ifdef CONFIG_PROC_FS
4970static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4971 struct hda_codec *codec, hda_nid_t nid)
4972{
4973 if (nid == codec->afg)
4974 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4975 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4976}
4977
4978static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4979 struct hda_codec *codec,
4980 unsigned int verb)
4981{
4982 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4983 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4984}
4985
4986/* stac92hd71bxx, stac92hd73xx */
4987static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4988 struct hda_codec *codec, hda_nid_t nid)
4989{
4990 stac92hd_proc_hook(buffer, codec, nid);
4991 if (nid == codec->afg)
4992 analog_loop_proc_hook(buffer, codec, 0xfa0);
4993}
4994
4995static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4996 struct hda_codec *codec, hda_nid_t nid)
4997{
4998 if (nid == codec->afg)
4999 analog_loop_proc_hook(buffer, codec, 0xfe0);
5000}
5001
5002static void stac927x_proc_hook(struct snd_info_buffer *buffer,
5003 struct hda_codec *codec, hda_nid_t nid)
5004{
5005 if (nid == codec->afg)
5006 analog_loop_proc_hook(buffer, codec, 0xfeb);
5007}
5008#else
5009#define stac92hd_proc_hook NULL
5010#define stac92hd7x_proc_hook NULL
5011#define stac9205_proc_hook NULL
5012#define stac927x_proc_hook NULL
5013#endif
5014
Takashi Iwai2a439522011-07-26 09:52:50 +02005015#ifdef CONFIG_PM
Mattff6fdc32005-06-27 15:06:52 +02005016static int stac92xx_resume(struct hda_codec *codec)
5017{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02005018 struct sigmatel_spec *spec = codec->spec;
5019
Takashi Iwai2c885872008-11-18 09:36:55 +01005020 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02005021 snd_hda_codec_resume_amp(codec);
5022 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01005023 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02005024 if (spec->hp_detect) {
5025 if (spec->autocfg.hp_pins[0])
5026 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
5027 else if (spec->autocfg.line_out_pins[0])
5028 stac_issue_unsol_event(codec,
5029 spec->autocfg.line_out_pins[0]);
5030 }
Mattff6fdc32005-06-27 15:06:52 +02005031 return 0;
5032}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005033
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005034static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
5035{
5036 stac92xx_shutup(codec);
5037 return 0;
5038}
5039
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005040#ifdef CONFIG_SND_HDA_POWER_SAVE
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005041static int stac92xx_pre_resume(struct hda_codec *codec)
5042{
5043 struct sigmatel_spec *spec = codec->spec;
5044
5045 /* sync mute LED */
5046 if (spec->gpio_led) {
5047 if (spec->gpio_led <= 8) {
5048 stac_gpio_set(codec, spec->gpio_mask,
5049 spec->gpio_dir, spec->gpio_data);
5050 } else {
5051 stac_vrefout_set(codec,
5052 spec->gpio_led, spec->vref_led);
5053 }
5054 }
5055 return 0;
5056}
5057
5058static int stac92xx_post_suspend(struct hda_codec *codec)
5059{
5060 struct sigmatel_spec *spec = codec->spec;
5061 if (spec->gpio_led > 8) {
5062 /* with vref-out pin used for mute led control
5063 * codec AFG is prevented from D3 state, but on
5064 * system suspend it can (and should) be used
5065 */
5066 snd_hda_codec_read(codec, codec->afg, 0,
5067 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
5068 }
5069 return 0;
5070}
5071
5072static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5073 unsigned int power_state)
5074{
5075 unsigned int afg_power_state = power_state;
5076 struct sigmatel_spec *spec = codec->spec;
5077
5078 if (power_state == AC_PWRST_D3) {
5079 if (spec->gpio_led > 8) {
5080 /* with vref-out pin used for mute led control
5081 * codec AFG is prevented from D3 state
5082 */
5083 afg_power_state = AC_PWRST_D1;
5084 }
5085 /* this delay seems necessary to avoid click noise at power-down */
5086 msleep(100);
5087 }
5088 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5089 afg_power_state);
5090 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
5091}
5092
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005093/*
5094 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed
5095 * as mute LED state is updated in check_power_status hook
5096 */
5097static int stac92xx_update_led_status(struct hda_codec *codec)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005098{
5099 struct sigmatel_spec *spec = codec->spec;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005100 int i, num_ext_dacs, muted = 1;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005101 unsigned int muted_lvl, notmtd_lvl;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005102 hda_nid_t nid;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005103
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005104 if (!spec->gpio_led)
5105 return 0;
5106
Takashi Iwaic21bd022010-02-08 15:16:08 +01005107 for (i = 0; i < spec->multiout.num_dacs; i++) {
5108 nid = spec->multiout.dac_nids[i];
5109 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5110 HDA_AMP_MUTE)) {
5111 muted = 0; /* something heard */
5112 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005113 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01005114 }
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005115 if (muted && spec->multiout.hp_nid)
5116 if (!(snd_hda_codec_amp_read(codec,
5117 spec->multiout.hp_nid, 0, HDA_OUTPUT, 0) &
5118 HDA_AMP_MUTE)) {
5119 muted = 0; /* HP is not muted */
5120 }
5121 num_ext_dacs = ARRAY_SIZE(spec->multiout.extra_out_nid);
5122 for (i = 0; muted && i < num_ext_dacs; i++) {
5123 nid = spec->multiout.extra_out_nid[i];
5124 if (nid == 0)
5125 break;
5126 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5127 HDA_AMP_MUTE)) {
5128 muted = 0; /* extra output is not muted */
5129 }
5130 }
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005131 /*polarity defines *not* muted state level*/
5132 if (spec->gpio_led <= 8) {
5133 if (muted)
5134 spec->gpio_data &= ~spec->gpio_led; /* orange */
5135 else
5136 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005137
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005138 if (!spec->gpio_led_polarity) {
5139 /* LED state is inverted on these systems */
5140 spec->gpio_data ^= spec->gpio_led;
5141 }
5142 stac_gpio_set(codec, spec->gpio_mask,
5143 spec->gpio_dir, spec->gpio_data);
5144 } else {
5145 notmtd_lvl = spec->gpio_led_polarity ?
5146 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_GRD;
5147 muted_lvl = spec->gpio_led_polarity ?
5148 AC_PINCTL_VREF_GRD : AC_PINCTL_VREF_HIZ;
5149 spec->vref_led = muted ? muted_lvl : notmtd_lvl;
5150 stac_vrefout_set(codec, spec->gpio_led, spec->vref_led);
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005151 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005152 return 0;
5153}
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005154
5155/*
5156 * use power check for controlling mute led of HP notebooks
5157 */
5158static int stac92xx_check_power_status(struct hda_codec *codec,
5159 hda_nid_t nid)
5160{
5161 stac92xx_update_led_status(codec);
5162
5163 return 0;
5164}
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005165#endif /* CONFIG_SND_HDA_POWER_SAVE */
Takashi Iwai2a439522011-07-26 09:52:50 +02005166#endif /* CONFIG_PM */
Mattff6fdc32005-06-27 15:06:52 +02005167
Takashi Iwai2b635362011-05-02 12:33:43 +02005168static const struct hda_codec_ops stac92xx_patch_ops = {
Matt2f2f4252005-04-13 14:45:30 +02005169 .build_controls = stac92xx_build_controls,
5170 .build_pcms = stac92xx_build_pcms,
5171 .init = stac92xx_init,
5172 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02005173 .unsol_event = stac92xx_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02005174#ifdef CONFIG_PM
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005175 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005176 .resume = stac92xx_resume,
5177#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005178 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005179};
5180
5181static int patch_stac9200(struct hda_codec *codec)
5182{
5183 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005184 int err;
Matt2f2f4252005-04-13 14:45:30 +02005185
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005186 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005187 if (spec == NULL)
5188 return -ENOMEM;
5189
Takashi Iwaia252c812009-12-25 22:56:20 +01005190 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005191 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005192 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005193 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005194 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005195 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5196 stac9200_models,
5197 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005198 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005199 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5200 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005201 else
5202 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005203 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005204
5205 spec->multiout.max_channels = 2;
5206 spec->multiout.num_dacs = 1;
5207 spec->multiout.dac_nids = stac9200_dac_nids;
5208 spec->adc_nids = stac9200_adc_nids;
5209 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005210 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005211 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005212 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005213 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005214
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005215 if (spec->board_config == STAC_9200_M4 ||
5216 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005217 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005218 spec->init = stac9200_eapd_init;
5219 else
5220 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005221 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005222
Takashi Iwai117f2572008-03-18 09:53:23 +01005223 if (spec->board_config == STAC_9200_PANASONIC) {
5224 spec->gpio_mask = spec->gpio_dir = 0x09;
5225 spec->gpio_data = 0x00;
5226 }
5227
Mattc7d4b2f2005-06-27 14:59:41 +02005228 err = stac9200_parse_auto_config(codec);
5229 if (err < 0) {
5230 stac92xx_free(codec);
5231 return err;
5232 }
Matt2f2f4252005-04-13 14:45:30 +02005233
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005234 /* CF-74 has no headphone detection, and the driver should *NOT*
5235 * do detection and HP/speaker toggle because the hardware does it.
5236 */
5237 if (spec->board_config == STAC_9200_PANASONIC)
5238 spec->hp_detect = 0;
5239
Matt2f2f4252005-04-13 14:45:30 +02005240 codec->patch_ops = stac92xx_patch_ops;
5241
5242 return 0;
5243}
5244
Tobin Davis8e21c342007-01-08 11:04:17 +01005245static int patch_stac925x(struct hda_codec *codec)
5246{
5247 struct sigmatel_spec *spec;
5248 int err;
5249
5250 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5251 if (spec == NULL)
5252 return -ENOMEM;
5253
Takashi Iwaia252c812009-12-25 22:56:20 +01005254 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005255 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005256 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005257 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005258 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005259
5260 /* Check first for codec ID */
5261 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5262 STAC_925x_MODELS,
5263 stac925x_models,
5264 stac925x_codec_id_cfg_tbl);
5265
5266 /* Now checks for PCI ID, if codec ID is not found */
5267 if (spec->board_config < 0)
5268 spec->board_config = snd_hda_check_board_config(codec,
5269 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005270 stac925x_models,
5271 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005272 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005273 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005274 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5275 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005276 else
5277 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005278 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005279
5280 spec->multiout.max_channels = 2;
5281 spec->multiout.num_dacs = 1;
5282 spec->multiout.dac_nids = stac925x_dac_nids;
5283 spec->adc_nids = stac925x_adc_nids;
5284 spec->mux_nids = stac925x_mux_nids;
5285 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005286 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005287 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005288 switch (codec->vendor_id) {
5289 case 0x83847632: /* STAC9202 */
5290 case 0x83847633: /* STAC9202D */
5291 case 0x83847636: /* STAC9251 */
5292 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005293 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005294 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005295 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5296 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005297 break;
5298 default:
5299 spec->num_dmics = 0;
5300 break;
5301 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005302
5303 spec->init = stac925x_core_init;
5304 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005305 spec->num_caps = 1;
5306 spec->capvols = stac925x_capvols;
5307 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005308
Charles Chin9009b0e2011-11-03 10:27:27 +01005309 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005310 if (!err) {
5311 if (spec->board_config < 0) {
5312 printk(KERN_WARNING "hda_codec: No auto-config is "
5313 "available, default to model=ref\n");
5314 spec->board_config = STAC_925x_REF;
5315 goto again;
5316 }
5317 err = -EINVAL;
5318 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005319 if (err < 0) {
5320 stac92xx_free(codec);
5321 return err;
5322 }
5323
5324 codec->patch_ops = stac92xx_patch_ops;
5325
5326 return 0;
5327}
5328
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005329static int patch_stac92hd73xx(struct hda_codec *codec)
5330{
5331 struct sigmatel_spec *spec;
5332 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5333 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005334 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005335
5336 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5337 if (spec == NULL)
5338 return -ENOMEM;
5339
Takashi Iwaia252c812009-12-25 22:56:20 +01005340 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005341 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005342 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005343 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005344 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5345 spec->pin_nids = stac92hd73xx_pin_nids;
5346 spec->board_config = snd_hda_check_board_config(codec,
5347 STAC_92HD73XX_MODELS,
5348 stac92hd73xx_models,
5349 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005350 /* check codec subsystem id if not found */
5351 if (spec->board_config < 0)
5352 spec->board_config =
5353 snd_hda_check_board_codec_sid_config(codec,
5354 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5355 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005356again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005357 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005358 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5359 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005360 else
5361 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005362 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005363
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005364 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005365 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5366
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005367 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005368 printk(KERN_WARNING "hda_codec: Could not determine "
5369 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005370 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005371 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005372 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005373 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005374 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005375 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005376 break;
5377 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005378 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005379 break;
5380 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005381 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5382 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005383 }
5384 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005385
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005386 spec->aloopback_mask = 0x01;
5387 spec->aloopback_shift = 8;
5388
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005389 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005390 spec->mux_nids = stac92hd73xx_mux_nids;
5391 spec->adc_nids = stac92hd73xx_adc_nids;
5392 spec->dmic_nids = stac92hd73xx_dmic_nids;
5393 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005394 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005395
5396 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5397 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005398 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005399
Takashi Iwai6479c632009-07-28 18:20:25 +02005400 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5401 spec->capvols = stac92hd73xx_capvols;
5402 spec->capsws = stac92hd73xx_capsws;
5403
Matthew Ranostaya7662642008-02-21 07:51:14 +01005404 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005405 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005406 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005407 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005408 case STAC_DELL_M6_AMIC:
5409 case STAC_DELL_M6_DMIC:
5410 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005411 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005412 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005413
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005414 switch (spec->board_config) {
5415 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005416 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005417 spec->num_dmics = 0;
5418 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005419 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005420 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005421 spec->num_dmics = 1;
5422 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005423 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005424 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5425 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005426 spec->num_dmics = 1;
5427 break;
5428 }
5429 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005430 case STAC_ALIENWARE_M17X:
5431 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5432 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5433 spec->eapd_switch = 0;
5434 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005435 default:
5436 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005437 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005438 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005439 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005440 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005441 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005442 /* GPIO0 High = Enable EAPD */
5443 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5444 spec->gpio_data = 0x01;
5445 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005446
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005447 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5448 spec->pwr_nids = stac92hd73xx_pwr_nids;
5449
Charles Chin9009b0e2011-11-03 10:27:27 +01005450 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005451
5452 if (!err) {
5453 if (spec->board_config < 0) {
5454 printk(KERN_WARNING "hda_codec: No auto-config is "
5455 "available, default to model=ref\n");
5456 spec->board_config = STAC_92HD73XX_REF;
5457 goto again;
5458 }
5459 err = -EINVAL;
5460 }
5461
5462 if (err < 0) {
5463 stac92xx_free(codec);
5464 return err;
5465 }
5466
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005467 if (spec->board_config == STAC_92HD73XX_NO_JD)
5468 spec->hp_detect = 0;
5469
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005470 codec->patch_ops = stac92xx_patch_ops;
5471
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005472 codec->proc_widget_hook = stac92hd7x_proc_hook;
5473
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005474 return 0;
5475}
5476
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005477static int hp_bnb2011_with_dock(struct hda_codec *codec)
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005478{
5479 if (codec->vendor_id != 0x111d7605 &&
5480 codec->vendor_id != 0x111d76d1)
5481 return 0;
5482
5483 switch (codec->subsystem_id) {
5484 case 0x103c1618:
5485 case 0x103c1619:
5486 case 0x103c161a:
5487 case 0x103c161b:
5488 case 0x103c161c:
5489 case 0x103c161d:
5490 case 0x103c161e:
5491 case 0x103c161f:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005492
5493 case 0x103c162a:
5494 case 0x103c162b:
5495
5496 case 0x103c1630:
5497 case 0x103c1631:
5498
5499 case 0x103c1633:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005500 case 0x103c1634:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005501 case 0x103c1635:
5502
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005503 case 0x103c3587:
5504 case 0x103c3588:
5505 case 0x103c3589:
5506 case 0x103c358a:
5507
5508 case 0x103c3667:
5509 case 0x103c3668:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005510 case 0x103c3669:
5511
5512 return 1;
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005513 }
5514 return 0;
5515}
5516
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005517static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
5518{
5519 struct sigmatel_spec *spec = codec->spec;
5520 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5521 int i;
5522
5523 spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5524 spec->auto_pin_cnt++;
5525
5526 if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5527 get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5528 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5529 if (nid == stac92hd83xxx_dmic_nids[i]) {
5530 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5531 spec->auto_dmic_cnt++;
5532 }
5533 }
5534 }
5535}
5536
5537static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5538{
5539 struct sigmatel_spec *spec = codec->spec;
5540
5541 spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5542 spec->auto_adc_cnt++;
5543}
5544
5545static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5546{
5547 int i, j;
5548 struct sigmatel_spec *spec = codec->spec;
5549
5550 for (i = 0; i < spec->auto_adc_cnt; i++) {
5551 if (get_connection_index(codec,
5552 spec->auto_adc_nids[i], nid) >= 0) {
5553 /* mux and volume for adc_nids[i] */
5554 if (!spec->auto_mux_nids[i]) {
5555 spec->auto_mux_nids[i] = nid;
5556 /* 92hd codecs capture volume is in mux */
5557 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
5558 3, 0, HDA_OUTPUT);
5559 }
5560 for (j = 0; j < spec->auto_dmic_cnt; j++) {
5561 if (get_connection_index(codec, nid,
5562 spec->auto_dmic_nids[j]) >= 0) {
5563 /* dmux for adc_nids[i] */
5564 if (!spec->auto_dmux_nids[i])
5565 spec->auto_dmux_nids[i] = nid;
5566 break;
5567 }
5568 }
5569 break;
5570 }
5571 }
5572}
5573
5574static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5575{
5576 hda_nid_t nid, end_nid;
5577 unsigned int wid_caps, wid_type;
5578 struct sigmatel_spec *spec = codec->spec;
5579
5580 end_nid = codec->start_nid + codec->num_nodes;
5581
5582 for (nid = codec->start_nid; nid < end_nid; nid++) {
5583 wid_caps = get_wcaps(codec, nid);
5584 wid_type = get_wcaps_type(wid_caps);
5585
5586 if (wid_type == AC_WID_PIN)
5587 stac92hd8x_add_pin(codec, nid);
5588
5589 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5590 stac92hd8x_add_adc(codec, nid);
5591 }
5592
5593 for (nid = codec->start_nid; nid < end_nid; nid++) {
5594 wid_caps = get_wcaps(codec, nid);
5595 wid_type = get_wcaps_type(wid_caps);
5596
5597 if (wid_type == AC_WID_AUD_SEL)
5598 stac92hd8x_add_mux(codec, nid);
5599 }
5600
5601 spec->pin_nids = spec->auto_pin_nids;
5602 spec->num_pins = spec->auto_pin_cnt;
5603 spec->adc_nids = spec->auto_adc_nids;
5604 spec->num_adcs = spec->auto_adc_cnt;
5605 spec->capvols = spec->auto_capvols;
5606 spec->capsws = spec->auto_capvols;
5607 spec->num_caps = spec->auto_adc_cnt;
5608 spec->mux_nids = spec->auto_mux_nids;
5609 spec->num_muxes = spec->auto_adc_cnt;
5610 spec->dmux_nids = spec->auto_dmux_nids;
5611 spec->num_dmuxes = spec->auto_adc_cnt;
5612 spec->dmic_nids = spec->auto_dmic_nids;
5613 spec->num_dmics = spec->auto_dmic_cnt;
5614}
5615
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005616static int patch_stac92hd83xxx(struct hda_codec *codec)
5617{
5618 struct sigmatel_spec *spec;
5619 int err;
5620
5621 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5622 if (spec == NULL)
5623 return -ENOMEM;
5624
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005625 if (hp_bnb2011_with_dock(codec)) {
5626 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5627 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5628 }
5629
Takashi Iwaia252c812009-12-25 22:56:20 +01005630 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005631 codec->spec = spec;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005632
5633 stac92hd8x_fill_auto_spec(codec);
5634
Takashi Iwai1db7ccdb2010-12-03 15:19:14 +01005635 spec->linear_tone_beep = 0;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005636 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005637 spec->digbeep_nid = 0x21;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005638 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005639 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005640 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005641 spec->init = stac92hd83xxx_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005642
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005643 spec->board_config = snd_hda_check_board_config(codec,
5644 STAC_92HD83XXX_MODELS,
5645 stac92hd83xxx_models,
5646 stac92hd83xxx_cfg_tbl);
5647again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005648 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005649 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5650 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005651 else
5652 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005653 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005654
Takashi Iwaib4e81872009-11-18 17:20:24 +01005655 codec->patch_ops = stac92xx_patch_ops;
5656
Takashi Iwaidce17d42010-02-09 09:25:26 +01005657 if (find_mute_led_gpio(codec, 0))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005658 snd_printd("mute LED gpio %d polarity %d\n",
5659 spec->gpio_led,
5660 spec->gpio_led_polarity);
5661
Takashi Iwaib4e81872009-11-18 17:20:24 +01005662#ifdef CONFIG_SND_HDA_POWER_SAVE
5663 if (spec->gpio_led) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005664 if (spec->gpio_led <= 8) {
5665 spec->gpio_mask |= spec->gpio_led;
5666 spec->gpio_dir |= spec->gpio_led;
5667 spec->gpio_data |= spec->gpio_led;
5668 } else {
5669 codec->patch_ops.set_power_state =
5670 stac92xx_set_power_state;
5671 codec->patch_ops.post_suspend =
5672 stac92xx_post_suspend;
5673 }
5674 codec->patch_ops.pre_resume = stac92xx_pre_resume;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005675 codec->patch_ops.check_power_status =
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005676 stac92xx_check_power_status;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005677 }
5678#endif
5679
Charles Chin9009b0e2011-11-03 10:27:27 +01005680 err = stac92xx_parse_auto_config(codec);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005681 if (!err) {
5682 if (spec->board_config < 0) {
5683 printk(KERN_WARNING "hda_codec: No auto-config is "
5684 "available, default to model=ref\n");
5685 spec->board_config = STAC_92HD83XXX_REF;
5686 goto again;
5687 }
5688 err = -EINVAL;
5689 }
5690
5691 if (err < 0) {
5692 stac92xx_free(codec);
5693 return err;
5694 }
5695
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005696 codec->proc_widget_hook = stac92hd_proc_hook;
5697
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005698 return 0;
5699}
5700
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005701static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5702 hda_nid_t dig0pin)
5703{
5704 struct sigmatel_spec *spec = codec->spec;
5705 int idx;
5706
5707 for (idx = 0; idx < spec->num_pins; idx++)
5708 if (spec->pin_nids[idx] == dig0pin)
5709 break;
5710 if ((idx + 2) >= spec->num_pins)
5711 return 0;
5712
5713 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005714 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005715 return 2;
5716
5717 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005718 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005719 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005720 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005721 return 1;
5722 else
5723 return 0;
5724}
5725
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005726/* HP dv7 bass switch - GPIO5 */
5727#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5728static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5729 struct snd_ctl_elem_value *ucontrol)
5730{
5731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5732 struct sigmatel_spec *spec = codec->spec;
5733 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5734 return 0;
5735}
5736
5737static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5738 struct snd_ctl_elem_value *ucontrol)
5739{
5740 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5741 struct sigmatel_spec *spec = codec->spec;
5742 unsigned int gpio_data;
5743
5744 gpio_data = (spec->gpio_data & ~0x20) |
5745 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5746 if (gpio_data == spec->gpio_data)
5747 return 0;
5748 spec->gpio_data = gpio_data;
5749 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5750 return 1;
5751}
5752
Takashi Iwai2b635362011-05-02 12:33:43 +02005753static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5755 .info = stac_hp_bass_gpio_info,
5756 .get = stac_hp_bass_gpio_get,
5757 .put = stac_hp_bass_gpio_put,
5758};
5759
5760static int stac_add_hp_bass_switch(struct hda_codec *codec)
5761{
5762 struct sigmatel_spec *spec = codec->spec;
5763
5764 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5765 "Bass Speaker Playback Switch", 0))
5766 return -ENOMEM;
5767
5768 spec->gpio_mask |= 0x20;
5769 spec->gpio_dir |= 0x20;
5770 spec->gpio_data |= 0x20;
5771 return 0;
5772}
5773
Matthew Ranostaye035b842007-11-06 11:53:55 +01005774static int patch_stac92hd71bxx(struct hda_codec *codec)
5775{
5776 struct sigmatel_spec *spec;
Takashi Iwai2b635362011-05-02 12:33:43 +02005777 const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005778 unsigned int pin_cfg;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005779 int err = 0;
5780
5781 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5782 if (spec == NULL)
5783 return -ENOMEM;
5784
Takashi Iwaia252c812009-12-25 22:56:20 +01005785 codec->no_trigger_sense = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005786 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005787 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005788 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005789 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5790 switch (codec->vendor_id) {
5791 case 0x111d76b6:
5792 case 0x111d76b7:
5793 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5794 break;
5795 case 0x111d7603:
5796 case 0x111d7608:
5797 /* On 92HD75Bx 0x27 isn't a pin nid */
5798 spec->num_pins--;
5799 /* fallthrough */
5800 default:
5801 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5802 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005803 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005804 spec->board_config = snd_hda_check_board_config(codec,
5805 STAC_92HD71BXX_MODELS,
5806 stac92hd71bxx_models,
5807 stac92hd71bxx_cfg_tbl);
5808again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005809 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005810 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5811 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005812 else
5813 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005814 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005815
Takashi Iwaifc64b262009-09-14 15:33:01 +02005816 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005817 /* GPIO0 = EAPD */
5818 spec->gpio_mask = 0x01;
5819 spec->gpio_dir = 0x01;
5820 spec->gpio_data = 0x01;
5821 }
5822
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005823 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5824 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5825
Takashi Iwai6479c632009-07-28 18:20:25 +02005826 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5827 spec->capvols = stac92hd71bxx_capvols;
5828 spec->capsws = stac92hd71bxx_capsws;
5829
Matthew Ranostay541eee82007-12-14 12:08:04 +01005830 switch (codec->vendor_id) {
5831 case 0x111d76b6: /* 4 Port without Analog Mixer */
5832 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005833 unmute_init++;
5834 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005835 case 0x111d76b4: /* 6 Port without Analog Mixer */
5836 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005837 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005838 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005839 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005840 stac92hd71bxx_dmic_nids,
5841 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005842 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005843 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005844 switch (spec->board_config) {
5845 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005846 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005847 err = stac_add_event(spec, codec->afg,
5848 STAC_VREF_EVENT, 0x02);
5849 if (err < 0)
5850 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005851 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005852 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5853 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005854 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005855 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005856 spec->gpio_mask |= 0x02;
5857 break;
5858 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005859 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005860 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005861 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005862
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005863 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005864 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005865 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005866 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5867 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Takashi Iwai2b635362011-05-02 12:33:43 +02005868 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005869 spec->num_dmics = stac92xx_connected_ports(codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02005870 stac92hd71bxx_dmic_5port_nids,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005871 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005872 break;
5873 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005874 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005875 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005876
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005877 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005878 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005879 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005880 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005881 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005882 stac92hd71bxx_dmic_nids,
5883 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005884 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005885 }
5886
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005887 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5888 snd_hda_sequence_write_cache(codec, unmute_init);
5889
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005890 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005891 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005892 spec->aloopback_shift = 0;
5893
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005894 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005895 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005896 spec->mux_nids = stac92hd71bxx_mux_nids;
5897 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005898 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005899 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005900
5901 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5902 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005903 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005904 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005905
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305906 snd_printdd("Found board config: %d\n", spec->board_config);
5907
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005908 switch (spec->board_config) {
5909 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005910 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005911 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005912 stac92xx_auto_set_pinctl(codec, 0x0e,
5913 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005914 /* fallthru */
5915 case STAC_DELL_M4_2:
5916 spec->num_dmics = 0;
5917 spec->num_smuxes = 0;
5918 spec->num_dmuxes = 0;
5919 break;
5920 case STAC_DELL_M4_1:
5921 case STAC_DELL_M4_3:
5922 spec->num_dmics = 1;
5923 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005924 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005925 break;
James Gardiner514bf542009-05-03 04:00:44 -04005926 case STAC_HP_DV4_1222NR:
5927 spec->num_dmics = 1;
5928 /* I don't know if it needs 1 or 2 smuxes - will wait for
5929 * bug reports to fix if needed
5930 */
5931 spec->num_smuxes = 1;
5932 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005933 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005934 case STAC_HP_DV4:
5935 spec->gpio_led = 0x01;
5936 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005937 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005938 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005939 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005940 /* HP dv6 gives the headphone pin as a line-out. Thus we
5941 * need to set hp_detect flag here to force to enable HP
5942 * detection.
5943 */
5944 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005945 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005946 case STAC_HP_HDX:
5947 spec->num_dmics = 1;
5948 spec->num_dmuxes = 1;
5949 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005950 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005951 break;
5952 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005953
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005954 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005955 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5956 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5957 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5958 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5959 /* It was changed in the BIOS to just satisfy MS DTM.
5960 * Lets turn it back into slaved HP
5961 */
5962 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5963 | (AC_JACK_HP_OUT <<
5964 AC_DEFCFG_DEVICE_SHIFT);
5965 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5966 | AC_DEFCFG_SEQUENCE)))
5967 | 0x1f;
5968 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5969 }
5970 }
5971
Takashi Iwaidce17d42010-02-09 09:25:26 +01005972 if (find_mute_led_gpio(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005973 snd_printd("mute LED gpio %d polarity %d\n",
5974 spec->gpio_led,
5975 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005976
Takashi Iwai86d190e2009-05-26 15:18:58 +02005977#ifdef CONFIG_SND_HDA_POWER_SAVE
5978 if (spec->gpio_led) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005979 if (spec->gpio_led <= 8) {
5980 spec->gpio_mask |= spec->gpio_led;
5981 spec->gpio_dir |= spec->gpio_led;
5982 spec->gpio_data |= spec->gpio_led;
5983 } else {
5984 codec->patch_ops.set_power_state =
5985 stac92xx_set_power_state;
5986 codec->patch_ops.post_suspend =
5987 stac92xx_post_suspend;
5988 }
5989 codec->patch_ops.pre_resume = stac92xx_pre_resume;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005990 codec->patch_ops.check_power_status =
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005991 stac92xx_check_power_status;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005992 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005993#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005994
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005995 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005996
Charles Chin9009b0e2011-11-03 10:27:27 +01005997 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005998 if (!err) {
5999 if (spec->board_config < 0) {
6000 printk(KERN_WARNING "hda_codec: No auto-config is "
6001 "available, default to model=ref\n");
6002 spec->board_config = STAC_92HD71BXX_REF;
6003 goto again;
6004 }
6005 err = -EINVAL;
6006 }
6007
6008 if (err < 0) {
6009 stac92xx_free(codec);
6010 return err;
6011 }
6012
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006013 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02006014 if (spec->board_config == STAC_HP_DV4 ||
6015 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006016 unsigned int cap;
6017 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
6018 cap &= AC_GPIO_IO_COUNT;
6019 if (cap >= 6)
6020 stac_add_hp_bass_switch(codec);
6021 }
6022
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006023 codec->proc_widget_hook = stac92hd7x_proc_hook;
6024
Matthew Ranostaye035b842007-11-06 11:53:55 +01006025 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006026}
Matthew Ranostaye035b842007-11-06 11:53:55 +01006027
Matt2f2f4252005-04-13 14:45:30 +02006028static int patch_stac922x(struct hda_codec *codec)
6029{
6030 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02006031 int err;
Matt2f2f4252005-04-13 14:45:30 +02006032
Takashi Iwaie560d8d2005-09-09 14:21:46 +02006033 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02006034 if (spec == NULL)
6035 return -ENOMEM;
6036
Takashi Iwaia252c812009-12-25 22:56:20 +01006037 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02006038 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006039 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006040 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006041 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006042 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
6043 stac922x_models,
6044 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08006045 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006046 spec->gpio_mask = spec->gpio_dir = 0x03;
6047 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006048 /* Intel Macs have all same PCI SSID, so we need to check
6049 * codec SSID to distinguish the exact models
6050 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006051 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006052 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006053
6054 case 0x106b0800:
6055 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02006056 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006057 case 0x106b0600:
6058 case 0x106b0700:
6059 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006060 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006061 case 0x106b0e00:
6062 case 0x106b0f00:
6063 case 0x106b1600:
6064 case 0x106b1700:
6065 case 0x106b0200:
6066 case 0x106b1e00:
6067 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006068 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006069 case 0x106b1a00:
6070 case 0x00000100:
6071 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02006072 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006073 case 0x106b0a00:
6074 case 0x106b2200:
6075 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02006076 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08006077 default:
6078 spec->board_config = STAC_INTEL_MAC_V3;
6079 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006080 }
6081 }
6082
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006083 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006084 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006085 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6086 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006087 else
6088 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006089 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02006090
Matt2f2f4252005-04-13 14:45:30 +02006091 spec->adc_nids = stac922x_adc_nids;
6092 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006093 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006094 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006095 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006096 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02006097
6098 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006099
6100 spec->num_caps = STAC922X_NUM_CAPS;
6101 spec->capvols = stac922x_capvols;
6102 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02006103
6104 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02006105
Charles Chin9009b0e2011-11-03 10:27:27 +01006106 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006107 if (!err) {
6108 if (spec->board_config < 0) {
6109 printk(KERN_WARNING "hda_codec: No auto-config is "
6110 "available, default to model=ref\n");
6111 spec->board_config = STAC_D945_REF;
6112 goto again;
6113 }
6114 err = -EINVAL;
6115 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006116 if (err < 0) {
6117 stac92xx_free(codec);
6118 return err;
6119 }
6120
6121 codec->patch_ops = stac92xx_patch_ops;
6122
Takashi Iwai807a46362007-05-29 19:01:37 +02006123 /* Fix Mux capture level; max to 2 */
6124 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
6125 (0 << AC_AMPCAP_OFFSET_SHIFT) |
6126 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
6127 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6128 (0 << AC_AMPCAP_MUTE_SHIFT));
6129
Matt Porter3cc08dc2006-01-23 15:27:49 +01006130 return 0;
6131}
6132
6133static int patch_stac927x(struct hda_codec *codec)
6134{
6135 struct sigmatel_spec *spec;
6136 int err;
6137
6138 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6139 if (spec == NULL)
6140 return -ENOMEM;
6141
Takashi Iwaia252c812009-12-25 22:56:20 +01006142 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01006143 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006144 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05006145 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006146 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006147 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006148 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
6149 stac927x_models,
6150 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006151 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006152 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006153 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6154 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006155 else
6156 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006157 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01006158
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006159 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006160 spec->adc_nids = stac927x_adc_nids;
6161 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6162 spec->mux_nids = stac927x_mux_nids;
6163 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006164 spec->smux_nids = stac927x_smux_nids;
6165 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04006166 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01006167 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006168 spec->multiout.dac_nids = spec->dac_nids;
6169
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006170 if (spec->board_config != STAC_D965_REF) {
6171 /* GPIO0 High = Enable EAPD */
6172 spec->eapd_mask = spec->gpio_mask = 0x01;
6173 spec->gpio_dir = spec->gpio_data = 0x01;
6174 }
6175
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006176 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02006177 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006178 case STAC_D965_5ST:
6179 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006180 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02006181 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006182 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006183 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006184 switch (codec->subsystem_id) {
6185 case 0x10280209:
6186 case 0x1028022e:
6187 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006188 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006189 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006190 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01006191 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01006192 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01006193 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006194 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006195 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01006196 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006197 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006198 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006199 if (codec->subsystem_id != 0x1028022f) {
6200 /* GPIO2 High = Enable EAPD */
6201 spec->eapd_mask = spec->gpio_mask = 0x04;
6202 spec->gpio_dir = spec->gpio_data = 0x04;
6203 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006204 spec->dmic_nids = stac927x_dmic_nids;
6205 spec->num_dmics = STAC927X_NUM_DMICS;
6206
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02006207 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006208 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006209 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006210 break;
Takashi Iwai54930532009-10-11 17:38:29 +02006211 case STAC_927X_VOLKNOB:
6212 spec->num_dmics = 0;
6213 spec->init = stac927x_volknob_core_init;
6214 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006215 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006216 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006217 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006218 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006219 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006220
Takashi Iwai6479c632009-07-28 18:20:25 +02006221 spec->num_caps = STAC927X_NUM_CAPS;
6222 spec->capvols = stac927x_capvols;
6223 spec->capsws = stac927x_capsws;
6224
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006225 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006226 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006227 spec->aloopback_mask = 0x40;
6228 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05006229 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006230
Charles Chin9009b0e2011-11-03 10:27:27 +01006231 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006232 if (!err) {
6233 if (spec->board_config < 0) {
6234 printk(KERN_WARNING "hda_codec: No auto-config is "
6235 "available, default to model=ref\n");
6236 spec->board_config = STAC_D965_REF;
6237 goto again;
6238 }
6239 err = -EINVAL;
6240 }
Mattc7d4b2f2005-06-27 14:59:41 +02006241 if (err < 0) {
6242 stac92xx_free(codec);
6243 return err;
6244 }
Matt2f2f4252005-04-13 14:45:30 +02006245
6246 codec->patch_ops = stac92xx_patch_ops;
6247
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006248 codec->proc_widget_hook = stac927x_proc_hook;
6249
Takashi Iwai52987652008-01-16 16:09:47 +01006250 /*
6251 * !!FIXME!!
6252 * The STAC927x seem to require fairly long delays for certain
6253 * command sequences. With too short delays (even if the answer
6254 * is set to RIRB properly), it results in the silence output
6255 * on some hardwares like Dell.
6256 *
6257 * The below flag enables the longer delay (see get_response
6258 * in hda_intel.c).
6259 */
6260 codec->bus->needs_damn_long_delay = 1;
6261
Takashi Iwaie28d8322008-12-17 13:48:29 +01006262 /* no jack detecion for ref-no-jd model */
6263 if (spec->board_config == STAC_D965_REF_NO_JD)
6264 spec->hp_detect = 0;
6265
Matt2f2f4252005-04-13 14:45:30 +02006266 return 0;
6267}
6268
Matt Porterf3302a52006-07-31 12:49:34 +02006269static int patch_stac9205(struct hda_codec *codec)
6270{
6271 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006272 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006273
6274 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6275 if (spec == NULL)
6276 return -ENOMEM;
6277
Takashi Iwaia252c812009-12-25 22:56:20 +01006278 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006279 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006280 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006281 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006282 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006283 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6284 stac9205_models,
6285 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006286 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006287 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006288 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6289 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006290 else
6291 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006292 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006293
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006294 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006295 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006296 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006297 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006298 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006299 spec->smux_nids = stac9205_smux_nids;
6300 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006301 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006302 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006303 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006304 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006305 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006306
6307 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006308 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006309
Takashi Iwai6479c632009-07-28 18:20:25 +02006310 spec->num_caps = STAC9205_NUM_CAPS;
6311 spec->capvols = stac9205_capvols;
6312 spec->capsws = stac9205_capsws;
6313
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006314 spec->aloopback_mask = 0x40;
6315 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006316 /* Turn on/off EAPD per HP plugging */
6317 if (spec->board_config != STAC_9205_EAPD)
6318 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006319 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006320
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006321 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006322 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006323 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006324 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6325 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006326
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006327 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006328 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6329 if (err < 0)
6330 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006331 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006332 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6333 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006334 AC_VERB_SET_UNSOLICITED_ENABLE,
6335 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006336
6337 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006338 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006339 spec->gpio_mask = 0x1b;
6340 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006341 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006342 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006343 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006344 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006345 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006346 case STAC_9205_REF:
6347 /* SPDIF-In enabled */
6348 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006349 default:
6350 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006351 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006352 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006353 break;
6354 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006355
Charles Chin9009b0e2011-11-03 10:27:27 +01006356 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006357 if (!err) {
6358 if (spec->board_config < 0) {
6359 printk(KERN_WARNING "hda_codec: No auto-config is "
6360 "available, default to model=ref\n");
6361 spec->board_config = STAC_9205_REF;
6362 goto again;
6363 }
6364 err = -EINVAL;
6365 }
Matt Porterf3302a52006-07-31 12:49:34 +02006366 if (err < 0) {
6367 stac92xx_free(codec);
6368 return err;
6369 }
6370
6371 codec->patch_ops = stac92xx_patch_ops;
6372
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006373 codec->proc_widget_hook = stac9205_proc_hook;
6374
Matt Porterf3302a52006-07-31 12:49:34 +02006375 return 0;
6376}
6377
Matt2f2f4252005-04-13 14:45:30 +02006378/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006379 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006380 */
6381
Takashi Iwai2b635362011-05-02 12:33:43 +02006382static const struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006383 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006384 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6385 {}
6386};
6387
Takashi Iwai2b635362011-05-02 12:33:43 +02006388static const hda_nid_t stac9872_pin_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006389 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6390 0x11, 0x13, 0x14,
6391};
6392
Takashi Iwai2b635362011-05-02 12:33:43 +02006393static const hda_nid_t stac9872_adc_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006394 0x8 /*,0x6*/
6395};
6396
Takashi Iwai2b635362011-05-02 12:33:43 +02006397static const hda_nid_t stac9872_mux_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006398 0x15
6399};
6400
Takashi Iwai2b635362011-05-02 12:33:43 +02006401static const unsigned long stac9872_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +02006402 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6403};
6404#define stac9872_capsws stac9872_capvols
6405
Takashi Iwai2b635362011-05-02 12:33:43 +02006406static const unsigned int stac9872_vaio_pin_configs[9] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006407 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6408 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6409 0x90a7013e
6410};
6411
Takashi Iwaiea734962011-01-17 11:29:34 +01006412static const char * const stac9872_models[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006413 [STAC_9872_AUTO] = "auto",
6414 [STAC_9872_VAIO] = "vaio",
6415};
6416
Takashi Iwai2b635362011-05-02 12:33:43 +02006417static const unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006418 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6419};
6420
Takashi Iwai2b635362011-05-02 12:33:43 +02006421static const struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006422 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6423 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006424 {} /* terminator */
6425};
6426
Guillaume Munch6d859062006-08-22 17:15:47 +02006427static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006428{
6429 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006430 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006431
Takashi Iwaidb064e52006-03-16 16:04:58 +01006432 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6433 if (spec == NULL)
6434 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006435 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006436 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006437 spec->linear_tone_beep = 1;
Takashi Iwaib04add92009-07-20 08:01:36 +02006438 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6439 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006440
6441 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6442 stac9872_models,
6443 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006444 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006445 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6446 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006447 else
6448 stac92xx_set_config_regs(codec,
6449 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006450
Takashi Iwai1e137f92009-01-21 07:41:22 +01006451 spec->multiout.dac_nids = spec->dac_nids;
6452 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6453 spec->adc_nids = stac9872_adc_nids;
6454 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6455 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006456 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006457 spec->num_caps = 1;
6458 spec->capvols = stac9872_capvols;
6459 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006460
Charles Chin9009b0e2011-11-03 10:27:27 +01006461 err = stac92xx_parse_auto_config(codec);
Takashi Iwai1e137f92009-01-21 07:41:22 +01006462 if (err < 0) {
6463 stac92xx_free(codec);
6464 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006465 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006466 spec->input_mux = &spec->private_imux;
6467 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006468 return 0;
6469}
6470
6471
6472/*
Matt2f2f4252005-04-13 14:45:30 +02006473 * patch entries
6474 */
Takashi Iwai2b635362011-05-02 12:33:43 +02006475static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006476 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6477 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6478 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6479 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6480 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6481 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6482 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006483 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6484 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6485 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6486 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6487 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6488 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006489 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6490 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6491 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6492 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6493 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6494 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6495 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6496 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6497 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6498 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006499 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6500 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6501 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6502 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6503 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6504 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006505 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6506 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006507 /* The following does not take into account .id=0x83847661 when subsys =
6508 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6509 * currently not fully supported.
6510 */
6511 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6512 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6513 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006514 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006515 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6516 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6517 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6518 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6519 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6520 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6521 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6522 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006523 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006524 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006525 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006526 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006527 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006528 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6529 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006530 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6531 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6532 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6533 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006534 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006535 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6536 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006537 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006538 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6539 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6540 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6541 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6542 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6543 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6544 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6545 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006546 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6547 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6548 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6549 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6550 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6551 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6552 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6553 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6554 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6555 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6556 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6557 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6558 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6559 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6560 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
David Henningsson46724c22011-09-20 09:02:22 +02006561 { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006562 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06006563 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6564 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006565 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Charles Chinad5d8752011-11-02 07:56:58 +01006566 { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6567 { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6568 { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6569 { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6570 { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6571 { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6572 { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6573 { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6574 { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6575 { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6576 { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6577 { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006578 {} /* terminator */
6579};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006580
6581MODULE_ALIAS("snd-hda-codec-id:8384*");
6582MODULE_ALIAS("snd-hda-codec-id:111d*");
6583
6584MODULE_LICENSE("GPL");
6585MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6586
6587static struct hda_codec_preset_list sigmatel_list = {
6588 .preset = snd_hda_preset_sigmatel,
6589 .owner = THIS_MODULE,
6590};
6591
6592static int __init patch_sigmatel_init(void)
6593{
6594 return snd_hda_add_codec_preset(&sigmatel_list);
6595}
6596
6597static void __exit patch_sigmatel_exit(void)
6598{
6599 snd_hda_delete_codec_preset(&sigmatel_list);
6600}
6601
6602module_init(patch_sigmatel_init)
6603module_exit(patch_sigmatel_exit)