blob: 6345df131a005a7202b696ccea02fb5dbfeb0898 [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"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020040#include "hda_jack.h"
Matt2f2f4252005-04-13 14:45:30 +020041
Takashi Iwaic6e4c662008-11-25 11:58:19 +010042enum {
43 STAC_VREF_EVENT = 1,
44 STAC_INSERT_EVENT,
45 STAC_PWR_EVENT,
46 STAC_HP_EVENT,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020047 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020048 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010049};
Matt4e550962005-07-04 17:51:39 +020050
Takashi Iwaif5fcc132006-11-24 17:07:44 +010051enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010052 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010053 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010054 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020055 STAC_9200_DELL_D21,
56 STAC_9200_DELL_D22,
57 STAC_9200_DELL_D23,
58 STAC_9200_DELL_M21,
59 STAC_9200_DELL_M22,
60 STAC_9200_DELL_M23,
61 STAC_9200_DELL_M24,
62 STAC_9200_DELL_M25,
63 STAC_9200_DELL_M26,
64 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020065 STAC_9200_M4,
66 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010067 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010068 STAC_9200_MODELS
69};
70
71enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010072 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010073 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020074 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020075 STAC_9205_DELL_M43,
76 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010077 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010078 STAC_9205_MODELS
79};
80
81enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010082 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010083 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010084 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080085 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010086 STAC_DELL_M6_AMIC,
87 STAC_DELL_M6_DMIC,
88 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050089 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020090 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010091 STAC_92HD73XX_MODELS
92};
93
94enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010095 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020096 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050097 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050098 STAC_DELL_S14,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +010099 STAC_DELL_VOSTRO_3500,
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
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200179struct sigmatel_mic_route {
180 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200181 signed char mux_idx;
182 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200183};
184
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600185#define MAX_PINS_NUM 16
186#define MAX_ADCS_NUM 4
187#define MAX_DMICS_NUM 4
188
Matt2f2f4252005-04-13 14:45:30 +0200189struct sigmatel_spec {
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100190 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200191 unsigned int num_mixers;
192
Matt Porter403d1942005-11-29 15:00:51 +0100193 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500194 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200195 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100196 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100197 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400198 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100199 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200200 unsigned int auto_mic:1;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +0100201 unsigned int linear_tone_beep:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200202
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100203 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200204 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100205 unsigned int gpio_mask;
206 unsigned int gpio_dir;
207 unsigned int gpio_data;
208 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200209 unsigned int gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +0100210 unsigned int gpio_led_polarity;
Takashi Iwaif1a73742011-12-04 13:44:06 +0100211 unsigned int vref_mute_led_nid; /* pin NID for mute-LED vref control */
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500212 unsigned int vref_led;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100213
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200214 /* stream */
215 unsigned int stream_delay;
216
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100217 /* analog loopback */
Takashi Iwai2b635362011-05-02 12:33:43 +0200218 const struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100219 unsigned char aloopback_mask;
220 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200221
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100222 /* power management */
223 unsigned int num_pwrs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200224 const hda_nid_t *pwr_nids;
225 const hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100226
Matt2f2f4252005-04-13 14:45:30 +0200227 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100228 struct hda_input_mux *mono_mux;
229 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200230 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100231 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100232 hda_nid_t hp_dacs[5];
233 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200234
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100235 int volume_offset;
236
Matt2f2f4252005-04-13 14:45:30 +0200237 /* capture */
Takashi Iwai2b635362011-05-02 12:33:43 +0200238 const hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200239 unsigned int num_adcs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200240 const hda_nid_t *mux_nids;
Mattdabbed62005-06-14 10:19:34 +0200241 unsigned int num_muxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200242 const hda_nid_t *dmic_nids;
Matt Porter8b657272006-10-26 17:12:59 +0200243 unsigned int num_dmics;
Takashi Iwai2b635362011-05-02 12:33:43 +0200244 const hda_nid_t *dmux_nids;
Takashi Iwai16970552007-12-18 18:05:52 +0100245 unsigned int num_dmuxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200246 const hda_nid_t *smux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200247 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200248 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200249
Takashi Iwai2b635362011-05-02 12:33:43 +0200250 const unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
251 const unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
Takashi Iwai6479c632009-07-28 18:20:25 +0200252 unsigned int num_caps; /* number of capture volume/switch elements */
253
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200254 struct sigmatel_mic_route ext_mic;
255 struct sigmatel_mic_route int_mic;
Charles Chin99077902010-09-17 10:22:32 +0200256 struct sigmatel_mic_route dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200257
Takashi Iwaiea734962011-01-17 11:29:34 +0100258 const char * const *spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200259
Mattdabbed62005-06-14 10:19:34 +0200260 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100261 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200262 hda_nid_t anabeep_nid;
263 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200264
Matt2f2f4252005-04-13 14:45:30 +0200265 /* pin widgets */
Takashi Iwai2b635362011-05-02 12:33:43 +0200266 const hda_nid_t *pin_nids;
Matt2f2f4252005-04-13 14:45:30 +0200267 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200268
269 /* codec specific stuff */
Takashi Iwai2b635362011-05-02 12:33:43 +0200270 const struct hda_verb *init;
271 const struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200272
273 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200274 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100275 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200276 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100277 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200278 struct hda_input_mux *sinput_mux;
279 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400280 unsigned int cur_amux;
281 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200282 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200283
Matt Porter403d1942005-11-29 15:00:51 +0100284 /* i/o switches */
285 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200286 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100287 hda_nid_t line_switch; /* shared line-in for input and output */
288 hda_nid_t mic_switch; /* shared mic-in for input and output */
289 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200290 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200291
Mattc7d4b2f2005-06-27 14:59:41 +0200292 struct hda_pcm pcm_rec[2]; /* PCM information */
293
294 /* dynamic controls and input_mux */
295 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200296 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200297 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200298 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200299 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100300 struct hda_input_mux private_mono_mux;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600301
302 /* auto spec */
303 unsigned auto_pin_cnt;
304 hda_nid_t auto_pin_nids[MAX_PINS_NUM];
305 unsigned auto_adc_cnt;
306 hda_nid_t auto_adc_nids[MAX_ADCS_NUM];
307 hda_nid_t auto_mux_nids[MAX_ADCS_NUM];
308 hda_nid_t auto_dmux_nids[MAX_ADCS_NUM];
309 unsigned long auto_capvols[MAX_ADCS_NUM];
310 unsigned auto_dmic_cnt;
311 hda_nid_t auto_dmic_nids[MAX_DMICS_NUM];
Matt2f2f4252005-04-13 14:45:30 +0200312};
313
Takashi Iwai2b635362011-05-02 12:33:43 +0200314static const hda_nid_t stac9200_adc_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200315 0x03,
316};
317
Takashi Iwai2b635362011-05-02 12:33:43 +0200318static const hda_nid_t stac9200_mux_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200319 0x0c,
320};
321
Takashi Iwai2b635362011-05-02 12:33:43 +0200322static const hda_nid_t stac9200_dac_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200323 0x02,
324};
325
Takashi Iwai2b635362011-05-02 12:33:43 +0200326static const hda_nid_t stac92hd73xx_pwr_nids[8] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100327 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
328 0x0f, 0x10, 0x11
329};
330
Takashi Iwai2b635362011-05-02 12:33:43 +0200331static const hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400332 0x26, 0,
333};
334
Takashi Iwai2b635362011-05-02 12:33:43 +0200335static const hda_nid_t stac92hd73xx_adc_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100336 0x1a, 0x1b
337};
338
339#define STAC92HD73XX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200340static const hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100341 0x13, 0x14, 0
342};
343
344#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100345
Takashi Iwai2b635362011-05-02 12:33:43 +0200346static const hda_nid_t stac92hd73xx_mux_nids[2] = {
Takashi Iwaie2aec172009-09-02 01:00:05 +0200347 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100348};
349
Takashi Iwai2b635362011-05-02 12:33:43 +0200350static const hda_nid_t stac92hd73xx_dmux_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100351 0x20, 0x21,
352};
353
Takashi Iwai2b635362011-05-02 12:33:43 +0200354static const hda_nid_t stac92hd73xx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200355 0x22, 0x23,
356};
357
Takashi Iwai6479c632009-07-28 18:20:25 +0200358#define STAC92HD73XX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200359static const unsigned long stac92hd73xx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200360 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
361 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
362};
363#define stac92hd73xx_capsws stac92hd73xx_capvols
364
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200365#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200366
Charles Chinafef2cf2011-11-11 08:05:28 +0100367static const hda_nid_t stac92hd83xxx_pwr_nids[7] = {
368 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
369 0x0f, 0x10
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200370};
371
Takashi Iwai2b635362011-05-02 12:33:43 +0200372static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400373 0x1e, 0,
374};
375
Takashi Iwai2b635362011-05-02 12:33:43 +0200376static const hda_nid_t stac92hd83xxx_dmic_nids[] = {
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600377 0x11, 0x20,
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +0200378};
379
Takashi Iwai2b635362011-05-02 12:33:43 +0200380static const hda_nid_t stac92hd71bxx_pwr_nids[3] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100381 0x0a, 0x0d, 0x0f
382};
383
Takashi Iwai2b635362011-05-02 12:33:43 +0200384static const hda_nid_t stac92hd71bxx_adc_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100385 0x12, 0x13,
386};
387
Takashi Iwai2b635362011-05-02 12:33:43 +0200388static const hda_nid_t stac92hd71bxx_mux_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100389 0x1a, 0x1b
390};
391
Takashi Iwai2b635362011-05-02 12:33:43 +0200392static const hda_nid_t stac92hd71bxx_dmux_nids[2] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400393 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100394};
395
Takashi Iwai2b635362011-05-02 12:33:43 +0200396static const hda_nid_t stac92hd71bxx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200397 0x24, 0x25,
398};
399
Matthew Ranostaye035b842007-11-06 11:53:55 +0100400#define STAC92HD71BXX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200401static const hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100402 0x18, 0x19, 0
403};
404
Takashi Iwai2b635362011-05-02 12:33:43 +0200405static const hda_nid_t stac92hd71bxx_dmic_5port_nids[STAC92HD71BXX_NUM_DMICS] = {
406 0x18, 0
407};
408
409static const hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400410 0x22, 0
411};
412
Takashi Iwai6479c632009-07-28 18:20:25 +0200413#define STAC92HD71BXX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200414static const unsigned long stac92hd71bxx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200415 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
416 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
417};
418#define stac92hd71bxx_capsws stac92hd71bxx_capvols
419
Takashi Iwai2b635362011-05-02 12:33:43 +0200420static const hda_nid_t stac925x_adc_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100421 0x03,
422};
423
Takashi Iwai2b635362011-05-02 12:33:43 +0200424static const hda_nid_t stac925x_mux_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100425 0x0f,
426};
427
Takashi Iwai2b635362011-05-02 12:33:43 +0200428static const hda_nid_t stac925x_dac_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100429 0x02,
430};
431
Takashi Iwaif6e98522007-10-16 14:27:04 +0200432#define STAC925X_NUM_DMICS 1
Takashi Iwai2b635362011-05-02 12:33:43 +0200433static const hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200434 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200435};
436
Takashi Iwai2b635362011-05-02 12:33:43 +0200437static const hda_nid_t stac925x_dmux_nids[1] = {
Takashi Iwai16970552007-12-18 18:05:52 +0100438 0x14,
439};
440
Takashi Iwai2b635362011-05-02 12:33:43 +0200441static const unsigned long stac925x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200442 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
443};
Takashi Iwai2b635362011-05-02 12:33:43 +0200444static const unsigned long stac925x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200445 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
446};
447
Takashi Iwai2b635362011-05-02 12:33:43 +0200448static const hda_nid_t stac922x_adc_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200449 0x06, 0x07,
450};
451
Takashi Iwai2b635362011-05-02 12:33:43 +0200452static const hda_nid_t stac922x_mux_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200453 0x12, 0x13,
454};
455
Takashi Iwai6479c632009-07-28 18:20:25 +0200456#define STAC922X_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200457static const unsigned long stac922x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200458 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
459 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
460};
461#define stac922x_capsws stac922x_capvols
462
Takashi Iwai2b635362011-05-02 12:33:43 +0200463static const hda_nid_t stac927x_slave_dig_outs[2] = {
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500464 0x1f, 0,
465};
466
Takashi Iwai2b635362011-05-02 12:33:43 +0200467static const hda_nid_t stac927x_adc_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100468 0x07, 0x08, 0x09
469};
470
Takashi Iwai2b635362011-05-02 12:33:43 +0200471static const hda_nid_t stac927x_mux_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100472 0x15, 0x16, 0x17
473};
474
Takashi Iwai2b635362011-05-02 12:33:43 +0200475static const hda_nid_t stac927x_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200476 0x21,
477};
478
Takashi Iwai2b635362011-05-02 12:33:43 +0200479static const hda_nid_t stac927x_dac_nids[6] = {
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100480 0x02, 0x03, 0x04, 0x05, 0x06, 0
481};
482
Takashi Iwai2b635362011-05-02 12:33:43 +0200483static const hda_nid_t stac927x_dmux_nids[1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100484 0x1b,
485};
486
Matthew Ranostay7f168592007-10-18 17:38:17 +0200487#define STAC927X_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200488static const hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
Matthew Ranostay7f168592007-10-18 17:38:17 +0200489 0x13, 0x14, 0
490};
491
Takashi Iwai6479c632009-07-28 18:20:25 +0200492#define STAC927X_NUM_CAPS 3
Takashi Iwai2b635362011-05-02 12:33:43 +0200493static const unsigned long stac927x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200494 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
495 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
496 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
497};
Takashi Iwai2b635362011-05-02 12:33:43 +0200498static const unsigned long stac927x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200499 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
500 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
501 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
502};
503
Takashi Iwaiea734962011-01-17 11:29:34 +0100504static const char * const stac927x_spdif_labels[5] = {
Matthew Ranostay65973632008-09-16 10:39:37 -0400505 "Digital Playback", "ADAT", "Analog Mux 1",
506 "Analog Mux 2", "Analog Mux 3"
507};
508
Takashi Iwai2b635362011-05-02 12:33:43 +0200509static const hda_nid_t stac9205_adc_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200510 0x12, 0x13
511};
512
Takashi Iwai2b635362011-05-02 12:33:43 +0200513static const hda_nid_t stac9205_mux_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200514 0x19, 0x1a
515};
516
Takashi Iwai2b635362011-05-02 12:33:43 +0200517static const hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai16970552007-12-18 18:05:52 +0100518 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100519};
520
Takashi Iwai2b635362011-05-02 12:33:43 +0200521static const hda_nid_t stac9205_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200522 0x21,
523};
524
Takashi Iwaif6e98522007-10-16 14:27:04 +0200525#define STAC9205_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200526static const hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200527 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200528};
529
Takashi Iwai6479c632009-07-28 18:20:25 +0200530#define STAC9205_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200531static const unsigned long stac9205_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200532 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
533 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
534};
Takashi Iwai2b635362011-05-02 12:33:43 +0200535static const unsigned long stac9205_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200536 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
537 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
538};
539
Takashi Iwai2b635362011-05-02 12:33:43 +0200540static const hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200541 0x08, 0x09, 0x0d, 0x0e,
542 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200543};
544
Takashi Iwai2b635362011-05-02 12:33:43 +0200545static const hda_nid_t stac925x_pin_nids[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100546 0x07, 0x08, 0x0a, 0x0b,
547 0x0c, 0x0d, 0x10, 0x11,
548};
549
Takashi Iwai2b635362011-05-02 12:33:43 +0200550static const hda_nid_t stac922x_pin_nids[10] = {
Matt2f2f4252005-04-13 14:45:30 +0200551 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
552 0x0f, 0x10, 0x11, 0x15, 0x1b,
553};
554
Takashi Iwai2b635362011-05-02 12:33:43 +0200555static const hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100556 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
557 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200558 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100559};
560
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500561#define STAC92HD71BXX_NUM_PINS 13
Takashi Iwai2b635362011-05-02 12:33:43 +0200562static const hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500563 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
564 0x00, 0x14, 0x18, 0x19, 0x1e,
565 0x1f, 0x20, 0x27
566};
Takashi Iwai2b635362011-05-02 12:33:43 +0200567static const hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100568 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
569 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500570 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100571};
572
Takashi Iwai2b635362011-05-02 12:33:43 +0200573static const hda_nid_t stac927x_pin_nids[14] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100574 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
575 0x0f, 0x10, 0x11, 0x12, 0x13,
576 0x14, 0x21, 0x22, 0x23,
577};
578
Takashi Iwai2b635362011-05-02 12:33:43 +0200579static const hda_nid_t stac9205_pin_nids[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200580 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
581 0x0f, 0x14, 0x16, 0x17, 0x18,
582 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200583};
584
Matt Porter8b657272006-10-26 17:12:59 +0200585static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
586 struct snd_ctl_elem_info *uinfo)
587{
588 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
589 struct sigmatel_spec *spec = codec->spec;
590 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
591}
592
593static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
594 struct snd_ctl_elem_value *ucontrol)
595{
596 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
597 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100598 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200599
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100600 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200601 return 0;
602}
603
604static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
605 struct snd_ctl_elem_value *ucontrol)
606{
607 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
608 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100609 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200610
611 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100612 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200613}
614
Matthew Ranostayd9737752008-09-07 12:03:41 +0200615static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
616 struct snd_ctl_elem_info *uinfo)
617{
618 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
619 struct sigmatel_spec *spec = codec->spec;
620 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
621}
622
623static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_value *ucontrol)
625{
626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
627 struct sigmatel_spec *spec = codec->spec;
628 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
629
630 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
631 return 0;
632}
633
634static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_value *ucontrol)
636{
637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400639 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200640 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400641 int err, val;
642 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200643
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400644 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200645 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400646 if (err < 0)
647 return err;
648
649 if (spec->spdif_mute) {
650 if (smux_idx == 0)
651 nid = spec->multiout.dig_out_nid;
652 else
653 nid = codec->slave_dig_outs[smux_idx - 1];
654 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100655 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400656 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100657 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400658 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100659 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
660 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400661 }
662 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200663}
664
Wang Shaoyan96b63592011-08-10 16:01:04 +0800665#ifdef CONFIG_SND_HDA_POWER_SAVE
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500666static int stac_vrefout_set(struct hda_codec *codec,
667 hda_nid_t nid, unsigned int new_vref)
668{
669 int error, pinctl;
670
671 snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
672 pinctl = snd_hda_codec_read(codec, nid, 0,
673 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
674
675 if (pinctl < 0)
676 return pinctl;
677
678 pinctl &= 0xff;
679 pinctl &= ~AC_PINCTL_VREFEN;
680 pinctl |= (new_vref & AC_PINCTL_VREFEN);
681
682 error = snd_hda_codec_write_cache(codec, nid, 0,
683 AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
684 if (error < 0)
685 return error;
686
687 return 1;
688}
Wang Shaoyan96b63592011-08-10 16:01:04 +0800689#endif
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500690
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200691static unsigned int stac92xx_vref_set(struct hda_codec *codec,
692 hda_nid_t nid, unsigned int new_vref)
693{
Takashi Iwaib8621512009-06-22 08:00:10 +0200694 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200695 unsigned int pincfg;
696 pincfg = snd_hda_codec_read(codec, nid, 0,
697 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
698
699 pincfg &= 0xff;
700 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
701 pincfg |= new_vref;
702
703 if (new_vref == AC_PINCTL_VREF_HIZ)
704 pincfg |= AC_PINCTL_OUT_EN;
705 else
706 pincfg |= AC_PINCTL_IN_EN;
707
708 error = snd_hda_codec_write_cache(codec, nid, 0,
709 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
710 if (error < 0)
711 return error;
712 else
713 return 1;
714}
715
716static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
717{
718 unsigned int vref;
719 vref = snd_hda_codec_read(codec, nid, 0,
720 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
721 vref &= AC_PINCTL_VREFEN;
722 return vref;
723}
724
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100725static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200726{
727 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
728 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200729 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200730}
731
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100732static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200733{
734 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
735 struct sigmatel_spec *spec = codec->spec;
736 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
737
738 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
739 return 0;
740}
741
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100742static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200743{
744 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
745 struct sigmatel_spec *spec = codec->spec;
746 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200747 const struct hda_input_mux *imux = spec->input_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600748 unsigned int idx, prev_idx, didx;
Matt2f2f4252005-04-13 14:45:30 +0200749
Takashi Iwai5207e102009-07-30 13:09:08 +0200750 idx = ucontrol->value.enumerated.item[0];
751 if (idx >= imux->num_items)
752 idx = imux->num_items - 1;
753 prev_idx = spec->cur_mux[adc_idx];
754 if (prev_idx == idx)
755 return 0;
756 if (idx < spec->num_analog_muxes) {
757 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
758 AC_VERB_SET_CONNECT_SEL,
759 imux->items[idx].index);
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600760 if (prev_idx >= spec->num_analog_muxes &&
761 spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
Takashi Iwai5207e102009-07-30 13:09:08 +0200762 imux = spec->dinput_mux;
763 /* 0 = analog */
764 snd_hda_codec_write_cache(codec,
765 spec->dmux_nids[adc_idx], 0,
766 AC_VERB_SET_CONNECT_SEL,
767 imux->items[0].index);
768 }
769 } else {
770 imux = spec->dinput_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600771 /* first dimux item is hardcoded to select analog imux,
772 * so lets skip it
773 */
774 didx = idx - spec->num_analog_muxes + 1;
Takashi Iwai5207e102009-07-30 13:09:08 +0200775 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
776 AC_VERB_SET_CONNECT_SEL,
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600777 imux->items[didx].index);
Takashi Iwai5207e102009-07-30 13:09:08 +0200778 }
779 spec->cur_mux[adc_idx] = idx;
780 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200781}
782
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100783static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
784 struct snd_ctl_elem_info *uinfo)
785{
786 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
787 struct sigmatel_spec *spec = codec->spec;
788 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
789}
790
791static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
792 struct snd_ctl_elem_value *ucontrol)
793{
794 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
795 struct sigmatel_spec *spec = codec->spec;
796
797 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
798 return 0;
799}
800
801static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
802 struct snd_ctl_elem_value *ucontrol)
803{
804 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
805 struct sigmatel_spec *spec = codec->spec;
806
807 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
808 spec->mono_nid, &spec->cur_mmux);
809}
810
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200811#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
812
813static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_value *ucontrol)
815{
816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100817 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200818 struct sigmatel_spec *spec = codec->spec;
819
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100820 ucontrol->value.integer.value[0] = !!(spec->aloopback &
821 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200822 return 0;
823}
824
825static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
826 struct snd_ctl_elem_value *ucontrol)
827{
828 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
829 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100830 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200831 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100832 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200833
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100834 idx_val = spec->aloopback_mask << idx;
835 if (ucontrol->value.integer.value[0])
836 val = spec->aloopback | idx_val;
837 else
838 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100839 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200840 return 0;
841
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100842 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200843
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100844 /* Only return the bits defined by the shift value of the
845 * first two bytes of the mask
846 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200847 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100848 kcontrol->private_value & 0xFFFF, 0x0);
849 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200850
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100851 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200852 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100853 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200854 } else {
855 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100856 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200857 }
858
859 snd_hda_codec_write_cache(codec, codec->afg, 0,
860 kcontrol->private_value >> 16, dac_mode);
861
862 return 1;
863}
864
Takashi Iwai2b635362011-05-02 12:33:43 +0200865static const struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200866 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200867 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200868 {}
869};
870
Takashi Iwai2b635362011-05-02 12:33:43 +0200871static const struct hda_verb stac9200_eapd_init[] = {
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200872 /* set dac0mux for dac converter */
873 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
874 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
875 {}
876};
877
Takashi Iwai2b635362011-05-02 12:33:43 +0200878static const struct hda_verb dell_eq_core_init[] = {
Matthew Ranostayd654a662008-03-14 08:46:51 +0100879 /* set master volume to max value without distortion
880 * and direct control */
881 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100882 {}
883};
884
Takashi Iwai2b635362011-05-02 12:33:43 +0200885static const struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100886 /* set master volume and direct control */
887 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100888 {}
889};
890
Takashi Iwai2b635362011-05-02 12:33:43 +0200891static const struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200892 /* power state controls amps */
893 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200894 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200895};
896
Takashi Iwai2b635362011-05-02 12:33:43 +0200897static const struct hda_verb stac92hd71bxx_core_init[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100898 /* set master volume and direct control */
899 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200900 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100901};
902
Takashi Iwai2b635362011-05-02 12:33:43 +0200903static const struct hda_verb stac92hd71bxx_unmute_core_init[] = {
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500904 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
905 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100906 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
907 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100908 {}
909};
910
Takashi Iwai2b635362011-05-02 12:33:43 +0200911static const struct hda_verb stac925x_core_init[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100912 /* set dac0mux for dac converter */
913 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100914 /* mute the master volume */
915 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100916 {}
917};
918
Takashi Iwai2b635362011-05-02 12:33:43 +0200919static const struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200920 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200921 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200922 {}
923};
924
Takashi Iwai2b635362011-05-02 12:33:43 +0200925static const struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200926 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200927 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200928 /* unmute node 0x1b */
929 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
930 /* select node 0x03 as DAC */
931 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
932 {}
933};
934
Takashi Iwai2b635362011-05-02 12:33:43 +0200935static const struct hda_verb dell_3st_core_init[] = {
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200936 /* don't set delta bit */
937 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
938 /* unmute node 0x1b */
939 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
940 /* select node 0x03 as DAC */
941 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
942 {}
943};
944
Takashi Iwai2b635362011-05-02 12:33:43 +0200945static const struct hda_verb stac927x_core_init[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100946 /* set master volume and direct control */
947 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200948 /* enable analog pc beep path */
949 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100950 {}
951};
952
Takashi Iwai2b635362011-05-02 12:33:43 +0200953static const struct hda_verb stac927x_volknob_core_init[] = {
Takashi Iwai54930532009-10-11 17:38:29 +0200954 /* don't set delta bit */
955 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
956 /* enable analog pc beep path */
957 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
958 {}
959};
960
Takashi Iwai2b635362011-05-02 12:33:43 +0200961static const struct hda_verb stac9205_core_init[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200962 /* set master volume and direct control */
963 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200964 /* enable analog pc beep path */
965 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200966 {}
967};
968
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100969#define STAC_MONO_MUX \
970 { \
971 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
972 .name = "Mono Mux", \
973 .count = 1, \
974 .info = stac92xx_mono_mux_enum_info, \
975 .get = stac92xx_mono_mux_enum_get, \
976 .put = stac92xx_mono_mux_enum_put, \
977 }
978
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100979#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200980 { \
981 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
982 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100983 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200984 .info = stac92xx_aloopback_info, \
985 .get = stac92xx_aloopback_get, \
986 .put = stac92xx_aloopback_put, \
987 .private_value = verb_read | (verb_write << 16), \
988 }
989
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200990#define DC_BIAS(xname, idx, nid) \
991 { \
992 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
993 .name = xname, \
994 .index = idx, \
995 .info = stac92xx_dc_bias_info, \
996 .get = stac92xx_dc_bias_get, \
997 .put = stac92xx_dc_bias_put, \
998 .private_value = nid, \
999 }
1000
Takashi Iwai2b635362011-05-02 12:33:43 +02001001static const struct snd_kcontrol_new stac9200_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001002 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001003 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001004 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1005 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001006 { } /* end */
1007};
1008
Takashi Iwai2b635362011-05-02 12:33:43 +02001009static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001010 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1011 {}
1012};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001013
Takashi Iwai2b635362011-05-02 12:33:43 +02001014static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001015 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1016 {}
1017};
1018
Takashi Iwai2b635362011-05-02 12:33:43 +02001019static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001020 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1021 {}
1022};
1023
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001024
Takashi Iwai2b635362011-05-02 12:33:43 +02001025static const struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001026 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1027};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001028
Takashi Iwai2b635362011-05-02 12:33:43 +02001029static const struct snd_kcontrol_new stac925x_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001030 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
Takashi Iwaic9280d62009-01-15 17:31:00 +01001031 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001032 { } /* end */
1033};
1034
Takashi Iwai2b635362011-05-02 12:33:43 +02001035static const struct snd_kcontrol_new stac9205_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001036 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1037 {}
1038};
1039
Takashi Iwai2b635362011-05-02 12:33:43 +02001040static const struct snd_kcontrol_new stac927x_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001041 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1042 {}
1043};
1044
Takashi Iwai16970552007-12-18 18:05:52 +01001045static struct snd_kcontrol_new stac_dmux_mixer = {
1046 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1047 .name = "Digital Input Source",
1048 /* count set later */
1049 .info = stac92xx_dmux_enum_info,
1050 .get = stac92xx_dmux_enum_get,
1051 .put = stac92xx_dmux_enum_put,
1052};
1053
Matthew Ranostayd9737752008-09-07 12:03:41 +02001054static struct snd_kcontrol_new stac_smux_mixer = {
1055 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001056 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001057 /* count set later */
1058 .info = stac92xx_smux_enum_info,
1059 .get = stac92xx_smux_enum_get,
1060 .put = stac92xx_smux_enum_put,
1061};
1062
Takashi Iwaiea734962011-01-17 11:29:34 +01001063static const char * const slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001064 "Front Playback Volume",
1065 "Surround Playback Volume",
1066 "Center Playback Volume",
1067 "LFE Playback Volume",
1068 "Side Playback Volume",
1069 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001070 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001071 NULL
1072};
1073
Takashi Iwaiea734962011-01-17 11:29:34 +01001074static const char * const slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001075 "Front Playback Switch",
1076 "Surround Playback Switch",
1077 "Center Playback Switch",
1078 "LFE Playback Switch",
1079 "Side Playback Switch",
1080 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001081 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001082 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001083 NULL
1084};
1085
Takashi Iwai603c4012008-07-30 15:01:44 +02001086static void stac92xx_free_kctls(struct hda_codec *codec);
1087
Matt2f2f4252005-04-13 14:45:30 +02001088static int stac92xx_build_controls(struct hda_codec *codec)
1089{
1090 struct sigmatel_spec *spec = codec->spec;
1091 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001092 int i;
Matt2f2f4252005-04-13 14:45:30 +02001093
Takashi Iwai6479c632009-07-28 18:20:25 +02001094 if (spec->mixer) {
1095 err = snd_hda_add_new_ctls(codec, spec->mixer);
1096 if (err < 0)
1097 return err;
1098 }
Mattc7d4b2f2005-06-27 14:59:41 +02001099
1100 for (i = 0; i < spec->num_mixers; i++) {
1101 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1102 if (err < 0)
1103 return err;
1104 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001105 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1106 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai16970552007-12-18 18:05:52 +01001107 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001108 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai16970552007-12-18 18:05:52 +01001109 snd_ctl_new1(&stac_dmux_mixer, codec));
1110 if (err < 0)
1111 return err;
1112 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001113 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001114 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1115 struct hda_input_mux *smux = &spec->private_smux;
1116 /* check for mute support on SPDIF out */
1117 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001118 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001119 spec->spdif_mute = 1;
1120 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001121 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001122 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001123 snd_ctl_new1(&stac_smux_mixer, codec));
1124 if (err < 0)
1125 return err;
1126 }
Mattc7d4b2f2005-06-27 14:59:41 +02001127
Mattdabbed62005-06-14 10:19:34 +02001128 if (spec->multiout.dig_out_nid) {
Stephen Warren74b654c2011-06-01 11:14:18 -06001129 err = snd_hda_create_spdif_out_ctls(codec,
1130 spec->multiout.dig_out_nid,
1131 spec->multiout.dig_out_nid);
Mattdabbed62005-06-14 10:19:34 +02001132 if (err < 0)
1133 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001134 err = snd_hda_create_spdif_share_sw(codec,
1135 &spec->multiout);
1136 if (err < 0)
1137 return err;
1138 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001139 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001140 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001141 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1142 if (err < 0)
1143 return err;
1144 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001145
1146 /* if we have no master control, let's create it */
1147 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001148 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001149 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001150 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001151 /* correct volume offset */
1152 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001153 /* minimum value is actually mute */
Clemens Ladischa74ccea2010-10-22 15:52:34 +02001154 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001155 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001156 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001157 if (err < 0)
1158 return err;
1159 }
1160 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1161 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1162 NULL, slave_sws);
1163 if (err < 0)
1164 return err;
1165 }
1166
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001167 if (spec->aloopback_ctl &&
1168 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1169 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1170 if (err < 0)
1171 return err;
1172 }
1173
Takashi Iwai603c4012008-07-30 15:01:44 +02001174 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001175
Takashi Iwai01a61e12011-10-28 00:03:22 +02001176 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1177 if (err < 0)
1178 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001179
Mattdabbed62005-06-14 10:19:34 +02001180 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001181}
1182
Takashi Iwai2b635362011-05-02 12:33:43 +02001183static const unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001184 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001185 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1186};
1187
Takashi Iwai2b635362011-05-02 12:33:43 +02001188static const unsigned int gateway9200_m4_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001189 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1190 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1191};
Takashi Iwai2b635362011-05-02 12:33:43 +02001192static const unsigned int gateway9200_m4_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001193 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1194 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1195};
1196
1197/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001198 STAC 9200 pin configs for
1199 102801A8
1200 102801DE
1201 102801E8
1202*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001203static const unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001204 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1205 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001206};
1207
1208/*
1209 STAC 9200 pin configs for
1210 102801C0
1211 102801C1
1212*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001213static const unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001214 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1215 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001216};
1217
1218/*
1219 STAC 9200 pin configs for
1220 102801C4 (Dell Dimension E310)
1221 102801C5
1222 102801C7
1223 102801D9
1224 102801DA
1225 102801E3
1226*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001227static const unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001228 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1229 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001230};
1231
1232
1233/*
1234 STAC 9200-32 pin configs for
1235 102801B5 (Dell Inspiron 630m)
1236 102801D8 (Dell Inspiron 640m)
1237*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001238static const unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001239 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1240 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001241};
1242
1243/*
1244 STAC 9200-32 pin configs for
1245 102801C2 (Dell Latitude D620)
1246 102801C8
1247 102801CC (Dell Latitude D820)
1248 102801D4
1249 102801D6
1250*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001251static const unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001252 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1253 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001254};
1255
1256/*
1257 STAC 9200-32 pin configs for
1258 102801CE (Dell XPS M1710)
1259 102801CF (Dell Precision M90)
1260*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001261static const unsigned int dell9200_m23_pin_configs[8] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001262 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1263 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1264};
1265
1266/*
1267 STAC 9200-32 pin configs for
1268 102801C9
1269 102801CA
1270 102801CB (Dell Latitude 120L)
1271 102801D3
1272*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001273static const unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001274 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1275 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001276};
1277
1278/*
1279 STAC 9200-32 pin configs for
1280 102801BD (Dell Inspiron E1505n)
1281 102801EE
1282 102801EF
1283*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001284static const unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001285 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1286 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001287};
1288
1289/*
1290 STAC 9200-32 pin configs for
1291 102801F5 (Dell Inspiron 1501)
1292 102801F6
1293*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001294static const unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001295 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1296 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001297};
1298
1299/*
1300 STAC 9200-32
1301 102801CD (Dell Inspiron E1705/9400)
1302*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001303static const unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001304 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1305 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001306};
1307
Takashi Iwai2b635362011-05-02 12:33:43 +02001308static const unsigned int oqo9200_pin_configs[8] = {
Tobin Davisbf277782008-02-03 20:31:47 +01001309 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1310 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1311};
1312
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001313
Takashi Iwai2b635362011-05-02 12:33:43 +02001314static const unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001315 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001316 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001317 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1318 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1319 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1320 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1321 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1322 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1323 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1324 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1325 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1326 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001327 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1328 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001329 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001330};
1331
Takashi Iwaiea734962011-01-17 11:29:34 +01001332static const char * const stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001333 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001334 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001335 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001336 [STAC_9200_DELL_D21] = "dell-d21",
1337 [STAC_9200_DELL_D22] = "dell-d22",
1338 [STAC_9200_DELL_D23] = "dell-d23",
1339 [STAC_9200_DELL_M21] = "dell-m21",
1340 [STAC_9200_DELL_M22] = "dell-m22",
1341 [STAC_9200_DELL_M23] = "dell-m23",
1342 [STAC_9200_DELL_M24] = "dell-m24",
1343 [STAC_9200_DELL_M25] = "dell-m25",
1344 [STAC_9200_DELL_M26] = "dell-m26",
1345 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001346 [STAC_9200_M4] = "gateway-m4",
1347 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001348 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001349};
1350
Takashi Iwai2b635362011-05-02 12:33:43 +02001351static const struct snd_pci_quirk stac9200_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001352 /* SigmaTel reference board */
1353 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1354 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001355 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1356 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001357 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001358 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1359 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001360 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001361 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1362 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1363 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1364 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1365 "unknown Dell", STAC_9200_DELL_D22),
1366 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1367 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001368 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001369 "Dell Latitude D620", STAC_9200_DELL_M22),
1370 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1371 "unknown Dell", STAC_9200_DELL_D23),
1372 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1373 "unknown Dell", STAC_9200_DELL_D23),
1374 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1375 "unknown Dell", STAC_9200_DELL_M22),
1376 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1377 "unknown Dell", STAC_9200_DELL_M24),
1378 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1379 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001380 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001381 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001382 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001383 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001384 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001385 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001386 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001387 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001388 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001389 "Dell Precision M90", STAC_9200_DELL_M23),
1390 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1391 "unknown Dell", STAC_9200_DELL_M22),
1392 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1393 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001394 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001395 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001396 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001397 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1398 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1399 "unknown Dell", STAC_9200_DELL_D23),
1400 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1401 "unknown Dell", STAC_9200_DELL_D23),
1402 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1403 "unknown Dell", STAC_9200_DELL_D21),
1404 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1405 "unknown Dell", STAC_9200_DELL_D23),
1406 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1407 "unknown Dell", STAC_9200_DELL_D21),
1408 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1409 "unknown Dell", STAC_9200_DELL_M25),
1410 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1411 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001412 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001413 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1414 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1415 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001416 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001417 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001418 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001419 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1420 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1421 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001422 /* OQO Mobile */
1423 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001424 {} /* terminator */
1425};
1426
Takashi Iwai2b635362011-05-02 12:33:43 +02001427static const unsigned int ref925x_pin_configs[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001428 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001429 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001430};
1431
Takashi Iwai2b635362011-05-02 12:33:43 +02001432static const unsigned int stac925xM1_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001433 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1434 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001435};
1436
Takashi Iwai2b635362011-05-02 12:33:43 +02001437static const unsigned int stac925xM1_2_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001438 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1439 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1440};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001441
Takashi Iwai2b635362011-05-02 12:33:43 +02001442static const unsigned int stac925xM2_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001443 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1444 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001445};
1446
Takashi Iwai2b635362011-05-02 12:33:43 +02001447static const unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001448 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1449 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1450};
1451
Takashi Iwai2b635362011-05-02 12:33:43 +02001452static const unsigned int stac925xM3_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001453 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1454 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1455};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001456
Takashi Iwai2b635362011-05-02 12:33:43 +02001457static const unsigned int stac925xM5_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001458 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1459 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1460};
1461
Takashi Iwai2b635362011-05-02 12:33:43 +02001462static const unsigned int stac925xM6_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001463 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1464 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001465};
1466
Takashi Iwai2b635362011-05-02 12:33:43 +02001467static const unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001468 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001469 [STAC_M1] = stac925xM1_pin_configs,
1470 [STAC_M1_2] = stac925xM1_2_pin_configs,
1471 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001472 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001473 [STAC_M3] = stac925xM3_pin_configs,
1474 [STAC_M5] = stac925xM5_pin_configs,
1475 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001476};
1477
Takashi Iwaiea734962011-01-17 11:29:34 +01001478static const char * const stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001479 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001480 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001481 [STAC_M1] = "m1",
1482 [STAC_M1_2] = "m1-2",
1483 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001484 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001485 [STAC_M3] = "m3",
1486 [STAC_M5] = "m5",
1487 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001488};
1489
Takashi Iwai2b635362011-05-02 12:33:43 +02001490static const struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001491 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1492 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1493 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1494 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001495 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001496 /* Not sure about the brand name for those */
1497 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1498 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1499 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1500 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001501 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001502};
1503
Takashi Iwai2b635362011-05-02 12:33:43 +02001504static const struct snd_pci_quirk stac925x_cfg_tbl[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001505 /* SigmaTel reference board */
1506 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001507 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001508 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001509
1510 /* Default table for unknown ID */
1511 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1512
Tobin Davis8e21c342007-01-08 11:04:17 +01001513 {} /* terminator */
1514};
1515
Takashi Iwai2b635362011-05-02 12:33:43 +02001516static const unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001517 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1518 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1519 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001520 0x01452050,
1521};
1522
Takashi Iwai2b635362011-05-02 12:33:43 +02001523static const unsigned int dell_m6_pin_configs[13] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001524 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001525 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001526 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1527 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001528};
1529
Takashi Iwai2b635362011-05-02 12:33:43 +02001530static const unsigned int alienware_m17x_pin_configs[13] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001531 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1532 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1533 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1534 0x904601b0,
1535};
1536
Takashi Iwai2b635362011-05-02 12:33:43 +02001537static const unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001538 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001539 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001540};
1541
Takashi Iwai2b635362011-05-02 12:33:43 +02001542static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001543 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001544 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1545 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1546 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001547 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001548 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001549 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001550};
1551
Takashi Iwaiea734962011-01-17 11:29:34 +01001552static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001553 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001554 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001555 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001556 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001557 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1558 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1559 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001560 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001561 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001562};
1563
Takashi Iwai2b635362011-05-02 12:33:43 +02001564static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001565 /* SigmaTel reference board */
1566 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001567 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001568 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1569 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001570 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1571 "Intel DG45ID", STAC_92HD73XX_INTEL),
1572 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1573 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001575 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001577 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001578 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001579 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001581 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001582 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001583 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001584 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001585 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001586 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001587 "unknown Dell", STAC_DELL_M6_DMIC),
1588 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1589 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001591 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1593 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1595 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1597 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
David Henningssonffe535e2012-01-16 10:52:20 +01001599 "Dell Studio XPS 1645", STAC_DELL_M6_DMIC),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
David Henningssone033ebf2011-05-16 12:09:29 +02001601 "Dell Studio 1558", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001602 {} /* terminator */
1603};
1604
Takashi Iwai2b635362011-05-02 12:33:43 +02001605static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001606 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1607 "Alienware M17x", STAC_ALIENWARE_M17X),
Daniel T Chen0defe092010-12-01 19:16:07 -05001608 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1609 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwaidbd1b542011-11-19 11:41:30 +01001610 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490,
Albert Poolb9ecc4e2012-01-19 22:08:50 +01001611 "Alienware M17x R3", STAC_DELL_EQ),
Takashi Iwai842ae632009-09-02 07:43:08 +02001612 {} /* terminator */
1613};
1614
Takashi Iwai2b635362011-05-02 12:33:43 +02001615static const unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001616 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1617 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001618 0x01451160, 0x98560170,
1619};
1620
Takashi Iwai2b635362011-05-02 12:33:43 +02001621static const unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001622 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1623 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001624 0x40f000f0, 0x40f000f0,
1625};
1626
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001627static const unsigned int dell_vostro_3500_pin_configs[10] = {
1628 0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
1629 0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
1630 0x400000f4, 0x400000f5,
1631};
1632
Takashi Iwai2b635362011-05-02 12:33:43 +02001633static const unsigned int hp_dv7_4000_pin_configs[10] = {
Steven Eastland48315592010-08-06 15:07:35 -06001634 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1635 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1636 0x40f000f0, 0x40f000f0,
1637};
1638
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001639static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
1640 0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
1641 0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
1642 0x40f000f0, 0x40f000f0,
1643};
1644
Takashi Iwai2b635362011-05-02 12:33:43 +02001645static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001646 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001647 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001648 [STAC_DELL_S14] = dell_s14_pin_configs,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001649 [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001650 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001651 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001652};
1653
Takashi Iwaiea734962011-01-17 11:29:34 +01001654static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001655 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001656 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001657 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001658 [STAC_DELL_S14] = "dell-s14",
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001659 [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001660 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
Steven Eastland48315592010-08-06 15:07:35 -06001661 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001662};
1663
Takashi Iwai2b635362011-05-02 12:33:43 +02001664static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001665 /* SigmaTel reference board */
1666 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001667 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001668 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1669 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001670 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1671 "unknown Dell", STAC_DELL_S14),
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001672 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
1673 "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001674 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
1675 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1676 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
1677 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1678 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
1679 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1680 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
1681 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1682 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
1683 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1684 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1685 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1686 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1687 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1688 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
1689 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1690 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
1691 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1692 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
1693 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1694 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
1695 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1696 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
1697 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1698 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
1699 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1700 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
1701 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1702 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
1703 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1704 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
1705 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1706 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
1707 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1708 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
1709 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1710 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
1711 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1712 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
1713 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001714 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001715};
1716
Takashi Iwai2b635362011-05-02 12:33:43 +02001717static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001718 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001719 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001720 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1721 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001722};
1723
Takashi Iwai2b635362011-05-02 12:33:43 +02001724static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001725 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001726 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001727 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1728 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001729};
1730
Takashi Iwai2b635362011-05-02 12:33:43 +02001731static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001732 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1733 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001734 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1735 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001736};
1737
Takashi Iwai2b635362011-05-02 12:33:43 +02001738static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001739 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1740 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001741 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1742 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001743};
1744
Takashi Iwai2b635362011-05-02 12:33:43 +02001745static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001746 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001747 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1748 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001749 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001750 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001751 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001752 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001753 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001754 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001755};
1756
Takashi Iwaiea734962011-01-17 11:29:34 +01001757static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001758 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001759 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001760 [STAC_DELL_M4_1] = "dell-m4-1",
1761 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001762 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001763 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001764 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001765 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001766 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001767 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001768};
1769
Takashi Iwai2b635362011-05-02 12:33:43 +02001770static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001771 /* SigmaTel reference board */
1772 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1773 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001774 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1775 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001776 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1777 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01001778 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1779 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01001780 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1781 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001782 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001783 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001784 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1785 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001786 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1787 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001788 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001789 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001790 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001791 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001792 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1793 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05301794 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1795 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11001796 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1797 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02001798 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1799 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001800 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1801 "unknown Dell", STAC_DELL_M4_1),
1802 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1803 "unknown Dell", STAC_DELL_M4_1),
1804 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1805 "unknown Dell", STAC_DELL_M4_1),
1806 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1807 "unknown Dell", STAC_DELL_M4_1),
1808 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1809 "unknown Dell", STAC_DELL_M4_1),
1810 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1811 "unknown Dell", STAC_DELL_M4_1),
1812 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1813 "unknown Dell", STAC_DELL_M4_1),
1814 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1815 "unknown Dell", STAC_DELL_M4_2),
1816 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1817 "unknown Dell", STAC_DELL_M4_2),
1818 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1819 "unknown Dell", STAC_DELL_M4_2),
1820 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1821 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001822 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1823 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001824 {} /* terminator */
1825};
1826
Takashi Iwai2b635362011-05-02 12:33:43 +02001827static const unsigned int ref922x_pin_configs[10] = {
Matt Porter403d1942005-11-29 15:00:51 +01001828 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1829 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001830 0x40000100, 0x40000100,
1831};
1832
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001833/*
1834 STAC 922X pin configs for
1835 102801A7
1836 102801AB
1837 102801A9
1838 102801D1
1839 102801D2
1840*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001841static const unsigned int dell_922x_d81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001842 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1843 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1844 0x01813122, 0x400001f2,
1845};
1846
1847/*
1848 STAC 922X pin configs for
1849 102801AC
1850 102801D0
1851*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001852static const unsigned int dell_922x_d82_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001853 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1854 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1855 0x01813122, 0x400001f1,
1856};
1857
1858/*
1859 STAC 922X pin configs for
1860 102801BF
1861*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001862static const unsigned int dell_922x_m81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001863 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1864 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1865 0x40C003f1, 0x405003f0,
1866};
1867
1868/*
1869 STAC 9221 A1 pin configs for
1870 102801D7 (Dell XPS M1210)
1871*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001872static const unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001873 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1874 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001875 0x508003f3, 0x405003f4,
1876};
1877
Takashi Iwai2b635362011-05-02 12:33:43 +02001878static const unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001879 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001880 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1881 0x02a19120, 0x40000100,
1882};
1883
Takashi Iwai2b635362011-05-02 12:33:43 +02001884static const unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001885 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1886 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001887 0x02a19320, 0x40000100,
1888};
1889
Takashi Iwai2b635362011-05-02 12:33:43 +02001890static const unsigned int intel_mac_v1_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001891 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1892 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001893 0x400000fc, 0x400000fb,
1894};
1895
Takashi Iwai2b635362011-05-02 12:33:43 +02001896static const unsigned int intel_mac_v2_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001897 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1898 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001899 0x400000fc, 0x400000fb,
1900};
1901
Takashi Iwai2b635362011-05-02 12:33:43 +02001902static const unsigned int intel_mac_v3_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001903 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1904 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1905 0x400000fc, 0x400000fb,
1906};
1907
Takashi Iwai2b635362011-05-02 12:33:43 +02001908static const unsigned int intel_mac_v4_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001909 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1910 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1911 0x400000fc, 0x400000fb,
1912};
1913
Takashi Iwai2b635362011-05-02 12:33:43 +02001914static const unsigned int intel_mac_v5_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001915 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1916 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1917 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001918};
1919
Takashi Iwai2b635362011-05-02 12:33:43 +02001920static const unsigned int ecs202_pin_configs[10] = {
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001921 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1922 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1923 0x9037012e, 0x40e000f2,
1924};
Takashi Iwai76c08822007-06-19 12:17:42 +02001925
Takashi Iwai2b635362011-05-02 12:33:43 +02001926static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001927 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001928 [STAC_D945GTP3] = d945gtp3_pin_configs,
1929 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001930 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1931 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1932 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1933 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1934 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001935 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001936 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001937 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1938 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1939 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1940 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1941 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1942 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001943 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001944 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1945 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1946 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1947 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001948};
1949
Takashi Iwaiea734962011-01-17 11:29:34 +01001950static const char * const stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001951 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001952 [STAC_D945_REF] = "ref",
1953 [STAC_D945GTP5] = "5stack",
1954 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001955 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1956 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1957 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1958 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1959 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001960 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001961 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001962 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001963 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001964 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1965 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001966 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001967 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001968 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001969 [STAC_922X_DELL_D81] = "dell-d81",
1970 [STAC_922X_DELL_D82] = "dell-d82",
1971 [STAC_922X_DELL_M81] = "dell-m81",
1972 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001973};
1974
Takashi Iwai2b635362011-05-02 12:33:43 +02001975static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001976 /* SigmaTel reference board */
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1978 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001979 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1980 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001981 /* Intel 945G based systems */
1982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1983 "Intel D945G", STAC_D945GTP3),
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1985 "Intel D945G", STAC_D945GTP3),
1986 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1987 "Intel D945G", STAC_D945GTP3),
1988 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1989 "Intel D945G", STAC_D945GTP3),
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1991 "Intel D945G", STAC_D945GTP3),
1992 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1993 "Intel D945G", STAC_D945GTP3),
1994 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1995 "Intel D945G", STAC_D945GTP3),
1996 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1997 "Intel D945G", STAC_D945GTP3),
1998 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1999 "Intel D945G", STAC_D945GTP3),
2000 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2001 "Intel D945G", STAC_D945GTP3),
2002 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2003 "Intel D945G", STAC_D945GTP3),
2004 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2005 "Intel D945G", STAC_D945GTP3),
2006 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2007 "Intel D945G", STAC_D945GTP3),
2008 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2009 "Intel D945G", STAC_D945GTP3),
2010 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2011 "Intel D945G", STAC_D945GTP3),
2012 /* Intel D945G 5-stack systems */
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2014 "Intel D945G", STAC_D945GTP5),
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2016 "Intel D945G", STAC_D945GTP5),
2017 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2018 "Intel D945G", STAC_D945GTP5),
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2020 "Intel D945G", STAC_D945GTP5),
2021 /* Intel 945P based systems */
2022 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2023 "Intel D945P", STAC_D945GTP3),
2024 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2025 "Intel D945P", STAC_D945GTP3),
2026 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2027 "Intel D945P", STAC_D945GTP3),
2028 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2029 "Intel D945P", STAC_D945GTP3),
2030 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2031 "Intel D945P", STAC_D945GTP3),
2032 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2033 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002034 /* other intel */
2035 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2036 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002037 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002038 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002039 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002040 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002041 /* Dell systems */
2042 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2043 "unknown Dell", STAC_922X_DELL_D81),
2044 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2045 "unknown Dell", STAC_922X_DELL_D81),
2046 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2047 "unknown Dell", STAC_922X_DELL_D81),
2048 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2049 "unknown Dell", STAC_922X_DELL_D82),
2050 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2051 "unknown Dell", STAC_922X_DELL_M81),
2052 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2053 "unknown Dell", STAC_922X_DELL_D82),
2054 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2055 "unknown Dell", STAC_922X_DELL_D81),
2056 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2057 "unknown Dell", STAC_922X_DELL_D81),
2058 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2059 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002060 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002061 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002062 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002063 {} /* terminator */
2064};
2065
Takashi Iwai2b635362011-05-02 12:33:43 +02002066static const unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002067 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2068 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2069 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2070 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002071};
2072
Takashi Iwai2b635362011-05-02 12:33:43 +02002073static const unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002074 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2075 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2076 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2077 0x40000100, 0x40000100
2078};
2079
Takashi Iwai2b635362011-05-02 12:33:43 +02002080static const unsigned int d965_5st_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002081 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2082 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2083 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2084 0x40000100, 0x40000100
2085};
2086
Takashi Iwai2b635362011-05-02 12:33:43 +02002087static const unsigned int d965_5st_no_fp_pin_configs[14] = {
Takashi Iwai679d92e2009-05-24 19:00:08 +02002088 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2089 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2090 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2091 0x40000100, 0x40000100
2092};
2093
Takashi Iwai2b635362011-05-02 12:33:43 +02002094static const unsigned int dell_3st_pin_configs[14] = {
Tobin Davis4ff076e2007-08-07 11:48:12 +02002095 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2096 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002097 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002098 0x40c003fc, 0x40000100
2099};
2100
Takashi Iwai2b635362011-05-02 12:33:43 +02002101static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002102 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002103 [STAC_D965_REF] = ref927x_pin_configs,
2104 [STAC_D965_3ST] = d965_3st_pin_configs,
2105 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002106 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002107 [STAC_DELL_3ST] = dell_3st_pin_configs,
2108 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002109 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002110};
2111
Takashi Iwaiea734962011-01-17 11:29:34 +01002112static const char * const stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002113 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002114 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002115 [STAC_D965_REF] = "ref",
2116 [STAC_D965_3ST] = "3stack",
2117 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002118 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002119 [STAC_DELL_3ST] = "dell-3stack",
2120 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002121 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002122};
2123
Takashi Iwai2b635362011-05-02 12:33:43 +02002124static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002125 /* SigmaTel reference board */
2126 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2127 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002128 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2129 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002130 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002131 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2132 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002133 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002134 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2135 "Intel D965", STAC_D965_3ST),
2136 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2137 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002138 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002139 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002140 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2141 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002142 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002143 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002144 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002145 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002146 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002147 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002148 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2149 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2150 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2151 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002152 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002153 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2154 "Intel D965", STAC_D965_5ST),
2155 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2156 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002157 /* volume-knob fixes */
2158 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002159 {} /* terminator */
2160};
2161
Takashi Iwai2b635362011-05-02 12:33:43 +02002162static const unsigned int ref9205_pin_configs[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +02002163 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002164 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002165 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002166};
2167
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002168/*
2169 STAC 9205 pin configs for
2170 102801F1
2171 102801F2
2172 102801FC
2173 102801FD
2174 10280204
2175 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002176 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002177 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002178*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002179static const unsigned int dell_9205_m42_pin_configs[12] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002180 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2181 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2182 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2183};
2184
2185/*
2186 STAC 9205 pin configs for
2187 102801F9
2188 102801FA
2189 102801FE
2190 102801FF (Dell Precision M4300)
2191 10280206
2192 10280200
2193 10280201
2194*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002195static const unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002196 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2197 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2198 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2199};
2200
Takashi Iwai2b635362011-05-02 12:33:43 +02002201static const unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002202 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2203 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2204 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2205};
2206
Takashi Iwai2b635362011-05-02 12:33:43 +02002207static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002208 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002209 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2210 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2211 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002212 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002213};
2214
Takashi Iwaiea734962011-01-17 11:29:34 +01002215static const char * const stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002216 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002217 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002218 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002219 [STAC_9205_DELL_M43] = "dell-m43",
2220 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002221 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002222};
2223
Takashi Iwai2b635362011-05-02 12:33:43 +02002224static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002225 /* SigmaTel reference board */
2226 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2227 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002228 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2229 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002230 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2231 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002232 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002233 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2234 "unknown Dell", STAC_9205_DELL_M42),
2235 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2236 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002237 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002238 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002239 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2240 "Dell Precision", STAC_9205_DELL_M43),
2241 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2242 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002243 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2244 "unknown Dell", STAC_9205_DELL_M42),
2245 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2246 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002247 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2248 "Dell Precision", STAC_9205_DELL_M43),
2249 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002250 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002251 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2252 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002253 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2254 "Dell Precision", STAC_9205_DELL_M43),
2255 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2256 "Dell Precision", STAC_9205_DELL_M43),
2257 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2258 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002259 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2260 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002261 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2262 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002263 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2264 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002265 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002266 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002267 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002268 {} /* terminator */
2269};
2270
Takashi Iwai330ee992009-02-20 14:33:36 +01002271static void stac92xx_set_config_regs(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002272 const unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002273{
2274 int i;
2275 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002276
Takashi Iwai330ee992009-02-20 14:33:36 +01002277 if (!pincfgs)
2278 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002279
Matthew Ranostay87d48362007-07-17 11:52:24 +02002280 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002281 if (spec->pin_nids[i] && pincfgs[i])
2282 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2283 pincfgs[i]);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002284}
2285
Matt2f2f4252005-04-13 14:45:30 +02002286/*
2287 * Analog playback callbacks
2288 */
2289static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2290 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002291 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002292{
2293 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002294 if (spec->stream_delay)
2295 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002296 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2297 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002298}
2299
2300static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2301 struct hda_codec *codec,
2302 unsigned int stream_tag,
2303 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002304 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002305{
2306 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002307 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002308}
2309
2310static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2311 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002312 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002313{
2314 struct sigmatel_spec *spec = codec->spec;
2315 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2316}
2317
2318/*
Mattdabbed62005-06-14 10:19:34 +02002319 * Digital playback callbacks
2320 */
2321static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2322 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002323 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002324{
2325 struct sigmatel_spec *spec = codec->spec;
2326 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2327}
2328
2329static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2330 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002331 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002332{
2333 struct sigmatel_spec *spec = codec->spec;
2334 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2335}
2336
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002337static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2338 struct hda_codec *codec,
2339 unsigned int stream_tag,
2340 unsigned int format,
2341 struct snd_pcm_substream *substream)
2342{
2343 struct sigmatel_spec *spec = codec->spec;
2344 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2345 stream_tag, format, substream);
2346}
2347
Takashi Iwai9411e212009-02-13 11:32:28 +01002348static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2349 struct hda_codec *codec,
2350 struct snd_pcm_substream *substream)
2351{
2352 struct sigmatel_spec *spec = codec->spec;
2353 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2354}
2355
Mattdabbed62005-06-14 10:19:34 +02002356
2357/*
Matt2f2f4252005-04-13 14:45:30 +02002358 * Analog capture callbacks
2359 */
2360static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2361 struct hda_codec *codec,
2362 unsigned int stream_tag,
2363 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002364 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002365{
2366 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002367 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002368
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002369 if (spec->powerdown_adcs) {
2370 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002371 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002372 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2373 }
2374 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002375 return 0;
2376}
2377
2378static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2379 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002380 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002381{
2382 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002383 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002384
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002385 snd_hda_codec_cleanup_stream(codec, nid);
2386 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002387 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002388 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002389 return 0;
2390}
2391
Takashi Iwai2b635362011-05-02 12:33:43 +02002392static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
Mattdabbed62005-06-14 10:19:34 +02002393 .substreams = 1,
2394 .channels_min = 2,
2395 .channels_max = 2,
2396 /* NID is set in stac92xx_build_pcms */
2397 .ops = {
2398 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002399 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002400 .prepare = stac92xx_dig_playback_pcm_prepare,
2401 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002402 },
2403};
2404
Takashi Iwai2b635362011-05-02 12:33:43 +02002405static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
Mattdabbed62005-06-14 10:19:34 +02002406 .substreams = 1,
2407 .channels_min = 2,
2408 .channels_max = 2,
2409 /* NID is set in stac92xx_build_pcms */
2410};
2411
Takashi Iwai2b635362011-05-02 12:33:43 +02002412static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
Matt2f2f4252005-04-13 14:45:30 +02002413 .substreams = 1,
2414 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002415 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002416 .nid = 0x02, /* NID to query formats and rates */
2417 .ops = {
2418 .open = stac92xx_playback_pcm_open,
2419 .prepare = stac92xx_playback_pcm_prepare,
2420 .cleanup = stac92xx_playback_pcm_cleanup
2421 },
2422};
2423
Takashi Iwai2b635362011-05-02 12:33:43 +02002424static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002425 .substreams = 1,
2426 .channels_min = 2,
2427 .channels_max = 2,
2428 .nid = 0x06, /* NID to query formats and rates */
2429 .ops = {
2430 .open = stac92xx_playback_pcm_open,
2431 .prepare = stac92xx_playback_pcm_prepare,
2432 .cleanup = stac92xx_playback_pcm_cleanup
2433 },
2434};
2435
Takashi Iwai2b635362011-05-02 12:33:43 +02002436static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002437 .channels_min = 2,
2438 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002439 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002440 .ops = {
2441 .prepare = stac92xx_capture_pcm_prepare,
2442 .cleanup = stac92xx_capture_pcm_cleanup
2443 },
2444};
2445
2446static int stac92xx_build_pcms(struct hda_codec *codec)
2447{
2448 struct sigmatel_spec *spec = codec->spec;
2449 struct hda_pcm *info = spec->pcm_rec;
2450
2451 codec->num_pcms = 1;
2452 codec->pcm_info = info;
2453
Mattc7d4b2f2005-06-27 14:59:41 +02002454 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002455 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002456 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2457 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002458 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002459 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002460 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002461
2462 if (spec->alt_switch) {
2463 codec->num_pcms++;
2464 info++;
2465 info->name = "STAC92xx Analog Alt";
2466 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2467 }
Matt2f2f4252005-04-13 14:45:30 +02002468
Mattdabbed62005-06-14 10:19:34 +02002469 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2470 codec->num_pcms++;
2471 info++;
2472 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002473 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002474 if (spec->multiout.dig_out_nid) {
2475 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2476 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2477 }
2478 if (spec->dig_in_nid) {
2479 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2480 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2481 }
2482 }
2483
Matt2f2f4252005-04-13 14:45:30 +02002484 return 0;
2485}
2486
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002487static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2488 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002489{
Takashi Iwai1327a322009-03-23 13:07:47 +01002490 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002491 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2492 if (pincap & AC_PINCAP_VREF_100)
2493 return AC_PINCTL_VREF_100;
2494 if (pincap & AC_PINCAP_VREF_80)
2495 return AC_PINCTL_VREF_80;
2496 if (pincap & AC_PINCAP_VREF_50)
2497 return AC_PINCTL_VREF_50;
2498 if (pincap & AC_PINCAP_VREF_GRD)
2499 return AC_PINCTL_VREF_GRD;
2500 return 0;
2501}
2502
Matt Porter403d1942005-11-29 15:00:51 +01002503static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2504
2505{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002506 snd_hda_codec_write_cache(codec, nid, 0,
2507 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002508}
2509
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002510#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2511
2512static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2513 struct snd_ctl_elem_value *ucontrol)
2514{
2515 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2516 struct sigmatel_spec *spec = codec->spec;
2517
Takashi Iwaid7a89432008-11-12 09:48:04 +01002518 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002519 return 0;
2520}
2521
Takashi Iwai62558ce2009-07-29 14:23:09 +02002522static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002523
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002524static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2525 struct snd_ctl_elem_value *ucontrol)
2526{
2527 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2528 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002529 int nid = kcontrol->private_value;
2530
2531 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002532
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002533 /* check to be sure that the ports are up to date with
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002534 * switch changes
2535 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002536 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002537
2538 return 1;
2539}
2540
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002541static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2542 struct snd_ctl_elem_info *uinfo)
2543{
2544 int i;
Takashi Iwai2b635362011-05-02 12:33:43 +02002545 static const char * const texts[] = {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002546 "Mic In", "Line In", "Line Out"
2547 };
2548
2549 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2550 struct sigmatel_spec *spec = codec->spec;
2551 hda_nid_t nid = kcontrol->private_value;
2552
2553 if (nid == spec->mic_switch || nid == spec->line_switch)
2554 i = 3;
2555 else
2556 i = 2;
2557
2558 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2559 uinfo->value.enumerated.items = i;
2560 uinfo->count = 1;
2561 if (uinfo->value.enumerated.item >= i)
2562 uinfo->value.enumerated.item = i-1;
2563 strcpy(uinfo->value.enumerated.name,
2564 texts[uinfo->value.enumerated.item]);
2565
2566 return 0;
2567}
2568
2569static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2570 struct snd_ctl_elem_value *ucontrol)
2571{
2572 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2573 hda_nid_t nid = kcontrol->private_value;
2574 unsigned int vref = stac92xx_vref_get(codec, nid);
2575
2576 if (vref == stac92xx_get_default_vref(codec, nid))
2577 ucontrol->value.enumerated.item[0] = 0;
2578 else if (vref == AC_PINCTL_VREF_GRD)
2579 ucontrol->value.enumerated.item[0] = 1;
2580 else if (vref == AC_PINCTL_VREF_HIZ)
2581 ucontrol->value.enumerated.item[0] = 2;
2582
2583 return 0;
2584}
2585
2586static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2587 struct snd_ctl_elem_value *ucontrol)
2588{
2589 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2590 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002591 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002592 hda_nid_t nid = kcontrol->private_value;
2593
2594 if (ucontrol->value.enumerated.item[0] == 0)
2595 new_vref = stac92xx_get_default_vref(codec, nid);
2596 else if (ucontrol->value.enumerated.item[0] == 1)
2597 new_vref = AC_PINCTL_VREF_GRD;
2598 else if (ucontrol->value.enumerated.item[0] == 2)
2599 new_vref = AC_PINCTL_VREF_HIZ;
2600 else
2601 return 0;
2602
2603 if (new_vref != stac92xx_vref_get(codec, nid)) {
2604 error = stac92xx_vref_set(codec, nid, new_vref);
2605 return error;
2606 }
2607
2608 return 0;
2609}
2610
2611static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2612 struct snd_ctl_elem_info *uinfo)
2613{
Takashi Iwai2b635362011-05-02 12:33:43 +02002614 char *texts[2];
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2616 struct sigmatel_spec *spec = codec->spec;
2617
2618 if (kcontrol->private_value == spec->line_switch)
2619 texts[0] = "Line In";
2620 else
2621 texts[0] = "Mic In";
2622 texts[1] = "Line Out";
2623 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2624 uinfo->value.enumerated.items = 2;
2625 uinfo->count = 1;
2626
2627 if (uinfo->value.enumerated.item >= 2)
2628 uinfo->value.enumerated.item = 1;
2629 strcpy(uinfo->value.enumerated.name,
2630 texts[uinfo->value.enumerated.item]);
2631
2632 return 0;
2633}
Matt Porter403d1942005-11-29 15:00:51 +01002634
2635static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2636{
2637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2638 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002639 hda_nid_t nid = kcontrol->private_value;
2640 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002641
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002642 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002643 return 0;
2644}
2645
2646static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2647{
2648 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2649 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002650 hda_nid_t nid = kcontrol->private_value;
2651 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2652 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002653
2654 spec->io_switch[io_idx] = val;
2655
2656 if (val)
2657 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002658 else {
2659 unsigned int pinctl = AC_PINCTL_IN_EN;
2660 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002661 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002662 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2663 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002664
2665 /* check the auto-mute again: we need to mute/unmute the speaker
2666 * appropriately according to the pin direction
2667 */
2668 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002669 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002670
Matt Porter403d1942005-11-29 15:00:51 +01002671 return 1;
2672}
2673
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002674#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2675
2676static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2677 struct snd_ctl_elem_value *ucontrol)
2678{
2679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2680 struct sigmatel_spec *spec = codec->spec;
2681
2682 ucontrol->value.integer.value[0] = spec->clfe_swap;
2683 return 0;
2684}
2685
2686static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2687 struct snd_ctl_elem_value *ucontrol)
2688{
2689 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2690 struct sigmatel_spec *spec = codec->spec;
2691 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002692 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002693
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002694 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002695 return 0;
2696
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002697 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002698
2699 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2700 spec->clfe_swap ? 0x4 : 0x0);
2701
2702 return 1;
2703}
2704
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002705#define STAC_CODEC_HP_SWITCH(xname) \
2706 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2707 .name = xname, \
2708 .index = 0, \
2709 .info = stac92xx_hp_switch_info, \
2710 .get = stac92xx_hp_switch_get, \
2711 .put = stac92xx_hp_switch_put, \
2712 }
2713
Matt Porter403d1942005-11-29 15:00:51 +01002714#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2715 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2716 .name = xname, \
2717 .index = 0, \
2718 .info = stac92xx_io_switch_info, \
2719 .get = stac92xx_io_switch_get, \
2720 .put = stac92xx_io_switch_put, \
2721 .private_value = xpval, \
2722 }
2723
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002724#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2725 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2726 .name = xname, \
2727 .index = 0, \
2728 .info = stac92xx_clfe_switch_info, \
2729 .get = stac92xx_clfe_switch_get, \
2730 .put = stac92xx_clfe_switch_put, \
2731 .private_value = xpval, \
2732 }
Matt Porter403d1942005-11-29 15:00:51 +01002733
Mattc7d4b2f2005-06-27 14:59:41 +02002734enum {
2735 STAC_CTL_WIDGET_VOL,
2736 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002737 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002738 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002739 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002740 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002741 STAC_CTL_WIDGET_CLFE_SWITCH,
2742 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002743};
2744
Takashi Iwai2b635362011-05-02 12:33:43 +02002745static const struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002746 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2747 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002748 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002749 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002750 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002751 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002752 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002753 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002754};
2755
2756/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002757static struct snd_kcontrol_new *
2758stac_control_new(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002759 const struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002760 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002761 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002762{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002763 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002764
Takashi Iwai603c4012008-07-30 15:01:44 +02002765 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2766 knew = snd_array_new(&spec->kctls);
2767 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002768 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002769 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002770 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002771 if (!knew->name) {
2772 /* roolback */
2773 memset(knew, 0, sizeof(*knew));
2774 spec->kctls.alloced--;
2775 return NULL;
2776 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002777 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002778 return knew;
2779}
2780
2781static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002782 const struct snd_kcontrol_new *ktemp,
Takashi Iwaie3c75962009-01-23 11:57:22 +01002783 int idx, const char *name,
2784 unsigned long val)
2785{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002786 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002787 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002788 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002789 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002790 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002791 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002792 return 0;
2793}
2794
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002795static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2796 int type, int idx, const char *name,
2797 unsigned long val)
2798{
2799 return stac92xx_add_control_temp(spec,
2800 &stac92xx_control_templates[type],
2801 idx, name, val);
2802}
2803
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002804
2805/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002806static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2807 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002808{
2809 return stac92xx_add_control_idx(spec, type, 0, name, val);
2810}
2811
Takashi Iwai2b635362011-05-02 12:33:43 +02002812static const struct snd_kcontrol_new stac_input_src_temp = {
Takashi Iwaie3c75962009-01-23 11:57:22 +01002813 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2814 .name = "Input Source",
2815 .info = stac92xx_mux_enum_info,
2816 .get = stac92xx_mux_enum_get,
2817 .put = stac92xx_mux_enum_put,
2818};
2819
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002820static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2821 hda_nid_t nid, int idx)
2822{
2823 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2824 int control = 0;
2825 struct sigmatel_spec *spec = codec->spec;
2826 char name[22];
2827
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002828 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002829 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2830 && nid == spec->line_switch)
2831 control = STAC_CTL_WIDGET_IO_SWITCH;
2832 else if (snd_hda_query_pin_caps(codec, nid)
2833 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2834 control = STAC_CTL_WIDGET_DC_BIAS;
2835 else if (nid == spec->mic_switch)
2836 control = STAC_CTL_WIDGET_IO_SWITCH;
2837 }
2838
2839 if (control) {
Takashi Iwai201e06f2011-11-16 15:33:26 +01002840 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
2841 name, sizeof(name), NULL);
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002842 return stac92xx_add_control(codec->spec, control,
2843 strcat(name, " Jack Mode"), nid);
2844 }
2845
2846 return 0;
2847}
2848
Takashi Iwaie3c75962009-01-23 11:57:22 +01002849static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2850{
2851 struct snd_kcontrol_new *knew;
2852 struct hda_input_mux *imux = &spec->private_imux;
2853
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002854 if (spec->auto_mic)
2855 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002856 if (!spec->num_adcs || imux->num_items <= 1)
2857 return 0; /* no need for input source control */
2858 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002859 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002860 if (!knew)
2861 return -ENOMEM;
2862 knew->count = spec->num_adcs;
2863 return 0;
2864}
2865
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002866/* check whether the line-input can be used as line-out */
2867static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002868{
2869 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002870 struct auto_pin_cfg *cfg = &spec->autocfg;
2871 hda_nid_t nid;
2872 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002873 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002874
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002875 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2876 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002877 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02002878 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002879 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01002880 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002881 if (pincap & AC_PINCAP_OUT)
2882 return nid;
2883 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002884 }
Matt Porter403d1942005-11-29 15:00:51 +01002885 return 0;
2886}
2887
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002888static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2889
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002890/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002891static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002892{
2893 struct sigmatel_spec *spec = codec->spec;
2894 struct auto_pin_cfg *cfg = &spec->autocfg;
2895 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02002896 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002897
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002898 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002899 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2900 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002901 for (i = 0; i < cfg->num_inputs; i++) {
2902 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02002903 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002904 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002905 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2906 /* some laptops have an internal analog microphone
2907 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002908 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002909 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002910 if (pincap & AC_PINCAP_OUT) {
2911 *dac = get_unassigned_dac(codec, nid);
2912 if (*dac)
2913 return nid;
2914 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002915 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002916 }
2917 return 0;
2918}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002919
2920static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2921{
2922 int i;
2923
2924 for (i = 0; i < spec->multiout.num_dacs; i++) {
2925 if (spec->multiout.dac_nids[i] == nid)
2926 return 1;
2927 }
2928
2929 return 0;
2930}
2931
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002932static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2933{
2934 int i;
2935 if (is_in_dac_nids(spec, nid))
2936 return 1;
2937 for (i = 0; i < spec->autocfg.hp_outs; i++)
2938 if (spec->hp_dacs[i] == nid)
2939 return 1;
2940 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2941 if (spec->speaker_dacs[i] == nid)
2942 return 1;
2943 return 0;
2944}
2945
2946static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2947{
2948 struct sigmatel_spec *spec = codec->spec;
David Henningsson48718ea2011-10-05 09:49:05 +02002949 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002950 int j, conn_len;
David Henningsson48718ea2011-10-05 09:49:05 +02002951 hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002952 unsigned int wcaps, wtype;
2953
2954 conn_len = snd_hda_get_connections(codec, nid, conn,
2955 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002956 /* 92HD88: trace back up the link of nids to find the DAC */
2957 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2958 != AC_WID_AUD_OUT)) {
2959 nid = conn[0];
2960 conn_len = snd_hda_get_connections(codec, nid, conn,
2961 HDA_MAX_CONNECTIONS);
2962 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002963 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002964 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002965 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002966 /* we check only analog outputs */
2967 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2968 continue;
2969 /* if this route has a free DAC, assign it */
2970 if (!check_all_dac_nids(spec, conn[j])) {
2971 if (conn_len > 1) {
2972 /* select this DAC in the pin's input mux */
2973 snd_hda_codec_write_cache(codec, nid, 0,
2974 AC_VERB_SET_CONNECT_SEL, j);
2975 }
2976 return conn[j];
2977 }
2978 }
David Henningsson48718ea2011-10-05 09:49:05 +02002979
2980 /* if all DACs are already assigned, connect to the primary DAC,
2981 unless we're assigning a secondary headphone */
2982 fallback_dac = spec->multiout.dac_nids[0];
2983 if (spec->multiout.hp_nid) {
2984 for (j = 0; j < cfg->hp_outs; j++)
2985 if (cfg->hp_pins[j] == nid) {
2986 fallback_dac = spec->multiout.hp_nid;
2987 break;
2988 }
2989 }
2990
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002991 if (conn_len > 1) {
2992 for (j = 0; j < conn_len; j++) {
David Henningsson48718ea2011-10-05 09:49:05 +02002993 if (conn[j] == fallback_dac) {
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002994 snd_hda_codec_write_cache(codec, nid, 0,
2995 AC_VERB_SET_CONNECT_SEL, j);
2996 break;
2997 }
2998 }
2999 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003000 return 0;
3001}
3002
3003static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3004static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3005
Matt Porter3cc08dc2006-01-23 15:27:49 +01003006/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02003007 * Fill in the dac_nids table from the parsed pin configuration
3008 * This function only works when every pin in line_out_pins[]
3009 * contains atleast one DAC in its connection list. Some 92xx
3010 * codecs are not connected directly to a DAC, such as the 9200
3011 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01003012 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003013static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003014{
3015 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003016 struct auto_pin_cfg *cfg = &spec->autocfg;
3017 int i;
3018 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02003019
Mattc7d4b2f2005-06-27 14:59:41 +02003020 for (i = 0; i < cfg->line_outs; i++) {
3021 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003022 dac = get_unassigned_dac(codec, nid);
3023 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003024 if (spec->multiout.num_dacs > 0) {
3025 /* we have already working output pins,
3026 * so let's drop the broken ones again
3027 */
3028 cfg->line_outs = spec->multiout.num_dacs;
3029 break;
3030 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003031 /* error out, no available DAC found */
3032 snd_printk(KERN_ERR
3033 "%s: No available DAC for pin 0x%x\n",
3034 __func__, nid);
3035 return -ENODEV;
3036 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003037 add_spec_dacs(spec, dac);
3038 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003039
Takashi Iwai139e0712009-03-06 12:10:41 +01003040 for (i = 0; i < cfg->hp_outs; i++) {
3041 nid = cfg->hp_pins[i];
3042 dac = get_unassigned_dac(codec, nid);
3043 if (dac) {
3044 if (!spec->multiout.hp_nid)
3045 spec->multiout.hp_nid = dac;
3046 else
3047 add_spec_extra_dacs(spec, dac);
3048 }
3049 spec->hp_dacs[i] = dac;
3050 }
3051
3052 for (i = 0; i < cfg->speaker_outs; i++) {
3053 nid = cfg->speaker_pins[i];
3054 dac = get_unassigned_dac(codec, nid);
3055 if (dac)
3056 add_spec_extra_dacs(spec, dac);
3057 spec->speaker_dacs[i] = dac;
3058 }
3059
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003060 /* add line-in as output */
3061 nid = check_line_out_switch(codec);
3062 if (nid) {
3063 dac = get_unassigned_dac(codec, nid);
3064 if (dac) {
3065 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3066 nid, cfg->line_outs);
3067 cfg->line_out_pins[cfg->line_outs] = nid;
3068 cfg->line_outs++;
3069 spec->line_switch = nid;
3070 add_spec_dacs(spec, dac);
3071 }
3072 }
3073 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003074 nid = check_mic_out_switch(codec, &dac);
3075 if (nid && dac) {
3076 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3077 nid, cfg->line_outs);
3078 cfg->line_out_pins[cfg->line_outs] = nid;
3079 cfg->line_outs++;
3080 spec->mic_switch = nid;
3081 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003082 }
3083
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003084 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003085 spec->multiout.num_dacs,
3086 spec->multiout.dac_nids[0],
3087 spec->multiout.dac_nids[1],
3088 spec->multiout.dac_nids[2],
3089 spec->multiout.dac_nids[3],
3090 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003091
Mattc7d4b2f2005-06-27 14:59:41 +02003092 return 0;
3093}
3094
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003095/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003096static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3097 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003098{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003099 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003100 char name[32];
3101 int err;
3102
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003103 if (!spec->check_volume_offset) {
3104 unsigned int caps, step, nums, db_scale;
3105 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3106 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3107 AC_AMPCAP_STEP_SIZE_SHIFT;
3108 step = (step + 1) * 25; /* in .01dB unit */
3109 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3110 AC_AMPCAP_NUM_STEPS_SHIFT;
3111 db_scale = nums * step;
3112 /* if dB scale is over -64dB, and finer enough,
3113 * let's reduce it to half
3114 */
3115 if (db_scale > 6400 && nums >= 0x1f)
3116 spec->volume_offset = nums / 2;
3117 spec->check_volume_offset = 1;
3118 }
3119
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003120 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003121 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003122 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3123 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003124 if (err < 0)
3125 return err;
3126 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003127 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003128 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3129 if (err < 0)
3130 return err;
3131 return 0;
3132}
3133
Takashi Iwai668b9652009-03-06 10:13:24 +01003134#define create_controls(codec, pfx, nid, chs) \
3135 create_controls_idx(codec, pfx, 0, nid, chs)
3136
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003137static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3138{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003139 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003140 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3141 return 1;
3142 } else {
Takashi Iwaidda14412011-05-02 11:29:30 +02003143 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3144 spec->dac_nids[spec->multiout.num_dacs] = nid;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003145 spec->multiout.num_dacs++;
3146 }
3147 return 0;
3148}
3149
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003150static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003151{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003152 int i;
3153 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3154 if (!spec->multiout.extra_out_nid[i]) {
3155 spec->multiout.extra_out_nid[i] = nid;
3156 return 0;
3157 }
3158 }
3159 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3160 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003161}
3162
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003163/* Create output controls
3164 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3165 */
3166static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3167 const hda_nid_t *pins,
3168 const hda_nid_t *dac_nids,
3169 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003170{
Takashi Iwai76624532008-12-19 10:09:47 +01003171 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaiea734962011-01-17 11:29:34 +01003172 static const char * const chname[4] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02003173 "Front", "Surround", NULL /*CLFE*/, "Side"
3174 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003175 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003176 int i, err;
3177 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003178
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003179 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003180 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003181 if (is_jack_detectable(codec, pins[i]))
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003182 spec->hp_detect = 1;
3183 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003184 nid = dac_nids[i];
3185 if (!nid)
3186 continue;
3187 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003188 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003189 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003190 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003191 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003192 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003193 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003194 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003195
3196 wid_caps = get_wcaps(codec, nid);
3197
3198 if (wid_caps & AC_WCAP_LR_SWAP) {
3199 err = stac92xx_add_control(spec,
3200 STAC_CTL_WIDGET_CLFE_SWITCH,
3201 "Swap Center/LFE Playback Switch", nid);
3202
3203 if (err < 0)
3204 return err;
3205 }
3206
Mattc7d4b2f2005-06-27 14:59:41 +02003207 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003208 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003209 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003210 switch (type) {
3211 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003212 name = "Headphone";
3213 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003214 break;
3215 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003216 name = "Speaker";
3217 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003218 break;
3219 default:
3220 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003221 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003222 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003223 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003224 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003225 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003226 return err;
3227 }
3228 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003229 return 0;
3230}
3231
Takashi Iwai6479c632009-07-28 18:20:25 +02003232static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3233 unsigned long sw, int idx)
3234{
3235 int err;
3236 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003237 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003238 if (err < 0)
3239 return err;
3240 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003241 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003242 if (err < 0)
3243 return err;
3244 return 0;
3245}
3246
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003247/* add playback controls from the parsed DAC table */
3248static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3249 const struct auto_pin_cfg *cfg)
3250{
3251 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003252 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003253 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003254 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003255
3256 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3257 spec->multiout.dac_nids,
3258 cfg->line_out_type);
3259 if (err < 0)
3260 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003261
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003262 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003263 err = stac92xx_add_control(spec,
3264 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003265 "Headphone as Line Out Switch",
3266 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003267 if (err < 0)
3268 return err;
3269 }
3270
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003271 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003272 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003273 break;
3274 nid = cfg->inputs[idx].pin;
3275 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3276 if (err < 0)
3277 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003278 }
Matt Porter403d1942005-11-29 15:00:51 +01003279
Mattc7d4b2f2005-06-27 14:59:41 +02003280 return 0;
3281}
3282
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003283/* add playback controls for Speaker and HP outputs */
3284static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3285 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003286{
3287 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003288 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003289
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003290 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3291 spec->hp_dacs, AUTO_PIN_HP_OUT);
3292 if (err < 0)
3293 return err;
3294
3295 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3296 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3297 if (err < 0)
3298 return err;
3299
Mattc7d4b2f2005-06-27 14:59:41 +02003300 return 0;
3301}
3302
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003303/* labels for mono mux outputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003304static const char * const stac92xx_mono_labels[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003305 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003306};
3307
3308/* create mono mux for mono out on capable codecs */
3309static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3310{
3311 struct sigmatel_spec *spec = codec->spec;
3312 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3313 int i, num_cons;
3314 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3315
3316 num_cons = snd_hda_get_connections(codec,
3317 spec->mono_nid,
3318 con_lst,
3319 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003320 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003321 return -EINVAL;
3322
Takashi Iwai10a20af2010-09-09 16:28:02 +02003323 for (i = 0; i < num_cons; i++)
3324 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3325 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003326
3327 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3328 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003329}
3330
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003331/* create PC beep volume controls */
3332static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3333 hda_nid_t nid)
3334{
3335 struct sigmatel_spec *spec = codec->spec;
3336 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003337 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3338
3339 if (spec->anabeep_nid == nid)
3340 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003341
3342 /* check for mute support for the the amp */
3343 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003344 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003345 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003346 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3347 if (err < 0)
3348 return err;
3349 }
3350
3351 /* check to see if there is volume support for the amp */
3352 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3353 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003354 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003355 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3356 if (err < 0)
3357 return err;
3358 }
3359 return 0;
3360}
3361
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003362#ifdef CONFIG_SND_HDA_INPUT_BEEP
3363#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3364
3365static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3366 struct snd_ctl_elem_value *ucontrol)
3367{
3368 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3369 ucontrol->value.integer.value[0] = codec->beep->enabled;
3370 return 0;
3371}
3372
3373static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3374 struct snd_ctl_elem_value *ucontrol)
3375{
3376 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003377 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003378}
3379
Takashi Iwai2b635362011-05-02 12:33:43 +02003380static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003381 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3382 .info = stac92xx_dig_beep_switch_info,
3383 .get = stac92xx_dig_beep_switch_get,
3384 .put = stac92xx_dig_beep_switch_put,
3385};
3386
3387static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3388{
3389 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003390 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003391}
3392#endif
3393
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003394static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3395{
3396 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003397 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003398
3399 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003400 hda_nid_t nid;
3401 unsigned int wcaps;
3402 unsigned long val;
3403
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003404 nid = spec->mux_nids[i];
3405 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003406 if (!(wcaps & AC_WCAP_OUT_AMP))
3407 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003408
Takashi Iwai667067d2009-08-13 18:14:42 +02003409 /* check whether already the same control was created as
3410 * normal Capture Volume.
3411 */
3412 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3413 for (j = 0; j < spec->num_caps; j++) {
3414 if (spec->capvols[j] == val)
3415 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003416 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003417 if (j < spec->num_caps)
3418 continue;
3419
3420 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3421 "Mux Capture Volume", val);
3422 if (err < 0)
3423 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003424 }
3425 return 0;
3426};
3427
Takashi Iwaiea734962011-01-17 11:29:34 +01003428static const char * const stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003429 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003430};
3431
3432static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3433{
3434 struct sigmatel_spec *spec = codec->spec;
3435 struct hda_input_mux *spdif_mux = &spec->private_smux;
Takashi Iwaiea734962011-01-17 11:29:34 +01003436 const char * const *labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003437 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003438 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003439
3440 num_cons = snd_hda_get_connections(codec,
3441 spec->smux_nids[0],
3442 con_lst,
3443 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003444 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003445 return -EINVAL;
3446
Matthew Ranostay65973632008-09-16 10:39:37 -04003447 if (!labels)
3448 labels = stac92xx_spdif_labels;
3449
Takashi Iwai10a20af2010-09-09 16:28:02 +02003450 for (i = 0; i < num_cons; i++)
3451 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003452
3453 return 0;
3454}
3455
Matt Porter8b657272006-10-26 17:12:59 +02003456/* labels for dmic mux inputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003457static const char * const stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003458 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3459 "Digital Mic 3", "Digital Mic 4"
3460};
3461
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003462static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3463 int idx)
3464{
3465 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3466 int nums;
3467 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3468 if (idx >= 0 && idx < nums)
3469 return conn[idx];
3470 return 0;
3471}
3472
Takashi Iwai8d087c72011-06-28 12:45:47 +02003473/* look for NID recursively */
3474#define get_connection_index(codec, mux, nid) \
3475 snd_hda_get_conn_index(codec, mux, nid, 1)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003476
Takashi Iwai667067d2009-08-13 18:14:42 +02003477/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003478/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003479static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003480 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003481{
3482 unsigned int caps, nums;
3483 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003484 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003485
Takashi Iwai96f845d2009-08-29 00:49:36 +02003486 if (direction == HDA_OUTPUT)
3487 caps = AC_WCAP_OUT_AMP;
3488 else
3489 caps = AC_WCAP_IN_AMP;
3490 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003491 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003492 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003493 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3494 if (!nums)
3495 return 0;
3496 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003497 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3498 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003499 if (err < 0)
3500 return err;
3501 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003502}
3503
Matt Porter8b657272006-10-26 17:12:59 +02003504/* create playback/capture controls for input pins on dmic capable codecs */
3505static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3506 const struct auto_pin_cfg *cfg)
3507{
3508 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003509 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003510 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003511 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003512 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003513
Takashi Iwai10a20af2010-09-09 16:28:02 +02003514 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003515
Matt Porter8b657272006-10-26 17:12:59 +02003516 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003517 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003518 int index, type_idx;
Takashi Iwai201e06f2011-11-16 15:33:26 +01003519 char label[32];
Matt Porter8b657272006-10-26 17:12:59 +02003520
Takashi Iwai667067d2009-08-13 18:14:42 +02003521 nid = spec->dmic_nids[i];
3522 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3523 continue;
3524 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003525 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3526 continue;
3527
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003528 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3529 if (index < 0)
3530 continue;
3531
Takashi Iwai201e06f2011-11-16 15:33:26 +01003532 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
3533 label, sizeof(label), NULL);
Takashi Iwai10a20af2010-09-09 16:28:02 +02003534 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai2d7ec122010-12-23 10:16:05 +01003535 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3536 snd_hda_add_imux_item(imux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003537
Takashi Iwai10a20af2010-09-09 16:28:02 +02003538 err = create_elem_capture_vol(codec, nid, label, type_idx,
3539 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003540 if (err < 0)
3541 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003542 if (!err) {
3543 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003544 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003545 if (err < 0)
3546 return err;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003547 if (!err) {
3548 nid = get_connected_node(codec,
3549 spec->dmux_nids[0], index);
3550 if (nid)
3551 err = create_elem_capture_vol(codec,
3552 nid, label,
3553 type_idx, HDA_INPUT);
3554 if (err < 0)
3555 return err;
3556 }
Takashi Iwai96f845d2009-08-29 00:49:36 +02003557 }
Matt Porter8b657272006-10-26 17:12:59 +02003558 }
3559
3560 return 0;
3561}
3562
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003563static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003564 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003565{
3566 unsigned int cfg;
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003567 unsigned int type;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003568
3569 if (!nid)
3570 return 0;
3571 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003572 type = get_defcfg_device(cfg);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003573 switch (snd_hda_get_input_pin_attr(cfg)) {
3574 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003575 if (*fixed)
3576 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003577 if (type != AC_JACK_MIC_IN)
3578 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003579 *fixed = nid;
3580 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003581 case INPUT_PIN_ATTR_UNUSED:
3582 break;
3583 case INPUT_PIN_ATTR_DOCK:
3584 if (*dock)
3585 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003586 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
3587 return 1; /* invalid type */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003588 *dock = nid;
3589 break;
3590 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003591 if (*ext)
3592 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003593 if (type != AC_JACK_MIC_IN)
3594 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003595 *ext = nid;
3596 break;
3597 }
3598 return 0;
3599}
3600
3601static int set_mic_route(struct hda_codec *codec,
3602 struct sigmatel_mic_route *mic,
3603 hda_nid_t pin)
3604{
3605 struct sigmatel_spec *spec = codec->spec;
3606 struct auto_pin_cfg *cfg = &spec->autocfg;
3607 int i;
3608
3609 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003610 if (pin == 0)
3611 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003612 for (i = 0; i < cfg->num_inputs; i++) {
3613 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003614 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003615 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003616 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003617 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003618 i = get_connection_index(codec, spec->mux_nids[0], pin);
3619 if (i < 0)
3620 return -1;
3621 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003622 mic->dmux_idx = -1;
3623 if (spec->dmux_nids)
3624 mic->dmux_idx = get_connection_index(codec,
3625 spec->dmux_nids[0],
3626 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003627 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003628 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003629 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3630 if (i < 0)
3631 return -1;
3632 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003633 mic->mux_idx = -1;
3634 if (spec->mux_nids)
3635 mic->mux_idx = get_connection_index(codec,
3636 spec->mux_nids[0],
3637 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003638 }
3639 return 0;
3640}
3641
3642/* return non-zero if the device is for automatic mic switch */
3643static int stac_check_auto_mic(struct hda_codec *codec)
3644{
3645 struct sigmatel_spec *spec = codec->spec;
3646 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02003647 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003648 int i;
3649
Charles Chin99077902010-09-17 10:22:32 +02003650 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003651 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02003652 if (check_mic_pin(codec, cfg->inputs[i].pin,
3653 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003654 return 0;
3655 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02003656 if (check_mic_pin(codec, spec->dmic_nids[i],
3657 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003658 return 0;
Takashi Iwai80c67852011-01-13 08:08:08 +01003659 if (!fixed || (!ext && !dock))
Charles Chin99077902010-09-17 10:22:32 +02003660 return 0; /* no input to switch */
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003661 if (!is_jack_detectable(codec, ext))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003662 return 0; /* no unsol support */
3663 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02003664 set_mic_route(codec, &spec->int_mic, fixed) ||
3665 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003666 return 0; /* something is wrong */
3667 return 1;
3668}
3669
Mattc7d4b2f2005-06-27 14:59:41 +02003670/* create playback/capture controls for input pins */
3671static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3672{
3673 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003674 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003675 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003676 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02003677
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003678 for (i = 0; i < cfg->num_inputs; i++) {
3679 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003680 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02003681
Takashi Iwai314634b2006-09-21 11:56:18 +02003682 index = -1;
3683 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003684 index = get_connection_index(codec, spec->mux_nids[j],
3685 nid);
3686 if (index >= 0)
3687 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003688 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003689 if (index < 0)
3690 continue;
3691
Takashi Iwai10a20af2010-09-09 16:28:02 +02003692 label = hda_get_autocfg_input_label(codec, cfg, i);
3693 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003694
Takashi Iwai667067d2009-08-13 18:14:42 +02003695 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003696 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003697 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003698 if (err < 0)
3699 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003700 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003701 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003702
Steve Longerbeam7b043892007-05-03 20:50:03 +02003703 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003704 /*
3705 * Set the current input for the muxes.
3706 * The STAC9221 has two input muxes with identical source
3707 * NID lists. Hopefully this won't get confused.
3708 */
3709 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003710 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3711 AC_VERB_SET_CONNECT_SEL,
3712 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003713 }
3714 }
3715
Mattc7d4b2f2005-06-27 14:59:41 +02003716 return 0;
3717}
3718
Mattc7d4b2f2005-06-27 14:59:41 +02003719static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3720{
3721 struct sigmatel_spec *spec = codec->spec;
3722 int i;
3723
3724 for (i = 0; i < spec->autocfg.line_outs; i++) {
3725 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3726 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3727 }
3728}
3729
3730static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3731{
3732 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003733 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003734
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003735 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3736 hda_nid_t pin;
3737 pin = spec->autocfg.hp_pins[i];
3738 if (pin) /* connect to front */
3739 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3740 }
3741 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3742 hda_nid_t pin;
3743 pin = spec->autocfg.speaker_pins[i];
3744 if (pin) /* connect to front */
3745 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3746 }
Mattc7d4b2f2005-06-27 14:59:41 +02003747}
3748
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003749static int is_dual_headphones(struct hda_codec *codec)
3750{
3751 struct sigmatel_spec *spec = codec->spec;
3752 int i, valid_hps;
3753
3754 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3755 spec->autocfg.hp_outs <= 1)
3756 return 0;
3757 valid_hps = 0;
3758 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3759 hda_nid_t nid = spec->autocfg.hp_pins[i];
3760 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3761 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3762 continue;
3763 valid_hps++;
3764 }
3765 return (valid_hps > 1);
3766}
3767
3768
Charles Chin9009b0e2011-11-03 10:27:27 +01003769static int stac92xx_parse_auto_config(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003770{
3771 struct sigmatel_spec *spec = codec->spec;
Charles Chin9009b0e2011-11-03 10:27:27 +01003772 hda_nid_t dig_out = 0, dig_in = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003773 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003774 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003775
Matt Porter8b657272006-10-26 17:12:59 +02003776 if ((err = snd_hda_parse_pin_def_config(codec,
3777 &spec->autocfg,
3778 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003779 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003780 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003781 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003782
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003783 /* If we have no real line-out pin and multiple hp-outs, HPs should
3784 * be set up as multi-channel outputs.
3785 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003786 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003787 /* Copy hp_outs to line_outs, backup line_outs in
3788 * speaker_outs so that the following routines can handle
3789 * HP pins as primary outputs.
3790 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003791 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003792 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3793 sizeof(spec->autocfg.line_out_pins));
3794 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3795 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3796 sizeof(spec->autocfg.hp_pins));
3797 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003798 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3799 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003800 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003801 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003802 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003803 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3804 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003805 u32 caps = query_amp_caps(codec,
3806 spec->autocfg.mono_out_pin, dir);
3807 hda_nid_t conn_list[1];
3808
3809 /* get the mixer node and then the mono mux if it exists */
3810 if (snd_hda_get_connections(codec,
3811 spec->autocfg.mono_out_pin, conn_list, 1) &&
3812 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003813 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003814
3815 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003816 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003817 /* LR swap check, some stac925x have a mux that
3818 * changes the DACs output path instead of the
3819 * mono-mux path.
3820 */
3821 if (wid_type == AC_WID_AUD_SEL &&
3822 !(wcaps & AC_WCAP_LR_SWAP))
3823 spec->mono_nid = conn_list[0];
3824 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003825 if (dir) {
3826 hda_nid_t nid = spec->autocfg.mono_out_pin;
3827
3828 /* most mono outs have a least a mute/unmute switch */
3829 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3830 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3831 "Mono Playback Switch",
3832 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003833 if (err < 0)
3834 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003835 /* check for volume support for the amp */
3836 if ((caps & AC_AMPCAP_NUM_STEPS)
3837 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3838 err = stac92xx_add_control(spec,
3839 STAC_CTL_WIDGET_VOL,
3840 "Mono Playback Volume",
3841 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3842 if (err < 0)
3843 return err;
3844 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003845 }
3846
3847 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3848 AC_PINCTL_OUT_EN);
3849 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003850
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003851 if (!spec->multiout.num_dacs) {
3852 err = stac92xx_auto_fill_dac_nids(codec);
3853 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003854 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003855 err = stac92xx_auto_create_multi_out_ctls(codec,
3856 &spec->autocfg);
3857 if (err < 0)
3858 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003859 }
Mattc7d4b2f2005-06-27 14:59:41 +02003860
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003861 /* setup analog beep controls */
3862 if (spec->anabeep_nid > 0) {
3863 err = stac92xx_auto_create_beep_ctls(codec,
3864 spec->anabeep_nid);
3865 if (err < 0)
3866 return err;
3867 }
3868
3869 /* setup digital beep controls and input device */
3870#ifdef CONFIG_SND_HDA_INPUT_BEEP
3871 if (spec->digbeep_nid > 0) {
3872 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003873 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003874
3875 err = stac92xx_auto_create_beep_ctls(codec, nid);
3876 if (err < 0)
3877 return err;
3878 err = snd_hda_attach_beep_device(codec, nid);
3879 if (err < 0)
3880 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003881 if (codec->beep) {
3882 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01003883 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003884 /* if no beep switch is available, make its own one */
3885 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3886 if (!(caps & AC_AMPCAP_MUTE)) {
3887 err = stac92xx_beep_switch_ctl(codec);
3888 if (err < 0)
3889 return err;
3890 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003891 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003892 }
3893#endif
3894
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003895 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003896 if (err < 0)
3897 return err;
3898
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003899 /* All output parsing done, now restore the swapped hp pins */
3900 if (hp_swap) {
3901 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3902 sizeof(spec->autocfg.hp_pins));
3903 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3904 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3905 spec->autocfg.line_outs = 0;
3906 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003907
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003908 if (stac_check_auto_mic(codec)) {
3909 spec->auto_mic = 1;
3910 /* only one capture for auto-mic */
3911 spec->num_adcs = 1;
3912 spec->num_caps = 1;
3913 spec->num_muxes = 1;
3914 }
3915
Takashi Iwai6479c632009-07-28 18:20:25 +02003916 for (i = 0; i < spec->num_caps; i++) {
3917 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3918 spec->capsws[i], i);
3919 if (err < 0)
3920 return err;
3921 }
3922
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003923 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003924 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003925 return err;
3926
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003927 if (spec->mono_nid > 0) {
3928 err = stac92xx_auto_create_mono_output_ctls(codec);
3929 if (err < 0)
3930 return err;
3931 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003932 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003933 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3934 &spec->autocfg)) < 0)
3935 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003936 if (spec->num_muxes > 0) {
3937 err = stac92xx_auto_create_mux_input_ctls(codec);
3938 if (err < 0)
3939 return err;
3940 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003941 if (spec->num_smuxes > 0) {
3942 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3943 if (err < 0)
3944 return err;
3945 }
Matt Porter8b657272006-10-26 17:12:59 +02003946
Takashi Iwaie3c75962009-01-23 11:57:22 +01003947 err = stac92xx_add_input_source(spec);
3948 if (err < 0)
3949 return err;
3950
Mattc7d4b2f2005-06-27 14:59:41 +02003951 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003952 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003953 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003954
Charles Chin9009b0e2011-11-03 10:27:27 +01003955 /* find digital out and in converters */
3956 for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
3957 unsigned int wid_caps = get_wcaps(codec, i);
3958 if (wid_caps & AC_WCAP_DIGITAL) {
3959 switch (get_wcaps_type(wid_caps)) {
3960 case AC_WID_AUD_OUT:
3961 if (!dig_out)
3962 dig_out = i;
3963 break;
3964 case AC_WID_AUD_IN:
3965 if (!dig_in)
3966 dig_in = i;
3967 break;
3968 }
3969 }
3970 }
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003971 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003972 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003973 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003974 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003975
Takashi Iwai603c4012008-07-30 15:01:44 +02003976 if (spec->kctls.list)
3977 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003978
3979 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003980 if (!spec->dinput_mux)
3981 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003982 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003983 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003984 return 1;
3985}
3986
Takashi Iwai82bc9552006-03-21 11:24:42 +01003987/* add playback controls for HP output */
3988static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3989 struct auto_pin_cfg *cfg)
3990{
3991 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003992 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003993
3994 if (! pin)
3995 return 0;
3996
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003997 if (is_jack_detectable(codec, pin))
Takashi Iwai82bc9552006-03-21 11:24:42 +01003998 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003999
4000 return 0;
4001}
4002
Richard Fish160ea0d2006-09-06 13:58:25 +02004003/* add playback controls for LFE output */
4004static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4005 struct auto_pin_cfg *cfg)
4006{
4007 struct sigmatel_spec *spec = codec->spec;
4008 int err;
4009 hda_nid_t lfe_pin = 0x0;
4010 int i;
4011
4012 /*
4013 * search speaker outs and line outs for a mono speaker pin
4014 * with an amp. If one is found, add LFE controls
4015 * for it.
4016 */
4017 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4018 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004019 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004020 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4021 if (wcaps == AC_WCAP_OUT_AMP)
4022 /* found a mono speaker with an amp, must be lfe */
4023 lfe_pin = pin;
4024 }
4025
4026 /* if speaker_outs is 0, then speakers may be in line_outs */
4027 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4028 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4029 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004030 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004031 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004032 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004033 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004034 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4035 if (wcaps == AC_WCAP_OUT_AMP)
4036 /* found a mono speaker with an amp,
4037 must be lfe */
4038 lfe_pin = pin;
4039 }
4040 }
4041 }
4042
4043 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004044 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004045 if (err < 0)
4046 return err;
4047 }
4048
4049 return 0;
4050}
4051
Mattc7d4b2f2005-06-27 14:59:41 +02004052static int stac9200_parse_auto_config(struct hda_codec *codec)
4053{
4054 struct sigmatel_spec *spec = codec->spec;
4055 int err;
4056
Kailang Yangdf694da2005-12-05 19:42:22 +01004057 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004058 return err;
4059
4060 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4061 return err;
4062
Takashi Iwai82bc9552006-03-21 11:24:42 +01004063 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4064 return err;
4065
Richard Fish160ea0d2006-09-06 13:58:25 +02004066 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4067 return err;
4068
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004069 if (spec->num_muxes > 0) {
4070 err = stac92xx_auto_create_mux_input_ctls(codec);
4071 if (err < 0)
4072 return err;
4073 }
4074
Takashi Iwaie3c75962009-01-23 11:57:22 +01004075 err = stac92xx_add_input_source(spec);
4076 if (err < 0)
4077 return err;
4078
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004079 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004080 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004081 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004082 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004083
Takashi Iwai603c4012008-07-30 15:01:44 +02004084 if (spec->kctls.list)
4085 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004086
4087 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004088 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004089
4090 return 1;
4091}
4092
Sam Revitch62fe78e2006-05-10 15:09:17 +02004093/*
4094 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4095 * funky external mute control using GPIO pins.
4096 */
4097
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004098static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004099 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004100{
4101 unsigned int gpiostate, gpiomask, gpiodir;
4102
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004103 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4104
Sam Revitch62fe78e2006-05-10 15:09:17 +02004105 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4106 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004107 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004108
4109 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4110 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004111 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004112
4113 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4114 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004115 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004116
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004117 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004118 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4119
4120 snd_hda_codec_write(codec, codec->afg, 0,
4121 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004122 snd_hda_codec_read(codec, codec->afg, 0,
4123 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004124
4125 msleep(1);
4126
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004127 snd_hda_codec_read(codec, codec->afg, 0,
4128 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004129}
4130
Takashi Iwai3a938972011-10-28 01:16:55 +02004131static int stac_add_event(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004132 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004133{
Takashi Iwai3a938972011-10-28 01:16:55 +02004134 struct hda_jack_tbl *event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004135
Takashi Iwai3a938972011-10-28 01:16:55 +02004136 event = snd_hda_jack_tbl_new(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004137 if (!event)
4138 return -ENOMEM;
Takashi Iwai3a938972011-10-28 01:16:55 +02004139 event->action = type;
4140 event->private_data = data;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004141
Takashi Iwai3a938972011-10-28 01:16:55 +02004142 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004143}
4144
Takashi Iwai62558ce2009-07-29 14:23:09 +02004145/* check if given nid is a valid pin and no other events are assigned
4146 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4147 * Otherwise, returns zero.
4148 */
4149static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4150 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004151{
Takashi Iwai3a938972011-10-28 01:16:55 +02004152 struct hda_jack_tbl *event;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004153
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004154 if (!is_jack_detectable(codec, nid))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004155 return 0;
Takashi Iwai3a938972011-10-28 01:16:55 +02004156 event = snd_hda_jack_tbl_new(codec, nid);
4157 if (!event)
4158 return -ENOMEM;
4159 if (event->action && event->action != type)
4160 return 0;
4161 event->action = type;
4162 snd_hda_jack_detect_enable(codec, nid, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004163 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004164}
4165
Takashi Iwaib4ead012012-01-23 18:23:36 +01004166static int is_nid_out_jack_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004167{
4168 int i;
4169 for (i = 0; i < cfg->hp_outs; i++)
4170 if (cfg->hp_pins[i] == nid)
4171 return 1; /* nid is a HP-Out */
Takashi Iwaib4ead012012-01-23 18:23:36 +01004172 for (i = 0; i < cfg->line_outs; i++)
4173 if (cfg->line_out_pins[i] == nid)
4174 return 1; /* nid is a line-Out */
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004175 return 0; /* nid is not a HP-Out */
4176};
4177
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004178static void stac92xx_power_down(struct hda_codec *codec)
4179{
4180 struct sigmatel_spec *spec = codec->spec;
4181
4182 /* power down inactive DACs */
Takashi Iwai2b635362011-05-02 12:33:43 +02004183 const hda_nid_t *dac;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004184 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004185 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004186 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004187 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4188}
4189
Takashi Iwaif73d3582008-11-25 08:21:51 +01004190static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4191 int enable);
4192
Takashi Iwai014c41f2009-12-27 13:53:24 +01004193static inline int get_int_hint(struct hda_codec *codec, const char *key,
4194 int *valp)
4195{
4196 const char *p;
4197 p = snd_hda_get_hint(codec, key);
4198 if (p) {
4199 unsigned long val;
4200 if (!strict_strtoul(p, 0, &val)) {
4201 *valp = val;
4202 return 1;
4203 }
4204 }
4205 return 0;
4206}
4207
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004208/* override some hints from the hwdep entry */
4209static void stac_store_hints(struct hda_codec *codec)
4210{
4211 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004212 int val;
4213
4214 val = snd_hda_get_bool_hint(codec, "hp_detect");
4215 if (val >= 0)
4216 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004217 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004218 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4219 spec->gpio_mask;
4220 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004221 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4222 spec->gpio_mask &= spec->gpio_mask;
4223 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4224 spec->gpio_dir &= spec->gpio_mask;
4225 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4226 spec->eapd_mask &= spec->gpio_mask;
4227 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4228 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004229 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4230 if (val >= 0)
4231 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004232 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4233 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01004234 spec->gpio_mask |= spec->gpio_led;
4235 spec->gpio_dir |= spec->gpio_led;
4236 if (spec->gpio_led_polarity)
4237 spec->gpio_data |= spec->gpio_led;
Takashi Iwai043958e2009-12-26 10:36:12 +01004238 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004239}
4240
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004241static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins,
4242 const hda_nid_t *pins)
4243{
4244 while (num_pins--)
4245 stac_issue_unsol_event(codec, *pins++);
4246}
4247
4248/* fake event to set up pins */
4249static void stac_fake_hp_events(struct hda_codec *codec)
4250{
4251 struct sigmatel_spec *spec = codec->spec;
4252
4253 if (spec->autocfg.hp_outs)
4254 stac_issue_unsol_events(codec, spec->autocfg.hp_outs,
4255 spec->autocfg.hp_pins);
4256 if (spec->autocfg.line_outs &&
4257 spec->autocfg.line_out_pins[0] != spec->autocfg.hp_pins[0])
4258 stac_issue_unsol_events(codec, spec->autocfg.line_outs,
4259 spec->autocfg.line_out_pins);
4260}
4261
Mattc7d4b2f2005-06-27 14:59:41 +02004262static int stac92xx_init(struct hda_codec *codec)
4263{
4264 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004265 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004266 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004267 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004268
Mattc7d4b2f2005-06-27 14:59:41 +02004269 snd_hda_sequence_write(codec, spec->init);
4270
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004271 /* power down adcs initially */
4272 if (spec->powerdown_adcs)
4273 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004274 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004275 spec->adc_nids[i], 0,
4276 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004277
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004278 /* override some hints */
4279 stac_store_hints(codec);
4280
Takashi Iwaif73d3582008-11-25 08:21:51 +01004281 /* set up GPIO */
4282 gpio = spec->gpio_data;
4283 /* turn on EAPD statically when spec->eapd_switch isn't set.
4284 * otherwise, unsol event will turn it on/off dynamically
4285 */
4286 if (!spec->eapd_switch)
4287 gpio |= spec->eapd_mask;
4288 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4289
Takashi Iwai82bc9552006-03-21 11:24:42 +01004290 /* set up pins */
4291 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004292 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004293 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004294 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004295 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004296 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004297 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4298 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004299 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004300 for (i = 0; i < cfg->line_outs; i++) {
4301 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004302 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4303 }
4304 }
4305
Takashi Iwai0a07aca2007-03-13 10:40:23 +01004306 /* force to enable the first line-out; the others are set up
4307 * in unsol_event
4308 */
4309 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004310 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004311 /* fake event to set up pins */
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004312 stac_fake_hp_events(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004313 } else {
4314 stac92xx_auto_init_multi_out(codec);
4315 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004316 for (i = 0; i < cfg->hp_outs; i++)
4317 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004318 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004319 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004320 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004321 if (spec->dmux_nids)
4322 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004323 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004324 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4325 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004326 if (enable_pin_detect(codec, spec->dock_mic.pin,
4327 STAC_MIC_EVENT))
4328 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004329 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004330 for (i = 0; i < cfg->num_inputs; i++) {
4331 hda_nid_t nid = cfg->inputs[i].pin;
4332 int type = cfg->inputs[i].type;
4333 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004334 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004335 /* for mic pins, force to initialize */
4336 pinctl = stac92xx_get_default_vref(codec, nid);
4337 pinctl |= AC_PINCTL_IN_EN;
4338 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4339 } else {
4340 pinctl = snd_hda_codec_read(codec, nid, 0,
4341 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4342 /* if PINCTL already set then skip */
4343 /* Also, if both INPUT and OUTPUT are set,
4344 * it must be a BIOS bug; need to override, too
4345 */
4346 if (!(pinctl & AC_PINCTL_IN_EN) ||
4347 (pinctl & AC_PINCTL_OUT_EN)) {
4348 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004349 pinctl |= AC_PINCTL_IN_EN;
4350 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004351 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004352 }
4353 conf = snd_hda_codec_get_pincfg(codec, nid);
4354 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4355 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4356 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004357 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004358 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004359 for (i = 0; i < spec->num_dmics; i++)
4360 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4361 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004362 if (cfg->dig_out_pins[0])
4363 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004364 AC_PINCTL_OUT_EN);
4365 if (cfg->dig_in_pin)
4366 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4367 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004368 for (i = 0; i < spec->num_pwrs; i++) {
4369 hda_nid_t nid = spec->pwr_nids[i];
4370 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004371
Takashi Iwaieb632122008-12-19 16:39:48 +01004372 /* power on when no jack detection is available */
Takashi Iwai542c9a02011-11-29 13:01:30 +01004373 /* or when the VREF is used for controlling LED */
4374 if (!spec->hp_detect ||
Takashi Iwaia0204282011-12-06 13:17:23 +01004375 spec->vref_mute_led_nid == nid) {
Takashi Iwaieb632122008-12-19 16:39:48 +01004376 stac_toggle_power_map(codec, nid, 1);
4377 continue;
4378 }
4379
Takashi Iwaib4ead012012-01-23 18:23:36 +01004380 if (is_nid_out_jack_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004381 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004382
Takashi Iwaif73d3582008-11-25 08:21:51 +01004383 pinctl = snd_hda_codec_read(codec, nid, 0,
4384 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4385 /* outputs are only ports capable of power management
4386 * any attempts on powering down a input port cause the
4387 * referenced VREF to act quirky.
4388 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004389 if (pinctl & AC_PINCTL_IN_EN) {
4390 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004391 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004392 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004393 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004394 def_conf = get_defcfg_connect(def_conf);
4395 /* skip any ports that don't have jacks since presence
4396 * detection is useless */
4397 if (def_conf != AC_JACK_PORT_COMPLEX) {
4398 if (def_conf != AC_JACK_PORT_NONE)
4399 stac_toggle_power_map(codec, nid, 1);
4400 continue;
4401 }
Charles Chinafef2cf2011-11-11 08:05:28 +01004402 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004403 stac_issue_unsol_event(codec, nid);
Charles Chinafef2cf2011-11-11 08:05:28 +01004404 continue;
4405 }
4406 /* none of the above, turn the port OFF */
4407 stac_toggle_power_map(codec, nid, 0);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004408 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004409
Takashi Iwai01a61e12011-10-28 00:03:22 +02004410 snd_hda_jack_report_sync(codec);
4411
Takashi Iwaic21bd022010-02-08 15:16:08 +01004412 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004413 if (spec->gpio_led)
4414 hda_call_check_power_status(codec, 0x01);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004415 if (spec->dac_list)
4416 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004417 return 0;
4418}
4419
Takashi Iwai603c4012008-07-30 15:01:44 +02004420static void stac92xx_free_kctls(struct hda_codec *codec)
4421{
4422 struct sigmatel_spec *spec = codec->spec;
4423
4424 if (spec->kctls.list) {
4425 struct snd_kcontrol_new *kctl = spec->kctls.list;
4426 int i;
4427 for (i = 0; i < spec->kctls.used; i++)
4428 kfree(kctl[i].name);
4429 }
4430 snd_array_free(&spec->kctls);
4431}
4432
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004433static void stac92xx_shutup_pins(struct hda_codec *codec)
4434{
4435 unsigned int i, def_conf;
4436
4437 if (codec->bus->shutdown)
4438 return;
4439 for (i = 0; i < codec->init_pins.used; i++) {
4440 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4441 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4442 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
4443 snd_hda_codec_write(codec, pin->nid, 0,
4444 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4445 }
4446}
4447
Takashi Iwai167eae52009-11-06 15:47:50 +01004448static void stac92xx_shutup(struct hda_codec *codec)
4449{
4450 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004451
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004452 stac92xx_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004453
4454 if (spec->eapd_mask)
4455 stac_gpio_set(codec, spec->gpio_mask,
4456 spec->gpio_dir, spec->gpio_data &
4457 ~spec->eapd_mask);
4458}
4459
Matt2f2f4252005-04-13 14:45:30 +02004460static void stac92xx_free(struct hda_codec *codec)
4461{
Mattc7d4b2f2005-06-27 14:59:41 +02004462 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004463
4464 if (! spec)
4465 return;
4466
Takashi Iwai167eae52009-11-06 15:47:50 +01004467 stac92xx_shutup(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02004468
Mattc7d4b2f2005-06-27 14:59:41 +02004469 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004470 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004471}
4472
Matt4e550962005-07-04 17:51:39 +02004473static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4474 unsigned int flag)
4475{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004476 unsigned int old_ctl, pin_ctl;
4477
4478 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004479 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004480
Takashi Iwaif9acba42007-05-29 18:01:06 +02004481 if (pin_ctl & AC_PINCTL_IN_EN) {
4482 /*
4483 * we need to check the current set-up direction of
4484 * shared input pins since they can be switched via
4485 * "xxx as Output" mixer switch
4486 */
4487 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004488 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004489 return;
4490 }
4491
Takashi Iwai8ce84192009-01-22 16:59:20 +01004492 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004493 /* if setting pin direction bits, clear the current
4494 direction bits first */
4495 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4496 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4497
Takashi Iwai8ce84192009-01-22 16:59:20 +01004498 pin_ctl |= flag;
4499 if (old_ctl != pin_ctl)
4500 snd_hda_codec_write_cache(codec, nid, 0,
4501 AC_VERB_SET_PIN_WIDGET_CONTROL,
4502 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004503}
4504
4505static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4506 unsigned int flag)
4507{
4508 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4509 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004510 if (pin_ctl & flag)
4511 snd_hda_codec_write_cache(codec, nid, 0,
4512 AC_VERB_SET_PIN_WIDGET_CONTROL,
4513 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004514}
4515
Takashi Iwaid56757a2009-11-18 08:00:14 +01004516static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004517{
4518 if (!nid)
4519 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004520 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004521}
4522
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004523static void stac92xx_line_out_detect(struct hda_codec *codec,
4524 int presence)
4525{
4526 struct sigmatel_spec *spec = codec->spec;
4527 struct auto_pin_cfg *cfg = &spec->autocfg;
4528 int i;
4529
4530 for (i = 0; i < cfg->line_outs; i++) {
4531 if (presence)
4532 break;
4533 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4534 if (presence) {
4535 unsigned int pinctl;
4536 pinctl = snd_hda_codec_read(codec,
4537 cfg->line_out_pins[i], 0,
4538 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4539 if (pinctl & AC_PINCTL_IN_EN)
4540 presence = 0; /* mic- or line-input */
4541 }
4542 }
4543
4544 if (presence) {
4545 /* disable speakers */
4546 for (i = 0; i < cfg->speaker_outs; i++)
4547 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4548 AC_PINCTL_OUT_EN);
4549 if (spec->eapd_mask && spec->eapd_switch)
4550 stac_gpio_set(codec, spec->gpio_mask,
4551 spec->gpio_dir, spec->gpio_data &
4552 ~spec->eapd_mask);
4553 } else {
4554 /* enable speakers */
4555 for (i = 0; i < cfg->speaker_outs; i++)
4556 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4557 AC_PINCTL_OUT_EN);
4558 if (spec->eapd_mask && spec->eapd_switch)
4559 stac_gpio_set(codec, spec->gpio_mask,
4560 spec->gpio_dir, spec->gpio_data |
4561 spec->eapd_mask);
4562 }
4563}
4564
Takashi Iwaid7a89432008-11-12 09:48:04 +01004565/* return non-zero if the hp-pin of the given array index isn't
4566 * a jack-detection target
4567 */
4568static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4569{
4570 struct auto_pin_cfg *cfg = &spec->autocfg;
4571
4572 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004573 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004574 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004575 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004576 return 1;
4577 /* ignore if the pin is set as line-out */
4578 if (cfg->hp_pins[i] == spec->hp_switch)
4579 return 1;
4580 return 0;
4581}
4582
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004583static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004584{
4585 struct sigmatel_spec *spec = codec->spec;
4586 struct auto_pin_cfg *cfg = &spec->autocfg;
4587 int i, presence;
4588
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004589 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004590 if (spec->gpio_mute)
4591 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4592 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4593
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004594 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004595 if (presence)
4596 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004597 if (no_hp_sensing(spec, i))
4598 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004599 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4600 if (presence) {
4601 unsigned int pinctl;
4602 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4603 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4604 if (pinctl & AC_PINCTL_IN_EN)
4605 presence = 0; /* mic- or line-input */
4606 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004607 }
Matt4e550962005-07-04 17:51:39 +02004608
4609 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004610 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004611 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004612 stac92xx_reset_pinctl(codec, spec->hp_switch,
4613 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004614 for (i = 0; i < cfg->line_outs; i++)
4615 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4616 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004617 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004618 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004619 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004620 stac92xx_set_pinctl(codec, spec->hp_switch,
4621 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004622 for (i = 0; i < cfg->line_outs; i++)
4623 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4624 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004625 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004626 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004627 /* toggle hp outs */
4628 for (i = 0; i < cfg->hp_outs; i++) {
4629 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4630 if (no_hp_sensing(spec, i))
4631 continue;
4632 if (presence)
4633 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004634#if 0 /* FIXME */
4635/* Resetting the pinctl like below may lead to (a sort of) regressions
4636 * on some devices since they use the HP pin actually for line/speaker
4637 * outs although the default pin config shows a different pin (that is
4638 * wrong and useless).
4639 *
4640 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4641 * But, disabling the code below just works around it, and I'm too tired of
4642 * bug reports with such devices...
4643 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004644 else
4645 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004646#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004647 }
Matt4e550962005-07-04 17:51:39 +02004648}
4649
Takashi Iwaif73d3582008-11-25 08:21:51 +01004650static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4651 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004652{
4653 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004654 unsigned int idx, val;
4655
4656 for (idx = 0; idx < spec->num_pwrs; idx++) {
4657 if (spec->pwr_nids[idx] == nid)
4658 break;
4659 }
4660 if (idx >= spec->num_pwrs)
4661 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004662
Charles Chinafef2cf2011-11-11 08:05:28 +01004663 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004664
Takashi Iwaif73d3582008-11-25 08:21:51 +01004665 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4666 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004667 val &= ~idx;
4668 else
4669 val |= idx;
4670
4671 /* power down unused output ports */
4672 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004673}
4674
Takashi Iwaif73d3582008-11-25 08:21:51 +01004675static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4676{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004677 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004678}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004679
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004680/* get the pin connection (fixed, none, etc) */
4681static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4682{
4683 struct sigmatel_spec *spec = codec->spec;
4684 unsigned int cfg;
4685
4686 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4687 return get_defcfg_connect(cfg);
4688}
4689
4690static int stac92xx_connected_ports(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02004691 const hda_nid_t *nids, int num_nids)
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004692{
4693 struct sigmatel_spec *spec = codec->spec;
4694 int idx, num;
4695 unsigned int def_conf;
4696
4697 for (num = 0; num < num_nids; num++) {
4698 for (idx = 0; idx < spec->num_pins; idx++)
4699 if (spec->pin_nids[idx] == nids[num])
4700 break;
4701 if (idx >= spec->num_pins)
4702 break;
4703 def_conf = stac_get_defcfg_connect(codec, idx);
4704 if (def_conf == AC_JACK_PORT_NONE)
4705 break;
4706 }
4707 return num;
4708}
4709
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004710static void stac92xx_mic_detect(struct hda_codec *codec)
4711{
4712 struct sigmatel_spec *spec = codec->spec;
4713 struct sigmatel_mic_route *mic;
4714
4715 if (get_pin_presence(codec, spec->ext_mic.pin))
4716 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02004717 else if (get_pin_presence(codec, spec->dock_mic.pin))
4718 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004719 else
4720 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004721 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004722 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4723 AC_VERB_SET_CONNECT_SEL,
4724 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004725 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004726 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4727 AC_VERB_SET_CONNECT_SEL,
4728 mic->mux_idx);
4729}
4730
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004731static void handle_unsol_event(struct hda_codec *codec,
Takashi Iwai3a938972011-10-28 01:16:55 +02004732 struct hda_jack_tbl *event)
Takashi Iwai314634b2006-09-21 11:56:18 +02004733{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004734 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004735 int data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004736
Takashi Iwai3a938972011-10-28 01:16:55 +02004737 switch (event->action) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004738 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004739 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004740 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004741 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004742 case STAC_MIC_EVENT:
4743 stac92xx_mic_detect(codec);
4744 break;
4745 }
4746
Takashi Iwai3a938972011-10-28 01:16:55 +02004747 switch (event->action) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004748 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004749 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004750 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004751 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004752 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004753 if (spec->num_pwrs > 0)
4754 stac92xx_pin_sense(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004755
4756 switch (codec->subsystem_id) {
4757 case 0x103c308f:
4758 if (event->nid == 0xb) {
4759 int pin = AC_PINCTL_IN_EN;
4760
4761 if (get_pin_presence(codec, 0xa)
4762 && get_pin_presence(codec, 0xb))
4763 pin |= AC_PINCTL_VREF_80;
4764 if (!get_pin_presence(codec, 0xb))
4765 pin |= AC_PINCTL_VREF_80;
4766
4767 /* toggle VREF state based on mic + hp pin
4768 * status
4769 */
4770 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4771 }
4772 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004773 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004774 case STAC_VREF_EVENT:
4775 data = snd_hda_codec_read(codec, codec->afg, 0,
4776 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004777 /* toggle VREF state based on GPIOx status */
4778 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwai3a938972011-10-28 01:16:55 +02004779 !!(data & (1 << event->private_data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004780 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004781 }
4782}
4783
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004784static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4785{
Takashi Iwai3a938972011-10-28 01:16:55 +02004786 struct hda_jack_tbl *event = snd_hda_jack_tbl_get(codec, nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004787 if (!event)
4788 return;
4789 handle_unsol_event(codec, event);
4790}
4791
4792static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4793{
Takashi Iwai3a938972011-10-28 01:16:55 +02004794 struct hda_jack_tbl *event;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004795 int tag;
4796
4797 tag = (res >> 26) & 0x7f;
Takashi Iwai3a938972011-10-28 01:16:55 +02004798 event = snd_hda_jack_tbl_get_from_tag(codec, tag);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004799 if (!event)
4800 return;
Takashi Iwai3a938972011-10-28 01:16:55 +02004801 event->jack_dirty = 1;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004802 handle_unsol_event(codec, event);
Takashi Iwai01a61e12011-10-28 00:03:22 +02004803 snd_hda_jack_report_sync(codec);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004804}
4805
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304806static int hp_blike_system(u32 subsystem_id);
4807
4808static void set_hp_led_gpio(struct hda_codec *codec)
4809{
4810 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004811 unsigned int gpio;
4812
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004813 if (spec->gpio_led)
4814 return;
4815
Takashi Iwai07f80442010-02-08 15:06:13 +01004816 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4817 gpio &= AC_GPIO_IO_COUNT;
4818 if (gpio > 3)
4819 spec->gpio_led = 0x08; /* GPIO 3 */
4820 else
4821 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304822}
4823
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004824/*
4825 * This method searches for the mute LED GPIO configuration
4826 * provided as OEM string in SMBIOS. The format of that string
4827 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4828 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4829 * that corresponds to the NOT muted state of the master volume
4830 * and G is the index of the GPIO to use as the mute LED control (0..9)
4831 * If _G portion is missing it is assigned based on the codec ID
4832 *
4833 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4834 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304835 *
4836 *
4837 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4838 * SMBIOS - at least the ones I have seen do not have them - which include
4839 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4840 * HP Pavilion dv9500t CTO.
4841 * Need more information on whether it is true across the entire series.
4842 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004843 */
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06004844static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004845{
4846 struct sigmatel_spec *spec = codec->spec;
4847 const struct dmi_device *dev = NULL;
4848
4849 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4850 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4851 NULL, dev))) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004852 if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304853 &spec->gpio_led_polarity,
4854 &spec->gpio_led) == 2) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01004855 unsigned int max_gpio;
4856 max_gpio = snd_hda_param_read(codec, codec->afg,
4857 AC_PAR_GPIO_CAP);
4858 max_gpio &= AC_GPIO_IO_COUNT;
4859 if (spec->gpio_led < max_gpio)
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004860 spec->gpio_led = 1 << spec->gpio_led;
Takashi Iwaif1a73742011-12-04 13:44:06 +01004861 else
4862 spec->vref_mute_led_nid = spec->gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004863 return 1;
4864 }
4865 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304866 &spec->gpio_led_polarity) == 1) {
4867 set_hp_led_gpio(codec);
4868 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004869 }
Gustavo Maciel Dias Vieirae2ef36c2011-12-13 11:47:22 -02004870 /* BIOS bug: unfilled OEM string */
4871 if (strstr(dev->name, "HP_Mute_LED_P_G")) {
4872 set_hp_led_gpio(codec);
Gustavo Maciel Dias Vieiraa6a600d2012-01-24 13:27:56 -02004873 switch (codec->subsystem_id) {
4874 case 0x103c148a:
4875 spec->gpio_led_polarity = 0;
4876 break;
4877 default:
4878 spec->gpio_led_polarity = 1;
4879 break;
4880 }
Gustavo Maciel Dias Vieirae2ef36c2011-12-13 11:47:22 -02004881 return 1;
4882 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004883 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304884
4885 /*
4886 * Fallback case - if we don't find the DMI strings,
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06004887 * we statically set the GPIO - if not a B-series system
4888 * and default polarity is provided
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304889 */
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06004890 if (!hp_blike_system(codec->subsystem_id) &&
4891 (default_polarity == 0 || default_polarity == 1)) {
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304892 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004893 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304894 return 1;
4895 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004896 }
4897 return 0;
4898}
4899
4900static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004901{
4902 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004903 case 0x103c1520:
4904 case 0x103c1521:
4905 case 0x103c1523:
4906 case 0x103c1524:
4907 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004908 case 0x103c1722:
4909 case 0x103c1723:
4910 case 0x103c1724:
4911 case 0x103c1725:
4912 case 0x103c1726:
4913 case 0x103c1727:
4914 case 0x103c1728:
4915 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004916 case 0x103c172a:
4917 case 0x103c172b:
4918 case 0x103c307e:
4919 case 0x103c307f:
4920 case 0x103c3080:
4921 case 0x103c3081:
4922 case 0x103c7007:
4923 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004924 return 1;
4925 }
4926 return 0;
4927}
4928
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004929#ifdef CONFIG_PROC_FS
4930static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4931 struct hda_codec *codec, hda_nid_t nid)
4932{
4933 if (nid == codec->afg)
4934 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4935 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4936}
4937
4938static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4939 struct hda_codec *codec,
4940 unsigned int verb)
4941{
4942 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4943 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4944}
4945
4946/* stac92hd71bxx, stac92hd73xx */
4947static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4948 struct hda_codec *codec, hda_nid_t nid)
4949{
4950 stac92hd_proc_hook(buffer, codec, nid);
4951 if (nid == codec->afg)
4952 analog_loop_proc_hook(buffer, codec, 0xfa0);
4953}
4954
4955static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4956 struct hda_codec *codec, hda_nid_t nid)
4957{
4958 if (nid == codec->afg)
4959 analog_loop_proc_hook(buffer, codec, 0xfe0);
4960}
4961
4962static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4963 struct hda_codec *codec, hda_nid_t nid)
4964{
4965 if (nid == codec->afg)
4966 analog_loop_proc_hook(buffer, codec, 0xfeb);
4967}
4968#else
4969#define stac92hd_proc_hook NULL
4970#define stac92hd7x_proc_hook NULL
4971#define stac9205_proc_hook NULL
4972#define stac927x_proc_hook NULL
4973#endif
4974
Takashi Iwai2a439522011-07-26 09:52:50 +02004975#ifdef CONFIG_PM
Mattff6fdc32005-06-27 15:06:52 +02004976static int stac92xx_resume(struct hda_codec *codec)
4977{
Takashi Iwai2c885872008-11-18 09:36:55 +01004978 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004979 snd_hda_codec_resume_amp(codec);
4980 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004981 /* fake event to set up pins again to override cached values */
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004982 stac_fake_hp_events(codec);
Mattff6fdc32005-06-27 15:06:52 +02004983 return 0;
4984}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004985
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004986static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4987{
4988 stac92xx_shutup(codec);
4989 return 0;
4990}
4991
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004992#ifdef CONFIG_SND_HDA_POWER_SAVE
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004993static int stac92xx_pre_resume(struct hda_codec *codec)
4994{
4995 struct sigmatel_spec *spec = codec->spec;
4996
4997 /* sync mute LED */
Takashi Iwaif1a73742011-12-04 13:44:06 +01004998 if (spec->vref_mute_led_nid)
4999 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5000 spec->vref_led);
5001 else if (spec->gpio_led)
5002 stac_gpio_set(codec, spec->gpio_mask,
5003 spec->gpio_dir, spec->gpio_data);
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005004 return 0;
5005}
5006
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005007static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5008 unsigned int power_state)
5009{
5010 unsigned int afg_power_state = power_state;
5011 struct sigmatel_spec *spec = codec->spec;
5012
5013 if (power_state == AC_PWRST_D3) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005014 if (spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005015 /* with vref-out pin used for mute led control
5016 * codec AFG is prevented from D3 state
5017 */
5018 afg_power_state = AC_PWRST_D1;
5019 }
5020 /* this delay seems necessary to avoid click noise at power-down */
5021 msleep(100);
5022 }
5023 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5024 afg_power_state);
5025 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
5026}
5027
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005028/*
5029 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed
5030 * as mute LED state is updated in check_power_status hook
5031 */
5032static int stac92xx_update_led_status(struct hda_codec *codec)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005033{
5034 struct sigmatel_spec *spec = codec->spec;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005035 int i, num_ext_dacs, muted = 1;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005036 unsigned int muted_lvl, notmtd_lvl;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005037 hda_nid_t nid;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005038
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005039 if (!spec->gpio_led)
5040 return 0;
5041
Takashi Iwaic21bd022010-02-08 15:16:08 +01005042 for (i = 0; i < spec->multiout.num_dacs; i++) {
5043 nid = spec->multiout.dac_nids[i];
5044 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5045 HDA_AMP_MUTE)) {
5046 muted = 0; /* something heard */
5047 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005048 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01005049 }
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005050 if (muted && spec->multiout.hp_nid)
5051 if (!(snd_hda_codec_amp_read(codec,
5052 spec->multiout.hp_nid, 0, HDA_OUTPUT, 0) &
5053 HDA_AMP_MUTE)) {
5054 muted = 0; /* HP is not muted */
5055 }
5056 num_ext_dacs = ARRAY_SIZE(spec->multiout.extra_out_nid);
5057 for (i = 0; muted && i < num_ext_dacs; i++) {
5058 nid = spec->multiout.extra_out_nid[i];
5059 if (nid == 0)
5060 break;
5061 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5062 HDA_AMP_MUTE)) {
5063 muted = 0; /* extra output is not muted */
5064 }
5065 }
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005066 /*polarity defines *not* muted state level*/
Takashi Iwaif1a73742011-12-04 13:44:06 +01005067 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005068 if (muted)
5069 spec->gpio_data &= ~spec->gpio_led; /* orange */
5070 else
5071 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005072
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005073 if (!spec->gpio_led_polarity) {
5074 /* LED state is inverted on these systems */
5075 spec->gpio_data ^= spec->gpio_led;
5076 }
5077 stac_gpio_set(codec, spec->gpio_mask,
5078 spec->gpio_dir, spec->gpio_data);
5079 } else {
5080 notmtd_lvl = spec->gpio_led_polarity ?
Takashi Iwaia1e0c3c2012-02-09 09:32:19 +01005081 AC_PINCTL_VREF_50 : AC_PINCTL_VREF_GRD;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005082 muted_lvl = spec->gpio_led_polarity ?
Takashi Iwaia1e0c3c2012-02-09 09:32:19 +01005083 AC_PINCTL_VREF_GRD : AC_PINCTL_VREF_50;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005084 spec->vref_led = muted ? muted_lvl : notmtd_lvl;
Takashi Iwaif1a73742011-12-04 13:44:06 +01005085 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5086 spec->vref_led);
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005087 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005088 return 0;
5089}
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005090
5091/*
5092 * use power check for controlling mute led of HP notebooks
5093 */
5094static int stac92xx_check_power_status(struct hda_codec *codec,
5095 hda_nid_t nid)
5096{
5097 stac92xx_update_led_status(codec);
5098
5099 return 0;
5100}
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005101#endif /* CONFIG_SND_HDA_POWER_SAVE */
Takashi Iwai2a439522011-07-26 09:52:50 +02005102#endif /* CONFIG_PM */
Mattff6fdc32005-06-27 15:06:52 +02005103
Takashi Iwai2b635362011-05-02 12:33:43 +02005104static const struct hda_codec_ops stac92xx_patch_ops = {
Matt2f2f4252005-04-13 14:45:30 +02005105 .build_controls = stac92xx_build_controls,
5106 .build_pcms = stac92xx_build_pcms,
5107 .init = stac92xx_init,
5108 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02005109 .unsol_event = stac92xx_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02005110#ifdef CONFIG_PM
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005111 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005112 .resume = stac92xx_resume,
5113#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005114 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005115};
5116
5117static int patch_stac9200(struct hda_codec *codec)
5118{
5119 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005120 int err;
Matt2f2f4252005-04-13 14:45:30 +02005121
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005122 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005123 if (spec == NULL)
5124 return -ENOMEM;
5125
Takashi Iwaia252c812009-12-25 22:56:20 +01005126 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005127 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005128 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005129 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005130 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005131 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5132 stac9200_models,
5133 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005134 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005135 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5136 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005137 else
5138 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005139 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005140
5141 spec->multiout.max_channels = 2;
5142 spec->multiout.num_dacs = 1;
5143 spec->multiout.dac_nids = stac9200_dac_nids;
5144 spec->adc_nids = stac9200_adc_nids;
5145 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005146 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005147 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005148 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005149 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005150
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005151 if (spec->board_config == STAC_9200_M4 ||
5152 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005153 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005154 spec->init = stac9200_eapd_init;
5155 else
5156 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005157 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005158
Takashi Iwai117f2572008-03-18 09:53:23 +01005159 if (spec->board_config == STAC_9200_PANASONIC) {
5160 spec->gpio_mask = spec->gpio_dir = 0x09;
5161 spec->gpio_data = 0x00;
5162 }
5163
Mattc7d4b2f2005-06-27 14:59:41 +02005164 err = stac9200_parse_auto_config(codec);
5165 if (err < 0) {
5166 stac92xx_free(codec);
5167 return err;
5168 }
Matt2f2f4252005-04-13 14:45:30 +02005169
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005170 /* CF-74 has no headphone detection, and the driver should *NOT*
5171 * do detection and HP/speaker toggle because the hardware does it.
5172 */
5173 if (spec->board_config == STAC_9200_PANASONIC)
5174 spec->hp_detect = 0;
5175
Matt2f2f4252005-04-13 14:45:30 +02005176 codec->patch_ops = stac92xx_patch_ops;
5177
5178 return 0;
5179}
5180
Tobin Davis8e21c342007-01-08 11:04:17 +01005181static int patch_stac925x(struct hda_codec *codec)
5182{
5183 struct sigmatel_spec *spec;
5184 int err;
5185
5186 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5187 if (spec == NULL)
5188 return -ENOMEM;
5189
Takashi Iwaia252c812009-12-25 22:56:20 +01005190 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005191 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(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005194 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005195
5196 /* Check first for codec ID */
5197 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5198 STAC_925x_MODELS,
5199 stac925x_models,
5200 stac925x_codec_id_cfg_tbl);
5201
5202 /* Now checks for PCI ID, if codec ID is not found */
5203 if (spec->board_config < 0)
5204 spec->board_config = snd_hda_check_board_config(codec,
5205 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005206 stac925x_models,
5207 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005208 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005209 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005210 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5211 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005212 else
5213 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005214 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005215
5216 spec->multiout.max_channels = 2;
5217 spec->multiout.num_dacs = 1;
5218 spec->multiout.dac_nids = stac925x_dac_nids;
5219 spec->adc_nids = stac925x_adc_nids;
5220 spec->mux_nids = stac925x_mux_nids;
5221 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005222 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005223 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005224 switch (codec->vendor_id) {
5225 case 0x83847632: /* STAC9202 */
5226 case 0x83847633: /* STAC9202D */
5227 case 0x83847636: /* STAC9251 */
5228 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005229 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005230 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai16970552007-12-18 18:05:52 +01005231 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5232 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005233 break;
5234 default:
5235 spec->num_dmics = 0;
5236 break;
5237 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005238
5239 spec->init = stac925x_core_init;
5240 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005241 spec->num_caps = 1;
5242 spec->capvols = stac925x_capvols;
5243 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005244
Charles Chin9009b0e2011-11-03 10:27:27 +01005245 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005246 if (!err) {
5247 if (spec->board_config < 0) {
5248 printk(KERN_WARNING "hda_codec: No auto-config is "
5249 "available, default to model=ref\n");
5250 spec->board_config = STAC_925x_REF;
5251 goto again;
5252 }
5253 err = -EINVAL;
5254 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005255 if (err < 0) {
5256 stac92xx_free(codec);
5257 return err;
5258 }
5259
5260 codec->patch_ops = stac92xx_patch_ops;
5261
5262 return 0;
5263}
5264
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005265static int patch_stac92hd73xx(struct hda_codec *codec)
5266{
5267 struct sigmatel_spec *spec;
5268 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5269 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005270 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005271
5272 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5273 if (spec == NULL)
5274 return -ENOMEM;
5275
Takashi Iwaia252c812009-12-25 22:56:20 +01005276 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005277 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005278 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005279 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005280 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5281 spec->pin_nids = stac92hd73xx_pin_nids;
5282 spec->board_config = snd_hda_check_board_config(codec,
5283 STAC_92HD73XX_MODELS,
5284 stac92hd73xx_models,
5285 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005286 /* check codec subsystem id if not found */
5287 if (spec->board_config < 0)
5288 spec->board_config =
5289 snd_hda_check_board_codec_sid_config(codec,
5290 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5291 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005292again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005293 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005294 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5295 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005296 else
5297 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005298 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005299
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005300 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005301 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5302
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005303 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005304 printk(KERN_WARNING "hda_codec: Could not determine "
5305 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005306 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005307 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005308 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005309 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005310 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005311 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005312 break;
5313 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005314 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005315 break;
5316 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005317 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5318 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005319 }
5320 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005321
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005322 spec->aloopback_mask = 0x01;
5323 spec->aloopback_shift = 8;
5324
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005325 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005326 spec->mux_nids = stac92hd73xx_mux_nids;
5327 spec->adc_nids = stac92hd73xx_adc_nids;
5328 spec->dmic_nids = stac92hd73xx_dmic_nids;
5329 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005330 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005331
5332 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5333 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai16970552007-12-18 18:05:52 +01005334 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005335
Takashi Iwai6479c632009-07-28 18:20:25 +02005336 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5337 spec->capvols = stac92hd73xx_capvols;
5338 spec->capsws = stac92hd73xx_capsws;
5339
Matthew Ranostaya7662642008-02-21 07:51:14 +01005340 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005341 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005342 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005343 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005344 case STAC_DELL_M6_AMIC:
5345 case STAC_DELL_M6_DMIC:
5346 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005347 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005348 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005349
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005350 switch (spec->board_config) {
5351 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005352 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005353 spec->num_dmics = 0;
5354 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005355 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005356 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005357 spec->num_dmics = 1;
5358 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005359 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005360 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5361 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005362 spec->num_dmics = 1;
5363 break;
5364 }
5365 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005366 case STAC_ALIENWARE_M17X:
5367 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5368 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5369 spec->eapd_switch = 0;
5370 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005371 default:
5372 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005373 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005374 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005375 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005376 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005377 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005378 /* GPIO0 High = Enable EAPD */
5379 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5380 spec->gpio_data = 0x01;
5381 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005382
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005383 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5384 spec->pwr_nids = stac92hd73xx_pwr_nids;
5385
Charles Chin9009b0e2011-11-03 10:27:27 +01005386 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005387
5388 if (!err) {
5389 if (spec->board_config < 0) {
5390 printk(KERN_WARNING "hda_codec: No auto-config is "
5391 "available, default to model=ref\n");
5392 spec->board_config = STAC_92HD73XX_REF;
5393 goto again;
5394 }
5395 err = -EINVAL;
5396 }
5397
5398 if (err < 0) {
5399 stac92xx_free(codec);
5400 return err;
5401 }
5402
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005403 if (spec->board_config == STAC_92HD73XX_NO_JD)
5404 spec->hp_detect = 0;
5405
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005406 codec->patch_ops = stac92xx_patch_ops;
5407
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005408 codec->proc_widget_hook = stac92hd7x_proc_hook;
5409
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005410 return 0;
5411}
5412
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005413static int hp_bnb2011_with_dock(struct hda_codec *codec)
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005414{
5415 if (codec->vendor_id != 0x111d7605 &&
5416 codec->vendor_id != 0x111d76d1)
5417 return 0;
5418
5419 switch (codec->subsystem_id) {
5420 case 0x103c1618:
5421 case 0x103c1619:
5422 case 0x103c161a:
5423 case 0x103c161b:
5424 case 0x103c161c:
5425 case 0x103c161d:
5426 case 0x103c161e:
5427 case 0x103c161f:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005428
5429 case 0x103c162a:
5430 case 0x103c162b:
5431
5432 case 0x103c1630:
5433 case 0x103c1631:
5434
5435 case 0x103c1633:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005436 case 0x103c1634:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005437 case 0x103c1635:
5438
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005439 case 0x103c3587:
5440 case 0x103c3588:
5441 case 0x103c3589:
5442 case 0x103c358a:
5443
5444 case 0x103c3667:
5445 case 0x103c3668:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005446 case 0x103c3669:
5447
5448 return 1;
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005449 }
5450 return 0;
5451}
5452
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005453static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
5454{
5455 struct sigmatel_spec *spec = codec->spec;
5456 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5457 int i;
5458
5459 spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5460 spec->auto_pin_cnt++;
5461
5462 if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5463 get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5464 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5465 if (nid == stac92hd83xxx_dmic_nids[i]) {
5466 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5467 spec->auto_dmic_cnt++;
5468 }
5469 }
5470 }
5471}
5472
5473static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5474{
5475 struct sigmatel_spec *spec = codec->spec;
5476
5477 spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5478 spec->auto_adc_cnt++;
5479}
5480
5481static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5482{
5483 int i, j;
5484 struct sigmatel_spec *spec = codec->spec;
5485
5486 for (i = 0; i < spec->auto_adc_cnt; i++) {
5487 if (get_connection_index(codec,
5488 spec->auto_adc_nids[i], nid) >= 0) {
5489 /* mux and volume for adc_nids[i] */
5490 if (!spec->auto_mux_nids[i]) {
5491 spec->auto_mux_nids[i] = nid;
5492 /* 92hd codecs capture volume is in mux */
5493 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
5494 3, 0, HDA_OUTPUT);
5495 }
5496 for (j = 0; j < spec->auto_dmic_cnt; j++) {
5497 if (get_connection_index(codec, nid,
5498 spec->auto_dmic_nids[j]) >= 0) {
5499 /* dmux for adc_nids[i] */
5500 if (!spec->auto_dmux_nids[i])
5501 spec->auto_dmux_nids[i] = nid;
5502 break;
5503 }
5504 }
5505 break;
5506 }
5507 }
5508}
5509
5510static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5511{
5512 hda_nid_t nid, end_nid;
5513 unsigned int wid_caps, wid_type;
5514 struct sigmatel_spec *spec = codec->spec;
5515
5516 end_nid = codec->start_nid + codec->num_nodes;
5517
5518 for (nid = codec->start_nid; nid < end_nid; nid++) {
5519 wid_caps = get_wcaps(codec, nid);
5520 wid_type = get_wcaps_type(wid_caps);
5521
5522 if (wid_type == AC_WID_PIN)
5523 stac92hd8x_add_pin(codec, nid);
5524
5525 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5526 stac92hd8x_add_adc(codec, nid);
5527 }
5528
5529 for (nid = codec->start_nid; nid < end_nid; nid++) {
5530 wid_caps = get_wcaps(codec, nid);
5531 wid_type = get_wcaps_type(wid_caps);
5532
5533 if (wid_type == AC_WID_AUD_SEL)
5534 stac92hd8x_add_mux(codec, nid);
5535 }
5536
5537 spec->pin_nids = spec->auto_pin_nids;
5538 spec->num_pins = spec->auto_pin_cnt;
5539 spec->adc_nids = spec->auto_adc_nids;
5540 spec->num_adcs = spec->auto_adc_cnt;
5541 spec->capvols = spec->auto_capvols;
5542 spec->capsws = spec->auto_capvols;
5543 spec->num_caps = spec->auto_adc_cnt;
5544 spec->mux_nids = spec->auto_mux_nids;
5545 spec->num_muxes = spec->auto_adc_cnt;
5546 spec->dmux_nids = spec->auto_dmux_nids;
5547 spec->num_dmuxes = spec->auto_adc_cnt;
5548 spec->dmic_nids = spec->auto_dmic_nids;
5549 spec->num_dmics = spec->auto_dmic_cnt;
5550}
5551
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005552static int patch_stac92hd83xxx(struct hda_codec *codec)
5553{
5554 struct sigmatel_spec *spec;
5555 int err;
5556
5557 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5558 if (spec == NULL)
5559 return -ENOMEM;
5560
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005561 if (hp_bnb2011_with_dock(codec)) {
5562 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5563 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5564 }
5565
Takashi Iwaia252c812009-12-25 22:56:20 +01005566 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005567 codec->spec = spec;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005568
5569 stac92hd8x_fill_auto_spec(codec);
5570
Takashi Iwai1db7ccd2010-12-03 15:19:14 +01005571 spec->linear_tone_beep = 0;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005572 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005573 spec->digbeep_nid = 0x21;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005574 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005575 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005576 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005577 spec->init = stac92hd83xxx_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005578
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005579 spec->board_config = snd_hda_check_board_config(codec,
5580 STAC_92HD83XXX_MODELS,
5581 stac92hd83xxx_models,
5582 stac92hd83xxx_cfg_tbl);
5583again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005584 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005585 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5586 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005587 else
5588 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005589 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005590
Takashi Iwaib4e81872009-11-18 17:20:24 +01005591 codec->patch_ops = stac92xx_patch_ops;
5592
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005593 if (find_mute_led_cfg(codec, -1/*no default cfg*/))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005594 snd_printd("mute LED gpio %d polarity %d\n",
5595 spec->gpio_led,
5596 spec->gpio_led_polarity);
5597
Takashi Iwaib4e81872009-11-18 17:20:24 +01005598#ifdef CONFIG_SND_HDA_POWER_SAVE
5599 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005600 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005601 spec->gpio_mask |= spec->gpio_led;
5602 spec->gpio_dir |= spec->gpio_led;
5603 spec->gpio_data |= spec->gpio_led;
5604 } else {
5605 codec->patch_ops.set_power_state =
5606 stac92xx_set_power_state;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005607 }
5608 codec->patch_ops.pre_resume = stac92xx_pre_resume;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005609 codec->patch_ops.check_power_status =
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005610 stac92xx_check_power_status;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005611 }
5612#endif
5613
Charles Chin9009b0e2011-11-03 10:27:27 +01005614 err = stac92xx_parse_auto_config(codec);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005615 if (!err) {
5616 if (spec->board_config < 0) {
5617 printk(KERN_WARNING "hda_codec: No auto-config is "
5618 "available, default to model=ref\n");
5619 spec->board_config = STAC_92HD83XXX_REF;
5620 goto again;
5621 }
5622 err = -EINVAL;
5623 }
5624
5625 if (err < 0) {
5626 stac92xx_free(codec);
5627 return err;
5628 }
5629
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005630 codec->proc_widget_hook = stac92hd_proc_hook;
5631
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005632 return 0;
5633}
5634
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005635static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5636 hda_nid_t dig0pin)
5637{
5638 struct sigmatel_spec *spec = codec->spec;
5639 int idx;
5640
5641 for (idx = 0; idx < spec->num_pins; idx++)
5642 if (spec->pin_nids[idx] == dig0pin)
5643 break;
5644 if ((idx + 2) >= spec->num_pins)
5645 return 0;
5646
5647 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005648 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005649 return 2;
5650
5651 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005652 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005653 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005654 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005655 return 1;
5656 else
5657 return 0;
5658}
5659
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005660/* HP dv7 bass switch - GPIO5 */
5661#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5662static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5663 struct snd_ctl_elem_value *ucontrol)
5664{
5665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5666 struct sigmatel_spec *spec = codec->spec;
5667 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5668 return 0;
5669}
5670
5671static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5672 struct snd_ctl_elem_value *ucontrol)
5673{
5674 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5675 struct sigmatel_spec *spec = codec->spec;
5676 unsigned int gpio_data;
5677
5678 gpio_data = (spec->gpio_data & ~0x20) |
5679 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5680 if (gpio_data == spec->gpio_data)
5681 return 0;
5682 spec->gpio_data = gpio_data;
5683 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5684 return 1;
5685}
5686
Takashi Iwai2b635362011-05-02 12:33:43 +02005687static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005688 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5689 .info = stac_hp_bass_gpio_info,
5690 .get = stac_hp_bass_gpio_get,
5691 .put = stac_hp_bass_gpio_put,
5692};
5693
5694static int stac_add_hp_bass_switch(struct hda_codec *codec)
5695{
5696 struct sigmatel_spec *spec = codec->spec;
5697
5698 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5699 "Bass Speaker Playback Switch", 0))
5700 return -ENOMEM;
5701
5702 spec->gpio_mask |= 0x20;
5703 spec->gpio_dir |= 0x20;
5704 spec->gpio_data |= 0x20;
5705 return 0;
5706}
5707
Matthew Ranostaye035b842007-11-06 11:53:55 +01005708static int patch_stac92hd71bxx(struct hda_codec *codec)
5709{
5710 struct sigmatel_spec *spec;
Takashi Iwai2b635362011-05-02 12:33:43 +02005711 const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005712 unsigned int pin_cfg;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005713 int err = 0;
5714
5715 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5716 if (spec == NULL)
5717 return -ENOMEM;
5718
Takashi Iwaia252c812009-12-25 22:56:20 +01005719 codec->no_trigger_sense = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005720 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005721 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005722 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005723 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5724 switch (codec->vendor_id) {
5725 case 0x111d76b6:
5726 case 0x111d76b7:
5727 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5728 break;
5729 case 0x111d7603:
5730 case 0x111d7608:
5731 /* On 92HD75Bx 0x27 isn't a pin nid */
5732 spec->num_pins--;
5733 /* fallthrough */
5734 default:
5735 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5736 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005737 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005738 spec->board_config = snd_hda_check_board_config(codec,
5739 STAC_92HD71BXX_MODELS,
5740 stac92hd71bxx_models,
5741 stac92hd71bxx_cfg_tbl);
5742again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005743 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005744 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5745 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005746 else
5747 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005748 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005749
Takashi Iwaifc64b262009-09-14 15:33:01 +02005750 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005751 /* GPIO0 = EAPD */
5752 spec->gpio_mask = 0x01;
5753 spec->gpio_dir = 0x01;
5754 spec->gpio_data = 0x01;
5755 }
5756
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005757 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5758 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5759
Takashi Iwai6479c632009-07-28 18:20:25 +02005760 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5761 spec->capvols = stac92hd71bxx_capvols;
5762 spec->capsws = stac92hd71bxx_capsws;
5763
Matthew Ranostay541eee82007-12-14 12:08:04 +01005764 switch (codec->vendor_id) {
5765 case 0x111d76b6: /* 4 Port without Analog Mixer */
5766 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005767 unmute_init++;
5768 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005769 case 0x111d76b4: /* 6 Port without Analog Mixer */
5770 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005771 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005772 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005773 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005774 stac92hd71bxx_dmic_nids,
5775 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005776 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005777 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005778 switch (spec->board_config) {
5779 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005780 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwai3a938972011-10-28 01:16:55 +02005781 err = stac_add_event(codec, codec->afg,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005782 STAC_VREF_EVENT, 0x02);
5783 if (err < 0)
5784 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005785 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005786 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
Takashi Iwai3a938972011-10-28 01:16:55 +02005787 snd_hda_jack_detect_enable(codec, codec->afg, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005788 spec->gpio_mask |= 0x02;
5789 break;
5790 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005791 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005792 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005793 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005794
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005795 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005796 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005797 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005798 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5799 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Takashi Iwai2b635362011-05-02 12:33:43 +02005800 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005801 spec->num_dmics = stac92xx_connected_ports(codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02005802 stac92hd71bxx_dmic_5port_nids,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005803 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005804 break;
5805 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005806 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005807 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005808
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005809 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005810 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005811 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005812 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005813 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005814 stac92hd71bxx_dmic_nids,
5815 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005816 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005817 }
5818
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005819 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5820 snd_hda_sequence_write_cache(codec, unmute_init);
5821
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005822 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005823 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005824 spec->aloopback_shift = 0;
5825
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005826 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005827 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005828 spec->mux_nids = stac92hd71bxx_mux_nids;
5829 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005830 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005831 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005832
5833 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5834 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005835 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005836 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005837
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305838 snd_printdd("Found board config: %d\n", spec->board_config);
5839
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005840 switch (spec->board_config) {
5841 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005842 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005843 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005844 stac92xx_auto_set_pinctl(codec, 0x0e,
5845 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005846 /* fallthru */
5847 case STAC_DELL_M4_2:
5848 spec->num_dmics = 0;
5849 spec->num_smuxes = 0;
5850 spec->num_dmuxes = 0;
5851 break;
5852 case STAC_DELL_M4_1:
5853 case STAC_DELL_M4_3:
5854 spec->num_dmics = 1;
5855 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005856 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005857 break;
James Gardiner514bf542009-05-03 04:00:44 -04005858 case STAC_HP_DV4_1222NR:
5859 spec->num_dmics = 1;
5860 /* I don't know if it needs 1 or 2 smuxes - will wait for
5861 * bug reports to fix if needed
5862 */
5863 spec->num_smuxes = 1;
5864 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005865 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005866 case STAC_HP_DV4:
5867 spec->gpio_led = 0x01;
5868 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005869 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005870 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005871 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005872 /* HP dv6 gives the headphone pin as a line-out. Thus we
5873 * need to set hp_detect flag here to force to enable HP
5874 * detection.
5875 */
5876 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005877 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005878 case STAC_HP_HDX:
5879 spec->num_dmics = 1;
5880 spec->num_dmuxes = 1;
5881 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005882 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005883 break;
5884 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005885
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005886 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005887 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5888 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5889 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5890 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5891 /* It was changed in the BIOS to just satisfy MS DTM.
5892 * Lets turn it back into slaved HP
5893 */
5894 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5895 | (AC_JACK_HP_OUT <<
5896 AC_DEFCFG_DEVICE_SHIFT);
5897 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5898 | AC_DEFCFG_SEQUENCE)))
5899 | 0x1f;
5900 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5901 }
5902 }
5903
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005904 if (find_mute_led_cfg(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005905 snd_printd("mute LED gpio %d polarity %d\n",
5906 spec->gpio_led,
5907 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005908
Takashi Iwai86d190e2009-05-26 15:18:58 +02005909#ifdef CONFIG_SND_HDA_POWER_SAVE
5910 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005911 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005912 spec->gpio_mask |= spec->gpio_led;
5913 spec->gpio_dir |= spec->gpio_led;
5914 spec->gpio_data |= spec->gpio_led;
5915 } else {
5916 codec->patch_ops.set_power_state =
5917 stac92xx_set_power_state;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005918 }
5919 codec->patch_ops.pre_resume = stac92xx_pre_resume;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005920 codec->patch_ops.check_power_status =
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005921 stac92xx_check_power_status;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005922 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005923#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005924
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005925 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005926
Charles Chin9009b0e2011-11-03 10:27:27 +01005927 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005928 if (!err) {
5929 if (spec->board_config < 0) {
5930 printk(KERN_WARNING "hda_codec: No auto-config is "
5931 "available, default to model=ref\n");
5932 spec->board_config = STAC_92HD71BXX_REF;
5933 goto again;
5934 }
5935 err = -EINVAL;
5936 }
5937
5938 if (err < 0) {
5939 stac92xx_free(codec);
5940 return err;
5941 }
5942
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005943 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005944 if (spec->board_config == STAC_HP_DV4 ||
5945 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005946 unsigned int cap;
5947 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5948 cap &= AC_GPIO_IO_COUNT;
5949 if (cap >= 6)
5950 stac_add_hp_bass_switch(codec);
5951 }
5952
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005953 codec->proc_widget_hook = stac92hd7x_proc_hook;
5954
Matthew Ranostaye035b842007-11-06 11:53:55 +01005955 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005956}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005957
Matt2f2f4252005-04-13 14:45:30 +02005958static int patch_stac922x(struct hda_codec *codec)
5959{
5960 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005961 int err;
Matt2f2f4252005-04-13 14:45:30 +02005962
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005963 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005964 if (spec == NULL)
5965 return -ENOMEM;
5966
Takashi Iwaia252c812009-12-25 22:56:20 +01005967 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005968 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005969 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005970 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005971 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005972 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5973 stac922x_models,
5974 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005975 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005976 spec->gpio_mask = spec->gpio_dir = 0x03;
5977 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005978 /* Intel Macs have all same PCI SSID, so we need to check
5979 * codec SSID to distinguish the exact models
5980 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005981 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005982 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005983
5984 case 0x106b0800:
5985 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005986 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005987 case 0x106b0600:
5988 case 0x106b0700:
5989 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005990 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005991 case 0x106b0e00:
5992 case 0x106b0f00:
5993 case 0x106b1600:
5994 case 0x106b1700:
5995 case 0x106b0200:
5996 case 0x106b1e00:
5997 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005998 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005999 case 0x106b1a00:
6000 case 0x00000100:
6001 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02006002 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006003 case 0x106b0a00:
6004 case 0x106b2200:
6005 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02006006 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08006007 default:
6008 spec->board_config = STAC_INTEL_MAC_V3;
6009 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006010 }
6011 }
6012
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006013 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006014 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006015 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6016 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006017 else
6018 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006019 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02006020
Matt2f2f4252005-04-13 14:45:30 +02006021 spec->adc_nids = stac922x_adc_nids;
6022 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006023 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006024 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006025 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006026 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02006027
6028 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006029
6030 spec->num_caps = STAC922X_NUM_CAPS;
6031 spec->capvols = stac922x_capvols;
6032 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02006033
6034 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02006035
Charles Chin9009b0e2011-11-03 10:27:27 +01006036 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006037 if (!err) {
6038 if (spec->board_config < 0) {
6039 printk(KERN_WARNING "hda_codec: No auto-config is "
6040 "available, default to model=ref\n");
6041 spec->board_config = STAC_D945_REF;
6042 goto again;
6043 }
6044 err = -EINVAL;
6045 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006046 if (err < 0) {
6047 stac92xx_free(codec);
6048 return err;
6049 }
6050
6051 codec->patch_ops = stac92xx_patch_ops;
6052
Takashi Iwai807a46362007-05-29 19:01:37 +02006053 /* Fix Mux capture level; max to 2 */
6054 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
6055 (0 << AC_AMPCAP_OFFSET_SHIFT) |
6056 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
6057 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6058 (0 << AC_AMPCAP_MUTE_SHIFT));
6059
Matt Porter3cc08dc2006-01-23 15:27:49 +01006060 return 0;
6061}
6062
6063static int patch_stac927x(struct hda_codec *codec)
6064{
6065 struct sigmatel_spec *spec;
6066 int err;
6067
6068 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6069 if (spec == NULL)
6070 return -ENOMEM;
6071
Takashi Iwaia252c812009-12-25 22:56:20 +01006072 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01006073 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006074 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05006075 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006076 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006077 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006078 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
6079 stac927x_models,
6080 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006081 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006082 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006083 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6084 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006085 else
6086 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006087 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01006088
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006089 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006090 spec->adc_nids = stac927x_adc_nids;
6091 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6092 spec->mux_nids = stac927x_mux_nids;
6093 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006094 spec->smux_nids = stac927x_smux_nids;
6095 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04006096 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01006097 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006098 spec->multiout.dac_nids = spec->dac_nids;
6099
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006100 if (spec->board_config != STAC_D965_REF) {
6101 /* GPIO0 High = Enable EAPD */
6102 spec->eapd_mask = spec->gpio_mask = 0x01;
6103 spec->gpio_dir = spec->gpio_data = 0x01;
6104 }
6105
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006106 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02006107 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006108 case STAC_D965_5ST:
6109 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006110 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02006111 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006112 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006113 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006114 switch (codec->subsystem_id) {
6115 case 0x10280209:
6116 case 0x1028022e:
6117 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006118 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006119 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006120 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01006121 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01006122 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01006123 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006124 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006125 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01006126 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006127 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006128 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006129 if (codec->subsystem_id != 0x1028022f) {
6130 /* GPIO2 High = Enable EAPD */
6131 spec->eapd_mask = spec->gpio_mask = 0x04;
6132 spec->gpio_dir = spec->gpio_data = 0x04;
6133 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006134 spec->dmic_nids = stac927x_dmic_nids;
6135 spec->num_dmics = STAC927X_NUM_DMICS;
6136
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02006137 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006138 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai16970552007-12-18 18:05:52 +01006139 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006140 break;
Takashi Iwai54930532009-10-11 17:38:29 +02006141 case STAC_927X_VOLKNOB:
6142 spec->num_dmics = 0;
6143 spec->init = stac927x_volknob_core_init;
6144 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006145 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006146 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006147 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006148 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006149 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006150
Takashi Iwai6479c632009-07-28 18:20:25 +02006151 spec->num_caps = STAC927X_NUM_CAPS;
6152 spec->capvols = stac927x_capvols;
6153 spec->capsws = stac927x_capsws;
6154
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006155 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006156 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006157 spec->aloopback_mask = 0x40;
6158 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05006159 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006160
Charles Chin9009b0e2011-11-03 10:27:27 +01006161 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006162 if (!err) {
6163 if (spec->board_config < 0) {
6164 printk(KERN_WARNING "hda_codec: No auto-config is "
6165 "available, default to model=ref\n");
6166 spec->board_config = STAC_D965_REF;
6167 goto again;
6168 }
6169 err = -EINVAL;
6170 }
Mattc7d4b2f2005-06-27 14:59:41 +02006171 if (err < 0) {
6172 stac92xx_free(codec);
6173 return err;
6174 }
Matt2f2f4252005-04-13 14:45:30 +02006175
6176 codec->patch_ops = stac92xx_patch_ops;
6177
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006178 codec->proc_widget_hook = stac927x_proc_hook;
6179
Takashi Iwai52987652008-01-16 16:09:47 +01006180 /*
6181 * !!FIXME!!
6182 * The STAC927x seem to require fairly long delays for certain
6183 * command sequences. With too short delays (even if the answer
6184 * is set to RIRB properly), it results in the silence output
6185 * on some hardwares like Dell.
6186 *
6187 * The below flag enables the longer delay (see get_response
6188 * in hda_intel.c).
6189 */
6190 codec->bus->needs_damn_long_delay = 1;
6191
Takashi Iwaie28d8322008-12-17 13:48:29 +01006192 /* no jack detecion for ref-no-jd model */
6193 if (spec->board_config == STAC_D965_REF_NO_JD)
6194 spec->hp_detect = 0;
6195
Matt2f2f4252005-04-13 14:45:30 +02006196 return 0;
6197}
6198
Matt Porterf3302a52006-07-31 12:49:34 +02006199static int patch_stac9205(struct hda_codec *codec)
6200{
6201 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006202 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006203
6204 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6205 if (spec == NULL)
6206 return -ENOMEM;
6207
Takashi Iwaia252c812009-12-25 22:56:20 +01006208 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006209 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006210 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006211 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006212 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006213 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6214 stac9205_models,
6215 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006216 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006217 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006218 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6219 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006220 else
6221 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006222 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006223
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006224 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006225 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006226 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006227 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006228 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006229 spec->smux_nids = stac9205_smux_nids;
6230 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006231 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006232 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006233 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai16970552007-12-18 18:05:52 +01006234 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006235 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006236
6237 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006238 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006239
Takashi Iwai6479c632009-07-28 18:20:25 +02006240 spec->num_caps = STAC9205_NUM_CAPS;
6241 spec->capvols = stac9205_capvols;
6242 spec->capsws = stac9205_capsws;
6243
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006244 spec->aloopback_mask = 0x40;
6245 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006246 /* Turn on/off EAPD per HP plugging */
6247 if (spec->board_config != STAC_9205_EAPD)
6248 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006249 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006250
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006251 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006252 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006253 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006254 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6255 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006256
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006257 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwai3a938972011-10-28 01:16:55 +02006258 err = stac_add_event(codec, codec->afg, STAC_VREF_EVENT, 0x01);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006259 if (err < 0)
6260 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006261 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006262 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
Takashi Iwai3a938972011-10-28 01:16:55 +02006263 snd_hda_jack_detect_enable(codec, codec->afg, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006264
6265 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006266 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006267 spec->gpio_mask = 0x1b;
6268 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006269 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006270 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006271 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006272 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006273 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006274 case STAC_9205_REF:
6275 /* SPDIF-In enabled */
6276 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006277 default:
6278 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006279 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006280 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006281 break;
6282 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006283
Charles Chin9009b0e2011-11-03 10:27:27 +01006284 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006285 if (!err) {
6286 if (spec->board_config < 0) {
6287 printk(KERN_WARNING "hda_codec: No auto-config is "
6288 "available, default to model=ref\n");
6289 spec->board_config = STAC_9205_REF;
6290 goto again;
6291 }
6292 err = -EINVAL;
6293 }
Matt Porterf3302a52006-07-31 12:49:34 +02006294 if (err < 0) {
6295 stac92xx_free(codec);
6296 return err;
6297 }
6298
6299 codec->patch_ops = stac92xx_patch_ops;
6300
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006301 codec->proc_widget_hook = stac9205_proc_hook;
6302
Matt Porterf3302a52006-07-31 12:49:34 +02006303 return 0;
6304}
6305
Matt2f2f4252005-04-13 14:45:30 +02006306/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006307 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006308 */
6309
Takashi Iwai2b635362011-05-02 12:33:43 +02006310static const struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006311 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006312 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6313 {}
6314};
6315
Takashi Iwai2b635362011-05-02 12:33:43 +02006316static const hda_nid_t stac9872_pin_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006317 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6318 0x11, 0x13, 0x14,
6319};
6320
Takashi Iwai2b635362011-05-02 12:33:43 +02006321static const hda_nid_t stac9872_adc_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006322 0x8 /*,0x6*/
6323};
6324
Takashi Iwai2b635362011-05-02 12:33:43 +02006325static const hda_nid_t stac9872_mux_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006326 0x15
6327};
6328
Takashi Iwai2b635362011-05-02 12:33:43 +02006329static const unsigned long stac9872_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +02006330 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6331};
6332#define stac9872_capsws stac9872_capvols
6333
Takashi Iwai2b635362011-05-02 12:33:43 +02006334static const unsigned int stac9872_vaio_pin_configs[9] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006335 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6336 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6337 0x90a7013e
6338};
6339
Takashi Iwaiea734962011-01-17 11:29:34 +01006340static const char * const stac9872_models[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006341 [STAC_9872_AUTO] = "auto",
6342 [STAC_9872_VAIO] = "vaio",
6343};
6344
Takashi Iwai2b635362011-05-02 12:33:43 +02006345static const unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006346 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6347};
6348
Takashi Iwai2b635362011-05-02 12:33:43 +02006349static const struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006350 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6351 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006352 {} /* terminator */
6353};
6354
Guillaume Munch6d859062006-08-22 17:15:47 +02006355static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006356{
6357 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006358 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006359
Takashi Iwaidb064e52006-03-16 16:04:58 +01006360 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6361 if (spec == NULL)
6362 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006363 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006364 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006365 spec->linear_tone_beep = 1;
Takashi Iwaib04add92009-07-20 08:01:36 +02006366 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6367 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006368
6369 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6370 stac9872_models,
6371 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006372 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006373 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6374 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006375 else
6376 stac92xx_set_config_regs(codec,
6377 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006378
Takashi Iwai1e137f92009-01-21 07:41:22 +01006379 spec->multiout.dac_nids = spec->dac_nids;
6380 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6381 spec->adc_nids = stac9872_adc_nids;
6382 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6383 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006384 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006385 spec->num_caps = 1;
6386 spec->capvols = stac9872_capvols;
6387 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006388
Charles Chin9009b0e2011-11-03 10:27:27 +01006389 err = stac92xx_parse_auto_config(codec);
Takashi Iwai1e137f92009-01-21 07:41:22 +01006390 if (err < 0) {
6391 stac92xx_free(codec);
6392 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006393 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006394 spec->input_mux = &spec->private_imux;
6395 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006396 return 0;
6397}
6398
6399
6400/*
Matt2f2f4252005-04-13 14:45:30 +02006401 * patch entries
6402 */
Takashi Iwai2b635362011-05-02 12:33:43 +02006403static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006404 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6405 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6406 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6407 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6408 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6409 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6410 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006411 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6412 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6413 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6414 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6415 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6416 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006417 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6418 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6419 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6420 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6421 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6422 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6423 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6424 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6425 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6426 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006427 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6428 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6429 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6430 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6431 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6432 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006433 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6434 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006435 /* The following does not take into account .id=0x83847661 when subsys =
6436 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6437 * currently not fully supported.
6438 */
6439 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6440 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6441 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006442 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006443 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6444 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6445 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6446 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6447 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6448 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6449 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6450 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006451 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006452 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006453 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006454 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006455 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006456 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6457 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006458 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6459 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6460 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6461 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006462 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006463 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6464 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006465 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006466 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6467 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6468 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6469 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6470 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6471 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6472 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6473 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006474 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6475 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6476 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6477 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6478 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6479 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6480 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6481 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6482 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6483 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6484 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6485 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6486 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6487 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6488 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
David Henningsson46724c22011-09-20 09:02:22 +02006489 { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006490 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06006491 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6492 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006493 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Charles Chinad5d8752011-11-02 07:56:58 +01006494 { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6495 { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6496 { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6497 { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6498 { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6499 { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6500 { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6501 { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6502 { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6503 { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6504 { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6505 { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006506 {} /* terminator */
6507};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006508
6509MODULE_ALIAS("snd-hda-codec-id:8384*");
6510MODULE_ALIAS("snd-hda-codec-id:111d*");
6511
6512MODULE_LICENSE("GPL");
6513MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6514
6515static struct hda_codec_preset_list sigmatel_list = {
6516 .preset = snd_hda_preset_sigmatel,
6517 .owner = THIS_MODULE,
6518};
6519
6520static int __init patch_sigmatel_init(void)
6521{
6522 return snd_hda_add_codec_preset(&sigmatel_list);
6523}
6524
6525static void __exit patch_sigmatel_exit(void)
6526{
6527 snd_hda_delete_codec_preset(&sigmatel_list);
6528}
6529
6530module_init(patch_sigmatel_init)
6531module_exit(patch_sigmatel_exit)