blob: f66c7d19a7df28bf0f3936d05e692ed3c39bd917 [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 {
73 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020074 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020075 STAC_9205_DELL_M43,
76 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010077 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010078 STAC_9205_MODELS
79};
80
81enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010082 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010083 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010084 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080085 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010086 STAC_DELL_M6_AMIC,
87 STAC_DELL_M6_DMIC,
88 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050089 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020090 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010091 STAC_92HD73XX_MODELS
92};
93
94enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010095 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020096 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050097 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050098 STAC_DELL_S14,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +010099 STAC_DELL_VOSTRO_3500,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -0500100 STAC_92HD83XXX_HP_cNB11_INTQUAD,
Steven Eastland48315592010-08-06 15:07:35 -0600101 STAC_HP_DV7_4000,
Vitaliy Kulikov5556e142012-02-27 16:47:37 -0600102 STAC_HP_ZEPHYR,
Takashi Iwaia3e19972012-07-26 08:17:20 +0200103 STAC_92HD83XXX_HP_LED,
Takashi Iwaiff8a1e22012-07-31 10:16:59 +0200104 STAC_92HD83XXX_HP_INV_LED,
Takashi Iwai62cbde12012-09-14 11:58:54 +0200105 STAC_92HD83XXX_HP_MIC_LED,
David Henningsson8d032a82012-10-09 12:48:40 +0200106 STAC_92HD83XXX_HEADSET_JACK,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200107 STAC_92HD83XXX_MODELS
108};
109
110enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100111 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100112 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100113 STAC_DELL_M4_1,
114 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500115 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400116 STAC_HP_M4,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +0200117 STAC_HP_DV4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100118 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100119 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400120 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100121 STAC_92HD71BXX_MODELS
122};
123
124enum {
Tobin Davis8e21c342007-01-08 11:04:17 +0100125 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200126 STAC_M1,
127 STAC_M1_2,
128 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100129 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200130 STAC_M3,
131 STAC_M5,
132 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100133 STAC_925x_MODELS
134};
135
136enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100137 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100138 STAC_D945_REF,
139 STAC_D945GTP3,
140 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200141 STAC_INTEL_MAC_V1,
142 STAC_INTEL_MAC_V2,
143 STAC_INTEL_MAC_V3,
144 STAC_INTEL_MAC_V4,
145 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800146 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
147 * is given, one of the above models will be
148 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200149 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100150 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100151 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100152 STAC_MACBOOK_PRO_V1,
153 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200154 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200155 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300156 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200157 STAC_922X_DELL_D81,
158 STAC_922X_DELL_D82,
159 STAC_922X_DELL_M81,
160 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100161 STAC_922X_MODELS
162};
163
164enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100165 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100166 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100167 STAC_D965_REF,
168 STAC_D965_3ST,
169 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200170 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200171 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100172 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200173 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100174 STAC_927X_MODELS
175};
Matt Porter403d1942005-11-29 15:00:51 +0100176
Takashi Iwai307282c2009-03-12 18:17:58 +0100177enum {
Takashi Iwai307282c2009-03-12 18:17:58 +0100178 STAC_9872_VAIO,
179 STAC_9872_MODELS
180};
181
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200182struct sigmatel_mic_route {
183 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200184 signed char mux_idx;
185 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200186};
187
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600188#define MAX_PINS_NUM 16
189#define MAX_ADCS_NUM 4
190#define MAX_DMICS_NUM 4
191
Matt2f2f4252005-04-13 14:45:30 +0200192struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100193 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200194 unsigned int num_mixers;
195
Matt Porter403d1942005-11-29 15:00:51 +0100196 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500197 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200198 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100199 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100200 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400201 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100202 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200203 unsigned int auto_mic:1;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +0100204 unsigned int linear_tone_beep:1;
David Henningsson8d032a82012-10-09 12:48:40 +0200205 unsigned int headset_jack:1; /* 4-pin headset jack (hp + mono mic) */
Mattc7d4b2f2005-06-27 14:59:41 +0200206
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100207 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200208 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100209 unsigned int gpio_mask;
210 unsigned int gpio_dir;
211 unsigned int gpio_data;
212 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200213 unsigned int gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +0100214 unsigned int gpio_led_polarity;
Takashi Iwaif1a73742011-12-04 13:44:06 +0100215 unsigned int vref_mute_led_nid; /* pin NID for mute-LED vref control */
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500216 unsigned int vref_led;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100217
Takashi Iwai62cbde12012-09-14 11:58:54 +0200218 unsigned int mic_mute_led_gpio; /* capture mute LED GPIO */
219 bool mic_mute_led_on; /* current mic mute state */
220
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200221 /* stream */
222 unsigned int stream_delay;
223
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100224 /* analog loopback */
Takashi Iwai2b635362011-05-02 12:33:43 +0200225 const struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100226 unsigned char aloopback_mask;
227 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200228
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100229 /* power management */
Takashi Iwaic8822462012-05-15 09:11:36 +0200230 unsigned int power_map_bits;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100231 unsigned int num_pwrs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200232 const hda_nid_t *pwr_nids;
233 const hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100234
Matt2f2f4252005-04-13 14:45:30 +0200235 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100236 struct hda_input_mux *mono_mux;
237 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200238 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100239 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100240 hda_nid_t hp_dacs[5];
241 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200242
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100243 int volume_offset;
244
Matt2f2f4252005-04-13 14:45:30 +0200245 /* capture */
Takashi Iwai2b635362011-05-02 12:33:43 +0200246 const hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200247 unsigned int num_adcs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200248 const hda_nid_t *mux_nids;
Mattdabbed62005-06-14 10:19:34 +0200249 unsigned int num_muxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200250 const hda_nid_t *dmic_nids;
Matt Porter8b657272006-10-26 17:12:59 +0200251 unsigned int num_dmics;
Takashi Iwai2b635362011-05-02 12:33:43 +0200252 const hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100253 unsigned int num_dmuxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200254 const hda_nid_t *smux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200255 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200256 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200257
Takashi Iwai2b635362011-05-02 12:33:43 +0200258 const unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
259 const unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
Takashi Iwai6479c632009-07-28 18:20:25 +0200260 unsigned int num_caps; /* number of capture volume/switch elements */
261
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200262 struct sigmatel_mic_route ext_mic;
263 struct sigmatel_mic_route int_mic;
Charles Chin99077902010-09-17 10:22:32 +0200264 struct sigmatel_mic_route dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200265
Takashi Iwaiea734962011-01-17 11:29:34 +0100266 const char * const *spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200267
Mattdabbed62005-06-14 10:19:34 +0200268 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100269 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200270 hda_nid_t anabeep_nid;
271 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200272
Matt2f2f4252005-04-13 14:45:30 +0200273 /* pin widgets */
Takashi Iwai2b635362011-05-02 12:33:43 +0200274 const hda_nid_t *pin_nids;
Matt2f2f4252005-04-13 14:45:30 +0200275 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200276
277 /* codec specific stuff */
Takashi Iwai2b635362011-05-02 12:33:43 +0200278 const struct hda_verb *init;
279 const struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200280
281 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200282 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100283 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200284 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100285 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200286 struct hda_input_mux *sinput_mux;
287 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400288 unsigned int cur_amux;
289 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200290 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200291
Matt Porter403d1942005-11-29 15:00:51 +0100292 /* i/o switches */
293 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200294 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100295 hda_nid_t line_switch; /* shared line-in for input and output */
296 hda_nid_t mic_switch; /* shared mic-in for input and output */
297 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200298 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200299
Mattc7d4b2f2005-06-27 14:59:41 +0200300 struct hda_pcm pcm_rec[2]; /* PCM information */
301
302 /* dynamic controls and input_mux */
303 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200304 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200305 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200306 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200307 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100308 struct hda_input_mux private_mono_mux;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600309
310 /* auto spec */
311 unsigned auto_pin_cnt;
312 hda_nid_t auto_pin_nids[MAX_PINS_NUM];
313 unsigned auto_adc_cnt;
314 hda_nid_t auto_adc_nids[MAX_ADCS_NUM];
315 hda_nid_t auto_mux_nids[MAX_ADCS_NUM];
316 hda_nid_t auto_dmux_nids[MAX_ADCS_NUM];
317 unsigned long auto_capvols[MAX_ADCS_NUM];
318 unsigned auto_dmic_cnt;
319 hda_nid_t auto_dmic_nids[MAX_DMICS_NUM];
Takashi Iwai2faa3bf2012-03-12 12:30:22 +0100320
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100321 struct hda_vmaster_mute_hook vmaster_mute;
Matt2f2f4252005-04-13 14:45:30 +0200322};
323
Takashi Iwaic8822462012-05-15 09:11:36 +0200324#define AC_VERB_IDT_SET_POWER_MAP 0x7ec
325#define AC_VERB_IDT_GET_POWER_MAP 0xfec
326
Takashi Iwai2b635362011-05-02 12:33:43 +0200327static const hda_nid_t stac9200_adc_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200328 0x03,
329};
330
Takashi Iwai2b635362011-05-02 12:33:43 +0200331static const hda_nid_t stac9200_mux_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200332 0x0c,
333};
334
Takashi Iwai2b635362011-05-02 12:33:43 +0200335static const hda_nid_t stac9200_dac_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200336 0x02,
337};
338
Takashi Iwai2b635362011-05-02 12:33:43 +0200339static const hda_nid_t stac92hd73xx_pwr_nids[8] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100340 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
341 0x0f, 0x10, 0x11
342};
343
Takashi Iwai2b635362011-05-02 12:33:43 +0200344static const hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400345 0x26, 0,
346};
347
Takashi Iwai2b635362011-05-02 12:33:43 +0200348static const hda_nid_t stac92hd73xx_adc_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100349 0x1a, 0x1b
350};
351
352#define STAC92HD73XX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200353static const hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100354 0x13, 0x14, 0
355};
356
357#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100358
Takashi Iwai2b635362011-05-02 12:33:43 +0200359static const hda_nid_t stac92hd73xx_mux_nids[2] = {
Takashi Iwaie2aec172009-09-02 01:00:05 +0200360 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100361};
362
Takashi Iwai2b635362011-05-02 12:33:43 +0200363static const hda_nid_t stac92hd73xx_dmux_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100364 0x20, 0x21,
365};
366
Takashi Iwai2b635362011-05-02 12:33:43 +0200367static const hda_nid_t stac92hd73xx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200368 0x22, 0x23,
369};
370
Takashi Iwai6479c632009-07-28 18:20:25 +0200371#define STAC92HD73XX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200372static const unsigned long stac92hd73xx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200373 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
374 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
375};
376#define stac92hd73xx_capsws stac92hd73xx_capvols
377
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200378#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200379
Charles Chinafef2cf2011-11-11 08:05:28 +0100380static const hda_nid_t stac92hd83xxx_pwr_nids[7] = {
381 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
382 0x0f, 0x10
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200383};
384
Takashi Iwai2b635362011-05-02 12:33:43 +0200385static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400386 0x1e, 0,
387};
388
Takashi Iwai2b635362011-05-02 12:33:43 +0200389static const hda_nid_t stac92hd83xxx_dmic_nids[] = {
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600390 0x11, 0x20,
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +0200391};
392
Takashi Iwai2b635362011-05-02 12:33:43 +0200393static const hda_nid_t stac92hd71bxx_pwr_nids[3] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100394 0x0a, 0x0d, 0x0f
395};
396
Takashi Iwai2b635362011-05-02 12:33:43 +0200397static const hda_nid_t stac92hd71bxx_adc_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100398 0x12, 0x13,
399};
400
Takashi Iwai2b635362011-05-02 12:33:43 +0200401static const hda_nid_t stac92hd71bxx_mux_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100402 0x1a, 0x1b
403};
404
Takashi Iwai2b635362011-05-02 12:33:43 +0200405static const hda_nid_t stac92hd71bxx_dmux_nids[2] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400406 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100407};
408
Takashi Iwai2b635362011-05-02 12:33:43 +0200409static const hda_nid_t stac92hd71bxx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200410 0x24, 0x25,
411};
412
Matthew Ranostaye035b842007-11-06 11:53:55 +0100413#define STAC92HD71BXX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200414static const hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100415 0x18, 0x19, 0
416};
417
Takashi Iwai2b635362011-05-02 12:33:43 +0200418static const hda_nid_t stac92hd71bxx_dmic_5port_nids[STAC92HD71BXX_NUM_DMICS] = {
419 0x18, 0
420};
421
422static const hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400423 0x22, 0
424};
425
Takashi Iwai6479c632009-07-28 18:20:25 +0200426#define STAC92HD71BXX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200427static const unsigned long stac92hd71bxx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200428 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
429 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
430};
431#define stac92hd71bxx_capsws stac92hd71bxx_capvols
432
Takashi Iwai2b635362011-05-02 12:33:43 +0200433static const hda_nid_t stac925x_adc_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100434 0x03,
435};
436
Takashi Iwai2b635362011-05-02 12:33:43 +0200437static const hda_nid_t stac925x_mux_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100438 0x0f,
439};
440
Takashi Iwai2b635362011-05-02 12:33:43 +0200441static const hda_nid_t stac925x_dac_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100442 0x02,
443};
444
Takashi Iwaif6e98522007-10-16 14:27:04 +0200445#define STAC925X_NUM_DMICS 1
Takashi Iwai2b635362011-05-02 12:33:43 +0200446static const hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200447 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200448};
449
Takashi Iwai2b635362011-05-02 12:33:43 +0200450static const hda_nid_t stac925x_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100451 0x14,
452};
453
Takashi Iwai2b635362011-05-02 12:33:43 +0200454static const unsigned long stac925x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200455 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
456};
Takashi Iwai2b635362011-05-02 12:33:43 +0200457static const unsigned long stac925x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200458 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
459};
460
Takashi Iwai2b635362011-05-02 12:33:43 +0200461static const hda_nid_t stac922x_adc_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200462 0x06, 0x07,
463};
464
Takashi Iwai2b635362011-05-02 12:33:43 +0200465static const hda_nid_t stac922x_mux_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200466 0x12, 0x13,
467};
468
Takashi Iwai6479c632009-07-28 18:20:25 +0200469#define STAC922X_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200470static const unsigned long stac922x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200471 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
472 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
473};
474#define stac922x_capsws stac922x_capvols
475
Takashi Iwai2b635362011-05-02 12:33:43 +0200476static const hda_nid_t stac927x_slave_dig_outs[2] = {
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500477 0x1f, 0,
478};
479
Takashi Iwai2b635362011-05-02 12:33:43 +0200480static const hda_nid_t stac927x_adc_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100481 0x07, 0x08, 0x09
482};
483
Takashi Iwai2b635362011-05-02 12:33:43 +0200484static const hda_nid_t stac927x_mux_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100485 0x15, 0x16, 0x17
486};
487
Takashi Iwai2b635362011-05-02 12:33:43 +0200488static const hda_nid_t stac927x_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200489 0x21,
490};
491
Takashi Iwai2b635362011-05-02 12:33:43 +0200492static const hda_nid_t stac927x_dac_nids[6] = {
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100493 0x02, 0x03, 0x04, 0x05, 0x06, 0
494};
495
Takashi Iwai2b635362011-05-02 12:33:43 +0200496static const hda_nid_t stac927x_dmux_nids[1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100497 0x1b,
498};
499
Matthew Ranostay7f168592007-10-18 17:38:17 +0200500#define STAC927X_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200501static const hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
Matthew Ranostay7f168592007-10-18 17:38:17 +0200502 0x13, 0x14, 0
503};
504
Takashi Iwai6479c632009-07-28 18:20:25 +0200505#define STAC927X_NUM_CAPS 3
Takashi Iwai2b635362011-05-02 12:33:43 +0200506static const unsigned long stac927x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200507 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
508 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
509 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
510};
Takashi Iwai2b635362011-05-02 12:33:43 +0200511static const unsigned long stac927x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200512 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
513 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
514 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
515};
516
Takashi Iwaiea734962011-01-17 11:29:34 +0100517static const char * const stac927x_spdif_labels[5] = {
Matthew Ranostay65973632008-09-16 10:39:37 -0400518 "Digital Playback", "ADAT", "Analog Mux 1",
519 "Analog Mux 2", "Analog Mux 3"
520};
521
Takashi Iwai2b635362011-05-02 12:33:43 +0200522static const hda_nid_t stac9205_adc_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200523 0x12, 0x13
524};
525
Takashi Iwai2b635362011-05-02 12:33:43 +0200526static const hda_nid_t stac9205_mux_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200527 0x19, 0x1a
528};
529
Takashi Iwai2b635362011-05-02 12:33:43 +0200530static const hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100531 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100532};
533
Takashi Iwai2b635362011-05-02 12:33:43 +0200534static const hda_nid_t stac9205_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200535 0x21,
536};
537
Takashi Iwaif6e98522007-10-16 14:27:04 +0200538#define STAC9205_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200539static const hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200540 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200541};
542
Takashi Iwai6479c632009-07-28 18:20:25 +0200543#define STAC9205_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200544static const unsigned long stac9205_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200545 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
546 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
547};
Takashi Iwai2b635362011-05-02 12:33:43 +0200548static const unsigned long stac9205_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200549 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
550 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
551};
552
Takashi Iwai2b635362011-05-02 12:33:43 +0200553static const hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200554 0x08, 0x09, 0x0d, 0x0e,
555 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200556};
557
Takashi Iwai2b635362011-05-02 12:33:43 +0200558static const hda_nid_t stac925x_pin_nids[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100559 0x07, 0x08, 0x0a, 0x0b,
560 0x0c, 0x0d, 0x10, 0x11,
561};
562
Takashi Iwai2b635362011-05-02 12:33:43 +0200563static const hda_nid_t stac922x_pin_nids[10] = {
Matt2f2f4252005-04-13 14:45:30 +0200564 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
565 0x0f, 0x10, 0x11, 0x15, 0x1b,
566};
567
Takashi Iwai2b635362011-05-02 12:33:43 +0200568static const hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100569 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
570 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200571 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100572};
573
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500574#define STAC92HD71BXX_NUM_PINS 13
Takashi Iwai2b635362011-05-02 12:33:43 +0200575static const hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500576 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
577 0x00, 0x14, 0x18, 0x19, 0x1e,
578 0x1f, 0x20, 0x27
579};
Takashi Iwai2b635362011-05-02 12:33:43 +0200580static const hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100581 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
582 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500583 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100584};
585
Takashi Iwai2b635362011-05-02 12:33:43 +0200586static const hda_nid_t stac927x_pin_nids[14] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100587 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
588 0x0f, 0x10, 0x11, 0x12, 0x13,
589 0x14, 0x21, 0x22, 0x23,
590};
591
Takashi Iwai2b635362011-05-02 12:33:43 +0200592static const hda_nid_t stac9205_pin_nids[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200593 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
594 0x0f, 0x14, 0x16, 0x17, 0x18,
595 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200596};
597
Matt Porter8b657272006-10-26 17:12:59 +0200598static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
599 struct snd_ctl_elem_info *uinfo)
600{
601 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
602 struct sigmatel_spec *spec = codec->spec;
603 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
604}
605
606static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
607 struct snd_ctl_elem_value *ucontrol)
608{
609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
610 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100611 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200612
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100613 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200614 return 0;
615}
616
617static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
618 struct snd_ctl_elem_value *ucontrol)
619{
620 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
621 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100622 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200623
624 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100625 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200626}
627
Matthew Ranostayd9737752008-09-07 12:03:41 +0200628static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
629 struct snd_ctl_elem_info *uinfo)
630{
631 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
632 struct sigmatel_spec *spec = codec->spec;
633 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
634}
635
636static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
637 struct snd_ctl_elem_value *ucontrol)
638{
639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
640 struct sigmatel_spec *spec = codec->spec;
641 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
642
643 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
644 return 0;
645}
646
647static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_value *ucontrol)
649{
650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400652 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200653 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400654 int err, val;
655 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200656
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400657 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200658 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400659 if (err < 0)
660 return err;
661
662 if (spec->spdif_mute) {
663 if (smux_idx == 0)
664 nid = spec->multiout.dig_out_nid;
665 else
666 nid = codec->slave_dig_outs[smux_idx - 1];
667 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100668 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400669 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100670 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400671 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100672 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
673 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400674 }
675 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200676}
677
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500678static int stac_vrefout_set(struct hda_codec *codec,
679 hda_nid_t nid, unsigned int new_vref)
680{
681 int error, pinctl;
682
683 snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
684 pinctl = snd_hda_codec_read(codec, nid, 0,
685 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
686
687 if (pinctl < 0)
688 return pinctl;
689
690 pinctl &= 0xff;
691 pinctl &= ~AC_PINCTL_VREFEN;
692 pinctl |= (new_vref & AC_PINCTL_VREFEN);
693
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200694 error = snd_hda_set_pin_ctl_cache(codec, nid, pinctl);
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500695 if (error < 0)
696 return error;
697
698 return 1;
699}
700
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200701static unsigned int stac92xx_vref_set(struct hda_codec *codec,
702 hda_nid_t nid, unsigned int new_vref)
703{
Takashi Iwaib8621512009-06-22 08:00:10 +0200704 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200705 unsigned int pincfg;
706 pincfg = snd_hda_codec_read(codec, nid, 0,
707 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
708
709 pincfg &= 0xff;
710 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
711 pincfg |= new_vref;
712
713 if (new_vref == AC_PINCTL_VREF_HIZ)
714 pincfg |= AC_PINCTL_OUT_EN;
715 else
716 pincfg |= AC_PINCTL_IN_EN;
717
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200718 error = snd_hda_set_pin_ctl_cache(codec, nid, pincfg);
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200719 if (error < 0)
720 return error;
721 else
722 return 1;
723}
724
725static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
726{
727 unsigned int vref;
728 vref = snd_hda_codec_read(codec, nid, 0,
729 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
730 vref &= AC_PINCTL_VREFEN;
731 return vref;
732}
733
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100734static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200735{
736 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
737 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200738 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200739}
740
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100741static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200742{
743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
744 struct sigmatel_spec *spec = codec->spec;
745 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
746
747 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
748 return 0;
749}
750
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100751static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200752{
753 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
754 struct sigmatel_spec *spec = codec->spec;
755 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200756 const struct hda_input_mux *imux = spec->input_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600757 unsigned int idx, prev_idx, didx;
Matt2f2f4252005-04-13 14:45:30 +0200758
Takashi Iwai5207e102009-07-30 13:09:08 +0200759 idx = ucontrol->value.enumerated.item[0];
760 if (idx >= imux->num_items)
761 idx = imux->num_items - 1;
762 prev_idx = spec->cur_mux[adc_idx];
763 if (prev_idx == idx)
764 return 0;
765 if (idx < spec->num_analog_muxes) {
766 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
767 AC_VERB_SET_CONNECT_SEL,
768 imux->items[idx].index);
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600769 if (prev_idx >= spec->num_analog_muxes &&
770 spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
Takashi Iwai5207e102009-07-30 13:09:08 +0200771 imux = spec->dinput_mux;
772 /* 0 = analog */
773 snd_hda_codec_write_cache(codec,
774 spec->dmux_nids[adc_idx], 0,
775 AC_VERB_SET_CONNECT_SEL,
776 imux->items[0].index);
777 }
778 } else {
779 imux = spec->dinput_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600780 /* first dimux item is hardcoded to select analog imux,
781 * so lets skip it
782 */
783 didx = idx - spec->num_analog_muxes + 1;
Takashi Iwai5207e102009-07-30 13:09:08 +0200784 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
785 AC_VERB_SET_CONNECT_SEL,
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600786 imux->items[didx].index);
Takashi Iwai5207e102009-07-30 13:09:08 +0200787 }
788 spec->cur_mux[adc_idx] = idx;
789 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200790}
791
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100792static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
793 struct snd_ctl_elem_info *uinfo)
794{
795 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
796 struct sigmatel_spec *spec = codec->spec;
797 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
798}
799
800static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
801 struct snd_ctl_elem_value *ucontrol)
802{
803 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
804 struct sigmatel_spec *spec = codec->spec;
805
806 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
807 return 0;
808}
809
810static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
811 struct snd_ctl_elem_value *ucontrol)
812{
813 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
814 struct sigmatel_spec *spec = codec->spec;
815
816 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
817 spec->mono_nid, &spec->cur_mmux);
818}
819
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200820#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
821
822static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
823 struct snd_ctl_elem_value *ucontrol)
824{
825 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100826 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200827 struct sigmatel_spec *spec = codec->spec;
828
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100829 ucontrol->value.integer.value[0] = !!(spec->aloopback &
830 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200831 return 0;
832}
833
834static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
835 struct snd_ctl_elem_value *ucontrol)
836{
837 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
838 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100839 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200840 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100841 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200842
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100843 idx_val = spec->aloopback_mask << idx;
844 if (ucontrol->value.integer.value[0])
845 val = spec->aloopback | idx_val;
846 else
847 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100848 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200849 return 0;
850
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100851 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200852
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100853 /* Only return the bits defined by the shift value of the
854 * first two bytes of the mask
855 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200856 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100857 kcontrol->private_value & 0xFFFF, 0x0);
858 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200859
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100860 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200861 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100862 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200863 } else {
864 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100865 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200866 }
867
868 snd_hda_codec_write_cache(codec, codec->afg, 0,
869 kcontrol->private_value >> 16, dac_mode);
870
871 return 1;
872}
873
Takashi Iwai2b635362011-05-02 12:33:43 +0200874static const struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200875 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200876 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200877 {}
878};
879
Takashi Iwai2b635362011-05-02 12:33:43 +0200880static const struct hda_verb stac9200_eapd_init[] = {
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200881 /* set dac0mux for dac converter */
882 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
883 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
884 {}
885};
886
Takashi Iwai2b635362011-05-02 12:33:43 +0200887static const struct hda_verb dell_eq_core_init[] = {
Matthew Ranostayd654a662008-03-14 08:46:51 +0100888 /* set master volume to max value without distortion
889 * and direct control */
890 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100891 {}
892};
893
Takashi Iwai2b635362011-05-02 12:33:43 +0200894static const struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100895 /* set master volume and direct control */
896 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100897 {}
898};
899
Takashi Iwai2b635362011-05-02 12:33:43 +0200900static const struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200901 /* power state controls amps */
902 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200903 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200904};
905
Vitaliy Kulikov5556e142012-02-27 16:47:37 -0600906static const struct hda_verb stac92hd83xxx_hp_zephyr_init[] = {
907 { 0x22, 0x785, 0x43 },
908 { 0x22, 0x782, 0xe0 },
909 { 0x22, 0x795, 0x00 },
910 {}
911};
912
Takashi Iwai2b635362011-05-02 12:33:43 +0200913static const struct hda_verb stac92hd71bxx_core_init[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100914 /* set master volume and direct control */
915 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200916 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100917};
918
Takashi Iwai2b635362011-05-02 12:33:43 +0200919static const struct hda_verb stac92hd71bxx_unmute_core_init[] = {
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500920 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
921 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100922 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
923 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100924 {}
925};
926
Takashi Iwai2b635362011-05-02 12:33:43 +0200927static const struct hda_verb stac925x_core_init[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100928 /* set dac0mux for dac converter */
929 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100930 /* mute the master volume */
931 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100932 {}
933};
934
Takashi Iwai2b635362011-05-02 12:33:43 +0200935static const struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200936 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200937 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200938 {}
939};
940
Takashi Iwai2b635362011-05-02 12:33:43 +0200941static const struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200942 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200943 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200944 /* unmute node 0x1b */
945 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
946 /* select node 0x03 as DAC */
947 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
948 {}
949};
950
Takashi Iwai2b635362011-05-02 12:33:43 +0200951static const struct hda_verb dell_3st_core_init[] = {
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200952 /* don't set delta bit */
953 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
954 /* unmute node 0x1b */
955 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
956 /* select node 0x03 as DAC */
957 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
958 {}
959};
960
Takashi Iwai2b635362011-05-02 12:33:43 +0200961static const struct hda_verb stac927x_core_init[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100962 /* set master volume and direct control */
963 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200964 /* enable analog pc beep path */
965 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100966 {}
967};
968
Takashi Iwai2b635362011-05-02 12:33:43 +0200969static const struct hda_verb stac927x_volknob_core_init[] = {
Takashi Iwai54930532009-10-11 17:38:29 +0200970 /* don't set delta bit */
971 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
972 /* enable analog pc beep path */
973 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
974 {}
975};
976
Takashi Iwai2b635362011-05-02 12:33:43 +0200977static const struct hda_verb stac9205_core_init[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200978 /* set master volume and direct control */
979 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200980 /* enable analog pc beep path */
981 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200982 {}
983};
984
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100985#define STAC_MONO_MUX \
986 { \
987 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
988 .name = "Mono Mux", \
989 .count = 1, \
990 .info = stac92xx_mono_mux_enum_info, \
991 .get = stac92xx_mono_mux_enum_get, \
992 .put = stac92xx_mono_mux_enum_put, \
993 }
994
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100995#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200996 { \
997 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
998 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100999 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +02001000 .info = stac92xx_aloopback_info, \
1001 .get = stac92xx_aloopback_get, \
1002 .put = stac92xx_aloopback_put, \
1003 .private_value = verb_read | (verb_write << 16), \
1004 }
1005
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02001006#define DC_BIAS(xname, idx, nid) \
1007 { \
1008 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1009 .name = xname, \
1010 .index = idx, \
1011 .info = stac92xx_dc_bias_info, \
1012 .get = stac92xx_dc_bias_get, \
1013 .put = stac92xx_dc_bias_put, \
1014 .private_value = nid, \
1015 }
1016
Takashi Iwai2b635362011-05-02 12:33:43 +02001017static const struct snd_kcontrol_new stac9200_mixer[] = {
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001018 HDA_CODEC_VOLUME_MIN_MUTE("PCM Playback Volume", 0xb, 0, HDA_OUTPUT),
1019 HDA_CODEC_MUTE("PCM Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001020 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1021 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001022 { } /* end */
1023};
1024
Takashi Iwai2b635362011-05-02 12:33:43 +02001025static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001026 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1027 {}
1028};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001029
Takashi Iwai2b635362011-05-02 12:33:43 +02001030static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001031 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1032 {}
1033};
1034
Takashi Iwai2b635362011-05-02 12:33:43 +02001035static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001036 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1037 {}
1038};
1039
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001040
Takashi Iwai2b635362011-05-02 12:33:43 +02001041static const struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001042 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1043};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001044
Takashi Iwai2b635362011-05-02 12:33:43 +02001045static const struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001046 HDA_CODEC_VOLUME_MIN_MUTE("PCM Playback Volume", 0xe, 0, HDA_OUTPUT),
1047 HDA_CODEC_MUTE("PCM Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001048 { } /* end */
1049};
1050
Takashi Iwai2b635362011-05-02 12:33:43 +02001051static const struct snd_kcontrol_new stac9205_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001052 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1053 {}
1054};
1055
Takashi Iwai2b635362011-05-02 12:33:43 +02001056static const struct snd_kcontrol_new stac927x_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001057 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1058 {}
1059};
1060
Takashi Iwai1697055e2007-12-18 18:05:52 +01001061static struct snd_kcontrol_new stac_dmux_mixer = {
1062 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1063 .name = "Digital Input Source",
1064 /* count set later */
1065 .info = stac92xx_dmux_enum_info,
1066 .get = stac92xx_dmux_enum_get,
1067 .put = stac92xx_dmux_enum_put,
1068};
1069
Matthew Ranostayd9737752008-09-07 12:03:41 +02001070static struct snd_kcontrol_new stac_smux_mixer = {
1071 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001072 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001073 /* count set later */
1074 .info = stac92xx_smux_enum_info,
1075 .get = stac92xx_smux_enum_get,
1076 .put = stac92xx_smux_enum_put,
1077};
1078
Takashi Iwai9322ca52012-02-03 14:28:01 +01001079static const char * const slave_pfxs[] = {
1080 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01001081 "Headphone", "Speaker", "Bass Speaker", "IEC958", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001082 NULL
1083};
1084
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001085static void stac92xx_update_led_status(struct hda_codec *codec, int enabled);
1086
1087static void stac92xx_vmaster_hook(void *private_data, int val)
1088{
1089 stac92xx_update_led_status(private_data, val);
1090}
1091
Takashi Iwai603c4012008-07-30 15:01:44 +02001092static void stac92xx_free_kctls(struct hda_codec *codec);
1093
Matt2f2f4252005-04-13 14:45:30 +02001094static int stac92xx_build_controls(struct hda_codec *codec)
1095{
1096 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001097 unsigned int vmaster_tlv[4];
Matt2f2f4252005-04-13 14:45:30 +02001098 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001099 int i;
Matt2f2f4252005-04-13 14:45:30 +02001100
Takashi Iwai6479c632009-07-28 18:20:25 +02001101 if (spec->mixer) {
1102 err = snd_hda_add_new_ctls(codec, spec->mixer);
1103 if (err < 0)
1104 return err;
1105 }
Mattc7d4b2f2005-06-27 14:59:41 +02001106
1107 for (i = 0; i < spec->num_mixers; i++) {
1108 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1109 if (err < 0)
1110 return err;
1111 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001112 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1113 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001114 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001115 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001116 snd_ctl_new1(&stac_dmux_mixer, codec));
1117 if (err < 0)
1118 return err;
1119 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001120 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001121 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1122 struct hda_input_mux *smux = &spec->private_smux;
1123 /* check for mute support on SPDIF out */
1124 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001125 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001126 spec->spdif_mute = 1;
1127 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001128 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001129 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001130 snd_ctl_new1(&stac_smux_mixer, codec));
1131 if (err < 0)
1132 return err;
1133 }
Mattc7d4b2f2005-06-27 14:59:41 +02001134
Mattdabbed62005-06-14 10:19:34 +02001135 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001136 err = snd_hda_create_dig_out_ctls(codec,
1137 spec->multiout.dig_out_nid,
1138 spec->multiout.dig_out_nid,
1139 spec->autocfg.dig_out_type[0]);
Mattdabbed62005-06-14 10:19:34 +02001140 if (err < 0)
1141 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001142 err = snd_hda_create_spdif_share_sw(codec,
1143 &spec->multiout);
1144 if (err < 0)
1145 return err;
1146 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001147 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001148 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001149 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1150 if (err < 0)
1151 return err;
1152 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001153
1154 /* if we have no master control, let's create it */
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001155 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1156 HDA_OUTPUT, vmaster_tlv);
1157 /* correct volume offset */
1158 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1159 /* minimum value is actually mute */
1160 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
1161 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1162 vmaster_tlv, slave_pfxs,
1163 "Playback Volume");
1164 if (err < 0)
1165 return err;
1166
1167 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1168 NULL, slave_pfxs,
1169 "Playback Switch", true,
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001170 &spec->vmaster_mute.sw_kctl);
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001171 if (err < 0)
1172 return err;
1173
1174 if (spec->gpio_led) {
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001175 spec->vmaster_mute.hook = stac92xx_vmaster_hook;
Takashi Iwaif29735cb2012-03-13 07:55:10 +01001176 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001177 if (err < 0)
1178 return err;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001179 }
1180
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001181 if (spec->aloopback_ctl &&
1182 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1183 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1184 if (err < 0)
1185 return err;
1186 }
1187
Takashi Iwai603c4012008-07-30 15:01:44 +02001188 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001189
Takashi Iwai01a61e12011-10-28 00:03:22 +02001190 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1191 if (err < 0)
1192 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001193
Mattdabbed62005-06-14 10:19:34 +02001194 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001195}
1196
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001197static const struct hda_pintbl ref9200_pin_configs[] = {
1198 { 0x08, 0x01c47010 },
1199 { 0x09, 0x01447010 },
1200 { 0x0d, 0x0221401f },
1201 { 0x0e, 0x01114010 },
1202 { 0x0f, 0x02a19020 },
1203 { 0x10, 0x01a19021 },
1204 { 0x11, 0x90100140 },
1205 { 0x12, 0x01813122 },
1206 {}
Matt2f2f4252005-04-13 14:45:30 +02001207};
1208
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001209static const struct hda_pintbl gateway9200_m4_pin_configs[] = {
1210 { 0x08, 0x400000fe },
1211 { 0x09, 0x404500f4 },
1212 { 0x0d, 0x400100f0 },
1213 { 0x0e, 0x90110010 },
1214 { 0x0f, 0x400100f1 },
1215 { 0x10, 0x02a1902e },
1216 { 0x11, 0x500000f2 },
1217 { 0x12, 0x500000f3 },
1218 {}
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001219};
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001220
1221static const struct hda_pintbl gateway9200_m4_2_pin_configs[] = {
1222 { 0x08, 0x400000fe },
1223 { 0x09, 0x404500f4 },
1224 { 0x0d, 0x400100f0 },
1225 { 0x0e, 0x90110010 },
1226 { 0x0f, 0x400100f1 },
1227 { 0x10, 0x02a1902e },
1228 { 0x11, 0x500000f2 },
1229 { 0x12, 0x500000f3 },
1230 {}
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001231};
1232
1233/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001234 STAC 9200 pin configs for
1235 102801A8
1236 102801DE
1237 102801E8
1238*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001239static const struct hda_pintbl dell9200_d21_pin_configs[] = {
1240 { 0x08, 0x400001f0 },
1241 { 0x09, 0x400001f1 },
1242 { 0x0d, 0x02214030 },
1243 { 0x0e, 0x01014010 },
1244 { 0x0f, 0x02a19020 },
1245 { 0x10, 0x01a19021 },
1246 { 0x11, 0x90100140 },
1247 { 0x12, 0x01813122 },
1248 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001249};
1250
1251/*
1252 STAC 9200 pin configs for
1253 102801C0
1254 102801C1
1255*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001256static const struct hda_pintbl dell9200_d22_pin_configs[] = {
1257 { 0x08, 0x400001f0 },
1258 { 0x09, 0x400001f1 },
1259 { 0x0d, 0x0221401f },
1260 { 0x0e, 0x01014010 },
1261 { 0x0f, 0x01813020 },
1262 { 0x10, 0x02a19021 },
1263 { 0x11, 0x90100140 },
1264 { 0x12, 0x400001f2 },
1265 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001266};
1267
1268/*
1269 STAC 9200 pin configs for
1270 102801C4 (Dell Dimension E310)
1271 102801C5
1272 102801C7
1273 102801D9
1274 102801DA
1275 102801E3
1276*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001277static const struct hda_pintbl dell9200_d23_pin_configs[] = {
1278 { 0x08, 0x400001f0 },
1279 { 0x09, 0x400001f1 },
1280 { 0x0d, 0x0221401f },
1281 { 0x0e, 0x01014010 },
1282 { 0x0f, 0x01813020 },
1283 { 0x10, 0x01a19021 },
1284 { 0x11, 0x90100140 },
1285 { 0x12, 0x400001f2 },
1286 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001287};
1288
1289
1290/*
1291 STAC 9200-32 pin configs for
1292 102801B5 (Dell Inspiron 630m)
1293 102801D8 (Dell Inspiron 640m)
1294*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001295static const struct hda_pintbl dell9200_m21_pin_configs[] = {
1296 { 0x08, 0x40c003fa },
1297 { 0x09, 0x03441340 },
1298 { 0x0d, 0x0321121f },
1299 { 0x0e, 0x90170310 },
1300 { 0x0f, 0x408003fb },
1301 { 0x10, 0x03a11020 },
1302 { 0x11, 0x401003fc },
1303 { 0x12, 0x403003fd },
1304 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001305};
1306
1307/*
1308 STAC 9200-32 pin configs for
1309 102801C2 (Dell Latitude D620)
1310 102801C8
1311 102801CC (Dell Latitude D820)
1312 102801D4
1313 102801D6
1314*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001315static const struct hda_pintbl dell9200_m22_pin_configs[] = {
1316 { 0x08, 0x40c003fa },
1317 { 0x09, 0x0144131f },
1318 { 0x0d, 0x0321121f },
1319 { 0x0e, 0x90170310 },
1320 { 0x0f, 0x90a70321 },
1321 { 0x10, 0x03a11020 },
1322 { 0x11, 0x401003fb },
1323 { 0x12, 0x40f000fc },
1324 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001325};
1326
1327/*
1328 STAC 9200-32 pin configs for
1329 102801CE (Dell XPS M1710)
1330 102801CF (Dell Precision M90)
1331*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001332static const struct hda_pintbl dell9200_m23_pin_configs[] = {
1333 { 0x08, 0x40c003fa },
1334 { 0x09, 0x01441340 },
1335 { 0x0d, 0x0421421f },
1336 { 0x0e, 0x90170310 },
1337 { 0x0f, 0x408003fb },
1338 { 0x10, 0x04a1102e },
1339 { 0x11, 0x90170311 },
1340 { 0x12, 0x403003fc },
1341 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001342};
1343
1344/*
1345 STAC 9200-32 pin configs for
1346 102801C9
1347 102801CA
1348 102801CB (Dell Latitude 120L)
1349 102801D3
1350*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001351static const struct hda_pintbl dell9200_m24_pin_configs[] = {
1352 { 0x08, 0x40c003fa },
1353 { 0x09, 0x404003fb },
1354 { 0x0d, 0x0321121f },
1355 { 0x0e, 0x90170310 },
1356 { 0x0f, 0x408003fc },
1357 { 0x10, 0x03a11020 },
1358 { 0x11, 0x401003fd },
1359 { 0x12, 0x403003fe },
1360 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001361};
1362
1363/*
1364 STAC 9200-32 pin configs for
1365 102801BD (Dell Inspiron E1505n)
1366 102801EE
1367 102801EF
1368*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001369static const struct hda_pintbl dell9200_m25_pin_configs[] = {
1370 { 0x08, 0x40c003fa },
1371 { 0x09, 0x01441340 },
1372 { 0x0d, 0x0421121f },
1373 { 0x0e, 0x90170310 },
1374 { 0x0f, 0x408003fb },
1375 { 0x10, 0x04a11020 },
1376 { 0x11, 0x401003fc },
1377 { 0x12, 0x403003fd },
1378 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001379};
1380
1381/*
1382 STAC 9200-32 pin configs for
1383 102801F5 (Dell Inspiron 1501)
1384 102801F6
1385*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001386static const struct hda_pintbl dell9200_m26_pin_configs[] = {
1387 { 0x08, 0x40c003fa },
1388 { 0x09, 0x404003fb },
1389 { 0x0d, 0x0421121f },
1390 { 0x0e, 0x90170310 },
1391 { 0x0f, 0x408003fc },
1392 { 0x10, 0x04a11020 },
1393 { 0x11, 0x401003fd },
1394 { 0x12, 0x403003fe },
1395 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001396};
1397
1398/*
1399 STAC 9200-32
1400 102801CD (Dell Inspiron E1705/9400)
1401*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001402static const struct hda_pintbl dell9200_m27_pin_configs[] = {
1403 { 0x08, 0x40c003fa },
1404 { 0x09, 0x01441340 },
1405 { 0x0d, 0x0421121f },
1406 { 0x0e, 0x90170310 },
1407 { 0x0f, 0x90170310 },
1408 { 0x10, 0x04a11020 },
1409 { 0x11, 0x90170310 },
1410 { 0x12, 0x40f003fc },
1411 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001412};
1413
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001414static const struct hda_pintbl oqo9200_pin_configs[] = {
1415 { 0x08, 0x40c000f0 },
1416 { 0x09, 0x404000f1 },
1417 { 0x0d, 0x0221121f },
1418 { 0x0e, 0x02211210 },
1419 { 0x0f, 0x90170111 },
1420 { 0x10, 0x90a70120 },
1421 { 0x11, 0x400000f2 },
1422 { 0x12, 0x400000f3 },
1423 {}
Tobin Davisbf277782008-02-03 20:31:47 +01001424};
1425
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001426
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001427static void stac9200_fixup_panasonic(struct hda_codec *codec,
1428 const struct hda_fixup *fix, int action)
1429{
1430 struct sigmatel_spec *spec = codec->spec;
1431
1432 switch (action) {
1433 case HDA_FIXUP_ACT_PRE_PROBE:
1434 spec->gpio_mask = spec->gpio_dir = 0x09;
1435 spec->gpio_data = 0x00;
1436 break;
1437 case HDA_FIXUP_ACT_PROBE:
1438 /* CF-74 has no headphone detection, and the driver should *NOT*
1439 * do detection and HP/speaker toggle because the hardware does it.
1440 */
1441 spec->hp_detect = 0;
1442 break;
1443 }
1444}
1445
1446
1447static const struct hda_fixup stac9200_fixups[] = {
1448 [STAC_REF] = {
1449 .type = HDA_FIXUP_PINS,
1450 .v.pins = ref9200_pin_configs,
1451 },
1452 [STAC_9200_OQO] = {
1453 .type = HDA_FIXUP_PINS,
1454 .v.pins = oqo9200_pin_configs,
1455 .chained = true,
1456 .chain_id = STAC_9200_EAPD_INIT,
1457 },
1458 [STAC_9200_DELL_D21] = {
1459 .type = HDA_FIXUP_PINS,
1460 .v.pins = dell9200_d21_pin_configs,
1461 },
1462 [STAC_9200_DELL_D22] = {
1463 .type = HDA_FIXUP_PINS,
1464 .v.pins = dell9200_d22_pin_configs,
1465 },
1466 [STAC_9200_DELL_D23] = {
1467 .type = HDA_FIXUP_PINS,
1468 .v.pins = dell9200_d23_pin_configs,
1469 },
1470 [STAC_9200_DELL_M21] = {
1471 .type = HDA_FIXUP_PINS,
1472 .v.pins = dell9200_m21_pin_configs,
1473 },
1474 [STAC_9200_DELL_M22] = {
1475 .type = HDA_FIXUP_PINS,
1476 .v.pins = dell9200_m22_pin_configs,
1477 },
1478 [STAC_9200_DELL_M23] = {
1479 .type = HDA_FIXUP_PINS,
1480 .v.pins = dell9200_m23_pin_configs,
1481 },
1482 [STAC_9200_DELL_M24] = {
1483 .type = HDA_FIXUP_PINS,
1484 .v.pins = dell9200_m24_pin_configs,
1485 },
1486 [STAC_9200_DELL_M25] = {
1487 .type = HDA_FIXUP_PINS,
1488 .v.pins = dell9200_m25_pin_configs,
1489 },
1490 [STAC_9200_DELL_M26] = {
1491 .type = HDA_FIXUP_PINS,
1492 .v.pins = dell9200_m26_pin_configs,
1493 },
1494 [STAC_9200_DELL_M27] = {
1495 .type = HDA_FIXUP_PINS,
1496 .v.pins = dell9200_m27_pin_configs,
1497 },
1498 [STAC_9200_M4] = {
1499 .type = HDA_FIXUP_PINS,
1500 .v.pins = gateway9200_m4_pin_configs,
1501 .chained = true,
1502 .chain_id = STAC_9200_EAPD_INIT,
1503 },
1504 [STAC_9200_M4_2] = {
1505 .type = HDA_FIXUP_PINS,
1506 .v.pins = gateway9200_m4_2_pin_configs,
1507 .chained = true,
1508 .chain_id = STAC_9200_EAPD_INIT,
1509 },
1510 [STAC_9200_PANASONIC] = {
1511 .type = HDA_FIXUP_FUNC,
1512 .v.func = stac9200_fixup_panasonic,
1513 },
1514 [STAC_9200_EAPD_INIT] = {
1515 .type = HDA_FIXUP_VERBS,
1516 .v.verbs = (const struct hda_verb[]) {
1517 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1518 {}
1519 },
1520 },
Matt Porter403d1942005-11-29 15:00:51 +01001521};
1522
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001523static const struct hda_model_fixup stac9200_models[] = {
1524 { .id = STAC_REF, .name = "ref" },
1525 { .id = STAC_9200_OQO, .name = "oqo" },
1526 { .id = STAC_9200_DELL_D21, .name = "dell-d21" },
1527 { .id = STAC_9200_DELL_D22, .name = "dell-d22" },
1528 { .id = STAC_9200_DELL_D23, .name = "dell-d23" },
1529 { .id = STAC_9200_DELL_M21, .name = "dell-m21" },
1530 { .id = STAC_9200_DELL_M22, .name = "dell-m22" },
1531 { .id = STAC_9200_DELL_M23, .name = "dell-m23" },
1532 { .id = STAC_9200_DELL_M24, .name = "dell-m24" },
1533 { .id = STAC_9200_DELL_M25, .name = "dell-m25" },
1534 { .id = STAC_9200_DELL_M26, .name = "dell-m26" },
1535 { .id = STAC_9200_DELL_M27, .name = "dell-m27" },
1536 { .id = STAC_9200_M4, .name = "gateway-m4" },
1537 { .id = STAC_9200_M4_2, .name = "gateway-m4-2" },
1538 { .id = STAC_9200_PANASONIC, .name = "panasonic" },
1539 {}
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001540};
1541
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001542static const struct snd_pci_quirk stac9200_fixup_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001543 /* SigmaTel reference board */
1544 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1545 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001546 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1547 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001548 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001549 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1550 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001551 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001552 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1553 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1554 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1555 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1556 "unknown Dell", STAC_9200_DELL_D22),
1557 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1558 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001559 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001560 "Dell Latitude D620", STAC_9200_DELL_M22),
1561 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1562 "unknown Dell", STAC_9200_DELL_D23),
1563 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1564 "unknown Dell", STAC_9200_DELL_D23),
1565 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1566 "unknown Dell", STAC_9200_DELL_M22),
1567 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1568 "unknown Dell", STAC_9200_DELL_M24),
1569 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1570 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001571 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001572 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001573 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001574 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001575 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001576 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001577 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001578 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001579 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001580 "Dell Precision M90", STAC_9200_DELL_M23),
1581 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1582 "unknown Dell", STAC_9200_DELL_M22),
1583 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1584 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001585 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001586 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001587 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001588 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1589 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1590 "unknown Dell", STAC_9200_DELL_D23),
1591 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1592 "unknown Dell", STAC_9200_DELL_D23),
1593 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1594 "unknown Dell", STAC_9200_DELL_D21),
1595 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1596 "unknown Dell", STAC_9200_DELL_D23),
1597 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1598 "unknown Dell", STAC_9200_DELL_D21),
1599 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1600 "unknown Dell", STAC_9200_DELL_M25),
1601 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1602 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001603 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001604 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1605 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1606 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001607 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001608 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001609 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001610 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1611 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1612 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001613 /* OQO Mobile */
1614 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001615 {} /* terminator */
1616};
1617
Takashi Iwaid2077d42013-01-14 14:20:16 +01001618static const struct hda_pintbl ref925x_pin_configs[] = {
1619 { 0x07, 0x40c003f0 },
1620 { 0x08, 0x424503f2 },
1621 { 0x0a, 0x01813022 },
1622 { 0x0b, 0x02a19021 },
1623 { 0x0c, 0x90a70320 },
1624 { 0x0d, 0x02214210 },
1625 { 0x10, 0x01019020 },
1626 { 0x11, 0x9033032e },
1627 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001628};
1629
Takashi Iwaid2077d42013-01-14 14:20:16 +01001630static const struct hda_pintbl stac925xM1_pin_configs[] = {
1631 { 0x07, 0x40c003f4 },
1632 { 0x08, 0x424503f2 },
1633 { 0x0a, 0x400000f3 },
1634 { 0x0b, 0x02a19020 },
1635 { 0x0c, 0x40a000f0 },
1636 { 0x0d, 0x90100210 },
1637 { 0x10, 0x400003f1 },
1638 { 0x11, 0x9033032e },
1639 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001640};
1641
Takashi Iwaid2077d42013-01-14 14:20:16 +01001642static const struct hda_pintbl stac925xM1_2_pin_configs[] = {
1643 { 0x07, 0x40c003f4 },
1644 { 0x08, 0x424503f2 },
1645 { 0x0a, 0x400000f3 },
1646 { 0x0b, 0x02a19020 },
1647 { 0x0c, 0x40a000f0 },
1648 { 0x0d, 0x90100210 },
1649 { 0x10, 0x400003f1 },
1650 { 0x11, 0x9033032e },
1651 {}
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001652};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001653
Takashi Iwaid2077d42013-01-14 14:20:16 +01001654static const struct hda_pintbl stac925xM2_pin_configs[] = {
1655 { 0x07, 0x40c003f4 },
1656 { 0x08, 0x424503f2 },
1657 { 0x0a, 0x400000f3 },
1658 { 0x0b, 0x02a19020 },
1659 { 0x0c, 0x40a000f0 },
1660 { 0x0d, 0x90100210 },
1661 { 0x10, 0x400003f1 },
1662 { 0x11, 0x9033032e },
1663 {}
Tobin Davis2c11f952007-05-17 09:36:34 +02001664};
1665
Takashi Iwaid2077d42013-01-14 14:20:16 +01001666static const struct hda_pintbl stac925xM2_2_pin_configs[] = {
1667 { 0x07, 0x40c003f4 },
1668 { 0x08, 0x424503f2 },
1669 { 0x0a, 0x400000f3 },
1670 { 0x0b, 0x02a19020 },
1671 { 0x0c, 0x40a000f0 },
1672 { 0x0d, 0x90100210 },
1673 { 0x10, 0x400003f1 },
1674 { 0x11, 0x9033032e },
1675 {}
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001676};
1677
Takashi Iwaid2077d42013-01-14 14:20:16 +01001678static const struct hda_pintbl stac925xM3_pin_configs[] = {
1679 { 0x07, 0x40c003f4 },
1680 { 0x08, 0x424503f2 },
1681 { 0x0a, 0x400000f3 },
1682 { 0x0b, 0x02a19020 },
1683 { 0x0c, 0x40a000f0 },
1684 { 0x0d, 0x90100210 },
1685 { 0x10, 0x400003f1 },
1686 { 0x11, 0x503303f3 },
1687 {}
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001688};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001689
Takashi Iwaid2077d42013-01-14 14:20:16 +01001690static const struct hda_pintbl stac925xM5_pin_configs[] = {
1691 { 0x07, 0x40c003f4 },
1692 { 0x08, 0x424503f2 },
1693 { 0x0a, 0x400000f3 },
1694 { 0x0b, 0x02a19020 },
1695 { 0x0c, 0x40a000f0 },
1696 { 0x0d, 0x90100210 },
1697 { 0x10, 0x400003f1 },
1698 { 0x11, 0x9033032e },
1699 {}
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001700};
1701
Takashi Iwaid2077d42013-01-14 14:20:16 +01001702static const struct hda_pintbl stac925xM6_pin_configs[] = {
1703 { 0x07, 0x40c003f4 },
1704 { 0x08, 0x424503f2 },
1705 { 0x0a, 0x400000f3 },
1706 { 0x0b, 0x02a19020 },
1707 { 0x0c, 0x40a000f0 },
1708 { 0x0d, 0x90100210 },
1709 { 0x10, 0x400003f1 },
1710 { 0x11, 0x90330320 },
1711 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001712};
1713
Takashi Iwaid2077d42013-01-14 14:20:16 +01001714static const struct hda_fixup stac925x_fixups[] = {
1715 [STAC_REF] = {
1716 .type = HDA_FIXUP_PINS,
1717 .v.pins = ref925x_pin_configs,
1718 },
1719 [STAC_M1] = {
1720 .type = HDA_FIXUP_PINS,
1721 .v.pins = stac925xM1_pin_configs,
1722 },
1723 [STAC_M1_2] = {
1724 .type = HDA_FIXUP_PINS,
1725 .v.pins = stac925xM1_2_pin_configs,
1726 },
1727 [STAC_M2] = {
1728 .type = HDA_FIXUP_PINS,
1729 .v.pins = stac925xM2_pin_configs,
1730 },
1731 [STAC_M2_2] = {
1732 .type = HDA_FIXUP_PINS,
1733 .v.pins = stac925xM2_2_pin_configs,
1734 },
1735 [STAC_M3] = {
1736 .type = HDA_FIXUP_PINS,
1737 .v.pins = stac925xM3_pin_configs,
1738 },
1739 [STAC_M5] = {
1740 .type = HDA_FIXUP_PINS,
1741 .v.pins = stac925xM5_pin_configs,
1742 },
1743 [STAC_M6] = {
1744 .type = HDA_FIXUP_PINS,
1745 .v.pins = stac925xM6_pin_configs,
1746 },
Tobin Davis8e21c342007-01-08 11:04:17 +01001747};
1748
Takashi Iwaid2077d42013-01-14 14:20:16 +01001749static const struct hda_model_fixup stac925x_models[] = {
1750 { .id = STAC_REF, .name = "ref" },
1751 { .id = STAC_M1, .name = "m1" },
1752 { .id = STAC_M1_2, .name = "m1-2" },
1753 { .id = STAC_M2, .name = "m2" },
1754 { .id = STAC_M2_2, .name = "m2-2" },
1755 { .id = STAC_M3, .name = "m3" },
1756 { .id = STAC_M5, .name = "m5" },
1757 { .id = STAC_M6, .name = "m6" },
1758 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001759};
1760
Takashi Iwaid2077d42013-01-14 14:20:16 +01001761static const struct snd_pci_quirk stac925x_fixup_tbl[] = {
1762 /* SigmaTel reference board */
1763 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1764 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1765 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1766
1767 /* Default table for unknown ID */
1768 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1769
1770 /* gateway machines are checked via codec ssid */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001771 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1772 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1773 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1774 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001775 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001776 /* Not sure about the brand name for those */
1777 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1778 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1779 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1780 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001781 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001782};
1783
Takashi Iwai2b635362011-05-02 12:33:43 +02001784static const unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001785 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1786 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1787 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001788 0x01452050,
1789};
1790
Takashi Iwai2b635362011-05-02 12:33:43 +02001791static const unsigned int dell_m6_pin_configs[13] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001792 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001793 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001794 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1795 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001796};
1797
Takashi Iwai2b635362011-05-02 12:33:43 +02001798static const unsigned int alienware_m17x_pin_configs[13] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001799 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1800 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1801 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1802 0x904601b0,
1803};
1804
Takashi Iwai2b635362011-05-02 12:33:43 +02001805static const unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001806 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001807 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001808};
1809
Takashi Iwai2b635362011-05-02 12:33:43 +02001810static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001811 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001812 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1813 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1814 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001815 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001816 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001817 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001818};
1819
Takashi Iwaiea734962011-01-17 11:29:34 +01001820static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001821 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001822 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001823 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001824 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001825 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1826 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1827 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001828 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001829 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001830};
1831
Takashi Iwai2b635362011-05-02 12:33:43 +02001832static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001833 /* SigmaTel reference board */
1834 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001835 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001836 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1837 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001838 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1839 "Intel DG45ID", STAC_92HD73XX_INTEL),
1840 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1841 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001842 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001843 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001844 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001845 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001846 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001847 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001848 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001849 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001850 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001851 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001852 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001853 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001854 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001855 "unknown Dell", STAC_DELL_M6_DMIC),
1856 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1857 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001858 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001859 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001860 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1861 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001862 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1863 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001864 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1865 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001866 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
David Henningssonffe535e2012-01-16 10:52:20 +01001867 "Dell Studio XPS 1645", STAC_DELL_M6_DMIC),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001868 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
David Henningssone033ebf2011-05-16 12:09:29 +02001869 "Dell Studio 1558", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001870 {} /* terminator */
1871};
1872
Takashi Iwai2b635362011-05-02 12:33:43 +02001873static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001874 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1875 "Alienware M17x", STAC_ALIENWARE_M17X),
Daniel T Chen0defe092010-12-01 19:16:07 -05001876 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1877 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwaidbd1b542011-11-19 11:41:30 +01001878 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490,
Albert Poolb9ecc4e2012-01-19 22:08:50 +01001879 "Alienware M17x R3", STAC_DELL_EQ),
Takashi Iwai842ae632009-09-02 07:43:08 +02001880 {} /* terminator */
1881};
1882
Takashi Iwai2b635362011-05-02 12:33:43 +02001883static const unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001884 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1885 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001886 0x01451160, 0x98560170,
1887};
1888
Takashi Iwai2b635362011-05-02 12:33:43 +02001889static const unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001890 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1891 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001892 0x40f000f0, 0x40f000f0,
1893};
1894
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001895static const unsigned int dell_vostro_3500_pin_configs[10] = {
1896 0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
1897 0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
1898 0x400000f4, 0x400000f5,
1899};
1900
Takashi Iwai2b635362011-05-02 12:33:43 +02001901static const unsigned int hp_dv7_4000_pin_configs[10] = {
Steven Eastland48315592010-08-06 15:07:35 -06001902 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1903 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1904 0x40f000f0, 0x40f000f0,
1905};
1906
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06001907static const unsigned int hp_zephyr_pin_configs[10] = {
1908 0x01813050, 0x0421201f, 0x04a1205e, 0x96130310,
1909 0x96130310, 0x0101401f, 0x1111611f, 0xd5a30130,
1910 0, 0,
1911};
1912
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001913static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
1914 0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
1915 0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
1916 0x40f000f0, 0x40f000f0,
1917};
1918
Takashi Iwai2b635362011-05-02 12:33:43 +02001919static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001920 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001921 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001922 [STAC_DELL_S14] = dell_s14_pin_configs,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001923 [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001924 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001925 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06001926 [STAC_HP_ZEPHYR] = hp_zephyr_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001927};
1928
Takashi Iwaiea734962011-01-17 11:29:34 +01001929static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001930 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001931 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001932 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001933 [STAC_DELL_S14] = "dell-s14",
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001934 [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001935 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
Steven Eastland48315592010-08-06 15:07:35 -06001936 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06001937 [STAC_HP_ZEPHYR] = "hp-zephyr",
Takashi Iwaia3e19972012-07-26 08:17:20 +02001938 [STAC_92HD83XXX_HP_LED] = "hp-led",
Takashi Iwaiff8a1e22012-07-31 10:16:59 +02001939 [STAC_92HD83XXX_HP_INV_LED] = "hp-inv-led",
Takashi Iwai62cbde12012-09-14 11:58:54 +02001940 [STAC_92HD83XXX_HP_MIC_LED] = "hp-mic-led",
David Henningsson8d032a82012-10-09 12:48:40 +02001941 [STAC_92HD83XXX_HEADSET_JACK] = "headset-jack",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001942};
1943
Takashi Iwai2b635362011-05-02 12:33:43 +02001944static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001945 /* SigmaTel reference board */
1946 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001947 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001948 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1949 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001950 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1951 "unknown Dell", STAC_DELL_S14),
David Henningsson8d032a82012-10-09 12:48:40 +02001952 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0532,
1953 "Dell Latitude E6230", STAC_92HD83XXX_HEADSET_JACK),
1954 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0533,
1955 "Dell Latitude E6330", STAC_92HD83XXX_HEADSET_JACK),
1956 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0534,
1957 "Dell Latitude E6430", STAC_92HD83XXX_HEADSET_JACK),
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0535,
1959 "Dell Latitude E6530", STAC_92HD83XXX_HEADSET_JACK),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x053c,
1961 "Dell Latitude E5430", STAC_92HD83XXX_HEADSET_JACK),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x053d,
1963 "Dell Latitude E5530", STAC_92HD83XXX_HEADSET_JACK),
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0549,
1965 "Dell Latitude E5430", STAC_92HD83XXX_HEADSET_JACK),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x057d,
1967 "Dell Latitude E6430s", STAC_92HD83XXX_HEADSET_JACK),
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0584,
1969 "Dell Latitude E6430U", STAC_92HD83XXX_HEADSET_JACK),
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001970 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
1971 "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001972 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
1973 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1974 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
1975 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1976 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
1977 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1978 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
Takashi Iwai8ae58652012-12-13 14:33:42 +01001979 "HP Pavilion dv7", STAC_HP_DV7_4000),
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001980 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
1981 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1982 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1983 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Takashi Iwai62cbde12012-09-14 11:58:54 +02001984 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18df,
1985 "HP Folio", STAC_92HD83XXX_HP_MIC_LED),
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001986 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1987 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1988 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
1989 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
1991 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1992 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
1993 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1994 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
1995 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1996 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
1997 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1998 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
1999 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2000 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
2001 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2002 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
2003 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2004 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
2005 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2006 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
2007 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2008 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
2009 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2010 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
2011 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2012 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
2013 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06002014 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3561,
2015 "HP", STAC_HP_ZEPHYR),
Takashi Iwaia3e19972012-07-26 08:17:20 +02002016 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3660,
2017 "HP Mini", STAC_92HD83XXX_HP_LED),
Gustavo Maciel Dias Vieira5afc13a2012-10-26 12:51:53 -02002018 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x144E,
2019 "HP Pavilion dv5", STAC_92HD83XXX_HP_INV_LED),
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06002020 {} /* terminator */
2021};
2022
2023static const struct snd_pci_quirk stac92hd83xxx_codec_id_cfg_tbl[] = {
2024 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3561,
2025 "HP", STAC_HP_ZEPHYR),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02002026 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02002027};
2028
Takashi Iwai2b635362011-05-02 12:33:43 +02002029static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01002030 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04002031 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002032 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
2033 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01002034};
2035
Takashi Iwai2b635362011-05-02 12:33:43 +02002036static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01002037 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01002038 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002039 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
2040 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01002041};
2042
Takashi Iwai2b635362011-05-02 12:33:43 +02002043static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01002044 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
2045 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002046 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
2047 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01002048};
2049
Takashi Iwai2b635362011-05-02 12:33:43 +02002050static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002051 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
2052 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002053 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
2054 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002055};
2056
Takashi Iwai2b635362011-05-02 12:33:43 +02002057static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01002058 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01002059 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
2060 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002061 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04002062 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02002063 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01002064 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01002065 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04002066 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01002067};
2068
Takashi Iwaiea734962011-01-17 11:29:34 +01002069static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002070 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01002071 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01002072 [STAC_DELL_M4_1] = "dell-m4-1",
2073 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002074 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04002075 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02002076 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01002077 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01002078 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04002079 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01002080};
2081
Takashi Iwai2b635362011-05-02 12:33:43 +02002082static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01002083 /* SigmaTel reference board */
2084 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2085 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002086 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2087 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04002088 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
2089 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01002090 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
2091 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01002092 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
2093 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01002094 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02002095 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01002096 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
2097 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01002098 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
2099 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04002100 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01002101 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01002102 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01002103 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02002104 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
2105 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05302106 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
2107 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11002108 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
2109 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02002110 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
2111 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01002112 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
2113 "unknown Dell", STAC_DELL_M4_1),
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
2115 "unknown Dell", STAC_DELL_M4_1),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
2117 "unknown Dell", STAC_DELL_M4_1),
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
2119 "unknown Dell", STAC_DELL_M4_1),
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
2121 "unknown Dell", STAC_DELL_M4_1),
2122 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
2123 "unknown Dell", STAC_DELL_M4_1),
2124 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
2125 "unknown Dell", STAC_DELL_M4_1),
2126 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
2127 "unknown Dell", STAC_DELL_M4_2),
2128 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
2129 "unknown Dell", STAC_DELL_M4_2),
2130 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
2131 "unknown Dell", STAC_DELL_M4_2),
2132 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
2133 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002134 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
2135 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01002136 {} /* terminator */
2137};
2138
Takashi Iwai2b635362011-05-02 12:33:43 +02002139static const unsigned int ref922x_pin_configs[10] = {
Matt Porter403d1942005-11-29 15:00:51 +01002140 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
2141 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02002142 0x40000100, 0x40000100,
2143};
2144
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002145/*
2146 STAC 922X pin configs for
2147 102801A7
2148 102801AB
2149 102801A9
2150 102801D1
2151 102801D2
2152*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002153static const unsigned int dell_922x_d81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002154 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
2155 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
2156 0x01813122, 0x400001f2,
2157};
2158
2159/*
2160 STAC 922X pin configs for
2161 102801AC
2162 102801D0
2163*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002164static const unsigned int dell_922x_d82_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002165 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
2166 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
2167 0x01813122, 0x400001f1,
2168};
2169
2170/*
2171 STAC 922X pin configs for
2172 102801BF
2173*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002174static const unsigned int dell_922x_m81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002175 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
2176 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
2177 0x40C003f1, 0x405003f0,
2178};
2179
2180/*
2181 STAC 9221 A1 pin configs for
2182 102801D7 (Dell XPS M1210)
2183*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002184static const unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01002185 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
2186 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002187 0x508003f3, 0x405003f4,
2188};
2189
Takashi Iwai2b635362011-05-02 12:33:43 +02002190static const unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01002191 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01002192 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2193 0x02a19120, 0x40000100,
2194};
2195
Takashi Iwai2b635362011-05-02 12:33:43 +02002196static const unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01002197 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
2198 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01002199 0x02a19320, 0x40000100,
2200};
2201
Takashi Iwai2b635362011-05-02 12:33:43 +02002202static const unsigned int intel_mac_v1_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002203 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
2204 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002205 0x400000fc, 0x400000fb,
2206};
2207
Takashi Iwai2b635362011-05-02 12:33:43 +02002208static const unsigned int intel_mac_v2_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002209 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2210 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02002211 0x400000fc, 0x400000fb,
2212};
2213
Takashi Iwai2b635362011-05-02 12:33:43 +02002214static const unsigned int intel_mac_v3_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002215 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2216 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
2217 0x400000fc, 0x400000fb,
2218};
2219
Takashi Iwai2b635362011-05-02 12:33:43 +02002220static const unsigned int intel_mac_v4_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002221 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2222 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2223 0x400000fc, 0x400000fb,
2224};
2225
Takashi Iwai2b635362011-05-02 12:33:43 +02002226static const unsigned int intel_mac_v5_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002227 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2228 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2229 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002230};
2231
Takashi Iwai2b635362011-05-02 12:33:43 +02002232static const unsigned int ecs202_pin_configs[10] = {
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002233 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
2234 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
2235 0x9037012e, 0x40e000f2,
2236};
Takashi Iwai76c08822007-06-19 12:17:42 +02002237
Takashi Iwai2b635362011-05-02 12:33:43 +02002238static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002239 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002240 [STAC_D945GTP3] = d945gtp3_pin_configs,
2241 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002242 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
2243 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
2244 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
2245 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
2246 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002247 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002248 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002249 [STAC_MACMINI] = intel_mac_v3_pin_configs,
2250 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2251 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2252 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2253 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2254 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002255 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002256 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2257 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2258 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2259 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01002260};
2261
Takashi Iwaiea734962011-01-17 11:29:34 +01002262static const char * const stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002263 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002264 [STAC_D945_REF] = "ref",
2265 [STAC_D945GTP5] = "5stack",
2266 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002267 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2268 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2269 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2270 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2271 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08002272 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002273 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002274 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002275 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002276 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2277 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02002278 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002279 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002280 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002281 [STAC_922X_DELL_D81] = "dell-d81",
2282 [STAC_922X_DELL_D82] = "dell-d82",
2283 [STAC_922X_DELL_M81] = "dell-m81",
2284 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002285};
2286
Takashi Iwai2b635362011-05-02 12:33:43 +02002287static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002288 /* SigmaTel reference board */
2289 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2290 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002291 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2292 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002293 /* Intel 945G based systems */
2294 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2295 "Intel D945G", STAC_D945GTP3),
2296 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2297 "Intel D945G", STAC_D945GTP3),
2298 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2299 "Intel D945G", STAC_D945GTP3),
2300 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2301 "Intel D945G", STAC_D945GTP3),
2302 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2303 "Intel D945G", STAC_D945GTP3),
2304 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2305 "Intel D945G", STAC_D945GTP3),
2306 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2307 "Intel D945G", STAC_D945GTP3),
2308 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2309 "Intel D945G", STAC_D945GTP3),
2310 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2311 "Intel D945G", STAC_D945GTP3),
2312 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2313 "Intel D945G", STAC_D945GTP3),
2314 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2315 "Intel D945G", STAC_D945GTP3),
2316 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2317 "Intel D945G", STAC_D945GTP3),
2318 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2319 "Intel D945G", STAC_D945GTP3),
2320 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2321 "Intel D945G", STAC_D945GTP3),
2322 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2323 "Intel D945G", STAC_D945GTP3),
2324 /* Intel D945G 5-stack systems */
2325 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2326 "Intel D945G", STAC_D945GTP5),
2327 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2328 "Intel D945G", STAC_D945GTP5),
2329 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2330 "Intel D945G", STAC_D945GTP5),
2331 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2332 "Intel D945G", STAC_D945GTP5),
2333 /* Intel 945P based systems */
2334 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2335 "Intel D945P", STAC_D945GTP3),
2336 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2337 "Intel D945P", STAC_D945GTP3),
2338 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2339 "Intel D945P", STAC_D945GTP3),
2340 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2341 "Intel D945P", STAC_D945GTP3),
2342 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2343 "Intel D945P", STAC_D945GTP3),
2344 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2345 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002346 /* other intel */
2347 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2348 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002349 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002350 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002351 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002352 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002353 /* Dell systems */
2354 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2355 "unknown Dell", STAC_922X_DELL_D81),
2356 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2357 "unknown Dell", STAC_922X_DELL_D81),
2358 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2359 "unknown Dell", STAC_922X_DELL_D81),
2360 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2361 "unknown Dell", STAC_922X_DELL_D82),
2362 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2363 "unknown Dell", STAC_922X_DELL_M81),
2364 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2365 "unknown Dell", STAC_922X_DELL_D82),
2366 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2367 "unknown Dell", STAC_922X_DELL_D81),
2368 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2369 "unknown Dell", STAC_922X_DELL_D81),
2370 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2371 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002372 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002373 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002374 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002375 {} /* terminator */
2376};
2377
Takashi Iwai2b635362011-05-02 12:33:43 +02002378static const unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002379 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2380 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2381 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2382 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002383};
2384
Takashi Iwai2b635362011-05-02 12:33:43 +02002385static const unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002386 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2387 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2388 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2389 0x40000100, 0x40000100
2390};
2391
Takashi Iwai2b635362011-05-02 12:33:43 +02002392static const unsigned int d965_5st_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002393 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2394 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2395 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2396 0x40000100, 0x40000100
2397};
2398
Takashi Iwai2b635362011-05-02 12:33:43 +02002399static const unsigned int d965_5st_no_fp_pin_configs[14] = {
Takashi Iwai679d92e2009-05-24 19:00:08 +02002400 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2401 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2402 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2403 0x40000100, 0x40000100
2404};
2405
Takashi Iwai2b635362011-05-02 12:33:43 +02002406static const unsigned int dell_3st_pin_configs[14] = {
Tobin Davis4ff076e2007-08-07 11:48:12 +02002407 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2408 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002409 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002410 0x40c003fc, 0x40000100
2411};
2412
Takashi Iwai2b635362011-05-02 12:33:43 +02002413static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002414 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002415 [STAC_D965_REF] = ref927x_pin_configs,
2416 [STAC_D965_3ST] = d965_3st_pin_configs,
2417 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002418 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002419 [STAC_DELL_3ST] = dell_3st_pin_configs,
2420 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002421 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002422};
2423
Takashi Iwaiea734962011-01-17 11:29:34 +01002424static const char * const stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002425 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002426 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002427 [STAC_D965_REF] = "ref",
2428 [STAC_D965_3ST] = "3stack",
2429 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002430 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002431 [STAC_DELL_3ST] = "dell-3stack",
2432 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002433 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002434};
2435
Takashi Iwai2b635362011-05-02 12:33:43 +02002436static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002437 /* SigmaTel reference board */
2438 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2439 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002440 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2441 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002442 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002443 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2444 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002445 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002446 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2447 "Intel D965", STAC_D965_3ST),
2448 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2449 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002450 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002451 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002452 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2453 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002454 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002455 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002456 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002457 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002458 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002459 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002460 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2461 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2462 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2463 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002464 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002465 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2466 "Intel D965", STAC_D965_5ST),
2467 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2468 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002469 /* volume-knob fixes */
2470 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002471 {} /* terminator */
2472};
2473
Takashi Iwaife6322c2013-01-14 14:46:51 +01002474static const struct hda_pintbl ref9205_pin_configs[] = {
2475 { 0x0a, 0x40000100 },
2476 { 0x0b, 0x40000100 },
2477 { 0x0c, 0x01016011 },
2478 { 0x0d, 0x01014010 },
2479 { 0x0e, 0x01813122 },
2480 { 0x0f, 0x01a19021 },
2481 { 0x14, 0x01019020 },
2482 { 0x16, 0x40000100 },
2483 { 0x17, 0x90a000f0 },
2484 { 0x18, 0x90a000f0 },
2485 { 0x21, 0x01441030 },
2486 { 0x22, 0x01c41030 },
2487 {}
Matt Porterf3302a52006-07-31 12:49:34 +02002488};
2489
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002490/*
2491 STAC 9205 pin configs for
2492 102801F1
2493 102801F2
2494 102801FC
2495 102801FD
2496 10280204
2497 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002498 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002499 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002500*/
Takashi Iwaife6322c2013-01-14 14:46:51 +01002501static const struct hda_pintbl dell_9205_m42_pin_configs[] = {
2502 { 0x0a, 0x0321101F },
2503 { 0x0b, 0x03A11020 },
2504 { 0x0c, 0x400003FA },
2505 { 0x0d, 0x90170310 },
2506 { 0x0e, 0x400003FB },
2507 { 0x0f, 0x400003FC },
2508 { 0x14, 0x400003FD },
2509 { 0x16, 0x40F000F9 },
2510 { 0x17, 0x90A60330 },
2511 { 0x18, 0x400003FF },
2512 { 0x21, 0x0144131F },
2513 { 0x22, 0x40C003FE },
2514 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002515};
2516
2517/*
2518 STAC 9205 pin configs for
2519 102801F9
2520 102801FA
2521 102801FE
2522 102801FF (Dell Precision M4300)
2523 10280206
2524 10280200
2525 10280201
2526*/
Takashi Iwaife6322c2013-01-14 14:46:51 +01002527static const struct hda_pintbl dell_9205_m43_pin_configs[] = {
2528 { 0x0a, 0x0321101f },
2529 { 0x0b, 0x03a11020 },
2530 { 0x0c, 0x90a70330 },
2531 { 0x0d, 0x90170310 },
2532 { 0x0e, 0x400000fe },
2533 { 0x0f, 0x400000ff },
2534 { 0x14, 0x400000fd },
2535 { 0x16, 0x40f000f9 },
2536 { 0x17, 0x400000fa },
2537 { 0x18, 0x400000fc },
2538 { 0x21, 0x0144131f },
2539 { 0x22, 0x40c003f8 },
2540 /* Enable SPDIF in/out */
2541 { 0x1f, 0x01441030 },
2542 { 0x20, 0x1c410030 },
2543 {}
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002544};
2545
Takashi Iwaife6322c2013-01-14 14:46:51 +01002546static const struct hda_pintbl dell_9205_m44_pin_configs[] = {
2547 { 0x0a, 0x0421101f },
2548 { 0x0b, 0x04a11020 },
2549 { 0x0c, 0x400003fa },
2550 { 0x0d, 0x90170310 },
2551 { 0x0e, 0x400003fb },
2552 { 0x0f, 0x400003fc },
2553 { 0x14, 0x400003fd },
2554 { 0x16, 0x400003f9 },
2555 { 0x17, 0x90a60330 },
2556 { 0x18, 0x400003ff },
2557 { 0x21, 0x01441340 },
2558 { 0x22, 0x40c003fe },
2559 {}
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002560};
2561
Takashi Iwaife6322c2013-01-14 14:46:51 +01002562static void stac9205_fixup_ref(struct hda_codec *codec,
2563 const struct hda_fixup *fix, int action)
2564{
2565 struct sigmatel_spec *spec = codec->spec;
2566
2567 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2568 snd_hda_apply_pincfgs(codec, ref9205_pin_configs);
2569 /* SPDIF-In enabled */
2570 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0;
2571 }
2572}
2573
2574static int stac_add_event(struct hda_codec *codec, hda_nid_t nid,
2575 unsigned char type, int data);
2576
2577static void stac9205_fixup_dell_m43(struct hda_codec *codec,
2578 const struct hda_fixup *fix, int action)
2579{
2580 struct sigmatel_spec *spec = codec->spec;
2581 int err;
2582
2583 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
2584 snd_hda_apply_pincfgs(codec, dell_9205_m43_pin_configs);
2585
2586 /* Enable unsol response for GPIO4/Dock HP connection */
2587 err = stac_add_event(codec, codec->afg, STAC_VREF_EVENT, 0x01);
2588 if (err < 0)
2589 return;
2590 snd_hda_codec_write_cache(codec, codec->afg, 0,
2591 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
2592 snd_hda_jack_detect_enable(codec, codec->afg, 0);
2593
2594 spec->gpio_dir = 0x0b;
2595 spec->eapd_mask = 0x01;
2596 spec->gpio_mask = 0x1b;
2597 spec->gpio_mute = 0x10;
2598 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
2599 * GPIO3 Low = DRM
2600 */
2601 spec->gpio_data = 0x01;
2602 }
2603}
2604
2605static void stac9205_fixup_eapd(struct hda_codec *codec,
2606 const struct hda_fixup *fix, int action)
2607{
2608 struct sigmatel_spec *spec = codec->spec;
2609
2610 if (action == HDA_FIXUP_ACT_PRE_PROBE)
2611 spec->eapd_switch = 0;
2612}
2613
2614static const struct hda_fixup stac9205_fixups[] = {
2615 [STAC_9205_REF] = {
2616 .type = HDA_FIXUP_FUNC,
2617 .v.func = stac9205_fixup_ref,
2618 },
2619 [STAC_9205_DELL_M42] = {
2620 .type = HDA_FIXUP_PINS,
2621 .v.pins = dell_9205_m42_pin_configs,
2622 },
2623 [STAC_9205_DELL_M43] = {
2624 .type = HDA_FIXUP_FUNC,
2625 .v.func = stac9205_fixup_dell_m43,
2626 },
2627 [STAC_9205_DELL_M44] = {
2628 .type = HDA_FIXUP_PINS,
2629 .v.pins = dell_9205_m44_pin_configs,
2630 },
2631 [STAC_9205_EAPD] = {
2632 .type = HDA_FIXUP_FUNC,
2633 .v.func = stac9205_fixup_eapd,
2634 },
2635 {}
Matt Porterf3302a52006-07-31 12:49:34 +02002636};
2637
Takashi Iwaife6322c2013-01-14 14:46:51 +01002638static const struct hda_model_fixup stac9205_models[] = {
2639 { .id = STAC_9205_REF, .name = "ref" },
2640 { .id = STAC_9205_DELL_M42, .name = "dell-m42" },
2641 { .id = STAC_9205_DELL_M43, .name = "dell-m43" },
2642 { .id = STAC_9205_DELL_M44, .name = "dell-m44" },
2643 { .id = STAC_9205_EAPD, .name = "eapd" },
2644 {}
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002645};
2646
Takashi Iwaife6322c2013-01-14 14:46:51 +01002647static const struct snd_pci_quirk stac9205_fixup_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002648 /* SigmaTel reference board */
2649 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2650 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002651 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2652 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002653 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2654 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002655 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002656 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2657 "unknown Dell", STAC_9205_DELL_M42),
2658 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2659 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002660 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002661 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002662 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2663 "Dell Precision", STAC_9205_DELL_M43),
2664 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2665 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002666 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2667 "unknown Dell", STAC_9205_DELL_M42),
2668 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2669 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002670 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2671 "Dell Precision", STAC_9205_DELL_M43),
2672 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002673 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002674 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2675 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002676 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2677 "Dell Precision", STAC_9205_DELL_M43),
2678 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2679 "Dell Precision", STAC_9205_DELL_M43),
2680 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2681 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002682 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2683 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002684 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2685 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002686 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2687 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002688 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002689 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002690 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002691 {} /* terminator */
2692};
2693
Takashi Iwai330ee992009-02-20 14:33:36 +01002694static void stac92xx_set_config_regs(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002695 const unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002696{
2697 int i;
2698 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002699
Takashi Iwai330ee992009-02-20 14:33:36 +01002700 if (!pincfgs)
2701 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002702
Matthew Ranostay87d48362007-07-17 11:52:24 +02002703 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002704 if (spec->pin_nids[i] && pincfgs[i])
2705 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2706 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002707}
2708
Matt2f2f4252005-04-13 14:45:30 +02002709/*
2710 * Analog playback callbacks
2711 */
2712static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2713 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002714 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002715{
2716 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002717 if (spec->stream_delay)
2718 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002719 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2720 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002721}
2722
2723static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2724 struct hda_codec *codec,
2725 unsigned int stream_tag,
2726 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002727 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002728{
2729 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002730 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002731}
2732
2733static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2734 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002735 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002736{
2737 struct sigmatel_spec *spec = codec->spec;
2738 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2739}
2740
2741/*
Mattdabbed62005-06-14 10:19:34 +02002742 * Digital playback callbacks
2743 */
2744static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2745 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002746 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002747{
2748 struct sigmatel_spec *spec = codec->spec;
2749 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2750}
2751
2752static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2753 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002754 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002755{
2756 struct sigmatel_spec *spec = codec->spec;
2757 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2758}
2759
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002760static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2761 struct hda_codec *codec,
2762 unsigned int stream_tag,
2763 unsigned int format,
2764 struct snd_pcm_substream *substream)
2765{
2766 struct sigmatel_spec *spec = codec->spec;
2767 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2768 stream_tag, format, substream);
2769}
2770
Takashi Iwai9411e212009-02-13 11:32:28 +01002771static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2772 struct hda_codec *codec,
2773 struct snd_pcm_substream *substream)
2774{
2775 struct sigmatel_spec *spec = codec->spec;
2776 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2777}
2778
Mattdabbed62005-06-14 10:19:34 +02002779
2780/*
Matt2f2f4252005-04-13 14:45:30 +02002781 * Analog capture callbacks
2782 */
2783static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2784 struct hda_codec *codec,
2785 unsigned int stream_tag,
2786 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002787 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002788{
2789 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002790 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002791
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002792 if (spec->powerdown_adcs) {
2793 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002794 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002795 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2796 }
2797 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002798 return 0;
2799}
2800
2801static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2802 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002803 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002804{
2805 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002806 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002807
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002808 snd_hda_codec_cleanup_stream(codec, nid);
2809 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002810 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002811 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002812 return 0;
2813}
2814
Takashi Iwai2b635362011-05-02 12:33:43 +02002815static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
Mattdabbed62005-06-14 10:19:34 +02002816 .substreams = 1,
2817 .channels_min = 2,
2818 .channels_max = 2,
2819 /* NID is set in stac92xx_build_pcms */
2820 .ops = {
2821 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002822 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002823 .prepare = stac92xx_dig_playback_pcm_prepare,
2824 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002825 },
2826};
2827
Takashi Iwai2b635362011-05-02 12:33:43 +02002828static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
Mattdabbed62005-06-14 10:19:34 +02002829 .substreams = 1,
2830 .channels_min = 2,
2831 .channels_max = 2,
2832 /* NID is set in stac92xx_build_pcms */
2833};
2834
Takashi Iwai2b635362011-05-02 12:33:43 +02002835static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
Matt2f2f4252005-04-13 14:45:30 +02002836 .substreams = 1,
2837 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002838 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002839 .nid = 0x02, /* NID to query formats and rates */
2840 .ops = {
2841 .open = stac92xx_playback_pcm_open,
2842 .prepare = stac92xx_playback_pcm_prepare,
2843 .cleanup = stac92xx_playback_pcm_cleanup
2844 },
2845};
2846
Takashi Iwai2b635362011-05-02 12:33:43 +02002847static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002848 .substreams = 1,
2849 .channels_min = 2,
2850 .channels_max = 2,
2851 .nid = 0x06, /* NID to query formats and rates */
2852 .ops = {
2853 .open = stac92xx_playback_pcm_open,
2854 .prepare = stac92xx_playback_pcm_prepare,
2855 .cleanup = stac92xx_playback_pcm_cleanup
2856 },
2857};
2858
Takashi Iwai2b635362011-05-02 12:33:43 +02002859static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002860 .channels_min = 2,
2861 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002862 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002863 .ops = {
2864 .prepare = stac92xx_capture_pcm_prepare,
2865 .cleanup = stac92xx_capture_pcm_cleanup
2866 },
2867};
2868
2869static int stac92xx_build_pcms(struct hda_codec *codec)
2870{
2871 struct sigmatel_spec *spec = codec->spec;
2872 struct hda_pcm *info = spec->pcm_rec;
2873
2874 codec->num_pcms = 1;
2875 codec->pcm_info = info;
2876
Mattc7d4b2f2005-06-27 14:59:41 +02002877 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002878 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002879 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2880 spec->multiout.dac_nids[0];
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002881 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2882 spec->autocfg.line_outs == 2)
2883 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2884 snd_pcm_2_1_chmaps;
2885
Matt2f2f4252005-04-13 14:45:30 +02002886 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002887 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002888 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002889
2890 if (spec->alt_switch) {
2891 codec->num_pcms++;
2892 info++;
2893 info->name = "STAC92xx Analog Alt";
2894 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2895 }
Matt2f2f4252005-04-13 14:45:30 +02002896
Mattdabbed62005-06-14 10:19:34 +02002897 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2898 codec->num_pcms++;
2899 info++;
2900 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002901 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002902 if (spec->multiout.dig_out_nid) {
2903 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2904 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2905 }
2906 if (spec->dig_in_nid) {
2907 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2908 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2909 }
2910 }
2911
Matt2f2f4252005-04-13 14:45:30 +02002912 return 0;
2913}
2914
Matt Porter403d1942005-11-29 15:00:51 +01002915static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2916
2917{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002918 snd_hda_set_pin_ctl_cache(codec, nid, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002919}
2920
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002921#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2922
2923static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2924 struct snd_ctl_elem_value *ucontrol)
2925{
2926 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2927 struct sigmatel_spec *spec = codec->spec;
2928
Takashi Iwaid7a89432008-11-12 09:48:04 +01002929 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002930 return 0;
2931}
2932
Takashi Iwai62558ce2009-07-29 14:23:09 +02002933static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002934
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002935static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2936 struct snd_ctl_elem_value *ucontrol)
2937{
2938 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2939 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002940 int nid = kcontrol->private_value;
2941
2942 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002943
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002944 /* check to be sure that the ports are up to date with
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002945 * switch changes
2946 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002947 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002948
2949 return 1;
2950}
2951
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002952static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2953 struct snd_ctl_elem_info *uinfo)
2954{
2955 int i;
Takashi Iwai2b635362011-05-02 12:33:43 +02002956 static const char * const texts[] = {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002957 "Mic In", "Line In", "Line Out"
2958 };
2959
2960 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2961 struct sigmatel_spec *spec = codec->spec;
2962 hda_nid_t nid = kcontrol->private_value;
2963
2964 if (nid == spec->mic_switch || nid == spec->line_switch)
2965 i = 3;
2966 else
2967 i = 2;
2968
2969 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2970 uinfo->value.enumerated.items = i;
2971 uinfo->count = 1;
2972 if (uinfo->value.enumerated.item >= i)
2973 uinfo->value.enumerated.item = i-1;
2974 strcpy(uinfo->value.enumerated.name,
2975 texts[uinfo->value.enumerated.item]);
2976
2977 return 0;
2978}
2979
2980static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2981 struct snd_ctl_elem_value *ucontrol)
2982{
2983 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2984 hda_nid_t nid = kcontrol->private_value;
2985 unsigned int vref = stac92xx_vref_get(codec, nid);
2986
Takashi Iwai47408602012-04-20 13:06:53 +02002987 if (vref == snd_hda_get_default_vref(codec, nid))
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002988 ucontrol->value.enumerated.item[0] = 0;
2989 else if (vref == AC_PINCTL_VREF_GRD)
2990 ucontrol->value.enumerated.item[0] = 1;
2991 else if (vref == AC_PINCTL_VREF_HIZ)
2992 ucontrol->value.enumerated.item[0] = 2;
2993
2994 return 0;
2995}
2996
2997static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2998 struct snd_ctl_elem_value *ucontrol)
2999{
3000 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3001 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02003002 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003003 hda_nid_t nid = kcontrol->private_value;
3004
3005 if (ucontrol->value.enumerated.item[0] == 0)
Takashi Iwai47408602012-04-20 13:06:53 +02003006 new_vref = snd_hda_get_default_vref(codec, nid);
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003007 else if (ucontrol->value.enumerated.item[0] == 1)
3008 new_vref = AC_PINCTL_VREF_GRD;
3009 else if (ucontrol->value.enumerated.item[0] == 2)
3010 new_vref = AC_PINCTL_VREF_HIZ;
3011 else
3012 return 0;
3013
3014 if (new_vref != stac92xx_vref_get(codec, nid)) {
3015 error = stac92xx_vref_set(codec, nid, new_vref);
3016 return error;
3017 }
3018
3019 return 0;
3020}
3021
3022static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
3023 struct snd_ctl_elem_info *uinfo)
3024{
Takashi Iwai2b635362011-05-02 12:33:43 +02003025 char *texts[2];
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003026 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3027 struct sigmatel_spec *spec = codec->spec;
3028
3029 if (kcontrol->private_value == spec->line_switch)
3030 texts[0] = "Line In";
3031 else
3032 texts[0] = "Mic In";
3033 texts[1] = "Line Out";
3034 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3035 uinfo->value.enumerated.items = 2;
3036 uinfo->count = 1;
3037
3038 if (uinfo->value.enumerated.item >= 2)
3039 uinfo->value.enumerated.item = 1;
3040 strcpy(uinfo->value.enumerated.name,
3041 texts[uinfo->value.enumerated.item]);
3042
3043 return 0;
3044}
Matt Porter403d1942005-11-29 15:00:51 +01003045
3046static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3047{
3048 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3049 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003050 hda_nid_t nid = kcontrol->private_value;
3051 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01003052
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003053 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01003054 return 0;
3055}
3056
3057static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3058{
3059 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3060 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003061 hda_nid_t nid = kcontrol->private_value;
3062 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
3063 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01003064
3065 spec->io_switch[io_idx] = val;
3066
3067 if (val)
3068 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01003069 else {
3070 unsigned int pinctl = AC_PINCTL_IN_EN;
3071 if (io_idx) /* set VREF for mic */
Takashi Iwai47408602012-04-20 13:06:53 +02003072 pinctl |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01003073 stac92xx_auto_set_pinctl(codec, nid, pinctl);
3074 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01003075
3076 /* check the auto-mute again: we need to mute/unmute the speaker
3077 * appropriately according to the pin direction
3078 */
3079 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02003080 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01003081
Matt Porter403d1942005-11-29 15:00:51 +01003082 return 1;
3083}
3084
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003085#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
3086
3087static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
3088 struct snd_ctl_elem_value *ucontrol)
3089{
3090 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3091 struct sigmatel_spec *spec = codec->spec;
3092
3093 ucontrol->value.integer.value[0] = spec->clfe_swap;
3094 return 0;
3095}
3096
3097static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
3098 struct snd_ctl_elem_value *ucontrol)
3099{
3100 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3101 struct sigmatel_spec *spec = codec->spec;
3102 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01003103 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003104
Takashi Iwai68ea7b22007-11-15 15:54:38 +01003105 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003106 return 0;
3107
Takashi Iwai68ea7b22007-11-15 15:54:38 +01003108 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003109
3110 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
3111 spec->clfe_swap ? 0x4 : 0x0);
3112
3113 return 1;
3114}
3115
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003116#define STAC_CODEC_HP_SWITCH(xname) \
3117 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3118 .name = xname, \
3119 .index = 0, \
3120 .info = stac92xx_hp_switch_info, \
3121 .get = stac92xx_hp_switch_get, \
3122 .put = stac92xx_hp_switch_put, \
3123 }
3124
Matt Porter403d1942005-11-29 15:00:51 +01003125#define STAC_CODEC_IO_SWITCH(xname, xpval) \
3126 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3127 .name = xname, \
3128 .index = 0, \
3129 .info = stac92xx_io_switch_info, \
3130 .get = stac92xx_io_switch_get, \
3131 .put = stac92xx_io_switch_put, \
3132 .private_value = xpval, \
3133 }
3134
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003135#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
3136 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3137 .name = xname, \
3138 .index = 0, \
3139 .info = stac92xx_clfe_switch_info, \
3140 .get = stac92xx_clfe_switch_get, \
3141 .put = stac92xx_clfe_switch_put, \
3142 .private_value = xpval, \
3143 }
Matt Porter403d1942005-11-29 15:00:51 +01003144
Mattc7d4b2f2005-06-27 14:59:41 +02003145enum {
3146 STAC_CTL_WIDGET_VOL,
3147 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003148 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01003149 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003150 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01003151 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02003152 STAC_CTL_WIDGET_CLFE_SWITCH,
3153 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02003154};
3155
Takashi Iwai2b635362011-05-02 12:33:43 +02003156static const struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02003157 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3158 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003159 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01003160 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003161 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01003162 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003163 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02003164 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02003165};
3166
3167/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01003168static struct snd_kcontrol_new *
3169stac_control_new(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02003170 const struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01003171 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01003172 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02003173{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01003174 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02003175
Takashi Iwai603c4012008-07-30 15:01:44 +02003176 knew = snd_array_new(&spec->kctls);
3177 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01003178 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003179 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02003180 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01003181 if (!knew->name) {
3182 /* roolback */
3183 memset(knew, 0, sizeof(*knew));
3184 spec->kctls.alloced--;
3185 return NULL;
3186 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01003187 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01003188 return knew;
3189}
3190
Takashi Iwai62cbde12012-09-14 11:58:54 +02003191static struct snd_kcontrol_new *
3192add_control_temp(struct sigmatel_spec *spec,
3193 const struct snd_kcontrol_new *ktemp,
3194 int idx, const char *name,
3195 unsigned long val)
3196{
3197 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
3198 HDA_SUBDEV_AMP_FLAG);
3199 if (!knew)
3200 return NULL;
3201 knew->index = idx;
3202 knew->private_value = val;
3203 return knew;
3204}
3205
Takashi Iwaie3c75962009-01-23 11:57:22 +01003206static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02003207 const struct snd_kcontrol_new *ktemp,
Takashi Iwaie3c75962009-01-23 11:57:22 +01003208 int idx, const char *name,
3209 unsigned long val)
3210{
Takashi Iwai62cbde12012-09-14 11:58:54 +02003211 return add_control_temp(spec, ktemp, idx, name, val) ? 0 : -ENOMEM;
Mattc7d4b2f2005-06-27 14:59:41 +02003212}
3213
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003214static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
3215 int type, int idx, const char *name,
3216 unsigned long val)
3217{
3218 return stac92xx_add_control_temp(spec,
3219 &stac92xx_control_templates[type],
3220 idx, name, val);
3221}
3222
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003223
3224/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003225static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
3226 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003227{
3228 return stac92xx_add_control_idx(spec, type, 0, name, val);
3229}
3230
Takashi Iwai2b635362011-05-02 12:33:43 +02003231static const struct snd_kcontrol_new stac_input_src_temp = {
Takashi Iwaie3c75962009-01-23 11:57:22 +01003232 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3233 .name = "Input Source",
3234 .info = stac92xx_mux_enum_info,
3235 .get = stac92xx_mux_enum_get,
3236 .put = stac92xx_mux_enum_put,
3237};
3238
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003239static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
3240 hda_nid_t nid, int idx)
3241{
3242 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
3243 int control = 0;
3244 struct sigmatel_spec *spec = codec->spec;
3245 char name[22];
3246
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003247 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
David Henningsson8d032a82012-10-09 12:48:40 +02003248 if (spec->headset_jack && snd_hda_get_input_pin_attr(def_conf)
3249 != INPUT_PIN_ATTR_DOCK)
3250 return 0;
Takashi Iwai47408602012-04-20 13:06:53 +02003251 if (snd_hda_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003252 && nid == spec->line_switch)
3253 control = STAC_CTL_WIDGET_IO_SWITCH;
3254 else if (snd_hda_query_pin_caps(codec, nid)
3255 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
3256 control = STAC_CTL_WIDGET_DC_BIAS;
3257 else if (nid == spec->mic_switch)
3258 control = STAC_CTL_WIDGET_IO_SWITCH;
3259 }
3260
3261 if (control) {
Takashi Iwai201e06f2011-11-16 15:33:26 +01003262 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
3263 name, sizeof(name), NULL);
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003264 return stac92xx_add_control(codec->spec, control,
3265 strcat(name, " Jack Mode"), nid);
3266 }
3267
3268 return 0;
3269}
3270
Takashi Iwaie3c75962009-01-23 11:57:22 +01003271static int stac92xx_add_input_source(struct sigmatel_spec *spec)
3272{
3273 struct snd_kcontrol_new *knew;
3274 struct hda_input_mux *imux = &spec->private_imux;
3275
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003276 if (spec->auto_mic)
3277 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01003278 if (!spec->num_adcs || imux->num_items <= 1)
3279 return 0; /* no need for input source control */
3280 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01003281 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01003282 if (!knew)
3283 return -ENOMEM;
3284 knew->count = spec->num_adcs;
3285 return 0;
3286}
3287
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003288/* check whether the line-input can be used as line-out */
3289static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01003290{
3291 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003292 struct auto_pin_cfg *cfg = &spec->autocfg;
3293 hda_nid_t nid;
3294 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003295 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003296
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003297 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
3298 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003299 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003300 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003301 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01003302 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003303 if (pincap & AC_PINCAP_OUT)
3304 return nid;
3305 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003306 }
Matt Porter403d1942005-11-29 15:00:51 +01003307 return 0;
3308}
3309
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003310static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
3311
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003312/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003313static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003314{
3315 struct sigmatel_spec *spec = codec->spec;
3316 struct auto_pin_cfg *cfg = &spec->autocfg;
3317 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02003318 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003319
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003320 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003321 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
3322 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003323 for (i = 0; i < cfg->num_inputs; i++) {
3324 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02003325 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003326 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003327 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3328 /* some laptops have an internal analog microphone
3329 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003330 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003331 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003332 if (pincap & AC_PINCAP_OUT) {
3333 *dac = get_unassigned_dac(codec, nid);
3334 if (*dac)
3335 return nid;
3336 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003337 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003338 }
3339 return 0;
3340}
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003341
3342static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3343{
3344 int i;
3345
3346 for (i = 0; i < spec->multiout.num_dacs; i++) {
3347 if (spec->multiout.dac_nids[i] == nid)
3348 return 1;
3349 }
3350
3351 return 0;
3352}
3353
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003354static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3355{
3356 int i;
3357 if (is_in_dac_nids(spec, nid))
3358 return 1;
3359 for (i = 0; i < spec->autocfg.hp_outs; i++)
3360 if (spec->hp_dacs[i] == nid)
3361 return 1;
3362 for (i = 0; i < spec->autocfg.speaker_outs; i++)
3363 if (spec->speaker_dacs[i] == nid)
3364 return 1;
3365 return 0;
3366}
3367
3368static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
3369{
3370 struct sigmatel_spec *spec = codec->spec;
David Henningsson48718ea2011-10-05 09:49:05 +02003371 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003372 int j, conn_len;
David Henningsson48718ea2011-10-05 09:49:05 +02003373 hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003374 unsigned int wcaps, wtype;
3375
3376 conn_len = snd_hda_get_connections(codec, nid, conn,
3377 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01003378 /* 92HD88: trace back up the link of nids to find the DAC */
3379 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
3380 != AC_WID_AUD_OUT)) {
3381 nid = conn[0];
3382 conn_len = snd_hda_get_connections(codec, nid, conn,
3383 HDA_MAX_CONNECTIONS);
3384 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003385 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01003386 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003387 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003388 /* we check only analog outputs */
3389 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3390 continue;
3391 /* if this route has a free DAC, assign it */
3392 if (!check_all_dac_nids(spec, conn[j])) {
3393 if (conn_len > 1) {
3394 /* select this DAC in the pin's input mux */
3395 snd_hda_codec_write_cache(codec, nid, 0,
3396 AC_VERB_SET_CONNECT_SEL, j);
3397 }
3398 return conn[j];
3399 }
3400 }
David Henningsson48718ea2011-10-05 09:49:05 +02003401
3402 /* if all DACs are already assigned, connect to the primary DAC,
3403 unless we're assigning a secondary headphone */
3404 fallback_dac = spec->multiout.dac_nids[0];
3405 if (spec->multiout.hp_nid) {
3406 for (j = 0; j < cfg->hp_outs; j++)
3407 if (cfg->hp_pins[j] == nid) {
3408 fallback_dac = spec->multiout.hp_nid;
3409 break;
3410 }
3411 }
3412
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003413 if (conn_len > 1) {
3414 for (j = 0; j < conn_len; j++) {
David Henningsson48718ea2011-10-05 09:49:05 +02003415 if (conn[j] == fallback_dac) {
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003416 snd_hda_codec_write_cache(codec, nid, 0,
3417 AC_VERB_SET_CONNECT_SEL, j);
3418 break;
3419 }
3420 }
3421 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003422 return 0;
3423}
3424
3425static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3426static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3427
Matt Porter3cc08dc2006-01-23 15:27:49 +01003428/*
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003429 * Fill in the dac_nids table from the parsed pin configuration
3430 * This function only works when every pin in line_out_pins[]
3431 * contains atleast one DAC in its connection list. Some 92xx
3432 * codecs are not connected directly to a DAC, such as the 9200
3433 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01003434 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003435static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003436{
3437 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003438 struct auto_pin_cfg *cfg = &spec->autocfg;
3439 int i;
3440 hda_nid_t nid, dac;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003441
Mattc7d4b2f2005-06-27 14:59:41 +02003442 for (i = 0; i < cfg->line_outs; i++) {
3443 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003444 dac = get_unassigned_dac(codec, nid);
3445 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003446 if (spec->multiout.num_dacs > 0) {
3447 /* we have already working output pins,
3448 * so let's drop the broken ones again
3449 */
3450 cfg->line_outs = spec->multiout.num_dacs;
3451 break;
3452 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003453 /* error out, no available DAC found */
3454 snd_printk(KERN_ERR
3455 "%s: No available DAC for pin 0x%x\n",
3456 __func__, nid);
3457 return -ENODEV;
3458 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003459 add_spec_dacs(spec, dac);
3460 }
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003461
Takashi Iwai139e0712009-03-06 12:10:41 +01003462 for (i = 0; i < cfg->hp_outs; i++) {
3463 nid = cfg->hp_pins[i];
3464 dac = get_unassigned_dac(codec, nid);
3465 if (dac) {
3466 if (!spec->multiout.hp_nid)
3467 spec->multiout.hp_nid = dac;
3468 else
3469 add_spec_extra_dacs(spec, dac);
3470 }
3471 spec->hp_dacs[i] = dac;
3472 }
3473
3474 for (i = 0; i < cfg->speaker_outs; i++) {
3475 nid = cfg->speaker_pins[i];
3476 dac = get_unassigned_dac(codec, nid);
3477 if (dac)
3478 add_spec_extra_dacs(spec, dac);
3479 spec->speaker_dacs[i] = dac;
3480 }
3481
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003482 /* add line-in as output */
3483 nid = check_line_out_switch(codec);
3484 if (nid) {
3485 dac = get_unassigned_dac(codec, nid);
3486 if (dac) {
3487 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3488 nid, cfg->line_outs);
3489 cfg->line_out_pins[cfg->line_outs] = nid;
3490 cfg->line_outs++;
3491 spec->line_switch = nid;
3492 add_spec_dacs(spec, dac);
3493 }
3494 }
3495 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003496 nid = check_mic_out_switch(codec, &dac);
3497 if (nid && dac) {
3498 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3499 nid, cfg->line_outs);
3500 cfg->line_out_pins[cfg->line_outs] = nid;
3501 cfg->line_outs++;
3502 spec->mic_switch = nid;
3503 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003504 }
3505
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003506 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b0438992007-05-03 20:50:03 +02003507 spec->multiout.num_dacs,
3508 spec->multiout.dac_nids[0],
3509 spec->multiout.dac_nids[1],
3510 spec->multiout.dac_nids[2],
3511 spec->multiout.dac_nids[3],
3512 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003513
Mattc7d4b2f2005-06-27 14:59:41 +02003514 return 0;
3515}
3516
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003517/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003518static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3519 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003520{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003521 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003522 char name[32];
3523 int err;
3524
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003525 if (!spec->check_volume_offset) {
3526 unsigned int caps, step, nums, db_scale;
3527 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3528 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3529 AC_AMPCAP_STEP_SIZE_SHIFT;
3530 step = (step + 1) * 25; /* in .01dB unit */
3531 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3532 AC_AMPCAP_NUM_STEPS_SHIFT;
3533 db_scale = nums * step;
3534 /* if dB scale is over -64dB, and finer enough,
3535 * let's reduce it to half
3536 */
3537 if (db_scale > 6400 && nums >= 0x1f)
3538 spec->volume_offset = nums / 2;
3539 spec->check_volume_offset = 1;
3540 }
3541
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003542 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003543 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003544 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3545 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003546 if (err < 0)
3547 return err;
3548 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003549 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003550 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3551 if (err < 0)
3552 return err;
3553 return 0;
3554}
3555
Takashi Iwai668b9652009-03-06 10:13:24 +01003556#define create_controls(codec, pfx, nid, chs) \
3557 create_controls_idx(codec, pfx, 0, nid, chs)
3558
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003559static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3560{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003561 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003562 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3563 return 1;
3564 } else {
Takashi Iwaidda14412011-05-02 11:29:30 +02003565 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3566 spec->dac_nids[spec->multiout.num_dacs] = nid;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003567 spec->multiout.num_dacs++;
3568 }
3569 return 0;
3570}
3571
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003572static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003573{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003574 int i;
3575 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3576 if (!spec->multiout.extra_out_nid[i]) {
3577 spec->multiout.extra_out_nid[i] = nid;
3578 return 0;
3579 }
3580 }
3581 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3582 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003583}
3584
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003585/* Create output controls
3586 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3587 */
3588static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3589 const hda_nid_t *pins,
3590 const hda_nid_t *dac_nids,
3591 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003592{
Takashi Iwai76624532008-12-19 10:09:47 +01003593 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaiea734962011-01-17 11:29:34 +01003594 static const char * const chname[4] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02003595 "Front", "Surround", NULL /*CLFE*/, "Side"
3596 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003597 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003598 int i, err;
3599 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003600
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003601 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003602 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003603 if (is_jack_detectable(codec, pins[i]))
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003604 spec->hp_detect = 1;
3605 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003606 nid = dac_nids[i];
3607 if (!nid)
3608 continue;
3609 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003610 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003611 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003612 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003613 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003614 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003615 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003616 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003617
3618 wid_caps = get_wcaps(codec, nid);
3619
3620 if (wid_caps & AC_WCAP_LR_SWAP) {
3621 err = stac92xx_add_control(spec,
3622 STAC_CTL_WIDGET_CLFE_SWITCH,
3623 "Swap Center/LFE Playback Switch", nid);
3624
3625 if (err < 0)
3626 return err;
3627 }
3628
Mattc7d4b2f2005-06-27 14:59:41 +02003629 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003630 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003631 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003632 switch (type) {
3633 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003634 name = "Headphone";
3635 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003636 break;
3637 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01003638 if (num_outs <= 2) {
3639 name = i ? "Bass Speaker" : "Speaker";
3640 idx = 0;
David Henningsson298efee2012-09-06 11:17:58 +02003641 break;
3642 }
3643 /* Fall through in case of multi speaker outs */
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003644 default:
3645 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003646 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003647 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003648 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003649 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003650 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003651 return err;
3652 }
3653 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003654 return 0;
3655}
3656
Takashi Iwai62cbde12012-09-14 11:58:54 +02003657static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
3658 unsigned int dir_mask, unsigned int data);
3659
3660/* hook for controlling mic-mute LED GPIO */
3661static int stac92xx_capture_sw_put_led(struct snd_kcontrol *kcontrol,
3662 struct snd_ctl_elem_value *ucontrol)
3663{
3664 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3665 struct sigmatel_spec *spec = codec->spec;
3666 int err;
3667 bool mute;
3668
3669 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3670 if (err <= 0)
3671 return err;
3672 mute = !(ucontrol->value.integer.value[0] &&
3673 ucontrol->value.integer.value[1]);
3674 if (spec->mic_mute_led_on != mute) {
3675 spec->mic_mute_led_on = mute;
3676 if (mute)
3677 spec->gpio_data |= spec->mic_mute_led_gpio;
3678 else
3679 spec->gpio_data &= ~spec->mic_mute_led_gpio;
3680 stac_gpio_set(codec, spec->gpio_mask,
3681 spec->gpio_dir, spec->gpio_data);
3682 }
3683 return err;
3684}
3685
Takashi Iwai6479c632009-07-28 18:20:25 +02003686static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3687 unsigned long sw, int idx)
3688{
Takashi Iwai62cbde12012-09-14 11:58:54 +02003689 struct sigmatel_spec *spec = codec->spec;
3690 struct snd_kcontrol_new *knew;
Takashi Iwai6479c632009-07-28 18:20:25 +02003691 int err;
Takashi Iwai62cbde12012-09-14 11:58:54 +02003692
Takashi Iwai6479c632009-07-28 18:20:25 +02003693 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003694 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003695 if (err < 0)
3696 return err;
Takashi Iwai62cbde12012-09-14 11:58:54 +02003697
3698 knew = add_control_temp(spec,
3699 &stac92xx_control_templates[STAC_CTL_WIDGET_MUTE],
3700 idx, "Capture Switch", sw);
3701 if (!knew)
3702 return -ENOMEM;
3703 /* add a LED hook for some HP laptops */
3704 if (spec->mic_mute_led_gpio)
3705 knew->put = stac92xx_capture_sw_put_led;
3706
Takashi Iwai6479c632009-07-28 18:20:25 +02003707 return 0;
3708}
3709
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003710/* add playback controls from the parsed DAC table */
3711static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3712 const struct auto_pin_cfg *cfg)
3713{
3714 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003715 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003716 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003717 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003718
3719 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3720 spec->multiout.dac_nids,
3721 cfg->line_out_type);
3722 if (err < 0)
3723 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003724
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003725 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003726 err = stac92xx_add_control(spec,
3727 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003728 "Headphone as Line Out Switch",
3729 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003730 if (err < 0)
3731 return err;
3732 }
3733
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003734 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003735 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003736 break;
3737 nid = cfg->inputs[idx].pin;
3738 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3739 if (err < 0)
3740 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003741 }
Matt Porter403d1942005-11-29 15:00:51 +01003742
Mattc7d4b2f2005-06-27 14:59:41 +02003743 return 0;
3744}
3745
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003746/* add playback controls for Speaker and HP outputs */
3747static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3748 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003749{
3750 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003751 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003752
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003753 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3754 spec->hp_dacs, AUTO_PIN_HP_OUT);
3755 if (err < 0)
3756 return err;
3757
3758 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3759 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3760 if (err < 0)
3761 return err;
3762
Mattc7d4b2f2005-06-27 14:59:41 +02003763 return 0;
3764}
3765
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003766/* labels for mono mux outputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003767static const char * const stac92xx_mono_labels[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003768 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003769};
3770
3771/* create mono mux for mono out on capable codecs */
3772static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3773{
3774 struct sigmatel_spec *spec = codec->spec;
3775 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3776 int i, num_cons;
3777 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3778
3779 num_cons = snd_hda_get_connections(codec,
3780 spec->mono_nid,
3781 con_lst,
3782 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003783 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003784 return -EINVAL;
3785
Takashi Iwai10a20af2010-09-09 16:28:02 +02003786 for (i = 0; i < num_cons; i++)
3787 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3788 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003789
3790 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3791 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003792}
3793
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003794/* create PC beep volume controls */
3795static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3796 hda_nid_t nid)
3797{
3798 struct sigmatel_spec *spec = codec->spec;
3799 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003800 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3801
3802 if (spec->anabeep_nid == nid)
3803 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003804
3805 /* check for mute support for the the amp */
3806 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003807 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003808 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003809 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3810 if (err < 0)
3811 return err;
3812 }
3813
3814 /* check to see if there is volume support for the amp */
3815 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3816 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003817 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003818 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3819 if (err < 0)
3820 return err;
3821 }
3822 return 0;
3823}
3824
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003825#ifdef CONFIG_SND_HDA_INPUT_BEEP
3826#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3827
3828static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3829 struct snd_ctl_elem_value *ucontrol)
3830{
3831 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3832 ucontrol->value.integer.value[0] = codec->beep->enabled;
3833 return 0;
3834}
3835
3836static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3837 struct snd_ctl_elem_value *ucontrol)
3838{
3839 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003840 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003841}
3842
Takashi Iwai2b635362011-05-02 12:33:43 +02003843static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003844 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3845 .info = stac92xx_dig_beep_switch_info,
3846 .get = stac92xx_dig_beep_switch_get,
3847 .put = stac92xx_dig_beep_switch_put,
3848};
3849
3850static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3851{
3852 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003853 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003854}
3855#endif
3856
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003857static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3858{
3859 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003860 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003861
3862 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003863 hda_nid_t nid;
3864 unsigned int wcaps;
3865 unsigned long val;
3866
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003867 nid = spec->mux_nids[i];
3868 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003869 if (!(wcaps & AC_WCAP_OUT_AMP))
3870 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003871
Takashi Iwai667067d2009-08-13 18:14:42 +02003872 /* check whether already the same control was created as
3873 * normal Capture Volume.
3874 */
3875 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3876 for (j = 0; j < spec->num_caps; j++) {
3877 if (spec->capvols[j] == val)
3878 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003879 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003880 if (j < spec->num_caps)
3881 continue;
3882
3883 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3884 "Mux Capture Volume", val);
3885 if (err < 0)
3886 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003887 }
3888 return 0;
3889};
3890
Takashi Iwaiea734962011-01-17 11:29:34 +01003891static const char * const stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003892 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003893};
3894
3895static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3896{
3897 struct sigmatel_spec *spec = codec->spec;
3898 struct hda_input_mux *spdif_mux = &spec->private_smux;
Takashi Iwaiea734962011-01-17 11:29:34 +01003899 const char * const *labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003900 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003901 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003902
3903 num_cons = snd_hda_get_connections(codec,
3904 spec->smux_nids[0],
3905 con_lst,
3906 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003907 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003908 return -EINVAL;
3909
Matthew Ranostay65973632008-09-16 10:39:37 -04003910 if (!labels)
3911 labels = stac92xx_spdif_labels;
3912
Takashi Iwai10a20af2010-09-09 16:28:02 +02003913 for (i = 0; i < num_cons; i++)
3914 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003915
3916 return 0;
3917}
3918
Matt Porter8b657272006-10-26 17:12:59 +02003919/* labels for dmic mux inputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003920static const char * const stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003921 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3922 "Digital Mic 3", "Digital Mic 4"
3923};
3924
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003925static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3926 int idx)
3927{
3928 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3929 int nums;
3930 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3931 if (idx >= 0 && idx < nums)
3932 return conn[idx];
3933 return 0;
3934}
3935
Takashi Iwai8d087c72011-06-28 12:45:47 +02003936/* look for NID recursively */
3937#define get_connection_index(codec, mux, nid) \
3938 snd_hda_get_conn_index(codec, mux, nid, 1)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003939
Takashi Iwai667067d2009-08-13 18:14:42 +02003940/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003941/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003942static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003943 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003944{
3945 unsigned int caps, nums;
3946 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003947 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003948
Takashi Iwai96f845d2009-08-29 00:49:36 +02003949 if (direction == HDA_OUTPUT)
3950 caps = AC_WCAP_OUT_AMP;
3951 else
3952 caps = AC_WCAP_IN_AMP;
3953 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003954 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003955 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003956 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3957 if (!nums)
3958 return 0;
3959 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003960 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3961 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003962 if (err < 0)
3963 return err;
3964 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003965}
3966
Matt Porter8b657272006-10-26 17:12:59 +02003967/* create playback/capture controls for input pins on dmic capable codecs */
3968static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3969 const struct auto_pin_cfg *cfg)
3970{
3971 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003972 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003973 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003974 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003975 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003976
Takashi Iwai10a20af2010-09-09 16:28:02 +02003977 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003978
Matt Porter8b657272006-10-26 17:12:59 +02003979 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003980 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003981 int index, type_idx;
Takashi Iwai201e06f2011-11-16 15:33:26 +01003982 char label[32];
Matt Porter8b657272006-10-26 17:12:59 +02003983
Takashi Iwai667067d2009-08-13 18:14:42 +02003984 nid = spec->dmic_nids[i];
3985 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3986 continue;
3987 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003988 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3989 continue;
3990
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003991 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3992 if (index < 0)
3993 continue;
3994
Takashi Iwai201e06f2011-11-16 15:33:26 +01003995 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
3996 label, sizeof(label), NULL);
Takashi Iwai10a20af2010-09-09 16:28:02 +02003997 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai2d7ec122010-12-23 10:16:05 +01003998 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3999 snd_hda_add_imux_item(imux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02004000
Takashi Iwai10a20af2010-09-09 16:28:02 +02004001 err = create_elem_capture_vol(codec, nid, label, type_idx,
4002 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02004003 if (err < 0)
4004 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02004005 if (!err) {
4006 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02004007 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02004008 if (err < 0)
4009 return err;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06004010 if (!err) {
4011 nid = get_connected_node(codec,
4012 spec->dmux_nids[0], index);
4013 if (nid)
4014 err = create_elem_capture_vol(codec,
4015 nid, label,
4016 type_idx, HDA_INPUT);
4017 if (err < 0)
4018 return err;
4019 }
Takashi Iwai96f845d2009-08-29 00:49:36 +02004020 }
Matt Porter8b657272006-10-26 17:12:59 +02004021 }
4022
4023 return 0;
4024}
4025
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004026static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02004027 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004028{
4029 unsigned int cfg;
Takashi Iwai1f83ac52011-05-17 12:29:09 +02004030 unsigned int type;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004031
4032 if (!nid)
4033 return 0;
4034 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai1f83ac52011-05-17 12:29:09 +02004035 type = get_defcfg_device(cfg);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02004036 switch (snd_hda_get_input_pin_attr(cfg)) {
4037 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004038 if (*fixed)
4039 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02004040 if (type != AC_JACK_MIC_IN)
4041 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004042 *fixed = nid;
4043 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02004044 case INPUT_PIN_ATTR_UNUSED:
4045 break;
4046 case INPUT_PIN_ATTR_DOCK:
4047 if (*dock)
4048 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02004049 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
4050 return 1; /* invalid type */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02004051 *dock = nid;
4052 break;
4053 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004054 if (*ext)
4055 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02004056 if (type != AC_JACK_MIC_IN)
4057 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004058 *ext = nid;
4059 break;
4060 }
4061 return 0;
4062}
4063
4064static int set_mic_route(struct hda_codec *codec,
4065 struct sigmatel_mic_route *mic,
4066 hda_nid_t pin)
4067{
4068 struct sigmatel_spec *spec = codec->spec;
4069 struct auto_pin_cfg *cfg = &spec->autocfg;
4070 int i;
4071
4072 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02004073 if (pin == 0)
4074 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004075 for (i = 0; i < cfg->num_inputs; i++) {
4076 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004077 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004078 }
Takashi Iwai86e29592010-09-09 14:50:17 +02004079 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004080 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004081 i = get_connection_index(codec, spec->mux_nids[0], pin);
4082 if (i < 0)
4083 return -1;
4084 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02004085 mic->dmux_idx = -1;
4086 if (spec->dmux_nids)
4087 mic->dmux_idx = get_connection_index(codec,
4088 spec->dmux_nids[0],
4089 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004090 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004091 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004092 i = get_connection_index(codec, spec->dmux_nids[0], pin);
4093 if (i < 0)
4094 return -1;
4095 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02004096 mic->mux_idx = -1;
4097 if (spec->mux_nids)
4098 mic->mux_idx = get_connection_index(codec,
4099 spec->mux_nids[0],
4100 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004101 }
4102 return 0;
4103}
4104
4105/* return non-zero if the device is for automatic mic switch */
4106static int stac_check_auto_mic(struct hda_codec *codec)
4107{
4108 struct sigmatel_spec *spec = codec->spec;
4109 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02004110 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004111 int i;
4112
Charles Chin99077902010-09-17 10:22:32 +02004113 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004114 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02004115 if (check_mic_pin(codec, cfg->inputs[i].pin,
4116 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004117 return 0;
4118 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02004119 if (check_mic_pin(codec, spec->dmic_nids[i],
4120 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004121 return 0;
Takashi Iwai80c67852011-01-13 08:08:08 +01004122 if (!fixed || (!ext && !dock))
Charles Chin99077902010-09-17 10:22:32 +02004123 return 0; /* no input to switch */
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004124 if (!is_jack_detectable(codec, ext))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004125 return 0; /* no unsol support */
4126 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02004127 set_mic_route(codec, &spec->int_mic, fixed) ||
4128 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004129 return 0; /* something is wrong */
4130 return 1;
4131}
4132
Mattc7d4b2f2005-06-27 14:59:41 +02004133/* create playback/capture controls for input pins */
4134static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
4135{
4136 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004137 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02004138 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02004139 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02004140
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004141 for (i = 0; i < cfg->num_inputs; i++) {
4142 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02004143 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02004144
Takashi Iwai314634b2006-09-21 11:56:18 +02004145 index = -1;
4146 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02004147 index = get_connection_index(codec, spec->mux_nids[j],
4148 nid);
4149 if (index >= 0)
4150 break;
Mattc7d4b2f2005-06-27 14:59:41 +02004151 }
Takashi Iwai667067d2009-08-13 18:14:42 +02004152 if (index < 0)
4153 continue;
4154
Takashi Iwai10a20af2010-09-09 16:28:02 +02004155 label = hda_get_autocfg_input_label(codec, cfg, i);
4156 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02004157
Takashi Iwai667067d2009-08-13 18:14:42 +02004158 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02004159 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02004160 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02004161 if (err < 0)
4162 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02004163 }
Takashi Iwai5207e102009-07-30 13:09:08 +02004164 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02004165
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004166 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02004167 /*
4168 * Set the current input for the muxes.
4169 * The STAC9221 has two input muxes with identical source
4170 * NID lists. Hopefully this won't get confused.
4171 */
4172 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004173 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
4174 AC_VERB_SET_CONNECT_SEL,
4175 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004176 }
4177 }
4178
Mattc7d4b2f2005-06-27 14:59:41 +02004179 return 0;
4180}
4181
Mattc7d4b2f2005-06-27 14:59:41 +02004182static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
4183{
4184 struct sigmatel_spec *spec = codec->spec;
4185 int i;
4186
4187 for (i = 0; i < spec->autocfg.line_outs; i++) {
4188 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4189 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
4190 }
4191}
4192
4193static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
4194{
4195 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004196 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004197
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004198 for (i = 0; i < spec->autocfg.hp_outs; i++) {
4199 hda_nid_t pin;
4200 pin = spec->autocfg.hp_pins[i];
4201 if (pin) /* connect to front */
4202 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
4203 }
4204 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
4205 hda_nid_t pin;
4206 pin = spec->autocfg.speaker_pins[i];
4207 if (pin) /* connect to front */
4208 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
4209 }
Mattc7d4b2f2005-06-27 14:59:41 +02004210}
4211
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01004212static int is_dual_headphones(struct hda_codec *codec)
4213{
4214 struct sigmatel_spec *spec = codec->spec;
4215 int i, valid_hps;
4216
4217 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
4218 spec->autocfg.hp_outs <= 1)
4219 return 0;
4220 valid_hps = 0;
4221 for (i = 0; i < spec->autocfg.hp_outs; i++) {
4222 hda_nid_t nid = spec->autocfg.hp_pins[i];
4223 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
4224 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
4225 continue;
4226 valid_hps++;
4227 }
4228 return (valid_hps > 1);
4229}
4230
4231
Charles Chin9009b0e2011-11-03 10:27:27 +01004232static int stac92xx_parse_auto_config(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02004233{
4234 struct sigmatel_spec *spec = codec->spec;
Charles Chin9009b0e2011-11-03 10:27:27 +01004235 hda_nid_t dig_out = 0, dig_in = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004236 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02004237 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02004238
Matt Porter8b657272006-10-26 17:12:59 +02004239 if ((err = snd_hda_parse_pin_def_config(codec,
4240 &spec->autocfg,
4241 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004242 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004243 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01004244 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02004245
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004246 /* If we have no real line-out pin and multiple hp-outs, HPs should
4247 * be set up as multi-channel outputs.
4248 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01004249 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004250 /* Copy hp_outs to line_outs, backup line_outs in
4251 * speaker_outs so that the following routines can handle
4252 * HP pins as primary outputs.
4253 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004254 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004255 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
4256 sizeof(spec->autocfg.line_out_pins));
4257 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
4258 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
4259 sizeof(spec->autocfg.hp_pins));
4260 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004261 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
4262 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004263 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004264 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01004265 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004266 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
4267 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01004268 u32 caps = query_amp_caps(codec,
4269 spec->autocfg.mono_out_pin, dir);
4270 hda_nid_t conn_list[1];
4271
4272 /* get the mixer node and then the mono mux if it exists */
4273 if (snd_hda_get_connections(codec,
4274 spec->autocfg.mono_out_pin, conn_list, 1) &&
4275 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02004276 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01004277
4278 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02004279 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01004280 /* LR swap check, some stac925x have a mux that
4281 * changes the DACs output path instead of the
4282 * mono-mux path.
4283 */
4284 if (wid_type == AC_WID_AUD_SEL &&
4285 !(wcaps & AC_WCAP_LR_SWAP))
4286 spec->mono_nid = conn_list[0];
4287 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004288 if (dir) {
4289 hda_nid_t nid = spec->autocfg.mono_out_pin;
4290
4291 /* most mono outs have a least a mute/unmute switch */
4292 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
4293 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
4294 "Mono Playback Switch",
4295 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01004296 if (err < 0)
4297 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004298 /* check for volume support for the amp */
4299 if ((caps & AC_AMPCAP_NUM_STEPS)
4300 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
4301 err = stac92xx_add_control(spec,
4302 STAC_CTL_WIDGET_VOL,
4303 "Mono Playback Volume",
4304 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
4305 if (err < 0)
4306 return err;
4307 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01004308 }
4309
4310 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
4311 AC_PINCTL_OUT_EN);
4312 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004313
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004314 if (!spec->multiout.num_dacs) {
4315 err = stac92xx_auto_fill_dac_nids(codec);
4316 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02004317 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01004318 err = stac92xx_auto_create_multi_out_ctls(codec,
4319 &spec->autocfg);
4320 if (err < 0)
4321 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004322 }
Mattc7d4b2f2005-06-27 14:59:41 +02004323
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004324 /* setup analog beep controls */
4325 if (spec->anabeep_nid > 0) {
4326 err = stac92xx_auto_create_beep_ctls(codec,
4327 spec->anabeep_nid);
4328 if (err < 0)
4329 return err;
4330 }
4331
4332 /* setup digital beep controls and input device */
4333#ifdef CONFIG_SND_HDA_INPUT_BEEP
4334 if (spec->digbeep_nid > 0) {
4335 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01004336 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004337
4338 err = stac92xx_auto_create_beep_ctls(codec, nid);
4339 if (err < 0)
4340 return err;
4341 err = snd_hda_attach_beep_device(codec, nid);
4342 if (err < 0)
4343 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01004344 if (codec->beep) {
4345 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01004346 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01004347 /* if no beep switch is available, make its own one */
4348 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
4349 if (!(caps & AC_AMPCAP_MUTE)) {
4350 err = stac92xx_beep_switch_ctl(codec);
4351 if (err < 0)
4352 return err;
4353 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01004354 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004355 }
4356#endif
4357
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004358 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004359 if (err < 0)
4360 return err;
4361
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004362 /* All output parsing done, now restore the swapped hp pins */
4363 if (hp_swap) {
4364 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
4365 sizeof(spec->autocfg.hp_pins));
4366 spec->autocfg.hp_outs = spec->autocfg.line_outs;
4367 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
4368 spec->autocfg.line_outs = 0;
4369 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004370
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004371 if (stac_check_auto_mic(codec)) {
4372 spec->auto_mic = 1;
4373 /* only one capture for auto-mic */
4374 spec->num_adcs = 1;
4375 spec->num_caps = 1;
4376 spec->num_muxes = 1;
4377 }
4378
Takashi Iwai6479c632009-07-28 18:20:25 +02004379 for (i = 0; i < spec->num_caps; i++) {
4380 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
4381 spec->capsws[i], i);
4382 if (err < 0)
4383 return err;
4384 }
4385
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004386 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004387 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004388 return err;
4389
Matthew Ranostayb22b4822008-01-22 12:32:30 +01004390 if (spec->mono_nid > 0) {
4391 err = stac92xx_auto_create_mono_output_ctls(codec);
4392 if (err < 0)
4393 return err;
4394 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004395 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02004396 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
4397 &spec->autocfg)) < 0)
4398 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02004399 if (spec->num_muxes > 0) {
4400 err = stac92xx_auto_create_mux_input_ctls(codec);
4401 if (err < 0)
4402 return err;
4403 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02004404 if (spec->num_smuxes > 0) {
4405 err = stac92xx_auto_create_spdif_mux_ctls(codec);
4406 if (err < 0)
4407 return err;
4408 }
Matt Porter8b657272006-10-26 17:12:59 +02004409
Takashi Iwaie3c75962009-01-23 11:57:22 +01004410 err = stac92xx_add_input_source(spec);
4411 if (err < 0)
4412 return err;
4413
Mattc7d4b2f2005-06-27 14:59:41 +02004414 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01004415 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02004416 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02004417
Charles Chin9009b0e2011-11-03 10:27:27 +01004418 /* find digital out and in converters */
4419 for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
4420 unsigned int wid_caps = get_wcaps(codec, i);
4421 if (wid_caps & AC_WCAP_DIGITAL) {
4422 switch (get_wcaps_type(wid_caps)) {
4423 case AC_WID_AUD_OUT:
4424 if (!dig_out)
4425 dig_out = i;
4426 break;
4427 case AC_WID_AUD_IN:
4428 if (!dig_in)
4429 dig_in = i;
4430 break;
4431 }
4432 }
4433 }
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004434 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004435 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004436 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004437 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02004438
Takashi Iwai603c4012008-07-30 15:01:44 +02004439 if (spec->kctls.list)
4440 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004441
4442 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05004443 if (!spec->dinput_mux)
4444 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004445 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01004446 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02004447 return 1;
4448}
4449
Takashi Iwai82bc9552006-03-21 11:24:42 +01004450/* add playback controls for HP output */
4451static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4452 struct auto_pin_cfg *cfg)
4453{
4454 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004455 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01004456
4457 if (! pin)
4458 return 0;
4459
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004460 if (is_jack_detectable(codec, pin))
Takashi Iwai82bc9552006-03-21 11:24:42 +01004461 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004462
4463 return 0;
4464}
4465
Richard Fish160ea0d2006-09-06 13:58:25 +02004466/* add playback controls for LFE output */
4467static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4468 struct auto_pin_cfg *cfg)
4469{
4470 struct sigmatel_spec *spec = codec->spec;
4471 int err;
4472 hda_nid_t lfe_pin = 0x0;
4473 int i;
4474
4475 /*
4476 * search speaker outs and line outs for a mono speaker pin
4477 * with an amp. If one is found, add LFE controls
4478 * for it.
4479 */
4480 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4481 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004482 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004483 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4484 if (wcaps == AC_WCAP_OUT_AMP)
4485 /* found a mono speaker with an amp, must be lfe */
4486 lfe_pin = pin;
4487 }
4488
4489 /* if speaker_outs is 0, then speakers may be in line_outs */
4490 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4491 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4492 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004493 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004494 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004495 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004496 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004497 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4498 if (wcaps == AC_WCAP_OUT_AMP)
4499 /* found a mono speaker with an amp,
4500 must be lfe */
4501 lfe_pin = pin;
4502 }
4503 }
4504 }
4505
4506 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004507 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004508 if (err < 0)
4509 return err;
4510 }
4511
4512 return 0;
4513}
4514
Mattc7d4b2f2005-06-27 14:59:41 +02004515static int stac9200_parse_auto_config(struct hda_codec *codec)
4516{
4517 struct sigmatel_spec *spec = codec->spec;
4518 int err;
4519
Kailang Yangdf694da2005-12-05 19:42:22 +01004520 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004521 return err;
4522
4523 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4524 return err;
4525
Takashi Iwai82bc9552006-03-21 11:24:42 +01004526 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4527 return err;
4528
Richard Fish160ea0d2006-09-06 13:58:25 +02004529 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4530 return err;
4531
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004532 if (spec->num_muxes > 0) {
4533 err = stac92xx_auto_create_mux_input_ctls(codec);
4534 if (err < 0)
4535 return err;
4536 }
4537
Takashi Iwaie3c75962009-01-23 11:57:22 +01004538 err = stac92xx_add_input_source(spec);
4539 if (err < 0)
4540 return err;
4541
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004542 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004543 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004544 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004545 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004546
Takashi Iwai603c4012008-07-30 15:01:44 +02004547 if (spec->kctls.list)
4548 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004549
4550 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004551 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004552
4553 return 1;
4554}
4555
Sam Revitch62fe78e2006-05-10 15:09:17 +02004556/*
4557 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4558 * funky external mute control using GPIO pins.
4559 */
4560
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004561static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004562 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004563{
4564 unsigned int gpiostate, gpiomask, gpiodir;
4565
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004566 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4567
Sam Revitch62fe78e2006-05-10 15:09:17 +02004568 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4569 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004570 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004571
4572 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4573 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004574 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004575
4576 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4577 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004578 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004579
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004580 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004581 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4582
4583 snd_hda_codec_write(codec, codec->afg, 0,
4584 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004585 snd_hda_codec_read(codec, codec->afg, 0,
4586 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004587
4588 msleep(1);
4589
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004590 snd_hda_codec_read(codec, codec->afg, 0,
4591 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004592}
4593
Takashi Iwai3a938972011-10-28 01:16:55 +02004594static int stac_add_event(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004595 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004596{
Takashi Iwai3a938972011-10-28 01:16:55 +02004597 struct hda_jack_tbl *event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004598
Takashi Iwai3a938972011-10-28 01:16:55 +02004599 event = snd_hda_jack_tbl_new(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004600 if (!event)
4601 return -ENOMEM;
Takashi Iwai3a938972011-10-28 01:16:55 +02004602 event->action = type;
4603 event->private_data = data;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004604
Takashi Iwai3a938972011-10-28 01:16:55 +02004605 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004606}
4607
David Henningsson29adc4b2012-09-25 11:31:00 +02004608static void handle_unsol_event(struct hda_codec *codec,
4609 struct hda_jack_tbl *event);
4610
Takashi Iwai62558ce2009-07-29 14:23:09 +02004611/* check if given nid is a valid pin and no other events are assigned
4612 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4613 * Otherwise, returns zero.
4614 */
4615static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4616 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004617{
Takashi Iwai3a938972011-10-28 01:16:55 +02004618 struct hda_jack_tbl *event;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004619
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004620 if (!is_jack_detectable(codec, nid))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004621 return 0;
Takashi Iwai3a938972011-10-28 01:16:55 +02004622 event = snd_hda_jack_tbl_new(codec, nid);
4623 if (!event)
4624 return -ENOMEM;
4625 if (event->action && event->action != type)
4626 return 0;
4627 event->action = type;
David Henningsson29adc4b2012-09-25 11:31:00 +02004628 event->callback = handle_unsol_event;
Takashi Iwai3a938972011-10-28 01:16:55 +02004629 snd_hda_jack_detect_enable(codec, nid, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004630 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004631}
4632
Takashi Iwaib4ead012012-01-23 18:23:36 +01004633static int is_nid_out_jack_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004634{
4635 int i;
4636 for (i = 0; i < cfg->hp_outs; i++)
4637 if (cfg->hp_pins[i] == nid)
4638 return 1; /* nid is a HP-Out */
Takashi Iwaib4ead012012-01-23 18:23:36 +01004639 for (i = 0; i < cfg->line_outs; i++)
4640 if (cfg->line_out_pins[i] == nid)
4641 return 1; /* nid is a line-Out */
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004642 return 0; /* nid is not a HP-Out */
4643};
4644
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004645static void stac92xx_power_down(struct hda_codec *codec)
4646{
4647 struct sigmatel_spec *spec = codec->spec;
4648
4649 /* power down inactive DACs */
Takashi Iwai2b635362011-05-02 12:33:43 +02004650 const hda_nid_t *dac;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004651 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004652 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004653 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004654 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4655}
4656
Takashi Iwaif73d3582008-11-25 08:21:51 +01004657static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4658 int enable);
4659
Takashi Iwaibc759722013-01-11 17:40:31 +01004660static inline bool get_int_hint(struct hda_codec *codec, const char *key,
4661 int *valp)
Takashi Iwai014c41f2009-12-27 13:53:24 +01004662{
Takashi Iwaibc759722013-01-11 17:40:31 +01004663 return !snd_hda_get_int_hint(codec, key, valp);
Takashi Iwai014c41f2009-12-27 13:53:24 +01004664}
4665
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004666/* override some hints from the hwdep entry */
4667static void stac_store_hints(struct hda_codec *codec)
4668{
4669 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004670 int val;
4671
4672 val = snd_hda_get_bool_hint(codec, "hp_detect");
4673 if (val >= 0)
4674 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004675 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004676 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4677 spec->gpio_mask;
4678 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004679 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4680 spec->gpio_mask &= spec->gpio_mask;
4681 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4682 spec->gpio_dir &= spec->gpio_mask;
4683 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4684 spec->eapd_mask &= spec->gpio_mask;
4685 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4686 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004687 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4688 if (val >= 0)
4689 spec->eapd_switch = val;
4690}
4691
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004692static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins,
4693 const hda_nid_t *pins)
4694{
4695 while (num_pins--)
4696 stac_issue_unsol_event(codec, *pins++);
4697}
4698
4699/* fake event to set up pins */
4700static void stac_fake_hp_events(struct hda_codec *codec)
4701{
4702 struct sigmatel_spec *spec = codec->spec;
4703
4704 if (spec->autocfg.hp_outs)
4705 stac_issue_unsol_events(codec, spec->autocfg.hp_outs,
4706 spec->autocfg.hp_pins);
4707 if (spec->autocfg.line_outs &&
4708 spec->autocfg.line_out_pins[0] != spec->autocfg.hp_pins[0])
4709 stac_issue_unsol_events(codec, spec->autocfg.line_outs,
4710 spec->autocfg.line_out_pins);
4711}
4712
Mattc7d4b2f2005-06-27 14:59:41 +02004713static int stac92xx_init(struct hda_codec *codec)
4714{
4715 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004716 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004717 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004718 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004719
David Henningsson5e68fb32012-08-16 14:11:09 +02004720 if (spec->init)
4721 snd_hda_sequence_write(codec, spec->init);
Mattc7d4b2f2005-06-27 14:59:41 +02004722
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01004723 snd_hda_apply_verbs(codec);
4724
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004725 /* power down adcs initially */
4726 if (spec->powerdown_adcs)
4727 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004728 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004729 spec->adc_nids[i], 0,
4730 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004731
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004732 /* override some hints */
4733 stac_store_hints(codec);
4734
Takashi Iwaif73d3582008-11-25 08:21:51 +01004735 /* set up GPIO */
4736 gpio = spec->gpio_data;
4737 /* turn on EAPD statically when spec->eapd_switch isn't set.
4738 * otherwise, unsol event will turn it on/off dynamically
4739 */
4740 if (!spec->eapd_switch)
4741 gpio |= spec->eapd_mask;
4742 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4743
Takashi Iwai82bc9552006-03-21 11:24:42 +01004744 /* set up pins */
4745 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004746 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004747 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004748 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004749 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004750 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004751 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4752 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004753 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004754 for (i = 0; i < cfg->line_outs; i++) {
4755 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004756 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4757 }
4758 }
4759
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004760 /* force to enable the first line-out; the others are set up
4761 * in unsol_event
4762 */
4763 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004764 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004765 /* fake event to set up pins */
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004766 stac_fake_hp_events(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004767 } else {
4768 stac92xx_auto_init_multi_out(codec);
4769 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004770 for (i = 0; i < cfg->hp_outs; i++)
4771 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004772 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004773 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004774 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004775 if (spec->dmux_nids)
4776 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004777 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004778 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4779 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004780 if (enable_pin_detect(codec, spec->dock_mic.pin,
4781 STAC_MIC_EVENT))
4782 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004783 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004784 for (i = 0; i < cfg->num_inputs; i++) {
4785 hda_nid_t nid = cfg->inputs[i].pin;
4786 int type = cfg->inputs[i].type;
4787 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004788 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004789 /* for mic pins, force to initialize */
Takashi Iwai47408602012-04-20 13:06:53 +02004790 pinctl = snd_hda_get_default_vref(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004791 pinctl |= AC_PINCTL_IN_EN;
4792 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4793 } else {
4794 pinctl = snd_hda_codec_read(codec, nid, 0,
4795 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4796 /* if PINCTL already set then skip */
4797 /* Also, if both INPUT and OUTPUT are set,
4798 * it must be a BIOS bug; need to override, too
4799 */
4800 if (!(pinctl & AC_PINCTL_IN_EN) ||
4801 (pinctl & AC_PINCTL_OUT_EN)) {
4802 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004803 pinctl |= AC_PINCTL_IN_EN;
4804 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004805 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004806 }
4807 conf = snd_hda_codec_get_pincfg(codec, nid);
4808 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4809 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4810 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004811 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004812 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004813 for (i = 0; i < spec->num_dmics; i++)
4814 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4815 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004816 if (cfg->dig_out_pins[0])
4817 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004818 AC_PINCTL_OUT_EN);
4819 if (cfg->dig_in_pin)
4820 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4821 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004822 for (i = 0; i < spec->num_pwrs; i++) {
4823 hda_nid_t nid = spec->pwr_nids[i];
Takashi Iwai6e1c39c2012-06-26 17:35:10 +02004824 unsigned int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004825
Takashi Iwaibfc89de2012-05-15 09:02:26 +02004826 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4827 def_conf = get_defcfg_connect(def_conf);
4828 if (def_conf == AC_JACK_PORT_NONE) {
4829 /* power off unused ports */
4830 stac_toggle_power_map(codec, nid, 0);
4831 continue;
4832 }
Takashi Iwai6e1c39c2012-06-26 17:35:10 +02004833 if (def_conf == AC_JACK_PORT_FIXED) {
4834 /* no need for jack detection for fixed pins */
4835 stac_toggle_power_map(codec, nid, 1);
4836 continue;
4837 }
Takashi Iwaieb632122008-12-19 16:39:48 +01004838 /* power on when no jack detection is available */
Takashi Iwai542c9a02011-11-29 13:01:30 +01004839 /* or when the VREF is used for controlling LED */
4840 if (!spec->hp_detect ||
Takashi Iwaibfc89de2012-05-15 09:02:26 +02004841 spec->vref_mute_led_nid == nid ||
4842 !is_jack_detectable(codec, nid)) {
Takashi Iwaieb632122008-12-19 16:39:48 +01004843 stac_toggle_power_map(codec, nid, 1);
4844 continue;
4845 }
4846
Takashi Iwaib4ead012012-01-23 18:23:36 +01004847 if (is_nid_out_jack_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004848 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004849
Takashi Iwaif73d3582008-11-25 08:21:51 +01004850 pinctl = snd_hda_codec_read(codec, nid, 0,
4851 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4852 /* outputs are only ports capable of power management
4853 * any attempts on powering down a input port cause the
4854 * referenced VREF to act quirky.
4855 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004856 if (pinctl & AC_PINCTL_IN_EN) {
4857 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004858 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004859 }
Charles Chinafef2cf2011-11-11 08:05:28 +01004860 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004861 stac_issue_unsol_event(codec, nid);
Charles Chinafef2cf2011-11-11 08:05:28 +01004862 continue;
4863 }
4864 /* none of the above, turn the port OFF */
4865 stac_toggle_power_map(codec, nid, 0);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004866 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004867
Takashi Iwaic21bd022010-02-08 15:16:08 +01004868 /* sync mute LED */
Takashi Iwai1f43f6c2012-07-31 10:40:05 +02004869 if (spec->gpio_led) {
4870 if (spec->vmaster_mute.hook)
4871 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4872 else /* the very first init call doesn't have vmaster yet */
4873 stac92xx_update_led_status(codec, false);
4874 }
Takashi Iwaic8822462012-05-15 09:11:36 +02004875
4876 /* sync the power-map */
4877 if (spec->num_pwrs)
4878 snd_hda_codec_write(codec, codec->afg, 0,
4879 AC_VERB_IDT_SET_POWER_MAP,
4880 spec->power_map_bits);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004881 if (spec->dac_list)
4882 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004883 return 0;
4884}
4885
Takashi Iwai603c4012008-07-30 15:01:44 +02004886static void stac92xx_free_kctls(struct hda_codec *codec)
4887{
4888 struct sigmatel_spec *spec = codec->spec;
4889
4890 if (spec->kctls.list) {
4891 struct snd_kcontrol_new *kctl = spec->kctls.list;
4892 int i;
4893 for (i = 0; i < spec->kctls.used; i++)
4894 kfree(kctl[i].name);
4895 }
4896 snd_array_free(&spec->kctls);
4897}
4898
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004899static void stac92xx_shutup_pins(struct hda_codec *codec)
4900{
4901 unsigned int i, def_conf;
4902
4903 if (codec->bus->shutdown)
4904 return;
4905 for (i = 0; i < codec->init_pins.used; i++) {
4906 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4907 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4908 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004909 snd_hda_set_pin_ctl(codec, pin->nid, 0);
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004910 }
4911}
4912
Takashi Iwai167eae52009-11-06 15:47:50 +01004913static void stac92xx_shutup(struct hda_codec *codec)
4914{
4915 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004916
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004917 stac92xx_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004918
4919 if (spec->eapd_mask)
4920 stac_gpio_set(codec, spec->gpio_mask,
4921 spec->gpio_dir, spec->gpio_data &
4922 ~spec->eapd_mask);
4923}
4924
Matt2f2f4252005-04-13 14:45:30 +02004925static void stac92xx_free(struct hda_codec *codec)
4926{
Mattc7d4b2f2005-06-27 14:59:41 +02004927 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004928
4929 if (! spec)
4930 return;
4931
Mattc7d4b2f2005-06-27 14:59:41 +02004932 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004933 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004934}
4935
Matt4e550962005-07-04 17:51:39 +02004936static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4937 unsigned int flag)
4938{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004939 unsigned int old_ctl, pin_ctl;
4940
4941 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004942 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004943
Takashi Iwaif9acba42007-05-29 18:01:06 +02004944 if (pin_ctl & AC_PINCTL_IN_EN) {
4945 /*
4946 * we need to check the current set-up direction of
4947 * shared input pins since they can be switched via
4948 * "xxx as Output" mixer switch
4949 */
4950 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004951 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004952 return;
4953 }
4954
Takashi Iwai8ce84192009-01-22 16:59:20 +01004955 old_ctl = pin_ctl;
Steve Longerbeam7b0438992007-05-03 20:50:03 +02004956 /* if setting pin direction bits, clear the current
4957 direction bits first */
4958 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4959 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4960
Takashi Iwai8ce84192009-01-22 16:59:20 +01004961 pin_ctl |= flag;
4962 if (old_ctl != pin_ctl)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004963 snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004964}
4965
4966static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4967 unsigned int flag)
4968{
4969 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4970 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004971 if (pin_ctl & flag)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004972 snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004973}
4974
Takashi Iwaid56757a2009-11-18 08:00:14 +01004975static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004976{
4977 if (!nid)
4978 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004979 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004980}
4981
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004982static void stac92xx_line_out_detect(struct hda_codec *codec,
4983 int presence)
4984{
4985 struct sigmatel_spec *spec = codec->spec;
4986 struct auto_pin_cfg *cfg = &spec->autocfg;
4987 int i;
4988
David Henningsson042b92c2012-08-22 16:10:43 +02004989 if (cfg->speaker_outs == 0)
4990 return;
4991
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004992 for (i = 0; i < cfg->line_outs; i++) {
4993 if (presence)
4994 break;
4995 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4996 if (presence) {
4997 unsigned int pinctl;
4998 pinctl = snd_hda_codec_read(codec,
4999 cfg->line_out_pins[i], 0,
5000 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5001 if (pinctl & AC_PINCTL_IN_EN)
5002 presence = 0; /* mic- or line-input */
5003 }
5004 }
5005
5006 if (presence) {
5007 /* disable speakers */
5008 for (i = 0; i < cfg->speaker_outs; i++)
5009 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
5010 AC_PINCTL_OUT_EN);
5011 if (spec->eapd_mask && spec->eapd_switch)
5012 stac_gpio_set(codec, spec->gpio_mask,
5013 spec->gpio_dir, spec->gpio_data &
5014 ~spec->eapd_mask);
5015 } else {
5016 /* enable speakers */
5017 for (i = 0; i < cfg->speaker_outs; i++)
5018 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
5019 AC_PINCTL_OUT_EN);
5020 if (spec->eapd_mask && spec->eapd_switch)
5021 stac_gpio_set(codec, spec->gpio_mask,
5022 spec->gpio_dir, spec->gpio_data |
5023 spec->eapd_mask);
5024 }
5025}
5026
Takashi Iwaid7a89432008-11-12 09:48:04 +01005027/* return non-zero if the hp-pin of the given array index isn't
5028 * a jack-detection target
5029 */
5030static int no_hp_sensing(struct sigmatel_spec *spec, int i)
5031{
5032 struct auto_pin_cfg *cfg = &spec->autocfg;
5033
5034 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005035 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01005036 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005037 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01005038 return 1;
5039 /* ignore if the pin is set as line-out */
5040 if (cfg->hp_pins[i] == spec->hp_switch)
5041 return 1;
5042 return 0;
5043}
5044
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005045static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02005046{
5047 struct sigmatel_spec *spec = codec->spec;
5048 struct auto_pin_cfg *cfg = &spec->autocfg;
5049 int i, presence;
5050
Takashi Iwaieb06ed82006-09-20 17:10:27 +02005051 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005052 if (spec->gpio_mute)
5053 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
5054 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
5055
Takashi Iwaieb06ed82006-09-20 17:10:27 +02005056 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02005057 if (presence)
5058 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01005059 if (no_hp_sensing(spec, i))
5060 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01005061 presence = get_pin_presence(codec, cfg->hp_pins[i]);
5062 if (presence) {
5063 unsigned int pinctl;
5064 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
5065 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5066 if (pinctl & AC_PINCTL_IN_EN)
5067 presence = 0; /* mic- or line-input */
5068 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02005069 }
Matt4e550962005-07-04 17:51:39 +02005070
5071 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01005072 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02005073 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01005074 stac92xx_reset_pinctl(codec, spec->hp_switch,
5075 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02005076 for (i = 0; i < cfg->line_outs; i++)
5077 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
5078 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02005079 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01005080 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02005081 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01005082 stac92xx_set_pinctl(codec, spec->hp_switch,
5083 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02005084 for (i = 0; i < cfg->line_outs; i++)
5085 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
5086 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02005087 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02005088 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01005089 /* toggle hp outs */
5090 for (i = 0; i < cfg->hp_outs; i++) {
5091 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
5092 if (no_hp_sensing(spec, i))
5093 continue;
Takashi Iwai7bff1722012-02-29 09:41:17 +01005094 if (1 /*presence*/)
Takashi Iwaid7a89432008-11-12 09:48:04 +01005095 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01005096#if 0 /* FIXME */
5097/* Resetting the pinctl like below may lead to (a sort of) regressions
5098 * on some devices since they use the HP pin actually for line/speaker
5099 * outs although the default pin config shows a different pin (that is
5100 * wrong and useless).
5101 *
5102 * So, it's basically a problem of default pin configs, likely a BIOS issue.
5103 * But, disabling the code below just works around it, and I'm too tired of
5104 * bug reports with such devices...
5105 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01005106 else
5107 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01005108#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01005109 }
Matt4e550962005-07-04 17:51:39 +02005110}
5111
Takashi Iwaif73d3582008-11-25 08:21:51 +01005112static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
5113 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005114{
5115 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01005116 unsigned int idx, val;
5117
5118 for (idx = 0; idx < spec->num_pwrs; idx++) {
5119 if (spec->pwr_nids[idx] == nid)
5120 break;
5121 }
5122 if (idx >= spec->num_pwrs)
5123 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005124
Charles Chinafef2cf2011-11-11 08:05:28 +01005125 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005126
Takashi Iwaic8822462012-05-15 09:11:36 +02005127 val = spec->power_map_bits;
Takashi Iwaif73d3582008-11-25 08:21:51 +01005128 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005129 val &= ~idx;
5130 else
5131 val |= idx;
5132
5133 /* power down unused output ports */
Takashi Iwaic8822462012-05-15 09:11:36 +02005134 if (val != spec->power_map_bits) {
5135 spec->power_map_bits = val;
5136 snd_hda_codec_write(codec, codec->afg, 0,
5137 AC_VERB_IDT_SET_POWER_MAP, val);
5138 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005139}
5140
Takashi Iwaif73d3582008-11-25 08:21:51 +01005141static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
5142{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01005143 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01005144}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005145
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005146/* get the pin connection (fixed, none, etc) */
5147static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5148{
5149 struct sigmatel_spec *spec = codec->spec;
5150 unsigned int cfg;
5151
5152 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5153 return get_defcfg_connect(cfg);
5154}
5155
5156static int stac92xx_connected_ports(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02005157 const hda_nid_t *nids, int num_nids)
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005158{
5159 struct sigmatel_spec *spec = codec->spec;
5160 int idx, num;
5161 unsigned int def_conf;
5162
5163 for (num = 0; num < num_nids; num++) {
5164 for (idx = 0; idx < spec->num_pins; idx++)
5165 if (spec->pin_nids[idx] == nids[num])
5166 break;
5167 if (idx >= spec->num_pins)
5168 break;
5169 def_conf = stac_get_defcfg_connect(codec, idx);
5170 if (def_conf == AC_JACK_PORT_NONE)
5171 break;
5172 }
5173 return num;
5174}
5175
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005176static void stac92xx_mic_detect(struct hda_codec *codec)
5177{
5178 struct sigmatel_spec *spec = codec->spec;
5179 struct sigmatel_mic_route *mic;
5180
5181 if (get_pin_presence(codec, spec->ext_mic.pin))
5182 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02005183 else if (get_pin_presence(codec, spec->dock_mic.pin))
5184 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005185 else
5186 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02005187 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005188 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
5189 AC_VERB_SET_CONNECT_SEL,
5190 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02005191 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005192 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
5193 AC_VERB_SET_CONNECT_SEL,
5194 mic->mux_idx);
5195}
5196
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005197static void handle_unsol_event(struct hda_codec *codec,
Takashi Iwai3a938972011-10-28 01:16:55 +02005198 struct hda_jack_tbl *event)
Takashi Iwai314634b2006-09-21 11:56:18 +02005199{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005200 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005201 int data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005202
Takashi Iwai3a938972011-10-28 01:16:55 +02005203 switch (event->action) {
Takashi Iwai314634b2006-09-21 11:56:18 +02005204 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02005205 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02005206 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02005207 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005208 case STAC_MIC_EVENT:
5209 stac92xx_mic_detect(codec);
5210 break;
5211 }
5212
Takashi Iwai3a938972011-10-28 01:16:55 +02005213 switch (event->action) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005214 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02005215 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005216 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005217 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005218 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005219 if (spec->num_pwrs > 0)
5220 stac92xx_pin_sense(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04005221
5222 switch (codec->subsystem_id) {
5223 case 0x103c308f:
5224 if (event->nid == 0xb) {
5225 int pin = AC_PINCTL_IN_EN;
5226
5227 if (get_pin_presence(codec, 0xa)
5228 && get_pin_presence(codec, 0xb))
5229 pin |= AC_PINCTL_VREF_80;
5230 if (!get_pin_presence(codec, 0xb))
5231 pin |= AC_PINCTL_VREF_80;
5232
5233 /* toggle VREF state based on mic + hp pin
5234 * status
5235 */
5236 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
5237 }
5238 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04005239 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005240 case STAC_VREF_EVENT:
5241 data = snd_hda_codec_read(codec, codec->afg, 0,
5242 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005243 /* toggle VREF state based on GPIOx status */
5244 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwai3a938972011-10-28 01:16:55 +02005245 !!(data & (1 << event->private_data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04005246 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02005247 }
5248}
5249
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005250static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
5251{
Takashi Iwai3a938972011-10-28 01:16:55 +02005252 struct hda_jack_tbl *event = snd_hda_jack_tbl_get(codec, nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005253 if (!event)
5254 return;
5255 handle_unsol_event(codec, event);
5256}
5257
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305258static int hp_blike_system(u32 subsystem_id);
5259
5260static void set_hp_led_gpio(struct hda_codec *codec)
5261{
5262 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01005263 unsigned int gpio;
5264
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005265 if (spec->gpio_led)
5266 return;
5267
Takashi Iwai07f80442010-02-08 15:06:13 +01005268 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
5269 gpio &= AC_GPIO_IO_COUNT;
5270 if (gpio > 3)
5271 spec->gpio_led = 0x08; /* GPIO 3 */
5272 else
5273 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305274}
5275
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005276/*
5277 * This method searches for the mute LED GPIO configuration
5278 * provided as OEM string in SMBIOS. The format of that string
5279 * is HP_Mute_LED_P_G or HP_Mute_LED_P
5280 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
5281 * that corresponds to the NOT muted state of the master volume
5282 * and G is the index of the GPIO to use as the mute LED control (0..9)
5283 * If _G portion is missing it is assigned based on the codec ID
5284 *
5285 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
5286 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305287 *
5288 *
5289 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
5290 * SMBIOS - at least the ones I have seen do not have them - which include
5291 * my own system (HP Pavilion dv6-1110ax) and my cousin's
5292 * HP Pavilion dv9500t CTO.
5293 * Need more information on whether it is true across the entire series.
5294 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005295 */
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005296static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005297{
5298 struct sigmatel_spec *spec = codec->spec;
5299 const struct dmi_device *dev = NULL;
5300
Takashi Iwai75609312012-05-14 16:52:00 +02005301 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
5302 get_int_hint(codec, "gpio_led_polarity",
5303 &spec->gpio_led_polarity);
5304 return 1;
5305 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005306 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
5307 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
5308 NULL, dev))) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005309 if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305310 &spec->gpio_led_polarity,
5311 &spec->gpio_led) == 2) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005312 unsigned int max_gpio;
5313 max_gpio = snd_hda_param_read(codec, codec->afg,
5314 AC_PAR_GPIO_CAP);
5315 max_gpio &= AC_GPIO_IO_COUNT;
5316 if (spec->gpio_led < max_gpio)
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005317 spec->gpio_led = 1 << spec->gpio_led;
Takashi Iwaif1a73742011-12-04 13:44:06 +01005318 else
5319 spec->vref_mute_led_nid = spec->gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005320 return 1;
5321 }
5322 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305323 &spec->gpio_led_polarity) == 1) {
5324 set_hp_led_gpio(codec);
5325 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005326 }
Gustavo Maciel Dias Vieirae2ef36c2011-12-13 11:47:22 -02005327 /* BIOS bug: unfilled OEM string */
5328 if (strstr(dev->name, "HP_Mute_LED_P_G")) {
5329 set_hp_led_gpio(codec);
Gustavo Maciel Dias Vieiraa6a600d2012-01-24 13:27:56 -02005330 switch (codec->subsystem_id) {
5331 case 0x103c148a:
5332 spec->gpio_led_polarity = 0;
5333 break;
5334 default:
5335 spec->gpio_led_polarity = 1;
5336 break;
5337 }
Gustavo Maciel Dias Vieirae2ef36c2011-12-13 11:47:22 -02005338 return 1;
5339 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005340 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305341
5342 /*
5343 * Fallback case - if we don't find the DMI strings,
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005344 * we statically set the GPIO - if not a B-series system
5345 * and default polarity is provided
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305346 */
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005347 if (!hp_blike_system(codec->subsystem_id) &&
5348 (default_polarity == 0 || default_polarity == 1)) {
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305349 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01005350 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305351 return 1;
5352 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005353 }
5354 return 0;
5355}
5356
5357static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08005358{
5359 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005360 case 0x103c1520:
5361 case 0x103c1521:
5362 case 0x103c1523:
5363 case 0x103c1524:
5364 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08005365 case 0x103c1722:
5366 case 0x103c1723:
5367 case 0x103c1724:
5368 case 0x103c1725:
5369 case 0x103c1726:
5370 case 0x103c1727:
5371 case 0x103c1728:
5372 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005373 case 0x103c172a:
5374 case 0x103c172b:
5375 case 0x103c307e:
5376 case 0x103c307f:
5377 case 0x103c3080:
5378 case 0x103c3081:
5379 case 0x103c7007:
5380 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08005381 return 1;
5382 }
5383 return 0;
5384}
5385
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005386#ifdef CONFIG_PROC_FS
5387static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
5388 struct hda_codec *codec, hda_nid_t nid)
5389{
5390 if (nid == codec->afg)
5391 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
Takashi Iwaic8822462012-05-15 09:11:36 +02005392 snd_hda_codec_read(codec, nid, 0,
5393 AC_VERB_IDT_GET_POWER_MAP, 0));
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005394}
5395
5396static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
5397 struct hda_codec *codec,
5398 unsigned int verb)
5399{
5400 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
5401 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
5402}
5403
5404/* stac92hd71bxx, stac92hd73xx */
5405static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
5406 struct hda_codec *codec, hda_nid_t nid)
5407{
5408 stac92hd_proc_hook(buffer, codec, nid);
5409 if (nid == codec->afg)
5410 analog_loop_proc_hook(buffer, codec, 0xfa0);
5411}
5412
5413static void stac9205_proc_hook(struct snd_info_buffer *buffer,
5414 struct hda_codec *codec, hda_nid_t nid)
5415{
5416 if (nid == codec->afg)
5417 analog_loop_proc_hook(buffer, codec, 0xfe0);
5418}
5419
5420static void stac927x_proc_hook(struct snd_info_buffer *buffer,
5421 struct hda_codec *codec, hda_nid_t nid)
5422{
5423 if (nid == codec->afg)
5424 analog_loop_proc_hook(buffer, codec, 0xfeb);
5425}
5426#else
5427#define stac92hd_proc_hook NULL
5428#define stac92hd7x_proc_hook NULL
5429#define stac9205_proc_hook NULL
5430#define stac927x_proc_hook NULL
5431#endif
5432
Takashi Iwai2a439522011-07-26 09:52:50 +02005433#ifdef CONFIG_PM
Mattff6fdc32005-06-27 15:06:52 +02005434static int stac92xx_resume(struct hda_codec *codec)
5435{
Takashi Iwai2c885872008-11-18 09:36:55 +01005436 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02005437 snd_hda_codec_resume_amp(codec);
5438 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01005439 /* fake event to set up pins again to override cached values */
Takashi Iwaif2cbba72012-01-11 12:34:11 +01005440 stac_fake_hp_events(codec);
Mattff6fdc32005-06-27 15:06:52 +02005441 return 0;
5442}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005443
Takashi Iwai68cb2b52012-07-02 15:20:37 +02005444static int stac92xx_suspend(struct hda_codec *codec)
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005445{
5446 stac92xx_shutup(codec);
5447 return 0;
5448}
5449
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005450static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5451 unsigned int power_state)
5452{
5453 unsigned int afg_power_state = power_state;
5454 struct sigmatel_spec *spec = codec->spec;
5455
5456 if (power_state == AC_PWRST_D3) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005457 if (spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005458 /* with vref-out pin used for mute led control
5459 * codec AFG is prevented from D3 state
5460 */
5461 afg_power_state = AC_PWRST_D1;
5462 }
5463 /* this delay seems necessary to avoid click noise at power-down */
5464 msleep(100);
5465 }
5466 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5467 afg_power_state);
5468 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
5469}
Takashi Iwai350eba432012-03-16 16:09:03 +01005470#else
5471#define stac92xx_suspend NULL
5472#define stac92xx_resume NULL
Takashi Iwai350eba432012-03-16 16:09:03 +01005473#define stac92xx_set_power_state NULL
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005474#endif /* CONFIG_PM */
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005475
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005476/* update mute-LED accoring to the master switch */
5477static void stac92xx_update_led_status(struct hda_codec *codec, int enabled)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005478{
5479 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005480 int muted = !enabled;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005481
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005482 if (!spec->gpio_led)
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005483 return;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005484
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005485 /* LED state is inverted on these systems */
5486 if (spec->gpio_led_polarity)
5487 muted = !muted;
5488
Takashi Iwaif1a73742011-12-04 13:44:06 +01005489 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005490 if (muted)
Takashi Iwai3e843192012-04-19 12:04:03 +02005491 spec->gpio_data |= spec->gpio_led;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005492 else
Takashi Iwai3e843192012-04-19 12:04:03 +02005493 spec->gpio_data &= ~spec->gpio_led;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005494 stac_gpio_set(codec, spec->gpio_mask,
5495 spec->gpio_dir, spec->gpio_data);
5496 } else {
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005497 spec->vref_led = muted ? AC_PINCTL_VREF_50 : AC_PINCTL_VREF_GRD;
Takashi Iwaif1a73742011-12-04 13:44:06 +01005498 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5499 spec->vref_led);
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005500 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005501}
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005502
Takashi Iwai2b635362011-05-02 12:33:43 +02005503static const struct hda_codec_ops stac92xx_patch_ops = {
Matt2f2f4252005-04-13 14:45:30 +02005504 .build_controls = stac92xx_build_controls,
5505 .build_pcms = stac92xx_build_pcms,
5506 .init = stac92xx_init,
5507 .free = stac92xx_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02005508 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02005509#ifdef CONFIG_PM
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005510 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005511 .resume = stac92xx_resume,
5512#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005513 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005514};
5515
Takashi Iwai361dab32012-05-09 14:35:27 +02005516static int alloc_stac_spec(struct hda_codec *codec, int num_pins,
5517 const hda_nid_t *pin_nids)
5518{
5519 struct sigmatel_spec *spec;
5520
5521 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5522 if (!spec)
5523 return -ENOMEM;
5524 codec->spec = spec;
5525 codec->no_trigger_sense = 1; /* seems common with STAC/IDT codecs */
5526 spec->num_pins = num_pins;
5527 spec->pin_nids = pin_nids;
5528 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
5529 return 0;
5530}
5531
Matt2f2f4252005-04-13 14:45:30 +02005532static int patch_stac9200(struct hda_codec *codec)
5533{
5534 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005535 int err;
Matt2f2f4252005-04-13 14:45:30 +02005536
Takashi Iwai361dab32012-05-09 14:35:27 +02005537 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9200_pin_nids),
5538 stac9200_pin_nids);
5539 if (err < 0)
5540 return err;
Matt2f2f4252005-04-13 14:45:30 +02005541
Takashi Iwai361dab32012-05-09 14:35:27 +02005542 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005543 spec->linear_tone_beep = 1;
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005544
5545 snd_hda_pick_fixup(codec, stac9200_models, stac9200_fixup_tbl,
5546 stac9200_fixups);
Matt2f2f4252005-04-13 14:45:30 +02005547
5548 spec->multiout.max_channels = 2;
5549 spec->multiout.num_dacs = 1;
5550 spec->multiout.dac_nids = stac9200_dac_nids;
5551 spec->adc_nids = stac9200_adc_nids;
5552 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005553 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005554 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005555 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005556 spec->num_pwrs = 0;
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005557 snd_hda_add_verbs(codec, stac9200_eapd_init);
Mattc7d4b2f2005-06-27 14:59:41 +02005558
Matt2f2f4252005-04-13 14:45:30 +02005559 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005560
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005561 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
Takashi Iwai117f2572008-03-18 09:53:23 +01005562
Mattc7d4b2f2005-06-27 14:59:41 +02005563 err = stac9200_parse_auto_config(codec);
5564 if (err < 0) {
5565 stac92xx_free(codec);
5566 return err;
5567 }
Matt2f2f4252005-04-13 14:45:30 +02005568
5569 codec->patch_ops = stac92xx_patch_ops;
5570
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005571 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5572
Matt2f2f4252005-04-13 14:45:30 +02005573 return 0;
5574}
5575
Tobin Davis8e21c342007-01-08 11:04:17 +01005576static int patch_stac925x(struct hda_codec *codec)
5577{
5578 struct sigmatel_spec *spec;
5579 int err;
5580
Takashi Iwai361dab32012-05-09 14:35:27 +02005581 err = alloc_stac_spec(codec, ARRAY_SIZE(stac925x_pin_nids),
5582 stac925x_pin_nids);
5583 if (err < 0)
5584 return err;
Tobin Davis8e21c342007-01-08 11:04:17 +01005585
Takashi Iwai361dab32012-05-09 14:35:27 +02005586 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005587 spec->linear_tone_beep = 1;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005588
Takashi Iwaid2077d42013-01-14 14:20:16 +01005589 snd_hda_pick_fixup(codec, stac925x_models, stac925x_fixup_tbl,
5590 stac925x_fixups);
Tobin Davis8e21c342007-01-08 11:04:17 +01005591
5592 spec->multiout.max_channels = 2;
5593 spec->multiout.num_dacs = 1;
5594 spec->multiout.dac_nids = stac925x_dac_nids;
5595 spec->adc_nids = stac925x_adc_nids;
5596 spec->mux_nids = stac925x_mux_nids;
5597 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005598 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005599 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005600 switch (codec->vendor_id) {
5601 case 0x83847632: /* STAC9202 */
5602 case 0x83847633: /* STAC9202D */
5603 case 0x83847636: /* STAC9251 */
5604 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005605 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005606 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005607 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5608 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005609 break;
5610 default:
5611 spec->num_dmics = 0;
5612 break;
5613 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005614
Takashi Iwaid2077d42013-01-14 14:20:16 +01005615 snd_hda_add_verbs(codec, stac925x_core_init);
Tobin Davis8e21c342007-01-08 11:04:17 +01005616 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005617 spec->num_caps = 1;
5618 spec->capvols = stac925x_capvols;
5619 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005620
Takashi Iwaid2077d42013-01-14 14:20:16 +01005621 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5622
Charles Chin9009b0e2011-11-03 10:27:27 +01005623 err = stac92xx_parse_auto_config(codec);
Takashi Iwaid2077d42013-01-14 14:20:16 +01005624 if (!err)
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005625 err = -EINVAL;
Tobin Davis8e21c342007-01-08 11:04:17 +01005626 if (err < 0) {
5627 stac92xx_free(codec);
5628 return err;
5629 }
5630
5631 codec->patch_ops = stac92xx_patch_ops;
5632
Takashi Iwaid2077d42013-01-14 14:20:16 +01005633 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5634
Tobin Davis8e21c342007-01-08 11:04:17 +01005635 return 0;
5636}
5637
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005638static int patch_stac92hd73xx(struct hda_codec *codec)
5639{
5640 struct sigmatel_spec *spec;
5641 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
Takashi Iwai361dab32012-05-09 14:35:27 +02005642 int err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005643 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005644
Takashi Iwai361dab32012-05-09 14:35:27 +02005645 err = alloc_stac_spec(codec, ARRAY_SIZE(stac92hd73xx_pin_nids),
5646 stac92hd73xx_pin_nids);
5647 if (err < 0)
5648 return err;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005649
Takashi Iwai361dab32012-05-09 14:35:27 +02005650 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005651 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005652 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005653 spec->board_config = snd_hda_check_board_config(codec,
5654 STAC_92HD73XX_MODELS,
5655 stac92hd73xx_models,
5656 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005657 /* check codec subsystem id if not found */
5658 if (spec->board_config < 0)
5659 spec->board_config =
5660 snd_hda_check_board_codec_sid_config(codec,
5661 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5662 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005663again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005664 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005665 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5666 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005667 else
5668 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005669 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005670
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005671 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005672 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5673
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005674 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005675 printk(KERN_WARNING "hda_codec: Could not determine "
5676 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005677 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005678 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005679 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005680 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005681 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005682 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005683 break;
5684 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005685 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005686 break;
5687 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005688 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5689 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005690 }
5691 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005692
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005693 spec->aloopback_mask = 0x01;
5694 spec->aloopback_shift = 8;
5695
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005696 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005697 spec->mux_nids = stac92hd73xx_mux_nids;
5698 spec->adc_nids = stac92hd73xx_adc_nids;
5699 spec->dmic_nids = stac92hd73xx_dmic_nids;
5700 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005701 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005702
5703 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5704 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005705 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005706
Takashi Iwai6479c632009-07-28 18:20:25 +02005707 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5708 spec->capvols = stac92hd73xx_capvols;
5709 spec->capsws = stac92hd73xx_capsws;
5710
Matthew Ranostaya7662642008-02-21 07:51:14 +01005711 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005712 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005713 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005714 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005715 case STAC_DELL_M6_AMIC:
5716 case STAC_DELL_M6_DMIC:
5717 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005718 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005719 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005720
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005721 switch (spec->board_config) {
5722 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005723 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005724 spec->num_dmics = 0;
5725 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005726 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005727 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005728 spec->num_dmics = 1;
5729 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005730 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005731 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5732 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005733 spec->num_dmics = 1;
5734 break;
5735 }
5736 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005737 case STAC_ALIENWARE_M17X:
5738 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5739 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5740 spec->eapd_switch = 0;
5741 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005742 default:
5743 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005744 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005745 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005746 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005747 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005748 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005749 /* GPIO0 High = Enable EAPD */
5750 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5751 spec->gpio_data = 0x01;
5752 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005753
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005754 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5755 spec->pwr_nids = stac92hd73xx_pwr_nids;
5756
Charles Chin9009b0e2011-11-03 10:27:27 +01005757 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005758
5759 if (!err) {
5760 if (spec->board_config < 0) {
5761 printk(KERN_WARNING "hda_codec: No auto-config is "
5762 "available, default to model=ref\n");
5763 spec->board_config = STAC_92HD73XX_REF;
5764 goto again;
5765 }
5766 err = -EINVAL;
5767 }
5768
5769 if (err < 0) {
5770 stac92xx_free(codec);
5771 return err;
5772 }
5773
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005774 if (spec->board_config == STAC_92HD73XX_NO_JD)
5775 spec->hp_detect = 0;
5776
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005777 codec->patch_ops = stac92xx_patch_ops;
5778
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005779 codec->proc_widget_hook = stac92hd7x_proc_hook;
5780
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005781 return 0;
5782}
5783
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005784static int hp_bnb2011_with_dock(struct hda_codec *codec)
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005785{
5786 if (codec->vendor_id != 0x111d7605 &&
5787 codec->vendor_id != 0x111d76d1)
5788 return 0;
5789
5790 switch (codec->subsystem_id) {
5791 case 0x103c1618:
5792 case 0x103c1619:
5793 case 0x103c161a:
5794 case 0x103c161b:
5795 case 0x103c161c:
5796 case 0x103c161d:
5797 case 0x103c161e:
5798 case 0x103c161f:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005799
5800 case 0x103c162a:
5801 case 0x103c162b:
5802
5803 case 0x103c1630:
5804 case 0x103c1631:
5805
5806 case 0x103c1633:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005807 case 0x103c1634:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005808 case 0x103c1635:
5809
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005810 case 0x103c3587:
5811 case 0x103c3588:
5812 case 0x103c3589:
5813 case 0x103c358a:
5814
5815 case 0x103c3667:
5816 case 0x103c3668:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005817 case 0x103c3669:
5818
5819 return 1;
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005820 }
5821 return 0;
5822}
5823
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005824static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
5825{
5826 struct sigmatel_spec *spec = codec->spec;
5827 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5828 int i;
5829
5830 spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5831 spec->auto_pin_cnt++;
5832
5833 if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5834 get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5835 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5836 if (nid == stac92hd83xxx_dmic_nids[i]) {
5837 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5838 spec->auto_dmic_cnt++;
5839 }
5840 }
5841 }
5842}
5843
5844static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5845{
5846 struct sigmatel_spec *spec = codec->spec;
5847
5848 spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5849 spec->auto_adc_cnt++;
5850}
5851
5852static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5853{
5854 int i, j;
5855 struct sigmatel_spec *spec = codec->spec;
5856
5857 for (i = 0; i < spec->auto_adc_cnt; i++) {
5858 if (get_connection_index(codec,
5859 spec->auto_adc_nids[i], nid) >= 0) {
5860 /* mux and volume for adc_nids[i] */
5861 if (!spec->auto_mux_nids[i]) {
5862 spec->auto_mux_nids[i] = nid;
5863 /* 92hd codecs capture volume is in mux */
5864 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
5865 3, 0, HDA_OUTPUT);
5866 }
5867 for (j = 0; j < spec->auto_dmic_cnt; j++) {
5868 if (get_connection_index(codec, nid,
5869 spec->auto_dmic_nids[j]) >= 0) {
5870 /* dmux for adc_nids[i] */
5871 if (!spec->auto_dmux_nids[i])
5872 spec->auto_dmux_nids[i] = nid;
5873 break;
5874 }
5875 }
5876 break;
5877 }
5878 }
5879}
5880
5881static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5882{
5883 hda_nid_t nid, end_nid;
5884 unsigned int wid_caps, wid_type;
5885 struct sigmatel_spec *spec = codec->spec;
5886
5887 end_nid = codec->start_nid + codec->num_nodes;
5888
5889 for (nid = codec->start_nid; nid < end_nid; nid++) {
5890 wid_caps = get_wcaps(codec, nid);
5891 wid_type = get_wcaps_type(wid_caps);
5892
5893 if (wid_type == AC_WID_PIN)
5894 stac92hd8x_add_pin(codec, nid);
5895
5896 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5897 stac92hd8x_add_adc(codec, nid);
5898 }
5899
5900 for (nid = codec->start_nid; nid < end_nid; nid++) {
5901 wid_caps = get_wcaps(codec, nid);
5902 wid_type = get_wcaps_type(wid_caps);
5903
5904 if (wid_type == AC_WID_AUD_SEL)
5905 stac92hd8x_add_mux(codec, nid);
5906 }
5907
5908 spec->pin_nids = spec->auto_pin_nids;
5909 spec->num_pins = spec->auto_pin_cnt;
5910 spec->adc_nids = spec->auto_adc_nids;
5911 spec->num_adcs = spec->auto_adc_cnt;
5912 spec->capvols = spec->auto_capvols;
5913 spec->capsws = spec->auto_capvols;
5914 spec->num_caps = spec->auto_adc_cnt;
5915 spec->mux_nids = spec->auto_mux_nids;
5916 spec->num_muxes = spec->auto_adc_cnt;
5917 spec->dmux_nids = spec->auto_dmux_nids;
5918 spec->num_dmuxes = spec->auto_adc_cnt;
5919 spec->dmic_nids = spec->auto_dmic_nids;
5920 spec->num_dmics = spec->auto_dmic_cnt;
5921}
5922
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005923static int patch_stac92hd83xxx(struct hda_codec *codec)
5924{
5925 struct sigmatel_spec *spec;
Takashi Iwaia3e19972012-07-26 08:17:20 +02005926 int default_polarity = -1; /* no default cfg */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005927 int err;
5928
Takashi Iwai361dab32012-05-09 14:35:27 +02005929 err = alloc_stac_spec(codec, 0, NULL); /* pins filled later */
5930 if (err < 0)
5931 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005932
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005933 if (hp_bnb2011_with_dock(codec)) {
5934 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5935 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5936 }
5937
Takashi Iwaic36b5b02012-08-28 09:20:13 -07005938 codec->epss = 0; /* longer delay needed for D3 */
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005939 stac92hd8x_fill_auto_spec(codec);
5940
Takashi Iwai361dab32012-05-09 14:35:27 +02005941 spec = codec->spec;
Takashi Iwai1db7ccdb2010-12-03 15:19:14 +01005942 spec->linear_tone_beep = 0;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005943 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005944 spec->digbeep_nid = 0x21;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005945 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005946 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005947 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005948 spec->init = stac92hd83xxx_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005949
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005950 spec->board_config = snd_hda_check_board_config(codec,
5951 STAC_92HD83XXX_MODELS,
5952 stac92hd83xxx_models,
5953 stac92hd83xxx_cfg_tbl);
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06005954 /* check codec subsystem id if not found */
5955 if (spec->board_config < 0)
5956 spec->board_config =
5957 snd_hda_check_board_codec_sid_config(codec,
5958 STAC_92HD83XXX_MODELS, stac92hd83xxx_models,
5959 stac92hd83xxx_codec_id_cfg_tbl);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005960again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005961 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005962 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5963 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005964 else
5965 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005966 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005967
Takashi Iwaib4e81872009-11-18 17:20:24 +01005968 codec->patch_ops = stac92xx_patch_ops;
5969
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06005970 switch (spec->board_config) {
5971 case STAC_HP_ZEPHYR:
5972 spec->init = stac92hd83xxx_hp_zephyr_init;
5973 break;
Takashi Iwaia3e19972012-07-26 08:17:20 +02005974 case STAC_92HD83XXX_HP_LED:
Takashi Iwaiff8a1e22012-07-31 10:16:59 +02005975 default_polarity = 0;
5976 break;
5977 case STAC_92HD83XXX_HP_INV_LED:
Takashi Iwaia3e19972012-07-26 08:17:20 +02005978 default_polarity = 1;
5979 break;
Takashi Iwai62cbde12012-09-14 11:58:54 +02005980 case STAC_92HD83XXX_HP_MIC_LED:
5981 spec->mic_mute_led_gpio = 0x08; /* GPIO3 */
5982 break;
David Henningsson8d032a82012-10-09 12:48:40 +02005983 case STAC_92HD83XXX_HEADSET_JACK:
5984 spec->headset_jack = 1;
5985 break;
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06005986 }
5987
Takashi Iwaia3e19972012-07-26 08:17:20 +02005988 if (find_mute_led_cfg(codec, default_polarity))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005989 snd_printd("mute LED gpio %d polarity %d\n",
5990 spec->gpio_led,
5991 spec->gpio_led_polarity);
5992
Takashi Iwaib4e81872009-11-18 17:20:24 +01005993 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005994 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005995 spec->gpio_mask |= spec->gpio_led;
5996 spec->gpio_dir |= spec->gpio_led;
5997 spec->gpio_data |= spec->gpio_led;
5998 } else {
5999 codec->patch_ops.set_power_state =
6000 stac92xx_set_power_state;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05006001 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01006002 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01006003
Takashi Iwai62cbde12012-09-14 11:58:54 +02006004 if (spec->mic_mute_led_gpio) {
6005 spec->gpio_mask |= spec->mic_mute_led_gpio;
6006 spec->gpio_dir |= spec->mic_mute_led_gpio;
6007 spec->mic_mute_led_on = true;
6008 spec->gpio_data |= spec->mic_mute_led_gpio;
6009 }
6010
Charles Chin9009b0e2011-11-03 10:27:27 +01006011 err = stac92xx_parse_auto_config(codec);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006012 if (!err) {
6013 if (spec->board_config < 0) {
6014 printk(KERN_WARNING "hda_codec: No auto-config is "
6015 "available, default to model=ref\n");
6016 spec->board_config = STAC_92HD83XXX_REF;
6017 goto again;
6018 }
6019 err = -EINVAL;
6020 }
6021
6022 if (err < 0) {
6023 stac92xx_free(codec);
6024 return err;
6025 }
6026
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006027 codec->proc_widget_hook = stac92hd_proc_hook;
6028
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006029 return 0;
6030}
6031
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006032static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
6033 hda_nid_t dig0pin)
6034{
6035 struct sigmatel_spec *spec = codec->spec;
6036 int idx;
6037
6038 for (idx = 0; idx < spec->num_pins; idx++)
6039 if (spec->pin_nids[idx] == dig0pin)
6040 break;
6041 if ((idx + 2) >= spec->num_pins)
6042 return 0;
6043
6044 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01006045 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006046 return 2;
6047
6048 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01006049 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006050 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01006051 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006052 return 1;
6053 else
6054 return 0;
6055}
6056
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006057/* HP dv7 bass switch - GPIO5 */
6058#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
6059static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
6060 struct snd_ctl_elem_value *ucontrol)
6061{
6062 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6063 struct sigmatel_spec *spec = codec->spec;
6064 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
6065 return 0;
6066}
6067
6068static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
6069 struct snd_ctl_elem_value *ucontrol)
6070{
6071 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6072 struct sigmatel_spec *spec = codec->spec;
6073 unsigned int gpio_data;
6074
6075 gpio_data = (spec->gpio_data & ~0x20) |
6076 (ucontrol->value.integer.value[0] ? 0x20 : 0);
6077 if (gpio_data == spec->gpio_data)
6078 return 0;
6079 spec->gpio_data = gpio_data;
6080 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
6081 return 1;
6082}
6083
Takashi Iwai2b635362011-05-02 12:33:43 +02006084static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006085 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6086 .info = stac_hp_bass_gpio_info,
6087 .get = stac_hp_bass_gpio_get,
6088 .put = stac_hp_bass_gpio_put,
6089};
6090
6091static int stac_add_hp_bass_switch(struct hda_codec *codec)
6092{
6093 struct sigmatel_spec *spec = codec->spec;
6094
6095 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
6096 "Bass Speaker Playback Switch", 0))
6097 return -ENOMEM;
6098
6099 spec->gpio_mask |= 0x20;
6100 spec->gpio_dir |= 0x20;
6101 spec->gpio_data |= 0x20;
6102 return 0;
6103}
6104
Matthew Ranostaye035b842007-11-06 11:53:55 +01006105static int patch_stac92hd71bxx(struct hda_codec *codec)
6106{
6107 struct sigmatel_spec *spec;
Takashi Iwai2b635362011-05-02 12:33:43 +02006108 const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01006109 unsigned int pin_cfg;
Takashi Iwai361dab32012-05-09 14:35:27 +02006110 int err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006111
Takashi Iwai361dab32012-05-09 14:35:27 +02006112 err = alloc_stac_spec(codec, STAC92HD71BXX_NUM_PINS,
6113 stac92hd71bxx_pin_nids_4port);
6114 if (err < 0)
6115 return err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006116
Takashi Iwai361dab32012-05-09 14:35:27 +02006117 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006118 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006119 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05006120 switch (codec->vendor_id) {
6121 case 0x111d76b6:
6122 case 0x111d76b7:
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05006123 break;
6124 case 0x111d7603:
6125 case 0x111d7608:
6126 /* On 92HD75Bx 0x27 isn't a pin nid */
6127 spec->num_pins--;
6128 /* fallthrough */
6129 default:
6130 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
6131 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006132 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006133 spec->board_config = snd_hda_check_board_config(codec,
6134 STAC_92HD71BXX_MODELS,
6135 stac92hd71bxx_models,
6136 stac92hd71bxx_cfg_tbl);
6137again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006138 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006139 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6140 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006141 else
6142 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006143 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006144
Takashi Iwaifc64b262009-09-14 15:33:01 +02006145 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01006146 /* GPIO0 = EAPD */
6147 spec->gpio_mask = 0x01;
6148 spec->gpio_dir = 0x01;
6149 spec->gpio_data = 0x01;
6150 }
6151
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006152 spec->dmic_nids = stac92hd71bxx_dmic_nids;
6153 spec->dmux_nids = stac92hd71bxx_dmux_nids;
6154
Takashi Iwai6479c632009-07-28 18:20:25 +02006155 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
6156 spec->capvols = stac92hd71bxx_capvols;
6157 spec->capsws = stac92hd71bxx_capsws;
6158
Matthew Ranostay541eee82007-12-14 12:08:04 +01006159 switch (codec->vendor_id) {
6160 case 0x111d76b6: /* 4 Port without Analog Mixer */
6161 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02006162 unmute_init++;
6163 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01006164 case 0x111d76b4: /* 6 Port without Analog Mixer */
6165 case 0x111d76b5:
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04006166 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006167 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006168 stac92hd71bxx_dmic_nids,
6169 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01006170 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006171 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01006172 switch (spec->board_config) {
6173 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04006174 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwai3a938972011-10-28 01:16:55 +02006175 err = stac_add_event(codec, codec->afg,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006176 STAC_VREF_EVENT, 0x02);
6177 if (err < 0)
6178 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006179 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04006180 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
Takashi Iwai3a938972011-10-28 01:16:55 +02006181 snd_hda_jack_detect_enable(codec, codec->afg, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04006182 spec->gpio_mask |= 0x02;
6183 break;
6184 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006185 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01006186 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006187 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006188
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006189 /* disable VSW */
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05006190 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01006191 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
6192 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Takashi Iwai2b635362011-05-02 12:33:43 +02006193 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006194 spec->num_dmics = stac92xx_connected_ports(codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02006195 stac92hd71bxx_dmic_5port_nids,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006196 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006197 break;
6198 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01006199 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006200 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006201
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006202 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01006203 default:
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04006204 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006205 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006206 stac92hd71bxx_dmic_nids,
6207 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02006208 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01006209 }
6210
David Henningsson5e68fb32012-08-16 14:11:09 +02006211 if (get_wcaps_type(get_wcaps(codec, 0x28)) == AC_WID_VOL_KNB)
6212 spec->init = stac92hd71bxx_core_init;
6213
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05006214 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
6215 snd_hda_sequence_write_cache(codec, unmute_init);
6216
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006217 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04006218 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01006219 spec->aloopback_shift = 0;
6220
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006221 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006222 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006223 spec->mux_nids = stac92hd71bxx_mux_nids;
6224 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02006225 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006226 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006227
6228 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
6229 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02006230 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006231 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006232
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05306233 snd_printdd("Found board config: %d\n", spec->board_config);
6234
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006235 switch (spec->board_config) {
6236 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006237 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01006238 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04006239 stac92xx_auto_set_pinctl(codec, 0x0e,
6240 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05006241 /* fallthru */
6242 case STAC_DELL_M4_2:
6243 spec->num_dmics = 0;
6244 spec->num_smuxes = 0;
6245 spec->num_dmuxes = 0;
6246 break;
6247 case STAC_DELL_M4_1:
6248 case STAC_DELL_M4_3:
6249 spec->num_dmics = 1;
6250 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01006251 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006252 break;
James Gardiner514bf542009-05-03 04:00:44 -04006253 case STAC_HP_DV4_1222NR:
6254 spec->num_dmics = 1;
6255 /* I don't know if it needs 1 or 2 smuxes - will wait for
6256 * bug reports to fix if needed
6257 */
6258 spec->num_smuxes = 1;
6259 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04006260 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02006261 case STAC_HP_DV4:
6262 spec->gpio_led = 0x01;
6263 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01006264 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01006265 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01006266 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02006267 /* HP dv6 gives the headphone pin as a line-out. Thus we
6268 * need to set hp_detect flag here to force to enable HP
6269 * detection.
6270 */
6271 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01006272 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01006273 case STAC_HP_HDX:
6274 spec->num_dmics = 1;
6275 spec->num_dmuxes = 1;
6276 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02006277 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006278 break;
6279 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01006280
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01006281 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01006282 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
6283 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
6284 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
6285 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
6286 /* It was changed in the BIOS to just satisfy MS DTM.
6287 * Lets turn it back into slaved HP
6288 */
6289 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
6290 | (AC_JACK_HP_OUT <<
6291 AC_DEFCFG_DEVICE_SHIFT);
6292 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
6293 | AC_DEFCFG_SEQUENCE)))
6294 | 0x1f;
6295 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
6296 }
6297 }
6298
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06006299 if (find_mute_led_cfg(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01006300 snd_printd("mute LED gpio %d polarity %d\n",
6301 spec->gpio_led,
6302 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01006303
Takashi Iwai86d190e2009-05-26 15:18:58 +02006304 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01006305 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05006306 spec->gpio_mask |= spec->gpio_led;
6307 spec->gpio_dir |= spec->gpio_led;
6308 spec->gpio_data |= spec->gpio_led;
6309 } else {
6310 codec->patch_ops.set_power_state =
6311 stac92xx_set_power_state;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05006312 }
Takashi Iwai86d190e2009-05-26 15:18:58 +02006313 }
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006314
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01006315 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006316
Charles Chin9009b0e2011-11-03 10:27:27 +01006317 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006318 if (!err) {
6319 if (spec->board_config < 0) {
6320 printk(KERN_WARNING "hda_codec: No auto-config is "
6321 "available, default to model=ref\n");
6322 spec->board_config = STAC_92HD71BXX_REF;
6323 goto again;
6324 }
6325 err = -EINVAL;
6326 }
6327
6328 if (err < 0) {
6329 stac92xx_free(codec);
6330 return err;
6331 }
6332
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006333 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02006334 if (spec->board_config == STAC_HP_DV4 ||
6335 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006336 unsigned int cap;
6337 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
6338 cap &= AC_GPIO_IO_COUNT;
6339 if (cap >= 6)
6340 stac_add_hp_bass_switch(codec);
6341 }
6342
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006343 codec->proc_widget_hook = stac92hd7x_proc_hook;
6344
Matthew Ranostaye035b842007-11-06 11:53:55 +01006345 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006346}
Matthew Ranostaye035b842007-11-06 11:53:55 +01006347
Matt2f2f4252005-04-13 14:45:30 +02006348static int patch_stac922x(struct hda_codec *codec)
6349{
6350 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02006351 int err;
Matt2f2f4252005-04-13 14:45:30 +02006352
Takashi Iwai361dab32012-05-09 14:35:27 +02006353 err = alloc_stac_spec(codec, ARRAY_SIZE(stac922x_pin_nids),
6354 stac922x_pin_nids);
6355 if (err < 0)
6356 return err;
Matt2f2f4252005-04-13 14:45:30 +02006357
Takashi Iwai361dab32012-05-09 14:35:27 +02006358 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006359 spec->linear_tone_beep = 1;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006360 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
6361 stac922x_models,
6362 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08006363 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006364 spec->gpio_mask = spec->gpio_dir = 0x03;
6365 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006366 /* Intel Macs have all same PCI SSID, so we need to check
6367 * codec SSID to distinguish the exact models
6368 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006369 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006370 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006371
6372 case 0x106b0800:
6373 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02006374 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006375 case 0x106b0600:
6376 case 0x106b0700:
6377 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006378 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006379 case 0x106b0e00:
6380 case 0x106b0f00:
6381 case 0x106b1600:
6382 case 0x106b1700:
6383 case 0x106b0200:
6384 case 0x106b1e00:
6385 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006386 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006387 case 0x106b1a00:
6388 case 0x00000100:
6389 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02006390 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006391 case 0x106b0a00:
6392 case 0x106b2200:
6393 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02006394 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08006395 default:
6396 spec->board_config = STAC_INTEL_MAC_V3;
6397 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006398 }
6399 }
6400
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006401 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006402 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006403 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6404 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006405 else
6406 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006407 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02006408
Matt2f2f4252005-04-13 14:45:30 +02006409 spec->adc_nids = stac922x_adc_nids;
6410 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006411 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006412 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006413 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006414 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02006415
6416 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006417
6418 spec->num_caps = STAC922X_NUM_CAPS;
6419 spec->capvols = stac922x_capvols;
6420 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02006421
6422 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02006423
Charles Chin9009b0e2011-11-03 10:27:27 +01006424 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006425 if (!err) {
6426 if (spec->board_config < 0) {
6427 printk(KERN_WARNING "hda_codec: No auto-config is "
6428 "available, default to model=ref\n");
6429 spec->board_config = STAC_D945_REF;
6430 goto again;
6431 }
6432 err = -EINVAL;
6433 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006434 if (err < 0) {
6435 stac92xx_free(codec);
6436 return err;
6437 }
6438
6439 codec->patch_ops = stac92xx_patch_ops;
6440
Takashi Iwai807a46362007-05-29 19:01:37 +02006441 /* Fix Mux capture level; max to 2 */
6442 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
6443 (0 << AC_AMPCAP_OFFSET_SHIFT) |
6444 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
6445 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6446 (0 << AC_AMPCAP_MUTE_SHIFT));
6447
Matt Porter3cc08dc2006-01-23 15:27:49 +01006448 return 0;
6449}
6450
6451static int patch_stac927x(struct hda_codec *codec)
6452{
6453 struct sigmatel_spec *spec;
6454 int err;
6455
Takashi Iwai361dab32012-05-09 14:35:27 +02006456 err = alloc_stac_spec(codec, ARRAY_SIZE(stac927x_pin_nids),
6457 stac927x_pin_nids);
6458 if (err < 0)
6459 return err;
Matt Porter3cc08dc2006-01-23 15:27:49 +01006460
Takashi Iwai361dab32012-05-09 14:35:27 +02006461 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006462 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05006463 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006464 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
6465 stac927x_models,
6466 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006467 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006468 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006469 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6470 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006471 else
6472 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006473 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01006474
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006475 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006476 spec->adc_nids = stac927x_adc_nids;
6477 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6478 spec->mux_nids = stac927x_mux_nids;
6479 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006480 spec->smux_nids = stac927x_smux_nids;
6481 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04006482 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01006483 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006484 spec->multiout.dac_nids = spec->dac_nids;
6485
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006486 if (spec->board_config != STAC_D965_REF) {
6487 /* GPIO0 High = Enable EAPD */
6488 spec->eapd_mask = spec->gpio_mask = 0x01;
6489 spec->gpio_dir = spec->gpio_data = 0x01;
6490 }
6491
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006492 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02006493 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006494 case STAC_D965_5ST:
6495 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006496 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02006497 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006498 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006499 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006500 switch (codec->subsystem_id) {
6501 case 0x10280209:
6502 case 0x1028022e:
6503 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006504 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006505 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006506 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01006507 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01006508 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01006509 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006510 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006511 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01006512 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006513 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006514 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006515 if (codec->subsystem_id != 0x1028022f) {
6516 /* GPIO2 High = Enable EAPD */
6517 spec->eapd_mask = spec->gpio_mask = 0x04;
6518 spec->gpio_dir = spec->gpio_data = 0x04;
6519 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006520 spec->dmic_nids = stac927x_dmic_nids;
6521 spec->num_dmics = STAC927X_NUM_DMICS;
6522
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02006523 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006524 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006525 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006526 break;
Takashi Iwai54930532009-10-11 17:38:29 +02006527 case STAC_927X_VOLKNOB:
6528 spec->num_dmics = 0;
6529 spec->init = stac927x_volknob_core_init;
6530 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006531 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006532 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006533 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006534 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006535 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006536
Takashi Iwai6479c632009-07-28 18:20:25 +02006537 spec->num_caps = STAC927X_NUM_CAPS;
6538 spec->capvols = stac927x_capvols;
6539 spec->capsws = stac927x_capsws;
6540
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006541 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006542 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006543 spec->aloopback_mask = 0x40;
6544 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05006545 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006546
Charles Chin9009b0e2011-11-03 10:27:27 +01006547 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006548 if (!err) {
6549 if (spec->board_config < 0) {
6550 printk(KERN_WARNING "hda_codec: No auto-config is "
6551 "available, default to model=ref\n");
6552 spec->board_config = STAC_D965_REF;
6553 goto again;
6554 }
6555 err = -EINVAL;
6556 }
Mattc7d4b2f2005-06-27 14:59:41 +02006557 if (err < 0) {
6558 stac92xx_free(codec);
6559 return err;
6560 }
Matt2f2f4252005-04-13 14:45:30 +02006561
6562 codec->patch_ops = stac92xx_patch_ops;
6563
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006564 codec->proc_widget_hook = stac927x_proc_hook;
6565
Takashi Iwai52987652008-01-16 16:09:47 +01006566 /*
6567 * !!FIXME!!
6568 * The STAC927x seem to require fairly long delays for certain
6569 * command sequences. With too short delays (even if the answer
6570 * is set to RIRB properly), it results in the silence output
6571 * on some hardwares like Dell.
6572 *
6573 * The below flag enables the longer delay (see get_response
6574 * in hda_intel.c).
6575 */
6576 codec->bus->needs_damn_long_delay = 1;
6577
Takashi Iwaie28d8322008-12-17 13:48:29 +01006578 /* no jack detecion for ref-no-jd model */
6579 if (spec->board_config == STAC_D965_REF_NO_JD)
6580 spec->hp_detect = 0;
6581
Matt2f2f4252005-04-13 14:45:30 +02006582 return 0;
6583}
6584
Matt Porterf3302a52006-07-31 12:49:34 +02006585static int patch_stac9205(struct hda_codec *codec)
6586{
6587 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006588 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006589
Takashi Iwai361dab32012-05-09 14:35:27 +02006590 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9205_pin_nids),
6591 stac9205_pin_nids);
6592 if (err < 0)
6593 return err;
Matt Porterf3302a52006-07-31 12:49:34 +02006594
Takashi Iwai361dab32012-05-09 14:35:27 +02006595 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006596 spec->linear_tone_beep = 1;
Takashi Iwaife6322c2013-01-14 14:46:51 +01006597
6598 snd_hda_pick_fixup(codec, stac9205_models, stac9205_fixup_tbl,
6599 stac9205_fixups);
Matt Porterf3302a52006-07-31 12:49:34 +02006600
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006601 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006602 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006603 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006604 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006605 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006606 spec->smux_nids = stac9205_smux_nids;
6607 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006608 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006609 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006610 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006611 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006612 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006613
Takashi Iwaife6322c2013-01-14 14:46:51 +01006614 snd_hda_add_verbs(codec, stac9205_core_init);
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006615 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006616
Takashi Iwai6479c632009-07-28 18:20:25 +02006617 spec->num_caps = STAC9205_NUM_CAPS;
6618 spec->capvols = stac9205_capvols;
6619 spec->capsws = stac9205_capsws;
6620
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006621 spec->aloopback_mask = 0x40;
6622 spec->aloopback_shift = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006623 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006624
Takashi Iwaife6322c2013-01-14 14:46:51 +01006625 /* GPIO0 High = EAPD */
6626 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
6627 spec->gpio_data = 0x01;
Matt Porter33382402006-12-18 13:17:28 +01006628
Takashi Iwaife6322c2013-01-14 14:46:51 +01006629 /* Turn on/off EAPD per HP plugging */
6630 spec->eapd_switch = 1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006631
Takashi Iwaife6322c2013-01-14 14:46:51 +01006632 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
Matthew Ranostay87d48362007-07-17 11:52:24 +02006633
Charles Chin9009b0e2011-11-03 10:27:27 +01006634 err = stac92xx_parse_auto_config(codec);
Takashi Iwaife6322c2013-01-14 14:46:51 +01006635 if (!err)
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006636 err = -EINVAL;
Matt Porterf3302a52006-07-31 12:49:34 +02006637 if (err < 0) {
6638 stac92xx_free(codec);
6639 return err;
6640 }
6641
6642 codec->patch_ops = stac92xx_patch_ops;
6643
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006644 codec->proc_widget_hook = stac9205_proc_hook;
6645
Takashi Iwaife6322c2013-01-14 14:46:51 +01006646 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6647
Matt Porterf3302a52006-07-31 12:49:34 +02006648 return 0;
6649}
6650
Matt2f2f4252005-04-13 14:45:30 +02006651/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006652 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006653 */
6654
Takashi Iwai2b635362011-05-02 12:33:43 +02006655static const struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006656 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006657 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6658 {}
6659};
6660
Takashi Iwai2b635362011-05-02 12:33:43 +02006661static const hda_nid_t stac9872_pin_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006662 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6663 0x11, 0x13, 0x14,
6664};
6665
Takashi Iwai2b635362011-05-02 12:33:43 +02006666static const hda_nid_t stac9872_adc_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006667 0x8 /*,0x6*/
6668};
6669
Takashi Iwai2b635362011-05-02 12:33:43 +02006670static const hda_nid_t stac9872_mux_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006671 0x15
6672};
6673
Takashi Iwai2b635362011-05-02 12:33:43 +02006674static const unsigned long stac9872_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +02006675 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6676};
6677#define stac9872_capsws stac9872_capvols
6678
Takashi Iwaifc268c12013-01-14 14:29:36 +01006679static const struct hda_pintbl stac9872_vaio_pin_configs[] = {
6680 { 0x0a, 0x03211020 },
6681 { 0x0b, 0x411111f0 },
6682 { 0x0c, 0x411111f0 },
6683 { 0x0d, 0x03a15030 },
6684 { 0x0e, 0x411111f0 },
6685 { 0x0f, 0x90170110 },
6686 { 0x11, 0x411111f0 },
6687 { 0x13, 0x411111f0 },
6688 { 0x14, 0x90a7013e },
6689 {}
Takashi Iwai307282c2009-03-12 18:17:58 +01006690};
6691
Takashi Iwaifc268c12013-01-14 14:29:36 +01006692static const struct hda_model_fixup stac9872_models[] = {
6693 { .id = STAC_9872_VAIO, .name = "vaio" },
6694 {}
Takashi Iwai307282c2009-03-12 18:17:58 +01006695};
6696
Takashi Iwaifc268c12013-01-14 14:29:36 +01006697static const struct hda_fixup stac9872_fixups[] = {
6698 [STAC_9872_VAIO] = {
6699 .type = HDA_FIXUP_PINS,
6700 .v.pins = stac9872_vaio_pin_configs,
6701 },
Takashi Iwai307282c2009-03-12 18:17:58 +01006702};
6703
Takashi Iwaifc268c12013-01-14 14:29:36 +01006704static const struct snd_pci_quirk stac9872_fixup_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006705 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6706 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006707 {} /* terminator */
6708};
6709
Guillaume Munch6d859062006-08-22 17:15:47 +02006710static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006711{
6712 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006713 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006714
Takashi Iwai361dab32012-05-09 14:35:27 +02006715 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9872_pin_nids),
6716 stac9872_pin_nids);
6717 if (err < 0)
6718 return err;
6719
6720 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006721 spec->linear_tone_beep = 1;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006722
Takashi Iwaifc268c12013-01-14 14:29:36 +01006723 snd_hda_pick_fixup(codec, stac9872_models, stac9872_fixup_tbl,
6724 stac9872_fixups);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006725
Takashi Iwai1e137f92009-01-21 07:41:22 +01006726 spec->multiout.dac_nids = spec->dac_nids;
6727 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6728 spec->adc_nids = stac9872_adc_nids;
6729 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6730 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02006731 spec->num_caps = 1;
6732 spec->capvols = stac9872_capvols;
6733 spec->capsws = stac9872_capsws;
Takashi Iwaifc268c12013-01-14 14:29:36 +01006734 snd_hda_add_verbs(codec, stac9872_core_init);
6735
6736 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006737
Charles Chin9009b0e2011-11-03 10:27:27 +01006738 err = stac92xx_parse_auto_config(codec);
Takashi Iwai1e137f92009-01-21 07:41:22 +01006739 if (err < 0) {
6740 stac92xx_free(codec);
6741 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006742 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006743 spec->input_mux = &spec->private_imux;
6744 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaifc268c12013-01-14 14:29:36 +01006745
6746 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
6747
Takashi Iwaidb064e52006-03-16 16:04:58 +01006748 return 0;
6749}
6750
6751
6752/*
Matt2f2f4252005-04-13 14:45:30 +02006753 * patch entries
6754 */
Takashi Iwai2b635362011-05-02 12:33:43 +02006755static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006756 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6757 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6758 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6759 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6760 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6761 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6762 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006763 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6764 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6765 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6766 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6767 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6768 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006769 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6770 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6771 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6772 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6773 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6774 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6775 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6776 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6777 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6778 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006779 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6780 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6781 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6782 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6783 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6784 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006785 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6786 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006787 /* The following does not take into account .id=0x83847661 when subsys =
6788 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6789 * currently not fully supported.
6790 */
6791 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6792 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6793 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006794 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006795 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6796 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6797 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6798 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6799 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6800 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6801 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6802 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006803 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006804 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006805 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006806 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006807 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006808 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6809 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006810 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6811 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6812 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6813 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006814 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006815 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6816 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006817 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006818 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6819 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6820 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6821 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6822 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6823 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6824 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6825 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006826 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6827 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6828 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6829 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6830 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6831 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6832 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6833 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6834 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6835 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6836 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6837 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6838 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6839 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6840 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
David Henningsson46724c22011-09-20 09:02:22 +02006841 { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006842 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06006843 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6844 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006845 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Charles Chinad5d8752011-11-02 07:56:58 +01006846 { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6847 { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6848 { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6849 { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6850 { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6851 { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6852 { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6853 { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6854 { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6855 { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6856 { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6857 { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006858 {} /* terminator */
6859};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006860
6861MODULE_ALIAS("snd-hda-codec-id:8384*");
6862MODULE_ALIAS("snd-hda-codec-id:111d*");
6863
6864MODULE_LICENSE("GPL");
6865MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6866
6867static struct hda_codec_preset_list sigmatel_list = {
6868 .preset = snd_hda_preset_sigmatel,
6869 .owner = THIS_MODULE,
6870};
6871
6872static int __init patch_sigmatel_init(void)
6873{
6874 return snd_hda_add_codec_preset(&sigmatel_list);
6875}
6876
6877static void __exit patch_sigmatel_exit(void)
6878{
6879 snd_hda_delete_codec_preset(&sigmatel_list);
6880}
6881
6882module_init(patch_sigmatel_init)
6883module_exit(patch_sigmatel_exit)