blob: 533afb698fb95321fec762056e73503d875d2a92 [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"
Takashi Iwai128bc4b2012-05-07 17:42:31 +020039#include "hda_auto_parser.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020040#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020041#include "hda_jack.h"
Matt2f2f4252005-04-13 14:45:30 +020042
Takashi Iwaic6e4c662008-11-25 11:58:19 +010043enum {
44 STAC_VREF_EVENT = 1,
45 STAC_INSERT_EVENT,
46 STAC_PWR_EVENT,
47 STAC_HP_EVENT,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020048 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020049 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010050};
Matt4e550962005-07-04 17:51:39 +020051
Takashi Iwaif5fcc132006-11-24 17:07:44 +010052enum {
53 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 Iwaid39a3ae2013-01-14 14:06:26 +010068 STAC_9200_EAPD_INIT,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010069 STAC_9200_MODELS
70};
71
72enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010073 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010074 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020075 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020076 STAC_9205_DELL_M43,
77 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010078 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010079 STAC_9205_MODELS
80};
81
82enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010083 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010084 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010085 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080086 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010087 STAC_DELL_M6_AMIC,
88 STAC_DELL_M6_DMIC,
89 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050090 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020091 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010092 STAC_92HD73XX_MODELS
93};
94
95enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010096 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020097 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050098 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050099 STAC_DELL_S14,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +0100100 STAC_DELL_VOSTRO_3500,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -0500101 STAC_92HD83XXX_HP_cNB11_INTQUAD,
Steven Eastland48315592010-08-06 15:07:35 -0600102 STAC_HP_DV7_4000,
Vitaliy Kulikov5556e142012-02-27 16:47:37 -0600103 STAC_HP_ZEPHYR,
Takashi Iwaia3e19972012-07-26 08:17:20 +0200104 STAC_92HD83XXX_HP_LED,
Takashi Iwaiff8a1e22012-07-31 10:16:59 +0200105 STAC_92HD83XXX_HP_INV_LED,
Takashi Iwai62cbde12012-09-14 11:58:54 +0200106 STAC_92HD83XXX_HP_MIC_LED,
David Henningsson8d032a82012-10-09 12:48:40 +0200107 STAC_92HD83XXX_HEADSET_JACK,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200108 STAC_92HD83XXX_MODELS
109};
110
111enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100112 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100113 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100114 STAC_DELL_M4_1,
115 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500116 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400117 STAC_HP_M4,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +0200118 STAC_HP_DV4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100119 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100120 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400121 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100122 STAC_92HD71BXX_MODELS
123};
124
125enum {
Tobin Davis8e21c342007-01-08 11:04:17 +0100126 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200127 STAC_M1,
128 STAC_M1_2,
129 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100130 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200131 STAC_M3,
132 STAC_M5,
133 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100134 STAC_925x_MODELS
135};
136
137enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100138 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100139 STAC_D945_REF,
140 STAC_D945GTP3,
141 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200142 STAC_INTEL_MAC_V1,
143 STAC_INTEL_MAC_V2,
144 STAC_INTEL_MAC_V3,
145 STAC_INTEL_MAC_V4,
146 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800147 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
148 * is given, one of the above models will be
149 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200150 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100151 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100152 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100153 STAC_MACBOOK_PRO_V1,
154 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200155 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200156 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300157 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200158 STAC_922X_DELL_D81,
159 STAC_922X_DELL_D82,
160 STAC_922X_DELL_M81,
161 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100162 STAC_922X_MODELS
163};
164
165enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100166 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100167 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100168 STAC_D965_REF,
169 STAC_D965_3ST,
170 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200171 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200172 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100173 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200174 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100175 STAC_927X_MODELS
176};
Matt Porter403d1942005-11-29 15:00:51 +0100177
Takashi Iwai307282c2009-03-12 18:17:58 +0100178enum {
Takashi Iwai307282c2009-03-12 18:17:58 +0100179 STAC_9872_VAIO,
180 STAC_9872_MODELS
181};
182
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200183struct sigmatel_mic_route {
184 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200185 signed char mux_idx;
186 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200187};
188
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600189#define MAX_PINS_NUM 16
190#define MAX_ADCS_NUM 4
191#define MAX_DMICS_NUM 4
192
Matt2f2f4252005-04-13 14:45:30 +0200193struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100194 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200195 unsigned int num_mixers;
196
Matt Porter403d1942005-11-29 15:00:51 +0100197 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500198 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200199 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100200 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100201 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400202 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100203 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200204 unsigned int auto_mic:1;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +0100205 unsigned int linear_tone_beep:1;
David Henningsson8d032a82012-10-09 12:48:40 +0200206 unsigned int headset_jack:1; /* 4-pin headset jack (hp + mono mic) */
Mattc7d4b2f2005-06-27 14:59:41 +0200207
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100208 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200209 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100210 unsigned int gpio_mask;
211 unsigned int gpio_dir;
212 unsigned int gpio_data;
213 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200214 unsigned int gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +0100215 unsigned int gpio_led_polarity;
Takashi Iwaif1a73742011-12-04 13:44:06 +0100216 unsigned int vref_mute_led_nid; /* pin NID for mute-LED vref control */
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500217 unsigned int vref_led;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100218
Takashi Iwai62cbde12012-09-14 11:58:54 +0200219 unsigned int mic_mute_led_gpio; /* capture mute LED GPIO */
220 bool mic_mute_led_on; /* current mic mute state */
221
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200222 /* stream */
223 unsigned int stream_delay;
224
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100225 /* analog loopback */
Takashi Iwai2b635362011-05-02 12:33:43 +0200226 const struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100227 unsigned char aloopback_mask;
228 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200229
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100230 /* power management */
Takashi Iwaic8822462012-05-15 09:11:36 +0200231 unsigned int power_map_bits;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100232 unsigned int num_pwrs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200233 const hda_nid_t *pwr_nids;
234 const hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100235
Matt2f2f4252005-04-13 14:45:30 +0200236 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100237 struct hda_input_mux *mono_mux;
238 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200239 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100240 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100241 hda_nid_t hp_dacs[5];
242 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200243
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100244 int volume_offset;
245
Matt2f2f4252005-04-13 14:45:30 +0200246 /* capture */
Takashi Iwai2b635362011-05-02 12:33:43 +0200247 const hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200248 unsigned int num_adcs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200249 const hda_nid_t *mux_nids;
Mattdabbed62005-06-14 10:19:34 +0200250 unsigned int num_muxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200251 const hda_nid_t *dmic_nids;
Matt Porter8b657272006-10-26 17:12:59 +0200252 unsigned int num_dmics;
Takashi Iwai2b635362011-05-02 12:33:43 +0200253 const hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100254 unsigned int num_dmuxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200255 const hda_nid_t *smux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200256 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200257 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200258
Takashi Iwai2b635362011-05-02 12:33:43 +0200259 const unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
260 const unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
Takashi Iwai6479c632009-07-28 18:20:25 +0200261 unsigned int num_caps; /* number of capture volume/switch elements */
262
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200263 struct sigmatel_mic_route ext_mic;
264 struct sigmatel_mic_route int_mic;
Charles Chin99077902010-09-17 10:22:32 +0200265 struct sigmatel_mic_route dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200266
Takashi Iwaiea734962011-01-17 11:29:34 +0100267 const char * const *spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200268
Mattdabbed62005-06-14 10:19:34 +0200269 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100270 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200271 hda_nid_t anabeep_nid;
272 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200273
Matt2f2f4252005-04-13 14:45:30 +0200274 /* pin widgets */
Takashi Iwai2b635362011-05-02 12:33:43 +0200275 const hda_nid_t *pin_nids;
Matt2f2f4252005-04-13 14:45:30 +0200276 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200277
278 /* codec specific stuff */
Takashi Iwai2b635362011-05-02 12:33:43 +0200279 const struct hda_verb *init;
280 const struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200281
282 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200283 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100284 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200285 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100286 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200287 struct hda_input_mux *sinput_mux;
288 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400289 unsigned int cur_amux;
290 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200291 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200292
Matt Porter403d1942005-11-29 15:00:51 +0100293 /* i/o switches */
294 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200295 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100296 hda_nid_t line_switch; /* shared line-in for input and output */
297 hda_nid_t mic_switch; /* shared mic-in for input and output */
298 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200299 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200300
Mattc7d4b2f2005-06-27 14:59:41 +0200301 struct hda_pcm pcm_rec[2]; /* PCM information */
302
303 /* dynamic controls and input_mux */
304 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200305 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200306 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200307 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200308 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100309 struct hda_input_mux private_mono_mux;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600310
311 /* auto spec */
312 unsigned auto_pin_cnt;
313 hda_nid_t auto_pin_nids[MAX_PINS_NUM];
314 unsigned auto_adc_cnt;
315 hda_nid_t auto_adc_nids[MAX_ADCS_NUM];
316 hda_nid_t auto_mux_nids[MAX_ADCS_NUM];
317 hda_nid_t auto_dmux_nids[MAX_ADCS_NUM];
318 unsigned long auto_capvols[MAX_ADCS_NUM];
319 unsigned auto_dmic_cnt;
320 hda_nid_t auto_dmic_nids[MAX_DMICS_NUM];
Takashi Iwai2faa3bf2012-03-12 12:30:22 +0100321
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100322 struct hda_vmaster_mute_hook vmaster_mute;
Matt2f2f4252005-04-13 14:45:30 +0200323};
324
Takashi Iwaic8822462012-05-15 09:11:36 +0200325#define AC_VERB_IDT_SET_POWER_MAP 0x7ec
326#define AC_VERB_IDT_GET_POWER_MAP 0xfec
327
Takashi Iwai2b635362011-05-02 12:33:43 +0200328static const hda_nid_t stac9200_adc_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200329 0x03,
330};
331
Takashi Iwai2b635362011-05-02 12:33:43 +0200332static const hda_nid_t stac9200_mux_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200333 0x0c,
334};
335
Takashi Iwai2b635362011-05-02 12:33:43 +0200336static const hda_nid_t stac9200_dac_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200337 0x02,
338};
339
Takashi Iwai2b635362011-05-02 12:33:43 +0200340static const hda_nid_t stac92hd73xx_pwr_nids[8] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100341 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
342 0x0f, 0x10, 0x11
343};
344
Takashi Iwai2b635362011-05-02 12:33:43 +0200345static const hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400346 0x26, 0,
347};
348
Takashi Iwai2b635362011-05-02 12:33:43 +0200349static const hda_nid_t stac92hd73xx_adc_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100350 0x1a, 0x1b
351};
352
353#define STAC92HD73XX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200354static const hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100355 0x13, 0x14, 0
356};
357
358#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100359
Takashi Iwai2b635362011-05-02 12:33:43 +0200360static const hda_nid_t stac92hd73xx_mux_nids[2] = {
Takashi Iwaie2aec172009-09-02 01:00:05 +0200361 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100362};
363
Takashi Iwai2b635362011-05-02 12:33:43 +0200364static const hda_nid_t stac92hd73xx_dmux_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100365 0x20, 0x21,
366};
367
Takashi Iwai2b635362011-05-02 12:33:43 +0200368static const hda_nid_t stac92hd73xx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200369 0x22, 0x23,
370};
371
Takashi Iwai6479c632009-07-28 18:20:25 +0200372#define STAC92HD73XX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200373static const unsigned long stac92hd73xx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200374 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
375 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
376};
377#define stac92hd73xx_capsws stac92hd73xx_capvols
378
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200379#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200380
Charles Chinafef2cf2011-11-11 08:05:28 +0100381static const hda_nid_t stac92hd83xxx_pwr_nids[7] = {
382 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
383 0x0f, 0x10
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200384};
385
Takashi Iwai2b635362011-05-02 12:33:43 +0200386static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400387 0x1e, 0,
388};
389
Takashi Iwai2b635362011-05-02 12:33:43 +0200390static const hda_nid_t stac92hd83xxx_dmic_nids[] = {
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600391 0x11, 0x20,
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +0200392};
393
Takashi Iwai2b635362011-05-02 12:33:43 +0200394static const hda_nid_t stac92hd71bxx_pwr_nids[3] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100395 0x0a, 0x0d, 0x0f
396};
397
Takashi Iwai2b635362011-05-02 12:33:43 +0200398static const hda_nid_t stac92hd71bxx_adc_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100399 0x12, 0x13,
400};
401
Takashi Iwai2b635362011-05-02 12:33:43 +0200402static const hda_nid_t stac92hd71bxx_mux_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100403 0x1a, 0x1b
404};
405
Takashi Iwai2b635362011-05-02 12:33:43 +0200406static const hda_nid_t stac92hd71bxx_dmux_nids[2] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400407 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100408};
409
Takashi Iwai2b635362011-05-02 12:33:43 +0200410static const hda_nid_t stac92hd71bxx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200411 0x24, 0x25,
412};
413
Matthew Ranostaye035b842007-11-06 11:53:55 +0100414#define STAC92HD71BXX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200415static const hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100416 0x18, 0x19, 0
417};
418
Takashi Iwai2b635362011-05-02 12:33:43 +0200419static const hda_nid_t stac92hd71bxx_dmic_5port_nids[STAC92HD71BXX_NUM_DMICS] = {
420 0x18, 0
421};
422
423static const hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400424 0x22, 0
425};
426
Takashi Iwai6479c632009-07-28 18:20:25 +0200427#define STAC92HD71BXX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200428static const unsigned long stac92hd71bxx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200429 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
430 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
431};
432#define stac92hd71bxx_capsws stac92hd71bxx_capvols
433
Takashi Iwai2b635362011-05-02 12:33:43 +0200434static const hda_nid_t stac925x_adc_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100435 0x03,
436};
437
Takashi Iwai2b635362011-05-02 12:33:43 +0200438static const hda_nid_t stac925x_mux_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100439 0x0f,
440};
441
Takashi Iwai2b635362011-05-02 12:33:43 +0200442static const hda_nid_t stac925x_dac_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100443 0x02,
444};
445
Takashi Iwaif6e98522007-10-16 14:27:04 +0200446#define STAC925X_NUM_DMICS 1
Takashi Iwai2b635362011-05-02 12:33:43 +0200447static const hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200448 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200449};
450
Takashi Iwai2b635362011-05-02 12:33:43 +0200451static const hda_nid_t stac925x_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100452 0x14,
453};
454
Takashi Iwai2b635362011-05-02 12:33:43 +0200455static const unsigned long stac925x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200456 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
457};
Takashi Iwai2b635362011-05-02 12:33:43 +0200458static const unsigned long stac925x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200459 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
460};
461
Takashi Iwai2b635362011-05-02 12:33:43 +0200462static const hda_nid_t stac922x_adc_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200463 0x06, 0x07,
464};
465
Takashi Iwai2b635362011-05-02 12:33:43 +0200466static const hda_nid_t stac922x_mux_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200467 0x12, 0x13,
468};
469
Takashi Iwai6479c632009-07-28 18:20:25 +0200470#define STAC922X_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200471static const unsigned long stac922x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200472 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
473 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
474};
475#define stac922x_capsws stac922x_capvols
476
Takashi Iwai2b635362011-05-02 12:33:43 +0200477static const hda_nid_t stac927x_slave_dig_outs[2] = {
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500478 0x1f, 0,
479};
480
Takashi Iwai2b635362011-05-02 12:33:43 +0200481static const hda_nid_t stac927x_adc_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100482 0x07, 0x08, 0x09
483};
484
Takashi Iwai2b635362011-05-02 12:33:43 +0200485static const hda_nid_t stac927x_mux_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100486 0x15, 0x16, 0x17
487};
488
Takashi Iwai2b635362011-05-02 12:33:43 +0200489static const hda_nid_t stac927x_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200490 0x21,
491};
492
Takashi Iwai2b635362011-05-02 12:33:43 +0200493static const hda_nid_t stac927x_dac_nids[6] = {
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100494 0x02, 0x03, 0x04, 0x05, 0x06, 0
495};
496
Takashi Iwai2b635362011-05-02 12:33:43 +0200497static const hda_nid_t stac927x_dmux_nids[1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100498 0x1b,
499};
500
Matthew Ranostay7f168592007-10-18 17:38:17 +0200501#define STAC927X_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200502static const hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
Matthew Ranostay7f168592007-10-18 17:38:17 +0200503 0x13, 0x14, 0
504};
505
Takashi Iwai6479c632009-07-28 18:20:25 +0200506#define STAC927X_NUM_CAPS 3
Takashi Iwai2b635362011-05-02 12:33:43 +0200507static const unsigned long stac927x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200508 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
509 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
510 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
511};
Takashi Iwai2b635362011-05-02 12:33:43 +0200512static const unsigned long stac927x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200513 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
514 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
515 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
516};
517
Takashi Iwaiea734962011-01-17 11:29:34 +0100518static const char * const stac927x_spdif_labels[5] = {
Matthew Ranostay65973632008-09-16 10:39:37 -0400519 "Digital Playback", "ADAT", "Analog Mux 1",
520 "Analog Mux 2", "Analog Mux 3"
521};
522
Takashi Iwai2b635362011-05-02 12:33:43 +0200523static const hda_nid_t stac9205_adc_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200524 0x12, 0x13
525};
526
Takashi Iwai2b635362011-05-02 12:33:43 +0200527static const hda_nid_t stac9205_mux_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200528 0x19, 0x1a
529};
530
Takashi Iwai2b635362011-05-02 12:33:43 +0200531static const hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100532 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100533};
534
Takashi Iwai2b635362011-05-02 12:33:43 +0200535static const hda_nid_t stac9205_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200536 0x21,
537};
538
Takashi Iwaif6e98522007-10-16 14:27:04 +0200539#define STAC9205_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200540static const hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200541 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200542};
543
Takashi Iwai6479c632009-07-28 18:20:25 +0200544#define STAC9205_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200545static const unsigned long stac9205_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200546 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
547 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
548};
Takashi Iwai2b635362011-05-02 12:33:43 +0200549static const unsigned long stac9205_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200550 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
551 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
552};
553
Takashi Iwai2b635362011-05-02 12:33:43 +0200554static const hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200555 0x08, 0x09, 0x0d, 0x0e,
556 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200557};
558
Takashi Iwai2b635362011-05-02 12:33:43 +0200559static const hda_nid_t stac925x_pin_nids[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100560 0x07, 0x08, 0x0a, 0x0b,
561 0x0c, 0x0d, 0x10, 0x11,
562};
563
Takashi Iwai2b635362011-05-02 12:33:43 +0200564static const hda_nid_t stac922x_pin_nids[10] = {
Matt2f2f4252005-04-13 14:45:30 +0200565 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
566 0x0f, 0x10, 0x11, 0x15, 0x1b,
567};
568
Takashi Iwai2b635362011-05-02 12:33:43 +0200569static const hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100570 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
571 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200572 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100573};
574
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500575#define STAC92HD71BXX_NUM_PINS 13
Takashi Iwai2b635362011-05-02 12:33:43 +0200576static const hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500577 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
578 0x00, 0x14, 0x18, 0x19, 0x1e,
579 0x1f, 0x20, 0x27
580};
Takashi Iwai2b635362011-05-02 12:33:43 +0200581static const hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100582 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
583 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500584 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100585};
586
Takashi Iwai2b635362011-05-02 12:33:43 +0200587static const hda_nid_t stac927x_pin_nids[14] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100588 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
589 0x0f, 0x10, 0x11, 0x12, 0x13,
590 0x14, 0x21, 0x22, 0x23,
591};
592
Takashi Iwai2b635362011-05-02 12:33:43 +0200593static const hda_nid_t stac9205_pin_nids[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200594 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
595 0x0f, 0x14, 0x16, 0x17, 0x18,
596 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200597};
598
Matt Porter8b657272006-10-26 17:12:59 +0200599static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
600 struct snd_ctl_elem_info *uinfo)
601{
602 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
603 struct sigmatel_spec *spec = codec->spec;
604 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
605}
606
607static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
608 struct snd_ctl_elem_value *ucontrol)
609{
610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
611 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100612 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200613
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100614 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200615 return 0;
616}
617
618static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
619 struct snd_ctl_elem_value *ucontrol)
620{
621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
622 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100623 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200624
625 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100626 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200627}
628
Matthew Ranostayd9737752008-09-07 12:03:41 +0200629static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
630 struct snd_ctl_elem_info *uinfo)
631{
632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633 struct sigmatel_spec *spec = codec->spec;
634 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
635}
636
637static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
638 struct snd_ctl_elem_value *ucontrol)
639{
640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
641 struct sigmatel_spec *spec = codec->spec;
642 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
643
644 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
645 return 0;
646}
647
648static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
650{
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400653 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200654 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400655 int err, val;
656 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200657
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400658 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200659 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400660 if (err < 0)
661 return err;
662
663 if (spec->spdif_mute) {
664 if (smux_idx == 0)
665 nid = spec->multiout.dig_out_nid;
666 else
667 nid = codec->slave_dig_outs[smux_idx - 1];
668 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100669 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400670 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100671 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400672 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100673 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
674 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400675 }
676 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200677}
678
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500679static int stac_vrefout_set(struct hda_codec *codec,
680 hda_nid_t nid, unsigned int new_vref)
681{
682 int error, pinctl;
683
684 snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
685 pinctl = snd_hda_codec_read(codec, nid, 0,
686 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
687
688 if (pinctl < 0)
689 return pinctl;
690
691 pinctl &= 0xff;
692 pinctl &= ~AC_PINCTL_VREFEN;
693 pinctl |= (new_vref & AC_PINCTL_VREFEN);
694
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200695 error = snd_hda_set_pin_ctl_cache(codec, nid, pinctl);
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500696 if (error < 0)
697 return error;
698
699 return 1;
700}
701
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200702static unsigned int stac92xx_vref_set(struct hda_codec *codec,
703 hda_nid_t nid, unsigned int new_vref)
704{
Takashi Iwaib8621512009-06-22 08:00:10 +0200705 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200706 unsigned int pincfg;
707 pincfg = snd_hda_codec_read(codec, nid, 0,
708 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
709
710 pincfg &= 0xff;
711 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
712 pincfg |= new_vref;
713
714 if (new_vref == AC_PINCTL_VREF_HIZ)
715 pincfg |= AC_PINCTL_OUT_EN;
716 else
717 pincfg |= AC_PINCTL_IN_EN;
718
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200719 error = snd_hda_set_pin_ctl_cache(codec, nid, pincfg);
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200720 if (error < 0)
721 return error;
722 else
723 return 1;
724}
725
726static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
727{
728 unsigned int vref;
729 vref = snd_hda_codec_read(codec, nid, 0,
730 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
731 vref &= AC_PINCTL_VREFEN;
732 return vref;
733}
734
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100735static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200736{
737 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
738 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200739 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200740}
741
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100742static int stac92xx_mux_enum_get(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);
747
748 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
749 return 0;
750}
751
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100752static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200753{
754 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
755 struct sigmatel_spec *spec = codec->spec;
756 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200757 const struct hda_input_mux *imux = spec->input_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600758 unsigned int idx, prev_idx, didx;
Matt2f2f4252005-04-13 14:45:30 +0200759
Takashi Iwai5207e102009-07-30 13:09:08 +0200760 idx = ucontrol->value.enumerated.item[0];
761 if (idx >= imux->num_items)
762 idx = imux->num_items - 1;
763 prev_idx = spec->cur_mux[adc_idx];
764 if (prev_idx == idx)
765 return 0;
766 if (idx < spec->num_analog_muxes) {
767 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
768 AC_VERB_SET_CONNECT_SEL,
769 imux->items[idx].index);
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600770 if (prev_idx >= spec->num_analog_muxes &&
771 spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
Takashi Iwai5207e102009-07-30 13:09:08 +0200772 imux = spec->dinput_mux;
773 /* 0 = analog */
774 snd_hda_codec_write_cache(codec,
775 spec->dmux_nids[adc_idx], 0,
776 AC_VERB_SET_CONNECT_SEL,
777 imux->items[0].index);
778 }
779 } else {
780 imux = spec->dinput_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600781 /* first dimux item is hardcoded to select analog imux,
782 * so lets skip it
783 */
784 didx = idx - spec->num_analog_muxes + 1;
Takashi Iwai5207e102009-07-30 13:09:08 +0200785 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
786 AC_VERB_SET_CONNECT_SEL,
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600787 imux->items[didx].index);
Takashi Iwai5207e102009-07-30 13:09:08 +0200788 }
789 spec->cur_mux[adc_idx] = idx;
790 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200791}
792
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100793static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
794 struct snd_ctl_elem_info *uinfo)
795{
796 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
797 struct sigmatel_spec *spec = codec->spec;
798 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
799}
800
801static int stac92xx_mono_mux_enum_get(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 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
808 return 0;
809}
810
811static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
812 struct snd_ctl_elem_value *ucontrol)
813{
814 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
815 struct sigmatel_spec *spec = codec->spec;
816
817 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
818 spec->mono_nid, &spec->cur_mmux);
819}
820
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200821#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
822
823static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
824 struct snd_ctl_elem_value *ucontrol)
825{
826 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100827 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200828 struct sigmatel_spec *spec = codec->spec;
829
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100830 ucontrol->value.integer.value[0] = !!(spec->aloopback &
831 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200832 return 0;
833}
834
835static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
836 struct snd_ctl_elem_value *ucontrol)
837{
838 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
839 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100840 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200841 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100842 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200843
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100844 idx_val = spec->aloopback_mask << idx;
845 if (ucontrol->value.integer.value[0])
846 val = spec->aloopback | idx_val;
847 else
848 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100849 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200850 return 0;
851
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100852 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200853
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100854 /* Only return the bits defined by the shift value of the
855 * first two bytes of the mask
856 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200857 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100858 kcontrol->private_value & 0xFFFF, 0x0);
859 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200860
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100861 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200862 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100863 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200864 } else {
865 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100866 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200867 }
868
869 snd_hda_codec_write_cache(codec, codec->afg, 0,
870 kcontrol->private_value >> 16, dac_mode);
871
872 return 1;
873}
874
Takashi Iwai2b635362011-05-02 12:33:43 +0200875static const struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200876 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200877 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200878 {}
879};
880
Takashi Iwai2b635362011-05-02 12:33:43 +0200881static const struct hda_verb stac9200_eapd_init[] = {
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200882 /* set dac0mux for dac converter */
883 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
884 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
885 {}
886};
887
Takashi Iwai2b635362011-05-02 12:33:43 +0200888static const struct hda_verb dell_eq_core_init[] = {
Matthew Ranostayd654a662008-03-14 08:46:51 +0100889 /* set master volume to max value without distortion
890 * and direct control */
891 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100892 {}
893};
894
Takashi Iwai2b635362011-05-02 12:33:43 +0200895static const struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100896 /* set master volume and direct control */
897 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100898 {}
899};
900
Takashi Iwai2b635362011-05-02 12:33:43 +0200901static const struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200902 /* power state controls amps */
903 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200904 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200905};
906
Vitaliy Kulikov5556e142012-02-27 16:47:37 -0600907static const struct hda_verb stac92hd83xxx_hp_zephyr_init[] = {
908 { 0x22, 0x785, 0x43 },
909 { 0x22, 0x782, 0xe0 },
910 { 0x22, 0x795, 0x00 },
911 {}
912};
913
Takashi Iwai2b635362011-05-02 12:33:43 +0200914static const struct hda_verb stac92hd71bxx_core_init[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100915 /* set master volume and direct control */
916 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200917 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100918};
919
Takashi Iwai2b635362011-05-02 12:33:43 +0200920static const struct hda_verb stac92hd71bxx_unmute_core_init[] = {
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500921 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
922 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100923 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
924 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100925 {}
926};
927
Takashi Iwai2b635362011-05-02 12:33:43 +0200928static const struct hda_verb stac925x_core_init[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100929 /* set dac0mux for dac converter */
930 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100931 /* mute the master volume */
932 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100933 {}
934};
935
Takashi Iwai2b635362011-05-02 12:33:43 +0200936static const struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200937 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200938 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200939 {}
940};
941
Takashi Iwai2b635362011-05-02 12:33:43 +0200942static const struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200943 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200944 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200945 /* unmute node 0x1b */
946 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
947 /* select node 0x03 as DAC */
948 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
949 {}
950};
951
Takashi Iwai2b635362011-05-02 12:33:43 +0200952static const struct hda_verb dell_3st_core_init[] = {
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200953 /* don't set delta bit */
954 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
955 /* unmute node 0x1b */
956 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
957 /* select node 0x03 as DAC */
958 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
959 {}
960};
961
Takashi Iwai2b635362011-05-02 12:33:43 +0200962static const struct hda_verb stac927x_core_init[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100963 /* set master volume and direct control */
964 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200965 /* enable analog pc beep path */
966 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100967 {}
968};
969
Takashi Iwai2b635362011-05-02 12:33:43 +0200970static const struct hda_verb stac927x_volknob_core_init[] = {
Takashi Iwai54930532009-10-11 17:38:29 +0200971 /* don't set delta bit */
972 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
973 /* enable analog pc beep path */
974 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
975 {}
976};
977
Takashi Iwai2b635362011-05-02 12:33:43 +0200978static const struct hda_verb stac9205_core_init[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200979 /* set master volume and direct control */
980 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200981 /* enable analog pc beep path */
982 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200983 {}
984};
985
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100986#define STAC_MONO_MUX \
987 { \
988 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
989 .name = "Mono Mux", \
990 .count = 1, \
991 .info = stac92xx_mono_mux_enum_info, \
992 .get = stac92xx_mono_mux_enum_get, \
993 .put = stac92xx_mono_mux_enum_put, \
994 }
995
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100996#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200997 { \
998 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
999 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001000 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +02001001 .info = stac92xx_aloopback_info, \
1002 .get = stac92xx_aloopback_get, \
1003 .put = stac92xx_aloopback_put, \
1004 .private_value = verb_read | (verb_write << 16), \
1005 }
1006
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02001007#define DC_BIAS(xname, idx, nid) \
1008 { \
1009 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1010 .name = xname, \
1011 .index = idx, \
1012 .info = stac92xx_dc_bias_info, \
1013 .get = stac92xx_dc_bias_get, \
1014 .put = stac92xx_dc_bias_put, \
1015 .private_value = nid, \
1016 }
1017
Takashi Iwai2b635362011-05-02 12:33:43 +02001018static const struct snd_kcontrol_new stac9200_mixer[] = {
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001019 HDA_CODEC_VOLUME_MIN_MUTE("PCM Playback Volume", 0xb, 0, HDA_OUTPUT),
1020 HDA_CODEC_MUTE("PCM Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001021 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1022 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001023 { } /* end */
1024};
1025
Takashi Iwai2b635362011-05-02 12:33:43 +02001026static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001027 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1028 {}
1029};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001030
Takashi Iwai2b635362011-05-02 12:33:43 +02001031static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001032 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1033 {}
1034};
1035
Takashi Iwai2b635362011-05-02 12:33:43 +02001036static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001037 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1038 {}
1039};
1040
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001041
Takashi Iwai2b635362011-05-02 12:33:43 +02001042static const struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001043 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1044};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001045
Takashi Iwai2b635362011-05-02 12:33:43 +02001046static const struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001047 HDA_CODEC_VOLUME_MIN_MUTE("PCM Playback Volume", 0xe, 0, HDA_OUTPUT),
1048 HDA_CODEC_MUTE("PCM Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001049 { } /* end */
1050};
1051
Takashi Iwai2b635362011-05-02 12:33:43 +02001052static const struct snd_kcontrol_new stac9205_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001053 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1054 {}
1055};
1056
Takashi Iwai2b635362011-05-02 12:33:43 +02001057static const struct snd_kcontrol_new stac927x_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001058 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1059 {}
1060};
1061
Takashi Iwai1697055e2007-12-18 18:05:52 +01001062static struct snd_kcontrol_new stac_dmux_mixer = {
1063 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1064 .name = "Digital Input Source",
1065 /* count set later */
1066 .info = stac92xx_dmux_enum_info,
1067 .get = stac92xx_dmux_enum_get,
1068 .put = stac92xx_dmux_enum_put,
1069};
1070
Matthew Ranostayd9737752008-09-07 12:03:41 +02001071static struct snd_kcontrol_new stac_smux_mixer = {
1072 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001073 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001074 /* count set later */
1075 .info = stac92xx_smux_enum_info,
1076 .get = stac92xx_smux_enum_get,
1077 .put = stac92xx_smux_enum_put,
1078};
1079
Takashi Iwai9322ca52012-02-03 14:28:01 +01001080static const char * const slave_pfxs[] = {
1081 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01001082 "Headphone", "Speaker", "Bass Speaker", "IEC958", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001083 NULL
1084};
1085
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001086static void stac92xx_update_led_status(struct hda_codec *codec, int enabled);
1087
1088static void stac92xx_vmaster_hook(void *private_data, int val)
1089{
1090 stac92xx_update_led_status(private_data, val);
1091}
1092
Takashi Iwai603c4012008-07-30 15:01:44 +02001093static void stac92xx_free_kctls(struct hda_codec *codec);
1094
Matt2f2f4252005-04-13 14:45:30 +02001095static int stac92xx_build_controls(struct hda_codec *codec)
1096{
1097 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001098 unsigned int vmaster_tlv[4];
Matt2f2f4252005-04-13 14:45:30 +02001099 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001100 int i;
Matt2f2f4252005-04-13 14:45:30 +02001101
Takashi Iwai6479c632009-07-28 18:20:25 +02001102 if (spec->mixer) {
1103 err = snd_hda_add_new_ctls(codec, spec->mixer);
1104 if (err < 0)
1105 return err;
1106 }
Mattc7d4b2f2005-06-27 14:59:41 +02001107
1108 for (i = 0; i < spec->num_mixers; i++) {
1109 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1110 if (err < 0)
1111 return err;
1112 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001113 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1114 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001115 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001116 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001117 snd_ctl_new1(&stac_dmux_mixer, codec));
1118 if (err < 0)
1119 return err;
1120 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001121 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001122 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1123 struct hda_input_mux *smux = &spec->private_smux;
1124 /* check for mute support on SPDIF out */
1125 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001126 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001127 spec->spdif_mute = 1;
1128 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001129 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001130 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001131 snd_ctl_new1(&stac_smux_mixer, codec));
1132 if (err < 0)
1133 return err;
1134 }
Mattc7d4b2f2005-06-27 14:59:41 +02001135
Mattdabbed62005-06-14 10:19:34 +02001136 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001137 err = snd_hda_create_dig_out_ctls(codec,
1138 spec->multiout.dig_out_nid,
1139 spec->multiout.dig_out_nid,
1140 spec->autocfg.dig_out_type[0]);
Mattdabbed62005-06-14 10:19:34 +02001141 if (err < 0)
1142 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001143 err = snd_hda_create_spdif_share_sw(codec,
1144 &spec->multiout);
1145 if (err < 0)
1146 return err;
1147 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001148 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001149 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001150 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1151 if (err < 0)
1152 return err;
1153 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001154
1155 /* if we have no master control, let's create it */
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001156 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1157 HDA_OUTPUT, vmaster_tlv);
1158 /* correct volume offset */
1159 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1160 /* minimum value is actually mute */
1161 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
1162 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1163 vmaster_tlv, slave_pfxs,
1164 "Playback Volume");
1165 if (err < 0)
1166 return err;
1167
1168 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1169 NULL, slave_pfxs,
1170 "Playback Switch", true,
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001171 &spec->vmaster_mute.sw_kctl);
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001172 if (err < 0)
1173 return err;
1174
1175 if (spec->gpio_led) {
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001176 spec->vmaster_mute.hook = stac92xx_vmaster_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01001177 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001178 if (err < 0)
1179 return err;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001180 }
1181
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001182 if (spec->aloopback_ctl &&
1183 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1184 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1185 if (err < 0)
1186 return err;
1187 }
1188
Takashi Iwai603c4012008-07-30 15:01:44 +02001189 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001190
Takashi Iwai01a61e12011-10-28 00:03:22 +02001191 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1192 if (err < 0)
1193 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001194
Mattdabbed62005-06-14 10:19:34 +02001195 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001196}
1197
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001198static const struct hda_pintbl ref9200_pin_configs[] = {
1199 { 0x08, 0x01c47010 },
1200 { 0x09, 0x01447010 },
1201 { 0x0d, 0x0221401f },
1202 { 0x0e, 0x01114010 },
1203 { 0x0f, 0x02a19020 },
1204 { 0x10, 0x01a19021 },
1205 { 0x11, 0x90100140 },
1206 { 0x12, 0x01813122 },
1207 {}
Matt2f2f4252005-04-13 14:45:30 +02001208};
1209
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001210static const struct hda_pintbl gateway9200_m4_pin_configs[] = {
1211 { 0x08, 0x400000fe },
1212 { 0x09, 0x404500f4 },
1213 { 0x0d, 0x400100f0 },
1214 { 0x0e, 0x90110010 },
1215 { 0x0f, 0x400100f1 },
1216 { 0x10, 0x02a1902e },
1217 { 0x11, 0x500000f2 },
1218 { 0x12, 0x500000f3 },
1219 {}
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001220};
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001221
1222static const struct hda_pintbl gateway9200_m4_2_pin_configs[] = {
1223 { 0x08, 0x400000fe },
1224 { 0x09, 0x404500f4 },
1225 { 0x0d, 0x400100f0 },
1226 { 0x0e, 0x90110010 },
1227 { 0x0f, 0x400100f1 },
1228 { 0x10, 0x02a1902e },
1229 { 0x11, 0x500000f2 },
1230 { 0x12, 0x500000f3 },
1231 {}
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001232};
1233
1234/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001235 STAC 9200 pin configs for
1236 102801A8
1237 102801DE
1238 102801E8
1239*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001240static const struct hda_pintbl dell9200_d21_pin_configs[] = {
1241 { 0x08, 0x400001f0 },
1242 { 0x09, 0x400001f1 },
1243 { 0x0d, 0x02214030 },
1244 { 0x0e, 0x01014010 },
1245 { 0x0f, 0x02a19020 },
1246 { 0x10, 0x01a19021 },
1247 { 0x11, 0x90100140 },
1248 { 0x12, 0x01813122 },
1249 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001250};
1251
1252/*
1253 STAC 9200 pin configs for
1254 102801C0
1255 102801C1
1256*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001257static const struct hda_pintbl dell9200_d22_pin_configs[] = {
1258 { 0x08, 0x400001f0 },
1259 { 0x09, 0x400001f1 },
1260 { 0x0d, 0x0221401f },
1261 { 0x0e, 0x01014010 },
1262 { 0x0f, 0x01813020 },
1263 { 0x10, 0x02a19021 },
1264 { 0x11, 0x90100140 },
1265 { 0x12, 0x400001f2 },
1266 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001267};
1268
1269/*
1270 STAC 9200 pin configs for
1271 102801C4 (Dell Dimension E310)
1272 102801C5
1273 102801C7
1274 102801D9
1275 102801DA
1276 102801E3
1277*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001278static const struct hda_pintbl dell9200_d23_pin_configs[] = {
1279 { 0x08, 0x400001f0 },
1280 { 0x09, 0x400001f1 },
1281 { 0x0d, 0x0221401f },
1282 { 0x0e, 0x01014010 },
1283 { 0x0f, 0x01813020 },
1284 { 0x10, 0x01a19021 },
1285 { 0x11, 0x90100140 },
1286 { 0x12, 0x400001f2 },
1287 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001288};
1289
1290
1291/*
1292 STAC 9200-32 pin configs for
1293 102801B5 (Dell Inspiron 630m)
1294 102801D8 (Dell Inspiron 640m)
1295*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001296static const struct hda_pintbl dell9200_m21_pin_configs[] = {
1297 { 0x08, 0x40c003fa },
1298 { 0x09, 0x03441340 },
1299 { 0x0d, 0x0321121f },
1300 { 0x0e, 0x90170310 },
1301 { 0x0f, 0x408003fb },
1302 { 0x10, 0x03a11020 },
1303 { 0x11, 0x401003fc },
1304 { 0x12, 0x403003fd },
1305 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001306};
1307
1308/*
1309 STAC 9200-32 pin configs for
1310 102801C2 (Dell Latitude D620)
1311 102801C8
1312 102801CC (Dell Latitude D820)
1313 102801D4
1314 102801D6
1315*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001316static const struct hda_pintbl dell9200_m22_pin_configs[] = {
1317 { 0x08, 0x40c003fa },
1318 { 0x09, 0x0144131f },
1319 { 0x0d, 0x0321121f },
1320 { 0x0e, 0x90170310 },
1321 { 0x0f, 0x90a70321 },
1322 { 0x10, 0x03a11020 },
1323 { 0x11, 0x401003fb },
1324 { 0x12, 0x40f000fc },
1325 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001326};
1327
1328/*
1329 STAC 9200-32 pin configs for
1330 102801CE (Dell XPS M1710)
1331 102801CF (Dell Precision M90)
1332*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001333static const struct hda_pintbl dell9200_m23_pin_configs[] = {
1334 { 0x08, 0x40c003fa },
1335 { 0x09, 0x01441340 },
1336 { 0x0d, 0x0421421f },
1337 { 0x0e, 0x90170310 },
1338 { 0x0f, 0x408003fb },
1339 { 0x10, 0x04a1102e },
1340 { 0x11, 0x90170311 },
1341 { 0x12, 0x403003fc },
1342 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001343};
1344
1345/*
1346 STAC 9200-32 pin configs for
1347 102801C9
1348 102801CA
1349 102801CB (Dell Latitude 120L)
1350 102801D3
1351*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001352static const struct hda_pintbl dell9200_m24_pin_configs[] = {
1353 { 0x08, 0x40c003fa },
1354 { 0x09, 0x404003fb },
1355 { 0x0d, 0x0321121f },
1356 { 0x0e, 0x90170310 },
1357 { 0x0f, 0x408003fc },
1358 { 0x10, 0x03a11020 },
1359 { 0x11, 0x401003fd },
1360 { 0x12, 0x403003fe },
1361 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001362};
1363
1364/*
1365 STAC 9200-32 pin configs for
1366 102801BD (Dell Inspiron E1505n)
1367 102801EE
1368 102801EF
1369*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001370static const struct hda_pintbl dell9200_m25_pin_configs[] = {
1371 { 0x08, 0x40c003fa },
1372 { 0x09, 0x01441340 },
1373 { 0x0d, 0x0421121f },
1374 { 0x0e, 0x90170310 },
1375 { 0x0f, 0x408003fb },
1376 { 0x10, 0x04a11020 },
1377 { 0x11, 0x401003fc },
1378 { 0x12, 0x403003fd },
1379 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001380};
1381
1382/*
1383 STAC 9200-32 pin configs for
1384 102801F5 (Dell Inspiron 1501)
1385 102801F6
1386*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001387static const struct hda_pintbl dell9200_m26_pin_configs[] = {
1388 { 0x08, 0x40c003fa },
1389 { 0x09, 0x404003fb },
1390 { 0x0d, 0x0421121f },
1391 { 0x0e, 0x90170310 },
1392 { 0x0f, 0x408003fc },
1393 { 0x10, 0x04a11020 },
1394 { 0x11, 0x401003fd },
1395 { 0x12, 0x403003fe },
1396 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001397};
1398
1399/*
1400 STAC 9200-32
1401 102801CD (Dell Inspiron E1705/9400)
1402*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001403static const struct hda_pintbl dell9200_m27_pin_configs[] = {
1404 { 0x08, 0x40c003fa },
1405 { 0x09, 0x01441340 },
1406 { 0x0d, 0x0421121f },
1407 { 0x0e, 0x90170310 },
1408 { 0x0f, 0x90170310 },
1409 { 0x10, 0x04a11020 },
1410 { 0x11, 0x90170310 },
1411 { 0x12, 0x40f003fc },
1412 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001413};
1414
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001415static const struct hda_pintbl oqo9200_pin_configs[] = {
1416 { 0x08, 0x40c000f0 },
1417 { 0x09, 0x404000f1 },
1418 { 0x0d, 0x0221121f },
1419 { 0x0e, 0x02211210 },
1420 { 0x0f, 0x90170111 },
1421 { 0x10, 0x90a70120 },
1422 { 0x11, 0x400000f2 },
1423 { 0x12, 0x400000f3 },
1424 {}
Tobin Davisbf277782008-02-03 20:31:47 +01001425};
1426
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001427
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001428static void stac9200_fixup_panasonic(struct hda_codec *codec,
1429 const struct hda_fixup *fix, int action)
1430{
1431 struct sigmatel_spec *spec = codec->spec;
1432
1433 switch (action) {
1434 case HDA_FIXUP_ACT_PRE_PROBE:
1435 spec->gpio_mask = spec->gpio_dir = 0x09;
1436 spec->gpio_data = 0x00;
1437 break;
1438 case HDA_FIXUP_ACT_PROBE:
1439 /* CF-74 has no headphone detection, and the driver should *NOT*
1440 * do detection and HP/speaker toggle because the hardware does it.
1441 */
1442 spec->hp_detect = 0;
1443 break;
1444 }
1445}
1446
1447
1448static const struct hda_fixup stac9200_fixups[] = {
1449 [STAC_REF] = {
1450 .type = HDA_FIXUP_PINS,
1451 .v.pins = ref9200_pin_configs,
1452 },
1453 [STAC_9200_OQO] = {
1454 .type = HDA_FIXUP_PINS,
1455 .v.pins = oqo9200_pin_configs,
1456 .chained = true,
1457 .chain_id = STAC_9200_EAPD_INIT,
1458 },
1459 [STAC_9200_DELL_D21] = {
1460 .type = HDA_FIXUP_PINS,
1461 .v.pins = dell9200_d21_pin_configs,
1462 },
1463 [STAC_9200_DELL_D22] = {
1464 .type = HDA_FIXUP_PINS,
1465 .v.pins = dell9200_d22_pin_configs,
1466 },
1467 [STAC_9200_DELL_D23] = {
1468 .type = HDA_FIXUP_PINS,
1469 .v.pins = dell9200_d23_pin_configs,
1470 },
1471 [STAC_9200_DELL_M21] = {
1472 .type = HDA_FIXUP_PINS,
1473 .v.pins = dell9200_m21_pin_configs,
1474 },
1475 [STAC_9200_DELL_M22] = {
1476 .type = HDA_FIXUP_PINS,
1477 .v.pins = dell9200_m22_pin_configs,
1478 },
1479 [STAC_9200_DELL_M23] = {
1480 .type = HDA_FIXUP_PINS,
1481 .v.pins = dell9200_m23_pin_configs,
1482 },
1483 [STAC_9200_DELL_M24] = {
1484 .type = HDA_FIXUP_PINS,
1485 .v.pins = dell9200_m24_pin_configs,
1486 },
1487 [STAC_9200_DELL_M25] = {
1488 .type = HDA_FIXUP_PINS,
1489 .v.pins = dell9200_m25_pin_configs,
1490 },
1491 [STAC_9200_DELL_M26] = {
1492 .type = HDA_FIXUP_PINS,
1493 .v.pins = dell9200_m26_pin_configs,
1494 },
1495 [STAC_9200_DELL_M27] = {
1496 .type = HDA_FIXUP_PINS,
1497 .v.pins = dell9200_m27_pin_configs,
1498 },
1499 [STAC_9200_M4] = {
1500 .type = HDA_FIXUP_PINS,
1501 .v.pins = gateway9200_m4_pin_configs,
1502 .chained = true,
1503 .chain_id = STAC_9200_EAPD_INIT,
1504 },
1505 [STAC_9200_M4_2] = {
1506 .type = HDA_FIXUP_PINS,
1507 .v.pins = gateway9200_m4_2_pin_configs,
1508 .chained = true,
1509 .chain_id = STAC_9200_EAPD_INIT,
1510 },
1511 [STAC_9200_PANASONIC] = {
1512 .type = HDA_FIXUP_FUNC,
1513 .v.func = stac9200_fixup_panasonic,
1514 },
1515 [STAC_9200_EAPD_INIT] = {
1516 .type = HDA_FIXUP_VERBS,
1517 .v.verbs = (const struct hda_verb[]) {
1518 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1519 {}
1520 },
1521 },
Matt Porter403d1942005-11-29 15:00:51 +01001522};
1523
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001524static const struct hda_model_fixup stac9200_models[] = {
1525 { .id = STAC_REF, .name = "ref" },
1526 { .id = STAC_9200_OQO, .name = "oqo" },
1527 { .id = STAC_9200_DELL_D21, .name = "dell-d21" },
1528 { .id = STAC_9200_DELL_D22, .name = "dell-d22" },
1529 { .id = STAC_9200_DELL_D23, .name = "dell-d23" },
1530 { .id = STAC_9200_DELL_M21, .name = "dell-m21" },
1531 { .id = STAC_9200_DELL_M22, .name = "dell-m22" },
1532 { .id = STAC_9200_DELL_M23, .name = "dell-m23" },
1533 { .id = STAC_9200_DELL_M24, .name = "dell-m24" },
1534 { .id = STAC_9200_DELL_M25, .name = "dell-m25" },
1535 { .id = STAC_9200_DELL_M26, .name = "dell-m26" },
1536 { .id = STAC_9200_DELL_M27, .name = "dell-m27" },
1537 { .id = STAC_9200_M4, .name = "gateway-m4" },
1538 { .id = STAC_9200_M4_2, .name = "gateway-m4-2" },
1539 { .id = STAC_9200_PANASONIC, .name = "panasonic" },
1540 {}
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001541};
1542
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001543static const struct snd_pci_quirk stac9200_fixup_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001544 /* SigmaTel reference board */
1545 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1546 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001547 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1548 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001549 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001550 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1551 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001552 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001553 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1554 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1555 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1556 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1557 "unknown Dell", STAC_9200_DELL_D22),
1558 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1559 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001560 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001561 "Dell Latitude D620", STAC_9200_DELL_M22),
1562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1563 "unknown Dell", STAC_9200_DELL_D23),
1564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1565 "unknown Dell", STAC_9200_DELL_D23),
1566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1567 "unknown Dell", STAC_9200_DELL_M22),
1568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1569 "unknown Dell", STAC_9200_DELL_M24),
1570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1571 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001573 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001575 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001577 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001578 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001579 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001581 "Dell Precision M90", STAC_9200_DELL_M23),
1582 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1583 "unknown Dell", STAC_9200_DELL_M22),
1584 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1585 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001586 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001587 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001588 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001589 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1591 "unknown Dell", STAC_9200_DELL_D23),
1592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1593 "unknown Dell", STAC_9200_DELL_D23),
1594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1595 "unknown Dell", STAC_9200_DELL_D21),
1596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1597 "unknown Dell", STAC_9200_DELL_D23),
1598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1599 "unknown Dell", STAC_9200_DELL_D21),
1600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1601 "unknown Dell", STAC_9200_DELL_M25),
1602 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1603 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001604 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001605 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1606 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1607 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001608 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001609 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001610 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001611 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1612 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1613 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001614 /* OQO Mobile */
1615 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001616 {} /* terminator */
1617};
1618
Takashi Iwaid2077d42013-01-14 14:20:16 +01001619static const struct hda_pintbl ref925x_pin_configs[] = {
1620 { 0x07, 0x40c003f0 },
1621 { 0x08, 0x424503f2 },
1622 { 0x0a, 0x01813022 },
1623 { 0x0b, 0x02a19021 },
1624 { 0x0c, 0x90a70320 },
1625 { 0x0d, 0x02214210 },
1626 { 0x10, 0x01019020 },
1627 { 0x11, 0x9033032e },
1628 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001629};
1630
Takashi Iwaid2077d42013-01-14 14:20:16 +01001631static const struct hda_pintbl stac925xM1_pin_configs[] = {
1632 { 0x07, 0x40c003f4 },
1633 { 0x08, 0x424503f2 },
1634 { 0x0a, 0x400000f3 },
1635 { 0x0b, 0x02a19020 },
1636 { 0x0c, 0x40a000f0 },
1637 { 0x0d, 0x90100210 },
1638 { 0x10, 0x400003f1 },
1639 { 0x11, 0x9033032e },
1640 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001641};
1642
Takashi Iwaid2077d42013-01-14 14:20:16 +01001643static const struct hda_pintbl stac925xM1_2_pin_configs[] = {
1644 { 0x07, 0x40c003f4 },
1645 { 0x08, 0x424503f2 },
1646 { 0x0a, 0x400000f3 },
1647 { 0x0b, 0x02a19020 },
1648 { 0x0c, 0x40a000f0 },
1649 { 0x0d, 0x90100210 },
1650 { 0x10, 0x400003f1 },
1651 { 0x11, 0x9033032e },
1652 {}
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001653};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001654
Takashi Iwaid2077d42013-01-14 14:20:16 +01001655static const struct hda_pintbl stac925xM2_pin_configs[] = {
1656 { 0x07, 0x40c003f4 },
1657 { 0x08, 0x424503f2 },
1658 { 0x0a, 0x400000f3 },
1659 { 0x0b, 0x02a19020 },
1660 { 0x0c, 0x40a000f0 },
1661 { 0x0d, 0x90100210 },
1662 { 0x10, 0x400003f1 },
1663 { 0x11, 0x9033032e },
1664 {}
Tobin Davis2c11f952007-05-17 09:36:34 +02001665};
1666
Takashi Iwaid2077d42013-01-14 14:20:16 +01001667static const struct hda_pintbl stac925xM2_2_pin_configs[] = {
1668 { 0x07, 0x40c003f4 },
1669 { 0x08, 0x424503f2 },
1670 { 0x0a, 0x400000f3 },
1671 { 0x0b, 0x02a19020 },
1672 { 0x0c, 0x40a000f0 },
1673 { 0x0d, 0x90100210 },
1674 { 0x10, 0x400003f1 },
1675 { 0x11, 0x9033032e },
1676 {}
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001677};
1678
Takashi Iwaid2077d42013-01-14 14:20:16 +01001679static const struct hda_pintbl stac925xM3_pin_configs[] = {
1680 { 0x07, 0x40c003f4 },
1681 { 0x08, 0x424503f2 },
1682 { 0x0a, 0x400000f3 },
1683 { 0x0b, 0x02a19020 },
1684 { 0x0c, 0x40a000f0 },
1685 { 0x0d, 0x90100210 },
1686 { 0x10, 0x400003f1 },
1687 { 0x11, 0x503303f3 },
1688 {}
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001689};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001690
Takashi Iwaid2077d42013-01-14 14:20:16 +01001691static const struct hda_pintbl stac925xM5_pin_configs[] = {
1692 { 0x07, 0x40c003f4 },
1693 { 0x08, 0x424503f2 },
1694 { 0x0a, 0x400000f3 },
1695 { 0x0b, 0x02a19020 },
1696 { 0x0c, 0x40a000f0 },
1697 { 0x0d, 0x90100210 },
1698 { 0x10, 0x400003f1 },
1699 { 0x11, 0x9033032e },
1700 {}
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001701};
1702
Takashi Iwaid2077d42013-01-14 14:20:16 +01001703static const struct hda_pintbl stac925xM6_pin_configs[] = {
1704 { 0x07, 0x40c003f4 },
1705 { 0x08, 0x424503f2 },
1706 { 0x0a, 0x400000f3 },
1707 { 0x0b, 0x02a19020 },
1708 { 0x0c, 0x40a000f0 },
1709 { 0x0d, 0x90100210 },
1710 { 0x10, 0x400003f1 },
1711 { 0x11, 0x90330320 },
1712 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001713};
1714
Takashi Iwaid2077d42013-01-14 14:20:16 +01001715static const struct hda_fixup stac925x_fixups[] = {
1716 [STAC_REF] = {
1717 .type = HDA_FIXUP_PINS,
1718 .v.pins = ref925x_pin_configs,
1719 },
1720 [STAC_M1] = {
1721 .type = HDA_FIXUP_PINS,
1722 .v.pins = stac925xM1_pin_configs,
1723 },
1724 [STAC_M1_2] = {
1725 .type = HDA_FIXUP_PINS,
1726 .v.pins = stac925xM1_2_pin_configs,
1727 },
1728 [STAC_M2] = {
1729 .type = HDA_FIXUP_PINS,
1730 .v.pins = stac925xM2_pin_configs,
1731 },
1732 [STAC_M2_2] = {
1733 .type = HDA_FIXUP_PINS,
1734 .v.pins = stac925xM2_2_pin_configs,
1735 },
1736 [STAC_M3] = {
1737 .type = HDA_FIXUP_PINS,
1738 .v.pins = stac925xM3_pin_configs,
1739 },
1740 [STAC_M5] = {
1741 .type = HDA_FIXUP_PINS,
1742 .v.pins = stac925xM5_pin_configs,
1743 },
1744 [STAC_M6] = {
1745 .type = HDA_FIXUP_PINS,
1746 .v.pins = stac925xM6_pin_configs,
1747 },
Tobin Davis8e21c342007-01-08 11:04:17 +01001748};
1749
Takashi Iwaid2077d42013-01-14 14:20:16 +01001750static const struct hda_model_fixup stac925x_models[] = {
1751 { .id = STAC_REF, .name = "ref" },
1752 { .id = STAC_M1, .name = "m1" },
1753 { .id = STAC_M1_2, .name = "m1-2" },
1754 { .id = STAC_M2, .name = "m2" },
1755 { .id = STAC_M2_2, .name = "m2-2" },
1756 { .id = STAC_M3, .name = "m3" },
1757 { .id = STAC_M5, .name = "m5" },
1758 { .id = STAC_M6, .name = "m6" },
1759 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001760};
1761
Takashi Iwaid2077d42013-01-14 14:20:16 +01001762static const struct snd_pci_quirk stac925x_fixup_tbl[] = {
1763 /* SigmaTel reference board */
1764 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1765 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1766 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1767
1768 /* Default table for unknown ID */
1769 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1770
1771 /* gateway machines are checked via codec ssid */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001772 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1773 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1774 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1775 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001776 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001777 /* Not sure about the brand name for those */
1778 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1779 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1780 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1781 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001782 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001783};
1784
Takashi Iwai2b635362011-05-02 12:33:43 +02001785static const unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001786 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1787 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1788 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001789 0x01452050,
1790};
1791
Takashi Iwai2b635362011-05-02 12:33:43 +02001792static const unsigned int dell_m6_pin_configs[13] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001793 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001794 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001795 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1796 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001797};
1798
Takashi Iwai2b635362011-05-02 12:33:43 +02001799static const unsigned int alienware_m17x_pin_configs[13] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001800 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1801 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1802 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1803 0x904601b0,
1804};
1805
Takashi Iwai2b635362011-05-02 12:33:43 +02001806static const unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001807 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001808 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001809};
1810
Takashi Iwai2b635362011-05-02 12:33:43 +02001811static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001812 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001813 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1814 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1815 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001816 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001817 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001818 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001819};
1820
Takashi Iwaiea734962011-01-17 11:29:34 +01001821static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001822 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001823 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001824 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001825 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001826 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1827 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1828 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001829 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001830 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001831};
1832
Takashi Iwai2b635362011-05-02 12:33:43 +02001833static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001834 /* SigmaTel reference board */
1835 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001836 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001837 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1838 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001839 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1840 "Intel DG45ID", STAC_92HD73XX_INTEL),
1841 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1842 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001843 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001844 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001845 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001846 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001847 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001848 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001849 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001850 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001851 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001852 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001853 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001854 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001855 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001856 "unknown Dell", STAC_DELL_M6_DMIC),
1857 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1858 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001859 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001860 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001861 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1862 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001863 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1864 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001865 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1866 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001867 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
David Henningssonffe535e2012-01-16 10:52:20 +01001868 "Dell Studio XPS 1645", STAC_DELL_M6_DMIC),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001869 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
David Henningssone033ebf2011-05-16 12:09:29 +02001870 "Dell Studio 1558", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001871 {} /* terminator */
1872};
1873
Takashi Iwai2b635362011-05-02 12:33:43 +02001874static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001875 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1876 "Alienware M17x", STAC_ALIENWARE_M17X),
Daniel T Chen0defe092010-12-01 19:16:07 -05001877 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1878 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwaidbd1b542011-11-19 11:41:30 +01001879 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490,
Albert Poolb9ecc4e2012-01-19 22:08:50 +01001880 "Alienware M17x R3", STAC_DELL_EQ),
Takashi Iwai842ae632009-09-02 07:43:08 +02001881 {} /* terminator */
1882};
1883
Takashi Iwai2b635362011-05-02 12:33:43 +02001884static const unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001885 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1886 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001887 0x01451160, 0x98560170,
1888};
1889
Takashi Iwai2b635362011-05-02 12:33:43 +02001890static const unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001891 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1892 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001893 0x40f000f0, 0x40f000f0,
1894};
1895
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001896static const unsigned int dell_vostro_3500_pin_configs[10] = {
1897 0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
1898 0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
1899 0x400000f4, 0x400000f5,
1900};
1901
Takashi Iwai2b635362011-05-02 12:33:43 +02001902static const unsigned int hp_dv7_4000_pin_configs[10] = {
Steven Eastland48315592010-08-06 15:07:35 -06001903 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1904 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1905 0x40f000f0, 0x40f000f0,
1906};
1907
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06001908static const unsigned int hp_zephyr_pin_configs[10] = {
1909 0x01813050, 0x0421201f, 0x04a1205e, 0x96130310,
1910 0x96130310, 0x0101401f, 0x1111611f, 0xd5a30130,
1911 0, 0,
1912};
1913
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001914static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
1915 0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
1916 0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
1917 0x40f000f0, 0x40f000f0,
1918};
1919
Takashi Iwai2b635362011-05-02 12:33:43 +02001920static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001921 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001922 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001923 [STAC_DELL_S14] = dell_s14_pin_configs,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001924 [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001925 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001926 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06001927 [STAC_HP_ZEPHYR] = hp_zephyr_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001928};
1929
Takashi Iwaiea734962011-01-17 11:29:34 +01001930static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001931 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001932 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001933 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001934 [STAC_DELL_S14] = "dell-s14",
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001935 [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001936 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
Steven Eastland48315592010-08-06 15:07:35 -06001937 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06001938 [STAC_HP_ZEPHYR] = "hp-zephyr",
Takashi Iwaia3e19972012-07-26 08:17:20 +02001939 [STAC_92HD83XXX_HP_LED] = "hp-led",
Takashi Iwaiff8a1e22012-07-31 10:16:59 +02001940 [STAC_92HD83XXX_HP_INV_LED] = "hp-inv-led",
Takashi Iwai62cbde12012-09-14 11:58:54 +02001941 [STAC_92HD83XXX_HP_MIC_LED] = "hp-mic-led",
David Henningsson8d032a82012-10-09 12:48:40 +02001942 [STAC_92HD83XXX_HEADSET_JACK] = "headset-jack",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001943};
1944
Takashi Iwai2b635362011-05-02 12:33:43 +02001945static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001946 /* SigmaTel reference board */
1947 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001948 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001949 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1950 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001951 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1952 "unknown Dell", STAC_DELL_S14),
David Henningsson8d032a82012-10-09 12:48:40 +02001953 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0532,
1954 "Dell Latitude E6230", STAC_92HD83XXX_HEADSET_JACK),
1955 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0533,
1956 "Dell Latitude E6330", STAC_92HD83XXX_HEADSET_JACK),
1957 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0534,
1958 "Dell Latitude E6430", STAC_92HD83XXX_HEADSET_JACK),
1959 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0535,
1960 "Dell Latitude E6530", STAC_92HD83XXX_HEADSET_JACK),
1961 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x053c,
1962 "Dell Latitude E5430", STAC_92HD83XXX_HEADSET_JACK),
1963 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x053d,
1964 "Dell Latitude E5530", STAC_92HD83XXX_HEADSET_JACK),
1965 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0549,
1966 "Dell Latitude E5430", STAC_92HD83XXX_HEADSET_JACK),
1967 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x057d,
1968 "Dell Latitude E6430s", STAC_92HD83XXX_HEADSET_JACK),
1969 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0584,
1970 "Dell Latitude E6430U", STAC_92HD83XXX_HEADSET_JACK),
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001971 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
1972 "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001973 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
1974 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1975 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
1976 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
1978 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1979 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
Takashi Iwai8ae58652012-12-13 14:33:42 +01001980 "HP Pavilion dv7", STAC_HP_DV7_4000),
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001981 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
1982 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1983 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1984 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Takashi Iwai62cbde12012-09-14 11:58:54 +02001985 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18df,
1986 "HP Folio", STAC_92HD83XXX_HP_MIC_LED),
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001987 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1988 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1989 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
1990 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1991 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
1992 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1993 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
1994 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1995 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
1996 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1997 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
1998 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1999 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
2000 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2001 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
2002 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2003 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
2004 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2005 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
2006 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2007 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
2008 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2009 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
2010 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2011 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
2012 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
2014 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06002015 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3561,
2016 "HP", STAC_HP_ZEPHYR),
Takashi Iwaia3e19972012-07-26 08:17:20 +02002017 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3660,
2018 "HP Mini", STAC_92HD83XXX_HP_LED),
Gustavo Maciel Dias Vieira5afc13a2012-10-26 12:51:53 -02002019 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x144E,
2020 "HP Pavilion dv5", STAC_92HD83XXX_HP_INV_LED),
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06002021 {} /* terminator */
2022};
2023
2024static const struct snd_pci_quirk stac92hd83xxx_codec_id_cfg_tbl[] = {
2025 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3561,
2026 "HP", STAC_HP_ZEPHYR),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02002027 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02002028};
2029
Takashi Iwai2b635362011-05-02 12:33:43 +02002030static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01002031 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04002032 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002033 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
2034 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01002035};
2036
Takashi Iwai2b635362011-05-02 12:33:43 +02002037static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01002038 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01002039 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002040 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
2041 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01002042};
2043
Takashi Iwai2b635362011-05-02 12:33:43 +02002044static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01002045 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
2046 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002047 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
2048 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01002049};
2050
Takashi Iwai2b635362011-05-02 12:33:43 +02002051static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002052 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
2053 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002054 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
2055 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002056};
2057
Takashi Iwai2b635362011-05-02 12:33:43 +02002058static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01002059 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01002060 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
2061 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002062 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04002063 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02002064 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01002065 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01002066 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04002067 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01002068};
2069
Takashi Iwaiea734962011-01-17 11:29:34 +01002070static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002071 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01002072 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01002073 [STAC_DELL_M4_1] = "dell-m4-1",
2074 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002075 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04002076 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02002077 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01002078 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01002079 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04002080 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01002081};
2082
Takashi Iwai2b635362011-05-02 12:33:43 +02002083static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01002084 /* SigmaTel reference board */
2085 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2086 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002087 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2088 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04002089 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
2090 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01002091 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
2092 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01002093 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
2094 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01002095 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02002096 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01002097 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
2098 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01002099 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
2100 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04002101 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01002102 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01002103 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01002104 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02002105 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
2106 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05302107 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
2108 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11002109 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
2110 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02002111 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
2112 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01002113 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
2114 "unknown Dell", STAC_DELL_M4_1),
2115 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
2116 "unknown Dell", STAC_DELL_M4_1),
2117 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
2118 "unknown Dell", STAC_DELL_M4_1),
2119 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
2120 "unknown Dell", STAC_DELL_M4_1),
2121 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
2122 "unknown Dell", STAC_DELL_M4_1),
2123 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
2124 "unknown Dell", STAC_DELL_M4_1),
2125 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
2126 "unknown Dell", STAC_DELL_M4_1),
2127 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
2128 "unknown Dell", STAC_DELL_M4_2),
2129 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
2130 "unknown Dell", STAC_DELL_M4_2),
2131 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
2132 "unknown Dell", STAC_DELL_M4_2),
2133 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
2134 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002135 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
2136 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01002137 {} /* terminator */
2138};
2139
Takashi Iwai2b635362011-05-02 12:33:43 +02002140static const unsigned int ref922x_pin_configs[10] = {
Matt Porter403d1942005-11-29 15:00:51 +01002141 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
2142 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02002143 0x40000100, 0x40000100,
2144};
2145
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002146/*
2147 STAC 922X pin configs for
2148 102801A7
2149 102801AB
2150 102801A9
2151 102801D1
2152 102801D2
2153*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002154static const unsigned int dell_922x_d81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002155 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
2156 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
2157 0x01813122, 0x400001f2,
2158};
2159
2160/*
2161 STAC 922X pin configs for
2162 102801AC
2163 102801D0
2164*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002165static const unsigned int dell_922x_d82_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002166 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
2167 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
2168 0x01813122, 0x400001f1,
2169};
2170
2171/*
2172 STAC 922X pin configs for
2173 102801BF
2174*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002175static const unsigned int dell_922x_m81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002176 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
2177 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
2178 0x40C003f1, 0x405003f0,
2179};
2180
2181/*
2182 STAC 9221 A1 pin configs for
2183 102801D7 (Dell XPS M1210)
2184*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002185static const unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01002186 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
2187 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002188 0x508003f3, 0x405003f4,
2189};
2190
Takashi Iwai2b635362011-05-02 12:33:43 +02002191static const unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01002192 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01002193 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2194 0x02a19120, 0x40000100,
2195};
2196
Takashi Iwai2b635362011-05-02 12:33:43 +02002197static const unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01002198 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
2199 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01002200 0x02a19320, 0x40000100,
2201};
2202
Takashi Iwai2b635362011-05-02 12:33:43 +02002203static const unsigned int intel_mac_v1_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002204 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
2205 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002206 0x400000fc, 0x400000fb,
2207};
2208
Takashi Iwai2b635362011-05-02 12:33:43 +02002209static const unsigned int intel_mac_v2_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002210 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2211 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02002212 0x400000fc, 0x400000fb,
2213};
2214
Takashi Iwai2b635362011-05-02 12:33:43 +02002215static const unsigned int intel_mac_v3_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002216 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2217 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
2218 0x400000fc, 0x400000fb,
2219};
2220
Takashi Iwai2b635362011-05-02 12:33:43 +02002221static const unsigned int intel_mac_v4_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002222 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2223 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2224 0x400000fc, 0x400000fb,
2225};
2226
Takashi Iwai2b635362011-05-02 12:33:43 +02002227static const unsigned int intel_mac_v5_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002228 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2229 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2230 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002231};
2232
Takashi Iwai2b635362011-05-02 12:33:43 +02002233static const unsigned int ecs202_pin_configs[10] = {
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002234 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
2235 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
2236 0x9037012e, 0x40e000f2,
2237};
Takashi Iwai76c08822007-06-19 12:17:42 +02002238
Takashi Iwai2b635362011-05-02 12:33:43 +02002239static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002240 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002241 [STAC_D945GTP3] = d945gtp3_pin_configs,
2242 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002243 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
2244 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
2245 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
2246 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
2247 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002248 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002249 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002250 [STAC_MACMINI] = intel_mac_v3_pin_configs,
2251 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2252 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2253 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2254 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2255 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002256 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002257 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2258 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2259 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2260 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01002261};
2262
Takashi Iwaiea734962011-01-17 11:29:34 +01002263static const char * const stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002264 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002265 [STAC_D945_REF] = "ref",
2266 [STAC_D945GTP5] = "5stack",
2267 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002268 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2269 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2270 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2271 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2272 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08002273 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002274 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002275 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002276 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002277 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2278 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02002279 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002280 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002281 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002282 [STAC_922X_DELL_D81] = "dell-d81",
2283 [STAC_922X_DELL_D82] = "dell-d82",
2284 [STAC_922X_DELL_M81] = "dell-m81",
2285 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002286};
2287
Takashi Iwai2b635362011-05-02 12:33:43 +02002288static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002289 /* SigmaTel reference board */
2290 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2291 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002292 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2293 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002294 /* Intel 945G based systems */
2295 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2296 "Intel D945G", STAC_D945GTP3),
2297 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2298 "Intel D945G", STAC_D945GTP3),
2299 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2300 "Intel D945G", STAC_D945GTP3),
2301 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2302 "Intel D945G", STAC_D945GTP3),
2303 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2304 "Intel D945G", STAC_D945GTP3),
2305 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2306 "Intel D945G", STAC_D945GTP3),
2307 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2308 "Intel D945G", STAC_D945GTP3),
2309 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2310 "Intel D945G", STAC_D945GTP3),
2311 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2312 "Intel D945G", STAC_D945GTP3),
2313 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2314 "Intel D945G", STAC_D945GTP3),
2315 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2316 "Intel D945G", STAC_D945GTP3),
2317 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2318 "Intel D945G", STAC_D945GTP3),
2319 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2320 "Intel D945G", STAC_D945GTP3),
2321 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2322 "Intel D945G", STAC_D945GTP3),
2323 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2324 "Intel D945G", STAC_D945GTP3),
2325 /* Intel D945G 5-stack systems */
2326 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2327 "Intel D945G", STAC_D945GTP5),
2328 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2329 "Intel D945G", STAC_D945GTP5),
2330 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2331 "Intel D945G", STAC_D945GTP5),
2332 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2333 "Intel D945G", STAC_D945GTP5),
2334 /* Intel 945P based systems */
2335 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2336 "Intel D945P", STAC_D945GTP3),
2337 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2338 "Intel D945P", STAC_D945GTP3),
2339 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2340 "Intel D945P", STAC_D945GTP3),
2341 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2342 "Intel D945P", STAC_D945GTP3),
2343 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2344 "Intel D945P", STAC_D945GTP3),
2345 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2346 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002347 /* other intel */
2348 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2349 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002350 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002351 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002352 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002353 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002354 /* Dell systems */
2355 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2356 "unknown Dell", STAC_922X_DELL_D81),
2357 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2358 "unknown Dell", STAC_922X_DELL_D81),
2359 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2360 "unknown Dell", STAC_922X_DELL_D81),
2361 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2362 "unknown Dell", STAC_922X_DELL_D82),
2363 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2364 "unknown Dell", STAC_922X_DELL_M81),
2365 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2366 "unknown Dell", STAC_922X_DELL_D82),
2367 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2368 "unknown Dell", STAC_922X_DELL_D81),
2369 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2370 "unknown Dell", STAC_922X_DELL_D81),
2371 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2372 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002373 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002374 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002375 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002376 {} /* terminator */
2377};
2378
Takashi Iwai2b635362011-05-02 12:33:43 +02002379static const unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002380 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2381 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2382 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2383 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002384};
2385
Takashi Iwai2b635362011-05-02 12:33:43 +02002386static const unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002387 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2388 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2389 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2390 0x40000100, 0x40000100
2391};
2392
Takashi Iwai2b635362011-05-02 12:33:43 +02002393static const unsigned int d965_5st_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002394 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2395 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2396 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2397 0x40000100, 0x40000100
2398};
2399
Takashi Iwai2b635362011-05-02 12:33:43 +02002400static const unsigned int d965_5st_no_fp_pin_configs[14] = {
Takashi Iwai679d92e2009-05-24 19:00:08 +02002401 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2402 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2403 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2404 0x40000100, 0x40000100
2405};
2406
Takashi Iwai2b635362011-05-02 12:33:43 +02002407static const unsigned int dell_3st_pin_configs[14] = {
Tobin Davis4ff076e2007-08-07 11:48:12 +02002408 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2409 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002410 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002411 0x40c003fc, 0x40000100
2412};
2413
Takashi Iwai2b635362011-05-02 12:33:43 +02002414static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002415 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002416 [STAC_D965_REF] = ref927x_pin_configs,
2417 [STAC_D965_3ST] = d965_3st_pin_configs,
2418 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002419 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002420 [STAC_DELL_3ST] = dell_3st_pin_configs,
2421 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002422 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002423};
2424
Takashi Iwaiea734962011-01-17 11:29:34 +01002425static const char * const stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002426 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002427 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002428 [STAC_D965_REF] = "ref",
2429 [STAC_D965_3ST] = "3stack",
2430 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002431 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002432 [STAC_DELL_3ST] = "dell-3stack",
2433 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002434 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002435};
2436
Takashi Iwai2b635362011-05-02 12:33:43 +02002437static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002438 /* SigmaTel reference board */
2439 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2440 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002441 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2442 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002443 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002444 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2445 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002446 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002447 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2448 "Intel D965", STAC_D965_3ST),
2449 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2450 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002451 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002452 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002453 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2454 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002455 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002456 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002457 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002458 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002459 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002460 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002461 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2462 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2463 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2464 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002465 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002466 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2467 "Intel D965", STAC_D965_5ST),
2468 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2469 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002470 /* volume-knob fixes */
2471 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002472 {} /* terminator */
2473};
2474
Takashi Iwai2b635362011-05-02 12:33:43 +02002475static const unsigned int ref9205_pin_configs[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +02002476 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002477 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002478 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002479};
2480
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002481/*
2482 STAC 9205 pin configs for
2483 102801F1
2484 102801F2
2485 102801FC
2486 102801FD
2487 10280204
2488 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002489 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002490 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002491*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002492static const unsigned int dell_9205_m42_pin_configs[12] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002493 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2494 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2495 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2496};
2497
2498/*
2499 STAC 9205 pin configs for
2500 102801F9
2501 102801FA
2502 102801FE
2503 102801FF (Dell Precision M4300)
2504 10280206
2505 10280200
2506 10280201
2507*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002508static const unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002509 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2510 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2511 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2512};
2513
Takashi Iwai2b635362011-05-02 12:33:43 +02002514static const unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002515 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2516 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2517 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2518};
2519
Takashi Iwai2b635362011-05-02 12:33:43 +02002520static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002521 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002522 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2523 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2524 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002525 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002526};
2527
Takashi Iwaiea734962011-01-17 11:29:34 +01002528static const char * const stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002529 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002530 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002531 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002532 [STAC_9205_DELL_M43] = "dell-m43",
2533 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002534 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002535};
2536
Takashi Iwai2b635362011-05-02 12:33:43 +02002537static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002538 /* SigmaTel reference board */
2539 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2540 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002541 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2542 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002543 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2544 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002545 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002546 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2547 "unknown Dell", STAC_9205_DELL_M42),
2548 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2549 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002550 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002551 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002552 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2553 "Dell Precision", STAC_9205_DELL_M43),
2554 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2555 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002556 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2557 "unknown Dell", STAC_9205_DELL_M42),
2558 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2559 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002560 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2561 "Dell Precision", STAC_9205_DELL_M43),
2562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002563 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2565 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2567 "Dell Precision", STAC_9205_DELL_M43),
2568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2569 "Dell Precision", STAC_9205_DELL_M43),
2570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2571 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2573 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2575 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2577 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002578 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002579 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002580 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002581 {} /* terminator */
2582};
2583
Takashi Iwai330ee992009-02-20 14:33:36 +01002584static void stac92xx_set_config_regs(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002585 const unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002586{
2587 int i;
2588 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002589
Takashi Iwai330ee992009-02-20 14:33:36 +01002590 if (!pincfgs)
2591 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002592
Matthew Ranostay87d48362007-07-17 11:52:24 +02002593 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002594 if (spec->pin_nids[i] && pincfgs[i])
2595 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2596 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002597}
2598
Matt2f2f4252005-04-13 14:45:30 +02002599/*
2600 * Analog playback callbacks
2601 */
2602static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2603 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002604 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002605{
2606 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002607 if (spec->stream_delay)
2608 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002609 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2610 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002611}
2612
2613static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2614 struct hda_codec *codec,
2615 unsigned int stream_tag,
2616 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002617 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002618{
2619 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002620 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002621}
2622
2623static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2624 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002625 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002626{
2627 struct sigmatel_spec *spec = codec->spec;
2628 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2629}
2630
2631/*
Mattdabbed62005-06-14 10:19:34 +02002632 * Digital playback callbacks
2633 */
2634static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2635 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002636 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002637{
2638 struct sigmatel_spec *spec = codec->spec;
2639 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2640}
2641
2642static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2643 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002644 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002645{
2646 struct sigmatel_spec *spec = codec->spec;
2647 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2648}
2649
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002650static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2651 struct hda_codec *codec,
2652 unsigned int stream_tag,
2653 unsigned int format,
2654 struct snd_pcm_substream *substream)
2655{
2656 struct sigmatel_spec *spec = codec->spec;
2657 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2658 stream_tag, format, substream);
2659}
2660
Takashi Iwai9411e212009-02-13 11:32:28 +01002661static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2662 struct hda_codec *codec,
2663 struct snd_pcm_substream *substream)
2664{
2665 struct sigmatel_spec *spec = codec->spec;
2666 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2667}
2668
Mattdabbed62005-06-14 10:19:34 +02002669
2670/*
Matt2f2f4252005-04-13 14:45:30 +02002671 * Analog capture callbacks
2672 */
2673static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2674 struct hda_codec *codec,
2675 unsigned int stream_tag,
2676 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002677 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002678{
2679 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002680 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002681
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002682 if (spec->powerdown_adcs) {
2683 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002684 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002685 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2686 }
2687 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002688 return 0;
2689}
2690
2691static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2692 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002693 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002694{
2695 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002696 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002697
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002698 snd_hda_codec_cleanup_stream(codec, nid);
2699 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002700 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002701 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002702 return 0;
2703}
2704
Takashi Iwai2b635362011-05-02 12:33:43 +02002705static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
Mattdabbed62005-06-14 10:19:34 +02002706 .substreams = 1,
2707 .channels_min = 2,
2708 .channels_max = 2,
2709 /* NID is set in stac92xx_build_pcms */
2710 .ops = {
2711 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002712 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002713 .prepare = stac92xx_dig_playback_pcm_prepare,
2714 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002715 },
2716};
2717
Takashi Iwai2b635362011-05-02 12:33:43 +02002718static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
Mattdabbed62005-06-14 10:19:34 +02002719 .substreams = 1,
2720 .channels_min = 2,
2721 .channels_max = 2,
2722 /* NID is set in stac92xx_build_pcms */
2723};
2724
Takashi Iwai2b635362011-05-02 12:33:43 +02002725static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
Matt2f2f4252005-04-13 14:45:30 +02002726 .substreams = 1,
2727 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002728 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002729 .nid = 0x02, /* NID to query formats and rates */
2730 .ops = {
2731 .open = stac92xx_playback_pcm_open,
2732 .prepare = stac92xx_playback_pcm_prepare,
2733 .cleanup = stac92xx_playback_pcm_cleanup
2734 },
2735};
2736
Takashi Iwai2b635362011-05-02 12:33:43 +02002737static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002738 .substreams = 1,
2739 .channels_min = 2,
2740 .channels_max = 2,
2741 .nid = 0x06, /* NID to query formats and rates */
2742 .ops = {
2743 .open = stac92xx_playback_pcm_open,
2744 .prepare = stac92xx_playback_pcm_prepare,
2745 .cleanup = stac92xx_playback_pcm_cleanup
2746 },
2747};
2748
Takashi Iwai2b635362011-05-02 12:33:43 +02002749static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002750 .channels_min = 2,
2751 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002752 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002753 .ops = {
2754 .prepare = stac92xx_capture_pcm_prepare,
2755 .cleanup = stac92xx_capture_pcm_cleanup
2756 },
2757};
2758
2759static int stac92xx_build_pcms(struct hda_codec *codec)
2760{
2761 struct sigmatel_spec *spec = codec->spec;
2762 struct hda_pcm *info = spec->pcm_rec;
2763
2764 codec->num_pcms = 1;
2765 codec->pcm_info = info;
2766
Mattc7d4b2f2005-06-27 14:59:41 +02002767 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002768 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002769 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2770 spec->multiout.dac_nids[0];
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002771 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2772 spec->autocfg.line_outs == 2)
2773 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2774 snd_pcm_2_1_chmaps;
2775
Matt2f2f4252005-04-13 14:45:30 +02002776 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002777 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002778 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002779
2780 if (spec->alt_switch) {
2781 codec->num_pcms++;
2782 info++;
2783 info->name = "STAC92xx Analog Alt";
2784 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2785 }
Matt2f2f4252005-04-13 14:45:30 +02002786
Mattdabbed62005-06-14 10:19:34 +02002787 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2788 codec->num_pcms++;
2789 info++;
2790 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002791 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002792 if (spec->multiout.dig_out_nid) {
2793 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2794 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2795 }
2796 if (spec->dig_in_nid) {
2797 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2798 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2799 }
2800 }
2801
Matt2f2f4252005-04-13 14:45:30 +02002802 return 0;
2803}
2804
Matt Porter403d1942005-11-29 15:00:51 +01002805static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2806
2807{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002808 snd_hda_set_pin_ctl_cache(codec, nid, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002809}
2810
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002811#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2812
2813static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2814 struct snd_ctl_elem_value *ucontrol)
2815{
2816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2817 struct sigmatel_spec *spec = codec->spec;
2818
Takashi Iwaid7a89432008-11-12 09:48:04 +01002819 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002820 return 0;
2821}
2822
Takashi Iwai62558ce2009-07-29 14:23:09 +02002823static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002824
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002825static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2826 struct snd_ctl_elem_value *ucontrol)
2827{
2828 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2829 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002830 int nid = kcontrol->private_value;
2831
2832 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002833
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002834 /* check to be sure that the ports are up to date with
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002835 * switch changes
2836 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002837 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002838
2839 return 1;
2840}
2841
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002842static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2843 struct snd_ctl_elem_info *uinfo)
2844{
2845 int i;
Takashi Iwai2b635362011-05-02 12:33:43 +02002846 static const char * const texts[] = {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002847 "Mic In", "Line In", "Line Out"
2848 };
2849
2850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2851 struct sigmatel_spec *spec = codec->spec;
2852 hda_nid_t nid = kcontrol->private_value;
2853
2854 if (nid == spec->mic_switch || nid == spec->line_switch)
2855 i = 3;
2856 else
2857 i = 2;
2858
2859 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2860 uinfo->value.enumerated.items = i;
2861 uinfo->count = 1;
2862 if (uinfo->value.enumerated.item >= i)
2863 uinfo->value.enumerated.item = i-1;
2864 strcpy(uinfo->value.enumerated.name,
2865 texts[uinfo->value.enumerated.item]);
2866
2867 return 0;
2868}
2869
2870static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2871 struct snd_ctl_elem_value *ucontrol)
2872{
2873 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2874 hda_nid_t nid = kcontrol->private_value;
2875 unsigned int vref = stac92xx_vref_get(codec, nid);
2876
Takashi Iwai47408602012-04-20 13:06:53 +02002877 if (vref == snd_hda_get_default_vref(codec, nid))
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002878 ucontrol->value.enumerated.item[0] = 0;
2879 else if (vref == AC_PINCTL_VREF_GRD)
2880 ucontrol->value.enumerated.item[0] = 1;
2881 else if (vref == AC_PINCTL_VREF_HIZ)
2882 ucontrol->value.enumerated.item[0] = 2;
2883
2884 return 0;
2885}
2886
2887static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2888 struct snd_ctl_elem_value *ucontrol)
2889{
2890 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2891 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002892 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002893 hda_nid_t nid = kcontrol->private_value;
2894
2895 if (ucontrol->value.enumerated.item[0] == 0)
Takashi Iwai47408602012-04-20 13:06:53 +02002896 new_vref = snd_hda_get_default_vref(codec, nid);
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002897 else if (ucontrol->value.enumerated.item[0] == 1)
2898 new_vref = AC_PINCTL_VREF_GRD;
2899 else if (ucontrol->value.enumerated.item[0] == 2)
2900 new_vref = AC_PINCTL_VREF_HIZ;
2901 else
2902 return 0;
2903
2904 if (new_vref != stac92xx_vref_get(codec, nid)) {
2905 error = stac92xx_vref_set(codec, nid, new_vref);
2906 return error;
2907 }
2908
2909 return 0;
2910}
2911
2912static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2913 struct snd_ctl_elem_info *uinfo)
2914{
Takashi Iwai2b635362011-05-02 12:33:43 +02002915 char *texts[2];
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002916 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2917 struct sigmatel_spec *spec = codec->spec;
2918
2919 if (kcontrol->private_value == spec->line_switch)
2920 texts[0] = "Line In";
2921 else
2922 texts[0] = "Mic In";
2923 texts[1] = "Line Out";
2924 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2925 uinfo->value.enumerated.items = 2;
2926 uinfo->count = 1;
2927
2928 if (uinfo->value.enumerated.item >= 2)
2929 uinfo->value.enumerated.item = 1;
2930 strcpy(uinfo->value.enumerated.name,
2931 texts[uinfo->value.enumerated.item]);
2932
2933 return 0;
2934}
Matt Porter403d1942005-11-29 15:00:51 +01002935
2936static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2937{
2938 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2939 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002940 hda_nid_t nid = kcontrol->private_value;
2941 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002942
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002943 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002944 return 0;
2945}
2946
2947static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2948{
2949 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2950 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002951 hda_nid_t nid = kcontrol->private_value;
2952 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2953 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002954
2955 spec->io_switch[io_idx] = val;
2956
2957 if (val)
2958 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002959 else {
2960 unsigned int pinctl = AC_PINCTL_IN_EN;
2961 if (io_idx) /* set VREF for mic */
Takashi Iwai47408602012-04-20 13:06:53 +02002962 pinctl |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002963 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2964 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002965
2966 /* check the auto-mute again: we need to mute/unmute the speaker
2967 * appropriately according to the pin direction
2968 */
2969 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002970 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002971
Matt Porter403d1942005-11-29 15:00:51 +01002972 return 1;
2973}
2974
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002975#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2976
2977static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2978 struct snd_ctl_elem_value *ucontrol)
2979{
2980 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2981 struct sigmatel_spec *spec = codec->spec;
2982
2983 ucontrol->value.integer.value[0] = spec->clfe_swap;
2984 return 0;
2985}
2986
2987static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2988 struct snd_ctl_elem_value *ucontrol)
2989{
2990 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2991 struct sigmatel_spec *spec = codec->spec;
2992 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002993 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002994
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002995 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002996 return 0;
2997
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002998 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002999
3000 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
3001 spec->clfe_swap ? 0x4 : 0x0);
3002
3003 return 1;
3004}
3005
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003006#define STAC_CODEC_HP_SWITCH(xname) \
3007 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3008 .name = xname, \
3009 .index = 0, \
3010 .info = stac92xx_hp_switch_info, \
3011 .get = stac92xx_hp_switch_get, \
3012 .put = stac92xx_hp_switch_put, \
3013 }
3014
Matt Porter403d1942005-11-29 15:00:51 +01003015#define STAC_CODEC_IO_SWITCH(xname, xpval) \
3016 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3017 .name = xname, \
3018 .index = 0, \
3019 .info = stac92xx_io_switch_info, \
3020 .get = stac92xx_io_switch_get, \
3021 .put = stac92xx_io_switch_put, \
3022 .private_value = xpval, \
3023 }
3024
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003025#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
3026 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3027 .name = xname, \
3028 .index = 0, \
3029 .info = stac92xx_clfe_switch_info, \
3030 .get = stac92xx_clfe_switch_get, \
3031 .put = stac92xx_clfe_switch_put, \
3032 .private_value = xpval, \
3033 }
Matt Porter403d1942005-11-29 15:00:51 +01003034
Mattc7d4b2f2005-06-27 14:59:41 +02003035enum {
3036 STAC_CTL_WIDGET_VOL,
3037 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003038 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01003039 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003040 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01003041 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02003042 STAC_CTL_WIDGET_CLFE_SWITCH,
3043 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02003044};
3045
Takashi Iwai2b635362011-05-02 12:33:43 +02003046static const struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02003047 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3048 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003049 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01003050 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003051 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01003052 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003053 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02003054 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02003055};
3056
3057/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01003058static struct snd_kcontrol_new *
3059stac_control_new(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02003060 const struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01003061 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01003062 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02003063{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01003064 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02003065
Takashi Iwai603c4012008-07-30 15:01:44 +02003066 knew = snd_array_new(&spec->kctls);
3067 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01003068 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003069 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02003070 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01003071 if (!knew->name) {
3072 /* roolback */
3073 memset(knew, 0, sizeof(*knew));
3074 spec->kctls.alloced--;
3075 return NULL;
3076 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01003077 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01003078 return knew;
3079}
3080
Takashi Iwai62cbde12012-09-14 11:58:54 +02003081static struct snd_kcontrol_new *
3082add_control_temp(struct sigmatel_spec *spec,
3083 const struct snd_kcontrol_new *ktemp,
3084 int idx, const char *name,
3085 unsigned long val)
3086{
3087 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
3088 HDA_SUBDEV_AMP_FLAG);
3089 if (!knew)
3090 return NULL;
3091 knew->index = idx;
3092 knew->private_value = val;
3093 return knew;
3094}
3095
Takashi Iwaie3c75962009-01-23 11:57:22 +01003096static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02003097 const struct snd_kcontrol_new *ktemp,
Takashi Iwaie3c75962009-01-23 11:57:22 +01003098 int idx, const char *name,
3099 unsigned long val)
3100{
Takashi Iwai62cbde12012-09-14 11:58:54 +02003101 return add_control_temp(spec, ktemp, idx, name, val) ? 0 : -ENOMEM;
Mattc7d4b2f2005-06-27 14:59:41 +02003102}
3103
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003104static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
3105 int type, int idx, const char *name,
3106 unsigned long val)
3107{
3108 return stac92xx_add_control_temp(spec,
3109 &stac92xx_control_templates[type],
3110 idx, name, val);
3111}
3112
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003113
3114/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003115static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
3116 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003117{
3118 return stac92xx_add_control_idx(spec, type, 0, name, val);
3119}
3120
Takashi Iwai2b635362011-05-02 12:33:43 +02003121static const struct snd_kcontrol_new stac_input_src_temp = {
Takashi Iwaie3c75962009-01-23 11:57:22 +01003122 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3123 .name = "Input Source",
3124 .info = stac92xx_mux_enum_info,
3125 .get = stac92xx_mux_enum_get,
3126 .put = stac92xx_mux_enum_put,
3127};
3128
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003129static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
3130 hda_nid_t nid, int idx)
3131{
3132 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
3133 int control = 0;
3134 struct sigmatel_spec *spec = codec->spec;
3135 char name[22];
3136
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003137 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
David Henningsson8d032a82012-10-09 12:48:40 +02003138 if (spec->headset_jack && snd_hda_get_input_pin_attr(def_conf)
3139 != INPUT_PIN_ATTR_DOCK)
3140 return 0;
Takashi Iwai47408602012-04-20 13:06:53 +02003141 if (snd_hda_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003142 && nid == spec->line_switch)
3143 control = STAC_CTL_WIDGET_IO_SWITCH;
3144 else if (snd_hda_query_pin_caps(codec, nid)
3145 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
3146 control = STAC_CTL_WIDGET_DC_BIAS;
3147 else if (nid == spec->mic_switch)
3148 control = STAC_CTL_WIDGET_IO_SWITCH;
3149 }
3150
3151 if (control) {
Takashi Iwai201e06f2011-11-16 15:33:26 +01003152 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
3153 name, sizeof(name), NULL);
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003154 return stac92xx_add_control(codec->spec, control,
3155 strcat(name, " Jack Mode"), nid);
3156 }
3157
3158 return 0;
3159}
3160
Takashi Iwaie3c75962009-01-23 11:57:22 +01003161static int stac92xx_add_input_source(struct sigmatel_spec *spec)
3162{
3163 struct snd_kcontrol_new *knew;
3164 struct hda_input_mux *imux = &spec->private_imux;
3165
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003166 if (spec->auto_mic)
3167 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01003168 if (!spec->num_adcs || imux->num_items <= 1)
3169 return 0; /* no need for input source control */
3170 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01003171 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01003172 if (!knew)
3173 return -ENOMEM;
3174 knew->count = spec->num_adcs;
3175 return 0;
3176}
3177
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003178/* check whether the line-input can be used as line-out */
3179static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01003180{
3181 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003182 struct auto_pin_cfg *cfg = &spec->autocfg;
3183 hda_nid_t nid;
3184 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003185 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003186
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003187 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
3188 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003189 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003190 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003191 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01003192 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003193 if (pincap & AC_PINCAP_OUT)
3194 return nid;
3195 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003196 }
Matt Porter403d1942005-11-29 15:00:51 +01003197 return 0;
3198}
3199
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003200static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
3201
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003202/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003203static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003204{
3205 struct sigmatel_spec *spec = codec->spec;
3206 struct auto_pin_cfg *cfg = &spec->autocfg;
3207 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02003208 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003209
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003210 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003211 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
3212 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003213 for (i = 0; i < cfg->num_inputs; i++) {
3214 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02003215 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003216 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003217 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3218 /* some laptops have an internal analog microphone
3219 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003220 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003221 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003222 if (pincap & AC_PINCAP_OUT) {
3223 *dac = get_unassigned_dac(codec, nid);
3224 if (*dac)
3225 return nid;
3226 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003227 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003228 }
3229 return 0;
3230}
Steve Longerbeam7b043892007-05-03 20:50:03 +02003231
3232static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3233{
3234 int i;
3235
3236 for (i = 0; i < spec->multiout.num_dacs; i++) {
3237 if (spec->multiout.dac_nids[i] == nid)
3238 return 1;
3239 }
3240
3241 return 0;
3242}
3243
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003244static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3245{
3246 int i;
3247 if (is_in_dac_nids(spec, nid))
3248 return 1;
3249 for (i = 0; i < spec->autocfg.hp_outs; i++)
3250 if (spec->hp_dacs[i] == nid)
3251 return 1;
3252 for (i = 0; i < spec->autocfg.speaker_outs; i++)
3253 if (spec->speaker_dacs[i] == nid)
3254 return 1;
3255 return 0;
3256}
3257
3258static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
3259{
3260 struct sigmatel_spec *spec = codec->spec;
David Henningsson48718ea2011-10-05 09:49:05 +02003261 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003262 int j, conn_len;
David Henningsson48718ea2011-10-05 09:49:05 +02003263 hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003264 unsigned int wcaps, wtype;
3265
3266 conn_len = snd_hda_get_connections(codec, nid, conn,
3267 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01003268 /* 92HD88: trace back up the link of nids to find the DAC */
3269 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
3270 != AC_WID_AUD_OUT)) {
3271 nid = conn[0];
3272 conn_len = snd_hda_get_connections(codec, nid, conn,
3273 HDA_MAX_CONNECTIONS);
3274 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003275 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01003276 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003277 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003278 /* we check only analog outputs */
3279 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3280 continue;
3281 /* if this route has a free DAC, assign it */
3282 if (!check_all_dac_nids(spec, conn[j])) {
3283 if (conn_len > 1) {
3284 /* select this DAC in the pin's input mux */
3285 snd_hda_codec_write_cache(codec, nid, 0,
3286 AC_VERB_SET_CONNECT_SEL, j);
3287 }
3288 return conn[j];
3289 }
3290 }
David Henningsson48718ea2011-10-05 09:49:05 +02003291
3292 /* if all DACs are already assigned, connect to the primary DAC,
3293 unless we're assigning a secondary headphone */
3294 fallback_dac = spec->multiout.dac_nids[0];
3295 if (spec->multiout.hp_nid) {
3296 for (j = 0; j < cfg->hp_outs; j++)
3297 if (cfg->hp_pins[j] == nid) {
3298 fallback_dac = spec->multiout.hp_nid;
3299 break;
3300 }
3301 }
3302
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003303 if (conn_len > 1) {
3304 for (j = 0; j < conn_len; j++) {
David Henningsson48718ea2011-10-05 09:49:05 +02003305 if (conn[j] == fallback_dac) {
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003306 snd_hda_codec_write_cache(codec, nid, 0,
3307 AC_VERB_SET_CONNECT_SEL, j);
3308 break;
3309 }
3310 }
3311 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003312 return 0;
3313}
3314
3315static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3316static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3317
Matt Porter3cc08dc2006-01-23 15:27:49 +01003318/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02003319 * Fill in the dac_nids table from the parsed pin configuration
3320 * This function only works when every pin in line_out_pins[]
3321 * contains atleast one DAC in its connection list. Some 92xx
3322 * codecs are not connected directly to a DAC, such as the 9200
3323 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01003324 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003325static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003326{
3327 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003328 struct auto_pin_cfg *cfg = &spec->autocfg;
3329 int i;
3330 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02003331
Mattc7d4b2f2005-06-27 14:59:41 +02003332 for (i = 0; i < cfg->line_outs; i++) {
3333 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003334 dac = get_unassigned_dac(codec, nid);
3335 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003336 if (spec->multiout.num_dacs > 0) {
3337 /* we have already working output pins,
3338 * so let's drop the broken ones again
3339 */
3340 cfg->line_outs = spec->multiout.num_dacs;
3341 break;
3342 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003343 /* error out, no available DAC found */
3344 snd_printk(KERN_ERR
3345 "%s: No available DAC for pin 0x%x\n",
3346 __func__, nid);
3347 return -ENODEV;
3348 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003349 add_spec_dacs(spec, dac);
3350 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003351
Takashi Iwai139e0712009-03-06 12:10:41 +01003352 for (i = 0; i < cfg->hp_outs; i++) {
3353 nid = cfg->hp_pins[i];
3354 dac = get_unassigned_dac(codec, nid);
3355 if (dac) {
3356 if (!spec->multiout.hp_nid)
3357 spec->multiout.hp_nid = dac;
3358 else
3359 add_spec_extra_dacs(spec, dac);
3360 }
3361 spec->hp_dacs[i] = dac;
3362 }
3363
3364 for (i = 0; i < cfg->speaker_outs; i++) {
3365 nid = cfg->speaker_pins[i];
3366 dac = get_unassigned_dac(codec, nid);
3367 if (dac)
3368 add_spec_extra_dacs(spec, dac);
3369 spec->speaker_dacs[i] = dac;
3370 }
3371
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003372 /* add line-in as output */
3373 nid = check_line_out_switch(codec);
3374 if (nid) {
3375 dac = get_unassigned_dac(codec, nid);
3376 if (dac) {
3377 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3378 nid, cfg->line_outs);
3379 cfg->line_out_pins[cfg->line_outs] = nid;
3380 cfg->line_outs++;
3381 spec->line_switch = nid;
3382 add_spec_dacs(spec, dac);
3383 }
3384 }
3385 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003386 nid = check_mic_out_switch(codec, &dac);
3387 if (nid && dac) {
3388 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3389 nid, cfg->line_outs);
3390 cfg->line_out_pins[cfg->line_outs] = nid;
3391 cfg->line_outs++;
3392 spec->mic_switch = nid;
3393 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003394 }
3395
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003396 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003397 spec->multiout.num_dacs,
3398 spec->multiout.dac_nids[0],
3399 spec->multiout.dac_nids[1],
3400 spec->multiout.dac_nids[2],
3401 spec->multiout.dac_nids[3],
3402 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003403
Mattc7d4b2f2005-06-27 14:59:41 +02003404 return 0;
3405}
3406
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003407/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003408static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3409 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003410{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003411 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003412 char name[32];
3413 int err;
3414
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003415 if (!spec->check_volume_offset) {
3416 unsigned int caps, step, nums, db_scale;
3417 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3418 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3419 AC_AMPCAP_STEP_SIZE_SHIFT;
3420 step = (step + 1) * 25; /* in .01dB unit */
3421 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3422 AC_AMPCAP_NUM_STEPS_SHIFT;
3423 db_scale = nums * step;
3424 /* if dB scale is over -64dB, and finer enough,
3425 * let's reduce it to half
3426 */
3427 if (db_scale > 6400 && nums >= 0x1f)
3428 spec->volume_offset = nums / 2;
3429 spec->check_volume_offset = 1;
3430 }
3431
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003432 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003433 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003434 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3435 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003436 if (err < 0)
3437 return err;
3438 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003439 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003440 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3441 if (err < 0)
3442 return err;
3443 return 0;
3444}
3445
Takashi Iwai668b9652009-03-06 10:13:24 +01003446#define create_controls(codec, pfx, nid, chs) \
3447 create_controls_idx(codec, pfx, 0, nid, chs)
3448
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003449static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3450{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003451 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003452 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3453 return 1;
3454 } else {
Takashi Iwaidda14412011-05-02 11:29:30 +02003455 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3456 spec->dac_nids[spec->multiout.num_dacs] = nid;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003457 spec->multiout.num_dacs++;
3458 }
3459 return 0;
3460}
3461
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003462static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003463{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003464 int i;
3465 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3466 if (!spec->multiout.extra_out_nid[i]) {
3467 spec->multiout.extra_out_nid[i] = nid;
3468 return 0;
3469 }
3470 }
3471 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3472 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003473}
3474
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003475/* Create output controls
3476 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3477 */
3478static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3479 const hda_nid_t *pins,
3480 const hda_nid_t *dac_nids,
3481 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003482{
Takashi Iwai76624532008-12-19 10:09:47 +01003483 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaiea734962011-01-17 11:29:34 +01003484 static const char * const chname[4] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02003485 "Front", "Surround", NULL /*CLFE*/, "Side"
3486 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003487 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003488 int i, err;
3489 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003490
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003491 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003492 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003493 if (is_jack_detectable(codec, pins[i]))
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003494 spec->hp_detect = 1;
3495 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003496 nid = dac_nids[i];
3497 if (!nid)
3498 continue;
3499 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003500 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003501 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003502 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003503 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003504 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003505 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003506 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003507
3508 wid_caps = get_wcaps(codec, nid);
3509
3510 if (wid_caps & AC_WCAP_LR_SWAP) {
3511 err = stac92xx_add_control(spec,
3512 STAC_CTL_WIDGET_CLFE_SWITCH,
3513 "Swap Center/LFE Playback Switch", nid);
3514
3515 if (err < 0)
3516 return err;
3517 }
3518
Mattc7d4b2f2005-06-27 14:59:41 +02003519 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003520 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003521 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003522 switch (type) {
3523 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003524 name = "Headphone";
3525 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003526 break;
3527 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01003528 if (num_outs <= 2) {
3529 name = i ? "Bass Speaker" : "Speaker";
3530 idx = 0;
David Henningsson298efee2012-09-06 11:17:58 +02003531 break;
3532 }
3533 /* Fall through in case of multi speaker outs */
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003534 default:
3535 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003536 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003537 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003538 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003539 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003540 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003541 return err;
3542 }
3543 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003544 return 0;
3545}
3546
Takashi Iwai62cbde12012-09-14 11:58:54 +02003547static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
3548 unsigned int dir_mask, unsigned int data);
3549
3550/* hook for controlling mic-mute LED GPIO */
3551static int stac92xx_capture_sw_put_led(struct snd_kcontrol *kcontrol,
3552 struct snd_ctl_elem_value *ucontrol)
3553{
3554 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3555 struct sigmatel_spec *spec = codec->spec;
3556 int err;
3557 bool mute;
3558
3559 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3560 if (err <= 0)
3561 return err;
3562 mute = !(ucontrol->value.integer.value[0] &&
3563 ucontrol->value.integer.value[1]);
3564 if (spec->mic_mute_led_on != mute) {
3565 spec->mic_mute_led_on = mute;
3566 if (mute)
3567 spec->gpio_data |= spec->mic_mute_led_gpio;
3568 else
3569 spec->gpio_data &= ~spec->mic_mute_led_gpio;
3570 stac_gpio_set(codec, spec->gpio_mask,
3571 spec->gpio_dir, spec->gpio_data);
3572 }
3573 return err;
3574}
3575
Takashi Iwai6479c632009-07-28 18:20:25 +02003576static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3577 unsigned long sw, int idx)
3578{
Takashi Iwai62cbde12012-09-14 11:58:54 +02003579 struct sigmatel_spec *spec = codec->spec;
3580 struct snd_kcontrol_new *knew;
Takashi Iwai6479c632009-07-28 18:20:25 +02003581 int err;
Takashi Iwai62cbde12012-09-14 11:58:54 +02003582
Takashi Iwai6479c632009-07-28 18:20:25 +02003583 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003584 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003585 if (err < 0)
3586 return err;
Takashi Iwai62cbde12012-09-14 11:58:54 +02003587
3588 knew = add_control_temp(spec,
3589 &stac92xx_control_templates[STAC_CTL_WIDGET_MUTE],
3590 idx, "Capture Switch", sw);
3591 if (!knew)
3592 return -ENOMEM;
3593 /* add a LED hook for some HP laptops */
3594 if (spec->mic_mute_led_gpio)
3595 knew->put = stac92xx_capture_sw_put_led;
3596
Takashi Iwai6479c632009-07-28 18:20:25 +02003597 return 0;
3598}
3599
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003600/* add playback controls from the parsed DAC table */
3601static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3602 const struct auto_pin_cfg *cfg)
3603{
3604 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003605 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003606 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003607 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003608
3609 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3610 spec->multiout.dac_nids,
3611 cfg->line_out_type);
3612 if (err < 0)
3613 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003614
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003615 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003616 err = stac92xx_add_control(spec,
3617 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003618 "Headphone as Line Out Switch",
3619 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003620 if (err < 0)
3621 return err;
3622 }
3623
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003624 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003625 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003626 break;
3627 nid = cfg->inputs[idx].pin;
3628 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3629 if (err < 0)
3630 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003631 }
Matt Porter403d1942005-11-29 15:00:51 +01003632
Mattc7d4b2f2005-06-27 14:59:41 +02003633 return 0;
3634}
3635
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003636/* add playback controls for Speaker and HP outputs */
3637static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3638 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003639{
3640 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003641 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003642
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003643 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3644 spec->hp_dacs, AUTO_PIN_HP_OUT);
3645 if (err < 0)
3646 return err;
3647
3648 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3649 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3650 if (err < 0)
3651 return err;
3652
Mattc7d4b2f2005-06-27 14:59:41 +02003653 return 0;
3654}
3655
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003656/* labels for mono mux outputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003657static const char * const stac92xx_mono_labels[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003658 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003659};
3660
3661/* create mono mux for mono out on capable codecs */
3662static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3663{
3664 struct sigmatel_spec *spec = codec->spec;
3665 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3666 int i, num_cons;
3667 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3668
3669 num_cons = snd_hda_get_connections(codec,
3670 spec->mono_nid,
3671 con_lst,
3672 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003673 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003674 return -EINVAL;
3675
Takashi Iwai10a20af2010-09-09 16:28:02 +02003676 for (i = 0; i < num_cons; i++)
3677 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3678 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003679
3680 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3681 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003682}
3683
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003684/* create PC beep volume controls */
3685static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3686 hda_nid_t nid)
3687{
3688 struct sigmatel_spec *spec = codec->spec;
3689 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003690 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3691
3692 if (spec->anabeep_nid == nid)
3693 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003694
3695 /* check for mute support for the the amp */
3696 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003697 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003698 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003699 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3700 if (err < 0)
3701 return err;
3702 }
3703
3704 /* check to see if there is volume support for the amp */
3705 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3706 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003707 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003708 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3709 if (err < 0)
3710 return err;
3711 }
3712 return 0;
3713}
3714
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003715#ifdef CONFIG_SND_HDA_INPUT_BEEP
3716#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3717
3718static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3719 struct snd_ctl_elem_value *ucontrol)
3720{
3721 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3722 ucontrol->value.integer.value[0] = codec->beep->enabled;
3723 return 0;
3724}
3725
3726static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3727 struct snd_ctl_elem_value *ucontrol)
3728{
3729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003730 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003731}
3732
Takashi Iwai2b635362011-05-02 12:33:43 +02003733static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003734 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3735 .info = stac92xx_dig_beep_switch_info,
3736 .get = stac92xx_dig_beep_switch_get,
3737 .put = stac92xx_dig_beep_switch_put,
3738};
3739
3740static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3741{
3742 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003743 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003744}
3745#endif
3746
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003747static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3748{
3749 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003750 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003751
3752 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003753 hda_nid_t nid;
3754 unsigned int wcaps;
3755 unsigned long val;
3756
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003757 nid = spec->mux_nids[i];
3758 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003759 if (!(wcaps & AC_WCAP_OUT_AMP))
3760 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003761
Takashi Iwai667067d2009-08-13 18:14:42 +02003762 /* check whether already the same control was created as
3763 * normal Capture Volume.
3764 */
3765 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3766 for (j = 0; j < spec->num_caps; j++) {
3767 if (spec->capvols[j] == val)
3768 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003769 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003770 if (j < spec->num_caps)
3771 continue;
3772
3773 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3774 "Mux Capture Volume", val);
3775 if (err < 0)
3776 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003777 }
3778 return 0;
3779};
3780
Takashi Iwaiea734962011-01-17 11:29:34 +01003781static const char * const stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003782 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003783};
3784
3785static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3786{
3787 struct sigmatel_spec *spec = codec->spec;
3788 struct hda_input_mux *spdif_mux = &spec->private_smux;
Takashi Iwaiea734962011-01-17 11:29:34 +01003789 const char * const *labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003790 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003791 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003792
3793 num_cons = snd_hda_get_connections(codec,
3794 spec->smux_nids[0],
3795 con_lst,
3796 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003797 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003798 return -EINVAL;
3799
Matthew Ranostay65973632008-09-16 10:39:37 -04003800 if (!labels)
3801 labels = stac92xx_spdif_labels;
3802
Takashi Iwai10a20af2010-09-09 16:28:02 +02003803 for (i = 0; i < num_cons; i++)
3804 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003805
3806 return 0;
3807}
3808
Matt Porter8b657272006-10-26 17:12:59 +02003809/* labels for dmic mux inputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003810static const char * const stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003811 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3812 "Digital Mic 3", "Digital Mic 4"
3813};
3814
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003815static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3816 int idx)
3817{
3818 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3819 int nums;
3820 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3821 if (idx >= 0 && idx < nums)
3822 return conn[idx];
3823 return 0;
3824}
3825
Takashi Iwai8d087c72011-06-28 12:45:47 +02003826/* look for NID recursively */
3827#define get_connection_index(codec, mux, nid) \
3828 snd_hda_get_conn_index(codec, mux, nid, 1)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003829
Takashi Iwai667067d2009-08-13 18:14:42 +02003830/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003831/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003832static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003833 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003834{
3835 unsigned int caps, nums;
3836 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003837 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003838
Takashi Iwai96f845d2009-08-29 00:49:36 +02003839 if (direction == HDA_OUTPUT)
3840 caps = AC_WCAP_OUT_AMP;
3841 else
3842 caps = AC_WCAP_IN_AMP;
3843 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003844 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003845 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003846 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3847 if (!nums)
3848 return 0;
3849 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003850 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3851 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003852 if (err < 0)
3853 return err;
3854 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003855}
3856
Matt Porter8b657272006-10-26 17:12:59 +02003857/* create playback/capture controls for input pins on dmic capable codecs */
3858static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3859 const struct auto_pin_cfg *cfg)
3860{
3861 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003862 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003863 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003864 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003865 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003866
Takashi Iwai10a20af2010-09-09 16:28:02 +02003867 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003868
Matt Porter8b657272006-10-26 17:12:59 +02003869 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003870 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003871 int index, type_idx;
Takashi Iwai201e06f2011-11-16 15:33:26 +01003872 char label[32];
Matt Porter8b657272006-10-26 17:12:59 +02003873
Takashi Iwai667067d2009-08-13 18:14:42 +02003874 nid = spec->dmic_nids[i];
3875 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3876 continue;
3877 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003878 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3879 continue;
3880
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003881 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3882 if (index < 0)
3883 continue;
3884
Takashi Iwai201e06f2011-11-16 15:33:26 +01003885 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
3886 label, sizeof(label), NULL);
Takashi Iwai10a20af2010-09-09 16:28:02 +02003887 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai2d7ec122010-12-23 10:16:05 +01003888 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3889 snd_hda_add_imux_item(imux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003890
Takashi Iwai10a20af2010-09-09 16:28:02 +02003891 err = create_elem_capture_vol(codec, nid, label, type_idx,
3892 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003893 if (err < 0)
3894 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003895 if (!err) {
3896 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003897 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003898 if (err < 0)
3899 return err;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003900 if (!err) {
3901 nid = get_connected_node(codec,
3902 spec->dmux_nids[0], index);
3903 if (nid)
3904 err = create_elem_capture_vol(codec,
3905 nid, label,
3906 type_idx, HDA_INPUT);
3907 if (err < 0)
3908 return err;
3909 }
Takashi Iwai96f845d2009-08-29 00:49:36 +02003910 }
Matt Porter8b657272006-10-26 17:12:59 +02003911 }
3912
3913 return 0;
3914}
3915
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003916static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003917 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003918{
3919 unsigned int cfg;
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003920 unsigned int type;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003921
3922 if (!nid)
3923 return 0;
3924 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003925 type = get_defcfg_device(cfg);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003926 switch (snd_hda_get_input_pin_attr(cfg)) {
3927 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003928 if (*fixed)
3929 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003930 if (type != AC_JACK_MIC_IN)
3931 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003932 *fixed = nid;
3933 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003934 case INPUT_PIN_ATTR_UNUSED:
3935 break;
3936 case INPUT_PIN_ATTR_DOCK:
3937 if (*dock)
3938 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003939 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
3940 return 1; /* invalid type */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003941 *dock = nid;
3942 break;
3943 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003944 if (*ext)
3945 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003946 if (type != AC_JACK_MIC_IN)
3947 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003948 *ext = nid;
3949 break;
3950 }
3951 return 0;
3952}
3953
3954static int set_mic_route(struct hda_codec *codec,
3955 struct sigmatel_mic_route *mic,
3956 hda_nid_t pin)
3957{
3958 struct sigmatel_spec *spec = codec->spec;
3959 struct auto_pin_cfg *cfg = &spec->autocfg;
3960 int i;
3961
3962 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003963 if (pin == 0)
3964 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003965 for (i = 0; i < cfg->num_inputs; i++) {
3966 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003967 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003968 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003969 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003970 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003971 i = get_connection_index(codec, spec->mux_nids[0], pin);
3972 if (i < 0)
3973 return -1;
3974 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003975 mic->dmux_idx = -1;
3976 if (spec->dmux_nids)
3977 mic->dmux_idx = get_connection_index(codec,
3978 spec->dmux_nids[0],
3979 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003980 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003981 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003982 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3983 if (i < 0)
3984 return -1;
3985 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003986 mic->mux_idx = -1;
3987 if (spec->mux_nids)
3988 mic->mux_idx = get_connection_index(codec,
3989 spec->mux_nids[0],
3990 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003991 }
3992 return 0;
3993}
3994
3995/* return non-zero if the device is for automatic mic switch */
3996static int stac_check_auto_mic(struct hda_codec *codec)
3997{
3998 struct sigmatel_spec *spec = codec->spec;
3999 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02004000 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004001 int i;
4002
Charles Chin99077902010-09-17 10:22:32 +02004003 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004004 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02004005 if (check_mic_pin(codec, cfg->inputs[i].pin,
4006 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004007 return 0;
4008 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02004009 if (check_mic_pin(codec, spec->dmic_nids[i],
4010 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004011 return 0;
Takashi Iwai80c67852011-01-13 08:08:08 +01004012 if (!fixed || (!ext && !dock))
Charles Chin99077902010-09-17 10:22:32 +02004013 return 0; /* no input to switch */
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004014 if (!is_jack_detectable(codec, ext))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004015 return 0; /* no unsol support */
4016 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02004017 set_mic_route(codec, &spec->int_mic, fixed) ||
4018 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004019 return 0; /* something is wrong */
4020 return 1;
4021}
4022
Mattc7d4b2f2005-06-27 14:59:41 +02004023/* create playback/capture controls for input pins */
4024static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
4025{
4026 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004027 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02004028 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02004029 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02004030
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004031 for (i = 0; i < cfg->num_inputs; i++) {
4032 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02004033 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02004034
Takashi Iwai314634b2006-09-21 11:56:18 +02004035 index = -1;
4036 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02004037 index = get_connection_index(codec, spec->mux_nids[j],
4038 nid);
4039 if (index >= 0)
4040 break;
Mattc7d4b2f2005-06-27 14:59:41 +02004041 }
Takashi Iwai667067d2009-08-13 18:14:42 +02004042 if (index < 0)
4043 continue;
4044
Takashi Iwai10a20af2010-09-09 16:28:02 +02004045 label = hda_get_autocfg_input_label(codec, cfg, i);
4046 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02004047
Takashi Iwai667067d2009-08-13 18:14:42 +02004048 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02004049 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02004050 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02004051 if (err < 0)
4052 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02004053 }
Takashi Iwai5207e102009-07-30 13:09:08 +02004054 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02004055
Steve Longerbeam7b043892007-05-03 20:50:03 +02004056 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02004057 /*
4058 * Set the current input for the muxes.
4059 * The STAC9221 has two input muxes with identical source
4060 * NID lists. Hopefully this won't get confused.
4061 */
4062 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004063 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
4064 AC_VERB_SET_CONNECT_SEL,
4065 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004066 }
4067 }
4068
Mattc7d4b2f2005-06-27 14:59:41 +02004069 return 0;
4070}
4071
Mattc7d4b2f2005-06-27 14:59:41 +02004072static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
4073{
4074 struct sigmatel_spec *spec = codec->spec;
4075 int i;
4076
4077 for (i = 0; i < spec->autocfg.line_outs; i++) {
4078 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4079 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
4080 }
4081}
4082
4083static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
4084{
4085 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004086 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004087
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004088 for (i = 0; i < spec->autocfg.hp_outs; i++) {
4089 hda_nid_t pin;
4090 pin = spec->autocfg.hp_pins[i];
4091 if (pin) /* connect to front */
4092 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
4093 }
4094 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
4095 hda_nid_t pin;
4096 pin = spec->autocfg.speaker_pins[i];
4097 if (pin) /* connect to front */
4098 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
4099 }
Mattc7d4b2f2005-06-27 14:59:41 +02004100}
4101
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01004102static int is_dual_headphones(struct hda_codec *codec)
4103{
4104 struct sigmatel_spec *spec = codec->spec;
4105 int i, valid_hps;
4106
4107 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
4108 spec->autocfg.hp_outs <= 1)
4109 return 0;
4110 valid_hps = 0;
4111 for (i = 0; i < spec->autocfg.hp_outs; i++) {
4112 hda_nid_t nid = spec->autocfg.hp_pins[i];
4113 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
4114 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
4115 continue;
4116 valid_hps++;
4117 }
4118 return (valid_hps > 1);
4119}
4120
4121
Charles Chin9009b0e2011-11-03 10:27:27 +01004122static int stac92xx_parse_auto_config(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02004123{
4124 struct sigmatel_spec *spec = codec->spec;
Charles Chin9009b0e2011-11-03 10:27:27 +01004125 hda_nid_t dig_out = 0, dig_in = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004126 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02004127 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02004128
Matt Porter8b657272006-10-26 17:12:59 +02004129 if ((err = snd_hda_parse_pin_def_config(codec,
4130 &spec->autocfg,
4131 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004132 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004133 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01004134 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02004135
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004136 /* If we have no real line-out pin and multiple hp-outs, HPs should
4137 * be set up as multi-channel outputs.
4138 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01004139 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004140 /* Copy hp_outs to line_outs, backup line_outs in
4141 * speaker_outs so that the following routines can handle
4142 * HP pins as primary outputs.
4143 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004144 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004145 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
4146 sizeof(spec->autocfg.line_out_pins));
4147 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
4148 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
4149 sizeof(spec->autocfg.hp_pins));
4150 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004151 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
4152 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004153 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004154 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01004155 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004156 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
4157 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01004158 u32 caps = query_amp_caps(codec,
4159 spec->autocfg.mono_out_pin, dir);
4160 hda_nid_t conn_list[1];
4161
4162 /* get the mixer node and then the mono mux if it exists */
4163 if (snd_hda_get_connections(codec,
4164 spec->autocfg.mono_out_pin, conn_list, 1) &&
4165 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02004166 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01004167
4168 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02004169 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01004170 /* LR swap check, some stac925x have a mux that
4171 * changes the DACs output path instead of the
4172 * mono-mux path.
4173 */
4174 if (wid_type == AC_WID_AUD_SEL &&
4175 !(wcaps & AC_WCAP_LR_SWAP))
4176 spec->mono_nid = conn_list[0];
4177 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004178 if (dir) {
4179 hda_nid_t nid = spec->autocfg.mono_out_pin;
4180
4181 /* most mono outs have a least a mute/unmute switch */
4182 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
4183 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
4184 "Mono Playback Switch",
4185 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01004186 if (err < 0)
4187 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004188 /* check for volume support for the amp */
4189 if ((caps & AC_AMPCAP_NUM_STEPS)
4190 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
4191 err = stac92xx_add_control(spec,
4192 STAC_CTL_WIDGET_VOL,
4193 "Mono Playback Volume",
4194 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
4195 if (err < 0)
4196 return err;
4197 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01004198 }
4199
4200 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
4201 AC_PINCTL_OUT_EN);
4202 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004203
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004204 if (!spec->multiout.num_dacs) {
4205 err = stac92xx_auto_fill_dac_nids(codec);
4206 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02004207 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01004208 err = stac92xx_auto_create_multi_out_ctls(codec,
4209 &spec->autocfg);
4210 if (err < 0)
4211 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004212 }
Mattc7d4b2f2005-06-27 14:59:41 +02004213
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004214 /* setup analog beep controls */
4215 if (spec->anabeep_nid > 0) {
4216 err = stac92xx_auto_create_beep_ctls(codec,
4217 spec->anabeep_nid);
4218 if (err < 0)
4219 return err;
4220 }
4221
4222 /* setup digital beep controls and input device */
4223#ifdef CONFIG_SND_HDA_INPUT_BEEP
4224 if (spec->digbeep_nid > 0) {
4225 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01004226 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004227
4228 err = stac92xx_auto_create_beep_ctls(codec, nid);
4229 if (err < 0)
4230 return err;
4231 err = snd_hda_attach_beep_device(codec, nid);
4232 if (err < 0)
4233 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01004234 if (codec->beep) {
4235 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01004236 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01004237 /* if no beep switch is available, make its own one */
4238 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
4239 if (!(caps & AC_AMPCAP_MUTE)) {
4240 err = stac92xx_beep_switch_ctl(codec);
4241 if (err < 0)
4242 return err;
4243 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01004244 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004245 }
4246#endif
4247
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004248 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004249 if (err < 0)
4250 return err;
4251
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004252 /* All output parsing done, now restore the swapped hp pins */
4253 if (hp_swap) {
4254 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
4255 sizeof(spec->autocfg.hp_pins));
4256 spec->autocfg.hp_outs = spec->autocfg.line_outs;
4257 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
4258 spec->autocfg.line_outs = 0;
4259 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004260
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004261 if (stac_check_auto_mic(codec)) {
4262 spec->auto_mic = 1;
4263 /* only one capture for auto-mic */
4264 spec->num_adcs = 1;
4265 spec->num_caps = 1;
4266 spec->num_muxes = 1;
4267 }
4268
Takashi Iwai6479c632009-07-28 18:20:25 +02004269 for (i = 0; i < spec->num_caps; i++) {
4270 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
4271 spec->capsws[i], i);
4272 if (err < 0)
4273 return err;
4274 }
4275
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004276 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004277 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004278 return err;
4279
Matthew Ranostayb22b4822008-01-22 12:32:30 +01004280 if (spec->mono_nid > 0) {
4281 err = stac92xx_auto_create_mono_output_ctls(codec);
4282 if (err < 0)
4283 return err;
4284 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004285 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02004286 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
4287 &spec->autocfg)) < 0)
4288 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02004289 if (spec->num_muxes > 0) {
4290 err = stac92xx_auto_create_mux_input_ctls(codec);
4291 if (err < 0)
4292 return err;
4293 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02004294 if (spec->num_smuxes > 0) {
4295 err = stac92xx_auto_create_spdif_mux_ctls(codec);
4296 if (err < 0)
4297 return err;
4298 }
Matt Porter8b657272006-10-26 17:12:59 +02004299
Takashi Iwaie3c75962009-01-23 11:57:22 +01004300 err = stac92xx_add_input_source(spec);
4301 if (err < 0)
4302 return err;
4303
Mattc7d4b2f2005-06-27 14:59:41 +02004304 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01004305 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02004306 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02004307
Charles Chin9009b0e2011-11-03 10:27:27 +01004308 /* find digital out and in converters */
4309 for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
4310 unsigned int wid_caps = get_wcaps(codec, i);
4311 if (wid_caps & AC_WCAP_DIGITAL) {
4312 switch (get_wcaps_type(wid_caps)) {
4313 case AC_WID_AUD_OUT:
4314 if (!dig_out)
4315 dig_out = i;
4316 break;
4317 case AC_WID_AUD_IN:
4318 if (!dig_in)
4319 dig_in = i;
4320 break;
4321 }
4322 }
4323 }
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004324 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004325 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004326 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004327 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02004328
Takashi Iwai603c4012008-07-30 15:01:44 +02004329 if (spec->kctls.list)
4330 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004331
4332 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05004333 if (!spec->dinput_mux)
4334 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004335 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01004336 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02004337 return 1;
4338}
4339
Takashi Iwai82bc9552006-03-21 11:24:42 +01004340/* add playback controls for HP output */
4341static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4342 struct auto_pin_cfg *cfg)
4343{
4344 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004345 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01004346
4347 if (! pin)
4348 return 0;
4349
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004350 if (is_jack_detectable(codec, pin))
Takashi Iwai82bc9552006-03-21 11:24:42 +01004351 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004352
4353 return 0;
4354}
4355
Richard Fish160ea0d2006-09-06 13:58:25 +02004356/* add playback controls for LFE output */
4357static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4358 struct auto_pin_cfg *cfg)
4359{
4360 struct sigmatel_spec *spec = codec->spec;
4361 int err;
4362 hda_nid_t lfe_pin = 0x0;
4363 int i;
4364
4365 /*
4366 * search speaker outs and line outs for a mono speaker pin
4367 * with an amp. If one is found, add LFE controls
4368 * for it.
4369 */
4370 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4371 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004372 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004373 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4374 if (wcaps == AC_WCAP_OUT_AMP)
4375 /* found a mono speaker with an amp, must be lfe */
4376 lfe_pin = pin;
4377 }
4378
4379 /* if speaker_outs is 0, then speakers may be in line_outs */
4380 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4381 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4382 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004383 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004384 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004385 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004386 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004387 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4388 if (wcaps == AC_WCAP_OUT_AMP)
4389 /* found a mono speaker with an amp,
4390 must be lfe */
4391 lfe_pin = pin;
4392 }
4393 }
4394 }
4395
4396 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004397 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004398 if (err < 0)
4399 return err;
4400 }
4401
4402 return 0;
4403}
4404
Mattc7d4b2f2005-06-27 14:59:41 +02004405static int stac9200_parse_auto_config(struct hda_codec *codec)
4406{
4407 struct sigmatel_spec *spec = codec->spec;
4408 int err;
4409
Kailang Yangdf694da2005-12-05 19:42:22 +01004410 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004411 return err;
4412
4413 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4414 return err;
4415
Takashi Iwai82bc9552006-03-21 11:24:42 +01004416 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4417 return err;
4418
Richard Fish160ea0d2006-09-06 13:58:25 +02004419 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4420 return err;
4421
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004422 if (spec->num_muxes > 0) {
4423 err = stac92xx_auto_create_mux_input_ctls(codec);
4424 if (err < 0)
4425 return err;
4426 }
4427
Takashi Iwaie3c75962009-01-23 11:57:22 +01004428 err = stac92xx_add_input_source(spec);
4429 if (err < 0)
4430 return err;
4431
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004432 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004433 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004434 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004435 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004436
Takashi Iwai603c4012008-07-30 15:01:44 +02004437 if (spec->kctls.list)
4438 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004439
4440 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004441 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004442
4443 return 1;
4444}
4445
Sam Revitch62fe78e2006-05-10 15:09:17 +02004446/*
4447 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4448 * funky external mute control using GPIO pins.
4449 */
4450
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004451static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004452 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004453{
4454 unsigned int gpiostate, gpiomask, gpiodir;
4455
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004456 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4457
Sam Revitch62fe78e2006-05-10 15:09:17 +02004458 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4459 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004460 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004461
4462 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4463 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004464 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004465
4466 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4467 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004468 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004469
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004470 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004471 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4472
4473 snd_hda_codec_write(codec, codec->afg, 0,
4474 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004475 snd_hda_codec_read(codec, codec->afg, 0,
4476 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004477
4478 msleep(1);
4479
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004480 snd_hda_codec_read(codec, codec->afg, 0,
4481 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004482}
4483
Takashi Iwai3a938972011-10-28 01:16:55 +02004484static int stac_add_event(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004485 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004486{
Takashi Iwai3a938972011-10-28 01:16:55 +02004487 struct hda_jack_tbl *event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004488
Takashi Iwai3a938972011-10-28 01:16:55 +02004489 event = snd_hda_jack_tbl_new(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004490 if (!event)
4491 return -ENOMEM;
Takashi Iwai3a938972011-10-28 01:16:55 +02004492 event->action = type;
4493 event->private_data = data;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004494
Takashi Iwai3a938972011-10-28 01:16:55 +02004495 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004496}
4497
David Henningsson29adc4b2012-09-25 11:31:00 +02004498static void handle_unsol_event(struct hda_codec *codec,
4499 struct hda_jack_tbl *event);
4500
Takashi Iwai62558ce2009-07-29 14:23:09 +02004501/* check if given nid is a valid pin and no other events are assigned
4502 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4503 * Otherwise, returns zero.
4504 */
4505static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4506 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004507{
Takashi Iwai3a938972011-10-28 01:16:55 +02004508 struct hda_jack_tbl *event;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004509
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004510 if (!is_jack_detectable(codec, nid))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004511 return 0;
Takashi Iwai3a938972011-10-28 01:16:55 +02004512 event = snd_hda_jack_tbl_new(codec, nid);
4513 if (!event)
4514 return -ENOMEM;
4515 if (event->action && event->action != type)
4516 return 0;
4517 event->action = type;
David Henningsson29adc4b2012-09-25 11:31:00 +02004518 event->callback = handle_unsol_event;
Takashi Iwai3a938972011-10-28 01:16:55 +02004519 snd_hda_jack_detect_enable(codec, nid, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004520 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004521}
4522
Takashi Iwaib4ead012012-01-23 18:23:36 +01004523static int is_nid_out_jack_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004524{
4525 int i;
4526 for (i = 0; i < cfg->hp_outs; i++)
4527 if (cfg->hp_pins[i] == nid)
4528 return 1; /* nid is a HP-Out */
Takashi Iwaib4ead012012-01-23 18:23:36 +01004529 for (i = 0; i < cfg->line_outs; i++)
4530 if (cfg->line_out_pins[i] == nid)
4531 return 1; /* nid is a line-Out */
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004532 return 0; /* nid is not a HP-Out */
4533};
4534
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004535static void stac92xx_power_down(struct hda_codec *codec)
4536{
4537 struct sigmatel_spec *spec = codec->spec;
4538
4539 /* power down inactive DACs */
Takashi Iwai2b635362011-05-02 12:33:43 +02004540 const hda_nid_t *dac;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004541 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004542 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004543 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004544 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4545}
4546
Takashi Iwaif73d3582008-11-25 08:21:51 +01004547static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4548 int enable);
4549
Takashi Iwaibc759722013-01-11 17:40:31 +01004550static inline bool get_int_hint(struct hda_codec *codec, const char *key,
4551 int *valp)
Takashi Iwai014c41f2009-12-27 13:53:24 +01004552{
Takashi Iwaibc759722013-01-11 17:40:31 +01004553 return !snd_hda_get_int_hint(codec, key, valp);
Takashi Iwai014c41f2009-12-27 13:53:24 +01004554}
4555
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004556/* override some hints from the hwdep entry */
4557static void stac_store_hints(struct hda_codec *codec)
4558{
4559 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004560 int val;
4561
4562 val = snd_hda_get_bool_hint(codec, "hp_detect");
4563 if (val >= 0)
4564 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004565 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004566 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4567 spec->gpio_mask;
4568 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004569 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4570 spec->gpio_mask &= spec->gpio_mask;
4571 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4572 spec->gpio_dir &= spec->gpio_mask;
4573 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4574 spec->eapd_mask &= spec->gpio_mask;
4575 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4576 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004577 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4578 if (val >= 0)
4579 spec->eapd_switch = val;
4580}
4581
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004582static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins,
4583 const hda_nid_t *pins)
4584{
4585 while (num_pins--)
4586 stac_issue_unsol_event(codec, *pins++);
4587}
4588
4589/* fake event to set up pins */
4590static void stac_fake_hp_events(struct hda_codec *codec)
4591{
4592 struct sigmatel_spec *spec = codec->spec;
4593
4594 if (spec->autocfg.hp_outs)
4595 stac_issue_unsol_events(codec, spec->autocfg.hp_outs,
4596 spec->autocfg.hp_pins);
4597 if (spec->autocfg.line_outs &&
4598 spec->autocfg.line_out_pins[0] != spec->autocfg.hp_pins[0])
4599 stac_issue_unsol_events(codec, spec->autocfg.line_outs,
4600 spec->autocfg.line_out_pins);
4601}
4602
Mattc7d4b2f2005-06-27 14:59:41 +02004603static int stac92xx_init(struct hda_codec *codec)
4604{
4605 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004606 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004607 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004608 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004609
David Henningsson5e68fb32012-08-16 14:11:09 +02004610 if (spec->init)
4611 snd_hda_sequence_write(codec, spec->init);
Mattc7d4b2f2005-06-27 14:59:41 +02004612
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01004613 snd_hda_apply_verbs(codec);
4614
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004615 /* power down adcs initially */
4616 if (spec->powerdown_adcs)
4617 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004618 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004619 spec->adc_nids[i], 0,
4620 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004621
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004622 /* override some hints */
4623 stac_store_hints(codec);
4624
Takashi Iwaif73d3582008-11-25 08:21:51 +01004625 /* set up GPIO */
4626 gpio = spec->gpio_data;
4627 /* turn on EAPD statically when spec->eapd_switch isn't set.
4628 * otherwise, unsol event will turn it on/off dynamically
4629 */
4630 if (!spec->eapd_switch)
4631 gpio |= spec->eapd_mask;
4632 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4633
Takashi Iwai82bc9552006-03-21 11:24:42 +01004634 /* set up pins */
4635 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004636 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004637 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004638 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004639 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004640 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004641 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4642 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004643 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004644 for (i = 0; i < cfg->line_outs; i++) {
4645 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004646 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4647 }
4648 }
4649
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004650 /* force to enable the first line-out; the others are set up
4651 * in unsol_event
4652 */
4653 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004654 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004655 /* fake event to set up pins */
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004656 stac_fake_hp_events(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004657 } else {
4658 stac92xx_auto_init_multi_out(codec);
4659 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004660 for (i = 0; i < cfg->hp_outs; i++)
4661 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004662 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004663 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004664 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004665 if (spec->dmux_nids)
4666 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004667 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004668 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4669 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004670 if (enable_pin_detect(codec, spec->dock_mic.pin,
4671 STAC_MIC_EVENT))
4672 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004673 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004674 for (i = 0; i < cfg->num_inputs; i++) {
4675 hda_nid_t nid = cfg->inputs[i].pin;
4676 int type = cfg->inputs[i].type;
4677 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004678 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004679 /* for mic pins, force to initialize */
Takashi Iwai47408602012-04-20 13:06:53 +02004680 pinctl = snd_hda_get_default_vref(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004681 pinctl |= AC_PINCTL_IN_EN;
4682 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4683 } else {
4684 pinctl = snd_hda_codec_read(codec, nid, 0,
4685 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4686 /* if PINCTL already set then skip */
4687 /* Also, if both INPUT and OUTPUT are set,
4688 * it must be a BIOS bug; need to override, too
4689 */
4690 if (!(pinctl & AC_PINCTL_IN_EN) ||
4691 (pinctl & AC_PINCTL_OUT_EN)) {
4692 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004693 pinctl |= AC_PINCTL_IN_EN;
4694 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004695 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004696 }
4697 conf = snd_hda_codec_get_pincfg(codec, nid);
4698 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4699 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4700 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004701 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004702 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004703 for (i = 0; i < spec->num_dmics; i++)
4704 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4705 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004706 if (cfg->dig_out_pins[0])
4707 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004708 AC_PINCTL_OUT_EN);
4709 if (cfg->dig_in_pin)
4710 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4711 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004712 for (i = 0; i < spec->num_pwrs; i++) {
4713 hda_nid_t nid = spec->pwr_nids[i];
Takashi Iwai6e1c39c2012-06-26 17:35:10 +02004714 unsigned int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004715
Takashi Iwaibfc89de2012-05-15 09:02:26 +02004716 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4717 def_conf = get_defcfg_connect(def_conf);
4718 if (def_conf == AC_JACK_PORT_NONE) {
4719 /* power off unused ports */
4720 stac_toggle_power_map(codec, nid, 0);
4721 continue;
4722 }
Takashi Iwai6e1c39c2012-06-26 17:35:10 +02004723 if (def_conf == AC_JACK_PORT_FIXED) {
4724 /* no need for jack detection for fixed pins */
4725 stac_toggle_power_map(codec, nid, 1);
4726 continue;
4727 }
Takashi Iwaieb632122008-12-19 16:39:48 +01004728 /* power on when no jack detection is available */
Takashi Iwai542c9a02011-11-29 13:01:30 +01004729 /* or when the VREF is used for controlling LED */
4730 if (!spec->hp_detect ||
Takashi Iwaibfc89de2012-05-15 09:02:26 +02004731 spec->vref_mute_led_nid == nid ||
4732 !is_jack_detectable(codec, nid)) {
Takashi Iwaieb632122008-12-19 16:39:48 +01004733 stac_toggle_power_map(codec, nid, 1);
4734 continue;
4735 }
4736
Takashi Iwaib4ead012012-01-23 18:23:36 +01004737 if (is_nid_out_jack_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004738 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004739
Takashi Iwaif73d3582008-11-25 08:21:51 +01004740 pinctl = snd_hda_codec_read(codec, nid, 0,
4741 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4742 /* outputs are only ports capable of power management
4743 * any attempts on powering down a input port cause the
4744 * referenced VREF to act quirky.
4745 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004746 if (pinctl & AC_PINCTL_IN_EN) {
4747 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004748 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004749 }
Charles Chinafef2cf2011-11-11 08:05:28 +01004750 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004751 stac_issue_unsol_event(codec, nid);
Charles Chinafef2cf2011-11-11 08:05:28 +01004752 continue;
4753 }
4754 /* none of the above, turn the port OFF */
4755 stac_toggle_power_map(codec, nid, 0);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004756 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004757
Takashi Iwaic21bd022010-02-08 15:16:08 +01004758 /* sync mute LED */
Takashi Iwai1f43f6c2012-07-31 10:40:05 +02004759 if (spec->gpio_led) {
4760 if (spec->vmaster_mute.hook)
4761 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4762 else /* the very first init call doesn't have vmaster yet */
4763 stac92xx_update_led_status(codec, false);
4764 }
Takashi Iwaic8822462012-05-15 09:11:36 +02004765
4766 /* sync the power-map */
4767 if (spec->num_pwrs)
4768 snd_hda_codec_write(codec, codec->afg, 0,
4769 AC_VERB_IDT_SET_POWER_MAP,
4770 spec->power_map_bits);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004771 if (spec->dac_list)
4772 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004773 return 0;
4774}
4775
Takashi Iwai603c4012008-07-30 15:01:44 +02004776static void stac92xx_free_kctls(struct hda_codec *codec)
4777{
4778 struct sigmatel_spec *spec = codec->spec;
4779
4780 if (spec->kctls.list) {
4781 struct snd_kcontrol_new *kctl = spec->kctls.list;
4782 int i;
4783 for (i = 0; i < spec->kctls.used; i++)
4784 kfree(kctl[i].name);
4785 }
4786 snd_array_free(&spec->kctls);
4787}
4788
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004789static void stac92xx_shutup_pins(struct hda_codec *codec)
4790{
4791 unsigned int i, def_conf;
4792
4793 if (codec->bus->shutdown)
4794 return;
4795 for (i = 0; i < codec->init_pins.used; i++) {
4796 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4797 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4798 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004799 snd_hda_set_pin_ctl(codec, pin->nid, 0);
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004800 }
4801}
4802
Takashi Iwai167eae52009-11-06 15:47:50 +01004803static void stac92xx_shutup(struct hda_codec *codec)
4804{
4805 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004806
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004807 stac92xx_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004808
4809 if (spec->eapd_mask)
4810 stac_gpio_set(codec, spec->gpio_mask,
4811 spec->gpio_dir, spec->gpio_data &
4812 ~spec->eapd_mask);
4813}
4814
Matt2f2f4252005-04-13 14:45:30 +02004815static void stac92xx_free(struct hda_codec *codec)
4816{
Mattc7d4b2f2005-06-27 14:59:41 +02004817 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004818
4819 if (! spec)
4820 return;
4821
Mattc7d4b2f2005-06-27 14:59:41 +02004822 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004823 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004824}
4825
Matt4e550962005-07-04 17:51:39 +02004826static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4827 unsigned int flag)
4828{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004829 unsigned int old_ctl, pin_ctl;
4830
4831 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004832 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004833
Takashi Iwaif9acba42007-05-29 18:01:06 +02004834 if (pin_ctl & AC_PINCTL_IN_EN) {
4835 /*
4836 * we need to check the current set-up direction of
4837 * shared input pins since they can be switched via
4838 * "xxx as Output" mixer switch
4839 */
4840 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004841 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004842 return;
4843 }
4844
Takashi Iwai8ce84192009-01-22 16:59:20 +01004845 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004846 /* if setting pin direction bits, clear the current
4847 direction bits first */
4848 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4849 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4850
Takashi Iwai8ce84192009-01-22 16:59:20 +01004851 pin_ctl |= flag;
4852 if (old_ctl != pin_ctl)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004853 snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004854}
4855
4856static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4857 unsigned int flag)
4858{
4859 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4860 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004861 if (pin_ctl & flag)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004862 snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004863}
4864
Takashi Iwaid56757a2009-11-18 08:00:14 +01004865static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004866{
4867 if (!nid)
4868 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004869 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004870}
4871
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004872static void stac92xx_line_out_detect(struct hda_codec *codec,
4873 int presence)
4874{
4875 struct sigmatel_spec *spec = codec->spec;
4876 struct auto_pin_cfg *cfg = &spec->autocfg;
4877 int i;
4878
David Henningsson042b92c2012-08-22 16:10:43 +02004879 if (cfg->speaker_outs == 0)
4880 return;
4881
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004882 for (i = 0; i < cfg->line_outs; i++) {
4883 if (presence)
4884 break;
4885 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4886 if (presence) {
4887 unsigned int pinctl;
4888 pinctl = snd_hda_codec_read(codec,
4889 cfg->line_out_pins[i], 0,
4890 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4891 if (pinctl & AC_PINCTL_IN_EN)
4892 presence = 0; /* mic- or line-input */
4893 }
4894 }
4895
4896 if (presence) {
4897 /* disable speakers */
4898 for (i = 0; i < cfg->speaker_outs; i++)
4899 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4900 AC_PINCTL_OUT_EN);
4901 if (spec->eapd_mask && spec->eapd_switch)
4902 stac_gpio_set(codec, spec->gpio_mask,
4903 spec->gpio_dir, spec->gpio_data &
4904 ~spec->eapd_mask);
4905 } else {
4906 /* enable speakers */
4907 for (i = 0; i < cfg->speaker_outs; i++)
4908 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4909 AC_PINCTL_OUT_EN);
4910 if (spec->eapd_mask && spec->eapd_switch)
4911 stac_gpio_set(codec, spec->gpio_mask,
4912 spec->gpio_dir, spec->gpio_data |
4913 spec->eapd_mask);
4914 }
4915}
4916
Takashi Iwaid7a89432008-11-12 09:48:04 +01004917/* return non-zero if the hp-pin of the given array index isn't
4918 * a jack-detection target
4919 */
4920static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4921{
4922 struct auto_pin_cfg *cfg = &spec->autocfg;
4923
4924 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004925 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004926 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004927 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004928 return 1;
4929 /* ignore if the pin is set as line-out */
4930 if (cfg->hp_pins[i] == spec->hp_switch)
4931 return 1;
4932 return 0;
4933}
4934
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004935static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004936{
4937 struct sigmatel_spec *spec = codec->spec;
4938 struct auto_pin_cfg *cfg = &spec->autocfg;
4939 int i, presence;
4940
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004941 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004942 if (spec->gpio_mute)
4943 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4944 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4945
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004946 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004947 if (presence)
4948 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004949 if (no_hp_sensing(spec, i))
4950 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004951 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4952 if (presence) {
4953 unsigned int pinctl;
4954 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4955 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4956 if (pinctl & AC_PINCTL_IN_EN)
4957 presence = 0; /* mic- or line-input */
4958 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004959 }
Matt4e550962005-07-04 17:51:39 +02004960
4961 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004962 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004963 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004964 stac92xx_reset_pinctl(codec, spec->hp_switch,
4965 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004966 for (i = 0; i < cfg->line_outs; i++)
4967 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4968 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004969 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004970 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004971 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004972 stac92xx_set_pinctl(codec, spec->hp_switch,
4973 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004974 for (i = 0; i < cfg->line_outs; i++)
4975 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4976 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004977 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004978 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004979 /* toggle hp outs */
4980 for (i = 0; i < cfg->hp_outs; i++) {
4981 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4982 if (no_hp_sensing(spec, i))
4983 continue;
Takashi Iwai7bff1722012-02-29 09:41:17 +01004984 if (1 /*presence*/)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004985 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004986#if 0 /* FIXME */
4987/* Resetting the pinctl like below may lead to (a sort of) regressions
4988 * on some devices since they use the HP pin actually for line/speaker
4989 * outs although the default pin config shows a different pin (that is
4990 * wrong and useless).
4991 *
4992 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4993 * But, disabling the code below just works around it, and I'm too tired of
4994 * bug reports with such devices...
4995 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004996 else
4997 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004998#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004999 }
Matt4e550962005-07-04 17:51:39 +02005000}
5001
Takashi Iwaif73d3582008-11-25 08:21:51 +01005002static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
5003 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005004{
5005 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01005006 unsigned int idx, val;
5007
5008 for (idx = 0; idx < spec->num_pwrs; idx++) {
5009 if (spec->pwr_nids[idx] == nid)
5010 break;
5011 }
5012 if (idx >= spec->num_pwrs)
5013 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005014
Charles Chinafef2cf2011-11-11 08:05:28 +01005015 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005016
Takashi Iwaic8822462012-05-15 09:11:36 +02005017 val = spec->power_map_bits;
Takashi Iwaif73d3582008-11-25 08:21:51 +01005018 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005019 val &= ~idx;
5020 else
5021 val |= idx;
5022
5023 /* power down unused output ports */
Takashi Iwaic8822462012-05-15 09:11:36 +02005024 if (val != spec->power_map_bits) {
5025 spec->power_map_bits = val;
5026 snd_hda_codec_write(codec, codec->afg, 0,
5027 AC_VERB_IDT_SET_POWER_MAP, val);
5028 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005029}
5030
Takashi Iwaif73d3582008-11-25 08:21:51 +01005031static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
5032{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01005033 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01005034}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005035
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005036/* get the pin connection (fixed, none, etc) */
5037static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5038{
5039 struct sigmatel_spec *spec = codec->spec;
5040 unsigned int cfg;
5041
5042 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5043 return get_defcfg_connect(cfg);
5044}
5045
5046static int stac92xx_connected_ports(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02005047 const hda_nid_t *nids, int num_nids)
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005048{
5049 struct sigmatel_spec *spec = codec->spec;
5050 int idx, num;
5051 unsigned int def_conf;
5052
5053 for (num = 0; num < num_nids; num++) {
5054 for (idx = 0; idx < spec->num_pins; idx++)
5055 if (spec->pin_nids[idx] == nids[num])
5056 break;
5057 if (idx >= spec->num_pins)
5058 break;
5059 def_conf = stac_get_defcfg_connect(codec, idx);
5060 if (def_conf == AC_JACK_PORT_NONE)
5061 break;
5062 }
5063 return num;
5064}
5065
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005066static void stac92xx_mic_detect(struct hda_codec *codec)
5067{
5068 struct sigmatel_spec *spec = codec->spec;
5069 struct sigmatel_mic_route *mic;
5070
5071 if (get_pin_presence(codec, spec->ext_mic.pin))
5072 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02005073 else if (get_pin_presence(codec, spec->dock_mic.pin))
5074 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005075 else
5076 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02005077 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005078 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
5079 AC_VERB_SET_CONNECT_SEL,
5080 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02005081 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005082 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
5083 AC_VERB_SET_CONNECT_SEL,
5084 mic->mux_idx);
5085}
5086
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005087static void handle_unsol_event(struct hda_codec *codec,
Takashi Iwai3a938972011-10-28 01:16:55 +02005088 struct hda_jack_tbl *event)
Takashi Iwai314634b2006-09-21 11:56:18 +02005089{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005090 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005091 int data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005092
Takashi Iwai3a938972011-10-28 01:16:55 +02005093 switch (event->action) {
Takashi Iwai314634b2006-09-21 11:56:18 +02005094 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02005095 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02005096 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02005097 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005098 case STAC_MIC_EVENT:
5099 stac92xx_mic_detect(codec);
5100 break;
5101 }
5102
Takashi Iwai3a938972011-10-28 01:16:55 +02005103 switch (event->action) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005104 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02005105 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005106 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005107 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005108 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005109 if (spec->num_pwrs > 0)
5110 stac92xx_pin_sense(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04005111
5112 switch (codec->subsystem_id) {
5113 case 0x103c308f:
5114 if (event->nid == 0xb) {
5115 int pin = AC_PINCTL_IN_EN;
5116
5117 if (get_pin_presence(codec, 0xa)
5118 && get_pin_presence(codec, 0xb))
5119 pin |= AC_PINCTL_VREF_80;
5120 if (!get_pin_presence(codec, 0xb))
5121 pin |= AC_PINCTL_VREF_80;
5122
5123 /* toggle VREF state based on mic + hp pin
5124 * status
5125 */
5126 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
5127 }
5128 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04005129 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005130 case STAC_VREF_EVENT:
5131 data = snd_hda_codec_read(codec, codec->afg, 0,
5132 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005133 /* toggle VREF state based on GPIOx status */
5134 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwai3a938972011-10-28 01:16:55 +02005135 !!(data & (1 << event->private_data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04005136 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02005137 }
5138}
5139
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005140static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
5141{
Takashi Iwai3a938972011-10-28 01:16:55 +02005142 struct hda_jack_tbl *event = snd_hda_jack_tbl_get(codec, nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005143 if (!event)
5144 return;
5145 handle_unsol_event(codec, event);
5146}
5147
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305148static int hp_blike_system(u32 subsystem_id);
5149
5150static void set_hp_led_gpio(struct hda_codec *codec)
5151{
5152 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01005153 unsigned int gpio;
5154
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005155 if (spec->gpio_led)
5156 return;
5157
Takashi Iwai07f80442010-02-08 15:06:13 +01005158 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
5159 gpio &= AC_GPIO_IO_COUNT;
5160 if (gpio > 3)
5161 spec->gpio_led = 0x08; /* GPIO 3 */
5162 else
5163 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305164}
5165
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005166/*
5167 * This method searches for the mute LED GPIO configuration
5168 * provided as OEM string in SMBIOS. The format of that string
5169 * is HP_Mute_LED_P_G or HP_Mute_LED_P
5170 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
5171 * that corresponds to the NOT muted state of the master volume
5172 * and G is the index of the GPIO to use as the mute LED control (0..9)
5173 * If _G portion is missing it is assigned based on the codec ID
5174 *
5175 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
5176 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305177 *
5178 *
5179 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
5180 * SMBIOS - at least the ones I have seen do not have them - which include
5181 * my own system (HP Pavilion dv6-1110ax) and my cousin's
5182 * HP Pavilion dv9500t CTO.
5183 * Need more information on whether it is true across the entire series.
5184 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005185 */
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005186static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005187{
5188 struct sigmatel_spec *spec = codec->spec;
5189 const struct dmi_device *dev = NULL;
5190
Takashi Iwai75609312012-05-14 16:52:00 +02005191 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
5192 get_int_hint(codec, "gpio_led_polarity",
5193 &spec->gpio_led_polarity);
5194 return 1;
5195 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005196 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
5197 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
5198 NULL, dev))) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005199 if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305200 &spec->gpio_led_polarity,
5201 &spec->gpio_led) == 2) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005202 unsigned int max_gpio;
5203 max_gpio = snd_hda_param_read(codec, codec->afg,
5204 AC_PAR_GPIO_CAP);
5205 max_gpio &= AC_GPIO_IO_COUNT;
5206 if (spec->gpio_led < max_gpio)
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005207 spec->gpio_led = 1 << spec->gpio_led;
Takashi Iwaif1a73742011-12-04 13:44:06 +01005208 else
5209 spec->vref_mute_led_nid = spec->gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005210 return 1;
5211 }
5212 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305213 &spec->gpio_led_polarity) == 1) {
5214 set_hp_led_gpio(codec);
5215 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005216 }
Gustavo Maciel Dias Vieirae2ef36c2011-12-13 11:47:22 -02005217 /* BIOS bug: unfilled OEM string */
5218 if (strstr(dev->name, "HP_Mute_LED_P_G")) {
5219 set_hp_led_gpio(codec);
Gustavo Maciel Dias Vieiraa6a600d2012-01-24 13:27:56 -02005220 switch (codec->subsystem_id) {
5221 case 0x103c148a:
5222 spec->gpio_led_polarity = 0;
5223 break;
5224 default:
5225 spec->gpio_led_polarity = 1;
5226 break;
5227 }
Gustavo Maciel Dias Vieirae2ef36c2011-12-13 11:47:22 -02005228 return 1;
5229 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005230 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305231
5232 /*
5233 * Fallback case - if we don't find the DMI strings,
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005234 * we statically set the GPIO - if not a B-series system
5235 * and default polarity is provided
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305236 */
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005237 if (!hp_blike_system(codec->subsystem_id) &&
5238 (default_polarity == 0 || default_polarity == 1)) {
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305239 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01005240 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305241 return 1;
5242 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005243 }
5244 return 0;
5245}
5246
5247static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08005248{
5249 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005250 case 0x103c1520:
5251 case 0x103c1521:
5252 case 0x103c1523:
5253 case 0x103c1524:
5254 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08005255 case 0x103c1722:
5256 case 0x103c1723:
5257 case 0x103c1724:
5258 case 0x103c1725:
5259 case 0x103c1726:
5260 case 0x103c1727:
5261 case 0x103c1728:
5262 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005263 case 0x103c172a:
5264 case 0x103c172b:
5265 case 0x103c307e:
5266 case 0x103c307f:
5267 case 0x103c3080:
5268 case 0x103c3081:
5269 case 0x103c7007:
5270 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08005271 return 1;
5272 }
5273 return 0;
5274}
5275
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005276#ifdef CONFIG_PROC_FS
5277static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
5278 struct hda_codec *codec, hda_nid_t nid)
5279{
5280 if (nid == codec->afg)
5281 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
Takashi Iwaic8822462012-05-15 09:11:36 +02005282 snd_hda_codec_read(codec, nid, 0,
5283 AC_VERB_IDT_GET_POWER_MAP, 0));
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005284}
5285
5286static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
5287 struct hda_codec *codec,
5288 unsigned int verb)
5289{
5290 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
5291 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
5292}
5293
5294/* stac92hd71bxx, stac92hd73xx */
5295static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
5296 struct hda_codec *codec, hda_nid_t nid)
5297{
5298 stac92hd_proc_hook(buffer, codec, nid);
5299 if (nid == codec->afg)
5300 analog_loop_proc_hook(buffer, codec, 0xfa0);
5301}
5302
5303static void stac9205_proc_hook(struct snd_info_buffer *buffer,
5304 struct hda_codec *codec, hda_nid_t nid)
5305{
5306 if (nid == codec->afg)
5307 analog_loop_proc_hook(buffer, codec, 0xfe0);
5308}
5309
5310static void stac927x_proc_hook(struct snd_info_buffer *buffer,
5311 struct hda_codec *codec, hda_nid_t nid)
5312{
5313 if (nid == codec->afg)
5314 analog_loop_proc_hook(buffer, codec, 0xfeb);
5315}
5316#else
5317#define stac92hd_proc_hook NULL
5318#define stac92hd7x_proc_hook NULL
5319#define stac9205_proc_hook NULL
5320#define stac927x_proc_hook NULL
5321#endif
5322
Takashi Iwai2a439522011-07-26 09:52:50 +02005323#ifdef CONFIG_PM
Mattff6fdc32005-06-27 15:06:52 +02005324static int stac92xx_resume(struct hda_codec *codec)
5325{
Takashi Iwai2c885872008-11-18 09:36:55 +01005326 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02005327 snd_hda_codec_resume_amp(codec);
5328 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01005329 /* fake event to set up pins again to override cached values */
Takashi Iwaif2cbba72012-01-11 12:34:11 +01005330 stac_fake_hp_events(codec);
Mattff6fdc32005-06-27 15:06:52 +02005331 return 0;
5332}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005333
Takashi Iwai68cb2b52012-07-02 15:20:37 +02005334static int stac92xx_suspend(struct hda_codec *codec)
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005335{
5336 stac92xx_shutup(codec);
5337 return 0;
5338}
5339
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005340static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5341 unsigned int power_state)
5342{
5343 unsigned int afg_power_state = power_state;
5344 struct sigmatel_spec *spec = codec->spec;
5345
5346 if (power_state == AC_PWRST_D3) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005347 if (spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005348 /* with vref-out pin used for mute led control
5349 * codec AFG is prevented from D3 state
5350 */
5351 afg_power_state = AC_PWRST_D1;
5352 }
5353 /* this delay seems necessary to avoid click noise at power-down */
5354 msleep(100);
5355 }
5356 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5357 afg_power_state);
5358 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
5359}
Takashi Iwai350eba432012-03-16 16:09:03 +01005360#else
5361#define stac92xx_suspend NULL
5362#define stac92xx_resume NULL
Takashi Iwai350eba432012-03-16 16:09:03 +01005363#define stac92xx_set_power_state NULL
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005364#endif /* CONFIG_PM */
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005365
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005366/* update mute-LED accoring to the master switch */
5367static void stac92xx_update_led_status(struct hda_codec *codec, int enabled)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005368{
5369 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005370 int muted = !enabled;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005371
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005372 if (!spec->gpio_led)
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005373 return;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005374
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005375 /* LED state is inverted on these systems */
5376 if (spec->gpio_led_polarity)
5377 muted = !muted;
5378
Takashi Iwaif1a73742011-12-04 13:44:06 +01005379 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005380 if (muted)
Takashi Iwai3e843192012-04-19 12:04:03 +02005381 spec->gpio_data |= spec->gpio_led;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005382 else
Takashi Iwai3e843192012-04-19 12:04:03 +02005383 spec->gpio_data &= ~spec->gpio_led;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005384 stac_gpio_set(codec, spec->gpio_mask,
5385 spec->gpio_dir, spec->gpio_data);
5386 } else {
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005387 spec->vref_led = muted ? AC_PINCTL_VREF_50 : AC_PINCTL_VREF_GRD;
Takashi Iwaif1a73742011-12-04 13:44:06 +01005388 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5389 spec->vref_led);
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005390 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005391}
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005392
Takashi Iwai2b635362011-05-02 12:33:43 +02005393static const struct hda_codec_ops stac92xx_patch_ops = {
Matt2f2f4252005-04-13 14:45:30 +02005394 .build_controls = stac92xx_build_controls,
5395 .build_pcms = stac92xx_build_pcms,
5396 .init = stac92xx_init,
5397 .free = stac92xx_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02005398 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02005399#ifdef CONFIG_PM
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005400 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005401 .resume = stac92xx_resume,
5402#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005403 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005404};
5405
Takashi Iwai361dab32012-05-09 14:35:27 +02005406static int alloc_stac_spec(struct hda_codec *codec, int num_pins,
5407 const hda_nid_t *pin_nids)
5408{
5409 struct sigmatel_spec *spec;
5410
5411 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5412 if (!spec)
5413 return -ENOMEM;
5414 codec->spec = spec;
5415 codec->no_trigger_sense = 1; /* seems common with STAC/IDT codecs */
5416 spec->num_pins = num_pins;
5417 spec->pin_nids = pin_nids;
5418 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
5419 return 0;
5420}
5421
Matt2f2f4252005-04-13 14:45:30 +02005422static int patch_stac9200(struct hda_codec *codec)
5423{
5424 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005425 int err;
Matt2f2f4252005-04-13 14:45:30 +02005426
Takashi Iwai361dab32012-05-09 14:35:27 +02005427 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9200_pin_nids),
5428 stac9200_pin_nids);
5429 if (err < 0)
5430 return err;
Matt2f2f4252005-04-13 14:45:30 +02005431
Takashi Iwai361dab32012-05-09 14:35:27 +02005432 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005433 spec->linear_tone_beep = 1;
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005434
5435 snd_hda_pick_fixup(codec, stac9200_models, stac9200_fixup_tbl,
5436 stac9200_fixups);
Matt2f2f4252005-04-13 14:45:30 +02005437
5438 spec->multiout.max_channels = 2;
5439 spec->multiout.num_dacs = 1;
5440 spec->multiout.dac_nids = stac9200_dac_nids;
5441 spec->adc_nids = stac9200_adc_nids;
5442 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005443 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005444 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005445 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005446 spec->num_pwrs = 0;
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005447 snd_hda_add_verbs(codec, stac9200_eapd_init);
Mattc7d4b2f2005-06-27 14:59:41 +02005448
Matt2f2f4252005-04-13 14:45:30 +02005449 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005450
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005451 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
Takashi Iwai117f2572008-03-18 09:53:23 +01005452
Mattc7d4b2f2005-06-27 14:59:41 +02005453 err = stac9200_parse_auto_config(codec);
5454 if (err < 0) {
5455 stac92xx_free(codec);
5456 return err;
5457 }
Matt2f2f4252005-04-13 14:45:30 +02005458
5459 codec->patch_ops = stac92xx_patch_ops;
5460
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005461 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5462
Matt2f2f4252005-04-13 14:45:30 +02005463 return 0;
5464}
5465
Tobin Davis8e21c342007-01-08 11:04:17 +01005466static int patch_stac925x(struct hda_codec *codec)
5467{
5468 struct sigmatel_spec *spec;
5469 int err;
5470
Takashi Iwai361dab32012-05-09 14:35:27 +02005471 err = alloc_stac_spec(codec, ARRAY_SIZE(stac925x_pin_nids),
5472 stac925x_pin_nids);
5473 if (err < 0)
5474 return err;
Tobin Davis8e21c342007-01-08 11:04:17 +01005475
Takashi Iwai361dab32012-05-09 14:35:27 +02005476 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005477 spec->linear_tone_beep = 1;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005478
Takashi Iwaid2077d42013-01-14 14:20:16 +01005479 snd_hda_pick_fixup(codec, stac925x_models, stac925x_fixup_tbl,
5480 stac925x_fixups);
Tobin Davis8e21c342007-01-08 11:04:17 +01005481
5482 spec->multiout.max_channels = 2;
5483 spec->multiout.num_dacs = 1;
5484 spec->multiout.dac_nids = stac925x_dac_nids;
5485 spec->adc_nids = stac925x_adc_nids;
5486 spec->mux_nids = stac925x_mux_nids;
5487 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005488 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005489 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005490 switch (codec->vendor_id) {
5491 case 0x83847632: /* STAC9202 */
5492 case 0x83847633: /* STAC9202D */
5493 case 0x83847636: /* STAC9251 */
5494 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005495 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005496 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005497 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5498 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005499 break;
5500 default:
5501 spec->num_dmics = 0;
5502 break;
5503 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005504
Takashi Iwaid2077d42013-01-14 14:20:16 +01005505 snd_hda_add_verbs(codec, stac925x_core_init);
Tobin Davis8e21c342007-01-08 11:04:17 +01005506 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005507 spec->num_caps = 1;
5508 spec->capvols = stac925x_capvols;
5509 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005510
Takashi Iwaid2077d42013-01-14 14:20:16 +01005511 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5512
Charles Chin9009b0e2011-11-03 10:27:27 +01005513 err = stac92xx_parse_auto_config(codec);
Takashi Iwaid2077d42013-01-14 14:20:16 +01005514 if (!err)
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005515 err = -EINVAL;
Tobin Davis8e21c342007-01-08 11:04:17 +01005516 if (err < 0) {
5517 stac92xx_free(codec);
5518 return err;
5519 }
5520
5521 codec->patch_ops = stac92xx_patch_ops;
5522
Takashi Iwaid2077d42013-01-14 14:20:16 +01005523 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5524
Tobin Davis8e21c342007-01-08 11:04:17 +01005525 return 0;
5526}
5527
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005528static int patch_stac92hd73xx(struct hda_codec *codec)
5529{
5530 struct sigmatel_spec *spec;
5531 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
Takashi Iwai361dab32012-05-09 14:35:27 +02005532 int err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005533 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005534
Takashi Iwai361dab32012-05-09 14:35:27 +02005535 err = alloc_stac_spec(codec, ARRAY_SIZE(stac92hd73xx_pin_nids),
5536 stac92hd73xx_pin_nids);
5537 if (err < 0)
5538 return err;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005539
Takashi Iwai361dab32012-05-09 14:35:27 +02005540 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005541 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005542 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005543 spec->board_config = snd_hda_check_board_config(codec,
5544 STAC_92HD73XX_MODELS,
5545 stac92hd73xx_models,
5546 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005547 /* check codec subsystem id if not found */
5548 if (spec->board_config < 0)
5549 spec->board_config =
5550 snd_hda_check_board_codec_sid_config(codec,
5551 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5552 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005553again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005554 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005555 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5556 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005557 else
5558 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005559 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005560
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005561 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005562 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5563
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005564 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005565 printk(KERN_WARNING "hda_codec: Could not determine "
5566 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005567 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005568 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005569 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005570 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005571 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005572 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005573 break;
5574 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005575 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005576 break;
5577 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005578 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5579 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005580 }
5581 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005582
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005583 spec->aloopback_mask = 0x01;
5584 spec->aloopback_shift = 8;
5585
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005586 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005587 spec->mux_nids = stac92hd73xx_mux_nids;
5588 spec->adc_nids = stac92hd73xx_adc_nids;
5589 spec->dmic_nids = stac92hd73xx_dmic_nids;
5590 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005591 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005592
5593 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5594 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005595 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005596
Takashi Iwai6479c632009-07-28 18:20:25 +02005597 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5598 spec->capvols = stac92hd73xx_capvols;
5599 spec->capsws = stac92hd73xx_capsws;
5600
Matthew Ranostaya7662642008-02-21 07:51:14 +01005601 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005602 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005603 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005604 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005605 case STAC_DELL_M6_AMIC:
5606 case STAC_DELL_M6_DMIC:
5607 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005608 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005609 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005610
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005611 switch (spec->board_config) {
5612 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005613 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005614 spec->num_dmics = 0;
5615 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005616 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005617 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005618 spec->num_dmics = 1;
5619 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005620 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005621 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5622 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005623 spec->num_dmics = 1;
5624 break;
5625 }
5626 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005627 case STAC_ALIENWARE_M17X:
5628 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5629 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5630 spec->eapd_switch = 0;
5631 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005632 default:
5633 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005634 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005635 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005636 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005637 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005638 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005639 /* GPIO0 High = Enable EAPD */
5640 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5641 spec->gpio_data = 0x01;
5642 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005643
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005644 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5645 spec->pwr_nids = stac92hd73xx_pwr_nids;
5646
Charles Chin9009b0e2011-11-03 10:27:27 +01005647 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005648
5649 if (!err) {
5650 if (spec->board_config < 0) {
5651 printk(KERN_WARNING "hda_codec: No auto-config is "
5652 "available, default to model=ref\n");
5653 spec->board_config = STAC_92HD73XX_REF;
5654 goto again;
5655 }
5656 err = -EINVAL;
5657 }
5658
5659 if (err < 0) {
5660 stac92xx_free(codec);
5661 return err;
5662 }
5663
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005664 if (spec->board_config == STAC_92HD73XX_NO_JD)
5665 spec->hp_detect = 0;
5666
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005667 codec->patch_ops = stac92xx_patch_ops;
5668
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005669 codec->proc_widget_hook = stac92hd7x_proc_hook;
5670
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005671 return 0;
5672}
5673
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005674static int hp_bnb2011_with_dock(struct hda_codec *codec)
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005675{
5676 if (codec->vendor_id != 0x111d7605 &&
5677 codec->vendor_id != 0x111d76d1)
5678 return 0;
5679
5680 switch (codec->subsystem_id) {
5681 case 0x103c1618:
5682 case 0x103c1619:
5683 case 0x103c161a:
5684 case 0x103c161b:
5685 case 0x103c161c:
5686 case 0x103c161d:
5687 case 0x103c161e:
5688 case 0x103c161f:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005689
5690 case 0x103c162a:
5691 case 0x103c162b:
5692
5693 case 0x103c1630:
5694 case 0x103c1631:
5695
5696 case 0x103c1633:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005697 case 0x103c1634:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005698 case 0x103c1635:
5699
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005700 case 0x103c3587:
5701 case 0x103c3588:
5702 case 0x103c3589:
5703 case 0x103c358a:
5704
5705 case 0x103c3667:
5706 case 0x103c3668:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005707 case 0x103c3669:
5708
5709 return 1;
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005710 }
5711 return 0;
5712}
5713
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005714static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
5715{
5716 struct sigmatel_spec *spec = codec->spec;
5717 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5718 int i;
5719
5720 spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5721 spec->auto_pin_cnt++;
5722
5723 if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5724 get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5725 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5726 if (nid == stac92hd83xxx_dmic_nids[i]) {
5727 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5728 spec->auto_dmic_cnt++;
5729 }
5730 }
5731 }
5732}
5733
5734static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5735{
5736 struct sigmatel_spec *spec = codec->spec;
5737
5738 spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5739 spec->auto_adc_cnt++;
5740}
5741
5742static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5743{
5744 int i, j;
5745 struct sigmatel_spec *spec = codec->spec;
5746
5747 for (i = 0; i < spec->auto_adc_cnt; i++) {
5748 if (get_connection_index(codec,
5749 spec->auto_adc_nids[i], nid) >= 0) {
5750 /* mux and volume for adc_nids[i] */
5751 if (!spec->auto_mux_nids[i]) {
5752 spec->auto_mux_nids[i] = nid;
5753 /* 92hd codecs capture volume is in mux */
5754 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
5755 3, 0, HDA_OUTPUT);
5756 }
5757 for (j = 0; j < spec->auto_dmic_cnt; j++) {
5758 if (get_connection_index(codec, nid,
5759 spec->auto_dmic_nids[j]) >= 0) {
5760 /* dmux for adc_nids[i] */
5761 if (!spec->auto_dmux_nids[i])
5762 spec->auto_dmux_nids[i] = nid;
5763 break;
5764 }
5765 }
5766 break;
5767 }
5768 }
5769}
5770
5771static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5772{
5773 hda_nid_t nid, end_nid;
5774 unsigned int wid_caps, wid_type;
5775 struct sigmatel_spec *spec = codec->spec;
5776
5777 end_nid = codec->start_nid + codec->num_nodes;
5778
5779 for (nid = codec->start_nid; nid < end_nid; nid++) {
5780 wid_caps = get_wcaps(codec, nid);
5781 wid_type = get_wcaps_type(wid_caps);
5782
5783 if (wid_type == AC_WID_PIN)
5784 stac92hd8x_add_pin(codec, nid);
5785
5786 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5787 stac92hd8x_add_adc(codec, nid);
5788 }
5789
5790 for (nid = codec->start_nid; nid < end_nid; nid++) {
5791 wid_caps = get_wcaps(codec, nid);
5792 wid_type = get_wcaps_type(wid_caps);
5793
5794 if (wid_type == AC_WID_AUD_SEL)
5795 stac92hd8x_add_mux(codec, nid);
5796 }
5797
5798 spec->pin_nids = spec->auto_pin_nids;
5799 spec->num_pins = spec->auto_pin_cnt;
5800 spec->adc_nids = spec->auto_adc_nids;
5801 spec->num_adcs = spec->auto_adc_cnt;
5802 spec->capvols = spec->auto_capvols;
5803 spec->capsws = spec->auto_capvols;
5804 spec->num_caps = spec->auto_adc_cnt;
5805 spec->mux_nids = spec->auto_mux_nids;
5806 spec->num_muxes = spec->auto_adc_cnt;
5807 spec->dmux_nids = spec->auto_dmux_nids;
5808 spec->num_dmuxes = spec->auto_adc_cnt;
5809 spec->dmic_nids = spec->auto_dmic_nids;
5810 spec->num_dmics = spec->auto_dmic_cnt;
5811}
5812
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005813static int patch_stac92hd83xxx(struct hda_codec *codec)
5814{
5815 struct sigmatel_spec *spec;
Takashi Iwaia3e19972012-07-26 08:17:20 +02005816 int default_polarity = -1; /* no default cfg */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005817 int err;
5818
Takashi Iwai361dab32012-05-09 14:35:27 +02005819 err = alloc_stac_spec(codec, 0, NULL); /* pins filled later */
5820 if (err < 0)
5821 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005822
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005823 if (hp_bnb2011_with_dock(codec)) {
5824 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5825 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5826 }
5827
Takashi Iwaic36b5b02012-08-28 09:20:13 -07005828 codec->epss = 0; /* longer delay needed for D3 */
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005829 stac92hd8x_fill_auto_spec(codec);
5830
Takashi Iwai361dab32012-05-09 14:35:27 +02005831 spec = codec->spec;
Takashi Iwai1db7ccdb2010-12-03 15:19:14 +01005832 spec->linear_tone_beep = 0;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005833 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005834 spec->digbeep_nid = 0x21;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005835 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005836 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005837 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005838 spec->init = stac92hd83xxx_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005839
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005840 spec->board_config = snd_hda_check_board_config(codec,
5841 STAC_92HD83XXX_MODELS,
5842 stac92hd83xxx_models,
5843 stac92hd83xxx_cfg_tbl);
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06005844 /* check codec subsystem id if not found */
5845 if (spec->board_config < 0)
5846 spec->board_config =
5847 snd_hda_check_board_codec_sid_config(codec,
5848 STAC_92HD83XXX_MODELS, stac92hd83xxx_models,
5849 stac92hd83xxx_codec_id_cfg_tbl);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005850again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005851 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005852 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5853 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005854 else
5855 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005856 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005857
Takashi Iwaib4e81872009-11-18 17:20:24 +01005858 codec->patch_ops = stac92xx_patch_ops;
5859
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06005860 switch (spec->board_config) {
5861 case STAC_HP_ZEPHYR:
5862 spec->init = stac92hd83xxx_hp_zephyr_init;
5863 break;
Takashi Iwaia3e19972012-07-26 08:17:20 +02005864 case STAC_92HD83XXX_HP_LED:
Takashi Iwaiff8a1e22012-07-31 10:16:59 +02005865 default_polarity = 0;
5866 break;
5867 case STAC_92HD83XXX_HP_INV_LED:
Takashi Iwaia3e19972012-07-26 08:17:20 +02005868 default_polarity = 1;
5869 break;
Takashi Iwai62cbde12012-09-14 11:58:54 +02005870 case STAC_92HD83XXX_HP_MIC_LED:
5871 spec->mic_mute_led_gpio = 0x08; /* GPIO3 */
5872 break;
David Henningsson8d032a82012-10-09 12:48:40 +02005873 case STAC_92HD83XXX_HEADSET_JACK:
5874 spec->headset_jack = 1;
5875 break;
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06005876 }
5877
Takashi Iwaia3e19972012-07-26 08:17:20 +02005878 if (find_mute_led_cfg(codec, default_polarity))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005879 snd_printd("mute LED gpio %d polarity %d\n",
5880 spec->gpio_led,
5881 spec->gpio_led_polarity);
5882
Takashi Iwaib4e81872009-11-18 17:20:24 +01005883 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005884 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005885 spec->gpio_mask |= spec->gpio_led;
5886 spec->gpio_dir |= spec->gpio_led;
5887 spec->gpio_data |= spec->gpio_led;
5888 } else {
5889 codec->patch_ops.set_power_state =
5890 stac92xx_set_power_state;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005891 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005892 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005893
Takashi Iwai62cbde12012-09-14 11:58:54 +02005894 if (spec->mic_mute_led_gpio) {
5895 spec->gpio_mask |= spec->mic_mute_led_gpio;
5896 spec->gpio_dir |= spec->mic_mute_led_gpio;
5897 spec->mic_mute_led_on = true;
5898 spec->gpio_data |= spec->mic_mute_led_gpio;
5899 }
5900
Charles Chin9009b0e2011-11-03 10:27:27 +01005901 err = stac92xx_parse_auto_config(codec);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005902 if (!err) {
5903 if (spec->board_config < 0) {
5904 printk(KERN_WARNING "hda_codec: No auto-config is "
5905 "available, default to model=ref\n");
5906 spec->board_config = STAC_92HD83XXX_REF;
5907 goto again;
5908 }
5909 err = -EINVAL;
5910 }
5911
5912 if (err < 0) {
5913 stac92xx_free(codec);
5914 return err;
5915 }
5916
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005917 codec->proc_widget_hook = stac92hd_proc_hook;
5918
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005919 return 0;
5920}
5921
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005922static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5923 hda_nid_t dig0pin)
5924{
5925 struct sigmatel_spec *spec = codec->spec;
5926 int idx;
5927
5928 for (idx = 0; idx < spec->num_pins; idx++)
5929 if (spec->pin_nids[idx] == dig0pin)
5930 break;
5931 if ((idx + 2) >= spec->num_pins)
5932 return 0;
5933
5934 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005935 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005936 return 2;
5937
5938 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005939 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005940 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005941 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005942 return 1;
5943 else
5944 return 0;
5945}
5946
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005947/* HP dv7 bass switch - GPIO5 */
5948#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5949static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5950 struct snd_ctl_elem_value *ucontrol)
5951{
5952 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5953 struct sigmatel_spec *spec = codec->spec;
5954 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5955 return 0;
5956}
5957
5958static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5959 struct snd_ctl_elem_value *ucontrol)
5960{
5961 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5962 struct sigmatel_spec *spec = codec->spec;
5963 unsigned int gpio_data;
5964
5965 gpio_data = (spec->gpio_data & ~0x20) |
5966 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5967 if (gpio_data == spec->gpio_data)
5968 return 0;
5969 spec->gpio_data = gpio_data;
5970 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5971 return 1;
5972}
5973
Takashi Iwai2b635362011-05-02 12:33:43 +02005974static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005975 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5976 .info = stac_hp_bass_gpio_info,
5977 .get = stac_hp_bass_gpio_get,
5978 .put = stac_hp_bass_gpio_put,
5979};
5980
5981static int stac_add_hp_bass_switch(struct hda_codec *codec)
5982{
5983 struct sigmatel_spec *spec = codec->spec;
5984
5985 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5986 "Bass Speaker Playback Switch", 0))
5987 return -ENOMEM;
5988
5989 spec->gpio_mask |= 0x20;
5990 spec->gpio_dir |= 0x20;
5991 spec->gpio_data |= 0x20;
5992 return 0;
5993}
5994
Matthew Ranostaye035b842007-11-06 11:53:55 +01005995static int patch_stac92hd71bxx(struct hda_codec *codec)
5996{
5997 struct sigmatel_spec *spec;
Takashi Iwai2b635362011-05-02 12:33:43 +02005998 const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005999 unsigned int pin_cfg;
Takashi Iwai361dab32012-05-09 14:35:27 +02006000 int err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006001
Takashi Iwai361dab32012-05-09 14:35:27 +02006002 err = alloc_stac_spec(codec, STAC92HD71BXX_NUM_PINS,
6003 stac92hd71bxx_pin_nids_4port);
6004 if (err < 0)
6005 return err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006006
Takashi Iwai361dab32012-05-09 14:35:27 +02006007 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006008 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006009 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05006010 switch (codec->vendor_id) {
6011 case 0x111d76b6:
6012 case 0x111d76b7:
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05006013 break;
6014 case 0x111d7603:
6015 case 0x111d7608:
6016 /* On 92HD75Bx 0x27 isn't a pin nid */
6017 spec->num_pins--;
6018 /* fallthrough */
6019 default:
6020 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
6021 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006022 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006023 spec->board_config = snd_hda_check_board_config(codec,
6024 STAC_92HD71BXX_MODELS,
6025 stac92hd71bxx_models,
6026 stac92hd71bxx_cfg_tbl);
6027again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006028 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006029 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6030 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006031 else
6032 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006033 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006034
Takashi Iwaifc64b262009-09-14 15:33:01 +02006035 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01006036 /* GPIO0 = EAPD */
6037 spec->gpio_mask = 0x01;
6038 spec->gpio_dir = 0x01;
6039 spec->gpio_data = 0x01;
6040 }
6041
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006042 spec->dmic_nids = stac92hd71bxx_dmic_nids;
6043 spec->dmux_nids = stac92hd71bxx_dmux_nids;
6044
Takashi Iwai6479c632009-07-28 18:20:25 +02006045 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
6046 spec->capvols = stac92hd71bxx_capvols;
6047 spec->capsws = stac92hd71bxx_capsws;
6048
Matthew Ranostay541eee82007-12-14 12:08:04 +01006049 switch (codec->vendor_id) {
6050 case 0x111d76b6: /* 4 Port without Analog Mixer */
6051 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02006052 unmute_init++;
6053 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01006054 case 0x111d76b4: /* 6 Port without Analog Mixer */
6055 case 0x111d76b5:
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04006056 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006057 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006058 stac92hd71bxx_dmic_nids,
6059 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01006060 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006061 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01006062 switch (spec->board_config) {
6063 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04006064 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwai3a938972011-10-28 01:16:55 +02006065 err = stac_add_event(codec, codec->afg,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006066 STAC_VREF_EVENT, 0x02);
6067 if (err < 0)
6068 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006069 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04006070 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
Takashi Iwai3a938972011-10-28 01:16:55 +02006071 snd_hda_jack_detect_enable(codec, codec->afg, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04006072 spec->gpio_mask |= 0x02;
6073 break;
6074 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006075 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01006076 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006077 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006078
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006079 /* disable VSW */
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05006080 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01006081 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
6082 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Takashi Iwai2b635362011-05-02 12:33:43 +02006083 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006084 spec->num_dmics = stac92xx_connected_ports(codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02006085 stac92hd71bxx_dmic_5port_nids,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006086 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006087 break;
6088 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01006089 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006090 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006091
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006092 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01006093 default:
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04006094 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006095 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006096 stac92hd71bxx_dmic_nids,
6097 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02006098 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01006099 }
6100
David Henningsson5e68fb32012-08-16 14:11:09 +02006101 if (get_wcaps_type(get_wcaps(codec, 0x28)) == AC_WID_VOL_KNB)
6102 spec->init = stac92hd71bxx_core_init;
6103
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05006104 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
6105 snd_hda_sequence_write_cache(codec, unmute_init);
6106
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006107 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04006108 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01006109 spec->aloopback_shift = 0;
6110
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006111 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006112 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006113 spec->mux_nids = stac92hd71bxx_mux_nids;
6114 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02006115 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006116 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006117
6118 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
6119 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02006120 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006121 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006122
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05306123 snd_printdd("Found board config: %d\n", spec->board_config);
6124
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006125 switch (spec->board_config) {
6126 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006127 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01006128 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04006129 stac92xx_auto_set_pinctl(codec, 0x0e,
6130 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05006131 /* fallthru */
6132 case STAC_DELL_M4_2:
6133 spec->num_dmics = 0;
6134 spec->num_smuxes = 0;
6135 spec->num_dmuxes = 0;
6136 break;
6137 case STAC_DELL_M4_1:
6138 case STAC_DELL_M4_3:
6139 spec->num_dmics = 1;
6140 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01006141 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006142 break;
James Gardiner514bf542009-05-03 04:00:44 -04006143 case STAC_HP_DV4_1222NR:
6144 spec->num_dmics = 1;
6145 /* I don't know if it needs 1 or 2 smuxes - will wait for
6146 * bug reports to fix if needed
6147 */
6148 spec->num_smuxes = 1;
6149 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04006150 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02006151 case STAC_HP_DV4:
6152 spec->gpio_led = 0x01;
6153 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01006154 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01006155 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01006156 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02006157 /* HP dv6 gives the headphone pin as a line-out. Thus we
6158 * need to set hp_detect flag here to force to enable HP
6159 * detection.
6160 */
6161 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01006162 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01006163 case STAC_HP_HDX:
6164 spec->num_dmics = 1;
6165 spec->num_dmuxes = 1;
6166 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02006167 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006168 break;
6169 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01006170
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01006171 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01006172 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
6173 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
6174 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
6175 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
6176 /* It was changed in the BIOS to just satisfy MS DTM.
6177 * Lets turn it back into slaved HP
6178 */
6179 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
6180 | (AC_JACK_HP_OUT <<
6181 AC_DEFCFG_DEVICE_SHIFT);
6182 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
6183 | AC_DEFCFG_SEQUENCE)))
6184 | 0x1f;
6185 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
6186 }
6187 }
6188
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06006189 if (find_mute_led_cfg(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01006190 snd_printd("mute LED gpio %d polarity %d\n",
6191 spec->gpio_led,
6192 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01006193
Takashi Iwai86d190e2009-05-26 15:18:58 +02006194 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01006195 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05006196 spec->gpio_mask |= spec->gpio_led;
6197 spec->gpio_dir |= spec->gpio_led;
6198 spec->gpio_data |= spec->gpio_led;
6199 } else {
6200 codec->patch_ops.set_power_state =
6201 stac92xx_set_power_state;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05006202 }
Takashi Iwai86d190e2009-05-26 15:18:58 +02006203 }
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006204
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01006205 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006206
Charles Chin9009b0e2011-11-03 10:27:27 +01006207 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006208 if (!err) {
6209 if (spec->board_config < 0) {
6210 printk(KERN_WARNING "hda_codec: No auto-config is "
6211 "available, default to model=ref\n");
6212 spec->board_config = STAC_92HD71BXX_REF;
6213 goto again;
6214 }
6215 err = -EINVAL;
6216 }
6217
6218 if (err < 0) {
6219 stac92xx_free(codec);
6220 return err;
6221 }
6222
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006223 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02006224 if (spec->board_config == STAC_HP_DV4 ||
6225 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006226 unsigned int cap;
6227 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
6228 cap &= AC_GPIO_IO_COUNT;
6229 if (cap >= 6)
6230 stac_add_hp_bass_switch(codec);
6231 }
6232
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006233 codec->proc_widget_hook = stac92hd7x_proc_hook;
6234
Matthew Ranostaye035b842007-11-06 11:53:55 +01006235 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006236}
Matthew Ranostaye035b842007-11-06 11:53:55 +01006237
Matt2f2f4252005-04-13 14:45:30 +02006238static int patch_stac922x(struct hda_codec *codec)
6239{
6240 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02006241 int err;
Matt2f2f4252005-04-13 14:45:30 +02006242
Takashi Iwai361dab32012-05-09 14:35:27 +02006243 err = alloc_stac_spec(codec, ARRAY_SIZE(stac922x_pin_nids),
6244 stac922x_pin_nids);
6245 if (err < 0)
6246 return err;
Matt2f2f4252005-04-13 14:45:30 +02006247
Takashi Iwai361dab32012-05-09 14:35:27 +02006248 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006249 spec->linear_tone_beep = 1;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006250 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
6251 stac922x_models,
6252 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08006253 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006254 spec->gpio_mask = spec->gpio_dir = 0x03;
6255 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006256 /* Intel Macs have all same PCI SSID, so we need to check
6257 * codec SSID to distinguish the exact models
6258 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006259 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006260 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006261
6262 case 0x106b0800:
6263 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02006264 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006265 case 0x106b0600:
6266 case 0x106b0700:
6267 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006268 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006269 case 0x106b0e00:
6270 case 0x106b0f00:
6271 case 0x106b1600:
6272 case 0x106b1700:
6273 case 0x106b0200:
6274 case 0x106b1e00:
6275 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006276 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006277 case 0x106b1a00:
6278 case 0x00000100:
6279 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02006280 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006281 case 0x106b0a00:
6282 case 0x106b2200:
6283 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02006284 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08006285 default:
6286 spec->board_config = STAC_INTEL_MAC_V3;
6287 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006288 }
6289 }
6290
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006291 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006292 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006293 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6294 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006295 else
6296 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006297 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02006298
Matt2f2f4252005-04-13 14:45:30 +02006299 spec->adc_nids = stac922x_adc_nids;
6300 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006301 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006302 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006303 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006304 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02006305
6306 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006307
6308 spec->num_caps = STAC922X_NUM_CAPS;
6309 spec->capvols = stac922x_capvols;
6310 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02006311
6312 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02006313
Charles Chin9009b0e2011-11-03 10:27:27 +01006314 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006315 if (!err) {
6316 if (spec->board_config < 0) {
6317 printk(KERN_WARNING "hda_codec: No auto-config is "
6318 "available, default to model=ref\n");
6319 spec->board_config = STAC_D945_REF;
6320 goto again;
6321 }
6322 err = -EINVAL;
6323 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006324 if (err < 0) {
6325 stac92xx_free(codec);
6326 return err;
6327 }
6328
6329 codec->patch_ops = stac92xx_patch_ops;
6330
Takashi Iwai807a46362007-05-29 19:01:37 +02006331 /* Fix Mux capture level; max to 2 */
6332 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
6333 (0 << AC_AMPCAP_OFFSET_SHIFT) |
6334 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
6335 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6336 (0 << AC_AMPCAP_MUTE_SHIFT));
6337
Matt Porter3cc08dc2006-01-23 15:27:49 +01006338 return 0;
6339}
6340
6341static int patch_stac927x(struct hda_codec *codec)
6342{
6343 struct sigmatel_spec *spec;
6344 int err;
6345
Takashi Iwai361dab32012-05-09 14:35:27 +02006346 err = alloc_stac_spec(codec, ARRAY_SIZE(stac927x_pin_nids),
6347 stac927x_pin_nids);
6348 if (err < 0)
6349 return err;
Matt Porter3cc08dc2006-01-23 15:27:49 +01006350
Takashi Iwai361dab32012-05-09 14:35:27 +02006351 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006352 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05006353 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006354 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
6355 stac927x_models,
6356 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006357 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006358 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006359 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6360 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006361 else
6362 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006363 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01006364
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006365 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006366 spec->adc_nids = stac927x_adc_nids;
6367 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6368 spec->mux_nids = stac927x_mux_nids;
6369 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006370 spec->smux_nids = stac927x_smux_nids;
6371 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04006372 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01006373 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006374 spec->multiout.dac_nids = spec->dac_nids;
6375
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006376 if (spec->board_config != STAC_D965_REF) {
6377 /* GPIO0 High = Enable EAPD */
6378 spec->eapd_mask = spec->gpio_mask = 0x01;
6379 spec->gpio_dir = spec->gpio_data = 0x01;
6380 }
6381
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006382 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02006383 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006384 case STAC_D965_5ST:
6385 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006386 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02006387 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006388 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006389 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006390 switch (codec->subsystem_id) {
6391 case 0x10280209:
6392 case 0x1028022e:
6393 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006394 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006395 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006396 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01006397 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01006398 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01006399 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006400 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006401 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01006402 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006403 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006404 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006405 if (codec->subsystem_id != 0x1028022f) {
6406 /* GPIO2 High = Enable EAPD */
6407 spec->eapd_mask = spec->gpio_mask = 0x04;
6408 spec->gpio_dir = spec->gpio_data = 0x04;
6409 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006410 spec->dmic_nids = stac927x_dmic_nids;
6411 spec->num_dmics = STAC927X_NUM_DMICS;
6412
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02006413 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006414 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006415 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006416 break;
Takashi Iwai54930532009-10-11 17:38:29 +02006417 case STAC_927X_VOLKNOB:
6418 spec->num_dmics = 0;
6419 spec->init = stac927x_volknob_core_init;
6420 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006421 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006422 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006423 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006424 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006425 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006426
Takashi Iwai6479c632009-07-28 18:20:25 +02006427 spec->num_caps = STAC927X_NUM_CAPS;
6428 spec->capvols = stac927x_capvols;
6429 spec->capsws = stac927x_capsws;
6430
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006431 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006432 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006433 spec->aloopback_mask = 0x40;
6434 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05006435 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006436
Charles Chin9009b0e2011-11-03 10:27:27 +01006437 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006438 if (!err) {
6439 if (spec->board_config < 0) {
6440 printk(KERN_WARNING "hda_codec: No auto-config is "
6441 "available, default to model=ref\n");
6442 spec->board_config = STAC_D965_REF;
6443 goto again;
6444 }
6445 err = -EINVAL;
6446 }
Mattc7d4b2f2005-06-27 14:59:41 +02006447 if (err < 0) {
6448 stac92xx_free(codec);
6449 return err;
6450 }
Matt2f2f4252005-04-13 14:45:30 +02006451
6452 codec->patch_ops = stac92xx_patch_ops;
6453
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006454 codec->proc_widget_hook = stac927x_proc_hook;
6455
Takashi Iwai52987652008-01-16 16:09:47 +01006456 /*
6457 * !!FIXME!!
6458 * The STAC927x seem to require fairly long delays for certain
6459 * command sequences. With too short delays (even if the answer
6460 * is set to RIRB properly), it results in the silence output
6461 * on some hardwares like Dell.
6462 *
6463 * The below flag enables the longer delay (see get_response
6464 * in hda_intel.c).
6465 */
6466 codec->bus->needs_damn_long_delay = 1;
6467
Takashi Iwaie28d8322008-12-17 13:48:29 +01006468 /* no jack detecion for ref-no-jd model */
6469 if (spec->board_config == STAC_D965_REF_NO_JD)
6470 spec->hp_detect = 0;
6471
Matt2f2f4252005-04-13 14:45:30 +02006472 return 0;
6473}
6474
Matt Porterf3302a52006-07-31 12:49:34 +02006475static int patch_stac9205(struct hda_codec *codec)
6476{
6477 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006478 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006479
Takashi Iwai361dab32012-05-09 14:35:27 +02006480 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9205_pin_nids),
6481 stac9205_pin_nids);
6482 if (err < 0)
6483 return err;
Matt Porterf3302a52006-07-31 12:49:34 +02006484
Takashi Iwai361dab32012-05-09 14:35:27 +02006485 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006486 spec->linear_tone_beep = 1;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006487 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6488 stac9205_models,
6489 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006490 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006491 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006492 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6493 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006494 else
6495 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006496 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006497
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006498 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006499 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006500 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006501 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006502 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006503 spec->smux_nids = stac9205_smux_nids;
6504 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006505 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006506 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006507 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006508 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006509 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006510
6511 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006512 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006513
Takashi Iwai6479c632009-07-28 18:20:25 +02006514 spec->num_caps = STAC9205_NUM_CAPS;
6515 spec->capvols = stac9205_capvols;
6516 spec->capsws = stac9205_capsws;
6517
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006518 spec->aloopback_mask = 0x40;
6519 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006520 /* Turn on/off EAPD per HP plugging */
6521 if (spec->board_config != STAC_9205_EAPD)
6522 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006523 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006524
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006525 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006526 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006527 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006528 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6529 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006530
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006531 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwai3a938972011-10-28 01:16:55 +02006532 err = stac_add_event(codec, codec->afg, STAC_VREF_EVENT, 0x01);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006533 if (err < 0)
6534 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006535 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006536 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
Takashi Iwai3a938972011-10-28 01:16:55 +02006537 snd_hda_jack_detect_enable(codec, codec->afg, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006538
6539 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006540 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006541 spec->gpio_mask = 0x1b;
6542 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006543 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006544 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006545 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006546 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006547 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006548 case STAC_9205_REF:
6549 /* SPDIF-In enabled */
6550 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006551 default:
6552 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006553 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006554 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006555 break;
6556 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006557
Charles Chin9009b0e2011-11-03 10:27:27 +01006558 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006559 if (!err) {
6560 if (spec->board_config < 0) {
6561 printk(KERN_WARNING "hda_codec: No auto-config is "
6562 "available, default to model=ref\n");
6563 spec->board_config = STAC_9205_REF;
6564 goto again;
6565 }
6566 err = -EINVAL;
6567 }
Matt Porterf3302a52006-07-31 12:49:34 +02006568 if (err < 0) {
6569 stac92xx_free(codec);
6570 return err;
6571 }
6572
6573 codec->patch_ops = stac92xx_patch_ops;
6574
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006575 codec->proc_widget_hook = stac9205_proc_hook;
6576
Matt Porterf3302a52006-07-31 12:49:34 +02006577 return 0;
6578}
6579
Matt2f2f4252005-04-13 14:45:30 +02006580/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006581 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006582 */
6583
Takashi Iwai2b635362011-05-02 12:33:43 +02006584static const struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006585 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006586 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6587 {}
6588};
6589
Takashi Iwai2b635362011-05-02 12:33:43 +02006590static const hda_nid_t stac9872_pin_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006591 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6592 0x11, 0x13, 0x14,
6593};
6594
Takashi Iwai2b635362011-05-02 12:33:43 +02006595static const hda_nid_t stac9872_adc_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006596 0x8 /*,0x6*/
6597};
6598
Takashi Iwai2b635362011-05-02 12:33:43 +02006599static const hda_nid_t stac9872_mux_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006600 0x15
6601};
6602
Takashi Iwai2b635362011-05-02 12:33:43 +02006603static const unsigned long stac9872_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +02006604 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6605};
6606#define stac9872_capsws stac9872_capvols
6607
Takashi Iwaifc268c12013-01-14 14:29:36 +01006608static const struct hda_pintbl stac9872_vaio_pin_configs[] = {
6609 { 0x0a, 0x03211020 },
6610 { 0x0b, 0x411111f0 },
6611 { 0x0c, 0x411111f0 },
6612 { 0x0d, 0x03a15030 },
6613 { 0x0e, 0x411111f0 },
6614 { 0x0f, 0x90170110 },
6615 { 0x11, 0x411111f0 },
6616 { 0x13, 0x411111f0 },
6617 { 0x14, 0x90a7013e },
6618 {}
Takashi Iwai307282c2009-03-12 18:17:58 +01006619};
6620
Takashi Iwaifc268c12013-01-14 14:29:36 +01006621static const struct hda_model_fixup stac9872_models[] = {
6622 { .id = STAC_9872_VAIO, .name = "vaio" },
6623 {}
Takashi Iwai307282c2009-03-12 18:17:58 +01006624};
6625
Takashi Iwaifc268c12013-01-14 14:29:36 +01006626static const struct hda_fixup stac9872_fixups[] = {
6627 [STAC_9872_VAIO] = {
6628 .type = HDA_FIXUP_PINS,
6629 .v.pins = stac9872_vaio_pin_configs,
6630 },
Takashi Iwai307282c2009-03-12 18:17:58 +01006631};
6632
Takashi Iwaifc268c12013-01-14 14:29:36 +01006633static const struct snd_pci_quirk stac9872_fixup_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006634 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6635 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006636 {} /* terminator */
6637};
6638
Guillaume Munch6d859062006-08-22 17:15:47 +02006639static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006640{
6641 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006642 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006643
Takashi Iwai361dab32012-05-09 14:35:27 +02006644 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9872_pin_nids),
6645 stac9872_pin_nids);
6646 if (err < 0)
6647 return err;
6648
6649 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006650 spec->linear_tone_beep = 1;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006651
Takashi Iwaifc268c12013-01-14 14:29:36 +01006652 snd_hda_pick_fixup(codec, stac9872_models, stac9872_fixup_tbl,
6653 stac9872_fixups);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006654
Takashi Iwai1e137f92009-01-21 07:41:22 +01006655 spec->multiout.dac_nids = spec->dac_nids;
6656 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6657 spec->adc_nids = stac9872_adc_nids;
6658 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6659 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02006660 spec->num_caps = 1;
6661 spec->capvols = stac9872_capvols;
6662 spec->capsws = stac9872_capsws;
Takashi Iwaifc268c12013-01-14 14:29:36 +01006663 snd_hda_add_verbs(codec, stac9872_core_init);
6664
6665 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006666
Charles Chin9009b0e2011-11-03 10:27:27 +01006667 err = stac92xx_parse_auto_config(codec);
Takashi Iwai1e137f92009-01-21 07:41:22 +01006668 if (err < 0) {
6669 stac92xx_free(codec);
6670 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006671 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006672 spec->input_mux = &spec->private_imux;
6673 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaifc268c12013-01-14 14:29:36 +01006674
6675 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6676
Takashi Iwaidb064e52006-03-16 16:04:58 +01006677 return 0;
6678}
6679
6680
6681/*
Matt2f2f4252005-04-13 14:45:30 +02006682 * patch entries
6683 */
Takashi Iwai2b635362011-05-02 12:33:43 +02006684static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006685 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6686 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6687 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6688 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6689 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6690 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6691 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006692 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6693 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6694 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6695 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6696 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6697 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006698 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6699 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6700 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6701 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6702 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6703 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6704 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6705 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6706 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6707 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006708 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6709 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6710 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6711 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6712 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6713 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006714 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6715 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006716 /* The following does not take into account .id=0x83847661 when subsys =
6717 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6718 * currently not fully supported.
6719 */
6720 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6721 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6722 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006723 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006724 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6725 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6726 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6727 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6728 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6729 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6730 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6731 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006732 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006733 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006734 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006735 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006736 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006737 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6738 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006739 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6740 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6741 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6742 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006743 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006744 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6745 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006746 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006747 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6748 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6749 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6750 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6751 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6752 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6753 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6754 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006755 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6756 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6757 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6758 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6759 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6760 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6761 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6762 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6763 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6764 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6765 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6766 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6767 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6768 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6769 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
David Henningsson46724c22011-09-20 09:02:22 +02006770 { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006771 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06006772 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6773 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006774 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Charles Chinad5d8752011-11-02 07:56:58 +01006775 { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6776 { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6777 { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6778 { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6779 { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6780 { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6781 { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6782 { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6783 { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6784 { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6785 { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6786 { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006787 {} /* terminator */
6788};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006789
6790MODULE_ALIAS("snd-hda-codec-id:8384*");
6791MODULE_ALIAS("snd-hda-codec-id:111d*");
6792
6793MODULE_LICENSE("GPL");
6794MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6795
6796static struct hda_codec_preset_list sigmatel_list = {
6797 .preset = snd_hda_preset_sigmatel,
6798 .owner = THIS_MODULE,
6799};
6800
6801static int __init patch_sigmatel_init(void)
6802{
6803 return snd_hda_add_codec_preset(&sigmatel_list);
6804}
6805
6806static void __exit patch_sigmatel_exit(void)
6807{
6808 snd_hda_delete_codec_preset(&sigmatel_list);
6809}
6810
6811module_init(patch_sigmatel_init)
6812module_exit(patch_sigmatel_exit)