blob: 4c98b3009e515d3c281d236841729f41a285eecd [file] [log] [blame]
Matt2f2f4252005-04-13 14:45:30 +02001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for SigmaTel STAC92xx
5 *
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
Matt Porter403d1942005-11-29 15:00:51 +01007 * Matt Porter <mporter@embeddedalley.com>
Matt2f2f4252005-04-13 14:45:30 +02008 *
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 *
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
Matt2f2f4252005-04-13 14:45:30 +020027#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/slab.h>
30#include <linux/pci.h>
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +010031#include <linux/dmi.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040032#include <linux/module.h>
Matt2f2f4252005-04-13 14:45:30 +020033#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020034#include <sound/asoundef.h>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040035#include <sound/jack.h>
Clemens Ladischa74ccea2010-10-22 15:52:34 +020036#include <sound/tlv.h>
Matt2f2f4252005-04-13 14:45:30 +020037#include "hda_codec.h"
38#include "hda_local.h"
Takashi Iwai128bc4b2012-05-07 17:42:31 +020039#include "hda_auto_parser.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020040#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020041#include "hda_jack.h"
Matt2f2f4252005-04-13 14:45:30 +020042
Takashi Iwaic6e4c662008-11-25 11:58:19 +010043enum {
44 STAC_VREF_EVENT = 1,
45 STAC_INSERT_EVENT,
46 STAC_PWR_EVENT,
47 STAC_HP_EVENT,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020048 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020049 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010050};
Matt4e550962005-07-04 17:51:39 +020051
Takashi Iwaif5fcc132006-11-24 17:07:44 +010052enum {
53 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010054 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020055 STAC_9200_DELL_D21,
56 STAC_9200_DELL_D22,
57 STAC_9200_DELL_D23,
58 STAC_9200_DELL_M21,
59 STAC_9200_DELL_M22,
60 STAC_9200_DELL_M23,
61 STAC_9200_DELL_M24,
62 STAC_9200_DELL_M25,
63 STAC_9200_DELL_M26,
64 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020065 STAC_9200_M4,
66 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010067 STAC_9200_PANASONIC,
Takashi Iwaid39a3ae2013-01-14 14:06:26 +010068 STAC_9200_EAPD_INIT,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010069 STAC_9200_MODELS
70};
71
72enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010073 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010074 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020075 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020076 STAC_9205_DELL_M43,
77 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010078 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010079 STAC_9205_MODELS
80};
81
82enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010083 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010084 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010085 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080086 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010087 STAC_DELL_M6_AMIC,
88 STAC_DELL_M6_DMIC,
89 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050090 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020091 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010092 STAC_92HD73XX_MODELS
93};
94
95enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010096 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020097 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050098 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050099 STAC_DELL_S14,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +0100100 STAC_DELL_VOSTRO_3500,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -0500101 STAC_92HD83XXX_HP_cNB11_INTQUAD,
Steven Eastland48315592010-08-06 15:07:35 -0600102 STAC_HP_DV7_4000,
Vitaliy Kulikov5556e142012-02-27 16:47:37 -0600103 STAC_HP_ZEPHYR,
Takashi Iwaia3e19972012-07-26 08:17:20 +0200104 STAC_92HD83XXX_HP_LED,
Takashi Iwaiff8a1e22012-07-31 10:16:59 +0200105 STAC_92HD83XXX_HP_INV_LED,
Takashi Iwai62cbde12012-09-14 11:58:54 +0200106 STAC_92HD83XXX_HP_MIC_LED,
David Henningsson8d032a82012-10-09 12:48:40 +0200107 STAC_92HD83XXX_HEADSET_JACK,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200108 STAC_92HD83XXX_MODELS
109};
110
111enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100112 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100113 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100114 STAC_DELL_M4_1,
115 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500116 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400117 STAC_HP_M4,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +0200118 STAC_HP_DV4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100119 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100120 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400121 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100122 STAC_92HD71BXX_MODELS
123};
124
125enum {
Tobin Davis8e21c342007-01-08 11:04:17 +0100126 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200127 STAC_M1,
128 STAC_M1_2,
129 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100130 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200131 STAC_M3,
132 STAC_M5,
133 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100134 STAC_925x_MODELS
135};
136
137enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100138 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100139 STAC_D945_REF,
140 STAC_D945GTP3,
141 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200142 STAC_INTEL_MAC_V1,
143 STAC_INTEL_MAC_V2,
144 STAC_INTEL_MAC_V3,
145 STAC_INTEL_MAC_V4,
146 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800147 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
148 * is given, one of the above models will be
149 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200150 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100151 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100152 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100153 STAC_MACBOOK_PRO_V1,
154 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200155 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200156 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300157 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200158 STAC_922X_DELL_D81,
159 STAC_922X_DELL_D82,
160 STAC_922X_DELL_M81,
161 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100162 STAC_922X_MODELS
163};
164
165enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100166 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100167 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100168 STAC_D965_REF,
169 STAC_D965_3ST,
170 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200171 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200172 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100173 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200174 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100175 STAC_927X_MODELS
176};
Matt Porter403d1942005-11-29 15:00:51 +0100177
Takashi Iwai307282c2009-03-12 18:17:58 +0100178enum {
179 STAC_9872_AUTO,
180 STAC_9872_VAIO,
181 STAC_9872_MODELS
182};
183
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200184struct sigmatel_mic_route {
185 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200186 signed char mux_idx;
187 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200188};
189
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600190#define MAX_PINS_NUM 16
191#define MAX_ADCS_NUM 4
192#define MAX_DMICS_NUM 4
193
Matt2f2f4252005-04-13 14:45:30 +0200194struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100195 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200196 unsigned int num_mixers;
197
Matt Porter403d1942005-11-29 15:00:51 +0100198 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500199 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200200 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100201 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100202 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400203 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100204 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200205 unsigned int auto_mic:1;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +0100206 unsigned int linear_tone_beep:1;
David Henningsson8d032a82012-10-09 12:48:40 +0200207 unsigned int headset_jack:1; /* 4-pin headset jack (hp + mono mic) */
Mattc7d4b2f2005-06-27 14:59:41 +0200208
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100209 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200210 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100211 unsigned int gpio_mask;
212 unsigned int gpio_dir;
213 unsigned int gpio_data;
214 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200215 unsigned int gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +0100216 unsigned int gpio_led_polarity;
Takashi Iwaif1a73742011-12-04 13:44:06 +0100217 unsigned int vref_mute_led_nid; /* pin NID for mute-LED vref control */
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500218 unsigned int vref_led;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100219
Takashi Iwai62cbde12012-09-14 11:58:54 +0200220 unsigned int mic_mute_led_gpio; /* capture mute LED GPIO */
221 bool mic_mute_led_on; /* current mic mute state */
222
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200223 /* stream */
224 unsigned int stream_delay;
225
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100226 /* analog loopback */
Takashi Iwai2b635362011-05-02 12:33:43 +0200227 const struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100228 unsigned char aloopback_mask;
229 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200230
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100231 /* power management */
Takashi Iwaic8822462012-05-15 09:11:36 +0200232 unsigned int power_map_bits;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100233 unsigned int num_pwrs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200234 const hda_nid_t *pwr_nids;
235 const hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100236
Matt2f2f4252005-04-13 14:45:30 +0200237 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100238 struct hda_input_mux *mono_mux;
239 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200240 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100241 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100242 hda_nid_t hp_dacs[5];
243 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200244
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100245 int volume_offset;
246
Matt2f2f4252005-04-13 14:45:30 +0200247 /* capture */
Takashi Iwai2b635362011-05-02 12:33:43 +0200248 const hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200249 unsigned int num_adcs;
Takashi Iwai2b635362011-05-02 12:33:43 +0200250 const hda_nid_t *mux_nids;
Mattdabbed62005-06-14 10:19:34 +0200251 unsigned int num_muxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200252 const hda_nid_t *dmic_nids;
Matt Porter8b657272006-10-26 17:12:59 +0200253 unsigned int num_dmics;
Takashi Iwai2b635362011-05-02 12:33:43 +0200254 const hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100255 unsigned int num_dmuxes;
Takashi Iwai2b635362011-05-02 12:33:43 +0200256 const hda_nid_t *smux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200257 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200258 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200259
Takashi Iwai2b635362011-05-02 12:33:43 +0200260 const unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
261 const unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
Takashi Iwai6479c632009-07-28 18:20:25 +0200262 unsigned int num_caps; /* number of capture volume/switch elements */
263
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200264 struct sigmatel_mic_route ext_mic;
265 struct sigmatel_mic_route int_mic;
Charles Chin99077902010-09-17 10:22:32 +0200266 struct sigmatel_mic_route dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200267
Takashi Iwaiea734962011-01-17 11:29:34 +0100268 const char * const *spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200269
Mattdabbed62005-06-14 10:19:34 +0200270 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100271 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200272 hda_nid_t anabeep_nid;
273 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200274
Matt2f2f4252005-04-13 14:45:30 +0200275 /* pin widgets */
Takashi Iwai2b635362011-05-02 12:33:43 +0200276 const hda_nid_t *pin_nids;
Matt2f2f4252005-04-13 14:45:30 +0200277 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200278
279 /* codec specific stuff */
Takashi Iwai2b635362011-05-02 12:33:43 +0200280 const struct hda_verb *init;
281 const struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200282
283 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200284 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100285 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200286 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100287 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200288 struct hda_input_mux *sinput_mux;
289 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400290 unsigned int cur_amux;
291 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200292 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200293
Matt Porter403d1942005-11-29 15:00:51 +0100294 /* i/o switches */
295 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200296 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100297 hda_nid_t line_switch; /* shared line-in for input and output */
298 hda_nid_t mic_switch; /* shared mic-in for input and output */
299 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200300 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200301
Mattc7d4b2f2005-06-27 14:59:41 +0200302 struct hda_pcm pcm_rec[2]; /* PCM information */
303
304 /* dynamic controls and input_mux */
305 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200306 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200307 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200308 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200309 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100310 struct hda_input_mux private_mono_mux;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600311
312 /* auto spec */
313 unsigned auto_pin_cnt;
314 hda_nid_t auto_pin_nids[MAX_PINS_NUM];
315 unsigned auto_adc_cnt;
316 hda_nid_t auto_adc_nids[MAX_ADCS_NUM];
317 hda_nid_t auto_mux_nids[MAX_ADCS_NUM];
318 hda_nid_t auto_dmux_nids[MAX_ADCS_NUM];
319 unsigned long auto_capvols[MAX_ADCS_NUM];
320 unsigned auto_dmic_cnt;
321 hda_nid_t auto_dmic_nids[MAX_DMICS_NUM];
Takashi Iwai2faa3bf2012-03-12 12:30:22 +0100322
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100323 struct hda_vmaster_mute_hook vmaster_mute;
Matt2f2f4252005-04-13 14:45:30 +0200324};
325
Takashi Iwaic8822462012-05-15 09:11:36 +0200326#define AC_VERB_IDT_SET_POWER_MAP 0x7ec
327#define AC_VERB_IDT_GET_POWER_MAP 0xfec
328
Takashi Iwai2b635362011-05-02 12:33:43 +0200329static const hda_nid_t stac9200_adc_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200330 0x03,
331};
332
Takashi Iwai2b635362011-05-02 12:33:43 +0200333static const hda_nid_t stac9200_mux_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200334 0x0c,
335};
336
Takashi Iwai2b635362011-05-02 12:33:43 +0200337static const hda_nid_t stac9200_dac_nids[1] = {
Matt2f2f4252005-04-13 14:45:30 +0200338 0x02,
339};
340
Takashi Iwai2b635362011-05-02 12:33:43 +0200341static const hda_nid_t stac92hd73xx_pwr_nids[8] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100342 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
343 0x0f, 0x10, 0x11
344};
345
Takashi Iwai2b635362011-05-02 12:33:43 +0200346static const hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400347 0x26, 0,
348};
349
Takashi Iwai2b635362011-05-02 12:33:43 +0200350static const hda_nid_t stac92hd73xx_adc_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100351 0x1a, 0x1b
352};
353
354#define STAC92HD73XX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200355static const hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100356 0x13, 0x14, 0
357};
358
359#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100360
Takashi Iwai2b635362011-05-02 12:33:43 +0200361static const hda_nid_t stac92hd73xx_mux_nids[2] = {
Takashi Iwaie2aec172009-09-02 01:00:05 +0200362 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100363};
364
Takashi Iwai2b635362011-05-02 12:33:43 +0200365static const hda_nid_t stac92hd73xx_dmux_nids[2] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100366 0x20, 0x21,
367};
368
Takashi Iwai2b635362011-05-02 12:33:43 +0200369static const hda_nid_t stac92hd73xx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200370 0x22, 0x23,
371};
372
Takashi Iwai6479c632009-07-28 18:20:25 +0200373#define STAC92HD73XX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200374static const unsigned long stac92hd73xx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200375 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
376 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
377};
378#define stac92hd73xx_capsws stac92hd73xx_capvols
379
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200380#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200381
Charles Chinafef2cf2011-11-11 08:05:28 +0100382static const hda_nid_t stac92hd83xxx_pwr_nids[7] = {
383 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
384 0x0f, 0x10
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200385};
386
Takashi Iwai2b635362011-05-02 12:33:43 +0200387static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400388 0x1e, 0,
389};
390
Takashi Iwai2b635362011-05-02 12:33:43 +0200391static const hda_nid_t stac92hd83xxx_dmic_nids[] = {
Vitaliy Kulikov699d8992011-03-10 13:43:35 -0600392 0x11, 0x20,
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +0200393};
394
Takashi Iwai2b635362011-05-02 12:33:43 +0200395static const hda_nid_t stac92hd71bxx_pwr_nids[3] = {
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100396 0x0a, 0x0d, 0x0f
397};
398
Takashi Iwai2b635362011-05-02 12:33:43 +0200399static const hda_nid_t stac92hd71bxx_adc_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100400 0x12, 0x13,
401};
402
Takashi Iwai2b635362011-05-02 12:33:43 +0200403static const hda_nid_t stac92hd71bxx_mux_nids[2] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100404 0x1a, 0x1b
405};
406
Takashi Iwai2b635362011-05-02 12:33:43 +0200407static const hda_nid_t stac92hd71bxx_dmux_nids[2] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400408 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100409};
410
Takashi Iwai2b635362011-05-02 12:33:43 +0200411static const hda_nid_t stac92hd71bxx_smux_nids[2] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200412 0x24, 0x25,
413};
414
Matthew Ranostaye035b842007-11-06 11:53:55 +0100415#define STAC92HD71BXX_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200416static const hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100417 0x18, 0x19, 0
418};
419
Takashi Iwai2b635362011-05-02 12:33:43 +0200420static const hda_nid_t stac92hd71bxx_dmic_5port_nids[STAC92HD71BXX_NUM_DMICS] = {
421 0x18, 0
422};
423
424static const hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400425 0x22, 0
426};
427
Takashi Iwai6479c632009-07-28 18:20:25 +0200428#define STAC92HD71BXX_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200429static const unsigned long stac92hd71bxx_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200430 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
431 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
432};
433#define stac92hd71bxx_capsws stac92hd71bxx_capvols
434
Takashi Iwai2b635362011-05-02 12:33:43 +0200435static const hda_nid_t stac925x_adc_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100436 0x03,
437};
438
Takashi Iwai2b635362011-05-02 12:33:43 +0200439static const hda_nid_t stac925x_mux_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100440 0x0f,
441};
442
Takashi Iwai2b635362011-05-02 12:33:43 +0200443static const hda_nid_t stac925x_dac_nids[1] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100444 0x02,
445};
446
Takashi Iwaif6e98522007-10-16 14:27:04 +0200447#define STAC925X_NUM_DMICS 1
Takashi Iwai2b635362011-05-02 12:33:43 +0200448static const hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200449 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200450};
451
Takashi Iwai2b635362011-05-02 12:33:43 +0200452static const hda_nid_t stac925x_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100453 0x14,
454};
455
Takashi Iwai2b635362011-05-02 12:33:43 +0200456static const unsigned long stac925x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200457 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
458};
Takashi Iwai2b635362011-05-02 12:33:43 +0200459static const unsigned long stac925x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200460 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
461};
462
Takashi Iwai2b635362011-05-02 12:33:43 +0200463static const hda_nid_t stac922x_adc_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200464 0x06, 0x07,
465};
466
Takashi Iwai2b635362011-05-02 12:33:43 +0200467static const hda_nid_t stac922x_mux_nids[2] = {
Matt2f2f4252005-04-13 14:45:30 +0200468 0x12, 0x13,
469};
470
Takashi Iwai6479c632009-07-28 18:20:25 +0200471#define STAC922X_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200472static const unsigned long stac922x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200473 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
474 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
475};
476#define stac922x_capsws stac922x_capvols
477
Takashi Iwai2b635362011-05-02 12:33:43 +0200478static const hda_nid_t stac927x_slave_dig_outs[2] = {
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500479 0x1f, 0,
480};
481
Takashi Iwai2b635362011-05-02 12:33:43 +0200482static const hda_nid_t stac927x_adc_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100483 0x07, 0x08, 0x09
484};
485
Takashi Iwai2b635362011-05-02 12:33:43 +0200486static const hda_nid_t stac927x_mux_nids[3] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100487 0x15, 0x16, 0x17
488};
489
Takashi Iwai2b635362011-05-02 12:33:43 +0200490static const hda_nid_t stac927x_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200491 0x21,
492};
493
Takashi Iwai2b635362011-05-02 12:33:43 +0200494static const hda_nid_t stac927x_dac_nids[6] = {
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100495 0x02, 0x03, 0x04, 0x05, 0x06, 0
496};
497
Takashi Iwai2b635362011-05-02 12:33:43 +0200498static const hda_nid_t stac927x_dmux_nids[1] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100499 0x1b,
500};
501
Matthew Ranostay7f168592007-10-18 17:38:17 +0200502#define STAC927X_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200503static const hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
Matthew Ranostay7f168592007-10-18 17:38:17 +0200504 0x13, 0x14, 0
505};
506
Takashi Iwai6479c632009-07-28 18:20:25 +0200507#define STAC927X_NUM_CAPS 3
Takashi Iwai2b635362011-05-02 12:33:43 +0200508static const unsigned long stac927x_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200509 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
510 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
511 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
512};
Takashi Iwai2b635362011-05-02 12:33:43 +0200513static const unsigned long stac927x_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200514 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
515 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
516 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
517};
518
Takashi Iwaiea734962011-01-17 11:29:34 +0100519static const char * const stac927x_spdif_labels[5] = {
Matthew Ranostay65973632008-09-16 10:39:37 -0400520 "Digital Playback", "ADAT", "Analog Mux 1",
521 "Analog Mux 2", "Analog Mux 3"
522};
523
Takashi Iwai2b635362011-05-02 12:33:43 +0200524static const hda_nid_t stac9205_adc_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200525 0x12, 0x13
526};
527
Takashi Iwai2b635362011-05-02 12:33:43 +0200528static const hda_nid_t stac9205_mux_nids[2] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200529 0x19, 0x1a
530};
531
Takashi Iwai2b635362011-05-02 12:33:43 +0200532static const hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100533 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100534};
535
Takashi Iwai2b635362011-05-02 12:33:43 +0200536static const hda_nid_t stac9205_smux_nids[1] = {
Matthew Ranostayd9737752008-09-07 12:03:41 +0200537 0x21,
538};
539
Takashi Iwaif6e98522007-10-16 14:27:04 +0200540#define STAC9205_NUM_DMICS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200541static const hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
Takashi Iwaif6e98522007-10-16 14:27:04 +0200542 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200543};
544
Takashi Iwai6479c632009-07-28 18:20:25 +0200545#define STAC9205_NUM_CAPS 2
Takashi Iwai2b635362011-05-02 12:33:43 +0200546static const unsigned long stac9205_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200547 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
548 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
549};
Takashi Iwai2b635362011-05-02 12:33:43 +0200550static const unsigned long stac9205_capsws[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +0200551 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
552 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
553};
554
Takashi Iwai2b635362011-05-02 12:33:43 +0200555static const hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200556 0x08, 0x09, 0x0d, 0x0e,
557 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200558};
559
Takashi Iwai2b635362011-05-02 12:33:43 +0200560static const hda_nid_t stac925x_pin_nids[8] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100561 0x07, 0x08, 0x0a, 0x0b,
562 0x0c, 0x0d, 0x10, 0x11,
563};
564
Takashi Iwai2b635362011-05-02 12:33:43 +0200565static const hda_nid_t stac922x_pin_nids[10] = {
Matt2f2f4252005-04-13 14:45:30 +0200566 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
567 0x0f, 0x10, 0x11, 0x15, 0x1b,
568};
569
Takashi Iwai2b635362011-05-02 12:33:43 +0200570static const hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100571 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
572 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200573 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100574};
575
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500576#define STAC92HD71BXX_NUM_PINS 13
Takashi Iwai2b635362011-05-02 12:33:43 +0200577static const hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500578 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
579 0x00, 0x14, 0x18, 0x19, 0x1e,
580 0x1f, 0x20, 0x27
581};
Takashi Iwai2b635362011-05-02 12:33:43 +0200582static const hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100583 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
584 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500585 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100586};
587
Takashi Iwai2b635362011-05-02 12:33:43 +0200588static const hda_nid_t stac927x_pin_nids[14] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100589 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
590 0x0f, 0x10, 0x11, 0x12, 0x13,
591 0x14, 0x21, 0x22, 0x23,
592};
593
Takashi Iwai2b635362011-05-02 12:33:43 +0200594static const hda_nid_t stac9205_pin_nids[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200595 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
596 0x0f, 0x14, 0x16, 0x17, 0x18,
597 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200598};
599
Matt Porter8b657272006-10-26 17:12:59 +0200600static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
601 struct snd_ctl_elem_info *uinfo)
602{
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct sigmatel_spec *spec = codec->spec;
605 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
606}
607
608static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
609 struct snd_ctl_elem_value *ucontrol)
610{
611 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
612 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100613 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200614
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100615 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200616 return 0;
617}
618
619static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
620 struct snd_ctl_elem_value *ucontrol)
621{
622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
623 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100624 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200625
626 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100627 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200628}
629
Matthew Ranostayd9737752008-09-07 12:03:41 +0200630static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
631 struct snd_ctl_elem_info *uinfo)
632{
633 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
634 struct sigmatel_spec *spec = codec->spec;
635 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
636}
637
638static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
639 struct snd_ctl_elem_value *ucontrol)
640{
641 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
642 struct sigmatel_spec *spec = codec->spec;
643 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
644
645 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
646 return 0;
647}
648
649static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
650 struct snd_ctl_elem_value *ucontrol)
651{
652 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
653 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400654 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200655 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400656 int err, val;
657 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200658
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400659 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200660 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400661 if (err < 0)
662 return err;
663
664 if (spec->spdif_mute) {
665 if (smux_idx == 0)
666 nid = spec->multiout.dig_out_nid;
667 else
668 nid = codec->slave_dig_outs[smux_idx - 1];
669 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100670 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400671 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100672 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400673 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100674 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
675 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400676 }
677 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200678}
679
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500680static int stac_vrefout_set(struct hda_codec *codec,
681 hda_nid_t nid, unsigned int new_vref)
682{
683 int error, pinctl;
684
685 snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
686 pinctl = snd_hda_codec_read(codec, nid, 0,
687 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
688
689 if (pinctl < 0)
690 return pinctl;
691
692 pinctl &= 0xff;
693 pinctl &= ~AC_PINCTL_VREFEN;
694 pinctl |= (new_vref & AC_PINCTL_VREFEN);
695
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200696 error = snd_hda_set_pin_ctl_cache(codec, nid, pinctl);
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -0500697 if (error < 0)
698 return error;
699
700 return 1;
701}
702
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200703static unsigned int stac92xx_vref_set(struct hda_codec *codec,
704 hda_nid_t nid, unsigned int new_vref)
705{
Takashi Iwaib8621512009-06-22 08:00:10 +0200706 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200707 unsigned int pincfg;
708 pincfg = snd_hda_codec_read(codec, nid, 0,
709 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
710
711 pincfg &= 0xff;
712 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
713 pincfg |= new_vref;
714
715 if (new_vref == AC_PINCTL_VREF_HIZ)
716 pincfg |= AC_PINCTL_OUT_EN;
717 else
718 pincfg |= AC_PINCTL_IN_EN;
719
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200720 error = snd_hda_set_pin_ctl_cache(codec, nid, pincfg);
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200721 if (error < 0)
722 return error;
723 else
724 return 1;
725}
726
727static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
728{
729 unsigned int vref;
730 vref = snd_hda_codec_read(codec, nid, 0,
731 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
732 vref &= AC_PINCTL_VREFEN;
733 return vref;
734}
735
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100736static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200737{
738 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
739 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200740 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200741}
742
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100743static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200744{
745 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
746 struct sigmatel_spec *spec = codec->spec;
747 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
748
749 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
750 return 0;
751}
752
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100753static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200754{
755 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
756 struct sigmatel_spec *spec = codec->spec;
757 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200758 const struct hda_input_mux *imux = spec->input_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600759 unsigned int idx, prev_idx, didx;
Matt2f2f4252005-04-13 14:45:30 +0200760
Takashi Iwai5207e102009-07-30 13:09:08 +0200761 idx = ucontrol->value.enumerated.item[0];
762 if (idx >= imux->num_items)
763 idx = imux->num_items - 1;
764 prev_idx = spec->cur_mux[adc_idx];
765 if (prev_idx == idx)
766 return 0;
767 if (idx < spec->num_analog_muxes) {
768 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
769 AC_VERB_SET_CONNECT_SEL,
770 imux->items[idx].index);
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600771 if (prev_idx >= spec->num_analog_muxes &&
772 spec->mux_nids[adc_idx] != spec->dmux_nids[adc_idx]) {
Takashi Iwai5207e102009-07-30 13:09:08 +0200773 imux = spec->dinput_mux;
774 /* 0 = analog */
775 snd_hda_codec_write_cache(codec,
776 spec->dmux_nids[adc_idx], 0,
777 AC_VERB_SET_CONNECT_SEL,
778 imux->items[0].index);
779 }
780 } else {
781 imux = spec->dinput_mux;
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600782 /* first dimux item is hardcoded to select analog imux,
783 * so lets skip it
784 */
785 didx = idx - spec->num_analog_muxes + 1;
Takashi Iwai5207e102009-07-30 13:09:08 +0200786 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
787 AC_VERB_SET_CONNECT_SEL,
Vitaliy Kulikov094a4242011-03-09 19:47:43 -0600788 imux->items[didx].index);
Takashi Iwai5207e102009-07-30 13:09:08 +0200789 }
790 spec->cur_mux[adc_idx] = idx;
791 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200792}
793
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100794static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
795 struct snd_ctl_elem_info *uinfo)
796{
797 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798 struct sigmatel_spec *spec = codec->spec;
799 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
800}
801
802static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
803 struct snd_ctl_elem_value *ucontrol)
804{
805 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
806 struct sigmatel_spec *spec = codec->spec;
807
808 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
809 return 0;
810}
811
812static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
813 struct snd_ctl_elem_value *ucontrol)
814{
815 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
816 struct sigmatel_spec *spec = codec->spec;
817
818 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
819 spec->mono_nid, &spec->cur_mmux);
820}
821
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200822#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
823
824static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
825 struct snd_ctl_elem_value *ucontrol)
826{
827 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100828 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200829 struct sigmatel_spec *spec = codec->spec;
830
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100831 ucontrol->value.integer.value[0] = !!(spec->aloopback &
832 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200833 return 0;
834}
835
836static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
837 struct snd_ctl_elem_value *ucontrol)
838{
839 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
840 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100841 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200842 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100843 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200844
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100845 idx_val = spec->aloopback_mask << idx;
846 if (ucontrol->value.integer.value[0])
847 val = spec->aloopback | idx_val;
848 else
849 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100850 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200851 return 0;
852
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100853 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200854
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100855 /* Only return the bits defined by the shift value of the
856 * first two bytes of the mask
857 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200858 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100859 kcontrol->private_value & 0xFFFF, 0x0);
860 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200861
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100862 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200863 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100864 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200865 } else {
866 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100867 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200868 }
869
870 snd_hda_codec_write_cache(codec, codec->afg, 0,
871 kcontrol->private_value >> 16, dac_mode);
872
873 return 1;
874}
875
Takashi Iwai2b635362011-05-02 12:33:43 +0200876static const struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200877 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200878 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200879 {}
880};
881
Takashi Iwai2b635362011-05-02 12:33:43 +0200882static const struct hda_verb stac9200_eapd_init[] = {
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200883 /* set dac0mux for dac converter */
884 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
885 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
886 {}
887};
888
Takashi Iwai2b635362011-05-02 12:33:43 +0200889static const struct hda_verb dell_eq_core_init[] = {
Matthew Ranostayd654a662008-03-14 08:46:51 +0100890 /* set master volume to max value without distortion
891 * and direct control */
892 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100893 {}
894};
895
Takashi Iwai2b635362011-05-02 12:33:43 +0200896static const struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100897 /* set master volume and direct control */
898 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100899 {}
900};
901
Takashi Iwai2b635362011-05-02 12:33:43 +0200902static const struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200903 /* power state controls amps */
904 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200905 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200906};
907
Vitaliy Kulikov5556e142012-02-27 16:47:37 -0600908static const struct hda_verb stac92hd83xxx_hp_zephyr_init[] = {
909 { 0x22, 0x785, 0x43 },
910 { 0x22, 0x782, 0xe0 },
911 { 0x22, 0x795, 0x00 },
912 {}
913};
914
Takashi Iwai2b635362011-05-02 12:33:43 +0200915static const struct hda_verb stac92hd71bxx_core_init[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100916 /* set master volume and direct control */
917 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200918 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100919};
920
Takashi Iwai2b635362011-05-02 12:33:43 +0200921static const struct hda_verb stac92hd71bxx_unmute_core_init[] = {
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500922 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
923 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100924 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
925 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100926 {}
927};
928
Takashi Iwai2b635362011-05-02 12:33:43 +0200929static const struct hda_verb stac925x_core_init[] = {
Tobin Davis8e21c342007-01-08 11:04:17 +0100930 /* set dac0mux for dac converter */
931 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100932 /* mute the master volume */
933 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100934 {}
935};
936
Takashi Iwai2b635362011-05-02 12:33:43 +0200937static const struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200938 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200939 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200940 {}
941};
942
Takashi Iwai2b635362011-05-02 12:33:43 +0200943static const struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200944 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200945 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200946 /* unmute node 0x1b */
947 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
948 /* select node 0x03 as DAC */
949 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
950 {}
951};
952
Takashi Iwai2b635362011-05-02 12:33:43 +0200953static const struct hda_verb dell_3st_core_init[] = {
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200954 /* don't set delta bit */
955 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
956 /* unmute node 0x1b */
957 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
958 /* select node 0x03 as DAC */
959 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
960 {}
961};
962
Takashi Iwai2b635362011-05-02 12:33:43 +0200963static const struct hda_verb stac927x_core_init[] = {
Matt Porter3cc08dc2006-01-23 15:27:49 +0100964 /* set master volume and direct control */
965 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200966 /* enable analog pc beep path */
967 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100968 {}
969};
970
Takashi Iwai2b635362011-05-02 12:33:43 +0200971static const struct hda_verb stac927x_volknob_core_init[] = {
Takashi Iwai54930532009-10-11 17:38:29 +0200972 /* don't set delta bit */
973 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
974 /* enable analog pc beep path */
975 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
976 {}
977};
978
Takashi Iwai2b635362011-05-02 12:33:43 +0200979static const struct hda_verb stac9205_core_init[] = {
Matt Porterf3302a52006-07-31 12:49:34 +0200980 /* set master volume and direct control */
981 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200982 /* enable analog pc beep path */
983 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200984 {}
985};
986
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100987#define STAC_MONO_MUX \
988 { \
989 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
990 .name = "Mono Mux", \
991 .count = 1, \
992 .info = stac92xx_mono_mux_enum_info, \
993 .get = stac92xx_mono_mux_enum_get, \
994 .put = stac92xx_mono_mux_enum_put, \
995 }
996
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100997#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200998 { \
999 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1000 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001001 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +02001002 .info = stac92xx_aloopback_info, \
1003 .get = stac92xx_aloopback_get, \
1004 .put = stac92xx_aloopback_put, \
1005 .private_value = verb_read | (verb_write << 16), \
1006 }
1007
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02001008#define DC_BIAS(xname, idx, nid) \
1009 { \
1010 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1011 .name = xname, \
1012 .index = idx, \
1013 .info = stac92xx_dc_bias_info, \
1014 .get = stac92xx_dc_bias_get, \
1015 .put = stac92xx_dc_bias_put, \
1016 .private_value = nid, \
1017 }
1018
Takashi Iwai2b635362011-05-02 12:33:43 +02001019static const struct snd_kcontrol_new stac9200_mixer[] = {
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001020 HDA_CODEC_VOLUME_MIN_MUTE("PCM Playback Volume", 0xb, 0, HDA_OUTPUT),
1021 HDA_CODEC_MUTE("PCM Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001022 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1023 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001024 { } /* end */
1025};
1026
Takashi Iwai2b635362011-05-02 12:33:43 +02001027static const struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001028 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1029 {}
1030};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001031
Takashi Iwai2b635362011-05-02 12:33:43 +02001032static const struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001033 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1034 {}
1035};
1036
Takashi Iwai2b635362011-05-02 12:33:43 +02001037static const struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001038 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1039 {}
1040};
1041
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001042
Takashi Iwai2b635362011-05-02 12:33:43 +02001043static const struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001044 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1045};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001046
Takashi Iwai2b635362011-05-02 12:33:43 +02001047static const struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001048 HDA_CODEC_VOLUME_MIN_MUTE("PCM Playback Volume", 0xe, 0, HDA_OUTPUT),
1049 HDA_CODEC_MUTE("PCM Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001050 { } /* end */
1051};
1052
Takashi Iwai2b635362011-05-02 12:33:43 +02001053static const struct snd_kcontrol_new stac9205_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001054 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1055 {}
1056};
1057
Takashi Iwai2b635362011-05-02 12:33:43 +02001058static const struct snd_kcontrol_new stac927x_loopback[] = {
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001059 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1060 {}
1061};
1062
Takashi Iwai1697055e2007-12-18 18:05:52 +01001063static struct snd_kcontrol_new stac_dmux_mixer = {
1064 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1065 .name = "Digital Input Source",
1066 /* count set later */
1067 .info = stac92xx_dmux_enum_info,
1068 .get = stac92xx_dmux_enum_get,
1069 .put = stac92xx_dmux_enum_put,
1070};
1071
Matthew Ranostayd9737752008-09-07 12:03:41 +02001072static struct snd_kcontrol_new stac_smux_mixer = {
1073 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001074 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001075 /* count set later */
1076 .info = stac92xx_smux_enum_info,
1077 .get = stac92xx_smux_enum_get,
1078 .put = stac92xx_smux_enum_put,
1079};
1080
Takashi Iwai9322ca52012-02-03 14:28:01 +01001081static const char * const slave_pfxs[] = {
1082 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01001083 "Headphone", "Speaker", "Bass Speaker", "IEC958", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001084 NULL
1085};
1086
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001087static void stac92xx_update_led_status(struct hda_codec *codec, int enabled);
1088
1089static void stac92xx_vmaster_hook(void *private_data, int val)
1090{
1091 stac92xx_update_led_status(private_data, val);
1092}
1093
Takashi Iwai603c4012008-07-30 15:01:44 +02001094static void stac92xx_free_kctls(struct hda_codec *codec);
1095
Matt2f2f4252005-04-13 14:45:30 +02001096static int stac92xx_build_controls(struct hda_codec *codec)
1097{
1098 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001099 unsigned int vmaster_tlv[4];
Matt2f2f4252005-04-13 14:45:30 +02001100 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001101 int i;
Matt2f2f4252005-04-13 14:45:30 +02001102
Takashi Iwai6479c632009-07-28 18:20:25 +02001103 if (spec->mixer) {
1104 err = snd_hda_add_new_ctls(codec, spec->mixer);
1105 if (err < 0)
1106 return err;
1107 }
Mattc7d4b2f2005-06-27 14:59:41 +02001108
1109 for (i = 0; i < spec->num_mixers; i++) {
1110 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1111 if (err < 0)
1112 return err;
1113 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001114 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1115 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001116 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001117 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001118 snd_ctl_new1(&stac_dmux_mixer, codec));
1119 if (err < 0)
1120 return err;
1121 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001122 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001123 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1124 struct hda_input_mux *smux = &spec->private_smux;
1125 /* check for mute support on SPDIF out */
1126 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001127 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001128 spec->spdif_mute = 1;
1129 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001130 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001131 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001132 snd_ctl_new1(&stac_smux_mixer, codec));
1133 if (err < 0)
1134 return err;
1135 }
Mattc7d4b2f2005-06-27 14:59:41 +02001136
Mattdabbed62005-06-14 10:19:34 +02001137 if (spec->multiout.dig_out_nid) {
Takashi Iwaidcda5802012-10-12 17:24:51 +02001138 err = snd_hda_create_dig_out_ctls(codec,
1139 spec->multiout.dig_out_nid,
1140 spec->multiout.dig_out_nid,
1141 spec->autocfg.dig_out_type[0]);
Mattdabbed62005-06-14 10:19:34 +02001142 if (err < 0)
1143 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001144 err = snd_hda_create_spdif_share_sw(codec,
1145 &spec->multiout);
1146 if (err < 0)
1147 return err;
1148 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001149 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001150 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001151 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1152 if (err < 0)
1153 return err;
1154 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001155
1156 /* if we have no master control, let's create it */
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001157 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1158 HDA_OUTPUT, vmaster_tlv);
1159 /* correct volume offset */
1160 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1161 /* minimum value is actually mute */
1162 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
1163 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1164 vmaster_tlv, slave_pfxs,
1165 "Playback Volume");
1166 if (err < 0)
1167 return err;
1168
1169 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1170 NULL, slave_pfxs,
1171 "Playback Switch", true,
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001172 &spec->vmaster_mute.sw_kctl);
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01001173 if (err < 0)
1174 return err;
1175
1176 if (spec->gpio_led) {
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001177 spec->vmaster_mute.hook = stac92xx_vmaster_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01001178 err = snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001179 if (err < 0)
1180 return err;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001181 }
1182
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001183 if (spec->aloopback_ctl &&
1184 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1185 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1186 if (err < 0)
1187 return err;
1188 }
1189
Takashi Iwai603c4012008-07-30 15:01:44 +02001190 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001191
Takashi Iwai01a61e12011-10-28 00:03:22 +02001192 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1193 if (err < 0)
1194 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001195
Mattdabbed62005-06-14 10:19:34 +02001196 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001197}
1198
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001199static const struct hda_pintbl ref9200_pin_configs[] = {
1200 { 0x08, 0x01c47010 },
1201 { 0x09, 0x01447010 },
1202 { 0x0d, 0x0221401f },
1203 { 0x0e, 0x01114010 },
1204 { 0x0f, 0x02a19020 },
1205 { 0x10, 0x01a19021 },
1206 { 0x11, 0x90100140 },
1207 { 0x12, 0x01813122 },
1208 {}
Matt2f2f4252005-04-13 14:45:30 +02001209};
1210
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001211static const struct hda_pintbl gateway9200_m4_pin_configs[] = {
1212 { 0x08, 0x400000fe },
1213 { 0x09, 0x404500f4 },
1214 { 0x0d, 0x400100f0 },
1215 { 0x0e, 0x90110010 },
1216 { 0x0f, 0x400100f1 },
1217 { 0x10, 0x02a1902e },
1218 { 0x11, 0x500000f2 },
1219 { 0x12, 0x500000f3 },
1220 {}
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001221};
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001222
1223static const struct hda_pintbl gateway9200_m4_2_pin_configs[] = {
1224 { 0x08, 0x400000fe },
1225 { 0x09, 0x404500f4 },
1226 { 0x0d, 0x400100f0 },
1227 { 0x0e, 0x90110010 },
1228 { 0x0f, 0x400100f1 },
1229 { 0x10, 0x02a1902e },
1230 { 0x11, 0x500000f2 },
1231 { 0x12, 0x500000f3 },
1232 {}
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001233};
1234
1235/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001236 STAC 9200 pin configs for
1237 102801A8
1238 102801DE
1239 102801E8
1240*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001241static const struct hda_pintbl dell9200_d21_pin_configs[] = {
1242 { 0x08, 0x400001f0 },
1243 { 0x09, 0x400001f1 },
1244 { 0x0d, 0x02214030 },
1245 { 0x0e, 0x01014010 },
1246 { 0x0f, 0x02a19020 },
1247 { 0x10, 0x01a19021 },
1248 { 0x11, 0x90100140 },
1249 { 0x12, 0x01813122 },
1250 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001251};
1252
1253/*
1254 STAC 9200 pin configs for
1255 102801C0
1256 102801C1
1257*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001258static const struct hda_pintbl dell9200_d22_pin_configs[] = {
1259 { 0x08, 0x400001f0 },
1260 { 0x09, 0x400001f1 },
1261 { 0x0d, 0x0221401f },
1262 { 0x0e, 0x01014010 },
1263 { 0x0f, 0x01813020 },
1264 { 0x10, 0x02a19021 },
1265 { 0x11, 0x90100140 },
1266 { 0x12, 0x400001f2 },
1267 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001268};
1269
1270/*
1271 STAC 9200 pin configs for
1272 102801C4 (Dell Dimension E310)
1273 102801C5
1274 102801C7
1275 102801D9
1276 102801DA
1277 102801E3
1278*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001279static const struct hda_pintbl dell9200_d23_pin_configs[] = {
1280 { 0x08, 0x400001f0 },
1281 { 0x09, 0x400001f1 },
1282 { 0x0d, 0x0221401f },
1283 { 0x0e, 0x01014010 },
1284 { 0x0f, 0x01813020 },
1285 { 0x10, 0x01a19021 },
1286 { 0x11, 0x90100140 },
1287 { 0x12, 0x400001f2 },
1288 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001289};
1290
1291
1292/*
1293 STAC 9200-32 pin configs for
1294 102801B5 (Dell Inspiron 630m)
1295 102801D8 (Dell Inspiron 640m)
1296*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001297static const struct hda_pintbl dell9200_m21_pin_configs[] = {
1298 { 0x08, 0x40c003fa },
1299 { 0x09, 0x03441340 },
1300 { 0x0d, 0x0321121f },
1301 { 0x0e, 0x90170310 },
1302 { 0x0f, 0x408003fb },
1303 { 0x10, 0x03a11020 },
1304 { 0x11, 0x401003fc },
1305 { 0x12, 0x403003fd },
1306 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001307};
1308
1309/*
1310 STAC 9200-32 pin configs for
1311 102801C2 (Dell Latitude D620)
1312 102801C8
1313 102801CC (Dell Latitude D820)
1314 102801D4
1315 102801D6
1316*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001317static const struct hda_pintbl dell9200_m22_pin_configs[] = {
1318 { 0x08, 0x40c003fa },
1319 { 0x09, 0x0144131f },
1320 { 0x0d, 0x0321121f },
1321 { 0x0e, 0x90170310 },
1322 { 0x0f, 0x90a70321 },
1323 { 0x10, 0x03a11020 },
1324 { 0x11, 0x401003fb },
1325 { 0x12, 0x40f000fc },
1326 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001327};
1328
1329/*
1330 STAC 9200-32 pin configs for
1331 102801CE (Dell XPS M1710)
1332 102801CF (Dell Precision M90)
1333*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001334static const struct hda_pintbl dell9200_m23_pin_configs[] = {
1335 { 0x08, 0x40c003fa },
1336 { 0x09, 0x01441340 },
1337 { 0x0d, 0x0421421f },
1338 { 0x0e, 0x90170310 },
1339 { 0x0f, 0x408003fb },
1340 { 0x10, 0x04a1102e },
1341 { 0x11, 0x90170311 },
1342 { 0x12, 0x403003fc },
1343 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001344};
1345
1346/*
1347 STAC 9200-32 pin configs for
1348 102801C9
1349 102801CA
1350 102801CB (Dell Latitude 120L)
1351 102801D3
1352*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001353static const struct hda_pintbl dell9200_m24_pin_configs[] = {
1354 { 0x08, 0x40c003fa },
1355 { 0x09, 0x404003fb },
1356 { 0x0d, 0x0321121f },
1357 { 0x0e, 0x90170310 },
1358 { 0x0f, 0x408003fc },
1359 { 0x10, 0x03a11020 },
1360 { 0x11, 0x401003fd },
1361 { 0x12, 0x403003fe },
1362 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001363};
1364
1365/*
1366 STAC 9200-32 pin configs for
1367 102801BD (Dell Inspiron E1505n)
1368 102801EE
1369 102801EF
1370*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001371static const struct hda_pintbl dell9200_m25_pin_configs[] = {
1372 { 0x08, 0x40c003fa },
1373 { 0x09, 0x01441340 },
1374 { 0x0d, 0x0421121f },
1375 { 0x0e, 0x90170310 },
1376 { 0x0f, 0x408003fb },
1377 { 0x10, 0x04a11020 },
1378 { 0x11, 0x401003fc },
1379 { 0x12, 0x403003fd },
1380 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001381};
1382
1383/*
1384 STAC 9200-32 pin configs for
1385 102801F5 (Dell Inspiron 1501)
1386 102801F6
1387*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001388static const struct hda_pintbl dell9200_m26_pin_configs[] = {
1389 { 0x08, 0x40c003fa },
1390 { 0x09, 0x404003fb },
1391 { 0x0d, 0x0421121f },
1392 { 0x0e, 0x90170310 },
1393 { 0x0f, 0x408003fc },
1394 { 0x10, 0x04a11020 },
1395 { 0x11, 0x401003fd },
1396 { 0x12, 0x403003fe },
1397 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001398};
1399
1400/*
1401 STAC 9200-32
1402 102801CD (Dell Inspiron E1705/9400)
1403*/
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001404static const struct hda_pintbl dell9200_m27_pin_configs[] = {
1405 { 0x08, 0x40c003fa },
1406 { 0x09, 0x01441340 },
1407 { 0x0d, 0x0421121f },
1408 { 0x0e, 0x90170310 },
1409 { 0x0f, 0x90170310 },
1410 { 0x10, 0x04a11020 },
1411 { 0x11, 0x90170310 },
1412 { 0x12, 0x40f003fc },
1413 {}
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001414};
1415
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001416static const struct hda_pintbl oqo9200_pin_configs[] = {
1417 { 0x08, 0x40c000f0 },
1418 { 0x09, 0x404000f1 },
1419 { 0x0d, 0x0221121f },
1420 { 0x0e, 0x02211210 },
1421 { 0x0f, 0x90170111 },
1422 { 0x10, 0x90a70120 },
1423 { 0x11, 0x400000f2 },
1424 { 0x12, 0x400000f3 },
1425 {}
Tobin Davisbf277782008-02-03 20:31:47 +01001426};
1427
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001428
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001429static void stac9200_fixup_panasonic(struct hda_codec *codec,
1430 const struct hda_fixup *fix, int action)
1431{
1432 struct sigmatel_spec *spec = codec->spec;
1433
1434 switch (action) {
1435 case HDA_FIXUP_ACT_PRE_PROBE:
1436 spec->gpio_mask = spec->gpio_dir = 0x09;
1437 spec->gpio_data = 0x00;
1438 break;
1439 case HDA_FIXUP_ACT_PROBE:
1440 /* CF-74 has no headphone detection, and the driver should *NOT*
1441 * do detection and HP/speaker toggle because the hardware does it.
1442 */
1443 spec->hp_detect = 0;
1444 break;
1445 }
1446}
1447
1448
1449static const struct hda_fixup stac9200_fixups[] = {
1450 [STAC_REF] = {
1451 .type = HDA_FIXUP_PINS,
1452 .v.pins = ref9200_pin_configs,
1453 },
1454 [STAC_9200_OQO] = {
1455 .type = HDA_FIXUP_PINS,
1456 .v.pins = oqo9200_pin_configs,
1457 .chained = true,
1458 .chain_id = STAC_9200_EAPD_INIT,
1459 },
1460 [STAC_9200_DELL_D21] = {
1461 .type = HDA_FIXUP_PINS,
1462 .v.pins = dell9200_d21_pin_configs,
1463 },
1464 [STAC_9200_DELL_D22] = {
1465 .type = HDA_FIXUP_PINS,
1466 .v.pins = dell9200_d22_pin_configs,
1467 },
1468 [STAC_9200_DELL_D23] = {
1469 .type = HDA_FIXUP_PINS,
1470 .v.pins = dell9200_d23_pin_configs,
1471 },
1472 [STAC_9200_DELL_M21] = {
1473 .type = HDA_FIXUP_PINS,
1474 .v.pins = dell9200_m21_pin_configs,
1475 },
1476 [STAC_9200_DELL_M22] = {
1477 .type = HDA_FIXUP_PINS,
1478 .v.pins = dell9200_m22_pin_configs,
1479 },
1480 [STAC_9200_DELL_M23] = {
1481 .type = HDA_FIXUP_PINS,
1482 .v.pins = dell9200_m23_pin_configs,
1483 },
1484 [STAC_9200_DELL_M24] = {
1485 .type = HDA_FIXUP_PINS,
1486 .v.pins = dell9200_m24_pin_configs,
1487 },
1488 [STAC_9200_DELL_M25] = {
1489 .type = HDA_FIXUP_PINS,
1490 .v.pins = dell9200_m25_pin_configs,
1491 },
1492 [STAC_9200_DELL_M26] = {
1493 .type = HDA_FIXUP_PINS,
1494 .v.pins = dell9200_m26_pin_configs,
1495 },
1496 [STAC_9200_DELL_M27] = {
1497 .type = HDA_FIXUP_PINS,
1498 .v.pins = dell9200_m27_pin_configs,
1499 },
1500 [STAC_9200_M4] = {
1501 .type = HDA_FIXUP_PINS,
1502 .v.pins = gateway9200_m4_pin_configs,
1503 .chained = true,
1504 .chain_id = STAC_9200_EAPD_INIT,
1505 },
1506 [STAC_9200_M4_2] = {
1507 .type = HDA_FIXUP_PINS,
1508 .v.pins = gateway9200_m4_2_pin_configs,
1509 .chained = true,
1510 .chain_id = STAC_9200_EAPD_INIT,
1511 },
1512 [STAC_9200_PANASONIC] = {
1513 .type = HDA_FIXUP_FUNC,
1514 .v.func = stac9200_fixup_panasonic,
1515 },
1516 [STAC_9200_EAPD_INIT] = {
1517 .type = HDA_FIXUP_VERBS,
1518 .v.verbs = (const struct hda_verb[]) {
1519 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
1520 {}
1521 },
1522 },
Matt Porter403d1942005-11-29 15:00:51 +01001523};
1524
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001525static const struct hda_model_fixup stac9200_models[] = {
1526 { .id = STAC_REF, .name = "ref" },
1527 { .id = STAC_9200_OQO, .name = "oqo" },
1528 { .id = STAC_9200_DELL_D21, .name = "dell-d21" },
1529 { .id = STAC_9200_DELL_D22, .name = "dell-d22" },
1530 { .id = STAC_9200_DELL_D23, .name = "dell-d23" },
1531 { .id = STAC_9200_DELL_M21, .name = "dell-m21" },
1532 { .id = STAC_9200_DELL_M22, .name = "dell-m22" },
1533 { .id = STAC_9200_DELL_M23, .name = "dell-m23" },
1534 { .id = STAC_9200_DELL_M24, .name = "dell-m24" },
1535 { .id = STAC_9200_DELL_M25, .name = "dell-m25" },
1536 { .id = STAC_9200_DELL_M26, .name = "dell-m26" },
1537 { .id = STAC_9200_DELL_M27, .name = "dell-m27" },
1538 { .id = STAC_9200_M4, .name = "gateway-m4" },
1539 { .id = STAC_9200_M4_2, .name = "gateway-m4-2" },
1540 { .id = STAC_9200_PANASONIC, .name = "panasonic" },
1541 {}
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001542};
1543
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01001544static const struct snd_pci_quirk stac9200_fixup_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001545 /* SigmaTel reference board */
1546 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1547 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001548 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1549 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001550 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001551 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1552 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001553 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001554 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1555 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1556 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1557 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1558 "unknown Dell", STAC_9200_DELL_D22),
1559 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1560 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001561 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001562 "Dell Latitude D620", STAC_9200_DELL_M22),
1563 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1564 "unknown Dell", STAC_9200_DELL_D23),
1565 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1566 "unknown Dell", STAC_9200_DELL_D23),
1567 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1568 "unknown Dell", STAC_9200_DELL_M22),
1569 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1570 "unknown Dell", STAC_9200_DELL_M24),
1571 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1572 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001573 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001574 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001575 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001576 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001577 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001578 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001579 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001580 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001581 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001582 "Dell Precision M90", STAC_9200_DELL_M23),
1583 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1584 "unknown Dell", STAC_9200_DELL_M22),
1585 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1586 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001587 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001588 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001589 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001590 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1591 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1592 "unknown Dell", STAC_9200_DELL_D23),
1593 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1594 "unknown Dell", STAC_9200_DELL_D23),
1595 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1596 "unknown Dell", STAC_9200_DELL_D21),
1597 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1598 "unknown Dell", STAC_9200_DELL_D23),
1599 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1600 "unknown Dell", STAC_9200_DELL_D21),
1601 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1602 "unknown Dell", STAC_9200_DELL_M25),
1603 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1604 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001605 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001606 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1607 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1608 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001609 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001610 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001611 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001612 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1613 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1614 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001615 /* OQO Mobile */
1616 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001617 {} /* terminator */
1618};
1619
Takashi Iwaid2077d42013-01-14 14:20:16 +01001620static const struct hda_pintbl ref925x_pin_configs[] = {
1621 { 0x07, 0x40c003f0 },
1622 { 0x08, 0x424503f2 },
1623 { 0x0a, 0x01813022 },
1624 { 0x0b, 0x02a19021 },
1625 { 0x0c, 0x90a70320 },
1626 { 0x0d, 0x02214210 },
1627 { 0x10, 0x01019020 },
1628 { 0x11, 0x9033032e },
1629 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001630};
1631
Takashi Iwaid2077d42013-01-14 14:20:16 +01001632static const struct hda_pintbl stac925xM1_pin_configs[] = {
1633 { 0x07, 0x40c003f4 },
1634 { 0x08, 0x424503f2 },
1635 { 0x0a, 0x400000f3 },
1636 { 0x0b, 0x02a19020 },
1637 { 0x0c, 0x40a000f0 },
1638 { 0x0d, 0x90100210 },
1639 { 0x10, 0x400003f1 },
1640 { 0x11, 0x9033032e },
1641 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001642};
1643
Takashi Iwaid2077d42013-01-14 14:20:16 +01001644static const struct hda_pintbl stac925xM1_2_pin_configs[] = {
1645 { 0x07, 0x40c003f4 },
1646 { 0x08, 0x424503f2 },
1647 { 0x0a, 0x400000f3 },
1648 { 0x0b, 0x02a19020 },
1649 { 0x0c, 0x40a000f0 },
1650 { 0x0d, 0x90100210 },
1651 { 0x10, 0x400003f1 },
1652 { 0x11, 0x9033032e },
1653 {}
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001654};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001655
Takashi Iwaid2077d42013-01-14 14:20:16 +01001656static const struct hda_pintbl stac925xM2_pin_configs[] = {
1657 { 0x07, 0x40c003f4 },
1658 { 0x08, 0x424503f2 },
1659 { 0x0a, 0x400000f3 },
1660 { 0x0b, 0x02a19020 },
1661 { 0x0c, 0x40a000f0 },
1662 { 0x0d, 0x90100210 },
1663 { 0x10, 0x400003f1 },
1664 { 0x11, 0x9033032e },
1665 {}
Tobin Davis2c11f952007-05-17 09:36:34 +02001666};
1667
Takashi Iwaid2077d42013-01-14 14:20:16 +01001668static const struct hda_pintbl stac925xM2_2_pin_configs[] = {
1669 { 0x07, 0x40c003f4 },
1670 { 0x08, 0x424503f2 },
1671 { 0x0a, 0x400000f3 },
1672 { 0x0b, 0x02a19020 },
1673 { 0x0c, 0x40a000f0 },
1674 { 0x0d, 0x90100210 },
1675 { 0x10, 0x400003f1 },
1676 { 0x11, 0x9033032e },
1677 {}
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001678};
1679
Takashi Iwaid2077d42013-01-14 14:20:16 +01001680static const struct hda_pintbl stac925xM3_pin_configs[] = {
1681 { 0x07, 0x40c003f4 },
1682 { 0x08, 0x424503f2 },
1683 { 0x0a, 0x400000f3 },
1684 { 0x0b, 0x02a19020 },
1685 { 0x0c, 0x40a000f0 },
1686 { 0x0d, 0x90100210 },
1687 { 0x10, 0x400003f1 },
1688 { 0x11, 0x503303f3 },
1689 {}
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001690};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001691
Takashi Iwaid2077d42013-01-14 14:20:16 +01001692static const struct hda_pintbl stac925xM5_pin_configs[] = {
1693 { 0x07, 0x40c003f4 },
1694 { 0x08, 0x424503f2 },
1695 { 0x0a, 0x400000f3 },
1696 { 0x0b, 0x02a19020 },
1697 { 0x0c, 0x40a000f0 },
1698 { 0x0d, 0x90100210 },
1699 { 0x10, 0x400003f1 },
1700 { 0x11, 0x9033032e },
1701 {}
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001702};
1703
Takashi Iwaid2077d42013-01-14 14:20:16 +01001704static const struct hda_pintbl stac925xM6_pin_configs[] = {
1705 { 0x07, 0x40c003f4 },
1706 { 0x08, 0x424503f2 },
1707 { 0x0a, 0x400000f3 },
1708 { 0x0b, 0x02a19020 },
1709 { 0x0c, 0x40a000f0 },
1710 { 0x0d, 0x90100210 },
1711 { 0x10, 0x400003f1 },
1712 { 0x11, 0x90330320 },
1713 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001714};
1715
Takashi Iwaid2077d42013-01-14 14:20:16 +01001716static const struct hda_fixup stac925x_fixups[] = {
1717 [STAC_REF] = {
1718 .type = HDA_FIXUP_PINS,
1719 .v.pins = ref925x_pin_configs,
1720 },
1721 [STAC_M1] = {
1722 .type = HDA_FIXUP_PINS,
1723 .v.pins = stac925xM1_pin_configs,
1724 },
1725 [STAC_M1_2] = {
1726 .type = HDA_FIXUP_PINS,
1727 .v.pins = stac925xM1_2_pin_configs,
1728 },
1729 [STAC_M2] = {
1730 .type = HDA_FIXUP_PINS,
1731 .v.pins = stac925xM2_pin_configs,
1732 },
1733 [STAC_M2_2] = {
1734 .type = HDA_FIXUP_PINS,
1735 .v.pins = stac925xM2_2_pin_configs,
1736 },
1737 [STAC_M3] = {
1738 .type = HDA_FIXUP_PINS,
1739 .v.pins = stac925xM3_pin_configs,
1740 },
1741 [STAC_M5] = {
1742 .type = HDA_FIXUP_PINS,
1743 .v.pins = stac925xM5_pin_configs,
1744 },
1745 [STAC_M6] = {
1746 .type = HDA_FIXUP_PINS,
1747 .v.pins = stac925xM6_pin_configs,
1748 },
Tobin Davis8e21c342007-01-08 11:04:17 +01001749};
1750
Takashi Iwaid2077d42013-01-14 14:20:16 +01001751static const struct hda_model_fixup stac925x_models[] = {
1752 { .id = STAC_REF, .name = "ref" },
1753 { .id = STAC_M1, .name = "m1" },
1754 { .id = STAC_M1_2, .name = "m1-2" },
1755 { .id = STAC_M2, .name = "m2" },
1756 { .id = STAC_M2_2, .name = "m2-2" },
1757 { .id = STAC_M3, .name = "m3" },
1758 { .id = STAC_M5, .name = "m5" },
1759 { .id = STAC_M6, .name = "m6" },
1760 {}
Tobin Davis8e21c342007-01-08 11:04:17 +01001761};
1762
Takashi Iwaid2077d42013-01-14 14:20:16 +01001763static const struct snd_pci_quirk stac925x_fixup_tbl[] = {
1764 /* SigmaTel reference board */
1765 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1766 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1767 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1768
1769 /* Default table for unknown ID */
1770 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1771
1772 /* gateway machines are checked via codec ssid */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001773 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1774 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1775 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1776 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001777 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001778 /* Not sure about the brand name for those */
1779 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1780 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1781 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1782 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001783 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001784};
1785
Takashi Iwai2b635362011-05-02 12:33:43 +02001786static const unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001787 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1788 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1789 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001790 0x01452050,
1791};
1792
Takashi Iwai2b635362011-05-02 12:33:43 +02001793static const unsigned int dell_m6_pin_configs[13] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001794 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001795 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001796 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1797 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001798};
1799
Takashi Iwai2b635362011-05-02 12:33:43 +02001800static const unsigned int alienware_m17x_pin_configs[13] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001801 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1802 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1803 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1804 0x904601b0,
1805};
1806
Takashi Iwai2b635362011-05-02 12:33:43 +02001807static const unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001808 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001809 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001810};
1811
Takashi Iwai2b635362011-05-02 12:33:43 +02001812static const unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001813 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001814 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1815 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1816 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001817 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001818 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001819 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001820};
1821
Takashi Iwaiea734962011-01-17 11:29:34 +01001822static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001823 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001824 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001825 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001826 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001827 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1828 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1829 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001830 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001831 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001832};
1833
Takashi Iwai2b635362011-05-02 12:33:43 +02001834static const struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001835 /* SigmaTel reference board */
1836 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001837 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001838 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1839 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001840 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1841 "Intel DG45ID", STAC_92HD73XX_INTEL),
1842 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1843 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001844 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001845 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001846 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001847 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001848 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
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, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001851 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001852 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
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, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001855 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001856 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001857 "unknown Dell", STAC_DELL_M6_DMIC),
1858 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1859 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001860 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001861 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001862 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1863 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001864 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1865 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001866 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1867 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001868 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
David Henningssonffe535e2012-01-16 10:52:20 +01001869 "Dell Studio XPS 1645", STAC_DELL_M6_DMIC),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001870 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
David Henningssone033ebf2011-05-16 12:09:29 +02001871 "Dell Studio 1558", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001872 {} /* terminator */
1873};
1874
Takashi Iwai2b635362011-05-02 12:33:43 +02001875static const struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
Takashi Iwai842ae632009-09-02 07:43:08 +02001876 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1877 "Alienware M17x", STAC_ALIENWARE_M17X),
Daniel T Chen0defe092010-12-01 19:16:07 -05001878 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1879 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwaidbd1b542011-11-19 11:41:30 +01001880 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490,
Albert Poolb9ecc4e2012-01-19 22:08:50 +01001881 "Alienware M17x R3", STAC_DELL_EQ),
Takashi Iwai842ae632009-09-02 07:43:08 +02001882 {} /* terminator */
1883};
1884
Takashi Iwai2b635362011-05-02 12:33:43 +02001885static const unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001886 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1887 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001888 0x01451160, 0x98560170,
1889};
1890
Takashi Iwai2b635362011-05-02 12:33:43 +02001891static const unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001892 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1893 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001894 0x40f000f0, 0x40f000f0,
1895};
1896
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001897static const unsigned int dell_vostro_3500_pin_configs[10] = {
1898 0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
1899 0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
1900 0x400000f4, 0x400000f5,
1901};
1902
Takashi Iwai2b635362011-05-02 12:33:43 +02001903static const unsigned int hp_dv7_4000_pin_configs[10] = {
Steven Eastland48315592010-08-06 15:07:35 -06001904 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1905 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1906 0x40f000f0, 0x40f000f0,
1907};
1908
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06001909static const unsigned int hp_zephyr_pin_configs[10] = {
1910 0x01813050, 0x0421201f, 0x04a1205e, 0x96130310,
1911 0x96130310, 0x0101401f, 0x1111611f, 0xd5a30130,
1912 0, 0,
1913};
1914
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001915static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
1916 0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
1917 0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
1918 0x40f000f0, 0x40f000f0,
1919};
1920
Takashi Iwai2b635362011-05-02 12:33:43 +02001921static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001922 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001923 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001924 [STAC_DELL_S14] = dell_s14_pin_configs,
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001925 [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001926 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001927 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06001928 [STAC_HP_ZEPHYR] = hp_zephyr_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001929};
1930
Takashi Iwaiea734962011-01-17 11:29:34 +01001931static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001932 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001933 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001934 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001935 [STAC_DELL_S14] = "dell-s14",
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001936 [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001937 [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
Steven Eastland48315592010-08-06 15:07:35 -06001938 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06001939 [STAC_HP_ZEPHYR] = "hp-zephyr",
Takashi Iwaia3e19972012-07-26 08:17:20 +02001940 [STAC_92HD83XXX_HP_LED] = "hp-led",
Takashi Iwaiff8a1e22012-07-31 10:16:59 +02001941 [STAC_92HD83XXX_HP_INV_LED] = "hp-inv-led",
Takashi Iwai62cbde12012-09-14 11:58:54 +02001942 [STAC_92HD83XXX_HP_MIC_LED] = "hp-mic-led",
David Henningsson8d032a82012-10-09 12:48:40 +02001943 [STAC_92HD83XXX_HEADSET_JACK] = "headset-jack",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001944};
1945
Takashi Iwai2b635362011-05-02 12:33:43 +02001946static const struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001947 /* SigmaTel reference board */
1948 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001949 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001950 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1951 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001952 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1953 "unknown Dell", STAC_DELL_S14),
David Henningsson8d032a82012-10-09 12:48:40 +02001954 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0532,
1955 "Dell Latitude E6230", STAC_92HD83XXX_HEADSET_JACK),
1956 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0533,
1957 "Dell Latitude E6330", STAC_92HD83XXX_HEADSET_JACK),
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0534,
1959 "Dell Latitude E6430", STAC_92HD83XXX_HEADSET_JACK),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0535,
1961 "Dell Latitude E6530", STAC_92HD83XXX_HEADSET_JACK),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x053c,
1963 "Dell Latitude E5430", STAC_92HD83XXX_HEADSET_JACK),
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x053d,
1965 "Dell Latitude E5530", STAC_92HD83XXX_HEADSET_JACK),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0549,
1967 "Dell Latitude E5430", STAC_92HD83XXX_HEADSET_JACK),
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x057d,
1969 "Dell Latitude E6430s", STAC_92HD83XXX_HEADSET_JACK),
1970 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0584,
1971 "Dell Latitude E6430U", STAC_92HD83XXX_HEADSET_JACK),
Julian Wollrathf7f9bdf2011-11-09 10:02:40 +01001972 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
1973 "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001974 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
1975 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1976 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
1977 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1978 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
1979 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1980 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
Takashi Iwai8ae58652012-12-13 14:33:42 +01001981 "HP Pavilion dv7", STAC_HP_DV7_4000),
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001982 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
1983 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
1985 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Takashi Iwai62cbde12012-09-14 11:58:54 +02001986 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x18df,
1987 "HP Folio", STAC_92HD83XXX_HP_MIC_LED),
Vitaliy Kulikov0c27c182011-07-22 17:50:37 -05001988 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
1989 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
1991 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1992 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
1993 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1994 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
1995 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1996 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
1997 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1998 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
1999 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2000 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
2001 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2002 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
2003 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2004 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
2005 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2006 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
2007 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2008 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
2009 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2010 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
2011 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2012 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
2013 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
2014 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
2015 "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06002016 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3561,
2017 "HP", STAC_HP_ZEPHYR),
Takashi Iwaia3e19972012-07-26 08:17:20 +02002018 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3660,
2019 "HP Mini", STAC_92HD83XXX_HP_LED),
Gustavo Maciel Dias Vieira5afc13a2012-10-26 12:51:53 -02002020 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x144E,
2021 "HP Pavilion dv5", STAC_92HD83XXX_HP_INV_LED),
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06002022 {} /* terminator */
2023};
2024
2025static const struct snd_pci_quirk stac92hd83xxx_codec_id_cfg_tbl[] = {
2026 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3561,
2027 "HP", STAC_HP_ZEPHYR),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02002028 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02002029};
2030
Takashi Iwai2b635362011-05-02 12:33:43 +02002031static const unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01002032 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04002033 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002034 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
2035 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01002036};
2037
Takashi Iwai2b635362011-05-02 12:33:43 +02002038static const unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01002039 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01002040 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002041 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
2042 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01002043};
2044
Takashi Iwai2b635362011-05-02 12:33:43 +02002045static const unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01002046 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
2047 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002048 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
2049 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01002050};
2051
Takashi Iwai2b635362011-05-02 12:33:43 +02002052static const unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002053 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
2054 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05002055 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
2056 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002057};
2058
Takashi Iwai2b635362011-05-02 12:33:43 +02002059static const unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01002060 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01002061 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
2062 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002063 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04002064 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02002065 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01002066 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01002067 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04002068 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01002069};
2070
Takashi Iwaiea734962011-01-17 11:29:34 +01002071static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002072 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01002073 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01002074 [STAC_DELL_M4_1] = "dell-m4-1",
2075 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002076 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04002077 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02002078 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01002079 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01002080 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04002081 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01002082};
2083
Takashi Iwai2b635362011-05-02 12:33:43 +02002084static const struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01002085 /* SigmaTel reference board */
2086 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2087 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002088 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2089 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04002090 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
2091 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01002092 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
2093 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01002094 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
2095 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01002096 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02002097 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01002098 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
2099 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01002100 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
2101 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04002102 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01002103 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01002104 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01002105 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02002106 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
2107 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05302108 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
2109 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11002110 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
2111 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02002112 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
2113 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01002114 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
2115 "unknown Dell", STAC_DELL_M4_1),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
2117 "unknown Dell", STAC_DELL_M4_1),
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
2119 "unknown Dell", STAC_DELL_M4_1),
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
2121 "unknown Dell", STAC_DELL_M4_1),
2122 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
2123 "unknown Dell", STAC_DELL_M4_1),
2124 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
2125 "unknown Dell", STAC_DELL_M4_1),
2126 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
2127 "unknown Dell", STAC_DELL_M4_1),
2128 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
2129 "unknown Dell", STAC_DELL_M4_2),
2130 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
2131 "unknown Dell", STAC_DELL_M4_2),
2132 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
2133 "unknown Dell", STAC_DELL_M4_2),
2134 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
2135 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05002136 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
2137 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01002138 {} /* terminator */
2139};
2140
Takashi Iwai2b635362011-05-02 12:33:43 +02002141static const unsigned int ref922x_pin_configs[10] = {
Matt Porter403d1942005-11-29 15:00:51 +01002142 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
2143 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02002144 0x40000100, 0x40000100,
2145};
2146
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002147/*
2148 STAC 922X pin configs for
2149 102801A7
2150 102801AB
2151 102801A9
2152 102801D1
2153 102801D2
2154*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002155static const unsigned int dell_922x_d81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002156 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
2157 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
2158 0x01813122, 0x400001f2,
2159};
2160
2161/*
2162 STAC 922X pin configs for
2163 102801AC
2164 102801D0
2165*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002166static const unsigned int dell_922x_d82_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002167 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
2168 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
2169 0x01813122, 0x400001f1,
2170};
2171
2172/*
2173 STAC 922X pin configs for
2174 102801BF
2175*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002176static const unsigned int dell_922x_m81_pin_configs[10] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002177 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
2178 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
2179 0x40C003f1, 0x405003f0,
2180};
2181
2182/*
2183 STAC 9221 A1 pin configs for
2184 102801D7 (Dell XPS M1210)
2185*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002186static const unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01002187 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
2188 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002189 0x508003f3, 0x405003f4,
2190};
2191
Takashi Iwai2b635362011-05-02 12:33:43 +02002192static const unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01002193 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01002194 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2195 0x02a19120, 0x40000100,
2196};
2197
Takashi Iwai2b635362011-05-02 12:33:43 +02002198static const unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01002199 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
2200 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01002201 0x02a19320, 0x40000100,
2202};
2203
Takashi Iwai2b635362011-05-02 12:33:43 +02002204static const unsigned int intel_mac_v1_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002205 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
2206 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002207 0x400000fc, 0x400000fb,
2208};
2209
Takashi Iwai2b635362011-05-02 12:33:43 +02002210static const unsigned int intel_mac_v2_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002211 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2212 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02002213 0x400000fc, 0x400000fb,
2214};
2215
Takashi Iwai2b635362011-05-02 12:33:43 +02002216static const unsigned int intel_mac_v3_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002217 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2218 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
2219 0x400000fc, 0x400000fb,
2220};
2221
Takashi Iwai2b635362011-05-02 12:33:43 +02002222static const unsigned int intel_mac_v4_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002223 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2224 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2225 0x400000fc, 0x400000fb,
2226};
2227
Takashi Iwai2b635362011-05-02 12:33:43 +02002228static const unsigned int intel_mac_v5_pin_configs[10] = {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002229 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2230 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2231 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002232};
2233
Takashi Iwai2b635362011-05-02 12:33:43 +02002234static const unsigned int ecs202_pin_configs[10] = {
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002235 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
2236 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
2237 0x9037012e, 0x40e000f2,
2238};
Takashi Iwai76c08822007-06-19 12:17:42 +02002239
Takashi Iwai2b635362011-05-02 12:33:43 +02002240static const unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002241 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002242 [STAC_D945GTP3] = d945gtp3_pin_configs,
2243 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002244 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
2245 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
2246 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
2247 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
2248 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002249 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002250 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002251 [STAC_MACMINI] = intel_mac_v3_pin_configs,
2252 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2253 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2254 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2255 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2256 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002257 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002258 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2259 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2260 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2261 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01002262};
2263
Takashi Iwaiea734962011-01-17 11:29:34 +01002264static const char * const stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002265 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002266 [STAC_D945_REF] = "ref",
2267 [STAC_D945GTP5] = "5stack",
2268 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002269 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2270 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2271 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2272 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2273 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08002274 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002275 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002276 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002277 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002278 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2279 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02002280 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002281 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002282 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002283 [STAC_922X_DELL_D81] = "dell-d81",
2284 [STAC_922X_DELL_D82] = "dell-d82",
2285 [STAC_922X_DELL_M81] = "dell-m81",
2286 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002287};
2288
Takashi Iwai2b635362011-05-02 12:33:43 +02002289static const struct snd_pci_quirk stac922x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002290 /* SigmaTel reference board */
2291 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2292 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002293 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2294 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002295 /* Intel 945G based systems */
2296 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2297 "Intel D945G", STAC_D945GTP3),
2298 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2299 "Intel D945G", STAC_D945GTP3),
2300 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2301 "Intel D945G", STAC_D945GTP3),
2302 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2303 "Intel D945G", STAC_D945GTP3),
2304 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2305 "Intel D945G", STAC_D945GTP3),
2306 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2307 "Intel D945G", STAC_D945GTP3),
2308 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2309 "Intel D945G", STAC_D945GTP3),
2310 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2311 "Intel D945G", STAC_D945GTP3),
2312 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2313 "Intel D945G", STAC_D945GTP3),
2314 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2315 "Intel D945G", STAC_D945GTP3),
2316 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2317 "Intel D945G", STAC_D945GTP3),
2318 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2319 "Intel D945G", STAC_D945GTP3),
2320 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2321 "Intel D945G", STAC_D945GTP3),
2322 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2323 "Intel D945G", STAC_D945GTP3),
2324 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2325 "Intel D945G", STAC_D945GTP3),
2326 /* Intel D945G 5-stack systems */
2327 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2328 "Intel D945G", STAC_D945GTP5),
2329 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2330 "Intel D945G", STAC_D945GTP5),
2331 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2332 "Intel D945G", STAC_D945GTP5),
2333 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2334 "Intel D945G", STAC_D945GTP5),
2335 /* Intel 945P based systems */
2336 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2337 "Intel D945P", STAC_D945GTP3),
2338 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2339 "Intel D945P", STAC_D945GTP3),
2340 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2341 "Intel D945P", STAC_D945GTP3),
2342 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2343 "Intel D945P", STAC_D945GTP3),
2344 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2345 "Intel D945P", STAC_D945GTP3),
2346 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2347 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002348 /* other intel */
2349 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2350 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002351 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002352 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002353 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002354 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002355 /* Dell systems */
2356 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2357 "unknown Dell", STAC_922X_DELL_D81),
2358 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2359 "unknown Dell", STAC_922X_DELL_D81),
2360 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2361 "unknown Dell", STAC_922X_DELL_D81),
2362 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2363 "unknown Dell", STAC_922X_DELL_D82),
2364 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2365 "unknown Dell", STAC_922X_DELL_M81),
2366 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2367 "unknown Dell", STAC_922X_DELL_D82),
2368 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2369 "unknown Dell", STAC_922X_DELL_D81),
2370 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2371 "unknown Dell", STAC_922X_DELL_D81),
2372 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2373 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002374 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002375 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002376 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002377 {} /* terminator */
2378};
2379
Takashi Iwai2b635362011-05-02 12:33:43 +02002380static const unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002381 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2382 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2383 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2384 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002385};
2386
Takashi Iwai2b635362011-05-02 12:33:43 +02002387static const unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002388 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2389 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2390 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2391 0x40000100, 0x40000100
2392};
2393
Takashi Iwai2b635362011-05-02 12:33:43 +02002394static const unsigned int d965_5st_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002395 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2396 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2397 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2398 0x40000100, 0x40000100
2399};
2400
Takashi Iwai2b635362011-05-02 12:33:43 +02002401static const unsigned int d965_5st_no_fp_pin_configs[14] = {
Takashi Iwai679d92e2009-05-24 19:00:08 +02002402 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2403 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2404 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2405 0x40000100, 0x40000100
2406};
2407
Takashi Iwai2b635362011-05-02 12:33:43 +02002408static const unsigned int dell_3st_pin_configs[14] = {
Tobin Davis4ff076e2007-08-07 11:48:12 +02002409 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2410 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002411 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002412 0x40c003fc, 0x40000100
2413};
2414
Takashi Iwai2b635362011-05-02 12:33:43 +02002415static const unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002416 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002417 [STAC_D965_REF] = ref927x_pin_configs,
2418 [STAC_D965_3ST] = d965_3st_pin_configs,
2419 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002420 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002421 [STAC_DELL_3ST] = dell_3st_pin_configs,
2422 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002423 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002424};
2425
Takashi Iwaiea734962011-01-17 11:29:34 +01002426static const char * const stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002427 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002428 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002429 [STAC_D965_REF] = "ref",
2430 [STAC_D965_3ST] = "3stack",
2431 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002432 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002433 [STAC_DELL_3ST] = "dell-3stack",
2434 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002435 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002436};
2437
Takashi Iwai2b635362011-05-02 12:33:43 +02002438static const struct snd_pci_quirk stac927x_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002439 /* SigmaTel reference board */
2440 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2441 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002442 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2443 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002444 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002445 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2446 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002447 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002448 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2449 "Intel D965", STAC_D965_3ST),
2450 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2451 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002452 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002453 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002454 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2455 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002456 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002457 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002458 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002459 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002460 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002461 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002462 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2463 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2464 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2465 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002466 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002467 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2468 "Intel D965", STAC_D965_5ST),
2469 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2470 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002471 /* volume-knob fixes */
2472 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002473 {} /* terminator */
2474};
2475
Takashi Iwai2b635362011-05-02 12:33:43 +02002476static const unsigned int ref9205_pin_configs[12] = {
Matt Porterf3302a52006-07-31 12:49:34 +02002477 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002478 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002479 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002480};
2481
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002482/*
2483 STAC 9205 pin configs for
2484 102801F1
2485 102801F2
2486 102801FC
2487 102801FD
2488 10280204
2489 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002490 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002491 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002492*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002493static const unsigned int dell_9205_m42_pin_configs[12] = {
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002494 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2495 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2496 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2497};
2498
2499/*
2500 STAC 9205 pin configs for
2501 102801F9
2502 102801FA
2503 102801FE
2504 102801FF (Dell Precision M4300)
2505 10280206
2506 10280200
2507 10280201
2508*/
Takashi Iwai2b635362011-05-02 12:33:43 +02002509static const unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002510 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2511 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2512 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2513};
2514
Takashi Iwai2b635362011-05-02 12:33:43 +02002515static const unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002516 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2517 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2518 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2519};
2520
Takashi Iwai2b635362011-05-02 12:33:43 +02002521static const unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002522 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002523 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2524 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2525 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002526 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002527};
2528
Takashi Iwaiea734962011-01-17 11:29:34 +01002529static const char * const stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002530 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002531 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002532 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002533 [STAC_9205_DELL_M43] = "dell-m43",
2534 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002535 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002536};
2537
Takashi Iwai2b635362011-05-02 12:33:43 +02002538static const struct snd_pci_quirk stac9205_cfg_tbl[] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002539 /* SigmaTel reference board */
2540 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2541 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002542 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2543 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002544 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2545 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002546 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002547 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2548 "unknown Dell", STAC_9205_DELL_M42),
2549 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2550 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002551 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002552 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002553 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2554 "Dell Precision", STAC_9205_DELL_M43),
2555 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2556 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002557 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2558 "unknown Dell", STAC_9205_DELL_M42),
2559 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2560 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002561 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2562 "Dell Precision", STAC_9205_DELL_M43),
2563 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002564 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002565 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2566 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002567 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2568 "Dell Precision", STAC_9205_DELL_M43),
2569 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2570 "Dell Precision", STAC_9205_DELL_M43),
2571 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2572 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002573 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2574 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002575 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2576 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002577 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2578 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002579 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002580 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002581 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002582 {} /* terminator */
2583};
2584
Takashi Iwai330ee992009-02-20 14:33:36 +01002585static void stac92xx_set_config_regs(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02002586 const unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002587{
2588 int i;
2589 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002590
Takashi Iwai330ee992009-02-20 14:33:36 +01002591 if (!pincfgs)
2592 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002593
Matthew Ranostay87d48362007-07-17 11:52:24 +02002594 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002595 if (spec->pin_nids[i] && pincfgs[i])
2596 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2597 pincfgs[i]);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002598}
2599
Matt2f2f4252005-04-13 14:45:30 +02002600/*
2601 * Analog playback callbacks
2602 */
2603static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2604 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002605 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002606{
2607 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002608 if (spec->stream_delay)
2609 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002610 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2611 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002612}
2613
2614static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2615 struct hda_codec *codec,
2616 unsigned int stream_tag,
2617 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002618 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002619{
2620 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002621 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002622}
2623
2624static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2625 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002626 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002627{
2628 struct sigmatel_spec *spec = codec->spec;
2629 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2630}
2631
2632/*
Mattdabbed62005-06-14 10:19:34 +02002633 * Digital playback callbacks
2634 */
2635static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2636 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002637 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002638{
2639 struct sigmatel_spec *spec = codec->spec;
2640 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2641}
2642
2643static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2644 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002645 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002646{
2647 struct sigmatel_spec *spec = codec->spec;
2648 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2649}
2650
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002651static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2652 struct hda_codec *codec,
2653 unsigned int stream_tag,
2654 unsigned int format,
2655 struct snd_pcm_substream *substream)
2656{
2657 struct sigmatel_spec *spec = codec->spec;
2658 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2659 stream_tag, format, substream);
2660}
2661
Takashi Iwai9411e212009-02-13 11:32:28 +01002662static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2663 struct hda_codec *codec,
2664 struct snd_pcm_substream *substream)
2665{
2666 struct sigmatel_spec *spec = codec->spec;
2667 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2668}
2669
Mattdabbed62005-06-14 10:19:34 +02002670
2671/*
Matt2f2f4252005-04-13 14:45:30 +02002672 * Analog capture callbacks
2673 */
2674static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2675 struct hda_codec *codec,
2676 unsigned int stream_tag,
2677 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002678 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002679{
2680 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002681 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002682
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002683 if (spec->powerdown_adcs) {
2684 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002685 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002686 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2687 }
2688 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002689 return 0;
2690}
2691
2692static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2693 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002694 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002695{
2696 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002697 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002698
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002699 snd_hda_codec_cleanup_stream(codec, nid);
2700 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002701 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002702 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002703 return 0;
2704}
2705
Takashi Iwai2b635362011-05-02 12:33:43 +02002706static const struct hda_pcm_stream stac92xx_pcm_digital_playback = {
Mattdabbed62005-06-14 10:19:34 +02002707 .substreams = 1,
2708 .channels_min = 2,
2709 .channels_max = 2,
2710 /* NID is set in stac92xx_build_pcms */
2711 .ops = {
2712 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002713 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002714 .prepare = stac92xx_dig_playback_pcm_prepare,
2715 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002716 },
2717};
2718
Takashi Iwai2b635362011-05-02 12:33:43 +02002719static const struct hda_pcm_stream stac92xx_pcm_digital_capture = {
Mattdabbed62005-06-14 10:19:34 +02002720 .substreams = 1,
2721 .channels_min = 2,
2722 .channels_max = 2,
2723 /* NID is set in stac92xx_build_pcms */
2724};
2725
Takashi Iwai2b635362011-05-02 12:33:43 +02002726static const struct hda_pcm_stream stac92xx_pcm_analog_playback = {
Matt2f2f4252005-04-13 14:45:30 +02002727 .substreams = 1,
2728 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002729 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002730 .nid = 0x02, /* NID to query formats and rates */
2731 .ops = {
2732 .open = stac92xx_playback_pcm_open,
2733 .prepare = stac92xx_playback_pcm_prepare,
2734 .cleanup = stac92xx_playback_pcm_cleanup
2735 },
2736};
2737
Takashi Iwai2b635362011-05-02 12:33:43 +02002738static const struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
Matt Porter3cc08dc2006-01-23 15:27:49 +01002739 .substreams = 1,
2740 .channels_min = 2,
2741 .channels_max = 2,
2742 .nid = 0x06, /* NID to query formats and rates */
2743 .ops = {
2744 .open = stac92xx_playback_pcm_open,
2745 .prepare = stac92xx_playback_pcm_prepare,
2746 .cleanup = stac92xx_playback_pcm_cleanup
2747 },
2748};
2749
Takashi Iwai2b635362011-05-02 12:33:43 +02002750static const struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002751 .channels_min = 2,
2752 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002753 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002754 .ops = {
2755 .prepare = stac92xx_capture_pcm_prepare,
2756 .cleanup = stac92xx_capture_pcm_cleanup
2757 },
2758};
2759
2760static int stac92xx_build_pcms(struct hda_codec *codec)
2761{
2762 struct sigmatel_spec *spec = codec->spec;
2763 struct hda_pcm *info = spec->pcm_rec;
2764
2765 codec->num_pcms = 1;
2766 codec->pcm_info = info;
2767
Mattc7d4b2f2005-06-27 14:59:41 +02002768 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002769 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002770 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2771 spec->multiout.dac_nids[0];
Takashi Iwaiee81abb2012-11-08 17:12:10 +01002772 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2773 spec->autocfg.line_outs == 2)
2774 info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
2775 snd_pcm_2_1_chmaps;
2776
Matt2f2f4252005-04-13 14:45:30 +02002777 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002778 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002779 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002780
2781 if (spec->alt_switch) {
2782 codec->num_pcms++;
2783 info++;
2784 info->name = "STAC92xx Analog Alt";
2785 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2786 }
Matt2f2f4252005-04-13 14:45:30 +02002787
Mattdabbed62005-06-14 10:19:34 +02002788 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2789 codec->num_pcms++;
2790 info++;
2791 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002792 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002793 if (spec->multiout.dig_out_nid) {
2794 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2795 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2796 }
2797 if (spec->dig_in_nid) {
2798 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2799 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2800 }
2801 }
2802
Matt2f2f4252005-04-13 14:45:30 +02002803 return 0;
2804}
2805
Matt Porter403d1942005-11-29 15:00:51 +01002806static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2807
2808{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002809 snd_hda_set_pin_ctl_cache(codec, nid, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002810}
2811
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002812#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2813
2814static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2815 struct snd_ctl_elem_value *ucontrol)
2816{
2817 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2818 struct sigmatel_spec *spec = codec->spec;
2819
Takashi Iwaid7a89432008-11-12 09:48:04 +01002820 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002821 return 0;
2822}
2823
Takashi Iwai62558ce2009-07-29 14:23:09 +02002824static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002825
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002826static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2827 struct snd_ctl_elem_value *ucontrol)
2828{
2829 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2830 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002831 int nid = kcontrol->private_value;
2832
2833 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002834
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002835 /* check to be sure that the ports are up to date with
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002836 * switch changes
2837 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002838 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002839
2840 return 1;
2841}
2842
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002843static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2844 struct snd_ctl_elem_info *uinfo)
2845{
2846 int i;
Takashi Iwai2b635362011-05-02 12:33:43 +02002847 static const char * const texts[] = {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002848 "Mic In", "Line In", "Line Out"
2849 };
2850
2851 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2852 struct sigmatel_spec *spec = codec->spec;
2853 hda_nid_t nid = kcontrol->private_value;
2854
2855 if (nid == spec->mic_switch || nid == spec->line_switch)
2856 i = 3;
2857 else
2858 i = 2;
2859
2860 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2861 uinfo->value.enumerated.items = i;
2862 uinfo->count = 1;
2863 if (uinfo->value.enumerated.item >= i)
2864 uinfo->value.enumerated.item = i-1;
2865 strcpy(uinfo->value.enumerated.name,
2866 texts[uinfo->value.enumerated.item]);
2867
2868 return 0;
2869}
2870
2871static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2872 struct snd_ctl_elem_value *ucontrol)
2873{
2874 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2875 hda_nid_t nid = kcontrol->private_value;
2876 unsigned int vref = stac92xx_vref_get(codec, nid);
2877
Takashi Iwai47408602012-04-20 13:06:53 +02002878 if (vref == snd_hda_get_default_vref(codec, nid))
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002879 ucontrol->value.enumerated.item[0] = 0;
2880 else if (vref == AC_PINCTL_VREF_GRD)
2881 ucontrol->value.enumerated.item[0] = 1;
2882 else if (vref == AC_PINCTL_VREF_HIZ)
2883 ucontrol->value.enumerated.item[0] = 2;
2884
2885 return 0;
2886}
2887
2888static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2889 struct snd_ctl_elem_value *ucontrol)
2890{
2891 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2892 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002893 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002894 hda_nid_t nid = kcontrol->private_value;
2895
2896 if (ucontrol->value.enumerated.item[0] == 0)
Takashi Iwai47408602012-04-20 13:06:53 +02002897 new_vref = snd_hda_get_default_vref(codec, nid);
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002898 else if (ucontrol->value.enumerated.item[0] == 1)
2899 new_vref = AC_PINCTL_VREF_GRD;
2900 else if (ucontrol->value.enumerated.item[0] == 2)
2901 new_vref = AC_PINCTL_VREF_HIZ;
2902 else
2903 return 0;
2904
2905 if (new_vref != stac92xx_vref_get(codec, nid)) {
2906 error = stac92xx_vref_set(codec, nid, new_vref);
2907 return error;
2908 }
2909
2910 return 0;
2911}
2912
2913static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2914 struct snd_ctl_elem_info *uinfo)
2915{
Takashi Iwai2b635362011-05-02 12:33:43 +02002916 char *texts[2];
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002917 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2918 struct sigmatel_spec *spec = codec->spec;
2919
2920 if (kcontrol->private_value == spec->line_switch)
2921 texts[0] = "Line In";
2922 else
2923 texts[0] = "Mic In";
2924 texts[1] = "Line Out";
2925 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2926 uinfo->value.enumerated.items = 2;
2927 uinfo->count = 1;
2928
2929 if (uinfo->value.enumerated.item >= 2)
2930 uinfo->value.enumerated.item = 1;
2931 strcpy(uinfo->value.enumerated.name,
2932 texts[uinfo->value.enumerated.item]);
2933
2934 return 0;
2935}
Matt Porter403d1942005-11-29 15:00:51 +01002936
2937static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2938{
2939 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2940 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002941 hda_nid_t nid = kcontrol->private_value;
2942 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002943
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002944 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002945 return 0;
2946}
2947
2948static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2949{
2950 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2951 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002952 hda_nid_t nid = kcontrol->private_value;
2953 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2954 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002955
2956 spec->io_switch[io_idx] = val;
2957
2958 if (val)
2959 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002960 else {
2961 unsigned int pinctl = AC_PINCTL_IN_EN;
2962 if (io_idx) /* set VREF for mic */
Takashi Iwai47408602012-04-20 13:06:53 +02002963 pinctl |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002964 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2965 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002966
2967 /* check the auto-mute again: we need to mute/unmute the speaker
2968 * appropriately according to the pin direction
2969 */
2970 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002971 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002972
Matt Porter403d1942005-11-29 15:00:51 +01002973 return 1;
2974}
2975
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002976#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2977
2978static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2979 struct snd_ctl_elem_value *ucontrol)
2980{
2981 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2982 struct sigmatel_spec *spec = codec->spec;
2983
2984 ucontrol->value.integer.value[0] = spec->clfe_swap;
2985 return 0;
2986}
2987
2988static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2989 struct snd_ctl_elem_value *ucontrol)
2990{
2991 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2992 struct sigmatel_spec *spec = codec->spec;
2993 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002994 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002995
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002996 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002997 return 0;
2998
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002999 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003000
3001 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
3002 spec->clfe_swap ? 0x4 : 0x0);
3003
3004 return 1;
3005}
3006
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003007#define STAC_CODEC_HP_SWITCH(xname) \
3008 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3009 .name = xname, \
3010 .index = 0, \
3011 .info = stac92xx_hp_switch_info, \
3012 .get = stac92xx_hp_switch_get, \
3013 .put = stac92xx_hp_switch_put, \
3014 }
3015
Matt Porter403d1942005-11-29 15:00:51 +01003016#define STAC_CODEC_IO_SWITCH(xname, xpval) \
3017 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3018 .name = xname, \
3019 .index = 0, \
3020 .info = stac92xx_io_switch_info, \
3021 .get = stac92xx_io_switch_get, \
3022 .put = stac92xx_io_switch_put, \
3023 .private_value = xpval, \
3024 }
3025
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003026#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
3027 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3028 .name = xname, \
3029 .index = 0, \
3030 .info = stac92xx_clfe_switch_info, \
3031 .get = stac92xx_clfe_switch_get, \
3032 .put = stac92xx_clfe_switch_put, \
3033 .private_value = xpval, \
3034 }
Matt Porter403d1942005-11-29 15:00:51 +01003035
Mattc7d4b2f2005-06-27 14:59:41 +02003036enum {
3037 STAC_CTL_WIDGET_VOL,
3038 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003039 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01003040 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003041 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01003042 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02003043 STAC_CTL_WIDGET_CLFE_SWITCH,
3044 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02003045};
3046
Takashi Iwai2b635362011-05-02 12:33:43 +02003047static const struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02003048 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
3049 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003050 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01003051 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003052 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01003053 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003054 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02003055 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02003056};
3057
3058/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01003059static struct snd_kcontrol_new *
3060stac_control_new(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02003061 const struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01003062 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01003063 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02003064{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01003065 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02003066
Takashi Iwai603c4012008-07-30 15:01:44 +02003067 knew = snd_array_new(&spec->kctls);
3068 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01003069 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003070 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02003071 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01003072 if (!knew->name) {
3073 /* roolback */
3074 memset(knew, 0, sizeof(*knew));
3075 spec->kctls.alloced--;
3076 return NULL;
3077 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01003078 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01003079 return knew;
3080}
3081
Takashi Iwai62cbde12012-09-14 11:58:54 +02003082static struct snd_kcontrol_new *
3083add_control_temp(struct sigmatel_spec *spec,
3084 const struct snd_kcontrol_new *ktemp,
3085 int idx, const char *name,
3086 unsigned long val)
3087{
3088 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
3089 HDA_SUBDEV_AMP_FLAG);
3090 if (!knew)
3091 return NULL;
3092 knew->index = idx;
3093 knew->private_value = val;
3094 return knew;
3095}
3096
Takashi Iwaie3c75962009-01-23 11:57:22 +01003097static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
Takashi Iwai2b635362011-05-02 12:33:43 +02003098 const struct snd_kcontrol_new *ktemp,
Takashi Iwaie3c75962009-01-23 11:57:22 +01003099 int idx, const char *name,
3100 unsigned long val)
3101{
Takashi Iwai62cbde12012-09-14 11:58:54 +02003102 return add_control_temp(spec, ktemp, idx, name, val) ? 0 : -ENOMEM;
Mattc7d4b2f2005-06-27 14:59:41 +02003103}
3104
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003105static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
3106 int type, int idx, const char *name,
3107 unsigned long val)
3108{
3109 return stac92xx_add_control_temp(spec,
3110 &stac92xx_control_templates[type],
3111 idx, name, val);
3112}
3113
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003114
3115/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003116static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
3117 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003118{
3119 return stac92xx_add_control_idx(spec, type, 0, name, val);
3120}
3121
Takashi Iwai2b635362011-05-02 12:33:43 +02003122static const struct snd_kcontrol_new stac_input_src_temp = {
Takashi Iwaie3c75962009-01-23 11:57:22 +01003123 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3124 .name = "Input Source",
3125 .info = stac92xx_mux_enum_info,
3126 .get = stac92xx_mux_enum_get,
3127 .put = stac92xx_mux_enum_put,
3128};
3129
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003130static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
3131 hda_nid_t nid, int idx)
3132{
3133 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
3134 int control = 0;
3135 struct sigmatel_spec *spec = codec->spec;
3136 char name[22];
3137
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003138 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
David Henningsson8d032a82012-10-09 12:48:40 +02003139 if (spec->headset_jack && snd_hda_get_input_pin_attr(def_conf)
3140 != INPUT_PIN_ATTR_DOCK)
3141 return 0;
Takashi Iwai47408602012-04-20 13:06:53 +02003142 if (snd_hda_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003143 && nid == spec->line_switch)
3144 control = STAC_CTL_WIDGET_IO_SWITCH;
3145 else if (snd_hda_query_pin_caps(codec, nid)
3146 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
3147 control = STAC_CTL_WIDGET_DC_BIAS;
3148 else if (nid == spec->mic_switch)
3149 control = STAC_CTL_WIDGET_IO_SWITCH;
3150 }
3151
3152 if (control) {
Takashi Iwai201e06f2011-11-16 15:33:26 +01003153 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
3154 name, sizeof(name), NULL);
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003155 return stac92xx_add_control(codec->spec, control,
3156 strcat(name, " Jack Mode"), nid);
3157 }
3158
3159 return 0;
3160}
3161
Takashi Iwaie3c75962009-01-23 11:57:22 +01003162static int stac92xx_add_input_source(struct sigmatel_spec *spec)
3163{
3164 struct snd_kcontrol_new *knew;
3165 struct hda_input_mux *imux = &spec->private_imux;
3166
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003167 if (spec->auto_mic)
3168 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01003169 if (!spec->num_adcs || imux->num_items <= 1)
3170 return 0; /* no need for input source control */
3171 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01003172 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01003173 if (!knew)
3174 return -ENOMEM;
3175 knew->count = spec->num_adcs;
3176 return 0;
3177}
3178
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003179/* check whether the line-input can be used as line-out */
3180static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01003181{
3182 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003183 struct auto_pin_cfg *cfg = &spec->autocfg;
3184 hda_nid_t nid;
3185 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003186 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003187
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003188 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
3189 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003190 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003191 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003192 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01003193 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003194 if (pincap & AC_PINCAP_OUT)
3195 return nid;
3196 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003197 }
Matt Porter403d1942005-11-29 15:00:51 +01003198 return 0;
3199}
3200
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003201static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
3202
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003203/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003204static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003205{
3206 struct sigmatel_spec *spec = codec->spec;
3207 struct auto_pin_cfg *cfg = &spec->autocfg;
3208 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02003209 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003210
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003211 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003212 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
3213 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003214 for (i = 0; i < cfg->num_inputs; i++) {
3215 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02003216 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003217 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003218 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3219 /* some laptops have an internal analog microphone
3220 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003221 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003222 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003223 if (pincap & AC_PINCAP_OUT) {
3224 *dac = get_unassigned_dac(codec, nid);
3225 if (*dac)
3226 return nid;
3227 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003228 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003229 }
3230 return 0;
3231}
Steve Longerbeam7b043892007-05-03 20:50:03 +02003232
3233static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3234{
3235 int i;
3236
3237 for (i = 0; i < spec->multiout.num_dacs; i++) {
3238 if (spec->multiout.dac_nids[i] == nid)
3239 return 1;
3240 }
3241
3242 return 0;
3243}
3244
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003245static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3246{
3247 int i;
3248 if (is_in_dac_nids(spec, nid))
3249 return 1;
3250 for (i = 0; i < spec->autocfg.hp_outs; i++)
3251 if (spec->hp_dacs[i] == nid)
3252 return 1;
3253 for (i = 0; i < spec->autocfg.speaker_outs; i++)
3254 if (spec->speaker_dacs[i] == nid)
3255 return 1;
3256 return 0;
3257}
3258
3259static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
3260{
3261 struct sigmatel_spec *spec = codec->spec;
David Henningsson48718ea2011-10-05 09:49:05 +02003262 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003263 int j, conn_len;
David Henningsson48718ea2011-10-05 09:49:05 +02003264 hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003265 unsigned int wcaps, wtype;
3266
3267 conn_len = snd_hda_get_connections(codec, nid, conn,
3268 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01003269 /* 92HD88: trace back up the link of nids to find the DAC */
3270 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
3271 != AC_WID_AUD_OUT)) {
3272 nid = conn[0];
3273 conn_len = snd_hda_get_connections(codec, nid, conn,
3274 HDA_MAX_CONNECTIONS);
3275 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003276 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01003277 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003278 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003279 /* we check only analog outputs */
3280 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3281 continue;
3282 /* if this route has a free DAC, assign it */
3283 if (!check_all_dac_nids(spec, conn[j])) {
3284 if (conn_len > 1) {
3285 /* select this DAC in the pin's input mux */
3286 snd_hda_codec_write_cache(codec, nid, 0,
3287 AC_VERB_SET_CONNECT_SEL, j);
3288 }
3289 return conn[j];
3290 }
3291 }
David Henningsson48718ea2011-10-05 09:49:05 +02003292
3293 /* if all DACs are already assigned, connect to the primary DAC,
3294 unless we're assigning a secondary headphone */
3295 fallback_dac = spec->multiout.dac_nids[0];
3296 if (spec->multiout.hp_nid) {
3297 for (j = 0; j < cfg->hp_outs; j++)
3298 if (cfg->hp_pins[j] == nid) {
3299 fallback_dac = spec->multiout.hp_nid;
3300 break;
3301 }
3302 }
3303
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003304 if (conn_len > 1) {
3305 for (j = 0; j < conn_len; j++) {
David Henningsson48718ea2011-10-05 09:49:05 +02003306 if (conn[j] == fallback_dac) {
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003307 snd_hda_codec_write_cache(codec, nid, 0,
3308 AC_VERB_SET_CONNECT_SEL, j);
3309 break;
3310 }
3311 }
3312 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003313 return 0;
3314}
3315
3316static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3317static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3318
Matt Porter3cc08dc2006-01-23 15:27:49 +01003319/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02003320 * Fill in the dac_nids table from the parsed pin configuration
3321 * This function only works when every pin in line_out_pins[]
3322 * contains atleast one DAC in its connection list. Some 92xx
3323 * codecs are not connected directly to a DAC, such as the 9200
3324 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01003325 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003326static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003327{
3328 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003329 struct auto_pin_cfg *cfg = &spec->autocfg;
3330 int i;
3331 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02003332
Mattc7d4b2f2005-06-27 14:59:41 +02003333 for (i = 0; i < cfg->line_outs; i++) {
3334 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003335 dac = get_unassigned_dac(codec, nid);
3336 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003337 if (spec->multiout.num_dacs > 0) {
3338 /* we have already working output pins,
3339 * so let's drop the broken ones again
3340 */
3341 cfg->line_outs = spec->multiout.num_dacs;
3342 break;
3343 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003344 /* error out, no available DAC found */
3345 snd_printk(KERN_ERR
3346 "%s: No available DAC for pin 0x%x\n",
3347 __func__, nid);
3348 return -ENODEV;
3349 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003350 add_spec_dacs(spec, dac);
3351 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003352
Takashi Iwai139e0712009-03-06 12:10:41 +01003353 for (i = 0; i < cfg->hp_outs; i++) {
3354 nid = cfg->hp_pins[i];
3355 dac = get_unassigned_dac(codec, nid);
3356 if (dac) {
3357 if (!spec->multiout.hp_nid)
3358 spec->multiout.hp_nid = dac;
3359 else
3360 add_spec_extra_dacs(spec, dac);
3361 }
3362 spec->hp_dacs[i] = dac;
3363 }
3364
3365 for (i = 0; i < cfg->speaker_outs; i++) {
3366 nid = cfg->speaker_pins[i];
3367 dac = get_unassigned_dac(codec, nid);
3368 if (dac)
3369 add_spec_extra_dacs(spec, dac);
3370 spec->speaker_dacs[i] = dac;
3371 }
3372
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003373 /* add line-in as output */
3374 nid = check_line_out_switch(codec);
3375 if (nid) {
3376 dac = get_unassigned_dac(codec, nid);
3377 if (dac) {
3378 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3379 nid, cfg->line_outs);
3380 cfg->line_out_pins[cfg->line_outs] = nid;
3381 cfg->line_outs++;
3382 spec->line_switch = nid;
3383 add_spec_dacs(spec, dac);
3384 }
3385 }
3386 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003387 nid = check_mic_out_switch(codec, &dac);
3388 if (nid && dac) {
3389 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3390 nid, cfg->line_outs);
3391 cfg->line_out_pins[cfg->line_outs] = nid;
3392 cfg->line_outs++;
3393 spec->mic_switch = nid;
3394 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003395 }
3396
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003397 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003398 spec->multiout.num_dacs,
3399 spec->multiout.dac_nids[0],
3400 spec->multiout.dac_nids[1],
3401 spec->multiout.dac_nids[2],
3402 spec->multiout.dac_nids[3],
3403 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003404
Mattc7d4b2f2005-06-27 14:59:41 +02003405 return 0;
3406}
3407
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003408/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003409static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3410 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003411{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003412 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003413 char name[32];
3414 int err;
3415
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003416 if (!spec->check_volume_offset) {
3417 unsigned int caps, step, nums, db_scale;
3418 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3419 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3420 AC_AMPCAP_STEP_SIZE_SHIFT;
3421 step = (step + 1) * 25; /* in .01dB unit */
3422 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3423 AC_AMPCAP_NUM_STEPS_SHIFT;
3424 db_scale = nums * step;
3425 /* if dB scale is over -64dB, and finer enough,
3426 * let's reduce it to half
3427 */
3428 if (db_scale > 6400 && nums >= 0x1f)
3429 spec->volume_offset = nums / 2;
3430 spec->check_volume_offset = 1;
3431 }
3432
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003433 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003434 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003435 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3436 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003437 if (err < 0)
3438 return err;
3439 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003440 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003441 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3442 if (err < 0)
3443 return err;
3444 return 0;
3445}
3446
Takashi Iwai668b9652009-03-06 10:13:24 +01003447#define create_controls(codec, pfx, nid, chs) \
3448 create_controls_idx(codec, pfx, 0, nid, chs)
3449
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003450static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3451{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003452 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003453 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3454 return 1;
3455 } else {
Takashi Iwaidda14412011-05-02 11:29:30 +02003456 snd_BUG_ON(spec->multiout.dac_nids != spec->dac_nids);
3457 spec->dac_nids[spec->multiout.num_dacs] = nid;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003458 spec->multiout.num_dacs++;
3459 }
3460 return 0;
3461}
3462
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003463static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003464{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003465 int i;
3466 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3467 if (!spec->multiout.extra_out_nid[i]) {
3468 spec->multiout.extra_out_nid[i] = nid;
3469 return 0;
3470 }
3471 }
3472 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3473 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003474}
3475
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003476/* Create output controls
3477 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3478 */
3479static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3480 const hda_nid_t *pins,
3481 const hda_nid_t *dac_nids,
3482 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003483{
Takashi Iwai76624532008-12-19 10:09:47 +01003484 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaiea734962011-01-17 11:29:34 +01003485 static const char * const chname[4] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02003486 "Front", "Surround", NULL /*CLFE*/, "Side"
3487 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003488 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003489 int i, err;
3490 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003491
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003492 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003493 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
Takashi Iwaie35d9d62011-05-17 11:28:16 +02003494 if (is_jack_detectable(codec, pins[i]))
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003495 spec->hp_detect = 1;
3496 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003497 nid = dac_nids[i];
3498 if (!nid)
3499 continue;
3500 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003501 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003502 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003503 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003504 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003505 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003506 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003507 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003508
3509 wid_caps = get_wcaps(codec, nid);
3510
3511 if (wid_caps & AC_WCAP_LR_SWAP) {
3512 err = stac92xx_add_control(spec,
3513 STAC_CTL_WIDGET_CLFE_SWITCH,
3514 "Swap Center/LFE Playback Switch", nid);
3515
3516 if (err < 0)
3517 return err;
3518 }
3519
Mattc7d4b2f2005-06-27 14:59:41 +02003520 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003521 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003522 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003523 switch (type) {
3524 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003525 name = "Headphone";
3526 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003527 break;
3528 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwaif37bc7a2012-11-08 15:59:23 +01003529 if (num_outs <= 2) {
3530 name = i ? "Bass Speaker" : "Speaker";
3531 idx = 0;
David Henningsson298efee2012-09-06 11:17:58 +02003532 break;
3533 }
3534 /* Fall through in case of multi speaker outs */
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003535 default:
3536 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003537 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003538 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003539 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003540 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003541 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003542 return err;
3543 }
3544 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003545 return 0;
3546}
3547
Takashi Iwai62cbde12012-09-14 11:58:54 +02003548static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
3549 unsigned int dir_mask, unsigned int data);
3550
3551/* hook for controlling mic-mute LED GPIO */
3552static int stac92xx_capture_sw_put_led(struct snd_kcontrol *kcontrol,
3553 struct snd_ctl_elem_value *ucontrol)
3554{
3555 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3556 struct sigmatel_spec *spec = codec->spec;
3557 int err;
3558 bool mute;
3559
3560 err = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
3561 if (err <= 0)
3562 return err;
3563 mute = !(ucontrol->value.integer.value[0] &&
3564 ucontrol->value.integer.value[1]);
3565 if (spec->mic_mute_led_on != mute) {
3566 spec->mic_mute_led_on = mute;
3567 if (mute)
3568 spec->gpio_data |= spec->mic_mute_led_gpio;
3569 else
3570 spec->gpio_data &= ~spec->mic_mute_led_gpio;
3571 stac_gpio_set(codec, spec->gpio_mask,
3572 spec->gpio_dir, spec->gpio_data);
3573 }
3574 return err;
3575}
3576
Takashi Iwai6479c632009-07-28 18:20:25 +02003577static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3578 unsigned long sw, int idx)
3579{
Takashi Iwai62cbde12012-09-14 11:58:54 +02003580 struct sigmatel_spec *spec = codec->spec;
3581 struct snd_kcontrol_new *knew;
Takashi Iwai6479c632009-07-28 18:20:25 +02003582 int err;
Takashi Iwai62cbde12012-09-14 11:58:54 +02003583
Takashi Iwai6479c632009-07-28 18:20:25 +02003584 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003585 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003586 if (err < 0)
3587 return err;
Takashi Iwai62cbde12012-09-14 11:58:54 +02003588
3589 knew = add_control_temp(spec,
3590 &stac92xx_control_templates[STAC_CTL_WIDGET_MUTE],
3591 idx, "Capture Switch", sw);
3592 if (!knew)
3593 return -ENOMEM;
3594 /* add a LED hook for some HP laptops */
3595 if (spec->mic_mute_led_gpio)
3596 knew->put = stac92xx_capture_sw_put_led;
3597
Takashi Iwai6479c632009-07-28 18:20:25 +02003598 return 0;
3599}
3600
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003601/* add playback controls from the parsed DAC table */
3602static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3603 const struct auto_pin_cfg *cfg)
3604{
3605 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003606 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003607 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003608 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003609
3610 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3611 spec->multiout.dac_nids,
3612 cfg->line_out_type);
3613 if (err < 0)
3614 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003615
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003616 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003617 err = stac92xx_add_control(spec,
3618 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003619 "Headphone as Line Out Switch",
3620 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003621 if (err < 0)
3622 return err;
3623 }
3624
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003625 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003626 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003627 break;
3628 nid = cfg->inputs[idx].pin;
3629 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3630 if (err < 0)
3631 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003632 }
Matt Porter403d1942005-11-29 15:00:51 +01003633
Mattc7d4b2f2005-06-27 14:59:41 +02003634 return 0;
3635}
3636
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003637/* add playback controls for Speaker and HP outputs */
3638static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3639 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003640{
3641 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003642 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003643
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003644 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3645 spec->hp_dacs, AUTO_PIN_HP_OUT);
3646 if (err < 0)
3647 return err;
3648
3649 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3650 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3651 if (err < 0)
3652 return err;
3653
Mattc7d4b2f2005-06-27 14:59:41 +02003654 return 0;
3655}
3656
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003657/* labels for mono mux outputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003658static const char * const stac92xx_mono_labels[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003659 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003660};
3661
3662/* create mono mux for mono out on capable codecs */
3663static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3664{
3665 struct sigmatel_spec *spec = codec->spec;
3666 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3667 int i, num_cons;
3668 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3669
3670 num_cons = snd_hda_get_connections(codec,
3671 spec->mono_nid,
3672 con_lst,
3673 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003674 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003675 return -EINVAL;
3676
Takashi Iwai10a20af2010-09-09 16:28:02 +02003677 for (i = 0; i < num_cons; i++)
3678 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3679 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003680
3681 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3682 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003683}
3684
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003685/* create PC beep volume controls */
3686static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3687 hda_nid_t nid)
3688{
3689 struct sigmatel_spec *spec = codec->spec;
3690 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003691 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3692
3693 if (spec->anabeep_nid == nid)
3694 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003695
3696 /* check for mute support for the the amp */
3697 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003698 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003699 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003700 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3701 if (err < 0)
3702 return err;
3703 }
3704
3705 /* check to see if there is volume support for the amp */
3706 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3707 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003708 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003709 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3710 if (err < 0)
3711 return err;
3712 }
3713 return 0;
3714}
3715
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003716#ifdef CONFIG_SND_HDA_INPUT_BEEP
3717#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3718
3719static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3720 struct snd_ctl_elem_value *ucontrol)
3721{
3722 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3723 ucontrol->value.integer.value[0] = codec->beep->enabled;
3724 return 0;
3725}
3726
3727static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3728 struct snd_ctl_elem_value *ucontrol)
3729{
3730 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003731 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003732}
3733
Takashi Iwai2b635362011-05-02 12:33:43 +02003734static const struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003735 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3736 .info = stac92xx_dig_beep_switch_info,
3737 .get = stac92xx_dig_beep_switch_get,
3738 .put = stac92xx_dig_beep_switch_put,
3739};
3740
3741static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3742{
3743 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003744 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003745}
3746#endif
3747
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003748static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3749{
3750 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003751 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003752
3753 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003754 hda_nid_t nid;
3755 unsigned int wcaps;
3756 unsigned long val;
3757
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003758 nid = spec->mux_nids[i];
3759 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003760 if (!(wcaps & AC_WCAP_OUT_AMP))
3761 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003762
Takashi Iwai667067d2009-08-13 18:14:42 +02003763 /* check whether already the same control was created as
3764 * normal Capture Volume.
3765 */
3766 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3767 for (j = 0; j < spec->num_caps; j++) {
3768 if (spec->capvols[j] == val)
3769 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003770 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003771 if (j < spec->num_caps)
3772 continue;
3773
3774 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3775 "Mux Capture Volume", val);
3776 if (err < 0)
3777 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003778 }
3779 return 0;
3780};
3781
Takashi Iwaiea734962011-01-17 11:29:34 +01003782static const char * const stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003783 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003784};
3785
3786static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3787{
3788 struct sigmatel_spec *spec = codec->spec;
3789 struct hda_input_mux *spdif_mux = &spec->private_smux;
Takashi Iwaiea734962011-01-17 11:29:34 +01003790 const char * const *labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003791 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003792 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003793
3794 num_cons = snd_hda_get_connections(codec,
3795 spec->smux_nids[0],
3796 con_lst,
3797 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003798 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003799 return -EINVAL;
3800
Matthew Ranostay65973632008-09-16 10:39:37 -04003801 if (!labels)
3802 labels = stac92xx_spdif_labels;
3803
Takashi Iwai10a20af2010-09-09 16:28:02 +02003804 for (i = 0; i < num_cons; i++)
3805 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003806
3807 return 0;
3808}
3809
Matt Porter8b657272006-10-26 17:12:59 +02003810/* labels for dmic mux inputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003811static const char * const stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003812 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3813 "Digital Mic 3", "Digital Mic 4"
3814};
3815
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003816static hda_nid_t get_connected_node(struct hda_codec *codec, hda_nid_t mux,
3817 int idx)
3818{
3819 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3820 int nums;
3821 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3822 if (idx >= 0 && idx < nums)
3823 return conn[idx];
3824 return 0;
3825}
3826
Takashi Iwai8d087c72011-06-28 12:45:47 +02003827/* look for NID recursively */
3828#define get_connection_index(codec, mux, nid) \
3829 snd_hda_get_conn_index(codec, mux, nid, 1)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003830
Takashi Iwai667067d2009-08-13 18:14:42 +02003831/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003832/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003833static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003834 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003835{
3836 unsigned int caps, nums;
3837 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003838 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003839
Takashi Iwai96f845d2009-08-29 00:49:36 +02003840 if (direction == HDA_OUTPUT)
3841 caps = AC_WCAP_OUT_AMP;
3842 else
3843 caps = AC_WCAP_IN_AMP;
3844 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003845 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003846 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003847 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3848 if (!nums)
3849 return 0;
3850 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003851 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3852 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003853 if (err < 0)
3854 return err;
3855 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003856}
3857
Matt Porter8b657272006-10-26 17:12:59 +02003858/* create playback/capture controls for input pins on dmic capable codecs */
3859static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3860 const struct auto_pin_cfg *cfg)
3861{
3862 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003863 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003864 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003865 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003866 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003867
Takashi Iwai10a20af2010-09-09 16:28:02 +02003868 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003869
Matt Porter8b657272006-10-26 17:12:59 +02003870 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003871 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003872 int index, type_idx;
Takashi Iwai201e06f2011-11-16 15:33:26 +01003873 char label[32];
Matt Porter8b657272006-10-26 17:12:59 +02003874
Takashi Iwai667067d2009-08-13 18:14:42 +02003875 nid = spec->dmic_nids[i];
3876 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3877 continue;
3878 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003879 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3880 continue;
3881
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003882 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3883 if (index < 0)
3884 continue;
3885
Takashi Iwai201e06f2011-11-16 15:33:26 +01003886 snd_hda_get_pin_label(codec, nid, &spec->autocfg,
3887 label, sizeof(label), NULL);
Takashi Iwai10a20af2010-09-09 16:28:02 +02003888 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai2d7ec122010-12-23 10:16:05 +01003889 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3890 snd_hda_add_imux_item(imux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003891
Takashi Iwai10a20af2010-09-09 16:28:02 +02003892 err = create_elem_capture_vol(codec, nid, label, type_idx,
3893 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003894 if (err < 0)
3895 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003896 if (!err) {
3897 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003898 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003899 if (err < 0)
3900 return err;
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06003901 if (!err) {
3902 nid = get_connected_node(codec,
3903 spec->dmux_nids[0], index);
3904 if (nid)
3905 err = create_elem_capture_vol(codec,
3906 nid, label,
3907 type_idx, HDA_INPUT);
3908 if (err < 0)
3909 return err;
3910 }
Takashi Iwai96f845d2009-08-29 00:49:36 +02003911 }
Matt Porter8b657272006-10-26 17:12:59 +02003912 }
3913
3914 return 0;
3915}
3916
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003917static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003918 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003919{
3920 unsigned int cfg;
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003921 unsigned int type;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003922
3923 if (!nid)
3924 return 0;
3925 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003926 type = get_defcfg_device(cfg);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003927 switch (snd_hda_get_input_pin_attr(cfg)) {
3928 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003929 if (*fixed)
3930 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003931 if (type != AC_JACK_MIC_IN)
3932 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003933 *fixed = nid;
3934 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003935 case INPUT_PIN_ATTR_UNUSED:
3936 break;
3937 case INPUT_PIN_ATTR_DOCK:
3938 if (*dock)
3939 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003940 if (type != AC_JACK_MIC_IN && type != AC_JACK_LINE_IN)
3941 return 1; /* invalid type */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003942 *dock = nid;
3943 break;
3944 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003945 if (*ext)
3946 return 1; /* already occupied */
Takashi Iwai1f83ac52011-05-17 12:29:09 +02003947 if (type != AC_JACK_MIC_IN)
3948 return 1; /* invalid type */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003949 *ext = nid;
3950 break;
3951 }
3952 return 0;
3953}
3954
3955static int set_mic_route(struct hda_codec *codec,
3956 struct sigmatel_mic_route *mic,
3957 hda_nid_t pin)
3958{
3959 struct sigmatel_spec *spec = codec->spec;
3960 struct auto_pin_cfg *cfg = &spec->autocfg;
3961 int i;
3962
3963 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003964 if (pin == 0)
3965 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003966 for (i = 0; i < cfg->num_inputs; i++) {
3967 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003968 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003969 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003970 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003971 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003972 i = get_connection_index(codec, spec->mux_nids[0], pin);
3973 if (i < 0)
3974 return -1;
3975 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003976 mic->dmux_idx = -1;
3977 if (spec->dmux_nids)
3978 mic->dmux_idx = get_connection_index(codec,
3979 spec->dmux_nids[0],
3980 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003981 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003982 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003983 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3984 if (i < 0)
3985 return -1;
3986 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003987 mic->mux_idx = -1;
3988 if (spec->mux_nids)
3989 mic->mux_idx = get_connection_index(codec,
3990 spec->mux_nids[0],
3991 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003992 }
3993 return 0;
3994}
3995
3996/* return non-zero if the device is for automatic mic switch */
3997static int stac_check_auto_mic(struct hda_codec *codec)
3998{
3999 struct sigmatel_spec *spec = codec->spec;
4000 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02004001 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004002 int i;
4003
Charles Chin99077902010-09-17 10:22:32 +02004004 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004005 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02004006 if (check_mic_pin(codec, cfg->inputs[i].pin,
4007 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004008 return 0;
4009 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02004010 if (check_mic_pin(codec, spec->dmic_nids[i],
4011 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004012 return 0;
Takashi Iwai80c67852011-01-13 08:08:08 +01004013 if (!fixed || (!ext && !dock))
Charles Chin99077902010-09-17 10:22:32 +02004014 return 0; /* no input to switch */
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004015 if (!is_jack_detectable(codec, ext))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004016 return 0; /* no unsol support */
4017 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02004018 set_mic_route(codec, &spec->int_mic, fixed) ||
4019 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004020 return 0; /* something is wrong */
4021 return 1;
4022}
4023
Mattc7d4b2f2005-06-27 14:59:41 +02004024/* create playback/capture controls for input pins */
4025static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
4026{
4027 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004028 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02004029 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02004030 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02004031
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004032 for (i = 0; i < cfg->num_inputs; i++) {
4033 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02004034 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02004035
Takashi Iwai314634b2006-09-21 11:56:18 +02004036 index = -1;
4037 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02004038 index = get_connection_index(codec, spec->mux_nids[j],
4039 nid);
4040 if (index >= 0)
4041 break;
Mattc7d4b2f2005-06-27 14:59:41 +02004042 }
Takashi Iwai667067d2009-08-13 18:14:42 +02004043 if (index < 0)
4044 continue;
4045
Takashi Iwai10a20af2010-09-09 16:28:02 +02004046 label = hda_get_autocfg_input_label(codec, cfg, i);
4047 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02004048
Takashi Iwai667067d2009-08-13 18:14:42 +02004049 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02004050 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02004051 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02004052 if (err < 0)
4053 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02004054 }
Takashi Iwai5207e102009-07-30 13:09:08 +02004055 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02004056
Steve Longerbeam7b043892007-05-03 20:50:03 +02004057 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02004058 /*
4059 * Set the current input for the muxes.
4060 * The STAC9221 has two input muxes with identical source
4061 * NID lists. Hopefully this won't get confused.
4062 */
4063 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004064 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
4065 AC_VERB_SET_CONNECT_SEL,
4066 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004067 }
4068 }
4069
Mattc7d4b2f2005-06-27 14:59:41 +02004070 return 0;
4071}
4072
Mattc7d4b2f2005-06-27 14:59:41 +02004073static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
4074{
4075 struct sigmatel_spec *spec = codec->spec;
4076 int i;
4077
4078 for (i = 0; i < spec->autocfg.line_outs; i++) {
4079 hda_nid_t nid = spec->autocfg.line_out_pins[i];
4080 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
4081 }
4082}
4083
4084static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
4085{
4086 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004087 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004088
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004089 for (i = 0; i < spec->autocfg.hp_outs; i++) {
4090 hda_nid_t pin;
4091 pin = spec->autocfg.hp_pins[i];
4092 if (pin) /* connect to front */
4093 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
4094 }
4095 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
4096 hda_nid_t pin;
4097 pin = spec->autocfg.speaker_pins[i];
4098 if (pin) /* connect to front */
4099 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
4100 }
Mattc7d4b2f2005-06-27 14:59:41 +02004101}
4102
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01004103static int is_dual_headphones(struct hda_codec *codec)
4104{
4105 struct sigmatel_spec *spec = codec->spec;
4106 int i, valid_hps;
4107
4108 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
4109 spec->autocfg.hp_outs <= 1)
4110 return 0;
4111 valid_hps = 0;
4112 for (i = 0; i < spec->autocfg.hp_outs; i++) {
4113 hda_nid_t nid = spec->autocfg.hp_pins[i];
4114 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
4115 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
4116 continue;
4117 valid_hps++;
4118 }
4119 return (valid_hps > 1);
4120}
4121
4122
Charles Chin9009b0e2011-11-03 10:27:27 +01004123static int stac92xx_parse_auto_config(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02004124{
4125 struct sigmatel_spec *spec = codec->spec;
Charles Chin9009b0e2011-11-03 10:27:27 +01004126 hda_nid_t dig_out = 0, dig_in = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004127 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02004128 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02004129
Matt Porter8b657272006-10-26 17:12:59 +02004130 if ((err = snd_hda_parse_pin_def_config(codec,
4131 &spec->autocfg,
4132 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004133 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004134 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01004135 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02004136
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004137 /* If we have no real line-out pin and multiple hp-outs, HPs should
4138 * be set up as multi-channel outputs.
4139 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01004140 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004141 /* Copy hp_outs to line_outs, backup line_outs in
4142 * speaker_outs so that the following routines can handle
4143 * HP pins as primary outputs.
4144 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004145 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004146 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
4147 sizeof(spec->autocfg.line_out_pins));
4148 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
4149 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
4150 sizeof(spec->autocfg.hp_pins));
4151 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004152 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
4153 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004154 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004155 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01004156 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004157 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
4158 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01004159 u32 caps = query_amp_caps(codec,
4160 spec->autocfg.mono_out_pin, dir);
4161 hda_nid_t conn_list[1];
4162
4163 /* get the mixer node and then the mono mux if it exists */
4164 if (snd_hda_get_connections(codec,
4165 spec->autocfg.mono_out_pin, conn_list, 1) &&
4166 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02004167 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01004168
4169 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02004170 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01004171 /* LR swap check, some stac925x have a mux that
4172 * changes the DACs output path instead of the
4173 * mono-mux path.
4174 */
4175 if (wid_type == AC_WID_AUD_SEL &&
4176 !(wcaps & AC_WCAP_LR_SWAP))
4177 spec->mono_nid = conn_list[0];
4178 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004179 if (dir) {
4180 hda_nid_t nid = spec->autocfg.mono_out_pin;
4181
4182 /* most mono outs have a least a mute/unmute switch */
4183 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
4184 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
4185 "Mono Playback Switch",
4186 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01004187 if (err < 0)
4188 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004189 /* check for volume support for the amp */
4190 if ((caps & AC_AMPCAP_NUM_STEPS)
4191 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
4192 err = stac92xx_add_control(spec,
4193 STAC_CTL_WIDGET_VOL,
4194 "Mono Playback Volume",
4195 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
4196 if (err < 0)
4197 return err;
4198 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01004199 }
4200
4201 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
4202 AC_PINCTL_OUT_EN);
4203 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01004204
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004205 if (!spec->multiout.num_dacs) {
4206 err = stac92xx_auto_fill_dac_nids(codec);
4207 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02004208 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01004209 err = stac92xx_auto_create_multi_out_ctls(codec,
4210 &spec->autocfg);
4211 if (err < 0)
4212 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004213 }
Mattc7d4b2f2005-06-27 14:59:41 +02004214
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004215 /* setup analog beep controls */
4216 if (spec->anabeep_nid > 0) {
4217 err = stac92xx_auto_create_beep_ctls(codec,
4218 spec->anabeep_nid);
4219 if (err < 0)
4220 return err;
4221 }
4222
4223 /* setup digital beep controls and input device */
4224#ifdef CONFIG_SND_HDA_INPUT_BEEP
4225 if (spec->digbeep_nid > 0) {
4226 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01004227 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004228
4229 err = stac92xx_auto_create_beep_ctls(codec, nid);
4230 if (err < 0)
4231 return err;
4232 err = snd_hda_attach_beep_device(codec, nid);
4233 if (err < 0)
4234 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01004235 if (codec->beep) {
4236 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01004237 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01004238 /* if no beep switch is available, make its own one */
4239 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
4240 if (!(caps & AC_AMPCAP_MUTE)) {
4241 err = stac92xx_beep_switch_ctl(codec);
4242 if (err < 0)
4243 return err;
4244 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01004245 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004246 }
4247#endif
4248
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004249 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004250 if (err < 0)
4251 return err;
4252
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004253 /* All output parsing done, now restore the swapped hp pins */
4254 if (hp_swap) {
4255 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
4256 sizeof(spec->autocfg.hp_pins));
4257 spec->autocfg.hp_outs = spec->autocfg.line_outs;
4258 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
4259 spec->autocfg.line_outs = 0;
4260 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004261
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004262 if (stac_check_auto_mic(codec)) {
4263 spec->auto_mic = 1;
4264 /* only one capture for auto-mic */
4265 spec->num_adcs = 1;
4266 spec->num_caps = 1;
4267 spec->num_muxes = 1;
4268 }
4269
Takashi Iwai6479c632009-07-28 18:20:25 +02004270 for (i = 0; i < spec->num_caps; i++) {
4271 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
4272 spec->capsws[i], i);
4273 if (err < 0)
4274 return err;
4275 }
4276
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01004277 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02004278 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004279 return err;
4280
Matthew Ranostayb22b4822008-01-22 12:32:30 +01004281 if (spec->mono_nid > 0) {
4282 err = stac92xx_auto_create_mono_output_ctls(codec);
4283 if (err < 0)
4284 return err;
4285 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004286 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02004287 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
4288 &spec->autocfg)) < 0)
4289 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02004290 if (spec->num_muxes > 0) {
4291 err = stac92xx_auto_create_mux_input_ctls(codec);
4292 if (err < 0)
4293 return err;
4294 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02004295 if (spec->num_smuxes > 0) {
4296 err = stac92xx_auto_create_spdif_mux_ctls(codec);
4297 if (err < 0)
4298 return err;
4299 }
Matt Porter8b657272006-10-26 17:12:59 +02004300
Takashi Iwaie3c75962009-01-23 11:57:22 +01004301 err = stac92xx_add_input_source(spec);
4302 if (err < 0)
4303 return err;
4304
Mattc7d4b2f2005-06-27 14:59:41 +02004305 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01004306 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02004307 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02004308
Charles Chin9009b0e2011-11-03 10:27:27 +01004309 /* find digital out and in converters */
4310 for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
4311 unsigned int wid_caps = get_wcaps(codec, i);
4312 if (wid_caps & AC_WCAP_DIGITAL) {
4313 switch (get_wcaps_type(wid_caps)) {
4314 case AC_WID_AUD_OUT:
4315 if (!dig_out)
4316 dig_out = i;
4317 break;
4318 case AC_WID_AUD_IN:
4319 if (!dig_in)
4320 dig_in = i;
4321 break;
4322 }
4323 }
4324 }
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004325 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004326 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004327 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004328 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02004329
Takashi Iwai603c4012008-07-30 15:01:44 +02004330 if (spec->kctls.list)
4331 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004332
4333 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05004334 if (!spec->dinput_mux)
4335 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004336 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01004337 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02004338 return 1;
4339}
4340
Takashi Iwai82bc9552006-03-21 11:24:42 +01004341/* add playback controls for HP output */
4342static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4343 struct auto_pin_cfg *cfg)
4344{
4345 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004346 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01004347
4348 if (! pin)
4349 return 0;
4350
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004351 if (is_jack_detectable(codec, pin))
Takashi Iwai82bc9552006-03-21 11:24:42 +01004352 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004353
4354 return 0;
4355}
4356
Richard Fish160ea0d2006-09-06 13:58:25 +02004357/* add playback controls for LFE output */
4358static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4359 struct auto_pin_cfg *cfg)
4360{
4361 struct sigmatel_spec *spec = codec->spec;
4362 int err;
4363 hda_nid_t lfe_pin = 0x0;
4364 int i;
4365
4366 /*
4367 * search speaker outs and line outs for a mono speaker pin
4368 * with an amp. If one is found, add LFE controls
4369 * for it.
4370 */
4371 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4372 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004373 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004374 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4375 if (wcaps == AC_WCAP_OUT_AMP)
4376 /* found a mono speaker with an amp, must be lfe */
4377 lfe_pin = pin;
4378 }
4379
4380 /* if speaker_outs is 0, then speakers may be in line_outs */
4381 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4382 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4383 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004384 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004385 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004386 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004387 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004388 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4389 if (wcaps == AC_WCAP_OUT_AMP)
4390 /* found a mono speaker with an amp,
4391 must be lfe */
4392 lfe_pin = pin;
4393 }
4394 }
4395 }
4396
4397 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004398 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004399 if (err < 0)
4400 return err;
4401 }
4402
4403 return 0;
4404}
4405
Mattc7d4b2f2005-06-27 14:59:41 +02004406static int stac9200_parse_auto_config(struct hda_codec *codec)
4407{
4408 struct sigmatel_spec *spec = codec->spec;
4409 int err;
4410
Kailang Yangdf694da2005-12-05 19:42:22 +01004411 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004412 return err;
4413
4414 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4415 return err;
4416
Takashi Iwai82bc9552006-03-21 11:24:42 +01004417 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4418 return err;
4419
Richard Fish160ea0d2006-09-06 13:58:25 +02004420 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4421 return err;
4422
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004423 if (spec->num_muxes > 0) {
4424 err = stac92xx_auto_create_mux_input_ctls(codec);
4425 if (err < 0)
4426 return err;
4427 }
4428
Takashi Iwaie3c75962009-01-23 11:57:22 +01004429 err = stac92xx_add_input_source(spec);
4430 if (err < 0)
4431 return err;
4432
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004433 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004434 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004435 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004436 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004437
Takashi Iwai603c4012008-07-30 15:01:44 +02004438 if (spec->kctls.list)
4439 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004440
4441 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004442 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004443
4444 return 1;
4445}
4446
Sam Revitch62fe78e2006-05-10 15:09:17 +02004447/*
4448 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4449 * funky external mute control using GPIO pins.
4450 */
4451
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004452static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004453 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004454{
4455 unsigned int gpiostate, gpiomask, gpiodir;
4456
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004457 snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
4458
Sam Revitch62fe78e2006-05-10 15:09:17 +02004459 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4460 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004461 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004462
4463 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4464 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004465 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004466
4467 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4468 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004469 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004470
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004471 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004472 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4473
4474 snd_hda_codec_write(codec, codec->afg, 0,
4475 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004476 snd_hda_codec_read(codec, codec->afg, 0,
4477 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004478
4479 msleep(1);
4480
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004481 snd_hda_codec_read(codec, codec->afg, 0,
4482 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004483}
4484
Takashi Iwai3a938972011-10-28 01:16:55 +02004485static int stac_add_event(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004486 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004487{
Takashi Iwai3a938972011-10-28 01:16:55 +02004488 struct hda_jack_tbl *event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004489
Takashi Iwai3a938972011-10-28 01:16:55 +02004490 event = snd_hda_jack_tbl_new(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004491 if (!event)
4492 return -ENOMEM;
Takashi Iwai3a938972011-10-28 01:16:55 +02004493 event->action = type;
4494 event->private_data = data;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004495
Takashi Iwai3a938972011-10-28 01:16:55 +02004496 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004497}
4498
David Henningsson29adc4b2012-09-25 11:31:00 +02004499static void handle_unsol_event(struct hda_codec *codec,
4500 struct hda_jack_tbl *event);
4501
Takashi Iwai62558ce2009-07-29 14:23:09 +02004502/* check if given nid is a valid pin and no other events are assigned
4503 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4504 * Otherwise, returns zero.
4505 */
4506static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4507 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004508{
Takashi Iwai3a938972011-10-28 01:16:55 +02004509 struct hda_jack_tbl *event;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004510
Takashi Iwaie35d9d62011-05-17 11:28:16 +02004511 if (!is_jack_detectable(codec, nid))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004512 return 0;
Takashi Iwai3a938972011-10-28 01:16:55 +02004513 event = snd_hda_jack_tbl_new(codec, nid);
4514 if (!event)
4515 return -ENOMEM;
4516 if (event->action && event->action != type)
4517 return 0;
4518 event->action = type;
David Henningsson29adc4b2012-09-25 11:31:00 +02004519 event->callback = handle_unsol_event;
Takashi Iwai3a938972011-10-28 01:16:55 +02004520 snd_hda_jack_detect_enable(codec, nid, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004521 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004522}
4523
Takashi Iwaib4ead012012-01-23 18:23:36 +01004524static int is_nid_out_jack_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004525{
4526 int i;
4527 for (i = 0; i < cfg->hp_outs; i++)
4528 if (cfg->hp_pins[i] == nid)
4529 return 1; /* nid is a HP-Out */
Takashi Iwaib4ead012012-01-23 18:23:36 +01004530 for (i = 0; i < cfg->line_outs; i++)
4531 if (cfg->line_out_pins[i] == nid)
4532 return 1; /* nid is a line-Out */
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004533 return 0; /* nid is not a HP-Out */
4534};
4535
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004536static void stac92xx_power_down(struct hda_codec *codec)
4537{
4538 struct sigmatel_spec *spec = codec->spec;
4539
4540 /* power down inactive DACs */
Takashi Iwai2b635362011-05-02 12:33:43 +02004541 const hda_nid_t *dac;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004542 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004543 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004544 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004545 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4546}
4547
Takashi Iwaif73d3582008-11-25 08:21:51 +01004548static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4549 int enable);
4550
Takashi Iwaibc759722013-01-11 17:40:31 +01004551static inline bool get_int_hint(struct hda_codec *codec, const char *key,
4552 int *valp)
Takashi Iwai014c41f2009-12-27 13:53:24 +01004553{
Takashi Iwaibc759722013-01-11 17:40:31 +01004554 return !snd_hda_get_int_hint(codec, key, valp);
Takashi Iwai014c41f2009-12-27 13:53:24 +01004555}
4556
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004557/* override some hints from the hwdep entry */
4558static void stac_store_hints(struct hda_codec *codec)
4559{
4560 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004561 int val;
4562
4563 val = snd_hda_get_bool_hint(codec, "hp_detect");
4564 if (val >= 0)
4565 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004566 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004567 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4568 spec->gpio_mask;
4569 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004570 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4571 spec->gpio_mask &= spec->gpio_mask;
4572 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4573 spec->gpio_dir &= spec->gpio_mask;
4574 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4575 spec->eapd_mask &= spec->gpio_mask;
4576 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4577 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004578 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4579 if (val >= 0)
4580 spec->eapd_switch = val;
4581}
4582
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004583static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins,
4584 const hda_nid_t *pins)
4585{
4586 while (num_pins--)
4587 stac_issue_unsol_event(codec, *pins++);
4588}
4589
4590/* fake event to set up pins */
4591static void stac_fake_hp_events(struct hda_codec *codec)
4592{
4593 struct sigmatel_spec *spec = codec->spec;
4594
4595 if (spec->autocfg.hp_outs)
4596 stac_issue_unsol_events(codec, spec->autocfg.hp_outs,
4597 spec->autocfg.hp_pins);
4598 if (spec->autocfg.line_outs &&
4599 spec->autocfg.line_out_pins[0] != spec->autocfg.hp_pins[0])
4600 stac_issue_unsol_events(codec, spec->autocfg.line_outs,
4601 spec->autocfg.line_out_pins);
4602}
4603
Mattc7d4b2f2005-06-27 14:59:41 +02004604static int stac92xx_init(struct hda_codec *codec)
4605{
4606 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004607 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004608 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004609 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004610
David Henningsson5e68fb32012-08-16 14:11:09 +02004611 if (spec->init)
4612 snd_hda_sequence_write(codec, spec->init);
Mattc7d4b2f2005-06-27 14:59:41 +02004613
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01004614 snd_hda_apply_verbs(codec);
4615
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004616 /* power down adcs initially */
4617 if (spec->powerdown_adcs)
4618 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004619 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004620 spec->adc_nids[i], 0,
4621 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004622
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004623 /* override some hints */
4624 stac_store_hints(codec);
4625
Takashi Iwaif73d3582008-11-25 08:21:51 +01004626 /* set up GPIO */
4627 gpio = spec->gpio_data;
4628 /* turn on EAPD statically when spec->eapd_switch isn't set.
4629 * otherwise, unsol event will turn it on/off dynamically
4630 */
4631 if (!spec->eapd_switch)
4632 gpio |= spec->eapd_mask;
4633 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4634
Takashi Iwai82bc9552006-03-21 11:24:42 +01004635 /* set up pins */
4636 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004637 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004638 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004639 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004640 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004641 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004642 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4643 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004644 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004645 for (i = 0; i < cfg->line_outs; i++) {
4646 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004647 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4648 }
4649 }
4650
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004651 /* force to enable the first line-out; the others are set up
4652 * in unsol_event
4653 */
4654 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004655 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004656 /* fake event to set up pins */
Takashi Iwaif2cbba72012-01-11 12:34:11 +01004657 stac_fake_hp_events(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004658 } else {
4659 stac92xx_auto_init_multi_out(codec);
4660 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004661 for (i = 0; i < cfg->hp_outs; i++)
4662 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004663 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004664 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004665 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004666 if (spec->dmux_nids)
4667 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004668 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004669 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4670 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004671 if (enable_pin_detect(codec, spec->dock_mic.pin,
4672 STAC_MIC_EVENT))
4673 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004674 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004675 for (i = 0; i < cfg->num_inputs; i++) {
4676 hda_nid_t nid = cfg->inputs[i].pin;
4677 int type = cfg->inputs[i].type;
4678 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004679 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004680 /* for mic pins, force to initialize */
Takashi Iwai47408602012-04-20 13:06:53 +02004681 pinctl = snd_hda_get_default_vref(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004682 pinctl |= AC_PINCTL_IN_EN;
4683 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4684 } else {
4685 pinctl = snd_hda_codec_read(codec, nid, 0,
4686 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4687 /* if PINCTL already set then skip */
4688 /* Also, if both INPUT and OUTPUT are set,
4689 * it must be a BIOS bug; need to override, too
4690 */
4691 if (!(pinctl & AC_PINCTL_IN_EN) ||
4692 (pinctl & AC_PINCTL_OUT_EN)) {
4693 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004694 pinctl |= AC_PINCTL_IN_EN;
4695 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004696 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004697 }
4698 conf = snd_hda_codec_get_pincfg(codec, nid);
4699 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4700 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4701 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004702 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004703 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004704 for (i = 0; i < spec->num_dmics; i++)
4705 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4706 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004707 if (cfg->dig_out_pins[0])
4708 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004709 AC_PINCTL_OUT_EN);
4710 if (cfg->dig_in_pin)
4711 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4712 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004713 for (i = 0; i < spec->num_pwrs; i++) {
4714 hda_nid_t nid = spec->pwr_nids[i];
Takashi Iwai6e1c39c2012-06-26 17:35:10 +02004715 unsigned int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004716
Takashi Iwaibfc89de2012-05-15 09:02:26 +02004717 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4718 def_conf = get_defcfg_connect(def_conf);
4719 if (def_conf == AC_JACK_PORT_NONE) {
4720 /* power off unused ports */
4721 stac_toggle_power_map(codec, nid, 0);
4722 continue;
4723 }
Takashi Iwai6e1c39c2012-06-26 17:35:10 +02004724 if (def_conf == AC_JACK_PORT_FIXED) {
4725 /* no need for jack detection for fixed pins */
4726 stac_toggle_power_map(codec, nid, 1);
4727 continue;
4728 }
Takashi Iwaieb632122008-12-19 16:39:48 +01004729 /* power on when no jack detection is available */
Takashi Iwai542c9a02011-11-29 13:01:30 +01004730 /* or when the VREF is used for controlling LED */
4731 if (!spec->hp_detect ||
Takashi Iwaibfc89de2012-05-15 09:02:26 +02004732 spec->vref_mute_led_nid == nid ||
4733 !is_jack_detectable(codec, nid)) {
Takashi Iwaieb632122008-12-19 16:39:48 +01004734 stac_toggle_power_map(codec, nid, 1);
4735 continue;
4736 }
4737
Takashi Iwaib4ead012012-01-23 18:23:36 +01004738 if (is_nid_out_jack_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004739 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004740
Takashi Iwaif73d3582008-11-25 08:21:51 +01004741 pinctl = snd_hda_codec_read(codec, nid, 0,
4742 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4743 /* outputs are only ports capable of power management
4744 * any attempts on powering down a input port cause the
4745 * referenced VREF to act quirky.
4746 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004747 if (pinctl & AC_PINCTL_IN_EN) {
4748 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004749 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004750 }
Charles Chinafef2cf2011-11-11 08:05:28 +01004751 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004752 stac_issue_unsol_event(codec, nid);
Charles Chinafef2cf2011-11-11 08:05:28 +01004753 continue;
4754 }
4755 /* none of the above, turn the port OFF */
4756 stac_toggle_power_map(codec, nid, 0);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004757 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004758
Takashi Iwaic21bd022010-02-08 15:16:08 +01004759 /* sync mute LED */
Takashi Iwai1f43f6c2012-07-31 10:40:05 +02004760 if (spec->gpio_led) {
4761 if (spec->vmaster_mute.hook)
4762 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
4763 else /* the very first init call doesn't have vmaster yet */
4764 stac92xx_update_led_status(codec, false);
4765 }
Takashi Iwaic8822462012-05-15 09:11:36 +02004766
4767 /* sync the power-map */
4768 if (spec->num_pwrs)
4769 snd_hda_codec_write(codec, codec->afg, 0,
4770 AC_VERB_IDT_SET_POWER_MAP,
4771 spec->power_map_bits);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004772 if (spec->dac_list)
4773 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004774 return 0;
4775}
4776
Takashi Iwai603c4012008-07-30 15:01:44 +02004777static void stac92xx_free_kctls(struct hda_codec *codec)
4778{
4779 struct sigmatel_spec *spec = codec->spec;
4780
4781 if (spec->kctls.list) {
4782 struct snd_kcontrol_new *kctl = spec->kctls.list;
4783 int i;
4784 for (i = 0; i < spec->kctls.used; i++)
4785 kfree(kctl[i].name);
4786 }
4787 snd_array_free(&spec->kctls);
4788}
4789
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004790static void stac92xx_shutup_pins(struct hda_codec *codec)
4791{
4792 unsigned int i, def_conf;
4793
4794 if (codec->bus->shutdown)
4795 return;
4796 for (i = 0; i < codec->init_pins.used; i++) {
4797 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
4798 def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
4799 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004800 snd_hda_set_pin_ctl(codec, pin->nid, 0);
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004801 }
4802}
4803
Takashi Iwai167eae52009-11-06 15:47:50 +01004804static void stac92xx_shutup(struct hda_codec *codec)
4805{
4806 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004807
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05004808 stac92xx_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004809
4810 if (spec->eapd_mask)
4811 stac_gpio_set(codec, spec->gpio_mask,
4812 spec->gpio_dir, spec->gpio_data &
4813 ~spec->eapd_mask);
4814}
4815
Matt2f2f4252005-04-13 14:45:30 +02004816static void stac92xx_free(struct hda_codec *codec)
4817{
Mattc7d4b2f2005-06-27 14:59:41 +02004818 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004819
4820 if (! spec)
4821 return;
4822
Mattc7d4b2f2005-06-27 14:59:41 +02004823 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004824 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004825}
4826
Matt4e550962005-07-04 17:51:39 +02004827static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4828 unsigned int flag)
4829{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004830 unsigned int old_ctl, pin_ctl;
4831
4832 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004833 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004834
Takashi Iwaif9acba42007-05-29 18:01:06 +02004835 if (pin_ctl & AC_PINCTL_IN_EN) {
4836 /*
4837 * we need to check the current set-up direction of
4838 * shared input pins since they can be switched via
4839 * "xxx as Output" mixer switch
4840 */
4841 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004842 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004843 return;
4844 }
4845
Takashi Iwai8ce84192009-01-22 16:59:20 +01004846 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004847 /* if setting pin direction bits, clear the current
4848 direction bits first */
4849 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4850 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4851
Takashi Iwai8ce84192009-01-22 16:59:20 +01004852 pin_ctl |= flag;
4853 if (old_ctl != pin_ctl)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004854 snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004855}
4856
4857static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4858 unsigned int flag)
4859{
4860 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4861 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004862 if (pin_ctl & flag)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02004863 snd_hda_set_pin_ctl_cache(codec, nid, pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004864}
4865
Takashi Iwaid56757a2009-11-18 08:00:14 +01004866static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004867{
4868 if (!nid)
4869 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004870 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004871}
4872
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004873static void stac92xx_line_out_detect(struct hda_codec *codec,
4874 int presence)
4875{
4876 struct sigmatel_spec *spec = codec->spec;
4877 struct auto_pin_cfg *cfg = &spec->autocfg;
4878 int i;
4879
David Henningsson042b92c2012-08-22 16:10:43 +02004880 if (cfg->speaker_outs == 0)
4881 return;
4882
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004883 for (i = 0; i < cfg->line_outs; i++) {
4884 if (presence)
4885 break;
4886 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4887 if (presence) {
4888 unsigned int pinctl;
4889 pinctl = snd_hda_codec_read(codec,
4890 cfg->line_out_pins[i], 0,
4891 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4892 if (pinctl & AC_PINCTL_IN_EN)
4893 presence = 0; /* mic- or line-input */
4894 }
4895 }
4896
4897 if (presence) {
4898 /* disable speakers */
4899 for (i = 0; i < cfg->speaker_outs; i++)
4900 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4901 AC_PINCTL_OUT_EN);
4902 if (spec->eapd_mask && spec->eapd_switch)
4903 stac_gpio_set(codec, spec->gpio_mask,
4904 spec->gpio_dir, spec->gpio_data &
4905 ~spec->eapd_mask);
4906 } else {
4907 /* enable speakers */
4908 for (i = 0; i < cfg->speaker_outs; i++)
4909 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4910 AC_PINCTL_OUT_EN);
4911 if (spec->eapd_mask && spec->eapd_switch)
4912 stac_gpio_set(codec, spec->gpio_mask,
4913 spec->gpio_dir, spec->gpio_data |
4914 spec->eapd_mask);
4915 }
4916}
4917
Takashi Iwaid7a89432008-11-12 09:48:04 +01004918/* return non-zero if the hp-pin of the given array index isn't
4919 * a jack-detection target
4920 */
4921static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4922{
4923 struct auto_pin_cfg *cfg = &spec->autocfg;
4924
4925 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004926 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004927 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004928 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004929 return 1;
4930 /* ignore if the pin is set as line-out */
4931 if (cfg->hp_pins[i] == spec->hp_switch)
4932 return 1;
4933 return 0;
4934}
4935
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004936static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004937{
4938 struct sigmatel_spec *spec = codec->spec;
4939 struct auto_pin_cfg *cfg = &spec->autocfg;
4940 int i, presence;
4941
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004942 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004943 if (spec->gpio_mute)
4944 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4945 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4946
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004947 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004948 if (presence)
4949 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004950 if (no_hp_sensing(spec, i))
4951 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004952 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4953 if (presence) {
4954 unsigned int pinctl;
4955 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4956 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4957 if (pinctl & AC_PINCTL_IN_EN)
4958 presence = 0; /* mic- or line-input */
4959 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004960 }
Matt4e550962005-07-04 17:51:39 +02004961
4962 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004963 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004964 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004965 stac92xx_reset_pinctl(codec, spec->hp_switch,
4966 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004967 for (i = 0; i < cfg->line_outs; i++)
4968 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4969 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004970 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004971 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004972 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004973 stac92xx_set_pinctl(codec, spec->hp_switch,
4974 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004975 for (i = 0; i < cfg->line_outs; i++)
4976 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4977 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004978 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004979 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004980 /* toggle hp outs */
4981 for (i = 0; i < cfg->hp_outs; i++) {
4982 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4983 if (no_hp_sensing(spec, i))
4984 continue;
Takashi Iwai7bff1722012-02-29 09:41:17 +01004985 if (1 /*presence*/)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004986 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004987#if 0 /* FIXME */
4988/* Resetting the pinctl like below may lead to (a sort of) regressions
4989 * on some devices since they use the HP pin actually for line/speaker
4990 * outs although the default pin config shows a different pin (that is
4991 * wrong and useless).
4992 *
4993 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4994 * But, disabling the code below just works around it, and I'm too tired of
4995 * bug reports with such devices...
4996 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004997 else
4998 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004999#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01005000 }
Matt4e550962005-07-04 17:51:39 +02005001}
5002
Takashi Iwaif73d3582008-11-25 08:21:51 +01005003static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
5004 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005005{
5006 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01005007 unsigned int idx, val;
5008
5009 for (idx = 0; idx < spec->num_pwrs; idx++) {
5010 if (spec->pwr_nids[idx] == nid)
5011 break;
5012 }
5013 if (idx >= spec->num_pwrs)
5014 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005015
Charles Chinafef2cf2011-11-11 08:05:28 +01005016 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005017
Takashi Iwaic8822462012-05-15 09:11:36 +02005018 val = spec->power_map_bits;
Takashi Iwaif73d3582008-11-25 08:21:51 +01005019 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005020 val &= ~idx;
5021 else
5022 val |= idx;
5023
5024 /* power down unused output ports */
Takashi Iwaic8822462012-05-15 09:11:36 +02005025 if (val != spec->power_map_bits) {
5026 spec->power_map_bits = val;
5027 snd_hda_codec_write(codec, codec->afg, 0,
5028 AC_VERB_IDT_SET_POWER_MAP, val);
5029 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005030}
5031
Takashi Iwaif73d3582008-11-25 08:21:51 +01005032static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
5033{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01005034 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01005035}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005036
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005037/* get the pin connection (fixed, none, etc) */
5038static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5039{
5040 struct sigmatel_spec *spec = codec->spec;
5041 unsigned int cfg;
5042
5043 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5044 return get_defcfg_connect(cfg);
5045}
5046
5047static int stac92xx_connected_ports(struct hda_codec *codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02005048 const hda_nid_t *nids, int num_nids)
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005049{
5050 struct sigmatel_spec *spec = codec->spec;
5051 int idx, num;
5052 unsigned int def_conf;
5053
5054 for (num = 0; num < num_nids; num++) {
5055 for (idx = 0; idx < spec->num_pins; idx++)
5056 if (spec->pin_nids[idx] == nids[num])
5057 break;
5058 if (idx >= spec->num_pins)
5059 break;
5060 def_conf = stac_get_defcfg_connect(codec, idx);
5061 if (def_conf == AC_JACK_PORT_NONE)
5062 break;
5063 }
5064 return num;
5065}
5066
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005067static void stac92xx_mic_detect(struct hda_codec *codec)
5068{
5069 struct sigmatel_spec *spec = codec->spec;
5070 struct sigmatel_mic_route *mic;
5071
5072 if (get_pin_presence(codec, spec->ext_mic.pin))
5073 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02005074 else if (get_pin_presence(codec, spec->dock_mic.pin))
5075 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005076 else
5077 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02005078 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005079 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
5080 AC_VERB_SET_CONNECT_SEL,
5081 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02005082 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005083 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
5084 AC_VERB_SET_CONNECT_SEL,
5085 mic->mux_idx);
5086}
5087
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005088static void handle_unsol_event(struct hda_codec *codec,
Takashi Iwai3a938972011-10-28 01:16:55 +02005089 struct hda_jack_tbl *event)
Takashi Iwai314634b2006-09-21 11:56:18 +02005090{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005091 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005092 int data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005093
Takashi Iwai3a938972011-10-28 01:16:55 +02005094 switch (event->action) {
Takashi Iwai314634b2006-09-21 11:56:18 +02005095 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02005096 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02005097 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02005098 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005099 case STAC_MIC_EVENT:
5100 stac92xx_mic_detect(codec);
5101 break;
5102 }
5103
Takashi Iwai3a938972011-10-28 01:16:55 +02005104 switch (event->action) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005105 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02005106 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02005107 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005108 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005109 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005110 if (spec->num_pwrs > 0)
5111 stac92xx_pin_sense(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04005112
5113 switch (codec->subsystem_id) {
5114 case 0x103c308f:
5115 if (event->nid == 0xb) {
5116 int pin = AC_PINCTL_IN_EN;
5117
5118 if (get_pin_presence(codec, 0xa)
5119 && get_pin_presence(codec, 0xb))
5120 pin |= AC_PINCTL_VREF_80;
5121 if (!get_pin_presence(codec, 0xb))
5122 pin |= AC_PINCTL_VREF_80;
5123
5124 /* toggle VREF state based on mic + hp pin
5125 * status
5126 */
5127 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
5128 }
5129 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04005130 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005131 case STAC_VREF_EVENT:
5132 data = snd_hda_codec_read(codec, codec->afg, 0,
5133 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005134 /* toggle VREF state based on GPIOx status */
5135 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwai3a938972011-10-28 01:16:55 +02005136 !!(data & (1 << event->private_data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04005137 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02005138 }
5139}
5140
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005141static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
5142{
Takashi Iwai3a938972011-10-28 01:16:55 +02005143 struct hda_jack_tbl *event = snd_hda_jack_tbl_get(codec, nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02005144 if (!event)
5145 return;
5146 handle_unsol_event(codec, event);
5147}
5148
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305149static int hp_blike_system(u32 subsystem_id);
5150
5151static void set_hp_led_gpio(struct hda_codec *codec)
5152{
5153 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01005154 unsigned int gpio;
5155
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005156 if (spec->gpio_led)
5157 return;
5158
Takashi Iwai07f80442010-02-08 15:06:13 +01005159 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
5160 gpio &= AC_GPIO_IO_COUNT;
5161 if (gpio > 3)
5162 spec->gpio_led = 0x08; /* GPIO 3 */
5163 else
5164 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305165}
5166
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005167/*
5168 * This method searches for the mute LED GPIO configuration
5169 * provided as OEM string in SMBIOS. The format of that string
5170 * is HP_Mute_LED_P_G or HP_Mute_LED_P
5171 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
5172 * that corresponds to the NOT muted state of the master volume
5173 * and G is the index of the GPIO to use as the mute LED control (0..9)
5174 * If _G portion is missing it is assigned based on the codec ID
5175 *
5176 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
5177 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305178 *
5179 *
5180 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
5181 * SMBIOS - at least the ones I have seen do not have them - which include
5182 * my own system (HP Pavilion dv6-1110ax) and my cousin's
5183 * HP Pavilion dv9500t CTO.
5184 * Need more information on whether it is true across the entire series.
5185 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005186 */
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005187static int find_mute_led_cfg(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005188{
5189 struct sigmatel_spec *spec = codec->spec;
5190 const struct dmi_device *dev = NULL;
5191
Takashi Iwai75609312012-05-14 16:52:00 +02005192 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
5193 get_int_hint(codec, "gpio_led_polarity",
5194 &spec->gpio_led_polarity);
5195 return 1;
5196 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005197 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
5198 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
5199 NULL, dev))) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005200 if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305201 &spec->gpio_led_polarity,
5202 &spec->gpio_led) == 2) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005203 unsigned int max_gpio;
5204 max_gpio = snd_hda_param_read(codec, codec->afg,
5205 AC_PAR_GPIO_CAP);
5206 max_gpio &= AC_GPIO_IO_COUNT;
5207 if (spec->gpio_led < max_gpio)
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005208 spec->gpio_led = 1 << spec->gpio_led;
Takashi Iwaif1a73742011-12-04 13:44:06 +01005209 else
5210 spec->vref_mute_led_nid = spec->gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005211 return 1;
5212 }
5213 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305214 &spec->gpio_led_polarity) == 1) {
5215 set_hp_led_gpio(codec);
5216 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005217 }
Gustavo Maciel Dias Vieirae2ef36c2011-12-13 11:47:22 -02005218 /* BIOS bug: unfilled OEM string */
5219 if (strstr(dev->name, "HP_Mute_LED_P_G")) {
5220 set_hp_led_gpio(codec);
Gustavo Maciel Dias Vieiraa6a600d2012-01-24 13:27:56 -02005221 switch (codec->subsystem_id) {
5222 case 0x103c148a:
5223 spec->gpio_led_polarity = 0;
5224 break;
5225 default:
5226 spec->gpio_led_polarity = 1;
5227 break;
5228 }
Gustavo Maciel Dias Vieirae2ef36c2011-12-13 11:47:22 -02005229 return 1;
5230 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005231 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305232
5233 /*
5234 * Fallback case - if we don't find the DMI strings,
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005235 * we statically set the GPIO - if not a B-series system
5236 * and default polarity is provided
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305237 */
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06005238 if (!hp_blike_system(codec->subsystem_id) &&
5239 (default_polarity == 0 || default_polarity == 1)) {
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305240 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01005241 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305242 return 1;
5243 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005244 }
5245 return 0;
5246}
5247
5248static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08005249{
5250 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005251 case 0x103c1520:
5252 case 0x103c1521:
5253 case 0x103c1523:
5254 case 0x103c1524:
5255 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08005256 case 0x103c1722:
5257 case 0x103c1723:
5258 case 0x103c1724:
5259 case 0x103c1725:
5260 case 0x103c1726:
5261 case 0x103c1727:
5262 case 0x103c1728:
5263 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005264 case 0x103c172a:
5265 case 0x103c172b:
5266 case 0x103c307e:
5267 case 0x103c307f:
5268 case 0x103c3080:
5269 case 0x103c3081:
5270 case 0x103c7007:
5271 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08005272 return 1;
5273 }
5274 return 0;
5275}
5276
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005277#ifdef CONFIG_PROC_FS
5278static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
5279 struct hda_codec *codec, hda_nid_t nid)
5280{
5281 if (nid == codec->afg)
5282 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
Takashi Iwaic8822462012-05-15 09:11:36 +02005283 snd_hda_codec_read(codec, nid, 0,
5284 AC_VERB_IDT_GET_POWER_MAP, 0));
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005285}
5286
5287static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
5288 struct hda_codec *codec,
5289 unsigned int verb)
5290{
5291 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
5292 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
5293}
5294
5295/* stac92hd71bxx, stac92hd73xx */
5296static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
5297 struct hda_codec *codec, hda_nid_t nid)
5298{
5299 stac92hd_proc_hook(buffer, codec, nid);
5300 if (nid == codec->afg)
5301 analog_loop_proc_hook(buffer, codec, 0xfa0);
5302}
5303
5304static void stac9205_proc_hook(struct snd_info_buffer *buffer,
5305 struct hda_codec *codec, hda_nid_t nid)
5306{
5307 if (nid == codec->afg)
5308 analog_loop_proc_hook(buffer, codec, 0xfe0);
5309}
5310
5311static void stac927x_proc_hook(struct snd_info_buffer *buffer,
5312 struct hda_codec *codec, hda_nid_t nid)
5313{
5314 if (nid == codec->afg)
5315 analog_loop_proc_hook(buffer, codec, 0xfeb);
5316}
5317#else
5318#define stac92hd_proc_hook NULL
5319#define stac92hd7x_proc_hook NULL
5320#define stac9205_proc_hook NULL
5321#define stac927x_proc_hook NULL
5322#endif
5323
Takashi Iwai2a439522011-07-26 09:52:50 +02005324#ifdef CONFIG_PM
Mattff6fdc32005-06-27 15:06:52 +02005325static int stac92xx_resume(struct hda_codec *codec)
5326{
Takashi Iwai2c885872008-11-18 09:36:55 +01005327 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02005328 snd_hda_codec_resume_amp(codec);
5329 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01005330 /* fake event to set up pins again to override cached values */
Takashi Iwaif2cbba72012-01-11 12:34:11 +01005331 stac_fake_hp_events(codec);
Mattff6fdc32005-06-27 15:06:52 +02005332 return 0;
5333}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005334
Takashi Iwai68cb2b52012-07-02 15:20:37 +02005335static int stac92xx_suspend(struct hda_codec *codec)
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005336{
5337 stac92xx_shutup(codec);
5338 return 0;
5339}
5340
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005341static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
5342 unsigned int power_state)
5343{
5344 unsigned int afg_power_state = power_state;
5345 struct sigmatel_spec *spec = codec->spec;
5346
5347 if (power_state == AC_PWRST_D3) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005348 if (spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005349 /* with vref-out pin used for mute led control
5350 * codec AFG is prevented from D3 state
5351 */
5352 afg_power_state = AC_PWRST_D1;
5353 }
5354 /* this delay seems necessary to avoid click noise at power-down */
5355 msleep(100);
5356 }
5357 snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
5358 afg_power_state);
5359 snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
5360}
Takashi Iwai350eba432012-03-16 16:09:03 +01005361#else
5362#define stac92xx_suspend NULL
5363#define stac92xx_resume NULL
Takashi Iwai350eba432012-03-16 16:09:03 +01005364#define stac92xx_set_power_state NULL
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005365#endif /* CONFIG_PM */
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005366
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005367/* update mute-LED accoring to the master switch */
5368static void stac92xx_update_led_status(struct hda_codec *codec, int enabled)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005369{
5370 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005371 int muted = !enabled;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005372
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005373 if (!spec->gpio_led)
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005374 return;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005375
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005376 /* LED state is inverted on these systems */
5377 if (spec->gpio_led_polarity)
5378 muted = !muted;
5379
Takashi Iwaif1a73742011-12-04 13:44:06 +01005380 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005381 if (muted)
Takashi Iwai3e843192012-04-19 12:04:03 +02005382 spec->gpio_data |= spec->gpio_led;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005383 else
Takashi Iwai3e843192012-04-19 12:04:03 +02005384 spec->gpio_data &= ~spec->gpio_led;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005385 stac_gpio_set(codec, spec->gpio_mask,
5386 spec->gpio_dir, spec->gpio_data);
5387 } else {
Takashi Iwai2faa3bf2012-03-12 12:30:22 +01005388 spec->vref_led = muted ? AC_PINCTL_VREF_50 : AC_PINCTL_VREF_GRD;
Takashi Iwaif1a73742011-12-04 13:44:06 +01005389 stac_vrefout_set(codec, spec->vref_mute_led_nid,
5390 spec->vref_led);
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005391 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005392}
Vitaliy Kulikov7df1ce12011-07-25 17:52:57 -05005393
Takashi Iwai2b635362011-05-02 12:33:43 +02005394static const struct hda_codec_ops stac92xx_patch_ops = {
Matt2f2f4252005-04-13 14:45:30 +02005395 .build_controls = stac92xx_build_controls,
5396 .build_pcms = stac92xx_build_pcms,
5397 .init = stac92xx_init,
5398 .free = stac92xx_free,
David Henningsson29adc4b2012-09-25 11:31:00 +02005399 .unsol_event = snd_hda_jack_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02005400#ifdef CONFIG_PM
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005401 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005402 .resume = stac92xx_resume,
5403#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005404 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005405};
5406
Takashi Iwai361dab32012-05-09 14:35:27 +02005407static int alloc_stac_spec(struct hda_codec *codec, int num_pins,
5408 const hda_nid_t *pin_nids)
5409{
5410 struct sigmatel_spec *spec;
5411
5412 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5413 if (!spec)
5414 return -ENOMEM;
5415 codec->spec = spec;
5416 codec->no_trigger_sense = 1; /* seems common with STAC/IDT codecs */
5417 spec->num_pins = num_pins;
5418 spec->pin_nids = pin_nids;
5419 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
5420 return 0;
5421}
5422
Matt2f2f4252005-04-13 14:45:30 +02005423static int patch_stac9200(struct hda_codec *codec)
5424{
5425 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005426 int err;
Matt2f2f4252005-04-13 14:45:30 +02005427
Takashi Iwai361dab32012-05-09 14:35:27 +02005428 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9200_pin_nids),
5429 stac9200_pin_nids);
5430 if (err < 0)
5431 return err;
Matt2f2f4252005-04-13 14:45:30 +02005432
Takashi Iwai361dab32012-05-09 14:35:27 +02005433 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005434 spec->linear_tone_beep = 1;
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005435
5436 snd_hda_pick_fixup(codec, stac9200_models, stac9200_fixup_tbl,
5437 stac9200_fixups);
Matt2f2f4252005-04-13 14:45:30 +02005438
5439 spec->multiout.max_channels = 2;
5440 spec->multiout.num_dacs = 1;
5441 spec->multiout.dac_nids = stac9200_dac_nids;
5442 spec->adc_nids = stac9200_adc_nids;
5443 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005444 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005445 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005446 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005447 spec->num_pwrs = 0;
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005448 snd_hda_add_verbs(codec, stac9200_eapd_init);
Mattc7d4b2f2005-06-27 14:59:41 +02005449
Matt2f2f4252005-04-13 14:45:30 +02005450 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005451
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005452 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
Takashi Iwai117f2572008-03-18 09:53:23 +01005453
Mattc7d4b2f2005-06-27 14:59:41 +02005454 err = stac9200_parse_auto_config(codec);
5455 if (err < 0) {
5456 stac92xx_free(codec);
5457 return err;
5458 }
Matt2f2f4252005-04-13 14:45:30 +02005459
5460 codec->patch_ops = stac92xx_patch_ops;
5461
Takashi Iwaid39a3ae2013-01-14 14:06:26 +01005462 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5463
Matt2f2f4252005-04-13 14:45:30 +02005464 return 0;
5465}
5466
Tobin Davis8e21c342007-01-08 11:04:17 +01005467static int patch_stac925x(struct hda_codec *codec)
5468{
5469 struct sigmatel_spec *spec;
5470 int err;
5471
Takashi Iwai361dab32012-05-09 14:35:27 +02005472 err = alloc_stac_spec(codec, ARRAY_SIZE(stac925x_pin_nids),
5473 stac925x_pin_nids);
5474 if (err < 0)
5475 return err;
Tobin Davis8e21c342007-01-08 11:04:17 +01005476
Takashi Iwai361dab32012-05-09 14:35:27 +02005477 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005478 spec->linear_tone_beep = 1;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005479
Takashi Iwaid2077d42013-01-14 14:20:16 +01005480 snd_hda_pick_fixup(codec, stac925x_models, stac925x_fixup_tbl,
5481 stac925x_fixups);
Tobin Davis8e21c342007-01-08 11:04:17 +01005482
5483 spec->multiout.max_channels = 2;
5484 spec->multiout.num_dacs = 1;
5485 spec->multiout.dac_nids = stac925x_dac_nids;
5486 spec->adc_nids = stac925x_adc_nids;
5487 spec->mux_nids = stac925x_mux_nids;
5488 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005489 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005490 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005491 switch (codec->vendor_id) {
5492 case 0x83847632: /* STAC9202 */
5493 case 0x83847633: /* STAC9202D */
5494 case 0x83847636: /* STAC9251 */
5495 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005496 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005497 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005498 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5499 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005500 break;
5501 default:
5502 spec->num_dmics = 0;
5503 break;
5504 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005505
Takashi Iwaid2077d42013-01-14 14:20:16 +01005506 snd_hda_add_verbs(codec, stac925x_core_init);
Tobin Davis8e21c342007-01-08 11:04:17 +01005507 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005508 spec->num_caps = 1;
5509 spec->capvols = stac925x_capvols;
5510 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005511
Takashi Iwaid2077d42013-01-14 14:20:16 +01005512 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
5513
Charles Chin9009b0e2011-11-03 10:27:27 +01005514 err = stac92xx_parse_auto_config(codec);
Takashi Iwaid2077d42013-01-14 14:20:16 +01005515 if (!err)
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005516 err = -EINVAL;
Tobin Davis8e21c342007-01-08 11:04:17 +01005517 if (err < 0) {
5518 stac92xx_free(codec);
5519 return err;
5520 }
5521
5522 codec->patch_ops = stac92xx_patch_ops;
5523
Takashi Iwaid2077d42013-01-14 14:20:16 +01005524 snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
5525
Tobin Davis8e21c342007-01-08 11:04:17 +01005526 return 0;
5527}
5528
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005529static int patch_stac92hd73xx(struct hda_codec *codec)
5530{
5531 struct sigmatel_spec *spec;
5532 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
Takashi Iwai361dab32012-05-09 14:35:27 +02005533 int err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005534 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005535
Takashi Iwai361dab32012-05-09 14:35:27 +02005536 err = alloc_stac_spec(codec, ARRAY_SIZE(stac92hd73xx_pin_nids),
5537 stac92hd73xx_pin_nids);
5538 if (err < 0)
5539 return err;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005540
Takashi Iwai361dab32012-05-09 14:35:27 +02005541 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005542 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005543 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005544 spec->board_config = snd_hda_check_board_config(codec,
5545 STAC_92HD73XX_MODELS,
5546 stac92hd73xx_models,
5547 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005548 /* check codec subsystem id if not found */
5549 if (spec->board_config < 0)
5550 spec->board_config =
5551 snd_hda_check_board_codec_sid_config(codec,
5552 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5553 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005554again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005555 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005556 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5557 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005558 else
5559 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005560 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005561
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005562 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005563 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5564
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005565 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005566 printk(KERN_WARNING "hda_codec: Could not determine "
5567 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005568 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005569 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005570 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005571 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005572 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005573 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005574 break;
5575 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005576 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005577 break;
5578 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005579 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5580 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005581 }
5582 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005583
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005584 spec->aloopback_mask = 0x01;
5585 spec->aloopback_shift = 8;
5586
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005587 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005588 spec->mux_nids = stac92hd73xx_mux_nids;
5589 spec->adc_nids = stac92hd73xx_adc_nids;
5590 spec->dmic_nids = stac92hd73xx_dmic_nids;
5591 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005592 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005593
5594 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5595 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005596 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005597
Takashi Iwai6479c632009-07-28 18:20:25 +02005598 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5599 spec->capvols = stac92hd73xx_capvols;
5600 spec->capsws = stac92hd73xx_capsws;
5601
Matthew Ranostaya7662642008-02-21 07:51:14 +01005602 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005603 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005604 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005605 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005606 case STAC_DELL_M6_AMIC:
5607 case STAC_DELL_M6_DMIC:
5608 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005609 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005610 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005611
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005612 switch (spec->board_config) {
5613 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005614 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005615 spec->num_dmics = 0;
5616 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005617 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005618 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005619 spec->num_dmics = 1;
5620 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005621 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005622 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5623 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005624 spec->num_dmics = 1;
5625 break;
5626 }
5627 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005628 case STAC_ALIENWARE_M17X:
5629 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5630 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5631 spec->eapd_switch = 0;
5632 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005633 default:
5634 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005635 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005636 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005637 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005638 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005639 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005640 /* GPIO0 High = Enable EAPD */
5641 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5642 spec->gpio_data = 0x01;
5643 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005644
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005645 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5646 spec->pwr_nids = stac92hd73xx_pwr_nids;
5647
Charles Chin9009b0e2011-11-03 10:27:27 +01005648 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005649
5650 if (!err) {
5651 if (spec->board_config < 0) {
5652 printk(KERN_WARNING "hda_codec: No auto-config is "
5653 "available, default to model=ref\n");
5654 spec->board_config = STAC_92HD73XX_REF;
5655 goto again;
5656 }
5657 err = -EINVAL;
5658 }
5659
5660 if (err < 0) {
5661 stac92xx_free(codec);
5662 return err;
5663 }
5664
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005665 if (spec->board_config == STAC_92HD73XX_NO_JD)
5666 spec->hp_detect = 0;
5667
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005668 codec->patch_ops = stac92xx_patch_ops;
5669
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005670 codec->proc_widget_hook = stac92hd7x_proc_hook;
5671
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005672 return 0;
5673}
5674
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005675static int hp_bnb2011_with_dock(struct hda_codec *codec)
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005676{
5677 if (codec->vendor_id != 0x111d7605 &&
5678 codec->vendor_id != 0x111d76d1)
5679 return 0;
5680
5681 switch (codec->subsystem_id) {
5682 case 0x103c1618:
5683 case 0x103c1619:
5684 case 0x103c161a:
5685 case 0x103c161b:
5686 case 0x103c161c:
5687 case 0x103c161d:
5688 case 0x103c161e:
5689 case 0x103c161f:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005690
5691 case 0x103c162a:
5692 case 0x103c162b:
5693
5694 case 0x103c1630:
5695 case 0x103c1631:
5696
5697 case 0x103c1633:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005698 case 0x103c1634:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005699 case 0x103c1635:
5700
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005701 case 0x103c3587:
5702 case 0x103c3588:
5703 case 0x103c3589:
5704 case 0x103c358a:
5705
5706 case 0x103c3667:
5707 case 0x103c3668:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005708 case 0x103c3669:
5709
5710 return 1;
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005711 }
5712 return 0;
5713}
5714
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005715static void stac92hd8x_add_pin(struct hda_codec *codec, hda_nid_t nid)
5716{
5717 struct sigmatel_spec *spec = codec->spec;
5718 unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
5719 int i;
5720
5721 spec->auto_pin_nids[spec->auto_pin_cnt] = nid;
5722 spec->auto_pin_cnt++;
5723
5724 if (get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
5725 get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE) {
5726 for (i = 0; i < ARRAY_SIZE(stac92hd83xxx_dmic_nids); i++) {
5727 if (nid == stac92hd83xxx_dmic_nids[i]) {
5728 spec->auto_dmic_nids[spec->auto_dmic_cnt] = nid;
5729 spec->auto_dmic_cnt++;
5730 }
5731 }
5732 }
5733}
5734
5735static void stac92hd8x_add_adc(struct hda_codec *codec, hda_nid_t nid)
5736{
5737 struct sigmatel_spec *spec = codec->spec;
5738
5739 spec->auto_adc_nids[spec->auto_adc_cnt] = nid;
5740 spec->auto_adc_cnt++;
5741}
5742
5743static void stac92hd8x_add_mux(struct hda_codec *codec, hda_nid_t nid)
5744{
5745 int i, j;
5746 struct sigmatel_spec *spec = codec->spec;
5747
5748 for (i = 0; i < spec->auto_adc_cnt; i++) {
5749 if (get_connection_index(codec,
5750 spec->auto_adc_nids[i], nid) >= 0) {
5751 /* mux and volume for adc_nids[i] */
5752 if (!spec->auto_mux_nids[i]) {
5753 spec->auto_mux_nids[i] = nid;
5754 /* 92hd codecs capture volume is in mux */
5755 spec->auto_capvols[i] = HDA_COMPOSE_AMP_VAL(nid,
5756 3, 0, HDA_OUTPUT);
5757 }
5758 for (j = 0; j < spec->auto_dmic_cnt; j++) {
5759 if (get_connection_index(codec, nid,
5760 spec->auto_dmic_nids[j]) >= 0) {
5761 /* dmux for adc_nids[i] */
5762 if (!spec->auto_dmux_nids[i])
5763 spec->auto_dmux_nids[i] = nid;
5764 break;
5765 }
5766 }
5767 break;
5768 }
5769 }
5770}
5771
5772static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5773{
5774 hda_nid_t nid, end_nid;
5775 unsigned int wid_caps, wid_type;
5776 struct sigmatel_spec *spec = codec->spec;
5777
5778 end_nid = codec->start_nid + codec->num_nodes;
5779
5780 for (nid = codec->start_nid; nid < end_nid; nid++) {
5781 wid_caps = get_wcaps(codec, nid);
5782 wid_type = get_wcaps_type(wid_caps);
5783
5784 if (wid_type == AC_WID_PIN)
5785 stac92hd8x_add_pin(codec, nid);
5786
5787 if (wid_type == AC_WID_AUD_IN && !(wid_caps & AC_WCAP_DIGITAL))
5788 stac92hd8x_add_adc(codec, nid);
5789 }
5790
5791 for (nid = codec->start_nid; nid < end_nid; nid++) {
5792 wid_caps = get_wcaps(codec, nid);
5793 wid_type = get_wcaps_type(wid_caps);
5794
5795 if (wid_type == AC_WID_AUD_SEL)
5796 stac92hd8x_add_mux(codec, nid);
5797 }
5798
5799 spec->pin_nids = spec->auto_pin_nids;
5800 spec->num_pins = spec->auto_pin_cnt;
5801 spec->adc_nids = spec->auto_adc_nids;
5802 spec->num_adcs = spec->auto_adc_cnt;
5803 spec->capvols = spec->auto_capvols;
5804 spec->capsws = spec->auto_capvols;
5805 spec->num_caps = spec->auto_adc_cnt;
5806 spec->mux_nids = spec->auto_mux_nids;
5807 spec->num_muxes = spec->auto_adc_cnt;
5808 spec->dmux_nids = spec->auto_dmux_nids;
5809 spec->num_dmuxes = spec->auto_adc_cnt;
5810 spec->dmic_nids = spec->auto_dmic_nids;
5811 spec->num_dmics = spec->auto_dmic_cnt;
5812}
5813
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005814static int patch_stac92hd83xxx(struct hda_codec *codec)
5815{
5816 struct sigmatel_spec *spec;
Takashi Iwaia3e19972012-07-26 08:17:20 +02005817 int default_polarity = -1; /* no default cfg */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005818 int err;
5819
Takashi Iwai361dab32012-05-09 14:35:27 +02005820 err = alloc_stac_spec(codec, 0, NULL); /* pins filled later */
5821 if (err < 0)
5822 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005823
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005824 if (hp_bnb2011_with_dock(codec)) {
5825 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5826 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5827 }
5828
Takashi Iwaic36b5b02012-08-28 09:20:13 -07005829 codec->epss = 0; /* longer delay needed for D3 */
Vitaliy Kulikov699d8992011-03-10 13:43:35 -06005830 stac92hd8x_fill_auto_spec(codec);
5831
Takashi Iwai361dab32012-05-09 14:35:27 +02005832 spec = codec->spec;
Takashi Iwai1db7ccdb2010-12-03 15:19:14 +01005833 spec->linear_tone_beep = 0;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005834 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005835 spec->digbeep_nid = 0x21;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005836 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005837 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005838 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005839 spec->init = stac92hd83xxx_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005840
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005841 spec->board_config = snd_hda_check_board_config(codec,
5842 STAC_92HD83XXX_MODELS,
5843 stac92hd83xxx_models,
5844 stac92hd83xxx_cfg_tbl);
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06005845 /* check codec subsystem id if not found */
5846 if (spec->board_config < 0)
5847 spec->board_config =
5848 snd_hda_check_board_codec_sid_config(codec,
5849 STAC_92HD83XXX_MODELS, stac92hd83xxx_models,
5850 stac92hd83xxx_codec_id_cfg_tbl);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005851again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005852 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005853 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5854 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005855 else
5856 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005857 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005858
Takashi Iwaib4e81872009-11-18 17:20:24 +01005859 codec->patch_ops = stac92xx_patch_ops;
5860
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06005861 switch (spec->board_config) {
5862 case STAC_HP_ZEPHYR:
5863 spec->init = stac92hd83xxx_hp_zephyr_init;
5864 break;
Takashi Iwaia3e19972012-07-26 08:17:20 +02005865 case STAC_92HD83XXX_HP_LED:
Takashi Iwaiff8a1e22012-07-31 10:16:59 +02005866 default_polarity = 0;
5867 break;
5868 case STAC_92HD83XXX_HP_INV_LED:
Takashi Iwaia3e19972012-07-26 08:17:20 +02005869 default_polarity = 1;
5870 break;
Takashi Iwai62cbde12012-09-14 11:58:54 +02005871 case STAC_92HD83XXX_HP_MIC_LED:
5872 spec->mic_mute_led_gpio = 0x08; /* GPIO3 */
5873 break;
David Henningsson8d032a82012-10-09 12:48:40 +02005874 case STAC_92HD83XXX_HEADSET_JACK:
5875 spec->headset_jack = 1;
5876 break;
Vitaliy Kulikov5556e142012-02-27 16:47:37 -06005877 }
5878
Takashi Iwaia3e19972012-07-26 08:17:20 +02005879 if (find_mute_led_cfg(codec, default_polarity))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005880 snd_printd("mute LED gpio %d polarity %d\n",
5881 spec->gpio_led,
5882 spec->gpio_led_polarity);
5883
Takashi Iwaib4e81872009-11-18 17:20:24 +01005884 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01005885 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005886 spec->gpio_mask |= spec->gpio_led;
5887 spec->gpio_dir |= spec->gpio_led;
5888 spec->gpio_data |= spec->gpio_led;
5889 } else {
5890 codec->patch_ops.set_power_state =
5891 stac92xx_set_power_state;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05005892 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005893 }
Takashi Iwaib4e81872009-11-18 17:20:24 +01005894
Takashi Iwai62cbde12012-09-14 11:58:54 +02005895 if (spec->mic_mute_led_gpio) {
5896 spec->gpio_mask |= spec->mic_mute_led_gpio;
5897 spec->gpio_dir |= spec->mic_mute_led_gpio;
5898 spec->mic_mute_led_on = true;
5899 spec->gpio_data |= spec->mic_mute_led_gpio;
5900 }
5901
Charles Chin9009b0e2011-11-03 10:27:27 +01005902 err = stac92xx_parse_auto_config(codec);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005903 if (!err) {
5904 if (spec->board_config < 0) {
5905 printk(KERN_WARNING "hda_codec: No auto-config is "
5906 "available, default to model=ref\n");
5907 spec->board_config = STAC_92HD83XXX_REF;
5908 goto again;
5909 }
5910 err = -EINVAL;
5911 }
5912
5913 if (err < 0) {
5914 stac92xx_free(codec);
5915 return err;
5916 }
5917
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005918 codec->proc_widget_hook = stac92hd_proc_hook;
5919
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005920 return 0;
5921}
5922
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005923static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5924 hda_nid_t dig0pin)
5925{
5926 struct sigmatel_spec *spec = codec->spec;
5927 int idx;
5928
5929 for (idx = 0; idx < spec->num_pins; idx++)
5930 if (spec->pin_nids[idx] == dig0pin)
5931 break;
5932 if ((idx + 2) >= spec->num_pins)
5933 return 0;
5934
5935 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005936 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005937 return 2;
5938
5939 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005940 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005941 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005942 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005943 return 1;
5944 else
5945 return 0;
5946}
5947
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005948/* HP dv7 bass switch - GPIO5 */
5949#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5950static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5951 struct snd_ctl_elem_value *ucontrol)
5952{
5953 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5954 struct sigmatel_spec *spec = codec->spec;
5955 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5956 return 0;
5957}
5958
5959static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5960 struct snd_ctl_elem_value *ucontrol)
5961{
5962 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5963 struct sigmatel_spec *spec = codec->spec;
5964 unsigned int gpio_data;
5965
5966 gpio_data = (spec->gpio_data & ~0x20) |
5967 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5968 if (gpio_data == spec->gpio_data)
5969 return 0;
5970 spec->gpio_data = gpio_data;
5971 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5972 return 1;
5973}
5974
Takashi Iwai2b635362011-05-02 12:33:43 +02005975static const struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005976 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5977 .info = stac_hp_bass_gpio_info,
5978 .get = stac_hp_bass_gpio_get,
5979 .put = stac_hp_bass_gpio_put,
5980};
5981
5982static int stac_add_hp_bass_switch(struct hda_codec *codec)
5983{
5984 struct sigmatel_spec *spec = codec->spec;
5985
5986 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5987 "Bass Speaker Playback Switch", 0))
5988 return -ENOMEM;
5989
5990 spec->gpio_mask |= 0x20;
5991 spec->gpio_dir |= 0x20;
5992 spec->gpio_data |= 0x20;
5993 return 0;
5994}
5995
Matthew Ranostaye035b842007-11-06 11:53:55 +01005996static int patch_stac92hd71bxx(struct hda_codec *codec)
5997{
5998 struct sigmatel_spec *spec;
Takashi Iwai2b635362011-05-02 12:33:43 +02005999 const struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01006000 unsigned int pin_cfg;
Takashi Iwai361dab32012-05-09 14:35:27 +02006001 int err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006002
Takashi Iwai361dab32012-05-09 14:35:27 +02006003 err = alloc_stac_spec(codec, STAC92HD71BXX_NUM_PINS,
6004 stac92hd71bxx_pin_nids_4port);
6005 if (err < 0)
6006 return err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006007
Takashi Iwai361dab32012-05-09 14:35:27 +02006008 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006009 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006010 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05006011 switch (codec->vendor_id) {
6012 case 0x111d76b6:
6013 case 0x111d76b7:
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05006014 break;
6015 case 0x111d7603:
6016 case 0x111d7608:
6017 /* On 92HD75Bx 0x27 isn't a pin nid */
6018 spec->num_pins--;
6019 /* fallthrough */
6020 default:
6021 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
6022 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006023 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006024 spec->board_config = snd_hda_check_board_config(codec,
6025 STAC_92HD71BXX_MODELS,
6026 stac92hd71bxx_models,
6027 stac92hd71bxx_cfg_tbl);
6028again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006029 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006030 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6031 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006032 else
6033 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006034 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006035
Takashi Iwaifc64b262009-09-14 15:33:01 +02006036 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01006037 /* GPIO0 = EAPD */
6038 spec->gpio_mask = 0x01;
6039 spec->gpio_dir = 0x01;
6040 spec->gpio_data = 0x01;
6041 }
6042
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006043 spec->dmic_nids = stac92hd71bxx_dmic_nids;
6044 spec->dmux_nids = stac92hd71bxx_dmux_nids;
6045
Takashi Iwai6479c632009-07-28 18:20:25 +02006046 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
6047 spec->capvols = stac92hd71bxx_capvols;
6048 spec->capsws = stac92hd71bxx_capsws;
6049
Matthew Ranostay541eee82007-12-14 12:08:04 +01006050 switch (codec->vendor_id) {
6051 case 0x111d76b6: /* 4 Port without Analog Mixer */
6052 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02006053 unmute_init++;
6054 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01006055 case 0x111d76b4: /* 6 Port without Analog Mixer */
6056 case 0x111d76b5:
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04006057 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006058 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006059 stac92hd71bxx_dmic_nids,
6060 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01006061 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006062 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01006063 switch (spec->board_config) {
6064 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04006065 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwai3a938972011-10-28 01:16:55 +02006066 err = stac_add_event(codec, codec->afg,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006067 STAC_VREF_EVENT, 0x02);
6068 if (err < 0)
6069 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006070 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04006071 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
Takashi Iwai3a938972011-10-28 01:16:55 +02006072 snd_hda_jack_detect_enable(codec, codec->afg, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04006073 spec->gpio_mask |= 0x02;
6074 break;
6075 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006076 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01006077 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006078 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006079
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006080 /* disable VSW */
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05006081 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01006082 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
6083 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Takashi Iwai2b635362011-05-02 12:33:43 +02006084 spec->dmic_nids = stac92hd71bxx_dmic_5port_nids;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006085 spec->num_dmics = stac92xx_connected_ports(codec,
Takashi Iwai2b635362011-05-02 12:33:43 +02006086 stac92hd71bxx_dmic_5port_nids,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006087 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006088 break;
6089 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01006090 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006091 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006092
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006093 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01006094 default:
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04006095 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006096 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006097 stac92hd71bxx_dmic_nids,
6098 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02006099 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01006100 }
6101
David Henningsson5e68fb32012-08-16 14:11:09 +02006102 if (get_wcaps_type(get_wcaps(codec, 0x28)) == AC_WID_VOL_KNB)
6103 spec->init = stac92hd71bxx_core_init;
6104
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05006105 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
6106 snd_hda_sequence_write_cache(codec, unmute_init);
6107
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006108 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04006109 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01006110 spec->aloopback_shift = 0;
6111
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02006112 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006113 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006114 spec->mux_nids = stac92hd71bxx_mux_nids;
6115 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02006116 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006117 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006118
6119 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
6120 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02006121 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05006122 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006123
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05306124 snd_printdd("Found board config: %d\n", spec->board_config);
6125
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006126 switch (spec->board_config) {
6127 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006128 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01006129 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04006130 stac92xx_auto_set_pinctl(codec, 0x0e,
6131 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05006132 /* fallthru */
6133 case STAC_DELL_M4_2:
6134 spec->num_dmics = 0;
6135 spec->num_smuxes = 0;
6136 spec->num_dmuxes = 0;
6137 break;
6138 case STAC_DELL_M4_1:
6139 case STAC_DELL_M4_3:
6140 spec->num_dmics = 1;
6141 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01006142 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006143 break;
James Gardiner514bf542009-05-03 04:00:44 -04006144 case STAC_HP_DV4_1222NR:
6145 spec->num_dmics = 1;
6146 /* I don't know if it needs 1 or 2 smuxes - will wait for
6147 * bug reports to fix if needed
6148 */
6149 spec->num_smuxes = 1;
6150 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04006151 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02006152 case STAC_HP_DV4:
6153 spec->gpio_led = 0x01;
6154 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01006155 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01006156 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01006157 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02006158 /* HP dv6 gives the headphone pin as a line-out. Thus we
6159 * need to set hp_detect flag here to force to enable HP
6160 * detection.
6161 */
6162 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01006163 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01006164 case STAC_HP_HDX:
6165 spec->num_dmics = 1;
6166 spec->num_dmuxes = 1;
6167 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02006168 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006169 break;
6170 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01006171
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01006172 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01006173 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
6174 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
6175 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
6176 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
6177 /* It was changed in the BIOS to just satisfy MS DTM.
6178 * Lets turn it back into slaved HP
6179 */
6180 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
6181 | (AC_JACK_HP_OUT <<
6182 AC_DEFCFG_DEVICE_SHIFT);
6183 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
6184 | AC_DEFCFG_SEQUENCE)))
6185 | 0x1f;
6186 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
6187 }
6188 }
6189
Vitaliy Kulikov6a557c92011-12-12 17:35:13 -06006190 if (find_mute_led_cfg(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01006191 snd_printd("mute LED gpio %d polarity %d\n",
6192 spec->gpio_led,
6193 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01006194
Takashi Iwai86d190e2009-05-26 15:18:58 +02006195 if (spec->gpio_led) {
Takashi Iwaif1a73742011-12-04 13:44:06 +01006196 if (!spec->vref_mute_led_nid) {
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05006197 spec->gpio_mask |= spec->gpio_led;
6198 spec->gpio_dir |= spec->gpio_led;
6199 spec->gpio_data |= spec->gpio_led;
6200 } else {
6201 codec->patch_ops.set_power_state =
6202 stac92xx_set_power_state;
Vitaliy Kulikov45eebda2011-07-26 16:56:20 -05006203 }
Takashi Iwai86d190e2009-05-26 15:18:58 +02006204 }
Matthew Ranostay6a14f582008-09-12 12:02:30 -04006205
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01006206 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01006207
Charles Chin9009b0e2011-11-03 10:27:27 +01006208 err = stac92xx_parse_auto_config(codec);
Matthew Ranostaye035b842007-11-06 11:53:55 +01006209 if (!err) {
6210 if (spec->board_config < 0) {
6211 printk(KERN_WARNING "hda_codec: No auto-config is "
6212 "available, default to model=ref\n");
6213 spec->board_config = STAC_92HD71BXX_REF;
6214 goto again;
6215 }
6216 err = -EINVAL;
6217 }
6218
6219 if (err < 0) {
6220 stac92xx_free(codec);
6221 return err;
6222 }
6223
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006224 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02006225 if (spec->board_config == STAC_HP_DV4 ||
6226 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01006227 unsigned int cap;
6228 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
6229 cap &= AC_GPIO_IO_COUNT;
6230 if (cap >= 6)
6231 stac_add_hp_bass_switch(codec);
6232 }
6233
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006234 codec->proc_widget_hook = stac92hd7x_proc_hook;
6235
Matthew Ranostaye035b842007-11-06 11:53:55 +01006236 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006237}
Matthew Ranostaye035b842007-11-06 11:53:55 +01006238
Matt2f2f4252005-04-13 14:45:30 +02006239static int patch_stac922x(struct hda_codec *codec)
6240{
6241 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02006242 int err;
Matt2f2f4252005-04-13 14:45:30 +02006243
Takashi Iwai361dab32012-05-09 14:35:27 +02006244 err = alloc_stac_spec(codec, ARRAY_SIZE(stac922x_pin_nids),
6245 stac922x_pin_nids);
6246 if (err < 0)
6247 return err;
Matt2f2f4252005-04-13 14:45:30 +02006248
Takashi Iwai361dab32012-05-09 14:35:27 +02006249 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006250 spec->linear_tone_beep = 1;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006251 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
6252 stac922x_models,
6253 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08006254 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006255 spec->gpio_mask = spec->gpio_dir = 0x03;
6256 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006257 /* Intel Macs have all same PCI SSID, so we need to check
6258 * codec SSID to distinguish the exact models
6259 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006260 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006261 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006262
6263 case 0x106b0800:
6264 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02006265 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006266 case 0x106b0600:
6267 case 0x106b0700:
6268 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01006269 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006270 case 0x106b0e00:
6271 case 0x106b0f00:
6272 case 0x106b1600:
6273 case 0x106b1700:
6274 case 0x106b0200:
6275 case 0x106b1e00:
6276 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006277 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006278 case 0x106b1a00:
6279 case 0x00000100:
6280 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02006281 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02006282 case 0x106b0a00:
6283 case 0x106b2200:
6284 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02006285 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08006286 default:
6287 spec->board_config = STAC_INTEL_MAC_V3;
6288 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01006289 }
6290 }
6291
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006292 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006293 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006294 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6295 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006296 else
6297 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006298 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02006299
Matt2f2f4252005-04-13 14:45:30 +02006300 spec->adc_nids = stac922x_adc_nids;
6301 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006302 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006303 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006304 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006305 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02006306
6307 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006308
6309 spec->num_caps = STAC922X_NUM_CAPS;
6310 spec->capvols = stac922x_capvols;
6311 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02006312
6313 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02006314
Charles Chin9009b0e2011-11-03 10:27:27 +01006315 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006316 if (!err) {
6317 if (spec->board_config < 0) {
6318 printk(KERN_WARNING "hda_codec: No auto-config is "
6319 "available, default to model=ref\n");
6320 spec->board_config = STAC_D945_REF;
6321 goto again;
6322 }
6323 err = -EINVAL;
6324 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006325 if (err < 0) {
6326 stac92xx_free(codec);
6327 return err;
6328 }
6329
6330 codec->patch_ops = stac92xx_patch_ops;
6331
Takashi Iwai807a46362007-05-29 19:01:37 +02006332 /* Fix Mux capture level; max to 2 */
6333 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
6334 (0 << AC_AMPCAP_OFFSET_SHIFT) |
6335 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
6336 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6337 (0 << AC_AMPCAP_MUTE_SHIFT));
6338
Matt Porter3cc08dc2006-01-23 15:27:49 +01006339 return 0;
6340}
6341
6342static int patch_stac927x(struct hda_codec *codec)
6343{
6344 struct sigmatel_spec *spec;
6345 int err;
6346
Takashi Iwai361dab32012-05-09 14:35:27 +02006347 err = alloc_stac_spec(codec, ARRAY_SIZE(stac927x_pin_nids),
6348 stac927x_pin_nids);
6349 if (err < 0)
6350 return err;
Matt Porter3cc08dc2006-01-23 15:27:49 +01006351
Takashi Iwai361dab32012-05-09 14:35:27 +02006352 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006353 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05006354 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006355 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
6356 stac927x_models,
6357 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006358 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006359 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006360 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6361 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006362 else
6363 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006364 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01006365
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006366 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006367 spec->adc_nids = stac927x_adc_nids;
6368 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6369 spec->mux_nids = stac927x_mux_nids;
6370 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006371 spec->smux_nids = stac927x_smux_nids;
6372 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04006373 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01006374 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006375 spec->multiout.dac_nids = spec->dac_nids;
6376
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006377 if (spec->board_config != STAC_D965_REF) {
6378 /* GPIO0 High = Enable EAPD */
6379 spec->eapd_mask = spec->gpio_mask = 0x01;
6380 spec->gpio_dir = spec->gpio_data = 0x01;
6381 }
6382
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006383 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02006384 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006385 case STAC_D965_5ST:
6386 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006387 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02006388 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006389 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006390 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006391 switch (codec->subsystem_id) {
6392 case 0x10280209:
6393 case 0x1028022e:
6394 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006395 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006396 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006397 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01006398 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01006399 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01006400 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006401 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006402 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01006403 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006404 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006405 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006406 if (codec->subsystem_id != 0x1028022f) {
6407 /* GPIO2 High = Enable EAPD */
6408 spec->eapd_mask = spec->gpio_mask = 0x04;
6409 spec->gpio_dir = spec->gpio_data = 0x04;
6410 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006411 spec->dmic_nids = stac927x_dmic_nids;
6412 spec->num_dmics = STAC927X_NUM_DMICS;
6413
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02006414 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006415 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006416 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006417 break;
Takashi Iwai54930532009-10-11 17:38:29 +02006418 case STAC_927X_VOLKNOB:
6419 spec->num_dmics = 0;
6420 spec->init = stac927x_volknob_core_init;
6421 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006422 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006423 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006424 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006425 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006426 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006427
Takashi Iwai6479c632009-07-28 18:20:25 +02006428 spec->num_caps = STAC927X_NUM_CAPS;
6429 spec->capvols = stac927x_capvols;
6430 spec->capsws = stac927x_capsws;
6431
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006432 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006433 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006434 spec->aloopback_mask = 0x40;
6435 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05006436 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006437
Charles Chin9009b0e2011-11-03 10:27:27 +01006438 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006439 if (!err) {
6440 if (spec->board_config < 0) {
6441 printk(KERN_WARNING "hda_codec: No auto-config is "
6442 "available, default to model=ref\n");
6443 spec->board_config = STAC_D965_REF;
6444 goto again;
6445 }
6446 err = -EINVAL;
6447 }
Mattc7d4b2f2005-06-27 14:59:41 +02006448 if (err < 0) {
6449 stac92xx_free(codec);
6450 return err;
6451 }
Matt2f2f4252005-04-13 14:45:30 +02006452
6453 codec->patch_ops = stac92xx_patch_ops;
6454
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006455 codec->proc_widget_hook = stac927x_proc_hook;
6456
Takashi Iwai52987652008-01-16 16:09:47 +01006457 /*
6458 * !!FIXME!!
6459 * The STAC927x seem to require fairly long delays for certain
6460 * command sequences. With too short delays (even if the answer
6461 * is set to RIRB properly), it results in the silence output
6462 * on some hardwares like Dell.
6463 *
6464 * The below flag enables the longer delay (see get_response
6465 * in hda_intel.c).
6466 */
6467 codec->bus->needs_damn_long_delay = 1;
6468
Takashi Iwaie28d8322008-12-17 13:48:29 +01006469 /* no jack detecion for ref-no-jd model */
6470 if (spec->board_config == STAC_D965_REF_NO_JD)
6471 spec->hp_detect = 0;
6472
Matt2f2f4252005-04-13 14:45:30 +02006473 return 0;
6474}
6475
Matt Porterf3302a52006-07-31 12:49:34 +02006476static int patch_stac9205(struct hda_codec *codec)
6477{
6478 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006479 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006480
Takashi Iwai361dab32012-05-09 14:35:27 +02006481 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9205_pin_nids),
6482 stac9205_pin_nids);
6483 if (err < 0)
6484 return err;
Matt Porterf3302a52006-07-31 12:49:34 +02006485
Takashi Iwai361dab32012-05-09 14:35:27 +02006486 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006487 spec->linear_tone_beep = 1;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006488 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6489 stac9205_models,
6490 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006491 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006492 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006493 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6494 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006495 else
6496 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006497 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006498
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006499 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006500 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006501 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006502 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006503 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006504 spec->smux_nids = stac9205_smux_nids;
6505 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006506 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006507 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006508 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006509 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006510 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006511
6512 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006513 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006514
Takashi Iwai6479c632009-07-28 18:20:25 +02006515 spec->num_caps = STAC9205_NUM_CAPS;
6516 spec->capvols = stac9205_capvols;
6517 spec->capsws = stac9205_capsws;
6518
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006519 spec->aloopback_mask = 0x40;
6520 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006521 /* Turn on/off EAPD per HP plugging */
6522 if (spec->board_config != STAC_9205_EAPD)
6523 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006524 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006525
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006526 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006527 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006528 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006529 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6530 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006531
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006532 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwai3a938972011-10-28 01:16:55 +02006533 err = stac_add_event(codec, codec->afg, STAC_VREF_EVENT, 0x01);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006534 if (err < 0)
6535 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006536 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006537 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
Takashi Iwai3a938972011-10-28 01:16:55 +02006538 snd_hda_jack_detect_enable(codec, codec->afg, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006539
6540 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006541 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006542 spec->gpio_mask = 0x1b;
6543 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006544 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006545 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006546 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006547 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006548 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006549 case STAC_9205_REF:
6550 /* SPDIF-In enabled */
6551 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006552 default:
6553 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006554 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006555 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006556 break;
6557 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006558
Charles Chin9009b0e2011-11-03 10:27:27 +01006559 err = stac92xx_parse_auto_config(codec);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006560 if (!err) {
6561 if (spec->board_config < 0) {
6562 printk(KERN_WARNING "hda_codec: No auto-config is "
6563 "available, default to model=ref\n");
6564 spec->board_config = STAC_9205_REF;
6565 goto again;
6566 }
6567 err = -EINVAL;
6568 }
Matt Porterf3302a52006-07-31 12:49:34 +02006569 if (err < 0) {
6570 stac92xx_free(codec);
6571 return err;
6572 }
6573
6574 codec->patch_ops = stac92xx_patch_ops;
6575
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006576 codec->proc_widget_hook = stac9205_proc_hook;
6577
Matt Porterf3302a52006-07-31 12:49:34 +02006578 return 0;
6579}
6580
Matt2f2f4252005-04-13 14:45:30 +02006581/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006582 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006583 */
6584
Takashi Iwai2b635362011-05-02 12:33:43 +02006585static const struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006586 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006587 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6588 {}
6589};
6590
Takashi Iwai2b635362011-05-02 12:33:43 +02006591static const hda_nid_t stac9872_pin_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006592 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6593 0x11, 0x13, 0x14,
6594};
6595
Takashi Iwai2b635362011-05-02 12:33:43 +02006596static const hda_nid_t stac9872_adc_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006597 0x8 /*,0x6*/
6598};
6599
Takashi Iwai2b635362011-05-02 12:33:43 +02006600static const hda_nid_t stac9872_mux_nids[] = {
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006601 0x15
6602};
6603
Takashi Iwai2b635362011-05-02 12:33:43 +02006604static const unsigned long stac9872_capvols[] = {
Takashi Iwai6479c632009-07-28 18:20:25 +02006605 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6606};
6607#define stac9872_capsws stac9872_capvols
6608
Takashi Iwai2b635362011-05-02 12:33:43 +02006609static const unsigned int stac9872_vaio_pin_configs[9] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006610 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6611 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6612 0x90a7013e
6613};
6614
Takashi Iwaiea734962011-01-17 11:29:34 +01006615static const char * const stac9872_models[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006616 [STAC_9872_AUTO] = "auto",
6617 [STAC_9872_VAIO] = "vaio",
6618};
6619
Takashi Iwai2b635362011-05-02 12:33:43 +02006620static const unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006621 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6622};
6623
Takashi Iwai2b635362011-05-02 12:33:43 +02006624static const struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006625 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6626 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006627 {} /* terminator */
6628};
6629
Guillaume Munch6d859062006-08-22 17:15:47 +02006630static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006631{
6632 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006633 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006634
Takashi Iwai361dab32012-05-09 14:35:27 +02006635 err = alloc_stac_spec(codec, ARRAY_SIZE(stac9872_pin_nids),
6636 stac9872_pin_nids);
6637 if (err < 0)
6638 return err;
6639
6640 spec = codec->spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006641 spec->linear_tone_beep = 1;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006642
6643 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6644 stac9872_models,
6645 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006646 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006647 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6648 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006649 else
6650 stac92xx_set_config_regs(codec,
6651 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006652
Takashi Iwai1e137f92009-01-21 07:41:22 +01006653 spec->multiout.dac_nids = spec->dac_nids;
6654 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6655 spec->adc_nids = stac9872_adc_nids;
6656 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6657 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006658 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006659 spec->num_caps = 1;
6660 spec->capvols = stac9872_capvols;
6661 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006662
Charles Chin9009b0e2011-11-03 10:27:27 +01006663 err = stac92xx_parse_auto_config(codec);
Takashi Iwai1e137f92009-01-21 07:41:22 +01006664 if (err < 0) {
6665 stac92xx_free(codec);
6666 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006667 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006668 spec->input_mux = &spec->private_imux;
6669 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006670 return 0;
6671}
6672
6673
6674/*
Matt2f2f4252005-04-13 14:45:30 +02006675 * patch entries
6676 */
Takashi Iwai2b635362011-05-02 12:33:43 +02006677static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006678 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6679 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6680 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6681 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6682 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6683 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6684 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006685 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6686 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6687 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6688 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6689 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6690 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006691 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6692 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6693 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6694 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6695 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6696 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6697 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6698 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6699 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6700 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006701 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6702 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6703 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6704 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6705 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6706 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006707 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6708 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006709 /* The following does not take into account .id=0x83847661 when subsys =
6710 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6711 * currently not fully supported.
6712 */
6713 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6714 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6715 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006716 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006717 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6718 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6719 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6720 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6721 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6722 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6723 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6724 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006725 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006726 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006727 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006728 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006729 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006730 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6731 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006732 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6733 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6734 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6735 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006736 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006737 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6738 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006739 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006740 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6741 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6742 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6743 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6744 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6745 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6746 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6747 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006748 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6749 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6750 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6751 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6752 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6753 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6754 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6755 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6756 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6757 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6758 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6759 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6760 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6761 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6762 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
David Henningsson46724c22011-09-20 09:02:22 +02006763 { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006764 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06006765 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6766 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006767 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Charles Chinad5d8752011-11-02 07:56:58 +01006768 { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6769 { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6770 { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6771 { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6772 { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6773 { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6774 { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6775 { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6776 { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6777 { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6778 { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6779 { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006780 {} /* terminator */
6781};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006782
6783MODULE_ALIAS("snd-hda-codec-id:8384*");
6784MODULE_ALIAS("snd-hda-codec-id:111d*");
6785
6786MODULE_LICENSE("GPL");
6787MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6788
6789static struct hda_codec_preset_list sigmatel_list = {
6790 .preset = snd_hda_preset_sigmatel,
6791 .owner = THIS_MODULE,
6792};
6793
6794static int __init patch_sigmatel_init(void)
6795{
6796 return snd_hda_add_codec_preset(&sigmatel_list);
6797}
6798
6799static void __exit patch_sigmatel_exit(void)
6800{
6801 snd_hda_delete_codec_preset(&sigmatel_list);
6802}
6803
6804module_init(patch_sigmatel_init)
6805module_exit(patch_sigmatel_exit)