blob: de7166a65f8b8964288a605c10d45cfa248dd4eb [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 Iwaic8b6bf92005-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 Ranostay4fe5195c2008-01-29 15:28:44 +0100203 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200204 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-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 Ranostay4fe5195c2008-01-29 15:28:44 +0100213
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200214 /* stream */
215 unsigned int stream_delay;
216
Matthew Ranostay4fe5195c2008-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 Iwai1697055e2007-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 Iwai1697055e2007-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 Iwai1697055e2007-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwai1697055e2007-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 Iwai9322ca52012-02-03 14:28:01 +01001063static const char * const slave_pfxs[] = {
1064 "Front", "Surround", "Center", "LFE", "Side",
1065 "Headphone", "Speaker", "IEC958",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001066 NULL
1067};
1068
Takashi Iwai603c4012008-07-30 15:01:44 +02001069static void stac92xx_free_kctls(struct hda_codec *codec);
1070
Matt2f2f4252005-04-13 14:45:30 +02001071static int stac92xx_build_controls(struct hda_codec *codec)
1072{
1073 struct sigmatel_spec *spec = codec->spec;
1074 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001075 int i;
Matt2f2f4252005-04-13 14:45:30 +02001076
Takashi Iwai6479c632009-07-28 18:20:25 +02001077 if (spec->mixer) {
1078 err = snd_hda_add_new_ctls(codec, spec->mixer);
1079 if (err < 0)
1080 return err;
1081 }
Mattc7d4b2f2005-06-27 14:59:41 +02001082
1083 for (i = 0; i < spec->num_mixers; i++) {
1084 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1085 if (err < 0)
1086 return err;
1087 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001088 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1089 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001090 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001091 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001092 snd_ctl_new1(&stac_dmux_mixer, codec));
1093 if (err < 0)
1094 return err;
1095 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001096 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001097 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1098 struct hda_input_mux *smux = &spec->private_smux;
1099 /* check for mute support on SPDIF out */
1100 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001101 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001102 spec->spdif_mute = 1;
1103 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001104 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001105 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001106 snd_ctl_new1(&stac_smux_mixer, codec));
1107 if (err < 0)
1108 return err;
1109 }
Mattc7d4b2f2005-06-27 14:59:41 +02001110
Mattdabbed62005-06-14 10:19:34 +02001111 if (spec->multiout.dig_out_nid) {
Stephen Warren74b654c2011-06-01 11:14:18 -06001112 err = snd_hda_create_spdif_out_ctls(codec,
1113 spec->multiout.dig_out_nid,
1114 spec->multiout.dig_out_nid);
Mattdabbed62005-06-14 10:19:34 +02001115 if (err < 0)
1116 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001117 err = snd_hda_create_spdif_share_sw(codec,
1118 &spec->multiout);
1119 if (err < 0)
1120 return err;
1121 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001122 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001123 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001124 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1125 if (err < 0)
1126 return err;
1127 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001128
1129 /* if we have no master control, let's create it */
1130 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001131 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001132 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001133 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001134 /* correct volume offset */
1135 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001136 /* minimum value is actually mute */
Clemens Ladischa74ccea2010-10-22 15:52:34 +02001137 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001138 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001139 vmaster_tlv, slave_pfxs,
1140 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001141 if (err < 0)
1142 return err;
1143 }
1144 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1145 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001146 NULL, slave_pfxs,
1147 "Playback Switch");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001148 if (err < 0)
1149 return err;
1150 }
1151
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001152 if (spec->aloopback_ctl &&
1153 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1154 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1155 if (err < 0)
1156 return err;
1157 }
1158
Takashi Iwai603c4012008-07-30 15:01:44 +02001159 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001160
Takashi Iwai01a61e12011-10-28 00:03:22 +02001161 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1162 if (err < 0)
1163 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001164
Mattdabbed62005-06-14 10:19:34 +02001165 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001166}
1167
Takashi Iwai2b635362011-05-02 12:33:43 +02001168static const unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001169 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001170 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1171};
1172
Takashi Iwai2b635362011-05-02 12:33:43 +02001173static const unsigned int gateway9200_m4_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001174 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1175 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1176};
Takashi Iwai2b635362011-05-02 12:33:43 +02001177static const unsigned int gateway9200_m4_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001178 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1179 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1180};
1181
1182/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001183 STAC 9200 pin configs for
1184 102801A8
1185 102801DE
1186 102801E8
1187*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001188static const unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001189 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1190 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001191};
1192
1193/*
1194 STAC 9200 pin configs for
1195 102801C0
1196 102801C1
1197*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001198static const unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001199 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1200 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001201};
1202
1203/*
1204 STAC 9200 pin configs for
1205 102801C4 (Dell Dimension E310)
1206 102801C5
1207 102801C7
1208 102801D9
1209 102801DA
1210 102801E3
1211*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001212static const unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001213 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1214 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001215};
1216
1217
1218/*
1219 STAC 9200-32 pin configs for
1220 102801B5 (Dell Inspiron 630m)
1221 102801D8 (Dell Inspiron 640m)
1222*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001223static const unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001224 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1225 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001226};
1227
1228/*
1229 STAC 9200-32 pin configs for
1230 102801C2 (Dell Latitude D620)
1231 102801C8
1232 102801CC (Dell Latitude D820)
1233 102801D4
1234 102801D6
1235*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001236static const unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001237 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1238 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001239};
1240
1241/*
1242 STAC 9200-32 pin configs for
1243 102801CE (Dell XPS M1710)
1244 102801CF (Dell Precision M90)
1245*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001246static const unsigned int dell9200_m23_pin_configs[8] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001247 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1248 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1249};
1250
1251/*
1252 STAC 9200-32 pin configs for
1253 102801C9
1254 102801CA
1255 102801CB (Dell Latitude 120L)
1256 102801D3
1257*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001258static const unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001259 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1260 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001261};
1262
1263/*
1264 STAC 9200-32 pin configs for
1265 102801BD (Dell Inspiron E1505n)
1266 102801EE
1267 102801EF
1268*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001269static const unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001270 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1271 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001272};
1273
1274/*
1275 STAC 9200-32 pin configs for
1276 102801F5 (Dell Inspiron 1501)
1277 102801F6
1278*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001279static const unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001280 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1281 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001282};
1283
1284/*
1285 STAC 9200-32
1286 102801CD (Dell Inspiron E1705/9400)
1287*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001288static const unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001289 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1290 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001291};
1292
Takashi Iwai2b635362011-05-02 12:33:43 +02001293static const unsigned int oqo9200_pin_configs[8] = {
Tobin Davisbf277782008-02-03 20:31:47 +01001294 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1295 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1296};
1297
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001298
Takashi Iwai2b635362011-05-02 12:33:43 +02001299static const unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001300 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001301 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001302 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1303 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1304 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1305 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1306 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1307 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1308 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1309 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1310 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1311 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001312 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1313 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001314 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001315};
1316
Takashi Iwaiea734962011-01-17 11:29:34 +01001317static const char * const stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001318 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001319 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001320 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001321 [STAC_9200_DELL_D21] = "dell-d21",
1322 [STAC_9200_DELL_D22] = "dell-d22",
1323 [STAC_9200_DELL_D23] = "dell-d23",
1324 [STAC_9200_DELL_M21] = "dell-m21",
1325 [STAC_9200_DELL_M22] = "dell-m22",
1326 [STAC_9200_DELL_M23] = "dell-m23",
1327 [STAC_9200_DELL_M24] = "dell-m24",
1328 [STAC_9200_DELL_M25] = "dell-m25",
1329 [STAC_9200_DELL_M26] = "dell-m26",
1330 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001331 [STAC_9200_M4] = "gateway-m4",
1332 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001333 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001334};
1335
Takashi Iwai2b635362011-05-02 12:33:43 +02001336static const struct snd_pci_quirk stac9200_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001337 /* SigmaTel reference board */
1338 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1339 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001340 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1341 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001342 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001343 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1344 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001345 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001346 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1347 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1348 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1349 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1350 "unknown Dell", STAC_9200_DELL_D22),
1351 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1352 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001353 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001354 "Dell Latitude D620", STAC_9200_DELL_M22),
1355 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1356 "unknown Dell", STAC_9200_DELL_D23),
1357 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1358 "unknown Dell", STAC_9200_DELL_D23),
1359 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1360 "unknown Dell", STAC_9200_DELL_M22),
1361 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1362 "unknown Dell", STAC_9200_DELL_M24),
1363 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1364 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001365 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001366 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001367 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001368 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001369 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001370 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001371 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001372 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001373 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001374 "Dell Precision M90", STAC_9200_DELL_M23),
1375 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1376 "unknown Dell", STAC_9200_DELL_M22),
1377 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1378 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001379 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001380 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001381 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001382 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1383 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1384 "unknown Dell", STAC_9200_DELL_D23),
1385 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1386 "unknown Dell", STAC_9200_DELL_D23),
1387 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1388 "unknown Dell", STAC_9200_DELL_D21),
1389 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1390 "unknown Dell", STAC_9200_DELL_D23),
1391 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1392 "unknown Dell", STAC_9200_DELL_D21),
1393 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1394 "unknown Dell", STAC_9200_DELL_M25),
1395 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1396 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001397 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001398 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1399 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1400 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001401 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001402 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001403 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001404 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1405 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1406 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001407 /* OQO Mobile */
1408 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001409 {} /* terminator */
1410};
1411
Takashi Iwai2b635362011-05-02 12:33:43 +02001412static const unsigned int ref925x_pin_configs[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001413 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001414 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001415};
1416
Takashi Iwai2b635362011-05-02 12:33:43 +02001417static const unsigned int stac925xM1_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001418 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1419 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001420};
1421
Takashi Iwai2b635362011-05-02 12:33:43 +02001422static const unsigned int stac925xM1_2_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001423 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1424 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1425};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001426
Takashi Iwai2b635362011-05-02 12:33:43 +02001427static const unsigned int stac925xM2_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001428 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1429 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001430};
1431
Takashi Iwai2b635362011-05-02 12:33:43 +02001432static const unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001433 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1434 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1435};
1436
Takashi Iwai2b635362011-05-02 12:33:43 +02001437static const unsigned int stac925xM3_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001438 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1439 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1440};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001441
Takashi Iwai2b635362011-05-02 12:33:43 +02001442static const unsigned int stac925xM5_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001443 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1444 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1445};
1446
Takashi Iwai2b635362011-05-02 12:33:43 +02001447static const unsigned int stac925xM6_pin_configs[8] = {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001448 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1449 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001450};
1451
Takashi Iwai2b635362011-05-02 12:33:43 +02001452static const unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001453 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001454 [STAC_M1] = stac925xM1_pin_configs,
1455 [STAC_M1_2] = stac925xM1_2_pin_configs,
1456 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001457 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001458 [STAC_M3] = stac925xM3_pin_configs,
1459 [STAC_M5] = stac925xM5_pin_configs,
1460 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001461};
1462
Takashi Iwaiea734962011-01-17 11:29:34 +01001463static const char * const stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001464 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001465 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001466 [STAC_M1] = "m1",
1467 [STAC_M1_2] = "m1-2",
1468 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001469 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001470 [STAC_M3] = "m3",
1471 [STAC_M5] = "m5",
1472 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001473};
1474
Takashi Iwai2b635362011-05-02 12:33:43 +02001475static const struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001476 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1477 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1478 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1479 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001480 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001481 /* Not sure about the brand name for those */
1482 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1483 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1484 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1485 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001486 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001487};
1488
Takashi Iwai2b635362011-05-02 12:33:43 +02001489static const struct snd_pci_quirk stac925x_cfg_tbl[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +01001490 /* SigmaTel reference board */
1491 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001492 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001493 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001494
1495 /* Default table for unknown ID */
1496 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1497
Tobin Davis8e21c342007-01-08 11:04:17 +01001498 {} /* terminator */
1499};
1500
Takashi Iwai2b635362011-05-02 12:33:43 +02001501static const unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001502 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1503 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1504 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001505 0x01452050,
1506};
1507
Takashi Iwai2b635362011-05-02 12:33:43 +02001508static const unsigned int dell_m6_pin_configs[13] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001509 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001510 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001511 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1512 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001513};
1514
Takashi Iwai2b635362011-05-02 12:33:43 +02001515static const unsigned int alienware_m17x_pin_configs[13] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001516 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1517 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1518 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1519 0x904601b0,
1520};
1521
Takashi Iwai2b635362011-05-02 12:33:43 +02001522static const unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001523 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001524 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001525};
1526
Takashi Iwai2b635362011-05-02 12:33:43 +02001527static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001528 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001529 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1530 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1531 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001532 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001533 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001534 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001535};
1536
Takashi Iwaiea734962011-01-17 11:29:34 +01001537static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001538 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001539 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001540 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001541 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001542 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1543 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1544 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001545 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001546 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001547};
1548
Takashi Iwai2b635362011-05-02 12:33:43 +02001549static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001550 /* SigmaTel reference board */
1551 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001552 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001553 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1554 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001555 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1556 "Intel DG45ID", STAC_92HD73XX_INTEL),
1557 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1558 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001559 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001560 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001561 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001562 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001563 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001564 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001565 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001566 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001567 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001568 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001569 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001570 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001571 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001572 "unknown Dell", STAC_DELL_M6_DMIC),
1573 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1574 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001575 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001576 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001577 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1578 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001579 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1580 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001581 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1582 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001583 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
David Henningssonffe535e2012-01-16 10:52:20 +01001584 "Dell Studio XPS 1645", STAC_DELL_M6_DMIC),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001585 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
David Henningssone033ebf2011-05-16 12:09:29 +02001586 "Dell Studio 1558", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001587 {} /* terminator */
1588};
1589
Takashi Iwai2b635362011-05-02 12:33:43 +02001590static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001591 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1592 "Alienware M17x", STAC_ALIENWARE_M17X),
Daniel T Chen0defe092010-12-01 19:16:07 -05001593 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1594 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwaidbd1b542011-11-19 11:41:30 +01001595 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490,
Albert Poolb9ecc4e2012-01-19 22:08:50 +01001596 "Alienware M17x R3", STAC_DELL_EQ),
Takashi Iwai842ae632009-09-02 07:43:08 +02001597 {} /* terminator */
1598};
1599
Takashi Iwai2b635362011-05-02 12:33:43 +02001600static const unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001601 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1602 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001603 0x01451160, 0x98560170,
1604};
1605
Takashi Iwai2b635362011-05-02 12:33:43 +02001606static const unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001607 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1608 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001609 0x40f000f0, 0x40f000f0,
1610};
1611
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001612static const unsigned int dell_vostro_3500_pin_configs[10] = {
1613 0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
1614 0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
1615 0x400000f4, 0x400000f5,
1616};
1617
Takashi Iwai2b635362011-05-02 12:33:43 +02001618static const unsigned int hp_dv7_4000_pin_configs[10] = {
Steven Eastland48315592010-08-06 15:07:35 -06001619 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1620 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1621 0x40f000f0, 0x40f000f0,
1622};
1623
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001624static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
1625 0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
1626 0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
1627 0x40f000f0, 0x40f000f0,
1628};
1629
Takashi Iwai2b635362011-05-02 12:33:43 +02001630static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001631 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001632 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001633 [STAC_DELL_S14] = dell_s14_pin_configs,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001634 [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001635 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001636 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001637};
1638
Takashi Iwaiea734962011-01-17 11:29:34 +01001639static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001640 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001641 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001642 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001643 [STAC_DELL_S14] = "dell-s14",
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001644 [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001645 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
Steven Eastland48315592010-08-06 15:07:35 -06001646 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001647};
1648
Takashi Iwai2b635362011-05-02 12:33:43 +02001649static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001650 /* SigmaTel reference board */
1651 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001652 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001653 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1654 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001655 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1656 "unknown Dell", STAC_DELL_S14),
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001657 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
1658 "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001659 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
1660 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1661 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
1662 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1663 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
1664 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1665 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
1666 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1667 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
1668 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1669 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1670 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1671 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1672 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1673 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
1674 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1675 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
1676 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1677 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
1678 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1679 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
1680 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1681 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
1682 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1683 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
1684 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1685 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
1686 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1687 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
1688 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1689 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
1690 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1691 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
1692 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1693 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
1694 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1695 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
1696 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1697 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
1698 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001699 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001700};
1701
Takashi Iwai2b635362011-05-02 12:33:43 +02001702static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001703 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001704 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001705 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1706 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001707};
1708
Takashi Iwai2b635362011-05-02 12:33:43 +02001709static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001710 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001711 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001712 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1713 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001714};
1715
Takashi Iwai2b635362011-05-02 12:33:43 +02001716static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001717 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1718 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001719 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1720 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001721};
1722
Takashi Iwai2b635362011-05-02 12:33:43 +02001723static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001724 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1725 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001726 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1727 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001728};
1729
Takashi Iwai2b635362011-05-02 12:33:43 +02001730static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001731 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001732 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1733 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001734 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001735 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001736 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001737 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001738 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001739 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001740};
1741
Takashi Iwaiea734962011-01-17 11:29:34 +01001742static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001743 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001744 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001745 [STAC_DELL_M4_1] = "dell-m4-1",
1746 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001747 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001748 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001749 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001750 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001751 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001752 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001753};
1754
Takashi Iwai2b635362011-05-02 12:33:43 +02001755static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001756 /* SigmaTel reference board */
1757 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1758 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001759 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1760 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001761 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1762 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01001763 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1764 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01001765 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1766 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001767 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001768 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001769 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1770 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001771 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1772 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001773 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001774 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001775 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001776 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001777 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1778 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05301779 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1780 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11001781 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1782 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02001783 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1784 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001785 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1786 "unknown Dell", STAC_DELL_M4_1),
1787 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1788 "unknown Dell", STAC_DELL_M4_1),
1789 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1790 "unknown Dell", STAC_DELL_M4_1),
1791 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1792 "unknown Dell", STAC_DELL_M4_1),
1793 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1794 "unknown Dell", STAC_DELL_M4_1),
1795 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1796 "unknown Dell", STAC_DELL_M4_1),
1797 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1798 "unknown Dell", STAC_DELL_M4_1),
1799 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1800 "unknown Dell", STAC_DELL_M4_2),
1801 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1802 "unknown Dell", STAC_DELL_M4_2),
1803 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1804 "unknown Dell", STAC_DELL_M4_2),
1805 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1806 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001807 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1808 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001809 {} /* terminator */
1810};
1811
Takashi Iwai2b635362011-05-02 12:33:43 +02001812static const unsigned int ref922x_pin_configs[10] = {
Matt Porter403d1942005-11-29 15:00:51 +01001813 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1814 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001815 0x40000100, 0x40000100,
1816};
1817
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001818/*
1819 STAC 922X pin configs for
1820 102801A7
1821 102801AB
1822 102801A9
1823 102801D1
1824 102801D2
1825*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001826static const unsigned int dell_922x_d81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001827 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1828 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1829 0x01813122, 0x400001f2,
1830};
1831
1832/*
1833 STAC 922X pin configs for
1834 102801AC
1835 102801D0
1836*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001837static const unsigned int dell_922x_d82_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001838 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1839 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1840 0x01813122, 0x400001f1,
1841};
1842
1843/*
1844 STAC 922X pin configs for
1845 102801BF
1846*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001847static const unsigned int dell_922x_m81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001848 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1849 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1850 0x40C003f1, 0x405003f0,
1851};
1852
1853/*
1854 STAC 9221 A1 pin configs for
1855 102801D7 (Dell XPS M1210)
1856*/
Takashi Iwai2b635362011-05-02 12:33:43 +02001857static const unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001858 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1859 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001860 0x508003f3, 0x405003f4,
1861};
1862
Takashi Iwai2b635362011-05-02 12:33:43 +02001863static const unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001864 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001865 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1866 0x02a19120, 0x40000100,
1867};
1868
Takashi Iwai2b635362011-05-02 12:33:43 +02001869static const unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001870 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1871 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001872 0x02a19320, 0x40000100,
1873};
1874
Takashi Iwai2b635362011-05-02 12:33:43 +02001875static const unsigned int intel_mac_v1_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001876 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1877 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001878 0x400000fc, 0x400000fb,
1879};
1880
Takashi Iwai2b635362011-05-02 12:33:43 +02001881static const unsigned int intel_mac_v2_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001882 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1883 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001884 0x400000fc, 0x400000fb,
1885};
1886
Takashi Iwai2b635362011-05-02 12:33:43 +02001887static const unsigned int intel_mac_v3_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001888 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1889 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1890 0x400000fc, 0x400000fb,
1891};
1892
Takashi Iwai2b635362011-05-02 12:33:43 +02001893static const unsigned int intel_mac_v4_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001894 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1895 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1896 0x400000fc, 0x400000fb,
1897};
1898
Takashi Iwai2b635362011-05-02 12:33:43 +02001899static const unsigned int intel_mac_v5_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001900 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1901 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1902 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001903};
1904
Takashi Iwai2b635362011-05-02 12:33:43 +02001905static const unsigned int ecs202_pin_configs[10] = {
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001906 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1907 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1908 0x9037012e, 0x40e000f2,
1909};
Takashi Iwai76c08822007-06-19 12:17:42 +02001910
Takashi Iwai2b635362011-05-02 12:33:43 +02001911static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001912 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001913 [STAC_D945GTP3] = d945gtp3_pin_configs,
1914 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001915 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1916 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1917 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1918 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1919 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001920 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001921 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001922 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1923 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1924 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1925 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1926 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1927 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001928 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001929 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1930 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1931 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1932 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001933};
1934
Takashi Iwaiea734962011-01-17 11:29:34 +01001935static const char * const stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001936 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001937 [STAC_D945_REF] = "ref",
1938 [STAC_D945GTP5] = "5stack",
1939 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001940 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1941 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1942 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1943 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1944 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001945 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001946 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001947 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001948 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001949 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1950 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001951 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001952 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001953 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001954 [STAC_922X_DELL_D81] = "dell-d81",
1955 [STAC_922X_DELL_D82] = "dell-d82",
1956 [STAC_922X_DELL_M81] = "dell-m81",
1957 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001958};
1959
Takashi Iwai2b635362011-05-02 12:33:43 +02001960static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001961 /* SigmaTel reference board */
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1963 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001964 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1965 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001966 /* Intel 945G based systems */
1967 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1968 "Intel D945G", STAC_D945GTP3),
1969 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1970 "Intel D945G", STAC_D945GTP3),
1971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1972 "Intel D945G", STAC_D945GTP3),
1973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1974 "Intel D945G", STAC_D945GTP3),
1975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1976 "Intel D945G", STAC_D945GTP3),
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1978 "Intel D945G", STAC_D945GTP3),
1979 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1980 "Intel D945G", STAC_D945GTP3),
1981 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1982 "Intel D945G", STAC_D945GTP3),
1983 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1984 "Intel D945G", STAC_D945GTP3),
1985 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1986 "Intel D945G", STAC_D945GTP3),
1987 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1988 "Intel D945G", STAC_D945GTP3),
1989 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1990 "Intel D945G", STAC_D945GTP3),
1991 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1992 "Intel D945G", STAC_D945GTP3),
1993 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1994 "Intel D945G", STAC_D945GTP3),
1995 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1996 "Intel D945G", STAC_D945GTP3),
1997 /* Intel D945G 5-stack systems */
1998 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1999 "Intel D945G", STAC_D945GTP5),
2000 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2001 "Intel D945G", STAC_D945GTP5),
2002 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2003 "Intel D945G", STAC_D945GTP5),
2004 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2005 "Intel D945G", STAC_D945GTP5),
2006 /* Intel 945P based systems */
2007 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2008 "Intel D945P", STAC_D945GTP3),
2009 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2010 "Intel D945P", STAC_D945GTP3),
2011 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2012 "Intel D945P", STAC_D945GTP3),
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2014 "Intel D945P", STAC_D945GTP3),
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2016 "Intel D945P", STAC_D945GTP3),
2017 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2018 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002019 /* other intel */
2020 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2021 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002022 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002023 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002024 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002025 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002026 /* Dell systems */
2027 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2028 "unknown Dell", STAC_922X_DELL_D81),
2029 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2030 "unknown Dell", STAC_922X_DELL_D81),
2031 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2032 "unknown Dell", STAC_922X_DELL_D81),
2033 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2034 "unknown Dell", STAC_922X_DELL_D82),
2035 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2036 "unknown Dell", STAC_922X_DELL_M81),
2037 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2038 "unknown Dell", STAC_922X_DELL_D82),
2039 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2040 "unknown Dell", STAC_922X_DELL_D81),
2041 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2042 "unknown Dell", STAC_922X_DELL_D81),
2043 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2044 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002045 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002046 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002047 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002048 {} /* terminator */
2049};
2050
Takashi Iwai2b635362011-05-02 12:33:43 +02002051static const unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002052 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2053 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2054 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2055 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002056};
2057
Takashi Iwai2b635362011-05-02 12:33:43 +02002058static const unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002059 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2060 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2061 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2062 0x40000100, 0x40000100
2063};
2064
Takashi Iwai2b635362011-05-02 12:33:43 +02002065static const unsigned int d965_5st_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002066 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2067 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2068 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2069 0x40000100, 0x40000100
2070};
2071
Takashi Iwai2b635362011-05-02 12:33:43 +02002072static const unsigned int d965_5st_no_fp_pin_configs[14] = {
Takashi Iwai679d92e2009-05-24 19:00:08 +02002073 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2074 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2075 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2076 0x40000100, 0x40000100
2077};
2078
Takashi Iwai2b635362011-05-02 12:33:43 +02002079static const unsigned int dell_3st_pin_configs[14] = {
Tobin Davis4ff076e2007-08-07 11:48:12 +02002080 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2081 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002082 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002083 0x40c003fc, 0x40000100
2084};
2085
Takashi Iwai2b635362011-05-02 12:33:43 +02002086static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002087 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002088 [STAC_D965_REF] = ref927x_pin_configs,
2089 [STAC_D965_3ST] = d965_3st_pin_configs,
2090 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002091 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002092 [STAC_DELL_3ST] = dell_3st_pin_configs,
2093 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002094 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002095};
2096
Takashi Iwaiea734962011-01-17 11:29:34 +01002097static const char * const stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002098 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002099 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002100 [STAC_D965_REF] = "ref",
2101 [STAC_D965_3ST] = "3stack",
2102 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002103 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002104 [STAC_DELL_3ST] = "dell-3stack",
2105 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002106 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002107};
2108
Takashi Iwai2b635362011-05-02 12:33:43 +02002109static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002110 /* SigmaTel reference board */
2111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2112 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002113 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2114 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002115 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2117 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002118 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002119 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2120 "Intel D965", STAC_D965_3ST),
2121 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2122 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002123 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002124 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002125 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2126 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002127 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002128 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002129 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002130 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002131 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002132 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002133 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2134 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2135 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2136 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002137 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002138 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2139 "Intel D965", STAC_D965_5ST),
2140 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2141 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002142 /* volume-knob fixes */
2143 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002144 {} /* terminator */
2145};
2146
Takashi Iwai2b635362011-05-02 12:33:43 +02002147static const unsigned int ref9205_pin_configs[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +02002148 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002149 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002150 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002151};
2152
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002153/*
2154 STAC 9205 pin configs for
2155 102801F1
2156 102801F2
2157 102801FC
2158 102801FD
2159 10280204
2160 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002161 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002162 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002163*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002164static const unsigned int dell_9205_m42_pin_configs[12] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002165 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2166 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2167 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2168};
2169
2170/*
2171 STAC 9205 pin configs for
2172 102801F9
2173 102801FA
2174 102801FE
2175 102801FF (Dell Precision M4300)
2176 10280206
2177 10280200
2178 10280201
2179*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002180static const unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002181 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2182 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2183 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2184};
2185
Takashi Iwai2b635362011-05-02 12:33:43 +02002186static const unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002187 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2188 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2189 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2190};
2191
Takashi Iwai2b635362011-05-02 12:33:43 +02002192static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002193 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002194 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2195 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2196 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002197 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002198};
2199
Takashi Iwaiea734962011-01-17 11:29:34 +01002200static const char * const stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002201 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002202 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002203 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002204 [STAC_9205_DELL_M43] = "dell-m43",
2205 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002206 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002207};
2208
Takashi Iwai2b635362011-05-02 12:33:43 +02002209static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002210 /* SigmaTel reference board */
2211 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2212 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002213 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2214 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002215 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2216 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002217 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002218 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2219 "unknown Dell", STAC_9205_DELL_M42),
2220 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2221 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002222 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002223 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002224 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2225 "Dell Precision", STAC_9205_DELL_M43),
2226 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2227 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002228 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2229 "unknown Dell", STAC_9205_DELL_M42),
2230 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2231 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002232 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2233 "Dell Precision", STAC_9205_DELL_M43),
2234 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002235 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002236 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2237 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002238 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2239 "Dell Precision", STAC_9205_DELL_M43),
2240 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2241 "Dell Precision", STAC_9205_DELL_M43),
2242 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2243 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002244 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2245 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002246 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2247 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002248 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2249 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002250 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002251 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002252 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002253 {} /* terminator */
2254};
2255
Takashi Iwai330ee992009-02-20 14:33:36 +01002256static void stac92xx_set_config_regs(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002257 const unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002258{
2259 int i;
2260 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002261
Takashi Iwai330ee992009-02-20 14:33:36 +01002262 if (!pincfgs)
2263 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002264
Matthew Ranostay87d48362007-07-17 11:52:24 +02002265 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002266 if (spec->pin_nids[i] && pincfgs[i])
2267 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2268 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002269}
2270
Matt2f2f4252005-04-13 14:45:30 +02002271/*
2272 * Analog playback callbacks
2273 */
2274static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2275 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002276 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002277{
2278 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002279 if (spec->stream_delay)
2280 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002281 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2282 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002283}
2284
2285static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2286 struct hda_codec *codec,
2287 unsigned int stream_tag,
2288 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002289 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002290{
2291 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002292 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002293}
2294
2295static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2296 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002297 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002298{
2299 struct sigmatel_spec *spec = codec->spec;
2300 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2301}
2302
2303/*
Mattdabbed62005-06-14 10:19:34 +02002304 * Digital playback callbacks
2305 */
2306static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2307 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002308 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002309{
2310 struct sigmatel_spec *spec = codec->spec;
2311 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2312}
2313
2314static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2315 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002316 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002317{
2318 struct sigmatel_spec *spec = codec->spec;
2319 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2320}
2321
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002322static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2323 struct hda_codec *codec,
2324 unsigned int stream_tag,
2325 unsigned int format,
2326 struct snd_pcm_substream *substream)
2327{
2328 struct sigmatel_spec *spec = codec->spec;
2329 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2330 stream_tag, format, substream);
2331}
2332
Takashi Iwai9411e212009-02-13 11:32:28 +01002333static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2334 struct hda_codec *codec,
2335 struct snd_pcm_substream *substream)
2336{
2337 struct sigmatel_spec *spec = codec->spec;
2338 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2339}
2340
Mattdabbed62005-06-14 10:19:34 +02002341
2342/*
Matt2f2f4252005-04-13 14:45:30 +02002343 * Analog capture callbacks
2344 */
2345static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2346 struct hda_codec *codec,
2347 unsigned int stream_tag,
2348 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002349 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002350{
2351 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002352 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002353
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002354 if (spec->powerdown_adcs) {
2355 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002356 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002357 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2358 }
2359 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002360 return 0;
2361}
2362
2363static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2364 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002365 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002366{
2367 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002368 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002369
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002370 snd_hda_codec_cleanup_stream(codec, nid);
2371 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002372 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002373 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002374 return 0;
2375}
2376
Takashi Iwai2b635362011-05-02 12:33:43 +02002377static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
Mattdabbed62005-06-14 10:19:34 +02002378 .substreams = 1,
2379 .channels_min = 2,
2380 .channels_max = 2,
2381 /* NID is set in stac92xx_build_pcms */
2382 .ops = {
2383 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002384 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002385 .prepare = stac92xx_dig_playback_pcm_prepare,
2386 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002387 },
2388};
2389
Takashi Iwai2b635362011-05-02 12:33:43 +02002390static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
Mattdabbed62005-06-14 10:19:34 +02002391 .substreams = 1,
2392 .channels_min = 2,
2393 .channels_max = 2,
2394 /* NID is set in stac92xx_build_pcms */
2395};
2396
Takashi Iwai2b635362011-05-02 12:33:43 +02002397static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
Matt2f2f4252005-04-13 14:45:30 +02002398 .substreams = 1,
2399 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002400 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002401 .nid = 0x02, /* NID to query formats and rates */
2402 .ops = {
2403 .open = stac92xx_playback_pcm_open,
2404 .prepare = stac92xx_playback_pcm_prepare,
2405 .cleanup = stac92xx_playback_pcm_cleanup
2406 },
2407};
2408
Takashi Iwai2b635362011-05-02 12:33:43 +02002409static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002410 .substreams = 1,
2411 .channels_min = 2,
2412 .channels_max = 2,
2413 .nid = 0x06, /* NID to query formats and rates */
2414 .ops = {
2415 .open = stac92xx_playback_pcm_open,
2416 .prepare = stac92xx_playback_pcm_prepare,
2417 .cleanup = stac92xx_playback_pcm_cleanup
2418 },
2419};
2420
Takashi Iwai2b635362011-05-02 12:33:43 +02002421static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002422 .channels_min = 2,
2423 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002424 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002425 .ops = {
2426 .prepare = stac92xx_capture_pcm_prepare,
2427 .cleanup = stac92xx_capture_pcm_cleanup
2428 },
2429};
2430
2431static int stac92xx_build_pcms(struct hda_codec *codec)
2432{
2433 struct sigmatel_spec *spec = codec->spec;
2434 struct hda_pcm *info = spec->pcm_rec;
2435
2436 codec->num_pcms = 1;
2437 codec->pcm_info = info;
2438
Mattc7d4b2f2005-06-27 14:59:41 +02002439 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002440 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002441 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2442 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002443 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002444 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002445 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002446
2447 if (spec->alt_switch) {
2448 codec->num_pcms++;
2449 info++;
2450 info->name = "STAC92xx Analog Alt";
2451 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2452 }
Matt2f2f4252005-04-13 14:45:30 +02002453
Mattdabbed62005-06-14 10:19:34 +02002454 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2455 codec->num_pcms++;
2456 info++;
2457 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002458 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002459 if (spec->multiout.dig_out_nid) {
2460 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2461 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2462 }
2463 if (spec->dig_in_nid) {
2464 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2465 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2466 }
2467 }
2468
Matt2f2f4252005-04-13 14:45:30 +02002469 return 0;
2470}
2471
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002472static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2473 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002474{
Takashi Iwai1327a322009-03-23 13:07:47 +01002475 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002476 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2477 if (pincap & AC_PINCAP_VREF_100)
2478 return AC_PINCTL_VREF_100;
2479 if (pincap & AC_PINCAP_VREF_80)
2480 return AC_PINCTL_VREF_80;
2481 if (pincap & AC_PINCAP_VREF_50)
2482 return AC_PINCTL_VREF_50;
2483 if (pincap & AC_PINCAP_VREF_GRD)
2484 return AC_PINCTL_VREF_GRD;
2485 return 0;
2486}
2487
Matt Porter403d1942005-11-29 15:00:51 +01002488static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2489
2490{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002491 snd_hda_codec_write_cache(codec, nid, 0,
2492 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002493}
2494
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002495#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2496
2497static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2498 struct snd_ctl_elem_value *ucontrol)
2499{
2500 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2501 struct sigmatel_spec *spec = codec->spec;
2502
Takashi Iwaid7a89432008-11-12 09:48:04 +01002503 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002504 return 0;
2505}
2506
Takashi Iwai62558ce2009-07-29 14:23:09 +02002507static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002508
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002509static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2510 struct snd_ctl_elem_value *ucontrol)
2511{
2512 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2513 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002514 int nid = kcontrol->private_value;
2515
2516 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002517
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002518 /* check to be sure that the ports are up to date with
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002519 * switch changes
2520 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002521 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002522
2523 return 1;
2524}
2525
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002526static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2527 struct snd_ctl_elem_info *uinfo)
2528{
2529 int i;
Takashi Iwai2b635362011-05-02 12:33:43 +02002530 static const char * const texts[] = {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002531 "Mic In", "Line In", "Line Out"
2532 };
2533
2534 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2535 struct sigmatel_spec *spec = codec->spec;
2536 hda_nid_t nid = kcontrol->private_value;
2537
2538 if (nid == spec->mic_switch || nid == spec->line_switch)
2539 i = 3;
2540 else
2541 i = 2;
2542
2543 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2544 uinfo->value.enumerated.items = i;
2545 uinfo->count = 1;
2546 if (uinfo->value.enumerated.item >= i)
2547 uinfo->value.enumerated.item = i-1;
2548 strcpy(uinfo->value.enumerated.name,
2549 texts[uinfo->value.enumerated.item]);
2550
2551 return 0;
2552}
2553
2554static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2555 struct snd_ctl_elem_value *ucontrol)
2556{
2557 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2558 hda_nid_t nid = kcontrol->private_value;
2559 unsigned int vref = stac92xx_vref_get(codec, nid);
2560
2561 if (vref == stac92xx_get_default_vref(codec, nid))
2562 ucontrol->value.enumerated.item[0] = 0;
2563 else if (vref == AC_PINCTL_VREF_GRD)
2564 ucontrol->value.enumerated.item[0] = 1;
2565 else if (vref == AC_PINCTL_VREF_HIZ)
2566 ucontrol->value.enumerated.item[0] = 2;
2567
2568 return 0;
2569}
2570
2571static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2572 struct snd_ctl_elem_value *ucontrol)
2573{
2574 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2575 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002576 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002577 hda_nid_t nid = kcontrol->private_value;
2578
2579 if (ucontrol->value.enumerated.item[0] == 0)
2580 new_vref = stac92xx_get_default_vref(codec, nid);
2581 else if (ucontrol->value.enumerated.item[0] == 1)
2582 new_vref = AC_PINCTL_VREF_GRD;
2583 else if (ucontrol->value.enumerated.item[0] == 2)
2584 new_vref = AC_PINCTL_VREF_HIZ;
2585 else
2586 return 0;
2587
2588 if (new_vref != stac92xx_vref_get(codec, nid)) {
2589 error = stac92xx_vref_set(codec, nid, new_vref);
2590 return error;
2591 }
2592
2593 return 0;
2594}
2595
2596static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2597 struct snd_ctl_elem_info *uinfo)
2598{
Takashi Iwai2b635362011-05-02 12:33:43 +02002599 char *texts[2];
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002600 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2601 struct sigmatel_spec *spec = codec->spec;
2602
2603 if (kcontrol->private_value == spec->line_switch)
2604 texts[0] = "Line In";
2605 else
2606 texts[0] = "Mic In";
2607 texts[1] = "Line Out";
2608 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2609 uinfo->value.enumerated.items = 2;
2610 uinfo->count = 1;
2611
2612 if (uinfo->value.enumerated.item >= 2)
2613 uinfo->value.enumerated.item = 1;
2614 strcpy(uinfo->value.enumerated.name,
2615 texts[uinfo->value.enumerated.item]);
2616
2617 return 0;
2618}
Matt Porter403d1942005-11-29 15:00:51 +01002619
2620static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2621{
2622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2623 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002624 hda_nid_t nid = kcontrol->private_value;
2625 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002626
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002627 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002628 return 0;
2629}
2630
2631static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2632{
2633 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2634 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002635 hda_nid_t nid = kcontrol->private_value;
2636 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2637 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002638
2639 spec->io_switch[io_idx] = val;
2640
2641 if (val)
2642 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002643 else {
2644 unsigned int pinctl = AC_PINCTL_IN_EN;
2645 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002646 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002647 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2648 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002649
2650 /* check the auto-mute again: we need to mute/unmute the speaker
2651 * appropriately according to the pin direction
2652 */
2653 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002654 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002655
Matt Porter403d1942005-11-29 15:00:51 +01002656 return 1;
2657}
2658
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002659#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2660
2661static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2662 struct snd_ctl_elem_value *ucontrol)
2663{
2664 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2665 struct sigmatel_spec *spec = codec->spec;
2666
2667 ucontrol->value.integer.value[0] = spec->clfe_swap;
2668 return 0;
2669}
2670
2671static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2672 struct snd_ctl_elem_value *ucontrol)
2673{
2674 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2675 struct sigmatel_spec *spec = codec->spec;
2676 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002677 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002678
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002679 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002680 return 0;
2681
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002682 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002683
2684 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2685 spec->clfe_swap ? 0x4 : 0x0);
2686
2687 return 1;
2688}
2689
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002690#define STAC_CODEC_HP_SWITCH(xname) \
2691 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2692 .name = xname, \
2693 .index = 0, \
2694 .info = stac92xx_hp_switch_info, \
2695 .get = stac92xx_hp_switch_get, \
2696 .put = stac92xx_hp_switch_put, \
2697 }
2698
Matt Porter403d1942005-11-29 15:00:51 +01002699#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2700 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2701 .name = xname, \
2702 .index = 0, \
2703 .info = stac92xx_io_switch_info, \
2704 .get = stac92xx_io_switch_get, \
2705 .put = stac92xx_io_switch_put, \
2706 .private_value = xpval, \
2707 }
2708
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002709#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2710 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2711 .name = xname, \
2712 .index = 0, \
2713 .info = stac92xx_clfe_switch_info, \
2714 .get = stac92xx_clfe_switch_get, \
2715 .put = stac92xx_clfe_switch_put, \
2716 .private_value = xpval, \
2717 }
Matt Porter403d1942005-11-29 15:00:51 +01002718
Mattc7d4b2f2005-06-27 14:59:41 +02002719enum {
2720 STAC_CTL_WIDGET_VOL,
2721 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002722 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002723 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002724 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002725 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002726 STAC_CTL_WIDGET_CLFE_SWITCH,
2727 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002728};
2729
Takashi Iwai2b635362011-05-02 12:33:43 +02002730static const struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002731 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2732 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002733 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002734 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002735 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002736 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002737 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002738 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002739};
2740
2741/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002742static struct snd_kcontrol_new *
2743stac_control_new(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002744 const struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002745 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002746 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002747{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002748 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002749
Takashi Iwai603c4012008-07-30 15:01:44 +02002750 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2751 knew = snd_array_new(&spec->kctls);
2752 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002753 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002754 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002755 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002756 if (!knew->name) {
2757 /* roolback */
2758 memset(knew, 0, sizeof(*knew));
2759 spec->kctls.alloced--;
2760 return NULL;
2761 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002762 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002763 return knew;
2764}
2765
2766static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002767 const struct snd_kcontrol_new *ktemp,
Takashi Iwaie3c75962009-01-23 11:57:22 +01002768 int idx, const char *name,
2769 unsigned long val)
2770{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002771 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002772 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002773 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002774 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002775 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002776 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002777 return 0;
2778}
2779
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002780static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2781 int type, int idx, const char *name,
2782 unsigned long val)
2783{
2784 return stac92xx_add_control_temp(spec,
2785 &stac92xx_control_templates[type],
2786 idx, name, val);
2787}
2788
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002789
2790/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002791static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2792 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002793{
2794 return stac92xx_add_control_idx(spec, type, 0, name, val);
2795}
2796
Takashi Iwai2b635362011-05-02 12:33:43 +02002797static const struct snd_kcontrol_new stac_input_src_temp = {
Takashi Iwaie3c75962009-01-23 11:57:22 +01002798 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2799 .name = "Input Source",
2800 .info = stac92xx_mux_enum_info,
2801 .get = stac92xx_mux_enum_get,
2802 .put = stac92xx_mux_enum_put,
2803};
2804
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002805static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2806 hda_nid_t nid, int idx)
2807{
2808 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2809 int control = 0;
2810 struct sigmatel_spec *spec = codec->spec;
2811 char name[22];
2812
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002813 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002814 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2815 && nid == spec->line_switch)
2816 control = STAC_CTL_WIDGET_IO_SWITCH;
2817 else if (snd_hda_query_pin_caps(codec, nid)
2818 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2819 control = STAC_CTL_WIDGET_DC_BIAS;
2820 else if (nid == spec->mic_switch)
2821 control = STAC_CTL_WIDGET_IO_SWITCH;
2822 }
2823
2824 if (control) {
Takashi Iwai201e06f2011-11-16 15:33:26 +01002825 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
2826 name, sizeof(name), NULL);
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002827 return stac92xx_add_control(codec->spec, control,
2828 strcat(name, " Jack Mode"), nid);
2829 }
2830
2831 return 0;
2832}
2833
Takashi Iwaie3c75962009-01-23 11:57:22 +01002834static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2835{
2836 struct snd_kcontrol_new *knew;
2837 struct hda_input_mux *imux = &spec->private_imux;
2838
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002839 if (spec->auto_mic)
2840 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002841 if (!spec->num_adcs || imux->num_items <= 1)
2842 return 0; /* no need for input source control */
2843 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002844 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002845 if (!knew)
2846 return -ENOMEM;
2847 knew->count = spec->num_adcs;
2848 return 0;
2849}
2850
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002851/* check whether the line-input can be used as line-out */
2852static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002853{
2854 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002855 struct auto_pin_cfg *cfg = &spec->autocfg;
2856 hda_nid_t nid;
2857 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002858 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002859
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002860 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2861 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002862 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02002863 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002864 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01002865 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002866 if (pincap & AC_PINCAP_OUT)
2867 return nid;
2868 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002869 }
Matt Porter403d1942005-11-29 15:00:51 +01002870 return 0;
2871}
2872
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002873static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2874
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002875/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002876static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002877{
2878 struct sigmatel_spec *spec = codec->spec;
2879 struct auto_pin_cfg *cfg = &spec->autocfg;
2880 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02002881 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002882
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002883 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002884 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2885 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002886 for (i = 0; i < cfg->num_inputs; i++) {
2887 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02002888 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002889 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002890 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2891 /* some laptops have an internal analog microphone
2892 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002893 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002894 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002895 if (pincap & AC_PINCAP_OUT) {
2896 *dac = get_unassigned_dac(codec, nid);
2897 if (*dac)
2898 return nid;
2899 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002900 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002901 }
2902 return 0;
2903}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002904
2905static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2906{
2907 int i;
2908
2909 for (i = 0; i < spec->multiout.num_dacs; i++) {
2910 if (spec->multiout.dac_nids[i] == nid)
2911 return 1;
2912 }
2913
2914 return 0;
2915}
2916
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002917static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2918{
2919 int i;
2920 if (is_in_dac_nids(spec, nid))
2921 return 1;
2922 for (i = 0; i < spec->autocfg.hp_outs; i++)
2923 if (spec->hp_dacs[i] == nid)
2924 return 1;
2925 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2926 if (spec->speaker_dacs[i] == nid)
2927 return 1;
2928 return 0;
2929}
2930
2931static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2932{
2933 struct sigmatel_spec *spec = codec->spec;
David Henningsson48718ea2011-10-05 09:49:05 +02002934 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002935 int j, conn_len;
David Henningsson48718ea2011-10-05 09:49:05 +02002936 hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002937 unsigned int wcaps, wtype;
2938
2939 conn_len = snd_hda_get_connections(codec, nid, conn,
2940 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002941 /* 92HD88: trace back up the link of nids to find the DAC */
2942 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2943 != AC_WID_AUD_OUT)) {
2944 nid = conn[0];
2945 conn_len = snd_hda_get_connections(codec, nid, conn,
2946 HDA_MAX_CONNECTIONS);
2947 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002948 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002949 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002950 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002951 /* we check only analog outputs */
2952 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2953 continue;
2954 /* if this route has a free DAC, assign it */
2955 if (!check_all_dac_nids(spec, conn[j])) {
2956 if (conn_len > 1) {
2957 /* select this DAC in the pin's input mux */
2958 snd_hda_codec_write_cache(codec, nid, 0,
2959 AC_VERB_SET_CONNECT_SEL, j);
2960 }
2961 return conn[j];
2962 }
2963 }
David Henningsson48718ea2011-10-05 09:49:05 +02002964
2965 /* if all DACs are already assigned, connect to the primary DAC,
2966 unless we're assigning a secondary headphone */
2967 fallback_dac = spec->multiout.dac_nids[0];
2968 if (spec->multiout.hp_nid) {
2969 for (j = 0; j < cfg->hp_outs; j++)
2970 if (cfg->hp_pins[j] == nid) {
2971 fallback_dac = spec->multiout.hp_nid;
2972 break;
2973 }
2974 }
2975
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002976 if (conn_len > 1) {
2977 for (j = 0; j < conn_len; j++) {
David Henningsson48718ea2011-10-05 09:49:05 +02002978 if (conn[j] == fallback_dac) {
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002979 snd_hda_codec_write_cache(codec, nid, 0,
2980 AC_VERB_SET_CONNECT_SEL, j);
2981 break;
2982 }
2983 }
2984 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002985 return 0;
2986}
2987
2988static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2989static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2990
Matt Porter3cc08dc2006-01-23 15:27:49 +01002991/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002992 * Fill in the dac_nids table from the parsed pin configuration
2993 * This function only works when every pin in line_out_pins[]
2994 * contains atleast one DAC in its connection list. Some 92xx
2995 * codecs are not connected directly to a DAC, such as the 9200
2996 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002997 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002998static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002999{
3000 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003001 struct auto_pin_cfg *cfg = &spec->autocfg;
3002 int i;
3003 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02003004
Mattc7d4b2f2005-06-27 14:59:41 +02003005 for (i = 0; i < cfg->line_outs; i++) {
3006 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003007 dac = get_unassigned_dac(codec, nid);
3008 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003009 if (spec->multiout.num_dacs > 0) {
3010 /* we have already working output pins,
3011 * so let's drop the broken ones again
3012 */
3013 cfg->line_outs = spec->multiout.num_dacs;
3014 break;
3015 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003016 /* error out, no available DAC found */
3017 snd_printk(KERN_ERR
3018 "%s: No available DAC for pin 0x%x\n",
3019 __func__, nid);
3020 return -ENODEV;
3021 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003022 add_spec_dacs(spec, dac);
3023 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003024
Takashi Iwai139e0712009-03-06 12:10:41 +01003025 for (i = 0; i < cfg->hp_outs; i++) {
3026 nid = cfg->hp_pins[i];
3027 dac = get_unassigned_dac(codec, nid);
3028 if (dac) {
3029 if (!spec->multiout.hp_nid)
3030 spec->multiout.hp_nid = dac;
3031 else
3032 add_spec_extra_dacs(spec, dac);
3033 }
3034 spec->hp_dacs[i] = dac;
3035 }
3036
3037 for (i = 0; i < cfg->speaker_outs; i++) {
3038 nid = cfg->speaker_pins[i];
3039 dac = get_unassigned_dac(codec, nid);
3040 if (dac)
3041 add_spec_extra_dacs(spec, dac);
3042 spec->speaker_dacs[i] = dac;
3043 }
3044
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003045 /* add line-in as output */
3046 nid = check_line_out_switch(codec);
3047 if (nid) {
3048 dac = get_unassigned_dac(codec, nid);
3049 if (dac) {
3050 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3051 nid, cfg->line_outs);
3052 cfg->line_out_pins[cfg->line_outs] = nid;
3053 cfg->line_outs++;
3054 spec->line_switch = nid;
3055 add_spec_dacs(spec, dac);
3056 }
3057 }
3058 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003059 nid = check_mic_out_switch(codec, &dac);
3060 if (nid && dac) {
3061 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3062 nid, cfg->line_outs);
3063 cfg->line_out_pins[cfg->line_outs] = nid;
3064 cfg->line_outs++;
3065 spec->mic_switch = nid;
3066 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003067 }
3068
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003069 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003070 spec->multiout.num_dacs,
3071 spec->multiout.dac_nids[0],
3072 spec->multiout.dac_nids[1],
3073 spec->multiout.dac_nids[2],
3074 spec->multiout.dac_nids[3],
3075 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003076
Mattc7d4b2f2005-06-27 14:59:41 +02003077 return 0;
3078}
3079
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003080/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003081static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3082 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003083{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003084 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003085 char name[32];
3086 int err;
3087
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003088 if (!spec->check_volume_offset) {
3089 unsigned int caps, step, nums, db_scale;
3090 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3091 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3092 AC_AMPCAP_STEP_SIZE_SHIFT;
3093 step = (step + 1) * 25; /* in .01dB unit */
3094 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3095 AC_AMPCAP_NUM_STEPS_SHIFT;
3096 db_scale = nums * step;
3097 /* if dB scale is over -64dB, and finer enough,
3098 * let's reduce it to half
3099 */
3100 if (db_scale > 6400 && nums >= 0x1f)
3101 spec->volume_offset = nums / 2;
3102 spec->check_volume_offset = 1;
3103 }
3104
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003105 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003106 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003107 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3108 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003109 if (err < 0)
3110 return err;
3111 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003112 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003113 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3114 if (err < 0)
3115 return err;
3116 return 0;
3117}
3118
Takashi Iwai668b9652009-03-06 10:13:24 +01003119#define create_controls(codec, pfx, nid, chs) \
3120 create_controls_idx(codec, pfx, 0, nid, chs)
3121
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003122static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3123{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003124 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003125 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3126 return 1;
3127 } else {
Takashi Iwaidda14412011-05-02 11:29:30 +02003128 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3129 spec->dac_nids[spec->multiout.num_dacs] = nid;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003130 spec->multiout.num_dacs++;
3131 }
3132 return 0;
3133}
3134
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003135static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003136{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003137 int i;
3138 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3139 if (!spec->multiout.extra_out_nid[i]) {
3140 spec->multiout.extra_out_nid[i] = nid;
3141 return 0;
3142 }
3143 }
3144 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3145 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003146}
3147
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003148/* Create output controls
3149 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3150 */
3151static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3152 const hda_nid_t *pins,
3153 const hda_nid_t *dac_nids,
3154 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003155{
Takashi Iwai76624532008-12-19 10:09:47 +01003156 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaiea734962011-01-17 11:29:34 +01003157 static const char * const chname[4] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02003158 "Front", "Surround", NULL /*CLFE*/, "Side"
3159 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003160 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003161 int i, err;
3162 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003163
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003164 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003165 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003166 if (is_jack_detectable(codec, pins[i]))
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003167 spec->hp_detect = 1;
3168 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003169 nid = dac_nids[i];
3170 if (!nid)
3171 continue;
3172 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003173 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003174 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003175 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003176 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003177 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003178 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003179 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003180
3181 wid_caps = get_wcaps(codec, nid);
3182
3183 if (wid_caps & AC_WCAP_LR_SWAP) {
3184 err = stac92xx_add_control(spec,
3185 STAC_CTL_WIDGET_CLFE_SWITCH,
3186 "Swap Center/LFE Playback Switch", nid);
3187
3188 if (err < 0)
3189 return err;
3190 }
3191
Mattc7d4b2f2005-06-27 14:59:41 +02003192 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003193 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003194 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003195 switch (type) {
3196 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003197 name = "Headphone";
3198 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003199 break;
3200 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003201 name = "Speaker";
3202 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003203 break;
3204 default:
3205 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003206 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003207 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003208 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003209 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003210 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003211 return err;
3212 }
3213 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003214 return 0;
3215}
3216
Takashi Iwai6479c632009-07-28 18:20:25 +02003217static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3218 unsigned long sw, int idx)
3219{
3220 int err;
3221 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003222 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003223 if (err < 0)
3224 return err;
3225 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003226 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003227 if (err < 0)
3228 return err;
3229 return 0;
3230}
3231
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003232/* add playback controls from the parsed DAC table */
3233static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3234 const struct auto_pin_cfg *cfg)
3235{
3236 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003237 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003238 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003239 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003240
3241 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3242 spec->multiout.dac_nids,
3243 cfg->line_out_type);
3244 if (err < 0)
3245 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003246
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003247 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003248 err = stac92xx_add_control(spec,
3249 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003250 "Headphone as Line Out Switch",
3251 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003252 if (err < 0)
3253 return err;
3254 }
3255
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003256 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003257 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003258 break;
3259 nid = cfg->inputs[idx].pin;
3260 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3261 if (err < 0)
3262 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003263 }
Matt Porter403d1942005-11-29 15:00:51 +01003264
Mattc7d4b2f2005-06-27 14:59:41 +02003265 return 0;
3266}
3267
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003268/* add playback controls for Speaker and HP outputs */
3269static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3270 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003271{
3272 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003273 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003274
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003275 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3276 spec->hp_dacs, AUTO_PIN_HP_OUT);
3277 if (err < 0)
3278 return err;
3279
3280 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3281 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3282 if (err < 0)
3283 return err;
3284
Mattc7d4b2f2005-06-27 14:59:41 +02003285 return 0;
3286}
3287
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003288/* labels for mono mux outputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003289static const char * const stac92xx_mono_labels[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003290 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003291};
3292
3293/* create mono mux for mono out on capable codecs */
3294static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3295{
3296 struct sigmatel_spec *spec = codec->spec;
3297 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3298 int i, num_cons;
3299 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3300
3301 num_cons = snd_hda_get_connections(codec,
3302 spec->mono_nid,
3303 con_lst,
3304 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003305 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003306 return -EINVAL;
3307
Takashi Iwai10a20af2010-09-09 16:28:02 +02003308 for (i = 0; i < num_cons; i++)
3309 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3310 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003311
3312 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3313 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003314}
3315
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003316/* create PC beep volume controls */
3317static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3318 hda_nid_t nid)
3319{
3320 struct sigmatel_spec *spec = codec->spec;
3321 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003322 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3323
3324 if (spec->anabeep_nid == nid)
3325 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003326
3327 /* check for mute support for the the amp */
3328 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003329 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003330 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003331 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3332 if (err < 0)
3333 return err;
3334 }
3335
3336 /* check to see if there is volume support for the amp */
3337 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3338 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003339 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003340 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3341 if (err < 0)
3342 return err;
3343 }
3344 return 0;
3345}
3346
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003347#ifdef CONFIG_SND_HDA_INPUT_BEEP
3348#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3349
3350static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3351 struct snd_ctl_elem_value *ucontrol)
3352{
3353 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3354 ucontrol->value.integer.value[0] = codec->beep->enabled;
3355 return 0;
3356}
3357
3358static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3359 struct snd_ctl_elem_value *ucontrol)
3360{
3361 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003362 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003363}
3364
Takashi Iwai2b635362011-05-02 12:33:43 +02003365static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003366 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3367 .info = stac92xx_dig_beep_switch_info,
3368 .get = stac92xx_dig_beep_switch_get,
3369 .put = stac92xx_dig_beep_switch_put,
3370};
3371
3372static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3373{
3374 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003375 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003376}
3377#endif
3378
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003379static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3380{
3381 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003382 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003383
3384 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003385 hda_nid_t nid;
3386 unsigned int wcaps;
3387 unsigned long val;
3388
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003389 nid = spec->mux_nids[i];
3390 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003391 if (!(wcaps & AC_WCAP_OUT_AMP))
3392 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003393
Takashi Iwai667067d2009-08-13 18:14:42 +02003394 /* check whether already the same control was created as
3395 * normal Capture Volume.
3396 */
3397 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3398 for (j = 0; j < spec->num_caps; j++) {
3399 if (spec->capvols[j] == val)
3400 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003401 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003402 if (j < spec->num_caps)
3403 continue;
3404
3405 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3406 "Mux Capture Volume", val);
3407 if (err < 0)
3408 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003409 }
3410 return 0;
3411};
3412
Takashi Iwaiea734962011-01-17 11:29:34 +01003413static const char * const stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003414 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003415};
3416
3417static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3418{
3419 struct sigmatel_spec *spec = codec->spec;
3420 struct hda_input_mux *spdif_mux = &spec->private_smux;
Takashi Iwaiea734962011-01-17 11:29:34 +01003421 const char * const *labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003422 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003423 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003424
3425 num_cons = snd_hda_get_connections(codec,
3426 spec->smux_nids[0],
3427 con_lst,
3428 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003429 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003430 return -EINVAL;
3431
Matthew Ranostay65973632008-09-16 10:39:37 -04003432 if (!labels)
3433 labels = stac92xx_spdif_labels;
3434
Takashi Iwai10a20af2010-09-09 16:28:02 +02003435 for (i = 0; i < num_cons; i++)
3436 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003437
3438 return 0;
3439}
3440
Matt Porter8b657272006-10-26 17:12:59 +02003441/* labels for dmic mux inputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003442static const char * const stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003443 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3444 "Digital Mic 3", "Digital Mic 4"
3445};
3446
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003447static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3448 int idx)
3449{
3450 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3451 int nums;
3452 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3453 if (idx >= 0 && idx < nums)
3454 return conn[idx];
3455 return 0;
3456}
3457
Takashi Iwai8d087c72011-06-28 12:45:47 +02003458/* look for NID recursively */
3459#define get_connection_index(codec, mux, nid) \
3460 snd_hda_get_conn_index(codec, mux, nid, 1)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003461
Takashi Iwai667067d2009-08-13 18:14:42 +02003462/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003463/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003464static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003465 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003466{
3467 unsigned int caps, nums;
3468 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003469 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003470
Takashi Iwai96f845d2009-08-29 00:49:36 +02003471 if (direction == HDA_OUTPUT)
3472 caps = AC_WCAP_OUT_AMP;
3473 else
3474 caps = AC_WCAP_IN_AMP;
3475 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003476 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003477 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003478 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3479 if (!nums)
3480 return 0;
3481 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003482 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3483 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003484 if (err < 0)
3485 return err;
3486 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003487}
3488
Matt Porter8b657272006-10-26 17:12:59 +02003489/* create playback/capture controls for input pins on dmic capable codecs */
3490static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3491 const struct auto_pin_cfg *cfg)
3492{
3493 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003494 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003495 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003496 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003497 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003498
Takashi Iwai10a20af2010-09-09 16:28:02 +02003499 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003500
Matt Porter8b657272006-10-26 17:12:59 +02003501 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003502 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003503 int index, type_idx;
Takashi Iwai201e06f2011-11-16 15:33:26 +01003504 char label[32];
Matt Porter8b657272006-10-26 17:12:59 +02003505
Takashi Iwai667067d2009-08-13 18:14:42 +02003506 nid = spec->dmic_nids[i];
3507 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3508 continue;
3509 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003510 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3511 continue;
3512
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003513 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3514 if (index < 0)
3515 continue;
3516
Takashi Iwai201e06f2011-11-16 15:33:26 +01003517 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
3518 label, sizeof(label), NULL);
Takashi Iwai10a20af2010-09-09 16:28:02 +02003519 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai2d7ec122010-12-23 10:16:05 +01003520 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3521 snd_hda_add_imux_item(imux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003522
Takashi Iwai10a20af2010-09-09 16:28:02 +02003523 err = create_elem_capture_vol(codec, nid, label, type_idx,
3524 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003525 if (err < 0)
3526 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003527 if (!err) {
3528 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003529 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003530 if (err < 0)
3531 return err;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003532 if (!err) {
3533 nid = get_connected_node(codec,
3534 spec->dmux_nids[0], index);
3535 if (nid)
3536 err = create_elem_capture_vol(codec,
3537 nid, label,
3538 type_idx, HDA_INPUT);
3539 if (err < 0)
3540 return err;
3541 }
Takashi Iwai96f845d2009-08-29 00:49:36 +02003542 }
Matt Porter8b657272006-10-26 17:12:59 +02003543 }
3544
3545 return 0;
3546}
3547
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003548static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003549 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003550{
3551 unsigned int cfg;
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003552 unsigned int type;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003553
3554 if (!nid)
3555 return 0;
3556 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003557 type = get_defcfg_device(cfg);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003558 switch (snd_hda_get_input_pin_attr(cfg)) {
3559 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003560 if (*fixed)
3561 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003562 if (type != AC_JACK_MIC_IN)
3563 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003564 *fixed = nid;
3565 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003566 case INPUT_PIN_ATTR_UNUSED:
3567 break;
3568 case INPUT_PIN_ATTR_DOCK:
3569 if (*dock)
3570 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003571 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
3572 return 1; /* invalid type */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003573 *dock = nid;
3574 break;
3575 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003576 if (*ext)
3577 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003578 if (type != AC_JACK_MIC_IN)
3579 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003580 *ext = nid;
3581 break;
3582 }
3583 return 0;
3584}
3585
3586static int set_mic_route(struct hda_codec *codec,
3587 struct sigmatel_mic_route *mic,
3588 hda_nid_t pin)
3589{
3590 struct sigmatel_spec *spec = codec->spec;
3591 struct auto_pin_cfg *cfg = &spec->autocfg;
3592 int i;
3593
3594 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003595 if (pin == 0)
3596 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003597 for (i = 0; i < cfg->num_inputs; i++) {
3598 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003599 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003600 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003601 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003602 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003603 i = get_connection_index(codec, spec->mux_nids[0], pin);
3604 if (i < 0)
3605 return -1;
3606 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003607 mic->dmux_idx = -1;
3608 if (spec->dmux_nids)
3609 mic->dmux_idx = get_connection_index(codec,
3610 spec->dmux_nids[0],
3611 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003612 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003613 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003614 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3615 if (i < 0)
3616 return -1;
3617 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003618 mic->mux_idx = -1;
3619 if (spec->mux_nids)
3620 mic->mux_idx = get_connection_index(codec,
3621 spec->mux_nids[0],
3622 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003623 }
3624 return 0;
3625}
3626
3627/* return non-zero if the device is for automatic mic switch */
3628static int stac_check_auto_mic(struct hda_codec *codec)
3629{
3630 struct sigmatel_spec *spec = codec->spec;
3631 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02003632 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003633 int i;
3634
Charles Chin99077902010-09-17 10:22:32 +02003635 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003636 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02003637 if (check_mic_pin(codec, cfg->inputs[i].pin,
3638 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003639 return 0;
3640 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02003641 if (check_mic_pin(codec, spec->dmic_nids[i],
3642 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003643 return 0;
Takashi Iwai80c67852011-01-13 08:08:08 +01003644 if (!fixed || (!ext && !dock))
Charles Chin99077902010-09-17 10:22:32 +02003645 return 0; /* no input to switch */
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003646 if (!is_jack_detectable(codec, ext))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003647 return 0; /* no unsol support */
3648 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02003649 set_mic_route(codec, &spec->int_mic, fixed) ||
3650 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003651 return 0; /* something is wrong */
3652 return 1;
3653}
3654
Mattc7d4b2f2005-06-27 14:59:41 +02003655/* create playback/capture controls for input pins */
3656static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3657{
3658 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003659 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003660 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003661 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02003662
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003663 for (i = 0; i < cfg->num_inputs; i++) {
3664 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003665 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02003666
Takashi Iwai314634b2006-09-21 11:56:18 +02003667 index = -1;
3668 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003669 index = get_connection_index(codec, spec->mux_nids[j],
3670 nid);
3671 if (index >= 0)
3672 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003673 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003674 if (index < 0)
3675 continue;
3676
Takashi Iwai10a20af2010-09-09 16:28:02 +02003677 label = hda_get_autocfg_input_label(codec, cfg, i);
3678 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003679
Takashi Iwai667067d2009-08-13 18:14:42 +02003680 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003681 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003682 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003683 if (err < 0)
3684 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003685 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003686 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003687
Steve Longerbeam7b043892007-05-03 20:50:03 +02003688 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003689 /*
3690 * Set the current input for the muxes.
3691 * The STAC9221 has two input muxes with identical source
3692 * NID lists. Hopefully this won't get confused.
3693 */
3694 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003695 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3696 AC_VERB_SET_CONNECT_SEL,
3697 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003698 }
3699 }
3700
Mattc7d4b2f2005-06-27 14:59:41 +02003701 return 0;
3702}
3703
Mattc7d4b2f2005-06-27 14:59:41 +02003704static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3705{
3706 struct sigmatel_spec *spec = codec->spec;
3707 int i;
3708
3709 for (i = 0; i < spec->autocfg.line_outs; i++) {
3710 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3711 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3712 }
3713}
3714
3715static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3716{
3717 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003718 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003719
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003720 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3721 hda_nid_t pin;
3722 pin = spec->autocfg.hp_pins[i];
3723 if (pin) /* connect to front */
3724 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3725 }
3726 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3727 hda_nid_t pin;
3728 pin = spec->autocfg.speaker_pins[i];
3729 if (pin) /* connect to front */
3730 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3731 }
Mattc7d4b2f2005-06-27 14:59:41 +02003732}
3733
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003734static int is_dual_headphones(struct hda_codec *codec)
3735{
3736 struct sigmatel_spec *spec = codec->spec;
3737 int i, valid_hps;
3738
3739 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3740 spec->autocfg.hp_outs <= 1)
3741 return 0;
3742 valid_hps = 0;
3743 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3744 hda_nid_t nid = spec->autocfg.hp_pins[i];
3745 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3746 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3747 continue;
3748 valid_hps++;
3749 }
3750 return (valid_hps > 1);
3751}
3752
3753
Charles Chin9009b0e2011-11-03 10:27:27 +01003754static int stac92xx_parse_auto_config(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003755{
3756 struct sigmatel_spec *spec = codec->spec;
Charles Chin9009b0e2011-11-03 10:27:27 +01003757 hda_nid_t dig_out = 0, dig_in = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003758 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003759 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003760
Matt Porter8b657272006-10-26 17:12:59 +02003761 if ((err = snd_hda_parse_pin_def_config(codec,
3762 &spec->autocfg,
3763 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003764 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003765 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003766 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003767
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003768 /* If we have no real line-out pin and multiple hp-outs, HPs should
3769 * be set up as multi-channel outputs.
3770 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003771 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003772 /* Copy hp_outs to line_outs, backup line_outs in
3773 * speaker_outs so that the following routines can handle
3774 * HP pins as primary outputs.
3775 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003776 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003777 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3778 sizeof(spec->autocfg.line_out_pins));
3779 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3780 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3781 sizeof(spec->autocfg.hp_pins));
3782 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003783 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3784 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003785 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003786 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003787 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003788 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3789 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003790 u32 caps = query_amp_caps(codec,
3791 spec->autocfg.mono_out_pin, dir);
3792 hda_nid_t conn_list[1];
3793
3794 /* get the mixer node and then the mono mux if it exists */
3795 if (snd_hda_get_connections(codec,
3796 spec->autocfg.mono_out_pin, conn_list, 1) &&
3797 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003798 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003799
3800 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003801 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003802 /* LR swap check, some stac925x have a mux that
3803 * changes the DACs output path instead of the
3804 * mono-mux path.
3805 */
3806 if (wid_type == AC_WID_AUD_SEL &&
3807 !(wcaps & AC_WCAP_LR_SWAP))
3808 spec->mono_nid = conn_list[0];
3809 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003810 if (dir) {
3811 hda_nid_t nid = spec->autocfg.mono_out_pin;
3812
3813 /* most mono outs have a least a mute/unmute switch */
3814 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3815 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3816 "Mono Playback Switch",
3817 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003818 if (err < 0)
3819 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003820 /* check for volume support for the amp */
3821 if ((caps & AC_AMPCAP_NUM_STEPS)
3822 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3823 err = stac92xx_add_control(spec,
3824 STAC_CTL_WIDGET_VOL,
3825 "Mono Playback Volume",
3826 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3827 if (err < 0)
3828 return err;
3829 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003830 }
3831
3832 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3833 AC_PINCTL_OUT_EN);
3834 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003835
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003836 if (!spec->multiout.num_dacs) {
3837 err = stac92xx_auto_fill_dac_nids(codec);
3838 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003839 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003840 err = stac92xx_auto_create_multi_out_ctls(codec,
3841 &spec->autocfg);
3842 if (err < 0)
3843 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003844 }
Mattc7d4b2f2005-06-27 14:59:41 +02003845
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003846 /* setup analog beep controls */
3847 if (spec->anabeep_nid > 0) {
3848 err = stac92xx_auto_create_beep_ctls(codec,
3849 spec->anabeep_nid);
3850 if (err < 0)
3851 return err;
3852 }
3853
3854 /* setup digital beep controls and input device */
3855#ifdef CONFIG_SND_HDA_INPUT_BEEP
3856 if (spec->digbeep_nid > 0) {
3857 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003858 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003859
3860 err = stac92xx_auto_create_beep_ctls(codec, nid);
3861 if (err < 0)
3862 return err;
3863 err = snd_hda_attach_beep_device(codec, nid);
3864 if (err < 0)
3865 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003866 if (codec->beep) {
3867 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01003868 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003869 /* if no beep switch is available, make its own one */
3870 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3871 if (!(caps & AC_AMPCAP_MUTE)) {
3872 err = stac92xx_beep_switch_ctl(codec);
3873 if (err < 0)
3874 return err;
3875 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003876 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003877 }
3878#endif
3879
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003880 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003881 if (err < 0)
3882 return err;
3883
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003884 /* All output parsing done, now restore the swapped hp pins */
3885 if (hp_swap) {
3886 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3887 sizeof(spec->autocfg.hp_pins));
3888 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3889 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3890 spec->autocfg.line_outs = 0;
3891 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003892
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003893 if (stac_check_auto_mic(codec)) {
3894 spec->auto_mic = 1;
3895 /* only one capture for auto-mic */
3896 spec->num_adcs = 1;
3897 spec->num_caps = 1;
3898 spec->num_muxes = 1;
3899 }
3900
Takashi Iwai6479c632009-07-28 18:20:25 +02003901 for (i = 0; i < spec->num_caps; i++) {
3902 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3903 spec->capsws[i], i);
3904 if (err < 0)
3905 return err;
3906 }
3907
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003908 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003909 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003910 return err;
3911
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003912 if (spec->mono_nid > 0) {
3913 err = stac92xx_auto_create_mono_output_ctls(codec);
3914 if (err < 0)
3915 return err;
3916 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003917 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003918 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3919 &spec->autocfg)) < 0)
3920 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003921 if (spec->num_muxes > 0) {
3922 err = stac92xx_auto_create_mux_input_ctls(codec);
3923 if (err < 0)
3924 return err;
3925 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003926 if (spec->num_smuxes > 0) {
3927 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3928 if (err < 0)
3929 return err;
3930 }
Matt Porter8b657272006-10-26 17:12:59 +02003931
Takashi Iwaie3c75962009-01-23 11:57:22 +01003932 err = stac92xx_add_input_source(spec);
3933 if (err < 0)
3934 return err;
3935
Mattc7d4b2f2005-06-27 14:59:41 +02003936 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003937 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003938 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003939
Charles Chin9009b0e2011-11-03 10:27:27 +01003940 /* find digital out and in converters */
3941 for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
3942 unsigned int wid_caps = get_wcaps(codec, i);
3943 if (wid_caps & AC_WCAP_DIGITAL) {
3944 switch (get_wcaps_type(wid_caps)) {
3945 case AC_WID_AUD_OUT:
3946 if (!dig_out)
3947 dig_out = i;
3948 break;
3949 case AC_WID_AUD_IN:
3950 if (!dig_in)
3951 dig_in = i;
3952 break;
3953 }
3954 }
3955 }
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003956 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003957 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003958 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003959 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003960
Takashi Iwai603c4012008-07-30 15:01:44 +02003961 if (spec->kctls.list)
3962 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003963
3964 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003965 if (!spec->dinput_mux)
3966 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003967 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003968 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003969 return 1;
3970}
3971
Takashi Iwai82bc9552006-03-21 11:24:42 +01003972/* add playback controls for HP output */
3973static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3974 struct auto_pin_cfg *cfg)
3975{
3976 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003977 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003978
3979 if (! pin)
3980 return 0;
3981
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003982 if (is_jack_detectable(codec, pin))
Takashi Iwai82bc9552006-03-21 11:24:42 +01003983 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003984
3985 return 0;
3986}
3987
Richard Fish160ea0d2006-09-06 13:58:25 +02003988/* add playback controls for LFE output */
3989static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3990 struct auto_pin_cfg *cfg)
3991{
3992 struct sigmatel_spec *spec = codec->spec;
3993 int err;
3994 hda_nid_t lfe_pin = 0x0;
3995 int i;
3996
3997 /*
3998 * search speaker outs and line outs for a mono speaker pin
3999 * with an amp. If one is found, add LFE controls
4000 * for it.
4001 */
4002 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4003 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004004 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004005 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4006 if (wcaps == AC_WCAP_OUT_AMP)
4007 /* found a mono speaker with an amp, must be lfe */
4008 lfe_pin = pin;
4009 }
4010
4011 /* if speaker_outs is 0, then speakers may be in line_outs */
4012 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4013 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4014 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004015 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004016 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004017 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004018 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004019 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4020 if (wcaps == AC_WCAP_OUT_AMP)
4021 /* found a mono speaker with an amp,
4022 must be lfe */
4023 lfe_pin = pin;
4024 }
4025 }
4026 }
4027
4028 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004029 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004030 if (err < 0)
4031 return err;
4032 }
4033
4034 return 0;
4035}
4036
Mattc7d4b2f2005-06-27 14:59:41 +02004037static int stac9200_parse_auto_config(struct hda_codec *codec)
4038{
4039 struct sigmatel_spec *spec = codec->spec;
4040 int err;
4041
Kailang Yangdf694da2005-12-05 19:42:22 +01004042 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004043 return err;
4044
4045 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4046 return err;
4047
Takashi Iwai82bc9552006-03-21 11:24:42 +01004048 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4049 return err;
4050
Richard Fish160ea0d2006-09-06 13:58:25 +02004051 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4052 return err;
4053
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004054 if (spec->num_muxes > 0) {
4055 err = stac92xx_auto_create_mux_input_ctls(codec);
4056 if (err < 0)
4057 return err;
4058 }
4059
Takashi Iwaie3c75962009-01-23 11:57:22 +01004060 err = stac92xx_add_input_source(spec);
4061 if (err < 0)
4062 return err;
4063
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004064 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004065 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004066 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004067 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004068
Takashi Iwai603c4012008-07-30 15:01:44 +02004069 if (spec->kctls.list)
4070 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004071
4072 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004073 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004074
4075 return 1;
4076}
4077
Sam Revitch62fe78e2006-05-10 15:09:17 +02004078/*
4079 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4080 * funky external mute control using GPIO pins.
4081 */
4082
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004083static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004084 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004085{
4086 unsigned int gpiostate, gpiomask, gpiodir;
4087
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004088 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4089
Sam Revitch62fe78e2006-05-10 15:09:17 +02004090 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4091 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004092 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004093
4094 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4095 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004096 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004097
4098 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4099 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004100 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004101
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004102 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004103 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4104
4105 snd_hda_codec_write(codec, codec->afg, 0,
4106 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004107 snd_hda_codec_read(codec, codec->afg, 0,
4108 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004109
4110 msleep(1);
4111
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004112 snd_hda_codec_read(codec, codec->afg, 0,
4113 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004114}
4115
Takashi Iwai3a938972011-10-28 01:16:55 +02004116static int stac_add_event(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004117 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004118{
Takashi Iwai3a938972011-10-28 01:16:55 +02004119 struct hda_jack_tbl *event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004120
Takashi Iwai3a938972011-10-28 01:16:55 +02004121 event = snd_hda_jack_tbl_new(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004122 if (!event)
4123 return -ENOMEM;
Takashi Iwai3a938972011-10-28 01:16:55 +02004124 event->action = type;
4125 event->private_data = data;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004126
Takashi Iwai3a938972011-10-28 01:16:55 +02004127 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004128}
4129
Takashi Iwai62558ce2009-07-29 14:23:09 +02004130/* check if given nid is a valid pin and no other events are assigned
4131 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4132 * Otherwise, returns zero.
4133 */
4134static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4135 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004136{
Takashi Iwai3a938972011-10-28 01:16:55 +02004137 struct hda_jack_tbl *event;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004138
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004139 if (!is_jack_detectable(codec, nid))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004140 return 0;
Takashi Iwai3a938972011-10-28 01:16:55 +02004141 event = snd_hda_jack_tbl_new(codec, nid);
4142 if (!event)
4143 return -ENOMEM;
4144 if (event->action && event->action != type)
4145 return 0;
4146 event->action = type;
4147 snd_hda_jack_detect_enable(codec, nid, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004148 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004149}
4150
Takashi Iwaib4ead012012-01-23 18:23:36 +01004151static int is_nid_out_jack_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004152{
4153 int i;
4154 for (i = 0; i < cfg->hp_outs; i++)
4155 if (cfg->hp_pins[i] == nid)
4156 return 1; /* nid is a HP-Out */
Takashi Iwaib4ead012012-01-23 18:23:36 +01004157 for (i = 0; i < cfg->line_outs; i++)
4158 if (cfg->line_out_pins[i] == nid)
4159 return 1; /* nid is a line-Out */
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004160 return 0; /* nid is not a HP-Out */
4161};
4162
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004163static void stac92xx_power_down(struct hda_codec *codec)
4164{
4165 struct sigmatel_spec *spec = codec->spec;
4166
4167 /* power down inactive DACs */
Takashi Iwai2b635362011-05-02 12:33:43 +02004168 const hda_nid_t *dac;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004169 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004170 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004171 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004172 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4173}
4174
Takashi Iwaif73d3582008-11-25 08:21:51 +01004175static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4176 int enable);
4177
Takashi Iwai014c41f2009-12-27 13:53:24 +01004178static inline int get_int_hint(struct hda_codec *codec, const char *key,
4179 int *valp)
4180{
4181 const char *p;
4182 p = snd_hda_get_hint(codec, key);
4183 if (p) {
4184 unsigned long val;
4185 if (!strict_strtoul(p, 0, &val)) {
4186 *valp = val;
4187 return 1;
4188 }
4189 }
4190 return 0;
4191}
4192
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004193/* override some hints from the hwdep entry */
4194static void stac_store_hints(struct hda_codec *codec)
4195{
4196 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004197 int val;
4198
4199 val = snd_hda_get_bool_hint(codec, "hp_detect");
4200 if (val >= 0)
4201 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004202 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004203 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4204 spec->gpio_mask;
4205 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004206 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4207 spec->gpio_mask &= spec->gpio_mask;
4208 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4209 spec->gpio_dir &= spec->gpio_mask;
4210 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4211 spec->eapd_mask &= spec->gpio_mask;
4212 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4213 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004214 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4215 if (val >= 0)
4216 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004217 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4218 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01004219 spec->gpio_mask |= spec->gpio_led;
4220 spec->gpio_dir |= spec->gpio_led;
4221 if (spec->gpio_led_polarity)
4222 spec->gpio_data |= spec->gpio_led;
Takashi Iwai043958e2009-12-26 10:36:12 +01004223 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004224}
4225
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004226static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins,
4227 const hda_nid_t *pins)
4228{
4229 while (num_pins--)
4230 stac_issue_unsol_event(codec, *pins++);
4231}
4232
4233/* fake event to set up pins */
4234static void stac_fake_hp_events(struct hda_codec *codec)
4235{
4236 struct sigmatel_spec *spec = codec->spec;
4237
4238 if (spec->autocfg.hp_outs)
4239 stac_issue_unsol_events(codec, spec->autocfg.hp_outs,
4240 spec->autocfg.hp_pins);
4241 if (spec->autocfg.line_outs &&
4242 spec->autocfg.line_out_pins[0] != spec->autocfg.hp_pins[0])
4243 stac_issue_unsol_events(codec, spec->autocfg.line_outs,
4244 spec->autocfg.line_out_pins);
4245}
4246
Mattc7d4b2f2005-06-27 14:59:41 +02004247static int stac92xx_init(struct hda_codec *codec)
4248{
4249 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004250 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004251 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004252 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004253
Mattc7d4b2f2005-06-27 14:59:41 +02004254 snd_hda_sequence_write(codec, spec->init);
4255
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004256 /* power down adcs initially */
4257 if (spec->powerdown_adcs)
4258 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004259 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004260 spec->adc_nids[i], 0,
4261 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004262
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004263 /* override some hints */
4264 stac_store_hints(codec);
4265
Takashi Iwaif73d3582008-11-25 08:21:51 +01004266 /* set up GPIO */
4267 gpio = spec->gpio_data;
4268 /* turn on EAPD statically when spec->eapd_switch isn't set.
4269 * otherwise, unsol event will turn it on/off dynamically
4270 */
4271 if (!spec->eapd_switch)
4272 gpio |= spec->eapd_mask;
4273 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4274
Takashi Iwai82bc9552006-03-21 11:24:42 +01004275 /* set up pins */
4276 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004277 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004278 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004279 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004280 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004281 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004282 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4283 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004284 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004285 for (i = 0; i < cfg->line_outs; i++) {
4286 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004287 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4288 }
4289 }
4290
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004291 /* force to enable the first line-out; the others are set up
4292 * in unsol_event
4293 */
4294 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004295 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004296 /* fake event to set up pins */
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004297 stac_fake_hp_events(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004298 } else {
4299 stac92xx_auto_init_multi_out(codec);
4300 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004301 for (i = 0; i < cfg->hp_outs; i++)
4302 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004303 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004304 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004305 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004306 if (spec->dmux_nids)
4307 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004308 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004309 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4310 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004311 if (enable_pin_detect(codec, spec->dock_mic.pin,
4312 STAC_MIC_EVENT))
4313 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004314 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004315 for (i = 0; i < cfg->num_inputs; i++) {
4316 hda_nid_t nid = cfg->inputs[i].pin;
4317 int type = cfg->inputs[i].type;
4318 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004319 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004320 /* for mic pins, force to initialize */
4321 pinctl = stac92xx_get_default_vref(codec, nid);
4322 pinctl |= AC_PINCTL_IN_EN;
4323 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4324 } else {
4325 pinctl = snd_hda_codec_read(codec, nid, 0,
4326 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4327 /* if PINCTL already set then skip */
4328 /* Also, if both INPUT and OUTPUT are set,
4329 * it must be a BIOS bug; need to override, too
4330 */
4331 if (!(pinctl & AC_PINCTL_IN_EN) ||
4332 (pinctl & AC_PINCTL_OUT_EN)) {
4333 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004334 pinctl |= AC_PINCTL_IN_EN;
4335 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004336 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004337 }
4338 conf = snd_hda_codec_get_pincfg(codec, nid);
4339 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4340 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4341 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004342 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004343 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004344 for (i = 0; i < spec->num_dmics; i++)
4345 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4346 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004347 if (cfg->dig_out_pins[0])
4348 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004349 AC_PINCTL_OUT_EN);
4350 if (cfg->dig_in_pin)
4351 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4352 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004353 for (i = 0; i < spec->num_pwrs; i++) {
4354 hda_nid_t nid = spec->pwr_nids[i];
4355 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004356
Takashi Iwaieb632122008-12-19 16:39:48 +01004357 /* power on when no jack detection is available */
Takashi Iwai542c9a02011-11-29 13:01:30 +01004358 /* or when the VREF is used for controlling LED */
4359 if (!spec->hp_detect ||
Takashi Iwaia0204282011-12-06 13:17:23 +01004360 spec->vref_mute_led_nid == nid) {
Takashi Iwaieb632122008-12-19 16:39:48 +01004361 stac_toggle_power_map(codec, nid, 1);
4362 continue;
4363 }
4364
Takashi Iwaib4ead012012-01-23 18:23:36 +01004365 if (is_nid_out_jack_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004366 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004367
Takashi Iwaif73d3582008-11-25 08:21:51 +01004368 pinctl = snd_hda_codec_read(codec, nid, 0,
4369 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4370 /* outputs are only ports capable of power management
4371 * any attempts on powering down a input port cause the
4372 * referenced VREF to act quirky.
4373 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004374 if (pinctl & AC_PINCTL_IN_EN) {
4375 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004376 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004377 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004378 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004379 def_conf = get_defcfg_connect(def_conf);
4380 /* skip any ports that don't have jacks since presence
4381 * detection is useless */
4382 if (def_conf != AC_JACK_PORT_COMPLEX) {
4383 if (def_conf != AC_JACK_PORT_NONE)
4384 stac_toggle_power_map(codec, nid, 1);
4385 continue;
4386 }
Charles Chinafef2cf2011-11-11 08:05:28 +01004387 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004388 stac_issue_unsol_event(codec, nid);
Charles Chinafef2cf2011-11-11 08:05:28 +01004389 continue;
4390 }
4391 /* none of the above, turn the port OFF */
4392 stac_toggle_power_map(codec, nid, 0);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004393 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004394
Takashi Iwai01a61e12011-10-28 00:03:22 +02004395 snd_hda_jack_report_sync(codec);
4396
Takashi Iwaic21bd022010-02-08 15:16:08 +01004397 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004398 if (spec->gpio_led)
4399 hda_call_check_power_status(codec, 0x01);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004400 if (spec->dac_list)
4401 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004402 return 0;
4403}
4404
Takashi Iwai603c4012008-07-30 15:01:44 +02004405static void stac92xx_free_kctls(struct hda_codec *codec)
4406{
4407 struct sigmatel_spec *spec = codec->spec;
4408
4409 if (spec->kctls.list) {
4410 struct snd_kcontrol_new *kctl = spec->kctls.list;
4411 int i;
4412 for (i = 0; i < spec->kctls.used; i++)
4413 kfree(kctl[i].name);
4414 }
4415 snd_array_free(&spec->kctls);
4416}
4417
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004418static void stac92xx_shutup_pins(struct hda_codec *codec)
4419{
4420 unsigned int i, def_conf;
4421
4422 if (codec->bus->shutdown)
4423 return;
4424 for (i = 0; i < codec->init_pins.used; i++) {
4425 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4426 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4427 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
4428 snd_hda_codec_write(codec, pin->nid, 0,
4429 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4430 }
4431}
4432
Takashi Iwai167eae52009-11-06 15:47:50 +01004433static void stac92xx_shutup(struct hda_codec *codec)
4434{
4435 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004436
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004437 stac92xx_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004438
4439 if (spec->eapd_mask)
4440 stac_gpio_set(codec, spec->gpio_mask,
4441 spec->gpio_dir, spec->gpio_data &
4442 ~spec->eapd_mask);
4443}
4444
Matt2f2f4252005-04-13 14:45:30 +02004445static void stac92xx_free(struct hda_codec *codec)
4446{
Mattc7d4b2f2005-06-27 14:59:41 +02004447 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004448
4449 if (! spec)
4450 return;
4451
Takashi Iwai167eae52009-11-06 15:47:50 +01004452 stac92xx_shutup(codec);
Richard Fish11b44bb2006-08-23 18:31:34 +02004453
Mattc7d4b2f2005-06-27 14:59:41 +02004454 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004455 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004456}
4457
Matt4e550962005-07-04 17:51:39 +02004458static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4459 unsigned int flag)
4460{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004461 unsigned int old_ctl, pin_ctl;
4462
4463 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004464 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004465
Takashi Iwaif9acba42007-05-29 18:01:06 +02004466 if (pin_ctl & AC_PINCTL_IN_EN) {
4467 /*
4468 * we need to check the current set-up direction of
4469 * shared input pins since they can be switched via
4470 * "xxx as Output" mixer switch
4471 */
4472 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004473 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004474 return;
4475 }
4476
Takashi Iwai8ce84192009-01-22 16:59:20 +01004477 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004478 /* if setting pin direction bits, clear the current
4479 direction bits first */
4480 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4481 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4482
Takashi Iwai8ce84192009-01-22 16:59:20 +01004483 pin_ctl |= flag;
4484 if (old_ctl != pin_ctl)
4485 snd_hda_codec_write_cache(codec, nid, 0,
4486 AC_VERB_SET_PIN_WIDGET_CONTROL,
4487 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004488}
4489
4490static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4491 unsigned int flag)
4492{
4493 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4494 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004495 if (pin_ctl & flag)
4496 snd_hda_codec_write_cache(codec, nid, 0,
4497 AC_VERB_SET_PIN_WIDGET_CONTROL,
4498 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004499}
4500
Takashi Iwaid56757a2009-11-18 08:00:14 +01004501static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004502{
4503 if (!nid)
4504 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004505 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004506}
4507
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004508static void stac92xx_line_out_detect(struct hda_codec *codec,
4509 int presence)
4510{
4511 struct sigmatel_spec *spec = codec->spec;
4512 struct auto_pin_cfg *cfg = &spec->autocfg;
4513 int i;
4514
4515 for (i = 0; i < cfg->line_outs; i++) {
4516 if (presence)
4517 break;
4518 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4519 if (presence) {
4520 unsigned int pinctl;
4521 pinctl = snd_hda_codec_read(codec,
4522 cfg->line_out_pins[i], 0,
4523 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4524 if (pinctl & AC_PINCTL_IN_EN)
4525 presence = 0; /* mic- or line-input */
4526 }
4527 }
4528
4529 if (presence) {
4530 /* disable speakers */
4531 for (i = 0; i < cfg->speaker_outs; i++)
4532 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4533 AC_PINCTL_OUT_EN);
4534 if (spec->eapd_mask && spec->eapd_switch)
4535 stac_gpio_set(codec, spec->gpio_mask,
4536 spec->gpio_dir, spec->gpio_data &
4537 ~spec->eapd_mask);
4538 } else {
4539 /* enable speakers */
4540 for (i = 0; i < cfg->speaker_outs; i++)
4541 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4542 AC_PINCTL_OUT_EN);
4543 if (spec->eapd_mask && spec->eapd_switch)
4544 stac_gpio_set(codec, spec->gpio_mask,
4545 spec->gpio_dir, spec->gpio_data |
4546 spec->eapd_mask);
4547 }
4548}
4549
Takashi Iwaid7a89432008-11-12 09:48:04 +01004550/* return non-zero if the hp-pin of the given array index isn't
4551 * a jack-detection target
4552 */
4553static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4554{
4555 struct auto_pin_cfg *cfg = &spec->autocfg;
4556
4557 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004558 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004559 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004560 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004561 return 1;
4562 /* ignore if the pin is set as line-out */
4563 if (cfg->hp_pins[i] == spec->hp_switch)
4564 return 1;
4565 return 0;
4566}
4567
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004568static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004569{
4570 struct sigmatel_spec *spec = codec->spec;
4571 struct auto_pin_cfg *cfg = &spec->autocfg;
4572 int i, presence;
4573
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004574 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004575 if (spec->gpio_mute)
4576 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4577 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4578
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004579 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004580 if (presence)
4581 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004582 if (no_hp_sensing(spec, i))
4583 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004584 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4585 if (presence) {
4586 unsigned int pinctl;
4587 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4588 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4589 if (pinctl & AC_PINCTL_IN_EN)
4590 presence = 0; /* mic- or line-input */
4591 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004592 }
Matt4e550962005-07-04 17:51:39 +02004593
4594 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004595 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004596 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004597 stac92xx_reset_pinctl(codec, spec->hp_switch,
4598 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004599 for (i = 0; i < cfg->line_outs; i++)
4600 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4601 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004602 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004603 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004604 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004605 stac92xx_set_pinctl(codec, spec->hp_switch,
4606 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004607 for (i = 0; i < cfg->line_outs; i++)
4608 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4609 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004610 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004611 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004612 /* toggle hp outs */
4613 for (i = 0; i < cfg->hp_outs; i++) {
4614 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4615 if (no_hp_sensing(spec, i))
4616 continue;
4617 if (presence)
4618 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004619#if 0 /* FIXME */
4620/* Resetting the pinctl like below may lead to (a sort of) regressions
4621 * on some devices since they use the HP pin actually for line/speaker
4622 * outs although the default pin config shows a different pin (that is
4623 * wrong and useless).
4624 *
4625 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4626 * But, disabling the code below just works around it, and I'm too tired of
4627 * bug reports with such devices...
4628 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004629 else
4630 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004631#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004632 }
Matt4e550962005-07-04 17:51:39 +02004633}
4634
Takashi Iwaif73d3582008-11-25 08:21:51 +01004635static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4636 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004637{
4638 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004639 unsigned int idx, val;
4640
4641 for (idx = 0; idx < spec->num_pwrs; idx++) {
4642 if (spec->pwr_nids[idx] == nid)
4643 break;
4644 }
4645 if (idx >= spec->num_pwrs)
4646 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004647
Charles Chinafef2cf2011-11-11 08:05:28 +01004648 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004649
Takashi Iwaif73d3582008-11-25 08:21:51 +01004650 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4651 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004652 val &= ~idx;
4653 else
4654 val |= idx;
4655
4656 /* power down unused output ports */
4657 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004658}
4659
Takashi Iwaif73d3582008-11-25 08:21:51 +01004660static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4661{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004662 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004663}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004664
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004665/* get the pin connection (fixed, none, etc) */
4666static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4667{
4668 struct sigmatel_spec *spec = codec->spec;
4669 unsigned int cfg;
4670
4671 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4672 return get_defcfg_connect(cfg);
4673}
4674
4675static int stac92xx_connected_ports(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02004676 const hda_nid_t *nids, int num_nids)
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004677{
4678 struct sigmatel_spec *spec = codec->spec;
4679 int idx, num;
4680 unsigned int def_conf;
4681
4682 for (num = 0; num < num_nids; num++) {
4683 for (idx = 0; idx < spec->num_pins; idx++)
4684 if (spec->pin_nids[idx] == nids[num])
4685 break;
4686 if (idx >= spec->num_pins)
4687 break;
4688 def_conf = stac_get_defcfg_connect(codec, idx);
4689 if (def_conf == AC_JACK_PORT_NONE)
4690 break;
4691 }
4692 return num;
4693}
4694
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004695static void stac92xx_mic_detect(struct hda_codec *codec)
4696{
4697 struct sigmatel_spec *spec = codec->spec;
4698 struct sigmatel_mic_route *mic;
4699
4700 if (get_pin_presence(codec, spec->ext_mic.pin))
4701 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02004702 else if (get_pin_presence(codec, spec->dock_mic.pin))
4703 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004704 else
4705 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004706 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004707 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4708 AC_VERB_SET_CONNECT_SEL,
4709 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004710 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004711 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4712 AC_VERB_SET_CONNECT_SEL,
4713 mic->mux_idx);
4714}
4715
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004716static void handle_unsol_event(struct hda_codec *codec,
Takashi Iwai3a938972011-10-28 01:16:55 +02004717 struct hda_jack_tbl *event)
Takashi Iwai314634b2006-09-21 11:56:18 +02004718{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004719 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004720 int data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004721
Takashi Iwai3a938972011-10-28 01:16:55 +02004722 switch (event->action) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004723 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004724 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004725 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004726 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004727 case STAC_MIC_EVENT:
4728 stac92xx_mic_detect(codec);
4729 break;
4730 }
4731
Takashi Iwai3a938972011-10-28 01:16:55 +02004732 switch (event->action) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004733 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004734 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004735 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004736 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004737 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004738 if (spec->num_pwrs > 0)
4739 stac92xx_pin_sense(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004740
4741 switch (codec->subsystem_id) {
4742 case 0x103c308f:
4743 if (event->nid == 0xb) {
4744 int pin = AC_PINCTL_IN_EN;
4745
4746 if (get_pin_presence(codec, 0xa)
4747 && get_pin_presence(codec, 0xb))
4748 pin |= AC_PINCTL_VREF_80;
4749 if (!get_pin_presence(codec, 0xb))
4750 pin |= AC_PINCTL_VREF_80;
4751
4752 /* toggle VREF state based on mic + hp pin
4753 * status
4754 */
4755 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4756 }
4757 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004758 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004759 case STAC_VREF_EVENT:
4760 data = snd_hda_codec_read(codec, codec->afg, 0,
4761 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004762 /* toggle VREF state based on GPIOx status */
4763 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwai3a938972011-10-28 01:16:55 +02004764 !!(data & (1 << event->private_data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004765 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004766 }
4767}
4768
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004769static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4770{
Takashi Iwai3a938972011-10-28 01:16:55 +02004771 struct hda_jack_tbl *event = snd_hda_jack_tbl_get(codec, nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004772 if (!event)
4773 return;
4774 handle_unsol_event(codec, event);
4775}
4776
4777static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4778{
Takashi Iwai3a938972011-10-28 01:16:55 +02004779 struct hda_jack_tbl *event;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004780 int tag;
4781
4782 tag = (res >> 26) & 0x7f;
Takashi Iwai3a938972011-10-28 01:16:55 +02004783 event = snd_hda_jack_tbl_get_from_tag(codec, tag);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004784 if (!event)
4785 return;
Takashi Iwai3a938972011-10-28 01:16:55 +02004786 event->jack_dirty = 1;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004787 handle_unsol_event(codec, event);
Takashi Iwai01a61e12011-10-28 00:03:22 +02004788 snd_hda_jack_report_sync(codec);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02004789}
4790
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304791static int hp_blike_system(u32 subsystem_id);
4792
4793static void set_hp_led_gpio(struct hda_codec *codec)
4794{
4795 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004796 unsigned int gpio;
4797
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004798 if (spec->gpio_led)
4799 return;
4800
Takashi Iwai07f80442010-02-08 15:06:13 +01004801 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4802 gpio &= AC_GPIO_IO_COUNT;
4803 if (gpio > 3)
4804 spec->gpio_led = 0x08; /* GPIO 3 */
4805 else
4806 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304807}
4808
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004809/*
4810 * This method searches for the mute LED GPIO configuration
4811 * provided as OEM string in SMBIOS. The format of that string
4812 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4813 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4814 * that corresponds to the NOT muted state of the master volume
4815 * and G is the index of the GPIO to use as the mute LED control (0..9)
4816 * If _G portion is missing it is assigned based on the codec ID
4817 *
4818 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4819 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304820 *
4821 *
4822 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4823 * SMBIOS - at least the ones I have seen do not have them - which include
4824 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4825 * HP Pavilion dv9500t CTO.
4826 * Need more information on whether it is true across the entire series.
4827 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004828 */
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06004829static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004830{
4831 struct sigmatel_spec *spec = codec->spec;
4832 const struct dmi_device *dev = NULL;
4833
4834 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4835 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4836 NULL, dev))) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004837 if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304838 &spec->gpio_led_polarity,
4839 &spec->gpio_led) == 2) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01004840 unsigned int max_gpio;
4841 max_gpio = snd_hda_param_read(codec, codec->afg,
4842 AC_PAR_GPIO_CAP);
4843 max_gpio &= AC_GPIO_IO_COUNT;
4844 if (spec->gpio_led < max_gpio)
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004845 spec->gpio_led = 1 << spec->gpio_led;
Takashi Iwaif1a73742011-12-04 13:44:06 +01004846 else
4847 spec->vref_mute_led_nid = spec->gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004848 return 1;
4849 }
4850 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304851 &spec->gpio_led_polarity) == 1) {
4852 set_hp_led_gpio(codec);
4853 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004854 }
Gustavo Maciel Dias Vieirae2ef36c2011-12-13 11:47:22 -02004855 /* BIOS bug: unfilled OEM string */
4856 if (strstr(dev->name, "HP_Mute_LED_P_G")) {
4857 set_hp_led_gpio(codec);
Gustavo Maciel Dias Vieiraa6a600d2012-01-24 13:27:56 -02004858 switch (codec->subsystem_id) {
4859 case 0x103c148a:
4860 spec->gpio_led_polarity = 0;
4861 break;
4862 default:
4863 spec->gpio_led_polarity = 1;
4864 break;
4865 }
Gustavo Maciel Dias Vieirae2ef36c2011-12-13 11:47:22 -02004866 return 1;
4867 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004868 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304869
4870 /*
4871 * Fallback case - if we don't find the DMI strings,
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06004872 * we statically set the GPIO - if not a B-series system
4873 * and default polarity is provided
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304874 */
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06004875 if (!hp_blike_system(codec->subsystem_id) &&
4876 (default_polarity == 0 || default_polarity == 1)) {
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304877 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004878 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304879 return 1;
4880 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004881 }
4882 return 0;
4883}
4884
4885static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004886{
4887 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004888 case 0x103c1520:
4889 case 0x103c1521:
4890 case 0x103c1523:
4891 case 0x103c1524:
4892 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004893 case 0x103c1722:
4894 case 0x103c1723:
4895 case 0x103c1724:
4896 case 0x103c1725:
4897 case 0x103c1726:
4898 case 0x103c1727:
4899 case 0x103c1728:
4900 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004901 case 0x103c172a:
4902 case 0x103c172b:
4903 case 0x103c307e:
4904 case 0x103c307f:
4905 case 0x103c3080:
4906 case 0x103c3081:
4907 case 0x103c7007:
4908 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004909 return 1;
4910 }
4911 return 0;
4912}
4913
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004914#ifdef CONFIG_PROC_FS
4915static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4916 struct hda_codec *codec, hda_nid_t nid)
4917{
4918 if (nid == codec->afg)
4919 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4920 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4921}
4922
4923static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4924 struct hda_codec *codec,
4925 unsigned int verb)
4926{
4927 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4928 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4929}
4930
4931/* stac92hd71bxx, stac92hd73xx */
4932static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4933 struct hda_codec *codec, hda_nid_t nid)
4934{
4935 stac92hd_proc_hook(buffer, codec, nid);
4936 if (nid == codec->afg)
4937 analog_loop_proc_hook(buffer, codec, 0xfa0);
4938}
4939
4940static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4941 struct hda_codec *codec, hda_nid_t nid)
4942{
4943 if (nid == codec->afg)
4944 analog_loop_proc_hook(buffer, codec, 0xfe0);
4945}
4946
4947static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4948 struct hda_codec *codec, hda_nid_t nid)
4949{
4950 if (nid == codec->afg)
4951 analog_loop_proc_hook(buffer, codec, 0xfeb);
4952}
4953#else
4954#define stac92hd_proc_hook NULL
4955#define stac92hd7x_proc_hook NULL
4956#define stac9205_proc_hook NULL
4957#define stac927x_proc_hook NULL
4958#endif
4959
Takashi Iwai2a439522011-07-26 09:52:50 +02004960#ifdef CONFIG_PM
Mattff6fdc32005-06-27 15:06:52 +02004961static int stac92xx_resume(struct hda_codec *codec)
4962{
Takashi Iwai2c885872008-11-18 09:36:55 +01004963 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004964 snd_hda_codec_resume_amp(codec);
4965 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004966 /* fake event to set up pins again to override cached values */
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004967 stac_fake_hp_events(codec);
Mattff6fdc32005-06-27 15:06:52 +02004968 return 0;
4969}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004970
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004971static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4972{
4973 stac92xx_shutup(codec);
4974 return 0;
4975}
4976
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004977#ifdef CONFIG_SND_HDA_POWER_SAVE
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004978static int stac92xx_pre_resume(struct hda_codec *codec)
4979{
4980 struct sigmatel_spec *spec = codec->spec;
4981
4982 /* sync mute LED */
Takashi Iwaif1a73742011-12-04 13:44:06 +01004983 if (spec->vref_mute_led_nid)
4984 stac_vrefout_set(codec, spec->vref_mute_led_nid,
4985 spec->vref_led);
4986 else if (spec->gpio_led)
4987 stac_gpio_set(codec, spec->gpio_mask,
4988 spec->gpio_dir, spec->gpio_data);
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004989 return 0;
4990}
4991
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004992static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
4993 unsigned int power_state)
4994{
4995 unsigned int afg_power_state = power_state;
4996 struct sigmatel_spec *spec = codec->spec;
4997
4998 if (power_state == AC_PWRST_D3) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01004999 if (spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005000 /* with vref-out pin used for mute led control
5001 * codec AFG is prevented from D3 state
5002 */
5003 afg_power_state = AC_PWRST_D1;
5004 }
5005 /* this delay seems necessary to avoid click noise at power-down */
5006 msleep(100);
5007 }
5008 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5009 afg_power_state);
5010 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
5011}
5012
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005013/*
5014 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed
5015 * as mute LED state is updated in check_power_status hook
5016 */
5017static int stac92xx_update_led_status(struct hda_codec *codec)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005018{
5019 struct sigmatel_spec *spec = codec->spec;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005020 int i, num_ext_dacs, muted = 1;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005021 unsigned int muted_lvl, notmtd_lvl;
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005022 hda_nid_t nid;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005023
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005024 if (!spec->gpio_led)
5025 return 0;
5026
Takashi Iwaic21bd022010-02-08 15:16:08 +01005027 for (i = 0; i < spec->multiout.num_dacs; i++) {
5028 nid = spec->multiout.dac_nids[i];
5029 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5030 HDA_AMP_MUTE)) {
5031 muted = 0; /* something heard */
5032 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005033 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01005034 }
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005035 if (muted && spec->multiout.hp_nid)
5036 if (!(snd_hda_codec_amp_read(codec,
5037 spec->multiout.hp_nid, 0, HDA_OUTPUT, 0) &
5038 HDA_AMP_MUTE)) {
5039 muted = 0; /* HP is not muted */
5040 }
5041 num_ext_dacs = ARRAY_SIZE(spec->multiout.extra_out_nid);
5042 for (i = 0; muted && i < num_ext_dacs; i++) {
5043 nid = spec->multiout.extra_out_nid[i];
5044 if (nid == 0)
5045 break;
5046 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5047 HDA_AMP_MUTE)) {
5048 muted = 0; /* extra output is not muted */
5049 }
5050 }
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005051 /*polarity defines *not* muted state level*/
Takashi Iwaif1a73742011-12-04 13:44:06 +01005052 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005053 if (muted)
5054 spec->gpio_data &= ~spec->gpio_led; /* orange */
5055 else
5056 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005057
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005058 if (!spec->gpio_led_polarity) {
5059 /* LED state is inverted on these systems */
5060 spec->gpio_data ^= spec->gpio_led;
5061 }
5062 stac_gpio_set(codec, spec->gpio_mask,
5063 spec->gpio_dir, spec->gpio_data);
5064 } else {
5065 notmtd_lvl = spec->gpio_led_polarity ?
5066 AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_GRD;
5067 muted_lvl = spec->gpio_led_polarity ?
5068 AC_PINCTL_VREF_GRD : AC_PINCTL_VREF_HIZ;
5069 spec->vref_led = muted ? muted_lvl : notmtd_lvl;
Takashi Iwaif1a73742011-12-04 13:44:06 +01005070 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5071 spec->vref_led);
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005072 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005073 return 0;
5074}
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005075
5076/*
5077 * use power check for controlling mute led of HP notebooks
5078 */
5079static int stac92xx_check_power_status(struct hda_codec *codec,
5080 hda_nid_t nid)
5081{
5082 stac92xx_update_led_status(codec);
5083
5084 return 0;
5085}
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005086#endif /* CONFIG_SND_HDA_POWER_SAVE */
Takashi Iwai2a439522011-07-26 09:52:50 +02005087#endif /* CONFIG_PM */
Mattff6fdc32005-06-27 15:06:52 +02005088
Takashi Iwai2b635362011-05-02 12:33:43 +02005089static const struct hda_codec_ops stac92xx_patch_ops = {
Matt2f2f4252005-04-13 14:45:30 +02005090 .build_controls = stac92xx_build_controls,
5091 .build_pcms = stac92xx_build_pcms,
5092 .init = stac92xx_init,
5093 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02005094 .unsol_event = stac92xx_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02005095#ifdef CONFIG_PM
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005096 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005097 .resume = stac92xx_resume,
5098#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005099 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005100};
5101
5102static int patch_stac9200(struct hda_codec *codec)
5103{
5104 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005105 int err;
Matt2f2f4252005-04-13 14:45:30 +02005106
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005107 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005108 if (spec == NULL)
5109 return -ENOMEM;
5110
Takashi Iwaia252c812009-12-25 22:56:20 +01005111 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005112 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005113 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005114 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005115 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005116 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5117 stac9200_models,
5118 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005119 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005120 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5121 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005122 else
5123 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005124 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005125
5126 spec->multiout.max_channels = 2;
5127 spec->multiout.num_dacs = 1;
5128 spec->multiout.dac_nids = stac9200_dac_nids;
5129 spec->adc_nids = stac9200_adc_nids;
5130 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005131 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005132 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005133 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005134 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005135
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005136 if (spec->board_config == STAC_9200_M4 ||
5137 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005138 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005139 spec->init = stac9200_eapd_init;
5140 else
5141 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005142 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005143
Takashi Iwai117f2572008-03-18 09:53:23 +01005144 if (spec->board_config == STAC_9200_PANASONIC) {
5145 spec->gpio_mask = spec->gpio_dir = 0x09;
5146 spec->gpio_data = 0x00;
5147 }
5148
Mattc7d4b2f2005-06-27 14:59:41 +02005149 err = stac9200_parse_auto_config(codec);
5150 if (err < 0) {
5151 stac92xx_free(codec);
5152 return err;
5153 }
Matt2f2f4252005-04-13 14:45:30 +02005154
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005155 /* CF-74 has no headphone detection, and the driver should *NOT*
5156 * do detection and HP/speaker toggle because the hardware does it.
5157 */
5158 if (spec->board_config == STAC_9200_PANASONIC)
5159 spec->hp_detect = 0;
5160
Matt2f2f4252005-04-13 14:45:30 +02005161 codec->patch_ops = stac92xx_patch_ops;
5162
5163 return 0;
5164}
5165
Tobin Davis8e21c342007-01-08 11:04:17 +01005166static int patch_stac925x(struct hda_codec *codec)
5167{
5168 struct sigmatel_spec *spec;
5169 int err;
5170
5171 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5172 if (spec == NULL)
5173 return -ENOMEM;
5174
Takashi Iwaia252c812009-12-25 22:56:20 +01005175 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005176 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005177 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005178 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005179 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005180
5181 /* Check first for codec ID */
5182 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5183 STAC_925x_MODELS,
5184 stac925x_models,
5185 stac925x_codec_id_cfg_tbl);
5186
5187 /* Now checks for PCI ID, if codec ID is not found */
5188 if (spec->board_config < 0)
5189 spec->board_config = snd_hda_check_board_config(codec,
5190 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005191 stac925x_models,
5192 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005193 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005194 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005195 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5196 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005197 else
5198 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005199 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005200
5201 spec->multiout.max_channels = 2;
5202 spec->multiout.num_dacs = 1;
5203 spec->multiout.dac_nids = stac925x_dac_nids;
5204 spec->adc_nids = stac925x_adc_nids;
5205 spec->mux_nids = stac925x_mux_nids;
5206 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005207 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005208 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005209 switch (codec->vendor_id) {
5210 case 0x83847632: /* STAC9202 */
5211 case 0x83847633: /* STAC9202D */
5212 case 0x83847636: /* STAC9251 */
5213 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005214 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005215 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005216 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5217 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005218 break;
5219 default:
5220 spec->num_dmics = 0;
5221 break;
5222 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005223
5224 spec->init = stac925x_core_init;
5225 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005226 spec->num_caps = 1;
5227 spec->capvols = stac925x_capvols;
5228 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005229
Charles Chin9009b0e2011-11-03 10:27:27 +01005230 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005231 if (!err) {
5232 if (spec->board_config < 0) {
5233 printk(KERN_WARNING "hda_codec: No auto-config is "
5234 "available, default to model=ref\n");
5235 spec->board_config = STAC_925x_REF;
5236 goto again;
5237 }
5238 err = -EINVAL;
5239 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005240 if (err < 0) {
5241 stac92xx_free(codec);
5242 return err;
5243 }
5244
5245 codec->patch_ops = stac92xx_patch_ops;
5246
5247 return 0;
5248}
5249
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005250static int patch_stac92hd73xx(struct hda_codec *codec)
5251{
5252 struct sigmatel_spec *spec;
5253 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5254 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005255 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005256
5257 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5258 if (spec == NULL)
5259 return -ENOMEM;
5260
Takashi Iwaia252c812009-12-25 22:56:20 +01005261 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005262 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005263 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005264 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005265 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5266 spec->pin_nids = stac92hd73xx_pin_nids;
5267 spec->board_config = snd_hda_check_board_config(codec,
5268 STAC_92HD73XX_MODELS,
5269 stac92hd73xx_models,
5270 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005271 /* check codec subsystem id if not found */
5272 if (spec->board_config < 0)
5273 spec->board_config =
5274 snd_hda_check_board_codec_sid_config(codec,
5275 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5276 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005277again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005278 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005279 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5280 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005281 else
5282 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005283 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005284
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005285 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005286 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5287
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005288 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005289 printk(KERN_WARNING "hda_codec: Could not determine "
5290 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005291 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005292 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005293 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005294 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005295 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005296 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005297 break;
5298 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005299 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005300 break;
5301 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005302 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5303 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005304 }
5305 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005306
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005307 spec->aloopback_mask = 0x01;
5308 spec->aloopback_shift = 8;
5309
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005310 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005311 spec->mux_nids = stac92hd73xx_mux_nids;
5312 spec->adc_nids = stac92hd73xx_adc_nids;
5313 spec->dmic_nids = stac92hd73xx_dmic_nids;
5314 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005315 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005316
5317 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5318 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005319 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005320
Takashi Iwai6479c632009-07-28 18:20:25 +02005321 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5322 spec->capvols = stac92hd73xx_capvols;
5323 spec->capsws = stac92hd73xx_capsws;
5324
Matthew Ranostaya7662642008-02-21 07:51:14 +01005325 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005326 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005327 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005328 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005329 case STAC_DELL_M6_AMIC:
5330 case STAC_DELL_M6_DMIC:
5331 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005332 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005333 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005334
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005335 switch (spec->board_config) {
5336 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005337 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005338 spec->num_dmics = 0;
5339 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005340 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005341 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005342 spec->num_dmics = 1;
5343 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005344 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005345 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5346 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005347 spec->num_dmics = 1;
5348 break;
5349 }
5350 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005351 case STAC_ALIENWARE_M17X:
5352 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5353 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5354 spec->eapd_switch = 0;
5355 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005356 default:
5357 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005358 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005359 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005360 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005361 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005362 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005363 /* GPIO0 High = Enable EAPD */
5364 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5365 spec->gpio_data = 0x01;
5366 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005367
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005368 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5369 spec->pwr_nids = stac92hd73xx_pwr_nids;
5370
Charles Chin9009b0e2011-11-03 10:27:27 +01005371 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005372
5373 if (!err) {
5374 if (spec->board_config < 0) {
5375 printk(KERN_WARNING "hda_codec: No auto-config is "
5376 "available, default to model=ref\n");
5377 spec->board_config = STAC_92HD73XX_REF;
5378 goto again;
5379 }
5380 err = -EINVAL;
5381 }
5382
5383 if (err < 0) {
5384 stac92xx_free(codec);
5385 return err;
5386 }
5387
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005388 if (spec->board_config == STAC_92HD73XX_NO_JD)
5389 spec->hp_detect = 0;
5390
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005391 codec->patch_ops = stac92xx_patch_ops;
5392
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005393 codec->proc_widget_hook = stac92hd7x_proc_hook;
5394
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005395 return 0;
5396}
5397
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005398static int hp_bnb2011_with_dock(struct hda_codec *codec)
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005399{
5400 if (codec->vendor_id != 0x111d7605 &&
5401 codec->vendor_id != 0x111d76d1)
5402 return 0;
5403
5404 switch (codec->subsystem_id) {
5405 case 0x103c1618:
5406 case 0x103c1619:
5407 case 0x103c161a:
5408 case 0x103c161b:
5409 case 0x103c161c:
5410 case 0x103c161d:
5411 case 0x103c161e:
5412 case 0x103c161f:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005413
5414 case 0x103c162a:
5415 case 0x103c162b:
5416
5417 case 0x103c1630:
5418 case 0x103c1631:
5419
5420 case 0x103c1633:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005421 case 0x103c1634:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005422 case 0x103c1635:
5423
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005424 case 0x103c3587:
5425 case 0x103c3588:
5426 case 0x103c3589:
5427 case 0x103c358a:
5428
5429 case 0x103c3667:
5430 case 0x103c3668:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005431 case 0x103c3669:
5432
5433 return 1;
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005434 }
5435 return 0;
5436}
5437
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005438static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
5439{
5440 struct sigmatel_spec *spec = codec->spec;
5441 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5442 int i;
5443
5444 spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5445 spec->auto_pin_cnt++;
5446
5447 if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5448 get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5449 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5450 if (nid == stac92hd83xxx_dmic_nids[i]) {
5451 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5452 spec->auto_dmic_cnt++;
5453 }
5454 }
5455 }
5456}
5457
5458static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5459{
5460 struct sigmatel_spec *spec = codec->spec;
5461
5462 spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5463 spec->auto_adc_cnt++;
5464}
5465
5466static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5467{
5468 int i, j;
5469 struct sigmatel_spec *spec = codec->spec;
5470
5471 for (i = 0; i < spec->auto_adc_cnt; i++) {
5472 if (get_connection_index(codec,
5473 spec->auto_adc_nids[i], nid) >= 0) {
5474 /* mux and volume for adc_nids[i] */
5475 if (!spec->auto_mux_nids[i]) {
5476 spec->auto_mux_nids[i] = nid;
5477 /* 92hd codecs capture volume is in mux */
5478 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
5479 3, 0, HDA_OUTPUT);
5480 }
5481 for (j = 0; j < spec->auto_dmic_cnt; j++) {
5482 if (get_connection_index(codec, nid,
5483 spec->auto_dmic_nids[j]) >= 0) {
5484 /* dmux for adc_nids[i] */
5485 if (!spec->auto_dmux_nids[i])
5486 spec->auto_dmux_nids[i] = nid;
5487 break;
5488 }
5489 }
5490 break;
5491 }
5492 }
5493}
5494
5495static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5496{
5497 hda_nid_t nid, end_nid;
5498 unsigned int wid_caps, wid_type;
5499 struct sigmatel_spec *spec = codec->spec;
5500
5501 end_nid = codec->start_nid + codec->num_nodes;
5502
5503 for (nid = codec->start_nid; nid < end_nid; nid++) {
5504 wid_caps = get_wcaps(codec, nid);
5505 wid_type = get_wcaps_type(wid_caps);
5506
5507 if (wid_type == AC_WID_PIN)
5508 stac92hd8x_add_pin(codec, nid);
5509
5510 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5511 stac92hd8x_add_adc(codec, nid);
5512 }
5513
5514 for (nid = codec->start_nid; nid < end_nid; nid++) {
5515 wid_caps = get_wcaps(codec, nid);
5516 wid_type = get_wcaps_type(wid_caps);
5517
5518 if (wid_type == AC_WID_AUD_SEL)
5519 stac92hd8x_add_mux(codec, nid);
5520 }
5521
5522 spec->pin_nids = spec->auto_pin_nids;
5523 spec->num_pins = spec->auto_pin_cnt;
5524 spec->adc_nids = spec->auto_adc_nids;
5525 spec->num_adcs = spec->auto_adc_cnt;
5526 spec->capvols = spec->auto_capvols;
5527 spec->capsws = spec->auto_capvols;
5528 spec->num_caps = spec->auto_adc_cnt;
5529 spec->mux_nids = spec->auto_mux_nids;
5530 spec->num_muxes = spec->auto_adc_cnt;
5531 spec->dmux_nids = spec->auto_dmux_nids;
5532 spec->num_dmuxes = spec->auto_adc_cnt;
5533 spec->dmic_nids = spec->auto_dmic_nids;
5534 spec->num_dmics = spec->auto_dmic_cnt;
5535}
5536
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005537static int patch_stac92hd83xxx(struct hda_codec *codec)
5538{
5539 struct sigmatel_spec *spec;
5540 int err;
5541
5542 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5543 if (spec == NULL)
5544 return -ENOMEM;
5545
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005546 if (hp_bnb2011_with_dock(codec)) {
5547 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5548 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5549 }
5550
Takashi Iwaia252c812009-12-25 22:56:20 +01005551 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005552 codec->spec = spec;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005553
5554 stac92hd8x_fill_auto_spec(codec);
5555
Takashi Iwai1db7ccdb2010-12-03 15:19:14 +01005556 spec->linear_tone_beep = 0;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005557 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005558 spec->digbeep_nid = 0x21;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005559 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005560 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005561 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005562 spec->init = stac92hd83xxx_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005563
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005564 spec->board_config = snd_hda_check_board_config(codec,
5565 STAC_92HD83XXX_MODELS,
5566 stac92hd83xxx_models,
5567 stac92hd83xxx_cfg_tbl);
5568again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005569 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005570 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5571 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005572 else
5573 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005574 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005575
Takashi Iwaib4e81872009-11-18 17:20:24 +01005576 codec->patch_ops = stac92xx_patch_ops;
5577
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005578 if (find_mute_led_cfg(codec, -1/*no default cfg*/))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005579 snd_printd("mute LED gpio %d polarity %d\n",
5580 spec->gpio_led,
5581 spec->gpio_led_polarity);
5582
Takashi Iwaib4e81872009-11-18 17:20:24 +01005583#ifdef CONFIG_SND_HDA_POWER_SAVE
5584 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005585 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005586 spec->gpio_mask |= spec->gpio_led;
5587 spec->gpio_dir |= spec->gpio_led;
5588 spec->gpio_data |= spec->gpio_led;
5589 } else {
5590 codec->patch_ops.set_power_state =
5591 stac92xx_set_power_state;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005592 }
5593 codec->patch_ops.pre_resume = stac92xx_pre_resume;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005594 codec->patch_ops.check_power_status =
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005595 stac92xx_check_power_status;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005596 }
5597#endif
5598
Charles Chin9009b0e2011-11-03 10:27:27 +01005599 err = stac92xx_parse_auto_config(codec);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005600 if (!err) {
5601 if (spec->board_config < 0) {
5602 printk(KERN_WARNING "hda_codec: No auto-config is "
5603 "available, default to model=ref\n");
5604 spec->board_config = STAC_92HD83XXX_REF;
5605 goto again;
5606 }
5607 err = -EINVAL;
5608 }
5609
5610 if (err < 0) {
5611 stac92xx_free(codec);
5612 return err;
5613 }
5614
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005615 codec->proc_widget_hook = stac92hd_proc_hook;
5616
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005617 return 0;
5618}
5619
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005620static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5621 hda_nid_t dig0pin)
5622{
5623 struct sigmatel_spec *spec = codec->spec;
5624 int idx;
5625
5626 for (idx = 0; idx < spec->num_pins; idx++)
5627 if (spec->pin_nids[idx] == dig0pin)
5628 break;
5629 if ((idx + 2) >= spec->num_pins)
5630 return 0;
5631
5632 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005633 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005634 return 2;
5635
5636 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005637 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005638 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005639 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005640 return 1;
5641 else
5642 return 0;
5643}
5644
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005645/* HP dv7 bass switch - GPIO5 */
5646#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5647static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5648 struct snd_ctl_elem_value *ucontrol)
5649{
5650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5651 struct sigmatel_spec *spec = codec->spec;
5652 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5653 return 0;
5654}
5655
5656static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5657 struct snd_ctl_elem_value *ucontrol)
5658{
5659 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5660 struct sigmatel_spec *spec = codec->spec;
5661 unsigned int gpio_data;
5662
5663 gpio_data = (spec->gpio_data & ~0x20) |
5664 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5665 if (gpio_data == spec->gpio_data)
5666 return 0;
5667 spec->gpio_data = gpio_data;
5668 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5669 return 1;
5670}
5671
Takashi Iwai2b635362011-05-02 12:33:43 +02005672static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005673 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5674 .info = stac_hp_bass_gpio_info,
5675 .get = stac_hp_bass_gpio_get,
5676 .put = stac_hp_bass_gpio_put,
5677};
5678
5679static int stac_add_hp_bass_switch(struct hda_codec *codec)
5680{
5681 struct sigmatel_spec *spec = codec->spec;
5682
5683 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5684 "Bass Speaker Playback Switch", 0))
5685 return -ENOMEM;
5686
5687 spec->gpio_mask |= 0x20;
5688 spec->gpio_dir |= 0x20;
5689 spec->gpio_data |= 0x20;
5690 return 0;
5691}
5692
Matthew Ranostaye035b842007-11-06 11:53:55 +01005693static int patch_stac92hd71bxx(struct hda_codec *codec)
5694{
5695 struct sigmatel_spec *spec;
Takashi Iwai2b635362011-05-02 12:33:43 +02005696 const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005697 unsigned int pin_cfg;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005698 int err = 0;
5699
5700 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5701 if (spec == NULL)
5702 return -ENOMEM;
5703
Takashi Iwaia252c812009-12-25 22:56:20 +01005704 codec->no_trigger_sense = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005705 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005706 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005707 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005708 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5709 switch (codec->vendor_id) {
5710 case 0x111d76b6:
5711 case 0x111d76b7:
5712 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5713 break;
5714 case 0x111d7603:
5715 case 0x111d7608:
5716 /* On 92HD75Bx 0x27 isn't a pin nid */
5717 spec->num_pins--;
5718 /* fallthrough */
5719 default:
5720 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5721 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005722 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005723 spec->board_config = snd_hda_check_board_config(codec,
5724 STAC_92HD71BXX_MODELS,
5725 stac92hd71bxx_models,
5726 stac92hd71bxx_cfg_tbl);
5727again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005728 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005729 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5730 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005731 else
5732 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005733 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005734
Takashi Iwaifc64b262009-09-14 15:33:01 +02005735 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005736 /* GPIO0 = EAPD */
5737 spec->gpio_mask = 0x01;
5738 spec->gpio_dir = 0x01;
5739 spec->gpio_data = 0x01;
5740 }
5741
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005742 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5743 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5744
Takashi Iwai6479c632009-07-28 18:20:25 +02005745 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5746 spec->capvols = stac92hd71bxx_capvols;
5747 spec->capsws = stac92hd71bxx_capsws;
5748
Matthew Ranostay541eee82007-12-14 12:08:04 +01005749 switch (codec->vendor_id) {
5750 case 0x111d76b6: /* 4 Port without Analog Mixer */
5751 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005752 unmute_init++;
5753 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005754 case 0x111d76b4: /* 6 Port without Analog Mixer */
5755 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005756 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005757 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005758 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005759 stac92hd71bxx_dmic_nids,
5760 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005761 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005762 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005763 switch (spec->board_config) {
5764 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005765 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwai3a938972011-10-28 01:16:55 +02005766 err = stac_add_event(codec, codec->afg,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005767 STAC_VREF_EVENT, 0x02);
5768 if (err < 0)
5769 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005770 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005771 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
Takashi Iwai3a938972011-10-28 01:16:55 +02005772 snd_hda_jack_detect_enable(codec, codec->afg, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005773 spec->gpio_mask |= 0x02;
5774 break;
5775 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005776 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005777 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005778 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005779
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005780 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005781 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005782 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005783 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5784 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Takashi Iwai2b635362011-05-02 12:33:43 +02005785 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005786 spec->num_dmics = stac92xx_connected_ports(codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02005787 stac92hd71bxx_dmic_5port_nids,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005788 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005789 break;
5790 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005791 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005792 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005793
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005794 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005795 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005796 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005797 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005798 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005799 stac92hd71bxx_dmic_nids,
5800 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005801 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005802 }
5803
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005804 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5805 snd_hda_sequence_write_cache(codec, unmute_init);
5806
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005807 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005808 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005809 spec->aloopback_shift = 0;
5810
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005811 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005812 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005813 spec->mux_nids = stac92hd71bxx_mux_nids;
5814 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005815 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005816 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005817
5818 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5819 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005820 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005821 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005822
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305823 snd_printdd("Found board config: %d\n", spec->board_config);
5824
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005825 switch (spec->board_config) {
5826 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005827 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005828 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005829 stac92xx_auto_set_pinctl(codec, 0x0e,
5830 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005831 /* fallthru */
5832 case STAC_DELL_M4_2:
5833 spec->num_dmics = 0;
5834 spec->num_smuxes = 0;
5835 spec->num_dmuxes = 0;
5836 break;
5837 case STAC_DELL_M4_1:
5838 case STAC_DELL_M4_3:
5839 spec->num_dmics = 1;
5840 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005841 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005842 break;
James Gardiner514bf542009-05-03 04:00:44 -04005843 case STAC_HP_DV4_1222NR:
5844 spec->num_dmics = 1;
5845 /* I don't know if it needs 1 or 2 smuxes - will wait for
5846 * bug reports to fix if needed
5847 */
5848 spec->num_smuxes = 1;
5849 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005850 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005851 case STAC_HP_DV4:
5852 spec->gpio_led = 0x01;
5853 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005854 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005855 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005856 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005857 /* HP dv6 gives the headphone pin as a line-out. Thus we
5858 * need to set hp_detect flag here to force to enable HP
5859 * detection.
5860 */
5861 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005862 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005863 case STAC_HP_HDX:
5864 spec->num_dmics = 1;
5865 spec->num_dmuxes = 1;
5866 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005867 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005868 break;
5869 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005870
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005871 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005872 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5873 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5874 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5875 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5876 /* It was changed in the BIOS to just satisfy MS DTM.
5877 * Lets turn it back into slaved HP
5878 */
5879 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5880 | (AC_JACK_HP_OUT <<
5881 AC_DEFCFG_DEVICE_SHIFT);
5882 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5883 | AC_DEFCFG_SEQUENCE)))
5884 | 0x1f;
5885 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5886 }
5887 }
5888
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005889 if (find_mute_led_cfg(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005890 snd_printd("mute LED gpio %d polarity %d\n",
5891 spec->gpio_led,
5892 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005893
Takashi Iwai86d190e2009-05-26 15:18:58 +02005894#ifdef CONFIG_SND_HDA_POWER_SAVE
5895 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005896 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005897 spec->gpio_mask |= spec->gpio_led;
5898 spec->gpio_dir |= spec->gpio_led;
5899 spec->gpio_data |= spec->gpio_led;
5900 } else {
5901 codec->patch_ops.set_power_state =
5902 stac92xx_set_power_state;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005903 }
5904 codec->patch_ops.pre_resume = stac92xx_pre_resume;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005905 codec->patch_ops.check_power_status =
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005906 stac92xx_check_power_status;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005907 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005908#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005909
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005910 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005911
Charles Chin9009b0e2011-11-03 10:27:27 +01005912 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005913 if (!err) {
5914 if (spec->board_config < 0) {
5915 printk(KERN_WARNING "hda_codec: No auto-config is "
5916 "available, default to model=ref\n");
5917 spec->board_config = STAC_92HD71BXX_REF;
5918 goto again;
5919 }
5920 err = -EINVAL;
5921 }
5922
5923 if (err < 0) {
5924 stac92xx_free(codec);
5925 return err;
5926 }
5927
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005928 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005929 if (spec->board_config == STAC_HP_DV4 ||
5930 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005931 unsigned int cap;
5932 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5933 cap &= AC_GPIO_IO_COUNT;
5934 if (cap >= 6)
5935 stac_add_hp_bass_switch(codec);
5936 }
5937
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005938 codec->proc_widget_hook = stac92hd7x_proc_hook;
5939
Matthew Ranostaye035b842007-11-06 11:53:55 +01005940 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005941}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005942
Matt2f2f4252005-04-13 14:45:30 +02005943static int patch_stac922x(struct hda_codec *codec)
5944{
5945 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005946 int err;
Matt2f2f4252005-04-13 14:45:30 +02005947
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005948 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005949 if (spec == NULL)
5950 return -ENOMEM;
5951
Takashi Iwaia252c812009-12-25 22:56:20 +01005952 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005953 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005954 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005955 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005956 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005957 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5958 stac922x_models,
5959 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005960 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005961 spec->gpio_mask = spec->gpio_dir = 0x03;
5962 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005963 /* Intel Macs have all same PCI SSID, so we need to check
5964 * codec SSID to distinguish the exact models
5965 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005966 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005967 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005968
5969 case 0x106b0800:
5970 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005971 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005972 case 0x106b0600:
5973 case 0x106b0700:
5974 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005975 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005976 case 0x106b0e00:
5977 case 0x106b0f00:
5978 case 0x106b1600:
5979 case 0x106b1700:
5980 case 0x106b0200:
5981 case 0x106b1e00:
5982 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005983 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005984 case 0x106b1a00:
5985 case 0x00000100:
5986 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005987 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005988 case 0x106b0a00:
5989 case 0x106b2200:
5990 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005991 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005992 default:
5993 spec->board_config = STAC_INTEL_MAC_V3;
5994 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005995 }
5996 }
5997
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005998 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005999 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006000 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6001 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006002 else
6003 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006004 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02006005
Matt2f2f4252005-04-13 14:45:30 +02006006 spec->adc_nids = stac922x_adc_nids;
6007 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006008 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006009 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006010 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006011 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02006012
6013 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006014
6015 spec->num_caps = STAC922X_NUM_CAPS;
6016 spec->capvols = stac922x_capvols;
6017 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02006018
6019 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02006020
Charles Chin9009b0e2011-11-03 10:27:27 +01006021 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006022 if (!err) {
6023 if (spec->board_config < 0) {
6024 printk(KERN_WARNING "hda_codec: No auto-config is "
6025 "available, default to model=ref\n");
6026 spec->board_config = STAC_D945_REF;
6027 goto again;
6028 }
6029 err = -EINVAL;
6030 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006031 if (err < 0) {
6032 stac92xx_free(codec);
6033 return err;
6034 }
6035
6036 codec->patch_ops = stac92xx_patch_ops;
6037
Takashi Iwai807a46362007-05-29 19:01:37 +02006038 /* Fix Mux capture level; max to 2 */
6039 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
6040 (0 << AC_AMPCAP_OFFSET_SHIFT) |
6041 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
6042 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6043 (0 << AC_AMPCAP_MUTE_SHIFT));
6044
Matt Porter3cc08dc2006-01-23 15:27:49 +01006045 return 0;
6046}
6047
6048static int patch_stac927x(struct hda_codec *codec)
6049{
6050 struct sigmatel_spec *spec;
6051 int err;
6052
6053 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6054 if (spec == NULL)
6055 return -ENOMEM;
6056
Takashi Iwaia252c812009-12-25 22:56:20 +01006057 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01006058 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006059 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05006060 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006061 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006062 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006063 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
6064 stac927x_models,
6065 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006066 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006067 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006068 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6069 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006070 else
6071 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006072 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01006073
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006074 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006075 spec->adc_nids = stac927x_adc_nids;
6076 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6077 spec->mux_nids = stac927x_mux_nids;
6078 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006079 spec->smux_nids = stac927x_smux_nids;
6080 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04006081 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01006082 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006083 spec->multiout.dac_nids = spec->dac_nids;
6084
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006085 if (spec->board_config != STAC_D965_REF) {
6086 /* GPIO0 High = Enable EAPD */
6087 spec->eapd_mask = spec->gpio_mask = 0x01;
6088 spec->gpio_dir = spec->gpio_data = 0x01;
6089 }
6090
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006091 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02006092 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006093 case STAC_D965_5ST:
6094 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006095 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02006096 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006097 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006098 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006099 switch (codec->subsystem_id) {
6100 case 0x10280209:
6101 case 0x1028022e:
6102 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006103 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006104 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006105 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01006106 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01006107 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01006108 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006109 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006110 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01006111 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006112 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006113 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006114 if (codec->subsystem_id != 0x1028022f) {
6115 /* GPIO2 High = Enable EAPD */
6116 spec->eapd_mask = spec->gpio_mask = 0x04;
6117 spec->gpio_dir = spec->gpio_data = 0x04;
6118 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006119 spec->dmic_nids = stac927x_dmic_nids;
6120 spec->num_dmics = STAC927X_NUM_DMICS;
6121
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02006122 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006123 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006124 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006125 break;
Takashi Iwai54930532009-10-11 17:38:29 +02006126 case STAC_927X_VOLKNOB:
6127 spec->num_dmics = 0;
6128 spec->init = stac927x_volknob_core_init;
6129 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006130 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006131 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006132 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006133 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006134 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006135
Takashi Iwai6479c632009-07-28 18:20:25 +02006136 spec->num_caps = STAC927X_NUM_CAPS;
6137 spec->capvols = stac927x_capvols;
6138 spec->capsws = stac927x_capsws;
6139
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006140 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006141 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006142 spec->aloopback_mask = 0x40;
6143 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05006144 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006145
Charles Chin9009b0e2011-11-03 10:27:27 +01006146 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006147 if (!err) {
6148 if (spec->board_config < 0) {
6149 printk(KERN_WARNING "hda_codec: No auto-config is "
6150 "available, default to model=ref\n");
6151 spec->board_config = STAC_D965_REF;
6152 goto again;
6153 }
6154 err = -EINVAL;
6155 }
Mattc7d4b2f2005-06-27 14:59:41 +02006156 if (err < 0) {
6157 stac92xx_free(codec);
6158 return err;
6159 }
Matt2f2f4252005-04-13 14:45:30 +02006160
6161 codec->patch_ops = stac92xx_patch_ops;
6162
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006163 codec->proc_widget_hook = stac927x_proc_hook;
6164
Takashi Iwai52987652008-01-16 16:09:47 +01006165 /*
6166 * !!FIXME!!
6167 * The STAC927x seem to require fairly long delays for certain
6168 * command sequences. With too short delays (even if the answer
6169 * is set to RIRB properly), it results in the silence output
6170 * on some hardwares like Dell.
6171 *
6172 * The below flag enables the longer delay (see get_response
6173 * in hda_intel.c).
6174 */
6175 codec->bus->needs_damn_long_delay = 1;
6176
Takashi Iwaie28d8322008-12-17 13:48:29 +01006177 /* no jack detecion for ref-no-jd model */
6178 if (spec->board_config == STAC_D965_REF_NO_JD)
6179 spec->hp_detect = 0;
6180
Matt2f2f4252005-04-13 14:45:30 +02006181 return 0;
6182}
6183
Matt Porterf3302a52006-07-31 12:49:34 +02006184static int patch_stac9205(struct hda_codec *codec)
6185{
6186 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006187 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006188
6189 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6190 if (spec == NULL)
6191 return -ENOMEM;
6192
Takashi Iwaia252c812009-12-25 22:56:20 +01006193 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006194 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006195 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006196 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006197 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006198 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6199 stac9205_models,
6200 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006201 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006202 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006203 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6204 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006205 else
6206 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006207 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006208
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006209 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006210 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006211 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006212 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006213 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006214 spec->smux_nids = stac9205_smux_nids;
6215 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006216 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006217 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006218 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006219 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006220 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006221
6222 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006223 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006224
Takashi Iwai6479c632009-07-28 18:20:25 +02006225 spec->num_caps = STAC9205_NUM_CAPS;
6226 spec->capvols = stac9205_capvols;
6227 spec->capsws = stac9205_capsws;
6228
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006229 spec->aloopback_mask = 0x40;
6230 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006231 /* Turn on/off EAPD per HP plugging */
6232 if (spec->board_config != STAC_9205_EAPD)
6233 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006234 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006235
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006236 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006237 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006238 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006239 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6240 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006241
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006242 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwai3a938972011-10-28 01:16:55 +02006243 err = stac_add_event(codec, codec->afg, STAC_VREF_EVENT, 0x01);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006244 if (err < 0)
6245 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006246 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006247 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
Takashi Iwai3a938972011-10-28 01:16:55 +02006248 snd_hda_jack_detect_enable(codec, codec->afg, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006249
6250 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006251 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006252 spec->gpio_mask = 0x1b;
6253 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006254 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006255 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006256 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006257 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006258 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006259 case STAC_9205_REF:
6260 /* SPDIF-In enabled */
6261 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006262 default:
6263 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006264 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006265 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006266 break;
6267 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006268
Charles Chin9009b0e2011-11-03 10:27:27 +01006269 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006270 if (!err) {
6271 if (spec->board_config < 0) {
6272 printk(KERN_WARNING "hda_codec: No auto-config is "
6273 "available, default to model=ref\n");
6274 spec->board_config = STAC_9205_REF;
6275 goto again;
6276 }
6277 err = -EINVAL;
6278 }
Matt Porterf3302a52006-07-31 12:49:34 +02006279 if (err < 0) {
6280 stac92xx_free(codec);
6281 return err;
6282 }
6283
6284 codec->patch_ops = stac92xx_patch_ops;
6285
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006286 codec->proc_widget_hook = stac9205_proc_hook;
6287
Matt Porterf3302a52006-07-31 12:49:34 +02006288 return 0;
6289}
6290
Matt2f2f4252005-04-13 14:45:30 +02006291/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006292 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006293 */
6294
Takashi Iwai2b635362011-05-02 12:33:43 +02006295static const struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006296 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006297 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6298 {}
6299};
6300
Takashi Iwai2b635362011-05-02 12:33:43 +02006301static const hda_nid_t stac9872_pin_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006302 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6303 0x11, 0x13, 0x14,
6304};
6305
Takashi Iwai2b635362011-05-02 12:33:43 +02006306static const hda_nid_t stac9872_adc_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006307 0x8 /*,0x6*/
6308};
6309
Takashi Iwai2b635362011-05-02 12:33:43 +02006310static const hda_nid_t stac9872_mux_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006311 0x15
6312};
6313
Takashi Iwai2b635362011-05-02 12:33:43 +02006314static const unsigned long stac9872_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +02006315 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6316};
6317#define stac9872_capsws stac9872_capvols
6318
Takashi Iwai2b635362011-05-02 12:33:43 +02006319static const unsigned int stac9872_vaio_pin_configs[9] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006320 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6321 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6322 0x90a7013e
6323};
6324
Takashi Iwaiea734962011-01-17 11:29:34 +01006325static const char * const stac9872_models[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006326 [STAC_9872_AUTO] = "auto",
6327 [STAC_9872_VAIO] = "vaio",
6328};
6329
Takashi Iwai2b635362011-05-02 12:33:43 +02006330static const unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006331 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6332};
6333
Takashi Iwai2b635362011-05-02 12:33:43 +02006334static const struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006335 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6336 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006337 {} /* terminator */
6338};
6339
Guillaume Munch6d859062006-08-22 17:15:47 +02006340static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006341{
6342 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006343 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006344
Takashi Iwaidb064e52006-03-16 16:04:58 +01006345 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6346 if (spec == NULL)
6347 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006348 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006349 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006350 spec->linear_tone_beep = 1;
Takashi Iwaib04add92009-07-20 08:01:36 +02006351 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6352 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006353
6354 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6355 stac9872_models,
6356 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006357 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006358 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6359 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006360 else
6361 stac92xx_set_config_regs(codec,
6362 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006363
Takashi Iwai1e137f92009-01-21 07:41:22 +01006364 spec->multiout.dac_nids = spec->dac_nids;
6365 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6366 spec->adc_nids = stac9872_adc_nids;
6367 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6368 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006369 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006370 spec->num_caps = 1;
6371 spec->capvols = stac9872_capvols;
6372 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006373
Charles Chin9009b0e2011-11-03 10:27:27 +01006374 err = stac92xx_parse_auto_config(codec);
Takashi Iwai1e137f92009-01-21 07:41:22 +01006375 if (err < 0) {
6376 stac92xx_free(codec);
6377 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006378 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006379 spec->input_mux = &spec->private_imux;
6380 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006381 return 0;
6382}
6383
6384
6385/*
Matt2f2f4252005-04-13 14:45:30 +02006386 * patch entries
6387 */
Takashi Iwai2b635362011-05-02 12:33:43 +02006388static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006389 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6390 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6391 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6392 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6393 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6394 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6395 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006396 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6397 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6398 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6399 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6400 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6401 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006402 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6403 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6404 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6405 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6406 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6407 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6408 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6409 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6410 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6411 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006412 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6413 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6414 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6415 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6416 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6417 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006418 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6419 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006420 /* The following does not take into account .id=0x83847661 when subsys =
6421 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6422 * currently not fully supported.
6423 */
6424 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6425 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6426 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006427 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006428 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6429 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6430 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6431 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6432 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6433 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6434 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6435 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006436 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006437 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006438 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006439 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006440 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006441 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6442 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006443 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6444 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6445 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6446 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006447 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006448 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6449 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006450 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006451 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6452 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6453 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6454 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6455 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6456 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6457 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6458 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006459 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6460 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6461 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6462 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6463 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6464 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6465 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6466 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6467 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6468 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6469 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6470 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6471 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6472 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6473 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
David Henningsson46724c22011-09-20 09:02:22 +02006474 { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006475 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06006476 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6477 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006478 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Charles Chinad5d8752011-11-02 07:56:58 +01006479 { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6480 { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6481 { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6482 { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6483 { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6484 { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6485 { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6486 { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6487 { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6488 { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6489 { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6490 { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006491 {} /* terminator */
6492};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006493
6494MODULE_ALIAS("snd-hda-codec-id:8384*");
6495MODULE_ALIAS("snd-hda-codec-id:111d*");
6496
6497MODULE_LICENSE("GPL");
6498MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6499
6500static struct hda_codec_preset_list sigmatel_list = {
6501 .preset = snd_hda_preset_sigmatel,
6502 .owner = THIS_MODULE,
6503};
6504
6505static int __init patch_sigmatel_init(void)
6506{
6507 return snd_hda_add_codec_preset(&sigmatel_list);
6508}
6509
6510static void __exit patch_sigmatel_exit(void)
6511{
6512 snd_hda_delete_codec_preset(&sigmatel_list);
6513}
6514
6515module_init(patch_sigmatel_init)
6516module_exit(patch_sigmatel_exit)