blob: bd7b123f64407e5398f0ddfe8a48ec10acfb1308 [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>
Matt2f2f4252005-04-13 14:45:30 +020032#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020033#include <sound/asoundef.h>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040034#include <sound/jack.h>
Clemens Ladischa74ccea2010-10-22 15:52:34 +020035#include <sound/tlv.h>
Matt2f2f4252005-04-13 14:45:30 +020036#include "hda_codec.h"
37#include "hda_local.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020038#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020039
Takashi Iwaic6e4c662008-11-25 11:58:19 +010040enum {
41 STAC_VREF_EVENT = 1,
42 STAC_INSERT_EVENT,
43 STAC_PWR_EVENT,
44 STAC_HP_EVENT,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020045 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020046 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010047};
Matt4e550962005-07-04 17:51:39 +020048
Takashi Iwaif5fcc132006-11-24 17:07:44 +010049enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010050 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010051 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010052 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020053 STAC_9200_DELL_D21,
54 STAC_9200_DELL_D22,
55 STAC_9200_DELL_D23,
56 STAC_9200_DELL_M21,
57 STAC_9200_DELL_M22,
58 STAC_9200_DELL_M23,
59 STAC_9200_DELL_M24,
60 STAC_9200_DELL_M25,
61 STAC_9200_DELL_M26,
62 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020063 STAC_9200_M4,
64 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010065 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010066 STAC_9200_MODELS
67};
68
69enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010070 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010071 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020072 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020073 STAC_9205_DELL_M43,
74 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010075 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010076 STAC_9205_MODELS
77};
78
79enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010080 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010081 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010082 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080083 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010084 STAC_DELL_M6_AMIC,
85 STAC_DELL_M6_DMIC,
86 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050087 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020088 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010089 STAC_92HD73XX_MODELS
90};
91
92enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010093 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020094 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050095 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050096 STAC_DELL_S14,
Takashi Iwaib4e81872009-11-18 17:20:24 +010097 STAC_92HD83XXX_HP,
Steven Eastland48315592010-08-06 15:07:35 -060098 STAC_HP_DV7_4000,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020099 STAC_92HD83XXX_MODELS
100};
101
102enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100103 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100104 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100105 STAC_DELL_M4_1,
106 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500107 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400108 STAC_HP_M4,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +0200109 STAC_HP_DV4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100110 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100111 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400112 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100113 STAC_92HD71BXX_MODELS
114};
115
116enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100117 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100118 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200119 STAC_M1,
120 STAC_M1_2,
121 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100122 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200123 STAC_M3,
124 STAC_M5,
125 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100126 STAC_925x_MODELS
127};
128
129enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100130 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100131 STAC_D945_REF,
132 STAC_D945GTP3,
133 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200134 STAC_INTEL_MAC_V1,
135 STAC_INTEL_MAC_V2,
136 STAC_INTEL_MAC_V3,
137 STAC_INTEL_MAC_V4,
138 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800139 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
140 * is given, one of the above models will be
141 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200142 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100143 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100144 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100145 STAC_MACBOOK_PRO_V1,
146 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200147 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200148 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300149 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200150 STAC_922X_DELL_D81,
151 STAC_922X_DELL_D82,
152 STAC_922X_DELL_M81,
153 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100154 STAC_922X_MODELS
155};
156
157enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100158 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100159 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100160 STAC_D965_REF,
161 STAC_D965_3ST,
162 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200163 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200164 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100165 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200166 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100167 STAC_927X_MODELS
168};
Matt Porter403d1942005-11-29 15:00:51 +0100169
Takashi Iwai307282c2009-03-12 18:17:58 +0100170enum {
171 STAC_9872_AUTO,
172 STAC_9872_VAIO,
173 STAC_9872_MODELS
174};
175
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400176struct sigmatel_event {
177 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100178 unsigned char type;
179 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400180 int data;
181};
182
183struct sigmatel_jack {
184 hda_nid_t nid;
185 int type;
186 struct snd_jack *jack;
187};
188
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200189struct sigmatel_mic_route {
190 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200191 signed char mux_idx;
192 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200193};
194
Matt2f2f4252005-04-13 14:45:30 +0200195struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100196 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200197 unsigned int num_mixers;
198
Matt Porter403d1942005-11-29 15:00:51 +0100199 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500200 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200201 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100202 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100203 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400204 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100205 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200206 unsigned int auto_mic:1;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +0100207 unsigned int linear_tone_beep:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200208
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100209 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200210 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-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;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100217
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200218 /* stream */
219 unsigned int stream_delay;
220
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100221 /* analog loopback */
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100222 struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100223 unsigned char aloopback_mask;
224 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200225
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100226 /* power management */
227 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200228 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100229 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100230 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100231
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400232 /* jack detection */
233 struct snd_array jacks;
234
235 /* events */
236 struct snd_array events;
237
Matt2f2f4252005-04-13 14:45:30 +0200238 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100239 struct hda_input_mux *mono_mux;
240 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200241 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100242 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100243 hda_nid_t hp_dacs[5];
244 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200245
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100246 int volume_offset;
247
Matt2f2f4252005-04-13 14:45:30 +0200248 /* capture */
249 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200250 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200251 hda_nid_t *mux_nids;
252 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200253 hda_nid_t *dmic_nids;
254 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100255 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100256 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200257 hda_nid_t *smux_nids;
258 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200259 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200260
261 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
262 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
263 unsigned int num_caps; /* number of capture volume/switch elements */
264
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200265 struct sigmatel_mic_route ext_mic;
266 struct sigmatel_mic_route int_mic;
Charles Chin99077902010-09-17 10:22:32 +0200267 struct sigmatel_mic_route dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200268
Takashi Iwaiea734962011-01-17 11:29:34 +0100269 const char * const *spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200270
Mattdabbed62005-06-14 10:19:34 +0200271 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100272 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200273 hda_nid_t anabeep_nid;
274 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200275
Matt2f2f4252005-04-13 14:45:30 +0200276 /* pin widgets */
277 hda_nid_t *pin_nids;
278 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200279
280 /* codec specific stuff */
281 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100282 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200283
284 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200285 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100286 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200287 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100288 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200289 struct hda_input_mux *sinput_mux;
290 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400291 unsigned int cur_amux;
292 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200293 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200294
Matt Porter403d1942005-11-29 15:00:51 +0100295 /* i/o switches */
296 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200297 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100298 hda_nid_t line_switch; /* shared line-in for input and output */
299 hda_nid_t mic_switch; /* shared mic-in for input and output */
300 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200301 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200302
Mattc7d4b2f2005-06-27 14:59:41 +0200303 struct hda_pcm pcm_rec[2]; /* PCM information */
304
305 /* dynamic controls and input_mux */
306 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200307 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200308 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200309 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200310 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100311 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200312};
313
314static hda_nid_t stac9200_adc_nids[1] = {
315 0x03,
316};
317
318static hda_nid_t stac9200_mux_nids[1] = {
319 0x0c,
320};
321
322static hda_nid_t stac9200_dac_nids[1] = {
323 0x02,
324};
325
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100326static hda_nid_t stac92hd73xx_pwr_nids[8] = {
327 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
328 0x0f, 0x10, 0x11
329};
330
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400331static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
332 0x26, 0,
333};
334
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100335static hda_nid_t stac92hd73xx_adc_nids[2] = {
336 0x1a, 0x1b
337};
338
339#define STAC92HD73XX_NUM_DMICS 2
340static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
341 0x13, 0x14, 0
342};
343
344#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100345
Takashi Iwaie2aec172009-09-02 01:00:05 +0200346static hda_nid_t stac92hd73xx_mux_nids[2] = {
347 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100348};
349
350static hda_nid_t stac92hd73xx_dmux_nids[2] = {
351 0x20, 0x21,
352};
353
Matthew Ranostayd9737752008-09-07 12:03:41 +0200354static hda_nid_t stac92hd73xx_smux_nids[2] = {
355 0x22, 0x23,
356};
357
Takashi Iwai6479c632009-07-28 18:20:25 +0200358#define STAC92HD73XX_NUM_CAPS 2
359static unsigned long stac92hd73xx_capvols[] = {
360 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
361 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
362};
363#define stac92hd73xx_capsws stac92hd73xx_capvols
364
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200365#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200366
Takashi Iwai667067d2009-08-13 18:14:42 +0200367static hda_nid_t stac92hd83xxx_mux_nids[2] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200368 0x17, 0x18,
369};
370
371static hda_nid_t stac92hd83xxx_adc_nids[2] = {
372 0x15, 0x16,
373};
374
375static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
376 0xa, 0xb, 0xd, 0xe,
377};
378
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400379static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
380 0x1e, 0,
381};
382
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200383static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500384 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200385};
386
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +0200387#define STAC92HD83XXX_NUM_DMICS 2
388static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
389 0x11, 0x20, 0
390};
391
David Henningssonbdfe6f42011-01-04 06:30:53 +0100392#define STAC92HD88XXX_NUM_DMICS STAC92HD83XXX_NUM_DMICS
393#define stac92hd88xxx_dmic_nids stac92hd83xxx_dmic_nids
394
David Henningsson89feca12010-10-13 15:48:24 +0200395#define STAC92HD87B_NUM_DMICS 1
396static hda_nid_t stac92hd87b_dmic_nids[STAC92HD87B_NUM_DMICS + 1] = {
397 0x11, 0
398};
399
Takashi Iwai6479c632009-07-28 18:20:25 +0200400#define STAC92HD83XXX_NUM_CAPS 2
401static unsigned long stac92hd83xxx_capvols[] = {
402 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
403 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
404};
405#define stac92hd83xxx_capsws stac92hd83xxx_capvols
406
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100407static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
408 0x0a, 0x0d, 0x0f
409};
410
Matthew Ranostaye035b842007-11-06 11:53:55 +0100411static hda_nid_t stac92hd71bxx_adc_nids[2] = {
412 0x12, 0x13,
413};
414
415static hda_nid_t stac92hd71bxx_mux_nids[2] = {
416 0x1a, 0x1b
417};
418
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400419static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
420 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100421};
422
Matthew Ranostayd9737752008-09-07 12:03:41 +0200423static hda_nid_t stac92hd71bxx_smux_nids[2] = {
424 0x24, 0x25,
425};
426
Matthew Ranostaye035b842007-11-06 11:53:55 +0100427#define STAC92HD71BXX_NUM_DMICS 2
428static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
429 0x18, 0x19, 0
430};
431
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400432static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
433 0x22, 0
434};
435
Takashi Iwai6479c632009-07-28 18:20:25 +0200436#define STAC92HD71BXX_NUM_CAPS 2
437static unsigned long stac92hd71bxx_capvols[] = {
438 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
439 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
440};
441#define stac92hd71bxx_capsws stac92hd71bxx_capvols
442
Tobin Davis8e21c342007-01-08 11:04:17 +0100443static hda_nid_t stac925x_adc_nids[1] = {
444 0x03,
445};
446
447static hda_nid_t stac925x_mux_nids[1] = {
448 0x0f,
449};
450
451static hda_nid_t stac925x_dac_nids[1] = {
452 0x02,
453};
454
Takashi Iwaif6e98522007-10-16 14:27:04 +0200455#define STAC925X_NUM_DMICS 1
456static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
457 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200458};
459
Takashi Iwai1697055e2007-12-18 18:05:52 +0100460static hda_nid_t stac925x_dmux_nids[1] = {
461 0x14,
462};
463
Takashi Iwai6479c632009-07-28 18:20:25 +0200464static unsigned long stac925x_capvols[] = {
465 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
466};
467static unsigned long stac925x_capsws[] = {
468 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
469};
470
Matt2f2f4252005-04-13 14:45:30 +0200471static hda_nid_t stac922x_adc_nids[2] = {
472 0x06, 0x07,
473};
474
475static hda_nid_t stac922x_mux_nids[2] = {
476 0x12, 0x13,
477};
478
Takashi Iwai6479c632009-07-28 18:20:25 +0200479#define STAC922X_NUM_CAPS 2
480static unsigned long stac922x_capvols[] = {
481 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
482 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
483};
484#define stac922x_capsws stac922x_capvols
485
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500486static hda_nid_t stac927x_slave_dig_outs[2] = {
487 0x1f, 0,
488};
489
Matt Porter3cc08dc2006-01-23 15:27:49 +0100490static hda_nid_t stac927x_adc_nids[3] = {
491 0x07, 0x08, 0x09
492};
493
494static hda_nid_t stac927x_mux_nids[3] = {
495 0x15, 0x16, 0x17
496};
497
Matthew Ranostayd9737752008-09-07 12:03:41 +0200498static hda_nid_t stac927x_smux_nids[1] = {
499 0x21,
500};
501
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100502static hda_nid_t stac927x_dac_nids[6] = {
503 0x02, 0x03, 0x04, 0x05, 0x06, 0
504};
505
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100506static hda_nid_t stac927x_dmux_nids[1] = {
507 0x1b,
508};
509
Matthew Ranostay7f168592007-10-18 17:38:17 +0200510#define STAC927X_NUM_DMICS 2
511static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
512 0x13, 0x14, 0
513};
514
Takashi Iwai6479c632009-07-28 18:20:25 +0200515#define STAC927X_NUM_CAPS 3
516static unsigned long stac927x_capvols[] = {
517 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
518 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
519 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
520};
521static unsigned long stac927x_capsws[] = {
522 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
523 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
524 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
525};
526
Takashi Iwaiea734962011-01-17 11:29:34 +0100527static const char * const stac927x_spdif_labels[5] = {
Matthew Ranostay65973632008-09-16 10:39:37 -0400528 "Digital Playback", "ADAT", "Analog Mux 1",
529 "Analog Mux 2", "Analog Mux 3"
530};
531
Matt Porterf3302a52006-07-31 12:49:34 +0200532static hda_nid_t stac9205_adc_nids[2] = {
533 0x12, 0x13
534};
535
536static hda_nid_t stac9205_mux_nids[2] = {
537 0x19, 0x1a
538};
539
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100540static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100541 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100542};
543
Matthew Ranostayd9737752008-09-07 12:03:41 +0200544static hda_nid_t stac9205_smux_nids[1] = {
545 0x21,
546};
547
Takashi Iwaif6e98522007-10-16 14:27:04 +0200548#define STAC9205_NUM_DMICS 2
549static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
550 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200551};
552
Takashi Iwai6479c632009-07-28 18:20:25 +0200553#define STAC9205_NUM_CAPS 2
554static unsigned long stac9205_capvols[] = {
555 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
556 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
557};
558static unsigned long stac9205_capsws[] = {
559 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
560 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
561};
562
Mattc7d4b2f2005-06-27 14:59:41 +0200563static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200564 0x08, 0x09, 0x0d, 0x0e,
565 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200566};
567
Tobin Davis8e21c342007-01-08 11:04:17 +0100568static hda_nid_t stac925x_pin_nids[8] = {
569 0x07, 0x08, 0x0a, 0x0b,
570 0x0c, 0x0d, 0x10, 0x11,
571};
572
Matt2f2f4252005-04-13 14:45:30 +0200573static hda_nid_t stac922x_pin_nids[10] = {
574 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
575 0x0f, 0x10, 0x11, 0x15, 0x1b,
576};
577
Matthew Ranostaya7662642008-02-21 07:51:14 +0100578static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100579 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
580 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200581 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100582};
583
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500584static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200585 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500586 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200587};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500588
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -0600589static hda_nid_t stac92hd87xxx_pin_nids[6] = {
590 0x0a, 0x0b, 0x0c, 0x0d,
591 0x0f, 0x11,
592};
593
594static hda_nid_t stac92hd88xxx_pin_nids[8] = {
Charles Chin36706002010-01-29 12:05:51 +0100595 0x0a, 0x0b, 0x0c, 0x0d,
596 0x0f, 0x11, 0x1f, 0x20,
597};
598
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500599#define STAC92HD71BXX_NUM_PINS 13
600static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
601 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
602 0x00, 0x14, 0x18, 0x19, 0x1e,
603 0x1f, 0x20, 0x27
604};
605static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100606 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
607 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500608 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100609};
610
Matt Porter3cc08dc2006-01-23 15:27:49 +0100611static hda_nid_t stac927x_pin_nids[14] = {
612 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
613 0x0f, 0x10, 0x11, 0x12, 0x13,
614 0x14, 0x21, 0x22, 0x23,
615};
616
Matt Porterf3302a52006-07-31 12:49:34 +0200617static hda_nid_t stac9205_pin_nids[12] = {
618 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
619 0x0f, 0x14, 0x16, 0x17, 0x18,
620 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200621};
622
Matt Porter8b657272006-10-26 17:12:59 +0200623static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
624 struct snd_ctl_elem_info *uinfo)
625{
626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
627 struct sigmatel_spec *spec = codec->spec;
628 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
629}
630
631static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
632 struct snd_ctl_elem_value *ucontrol)
633{
634 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
635 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100636 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200637
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100638 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200639 return 0;
640}
641
642static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
643 struct snd_ctl_elem_value *ucontrol)
644{
645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
646 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100647 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200648
649 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100650 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200651}
652
Matthew Ranostayd9737752008-09-07 12:03:41 +0200653static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
654 struct snd_ctl_elem_info *uinfo)
655{
656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
657 struct sigmatel_spec *spec = codec->spec;
658 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
659}
660
661static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
662 struct snd_ctl_elem_value *ucontrol)
663{
664 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
665 struct sigmatel_spec *spec = codec->spec;
666 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
667
668 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
669 return 0;
670}
671
672static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
673 struct snd_ctl_elem_value *ucontrol)
674{
675 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
676 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400677 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200678 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400679 int err, val;
680 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200681
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400682 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200683 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400684 if (err < 0)
685 return err;
686
687 if (spec->spdif_mute) {
688 if (smux_idx == 0)
689 nid = spec->multiout.dig_out_nid;
690 else
691 nid = codec->slave_dig_outs[smux_idx - 1];
692 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100693 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400694 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100695 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400696 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100697 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
698 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400699 }
700 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200701}
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
720 error = snd_hda_codec_write_cache(codec, nid, 0,
721 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
722 if (error < 0)
723 return error;
724 else
725 return 1;
726}
727
728static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
729{
730 unsigned int vref;
731 vref = snd_hda_codec_read(codec, nid, 0,
732 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
733 vref &= AC_PINCTL_VREFEN;
734 return vref;
735}
736
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100737static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200738{
739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
740 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200741 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200742}
743
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100744static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200745{
746 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
747 struct sigmatel_spec *spec = codec->spec;
748 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
749
750 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
751 return 0;
752}
753
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100754static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200755{
756 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
757 struct sigmatel_spec *spec = codec->spec;
758 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200759 const struct hda_input_mux *imux = spec->input_mux;
760 unsigned int idx, prev_idx;
Matt2f2f4252005-04-13 14:45:30 +0200761
Takashi Iwai5207e102009-07-30 13:09:08 +0200762 idx = ucontrol->value.enumerated.item[0];
763 if (idx >= imux->num_items)
764 idx = imux->num_items - 1;
765 prev_idx = spec->cur_mux[adc_idx];
766 if (prev_idx == idx)
767 return 0;
768 if (idx < spec->num_analog_muxes) {
769 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
770 AC_VERB_SET_CONNECT_SEL,
771 imux->items[idx].index);
772 if (prev_idx >= spec->num_analog_muxes) {
773 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;
782 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
783 AC_VERB_SET_CONNECT_SEL,
784 imux->items[idx - 1].index);
785 }
786 spec->cur_mux[adc_idx] = idx;
787 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200788}
789
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100790static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
791 struct snd_ctl_elem_info *uinfo)
792{
793 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
794 struct sigmatel_spec *spec = codec->spec;
795 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
796}
797
798static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
799 struct snd_ctl_elem_value *ucontrol)
800{
801 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
802 struct sigmatel_spec *spec = codec->spec;
803
804 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
805 return 0;
806}
807
808static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
809 struct snd_ctl_elem_value *ucontrol)
810{
811 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
812 struct sigmatel_spec *spec = codec->spec;
813
814 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
815 spec->mono_nid, &spec->cur_mmux);
816}
817
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200818#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
819
820static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
821 struct snd_ctl_elem_value *ucontrol)
822{
823 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100824 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200825 struct sigmatel_spec *spec = codec->spec;
826
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100827 ucontrol->value.integer.value[0] = !!(spec->aloopback &
828 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200829 return 0;
830}
831
832static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
833 struct snd_ctl_elem_value *ucontrol)
834{
835 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
836 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100837 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200838 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100839 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200840
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100841 idx_val = spec->aloopback_mask << idx;
842 if (ucontrol->value.integer.value[0])
843 val = spec->aloopback | idx_val;
844 else
845 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100846 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200847 return 0;
848
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100849 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200850
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100851 /* Only return the bits defined by the shift value of the
852 * first two bytes of the mask
853 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200854 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100855 kcontrol->private_value & 0xFFFF, 0x0);
856 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200857
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100858 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200859 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100860 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200861 } else {
862 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100863 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200864 }
865
866 snd_hda_codec_write_cache(codec, codec->afg, 0,
867 kcontrol->private_value >> 16, dac_mode);
868
869 return 1;
870}
871
Mattc7d4b2f2005-06-27 14:59:41 +0200872static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200873 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200874 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200875 {}
876};
877
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200878static struct hda_verb stac9200_eapd_init[] = {
879 /* set dac0mux for dac converter */
880 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
881 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
882 {}
883};
884
Matthew Ranostayd654a662008-03-14 08:46:51 +0100885static struct hda_verb dell_eq_core_init[] = {
886 /* set master volume to max value without distortion
887 * and direct control */
888 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100889 {}
890};
891
Takashi Iwaie2aec172009-09-02 01:00:05 +0200892static struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100893 /* set master volume and direct control */
894 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100895 {}
896};
897
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200898static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200899 /* power state controls amps */
900 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200901 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200902};
903
Matthew Ranostaye035b842007-11-06 11:53:55 +0100904static struct hda_verb stac92hd71bxx_core_init[] = {
905 /* set master volume and direct control */
906 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200907 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100908};
909
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500910static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
911 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
912 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100913 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
914 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100915 {}
916};
917
Tobin Davis8e21c342007-01-08 11:04:17 +0100918static struct hda_verb stac925x_core_init[] = {
919 /* set dac0mux for dac converter */
920 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100921 /* mute the master volume */
922 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100923 {}
924};
925
Mattc7d4b2f2005-06-27 14:59:41 +0200926static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200927 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200928 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200929 {}
930};
931
Tobin Davis93ed1502006-09-01 21:03:12 +0200932static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200933 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200934 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200935 /* unmute node 0x1b */
936 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
937 /* select node 0x03 as DAC */
938 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
939 {}
940};
941
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200942static struct hda_verb dell_3st_core_init[] = {
943 /* don't set delta bit */
944 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
945 /* unmute node 0x1b */
946 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
947 /* select node 0x03 as DAC */
948 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
949 {}
950};
951
Matt Porter3cc08dc2006-01-23 15:27:49 +0100952static struct hda_verb stac927x_core_init[] = {
953 /* set master volume and direct control */
954 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200955 /* enable analog pc beep path */
956 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100957 {}
958};
959
Takashi Iwai54930532009-10-11 17:38:29 +0200960static struct hda_verb stac927x_volknob_core_init[] = {
961 /* don't set delta bit */
962 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
963 /* enable analog pc beep path */
964 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
965 {}
966};
967
Matt Porterf3302a52006-07-31 12:49:34 +0200968static struct hda_verb stac9205_core_init[] = {
969 /* set master volume and direct control */
970 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200971 /* enable analog pc beep path */
972 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200973 {}
974};
975
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100976#define STAC_MONO_MUX \
977 { \
978 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
979 .name = "Mono Mux", \
980 .count = 1, \
981 .info = stac92xx_mono_mux_enum_info, \
982 .get = stac92xx_mono_mux_enum_get, \
983 .put = stac92xx_mono_mux_enum_put, \
984 }
985
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100986#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200987 { \
988 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
989 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100990 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200991 .info = stac92xx_aloopback_info, \
992 .get = stac92xx_aloopback_get, \
993 .put = stac92xx_aloopback_put, \
994 .private_value = verb_read | (verb_write << 16), \
995 }
996
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200997#define DC_BIAS(xname, idx, nid) \
998 { \
999 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1000 .name = xname, \
1001 .index = idx, \
1002 .info = stac92xx_dc_bias_info, \
1003 .get = stac92xx_dc_bias_get, \
1004 .put = stac92xx_dc_bias_put, \
1005 .private_value = nid, \
1006 }
1007
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001008static struct snd_kcontrol_new stac9200_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001009 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001010 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001011 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1012 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001013 { } /* end */
1014};
1015
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001016static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1017 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1018 {}
1019};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001020
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001021static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1022 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1023 {}
1024};
1025
1026static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1027 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1028 {}
1029};
1030
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001031
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001032static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1033 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1034};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001035
Tobin Davis8e21c342007-01-08 11:04:17 +01001036static struct snd_kcontrol_new stac925x_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001037 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
Takashi Iwaic9280d62009-01-15 17:31:00 +01001038 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001039 { } /* end */
1040};
1041
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001042static struct snd_kcontrol_new stac9205_loopback[] = {
1043 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1044 {}
1045};
1046
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001047static struct snd_kcontrol_new stac927x_loopback[] = {
1048 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1049 {}
1050};
1051
Takashi Iwai1697055e2007-12-18 18:05:52 +01001052static struct snd_kcontrol_new stac_dmux_mixer = {
1053 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1054 .name = "Digital Input Source",
1055 /* count set later */
1056 .info = stac92xx_dmux_enum_info,
1057 .get = stac92xx_dmux_enum_get,
1058 .put = stac92xx_dmux_enum_put,
1059};
1060
Matthew Ranostayd9737752008-09-07 12:03:41 +02001061static struct snd_kcontrol_new stac_smux_mixer = {
1062 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001063 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001064 /* count set later */
1065 .info = stac92xx_smux_enum_info,
1066 .get = stac92xx_smux_enum_get,
1067 .put = stac92xx_smux_enum_put,
1068};
1069
Takashi Iwaiea734962011-01-17 11:29:34 +01001070static const char * const slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001071 "Front Playback Volume",
1072 "Surround Playback Volume",
1073 "Center Playback Volume",
1074 "LFE Playback Volume",
1075 "Side Playback Volume",
1076 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001077 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001078 NULL
1079};
1080
Takashi Iwaiea734962011-01-17 11:29:34 +01001081static const char * const slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001082 "Front Playback Switch",
1083 "Surround Playback Switch",
1084 "Center Playback Switch",
1085 "LFE Playback Switch",
1086 "Side Playback Switch",
1087 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001088 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001089 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001090 NULL
1091};
1092
Takashi Iwai603c4012008-07-30 15:01:44 +02001093static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001094static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001095
Matt2f2f4252005-04-13 14:45:30 +02001096static int stac92xx_build_controls(struct hda_codec *codec)
1097{
1098 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001099 struct auto_pin_cfg *cfg = &spec->autocfg;
1100 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001101 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001102 int i;
Matt2f2f4252005-04-13 14:45:30 +02001103
Takashi Iwai6479c632009-07-28 18:20:25 +02001104 if (spec->mixer) {
1105 err = snd_hda_add_new_ctls(codec, spec->mixer);
1106 if (err < 0)
1107 return err;
1108 }
Mattc7d4b2f2005-06-27 14:59:41 +02001109
1110 for (i = 0; i < spec->num_mixers; i++) {
1111 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1112 if (err < 0)
1113 return err;
1114 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001115 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1116 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001117 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001118 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001119 snd_ctl_new1(&stac_dmux_mixer, codec));
1120 if (err < 0)
1121 return err;
1122 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001123 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001124 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1125 struct hda_input_mux *smux = &spec->private_smux;
1126 /* check for mute support on SPDIF out */
1127 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001128 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001129 spec->spdif_mute = 1;
1130 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001131 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001132 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001133 snd_ctl_new1(&stac_smux_mixer, codec));
1134 if (err < 0)
1135 return err;
1136 }
Mattc7d4b2f2005-06-27 14:59:41 +02001137
Mattdabbed62005-06-14 10:19:34 +02001138 if (spec->multiout.dig_out_nid) {
1139 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1140 if (err < 0)
1141 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001142 err = snd_hda_create_spdif_share_sw(codec,
1143 &spec->multiout);
1144 if (err < 0)
1145 return err;
1146 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001147 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001148 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001149 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1150 if (err < 0)
1151 return err;
1152 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001153
1154 /* if we have no master control, let's create it */
1155 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001156 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001157 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001158 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001159 /* correct volume offset */
1160 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001161 /* minimum value is actually mute */
Clemens Ladischa74ccea2010-10-22 15:52:34 +02001162 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001163 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001164 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001165 if (err < 0)
1166 return err;
1167 }
1168 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1169 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1170 NULL, slave_sws);
1171 if (err < 0)
1172 return err;
1173 }
1174
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001175 if (spec->aloopback_ctl &&
1176 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1177 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1178 if (err < 0)
1179 return err;
1180 }
1181
Takashi Iwai603c4012008-07-30 15:01:44 +02001182 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001183
1184 /* create jack input elements */
1185 if (spec->hp_detect) {
1186 for (i = 0; i < cfg->hp_outs; i++) {
1187 int type = SND_JACK_HEADPHONE;
1188 nid = cfg->hp_pins[i];
1189 /* jack detection */
1190 if (cfg->hp_outs == i)
1191 type |= SND_JACK_LINEOUT;
1192 err = stac92xx_add_jack(codec, nid, type);
1193 if (err < 0)
1194 return err;
1195 }
1196 }
1197 for (i = 0; i < cfg->line_outs; i++) {
1198 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1199 SND_JACK_LINEOUT);
1200 if (err < 0)
1201 return err;
1202 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02001203 for (i = 0; i < cfg->num_inputs; i++) {
1204 nid = cfg->inputs[i].pin;
1205 err = stac92xx_add_jack(codec, nid, SND_JACK_MICROPHONE);
1206 if (err < 0)
1207 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001208 }
1209
Mattdabbed62005-06-14 10:19:34 +02001210 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001211}
1212
Matt Porter403d1942005-11-29 15:00:51 +01001213static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001214 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001215 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1216};
1217
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001218static unsigned int gateway9200_m4_pin_configs[8] = {
1219 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1220 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1221};
1222static unsigned int gateway9200_m4_2_pin_configs[8] = {
1223 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1224 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1225};
1226
1227/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001228 STAC 9200 pin configs for
1229 102801A8
1230 102801DE
1231 102801E8
1232*/
1233static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001234 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1235 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001236};
1237
1238/*
1239 STAC 9200 pin configs for
1240 102801C0
1241 102801C1
1242*/
1243static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001244 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1245 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001246};
1247
1248/*
1249 STAC 9200 pin configs for
1250 102801C4 (Dell Dimension E310)
1251 102801C5
1252 102801C7
1253 102801D9
1254 102801DA
1255 102801E3
1256*/
1257static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001258 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1259 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001260};
1261
1262
1263/*
1264 STAC 9200-32 pin configs for
1265 102801B5 (Dell Inspiron 630m)
1266 102801D8 (Dell Inspiron 640m)
1267*/
1268static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001269 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1270 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001271};
1272
1273/*
1274 STAC 9200-32 pin configs for
1275 102801C2 (Dell Latitude D620)
1276 102801C8
1277 102801CC (Dell Latitude D820)
1278 102801D4
1279 102801D6
1280*/
1281static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001282 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1283 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001284};
1285
1286/*
1287 STAC 9200-32 pin configs for
1288 102801CE (Dell XPS M1710)
1289 102801CF (Dell Precision M90)
1290*/
1291static unsigned int dell9200_m23_pin_configs[8] = {
1292 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1293 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1294};
1295
1296/*
1297 STAC 9200-32 pin configs for
1298 102801C9
1299 102801CA
1300 102801CB (Dell Latitude 120L)
1301 102801D3
1302*/
1303static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001304 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1305 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001306};
1307
1308/*
1309 STAC 9200-32 pin configs for
1310 102801BD (Dell Inspiron E1505n)
1311 102801EE
1312 102801EF
1313*/
1314static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001315 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1316 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001317};
1318
1319/*
1320 STAC 9200-32 pin configs for
1321 102801F5 (Dell Inspiron 1501)
1322 102801F6
1323*/
1324static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001325 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1326 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001327};
1328
1329/*
1330 STAC 9200-32
1331 102801CD (Dell Inspiron E1705/9400)
1332*/
1333static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001334 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1335 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001336};
1337
Tobin Davisbf277782008-02-03 20:31:47 +01001338static unsigned int oqo9200_pin_configs[8] = {
1339 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1340 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1341};
1342
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001343
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001344static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1345 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001346 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001347 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1348 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1349 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1350 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1351 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1352 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1353 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1354 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1355 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1356 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001357 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1358 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001359 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001360};
1361
Takashi Iwaiea734962011-01-17 11:29:34 +01001362static const char * const stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001363 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001364 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001365 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001366 [STAC_9200_DELL_D21] = "dell-d21",
1367 [STAC_9200_DELL_D22] = "dell-d22",
1368 [STAC_9200_DELL_D23] = "dell-d23",
1369 [STAC_9200_DELL_M21] = "dell-m21",
1370 [STAC_9200_DELL_M22] = "dell-m22",
1371 [STAC_9200_DELL_M23] = "dell-m23",
1372 [STAC_9200_DELL_M24] = "dell-m24",
1373 [STAC_9200_DELL_M25] = "dell-m25",
1374 [STAC_9200_DELL_M26] = "dell-m26",
1375 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001376 [STAC_9200_M4] = "gateway-m4",
1377 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001378 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001379};
1380
1381static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1382 /* SigmaTel reference board */
1383 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1384 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001385 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1386 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001387 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001388 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1389 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001390 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001391 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1392 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1393 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1394 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1395 "unknown Dell", STAC_9200_DELL_D22),
1396 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1397 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001398 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001399 "Dell Latitude D620", STAC_9200_DELL_M22),
1400 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1401 "unknown Dell", STAC_9200_DELL_D23),
1402 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1403 "unknown Dell", STAC_9200_DELL_D23),
1404 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1405 "unknown Dell", STAC_9200_DELL_M22),
1406 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1407 "unknown Dell", STAC_9200_DELL_M24),
1408 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1409 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001410 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001411 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001412 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001413 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001414 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001415 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001416 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001417 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001418 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001419 "Dell Precision M90", STAC_9200_DELL_M23),
1420 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1421 "unknown Dell", STAC_9200_DELL_M22),
1422 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1423 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001424 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001425 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001426 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001427 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1428 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1429 "unknown Dell", STAC_9200_DELL_D23),
1430 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1431 "unknown Dell", STAC_9200_DELL_D23),
1432 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1433 "unknown Dell", STAC_9200_DELL_D21),
1434 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1435 "unknown Dell", STAC_9200_DELL_D23),
1436 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1437 "unknown Dell", STAC_9200_DELL_D21),
1438 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1439 "unknown Dell", STAC_9200_DELL_M25),
1440 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1441 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001442 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001443 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1444 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1445 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001446 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001447 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001448 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001449 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1450 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1451 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001452 /* OQO Mobile */
1453 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001454 {} /* terminator */
1455};
1456
Tobin Davis8e21c342007-01-08 11:04:17 +01001457static unsigned int ref925x_pin_configs[8] = {
1458 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001459 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001460};
1461
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001462static unsigned int stac925xM1_pin_configs[8] = {
1463 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1464 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001465};
1466
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001467static unsigned int stac925xM1_2_pin_configs[8] = {
1468 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1469 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1470};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001471
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001472static unsigned int stac925xM2_pin_configs[8] = {
1473 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1474 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001475};
1476
Tobin Davis8e21c342007-01-08 11:04:17 +01001477static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001478 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1479 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1480};
1481
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001482static unsigned int stac925xM3_pin_configs[8] = {
1483 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1484 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1485};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001486
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001487static unsigned int stac925xM5_pin_configs[8] = {
1488 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1489 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1490};
1491
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001492static unsigned int stac925xM6_pin_configs[8] = {
1493 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1494 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001495};
1496
1497static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1498 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001499 [STAC_M1] = stac925xM1_pin_configs,
1500 [STAC_M1_2] = stac925xM1_2_pin_configs,
1501 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001502 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001503 [STAC_M3] = stac925xM3_pin_configs,
1504 [STAC_M5] = stac925xM5_pin_configs,
1505 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001506};
1507
Takashi Iwaiea734962011-01-17 11:29:34 +01001508static const char * const stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001509 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001510 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001511 [STAC_M1] = "m1",
1512 [STAC_M1_2] = "m1-2",
1513 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001514 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001515 [STAC_M3] = "m3",
1516 [STAC_M5] = "m5",
1517 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001518};
1519
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001520static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001521 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1522 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1523 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1524 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001525 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001526 /* Not sure about the brand name for those */
1527 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1528 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1529 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1530 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001531 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001532};
1533
1534static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1535 /* SigmaTel reference board */
1536 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001537 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001538 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001539
1540 /* Default table for unknown ID */
1541 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1542
Tobin Davis8e21c342007-01-08 11:04:17 +01001543 {} /* terminator */
1544};
1545
Matthew Ranostaya7662642008-02-21 07:51:14 +01001546static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001547 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1548 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1549 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001550 0x01452050,
1551};
1552
1553static unsigned int dell_m6_pin_configs[13] = {
1554 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001555 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001556 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1557 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001558};
1559
Takashi Iwai842ae632009-09-02 07:43:08 +02001560static unsigned int alienware_m17x_pin_configs[13] = {
1561 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1562 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1563 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1564 0x904601b0,
1565};
1566
Wu Fengguang4d26f442010-05-07 08:47:54 +08001567static unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001568 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001569 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001570};
1571
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001572static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001573 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001574 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1575 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1576 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001577 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001578 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001579 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001580};
1581
Takashi Iwaiea734962011-01-17 11:29:34 +01001582static const char * const stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001583 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001584 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001585 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001586 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001587 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1588 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1589 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001590 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001591 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001592};
1593
1594static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1595 /* SigmaTel reference board */
1596 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001597 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001598 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1599 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001600 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1601 "Intel DG45ID", STAC_92HD73XX_INTEL),
1602 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1603 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001604 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001605 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001606 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001607 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001608 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001609 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001610 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001611 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001612 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001613 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001614 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001615 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001616 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001617 "unknown Dell", STAC_DELL_M6_DMIC),
1618 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1619 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001620 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001621 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001622 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1623 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001624 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1625 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001626 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1627 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001628 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1629 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001630 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1631 "Dell Studio 1558", STAC_DELL_M6_BOTH),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001632 {} /* terminator */
1633};
1634
Takashi Iwai842ae632009-09-02 07:43:08 +02001635static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1636 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1637 "Alienware M17x", STAC_ALIENWARE_M17X),
Daniel T Chen0defe092010-12-01 19:16:07 -05001638 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1639 "Alienware M17x", STAC_ALIENWARE_M17X),
Takashi Iwai842ae632009-09-02 07:43:08 +02001640 {} /* terminator */
1641};
1642
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001643static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001644 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1645 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001646 0x01451160, 0x98560170,
1647};
1648
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001649static unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001650 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1651 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001652 0x40f000f0, 0x40f000f0,
1653};
1654
Steven Eastland48315592010-08-06 15:07:35 -06001655static unsigned int hp_dv7_4000_pin_configs[10] = {
1656 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1657 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1658 0x40f000f0, 0x40f000f0,
1659};
1660
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001661static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1662 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001663 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001664 [STAC_DELL_S14] = dell_s14_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001665 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001666};
1667
Takashi Iwaiea734962011-01-17 11:29:34 +01001668static const char * const stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001669 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001670 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001671 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001672 [STAC_DELL_S14] = "dell-s14",
Takashi Iwaib4e81872009-11-18 17:20:24 +01001673 [STAC_92HD83XXX_HP] = "hp",
Steven Eastland48315592010-08-06 15:07:35 -06001674 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001675};
1676
1677static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1678 /* SigmaTel reference board */
1679 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001680 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001681 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1682 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001683 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1684 "unknown Dell", STAC_DELL_S14),
Takashi Iwaib4e81872009-11-18 17:20:24 +01001685 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1686 "HP", STAC_92HD83XXX_HP),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001687 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001688};
1689
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001690static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001691 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001692 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001693 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1694 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001695};
1696
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001697static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001698 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001699 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001700 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1701 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001702};
1703
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001704static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001705 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1706 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001707 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1708 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001709};
1710
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001711static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001712 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1713 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001714 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1715 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001716};
1717
Matthew Ranostaye035b842007-11-06 11:53:55 +01001718static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1719 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001720 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1721 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001722 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001723 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001724 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001725 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001726 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001727 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001728};
1729
Takashi Iwaiea734962011-01-17 11:29:34 +01001730static const char * const stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001731 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001732 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001733 [STAC_DELL_M4_1] = "dell-m4-1",
1734 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001735 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001736 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001737 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001738 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001739 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001740 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001741};
1742
1743static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1744 /* SigmaTel reference board */
1745 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1746 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001747 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1748 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001749 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1750 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01001751 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1752 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01001753 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1754 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001755 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001756 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001757 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1758 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001759 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1760 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001761 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001762 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001763 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001764 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001765 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1766 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05301767 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1768 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11001769 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1770 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02001771 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1772 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001773 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1774 "unknown Dell", STAC_DELL_M4_1),
1775 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1776 "unknown Dell", STAC_DELL_M4_1),
1777 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1778 "unknown Dell", STAC_DELL_M4_1),
1779 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1780 "unknown Dell", STAC_DELL_M4_1),
1781 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1782 "unknown Dell", STAC_DELL_M4_1),
1783 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1784 "unknown Dell", STAC_DELL_M4_1),
1785 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1786 "unknown Dell", STAC_DELL_M4_1),
1787 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1788 "unknown Dell", STAC_DELL_M4_2),
1789 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1790 "unknown Dell", STAC_DELL_M4_2),
1791 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1792 "unknown Dell", STAC_DELL_M4_2),
1793 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1794 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001795 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1796 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001797 {} /* terminator */
1798};
1799
Matt Porter403d1942005-11-29 15:00:51 +01001800static unsigned int ref922x_pin_configs[10] = {
1801 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1802 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001803 0x40000100, 0x40000100,
1804};
1805
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001806/*
1807 STAC 922X pin configs for
1808 102801A7
1809 102801AB
1810 102801A9
1811 102801D1
1812 102801D2
1813*/
1814static unsigned int dell_922x_d81_pin_configs[10] = {
1815 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1816 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1817 0x01813122, 0x400001f2,
1818};
1819
1820/*
1821 STAC 922X pin configs for
1822 102801AC
1823 102801D0
1824*/
1825static unsigned int dell_922x_d82_pin_configs[10] = {
1826 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1827 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1828 0x01813122, 0x400001f1,
1829};
1830
1831/*
1832 STAC 922X pin configs for
1833 102801BF
1834*/
1835static unsigned int dell_922x_m81_pin_configs[10] = {
1836 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1837 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1838 0x40C003f1, 0x405003f0,
1839};
1840
1841/*
1842 STAC 9221 A1 pin configs for
1843 102801D7 (Dell XPS M1210)
1844*/
1845static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001846 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1847 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001848 0x508003f3, 0x405003f4,
1849};
1850
Matt Porter403d1942005-11-29 15:00:51 +01001851static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001852 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001853 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1854 0x02a19120, 0x40000100,
1855};
1856
1857static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001858 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1859 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001860 0x02a19320, 0x40000100,
1861};
1862
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001863static unsigned int intel_mac_v1_pin_configs[10] = {
1864 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1865 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001866 0x400000fc, 0x400000fb,
1867};
1868
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001869static unsigned int intel_mac_v2_pin_configs[10] = {
1870 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1871 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001872 0x400000fc, 0x400000fb,
1873};
1874
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001875static unsigned int intel_mac_v3_pin_configs[10] = {
1876 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1877 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1878 0x400000fc, 0x400000fb,
1879};
1880
1881static unsigned int intel_mac_v4_pin_configs[10] = {
1882 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1883 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1884 0x400000fc, 0x400000fb,
1885};
1886
1887static unsigned int intel_mac_v5_pin_configs[10] = {
1888 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1889 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1890 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001891};
1892
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001893static unsigned int ecs202_pin_configs[10] = {
1894 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1895 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1896 0x9037012e, 0x40e000f2,
1897};
Takashi Iwai76c08822007-06-19 12:17:42 +02001898
Takashi Iwai19039bd2006-06-28 15:52:16 +02001899static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001900 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001901 [STAC_D945GTP3] = d945gtp3_pin_configs,
1902 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001903 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1904 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1905 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1906 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1907 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001908 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001909 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001910 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1911 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1912 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1913 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1914 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1915 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001916 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001917 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1918 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1919 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1920 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001921};
1922
Takashi Iwaiea734962011-01-17 11:29:34 +01001923static const char * const stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001924 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001925 [STAC_D945_REF] = "ref",
1926 [STAC_D945GTP5] = "5stack",
1927 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001928 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1929 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1930 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1931 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1932 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001933 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001934 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001935 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001936 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001937 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1938 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001939 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001940 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001941 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001942 [STAC_922X_DELL_D81] = "dell-d81",
1943 [STAC_922X_DELL_D82] = "dell-d82",
1944 [STAC_922X_DELL_M81] = "dell-m81",
1945 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001946};
1947
1948static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1949 /* SigmaTel reference board */
1950 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1951 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001952 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1953 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001954 /* Intel 945G based systems */
1955 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1956 "Intel D945G", STAC_D945GTP3),
1957 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1958 "Intel D945G", STAC_D945GTP3),
1959 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1960 "Intel D945G", STAC_D945GTP3),
1961 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1962 "Intel D945G", STAC_D945GTP3),
1963 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1964 "Intel D945G", STAC_D945GTP3),
1965 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1966 "Intel D945G", STAC_D945GTP3),
1967 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1968 "Intel D945G", STAC_D945GTP3),
1969 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1970 "Intel D945G", STAC_D945GTP3),
1971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1972 "Intel D945G", STAC_D945GTP3),
1973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1974 "Intel D945G", STAC_D945GTP3),
1975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1976 "Intel D945G", STAC_D945GTP3),
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1978 "Intel D945G", STAC_D945GTP3),
1979 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1980 "Intel D945G", STAC_D945GTP3),
1981 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1982 "Intel D945G", STAC_D945GTP3),
1983 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1984 "Intel D945G", STAC_D945GTP3),
1985 /* Intel D945G 5-stack systems */
1986 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1987 "Intel D945G", STAC_D945GTP5),
1988 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1989 "Intel D945G", STAC_D945GTP5),
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1991 "Intel D945G", STAC_D945GTP5),
1992 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1993 "Intel D945G", STAC_D945GTP5),
1994 /* Intel 945P based systems */
1995 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1996 "Intel D945P", STAC_D945GTP3),
1997 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1998 "Intel D945P", STAC_D945GTP3),
1999 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2000 "Intel D945P", STAC_D945GTP3),
2001 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2002 "Intel D945P", STAC_D945GTP3),
2003 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2004 "Intel D945P", STAC_D945GTP3),
2005 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2006 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002007 /* other intel */
2008 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2009 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002010 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002011 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002012 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002013 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002014 /* Dell systems */
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2016 "unknown Dell", STAC_922X_DELL_D81),
2017 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2018 "unknown Dell", STAC_922X_DELL_D81),
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2020 "unknown Dell", STAC_922X_DELL_D81),
2021 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2022 "unknown Dell", STAC_922X_DELL_D82),
2023 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2024 "unknown Dell", STAC_922X_DELL_M81),
2025 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2026 "unknown Dell", STAC_922X_DELL_D82),
2027 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2028 "unknown Dell", STAC_922X_DELL_D81),
2029 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2030 "unknown Dell", STAC_922X_DELL_D81),
2031 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2032 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002033 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002034 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002035 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002036 {} /* terminator */
2037};
2038
Matt Porter3cc08dc2006-01-23 15:27:49 +01002039static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002040 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2041 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2042 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2043 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002044};
2045
Tobin Davis93ed1502006-09-01 21:03:12 +02002046static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002047 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2048 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2049 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2050 0x40000100, 0x40000100
2051};
2052
Tobin Davis93ed1502006-09-01 21:03:12 +02002053static unsigned int d965_5st_pin_configs[14] = {
2054 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2055 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2056 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2057 0x40000100, 0x40000100
2058};
2059
Takashi Iwai679d92e2009-05-24 19:00:08 +02002060static unsigned int d965_5st_no_fp_pin_configs[14] = {
2061 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2062 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2063 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2064 0x40000100, 0x40000100
2065};
2066
Tobin Davis4ff076e2007-08-07 11:48:12 +02002067static unsigned int dell_3st_pin_configs[14] = {
2068 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2069 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002070 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002071 0x40c003fc, 0x40000100
2072};
2073
Tobin Davis93ed1502006-09-01 21:03:12 +02002074static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002075 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002076 [STAC_D965_REF] = ref927x_pin_configs,
2077 [STAC_D965_3ST] = d965_3st_pin_configs,
2078 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002079 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002080 [STAC_DELL_3ST] = dell_3st_pin_configs,
2081 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002082 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002083};
2084
Takashi Iwaiea734962011-01-17 11:29:34 +01002085static const char * const stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002086 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002087 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002088 [STAC_D965_REF] = "ref",
2089 [STAC_D965_3ST] = "3stack",
2090 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002091 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002092 [STAC_DELL_3ST] = "dell-3stack",
2093 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002094 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002095};
2096
2097static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2098 /* SigmaTel reference board */
2099 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2100 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002101 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2102 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002103 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002104 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002106 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002107 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2108 "Intel D965", STAC_D965_3ST),
2109 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2110 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002111 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002112 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002113 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002115 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002116 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002117 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002118 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002119 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002120 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002121 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2122 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2123 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2124 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002125 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002126 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2127 "Intel D965", STAC_D965_5ST),
2128 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2129 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002130 /* volume-knob fixes */
2131 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002132 {} /* terminator */
2133};
2134
Matt Porterf3302a52006-07-31 12:49:34 +02002135static unsigned int ref9205_pin_configs[12] = {
2136 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002137 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002138 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002139};
2140
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002141/*
2142 STAC 9205 pin configs for
2143 102801F1
2144 102801F2
2145 102801FC
2146 102801FD
2147 10280204
2148 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002149 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002150 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002151*/
2152static unsigned int dell_9205_m42_pin_configs[12] = {
2153 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2154 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2155 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2156};
2157
2158/*
2159 STAC 9205 pin configs for
2160 102801F9
2161 102801FA
2162 102801FE
2163 102801FF (Dell Precision M4300)
2164 10280206
2165 10280200
2166 10280201
2167*/
2168static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002169 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2170 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2171 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2172};
2173
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002174static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002175 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2176 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2177 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2178};
2179
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002180static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002181 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002182 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2183 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2184 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002185 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002186};
2187
Takashi Iwaiea734962011-01-17 11:29:34 +01002188static const char * const stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002189 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002190 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002191 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002192 [STAC_9205_DELL_M43] = "dell-m43",
2193 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002194 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002195};
2196
2197static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2198 /* SigmaTel reference board */
2199 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2200 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002201 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2202 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002203 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2204 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002205 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002206 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2207 "unknown Dell", STAC_9205_DELL_M42),
2208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2209 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002210 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002211 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002212 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2213 "Dell Precision", STAC_9205_DELL_M43),
2214 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2215 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002216 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2217 "unknown Dell", STAC_9205_DELL_M42),
2218 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2219 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002220 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2221 "Dell Precision", STAC_9205_DELL_M43),
2222 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002223 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002224 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2225 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002226 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2227 "Dell Precision", STAC_9205_DELL_M43),
2228 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2229 "Dell Precision", STAC_9205_DELL_M43),
2230 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2231 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002232 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2233 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002234 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2235 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002236 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2237 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002238 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002239 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002240 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002241 {} /* terminator */
2242};
2243
Takashi Iwai330ee992009-02-20 14:33:36 +01002244static void stac92xx_set_config_regs(struct hda_codec *codec,
2245 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002246{
2247 int i;
2248 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002249
Takashi Iwai330ee992009-02-20 14:33:36 +01002250 if (!pincfgs)
2251 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002252
Matthew Ranostay87d48362007-07-17 11:52:24 +02002253 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002254 if (spec->pin_nids[i] && pincfgs[i])
2255 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2256 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002257}
2258
Matt2f2f4252005-04-13 14:45:30 +02002259/*
2260 * Analog playback callbacks
2261 */
2262static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2263 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002264 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002265{
2266 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002267 if (spec->stream_delay)
2268 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002269 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2270 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002271}
2272
2273static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2274 struct hda_codec *codec,
2275 unsigned int stream_tag,
2276 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002277 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002278{
2279 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002280 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002281}
2282
2283static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2284 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002285 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002286{
2287 struct sigmatel_spec *spec = codec->spec;
2288 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2289}
2290
2291/*
Mattdabbed62005-06-14 10:19:34 +02002292 * Digital playback callbacks
2293 */
2294static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2295 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002296 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002297{
2298 struct sigmatel_spec *spec = codec->spec;
2299 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2300}
2301
2302static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2303 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002304 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002305{
2306 struct sigmatel_spec *spec = codec->spec;
2307 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2308}
2309
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002310static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2311 struct hda_codec *codec,
2312 unsigned int stream_tag,
2313 unsigned int format,
2314 struct snd_pcm_substream *substream)
2315{
2316 struct sigmatel_spec *spec = codec->spec;
2317 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2318 stream_tag, format, substream);
2319}
2320
Takashi Iwai9411e212009-02-13 11:32:28 +01002321static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2322 struct hda_codec *codec,
2323 struct snd_pcm_substream *substream)
2324{
2325 struct sigmatel_spec *spec = codec->spec;
2326 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2327}
2328
Mattdabbed62005-06-14 10:19:34 +02002329
2330/*
Matt2f2f4252005-04-13 14:45:30 +02002331 * Analog capture callbacks
2332 */
2333static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2334 struct hda_codec *codec,
2335 unsigned int stream_tag,
2336 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002337 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002338{
2339 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002340 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002341
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002342 if (spec->powerdown_adcs) {
2343 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002344 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002345 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2346 }
2347 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002348 return 0;
2349}
2350
2351static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2352 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002353 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002354{
2355 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002356 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002357
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002358 snd_hda_codec_cleanup_stream(codec, nid);
2359 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002360 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002361 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002362 return 0;
2363}
2364
Mattdabbed62005-06-14 10:19:34 +02002365static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2366 .substreams = 1,
2367 .channels_min = 2,
2368 .channels_max = 2,
2369 /* NID is set in stac92xx_build_pcms */
2370 .ops = {
2371 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002372 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002373 .prepare = stac92xx_dig_playback_pcm_prepare,
2374 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002375 },
2376};
2377
2378static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2379 .substreams = 1,
2380 .channels_min = 2,
2381 .channels_max = 2,
2382 /* NID is set in stac92xx_build_pcms */
2383};
2384
Matt2f2f4252005-04-13 14:45:30 +02002385static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2386 .substreams = 1,
2387 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002388 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002389 .nid = 0x02, /* NID to query formats and rates */
2390 .ops = {
2391 .open = stac92xx_playback_pcm_open,
2392 .prepare = stac92xx_playback_pcm_prepare,
2393 .cleanup = stac92xx_playback_pcm_cleanup
2394 },
2395};
2396
Matt Porter3cc08dc2006-01-23 15:27:49 +01002397static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2398 .substreams = 1,
2399 .channels_min = 2,
2400 .channels_max = 2,
2401 .nid = 0x06, /* NID to query formats and rates */
2402 .ops = {
2403 .open = stac92xx_playback_pcm_open,
2404 .prepare = stac92xx_playback_pcm_prepare,
2405 .cleanup = stac92xx_playback_pcm_cleanup
2406 },
2407};
2408
Matt2f2f4252005-04-13 14:45:30 +02002409static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002410 .channels_min = 2,
2411 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002412 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002413 .ops = {
2414 .prepare = stac92xx_capture_pcm_prepare,
2415 .cleanup = stac92xx_capture_pcm_cleanup
2416 },
2417};
2418
2419static int stac92xx_build_pcms(struct hda_codec *codec)
2420{
2421 struct sigmatel_spec *spec = codec->spec;
2422 struct hda_pcm *info = spec->pcm_rec;
2423
2424 codec->num_pcms = 1;
2425 codec->pcm_info = info;
2426
Mattc7d4b2f2005-06-27 14:59:41 +02002427 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002428 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002429 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2430 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002431 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002432 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002433 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002434
2435 if (spec->alt_switch) {
2436 codec->num_pcms++;
2437 info++;
2438 info->name = "STAC92xx Analog Alt";
2439 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2440 }
Matt2f2f4252005-04-13 14:45:30 +02002441
Mattdabbed62005-06-14 10:19:34 +02002442 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2443 codec->num_pcms++;
2444 info++;
2445 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002446 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002447 if (spec->multiout.dig_out_nid) {
2448 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2449 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2450 }
2451 if (spec->dig_in_nid) {
2452 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2453 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2454 }
2455 }
2456
Matt2f2f4252005-04-13 14:45:30 +02002457 return 0;
2458}
2459
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002460static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2461 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002462{
Takashi Iwai1327a322009-03-23 13:07:47 +01002463 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002464 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2465 if (pincap & AC_PINCAP_VREF_100)
2466 return AC_PINCTL_VREF_100;
2467 if (pincap & AC_PINCAP_VREF_80)
2468 return AC_PINCTL_VREF_80;
2469 if (pincap & AC_PINCAP_VREF_50)
2470 return AC_PINCTL_VREF_50;
2471 if (pincap & AC_PINCAP_VREF_GRD)
2472 return AC_PINCTL_VREF_GRD;
2473 return 0;
2474}
2475
Matt Porter403d1942005-11-29 15:00:51 +01002476static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2477
2478{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002479 snd_hda_codec_write_cache(codec, nid, 0,
2480 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002481}
2482
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002483#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2484
2485static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2486 struct snd_ctl_elem_value *ucontrol)
2487{
2488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2489 struct sigmatel_spec *spec = codec->spec;
2490
Takashi Iwaid7a89432008-11-12 09:48:04 +01002491 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002492 return 0;
2493}
2494
Takashi Iwai62558ce2009-07-29 14:23:09 +02002495static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002496
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002497static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2498 struct snd_ctl_elem_value *ucontrol)
2499{
2500 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2501 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002502 int nid = kcontrol->private_value;
2503
2504 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002505
2506 /* check to be sure that the ports are upto date with
2507 * switch changes
2508 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002509 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002510
2511 return 1;
2512}
2513
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002514static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2515 struct snd_ctl_elem_info *uinfo)
2516{
2517 int i;
2518 static char *texts[] = {
2519 "Mic In", "Line In", "Line Out"
2520 };
2521
2522 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2523 struct sigmatel_spec *spec = codec->spec;
2524 hda_nid_t nid = kcontrol->private_value;
2525
2526 if (nid == spec->mic_switch || nid == spec->line_switch)
2527 i = 3;
2528 else
2529 i = 2;
2530
2531 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2532 uinfo->value.enumerated.items = i;
2533 uinfo->count = 1;
2534 if (uinfo->value.enumerated.item >= i)
2535 uinfo->value.enumerated.item = i-1;
2536 strcpy(uinfo->value.enumerated.name,
2537 texts[uinfo->value.enumerated.item]);
2538
2539 return 0;
2540}
2541
2542static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2543 struct snd_ctl_elem_value *ucontrol)
2544{
2545 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2546 hda_nid_t nid = kcontrol->private_value;
2547 unsigned int vref = stac92xx_vref_get(codec, nid);
2548
2549 if (vref == stac92xx_get_default_vref(codec, nid))
2550 ucontrol->value.enumerated.item[0] = 0;
2551 else if (vref == AC_PINCTL_VREF_GRD)
2552 ucontrol->value.enumerated.item[0] = 1;
2553 else if (vref == AC_PINCTL_VREF_HIZ)
2554 ucontrol->value.enumerated.item[0] = 2;
2555
2556 return 0;
2557}
2558
2559static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2560 struct snd_ctl_elem_value *ucontrol)
2561{
2562 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2563 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002564 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002565 hda_nid_t nid = kcontrol->private_value;
2566
2567 if (ucontrol->value.enumerated.item[0] == 0)
2568 new_vref = stac92xx_get_default_vref(codec, nid);
2569 else if (ucontrol->value.enumerated.item[0] == 1)
2570 new_vref = AC_PINCTL_VREF_GRD;
2571 else if (ucontrol->value.enumerated.item[0] == 2)
2572 new_vref = AC_PINCTL_VREF_HIZ;
2573 else
2574 return 0;
2575
2576 if (new_vref != stac92xx_vref_get(codec, nid)) {
2577 error = stac92xx_vref_set(codec, nid, new_vref);
2578 return error;
2579 }
2580
2581 return 0;
2582}
2583
2584static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2585 struct snd_ctl_elem_info *uinfo)
2586{
2587 static char *texts[2];
2588 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2589 struct sigmatel_spec *spec = codec->spec;
2590
2591 if (kcontrol->private_value == spec->line_switch)
2592 texts[0] = "Line In";
2593 else
2594 texts[0] = "Mic In";
2595 texts[1] = "Line Out";
2596 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2597 uinfo->value.enumerated.items = 2;
2598 uinfo->count = 1;
2599
2600 if (uinfo->value.enumerated.item >= 2)
2601 uinfo->value.enumerated.item = 1;
2602 strcpy(uinfo->value.enumerated.name,
2603 texts[uinfo->value.enumerated.item]);
2604
2605 return 0;
2606}
Matt Porter403d1942005-11-29 15:00:51 +01002607
2608static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2609{
2610 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2611 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002612 hda_nid_t nid = kcontrol->private_value;
2613 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002614
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002615 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002616 return 0;
2617}
2618
2619static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2620{
2621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2622 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002623 hda_nid_t nid = kcontrol->private_value;
2624 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2625 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002626
2627 spec->io_switch[io_idx] = val;
2628
2629 if (val)
2630 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002631 else {
2632 unsigned int pinctl = AC_PINCTL_IN_EN;
2633 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002634 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002635 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2636 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002637
2638 /* check the auto-mute again: we need to mute/unmute the speaker
2639 * appropriately according to the pin direction
2640 */
2641 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002642 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002643
Matt Porter403d1942005-11-29 15:00:51 +01002644 return 1;
2645}
2646
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002647#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2648
2649static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2650 struct snd_ctl_elem_value *ucontrol)
2651{
2652 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2653 struct sigmatel_spec *spec = codec->spec;
2654
2655 ucontrol->value.integer.value[0] = spec->clfe_swap;
2656 return 0;
2657}
2658
2659static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2660 struct snd_ctl_elem_value *ucontrol)
2661{
2662 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2663 struct sigmatel_spec *spec = codec->spec;
2664 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002665 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002666
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002667 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002668 return 0;
2669
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002670 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002671
2672 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2673 spec->clfe_swap ? 0x4 : 0x0);
2674
2675 return 1;
2676}
2677
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002678#define STAC_CODEC_HP_SWITCH(xname) \
2679 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2680 .name = xname, \
2681 .index = 0, \
2682 .info = stac92xx_hp_switch_info, \
2683 .get = stac92xx_hp_switch_get, \
2684 .put = stac92xx_hp_switch_put, \
2685 }
2686
Matt Porter403d1942005-11-29 15:00:51 +01002687#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2688 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2689 .name = xname, \
2690 .index = 0, \
2691 .info = stac92xx_io_switch_info, \
2692 .get = stac92xx_io_switch_get, \
2693 .put = stac92xx_io_switch_put, \
2694 .private_value = xpval, \
2695 }
2696
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002697#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2698 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2699 .name = xname, \
2700 .index = 0, \
2701 .info = stac92xx_clfe_switch_info, \
2702 .get = stac92xx_clfe_switch_get, \
2703 .put = stac92xx_clfe_switch_put, \
2704 .private_value = xpval, \
2705 }
Matt Porter403d1942005-11-29 15:00:51 +01002706
Mattc7d4b2f2005-06-27 14:59:41 +02002707enum {
2708 STAC_CTL_WIDGET_VOL,
2709 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002710 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002711 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002712 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002713 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002714 STAC_CTL_WIDGET_CLFE_SWITCH,
2715 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002716};
2717
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002718static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002719 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2720 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002721 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002722 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002723 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002724 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002725 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002726 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002727};
2728
2729/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002730static struct snd_kcontrol_new *
2731stac_control_new(struct sigmatel_spec *spec,
2732 struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002733 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002734 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002735{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002736 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002737
Takashi Iwai603c4012008-07-30 15:01:44 +02002738 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2739 knew = snd_array_new(&spec->kctls);
2740 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002741 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002742 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002743 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002744 if (!knew->name) {
2745 /* roolback */
2746 memset(knew, 0, sizeof(*knew));
2747 spec->kctls.alloced--;
2748 return NULL;
2749 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002750 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002751 return knew;
2752}
2753
2754static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2755 struct snd_kcontrol_new *ktemp,
2756 int idx, const char *name,
2757 unsigned long val)
2758{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002759 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002760 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002761 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002762 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002763 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002764 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002765 return 0;
2766}
2767
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002768static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2769 int type, int idx, const char *name,
2770 unsigned long val)
2771{
2772 return stac92xx_add_control_temp(spec,
2773 &stac92xx_control_templates[type],
2774 idx, name, val);
2775}
2776
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002777
2778/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002779static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2780 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002781{
2782 return stac92xx_add_control_idx(spec, type, 0, name, val);
2783}
2784
Takashi Iwaie3c75962009-01-23 11:57:22 +01002785static struct snd_kcontrol_new stac_input_src_temp = {
2786 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2787 .name = "Input Source",
2788 .info = stac92xx_mux_enum_info,
2789 .get = stac92xx_mux_enum_get,
2790 .put = stac92xx_mux_enum_put,
2791};
2792
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002793static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2794 hda_nid_t nid, int idx)
2795{
2796 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2797 int control = 0;
2798 struct sigmatel_spec *spec = codec->spec;
2799 char name[22];
2800
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002801 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002802 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2803 && nid == spec->line_switch)
2804 control = STAC_CTL_WIDGET_IO_SWITCH;
2805 else if (snd_hda_query_pin_caps(codec, nid)
2806 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2807 control = STAC_CTL_WIDGET_DC_BIAS;
2808 else if (nid == spec->mic_switch)
2809 control = STAC_CTL_WIDGET_IO_SWITCH;
2810 }
2811
2812 if (control) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002813 strcpy(name, hda_get_input_pin_label(codec, nid, 1));
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002814 return stac92xx_add_control(codec->spec, control,
2815 strcat(name, " Jack Mode"), nid);
2816 }
2817
2818 return 0;
2819}
2820
Takashi Iwaie3c75962009-01-23 11:57:22 +01002821static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2822{
2823 struct snd_kcontrol_new *knew;
2824 struct hda_input_mux *imux = &spec->private_imux;
2825
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002826 if (spec->auto_mic)
2827 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002828 if (!spec->num_adcs || imux->num_items <= 1)
2829 return 0; /* no need for input source control */
2830 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002831 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002832 if (!knew)
2833 return -ENOMEM;
2834 knew->count = spec->num_adcs;
2835 return 0;
2836}
2837
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002838/* check whether the line-input can be used as line-out */
2839static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002840{
2841 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002842 struct auto_pin_cfg *cfg = &spec->autocfg;
2843 hda_nid_t nid;
2844 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002845 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002846
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002847 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2848 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002849 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02002850 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002851 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01002852 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002853 if (pincap & AC_PINCAP_OUT)
2854 return nid;
2855 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002856 }
Matt Porter403d1942005-11-29 15:00:51 +01002857 return 0;
2858}
2859
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002860static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2861
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002862/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002863static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002864{
2865 struct sigmatel_spec *spec = codec->spec;
2866 struct auto_pin_cfg *cfg = &spec->autocfg;
2867 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02002868 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002869
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002870 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002871 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2872 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002873 for (i = 0; i < cfg->num_inputs; i++) {
2874 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02002875 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002876 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002877 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2878 /* some laptops have an internal analog microphone
2879 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002880 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002881 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002882 if (pincap & AC_PINCAP_OUT) {
2883 *dac = get_unassigned_dac(codec, nid);
2884 if (*dac)
2885 return nid;
2886 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002887 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002888 }
2889 return 0;
2890}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002891
2892static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2893{
2894 int i;
2895
2896 for (i = 0; i < spec->multiout.num_dacs; i++) {
2897 if (spec->multiout.dac_nids[i] == nid)
2898 return 1;
2899 }
2900
2901 return 0;
2902}
2903
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002904static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2905{
2906 int i;
2907 if (is_in_dac_nids(spec, nid))
2908 return 1;
2909 for (i = 0; i < spec->autocfg.hp_outs; i++)
2910 if (spec->hp_dacs[i] == nid)
2911 return 1;
2912 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2913 if (spec->speaker_dacs[i] == nid)
2914 return 1;
2915 return 0;
2916}
2917
2918static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2919{
2920 struct sigmatel_spec *spec = codec->spec;
2921 int j, conn_len;
2922 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2923 unsigned int wcaps, wtype;
2924
2925 conn_len = snd_hda_get_connections(codec, nid, conn,
2926 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002927 /* 92HD88: trace back up the link of nids to find the DAC */
2928 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2929 != AC_WID_AUD_OUT)) {
2930 nid = conn[0];
2931 conn_len = snd_hda_get_connections(codec, nid, conn,
2932 HDA_MAX_CONNECTIONS);
2933 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002934 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002935 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002936 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002937 /* we check only analog outputs */
2938 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2939 continue;
2940 /* if this route has a free DAC, assign it */
2941 if (!check_all_dac_nids(spec, conn[j])) {
2942 if (conn_len > 1) {
2943 /* select this DAC in the pin's input mux */
2944 snd_hda_codec_write_cache(codec, nid, 0,
2945 AC_VERB_SET_CONNECT_SEL, j);
2946 }
2947 return conn[j];
2948 }
2949 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002950 /* if all DACs are already assigned, connect to the primary DAC */
2951 if (conn_len > 1) {
2952 for (j = 0; j < conn_len; j++) {
2953 if (conn[j] == spec->multiout.dac_nids[0]) {
2954 snd_hda_codec_write_cache(codec, nid, 0,
2955 AC_VERB_SET_CONNECT_SEL, j);
2956 break;
2957 }
2958 }
2959 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002960 return 0;
2961}
2962
2963static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2964static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2965
Matt Porter3cc08dc2006-01-23 15:27:49 +01002966/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002967 * Fill in the dac_nids table from the parsed pin configuration
2968 * This function only works when every pin in line_out_pins[]
2969 * contains atleast one DAC in its connection list. Some 92xx
2970 * codecs are not connected directly to a DAC, such as the 9200
2971 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002972 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002973static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002974{
2975 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002976 struct auto_pin_cfg *cfg = &spec->autocfg;
2977 int i;
2978 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002979
Mattc7d4b2f2005-06-27 14:59:41 +02002980 for (i = 0; i < cfg->line_outs; i++) {
2981 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002982 dac = get_unassigned_dac(codec, nid);
2983 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002984 if (spec->multiout.num_dacs > 0) {
2985 /* we have already working output pins,
2986 * so let's drop the broken ones again
2987 */
2988 cfg->line_outs = spec->multiout.num_dacs;
2989 break;
2990 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002991 /* error out, no available DAC found */
2992 snd_printk(KERN_ERR
2993 "%s: No available DAC for pin 0x%x\n",
2994 __func__, nid);
2995 return -ENODEV;
2996 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002997 add_spec_dacs(spec, dac);
2998 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002999
Takashi Iwai139e0712009-03-06 12:10:41 +01003000 for (i = 0; i < cfg->hp_outs; i++) {
3001 nid = cfg->hp_pins[i];
3002 dac = get_unassigned_dac(codec, nid);
3003 if (dac) {
3004 if (!spec->multiout.hp_nid)
3005 spec->multiout.hp_nid = dac;
3006 else
3007 add_spec_extra_dacs(spec, dac);
3008 }
3009 spec->hp_dacs[i] = dac;
3010 }
3011
3012 for (i = 0; i < cfg->speaker_outs; i++) {
3013 nid = cfg->speaker_pins[i];
3014 dac = get_unassigned_dac(codec, nid);
3015 if (dac)
3016 add_spec_extra_dacs(spec, dac);
3017 spec->speaker_dacs[i] = dac;
3018 }
3019
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003020 /* add line-in as output */
3021 nid = check_line_out_switch(codec);
3022 if (nid) {
3023 dac = get_unassigned_dac(codec, nid);
3024 if (dac) {
3025 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3026 nid, cfg->line_outs);
3027 cfg->line_out_pins[cfg->line_outs] = nid;
3028 cfg->line_outs++;
3029 spec->line_switch = nid;
3030 add_spec_dacs(spec, dac);
3031 }
3032 }
3033 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003034 nid = check_mic_out_switch(codec, &dac);
3035 if (nid && dac) {
3036 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3037 nid, cfg->line_outs);
3038 cfg->line_out_pins[cfg->line_outs] = nid;
3039 cfg->line_outs++;
3040 spec->mic_switch = nid;
3041 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003042 }
3043
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003044 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003045 spec->multiout.num_dacs,
3046 spec->multiout.dac_nids[0],
3047 spec->multiout.dac_nids[1],
3048 spec->multiout.dac_nids[2],
3049 spec->multiout.dac_nids[3],
3050 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003051
Mattc7d4b2f2005-06-27 14:59:41 +02003052 return 0;
3053}
3054
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003055/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003056static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3057 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003058{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003059 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003060 char name[32];
3061 int err;
3062
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003063 if (!spec->check_volume_offset) {
3064 unsigned int caps, step, nums, db_scale;
3065 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3066 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3067 AC_AMPCAP_STEP_SIZE_SHIFT;
3068 step = (step + 1) * 25; /* in .01dB unit */
3069 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3070 AC_AMPCAP_NUM_STEPS_SHIFT;
3071 db_scale = nums * step;
3072 /* if dB scale is over -64dB, and finer enough,
3073 * let's reduce it to half
3074 */
3075 if (db_scale > 6400 && nums >= 0x1f)
3076 spec->volume_offset = nums / 2;
3077 spec->check_volume_offset = 1;
3078 }
3079
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003080 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003081 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003082 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3083 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003084 if (err < 0)
3085 return err;
3086 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003087 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003088 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3089 if (err < 0)
3090 return err;
3091 return 0;
3092}
3093
Takashi Iwai668b9652009-03-06 10:13:24 +01003094#define create_controls(codec, pfx, nid, chs) \
3095 create_controls_idx(codec, pfx, 0, nid, chs)
3096
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003097static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3098{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003099 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003100 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3101 return 1;
3102 } else {
3103 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3104 spec->multiout.num_dacs++;
3105 }
3106 return 0;
3107}
3108
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003109static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003110{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003111 int i;
3112 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3113 if (!spec->multiout.extra_out_nid[i]) {
3114 spec->multiout.extra_out_nid[i] = nid;
3115 return 0;
3116 }
3117 }
3118 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3119 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003120}
3121
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003122/* Create output controls
3123 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3124 */
3125static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3126 const hda_nid_t *pins,
3127 const hda_nid_t *dac_nids,
3128 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003129{
Takashi Iwai76624532008-12-19 10:09:47 +01003130 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaiea734962011-01-17 11:29:34 +01003131 static const char * const chname[4] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02003132 "Front", "Surround", NULL /*CLFE*/, "Side"
3133 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003134 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003135 int i, err;
3136 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003137
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003138 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003139 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3140 wid_caps = get_wcaps(codec, pins[i]);
3141 if (wid_caps & AC_WCAP_UNSOL_CAP)
3142 spec->hp_detect = 1;
3143 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003144 nid = dac_nids[i];
3145 if (!nid)
3146 continue;
3147 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003148 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003149 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003150 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003151 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003152 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003153 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003154 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003155
3156 wid_caps = get_wcaps(codec, nid);
3157
3158 if (wid_caps & AC_WCAP_LR_SWAP) {
3159 err = stac92xx_add_control(spec,
3160 STAC_CTL_WIDGET_CLFE_SWITCH,
3161 "Swap Center/LFE Playback Switch", nid);
3162
3163 if (err < 0)
3164 return err;
3165 }
3166
Mattc7d4b2f2005-06-27 14:59:41 +02003167 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003168 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003169 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003170 switch (type) {
3171 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003172 name = "Headphone";
3173 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003174 break;
3175 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003176 name = "Speaker";
3177 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003178 break;
3179 default:
3180 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003181 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003182 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003183 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003184 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003185 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003186 return err;
3187 }
3188 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003189 return 0;
3190}
3191
Takashi Iwai6479c632009-07-28 18:20:25 +02003192static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3193 unsigned long sw, int idx)
3194{
3195 int err;
3196 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003197 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003198 if (err < 0)
3199 return err;
3200 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003201 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003202 if (err < 0)
3203 return err;
3204 return 0;
3205}
3206
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003207/* add playback controls from the parsed DAC table */
3208static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3209 const struct auto_pin_cfg *cfg)
3210{
3211 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003212 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003213 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003214 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003215
3216 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3217 spec->multiout.dac_nids,
3218 cfg->line_out_type);
3219 if (err < 0)
3220 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003221
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003222 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003223 err = stac92xx_add_control(spec,
3224 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003225 "Headphone as Line Out Switch",
3226 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003227 if (err < 0)
3228 return err;
3229 }
3230
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003231 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003232 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003233 break;
3234 nid = cfg->inputs[idx].pin;
3235 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3236 if (err < 0)
3237 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003238 }
Matt Porter403d1942005-11-29 15:00:51 +01003239
Mattc7d4b2f2005-06-27 14:59:41 +02003240 return 0;
3241}
3242
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003243/* add playback controls for Speaker and HP outputs */
3244static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3245 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003246{
3247 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003248 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003249
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003250 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3251 spec->hp_dacs, AUTO_PIN_HP_OUT);
3252 if (err < 0)
3253 return err;
3254
3255 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3256 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3257 if (err < 0)
3258 return err;
3259
Mattc7d4b2f2005-06-27 14:59:41 +02003260 return 0;
3261}
3262
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003263/* labels for mono mux outputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003264static const char * const stac92xx_mono_labels[4] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003265 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003266};
3267
3268/* create mono mux for mono out on capable codecs */
3269static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3270{
3271 struct sigmatel_spec *spec = codec->spec;
3272 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3273 int i, num_cons;
3274 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3275
3276 num_cons = snd_hda_get_connections(codec,
3277 spec->mono_nid,
3278 con_lst,
3279 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003280 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003281 return -EINVAL;
3282
Takashi Iwai10a20af2010-09-09 16:28:02 +02003283 for (i = 0; i < num_cons; i++)
3284 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3285 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003286
3287 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3288 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003289}
3290
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003291/* create PC beep volume controls */
3292static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3293 hda_nid_t nid)
3294{
3295 struct sigmatel_spec *spec = codec->spec;
3296 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003297 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3298
3299 if (spec->anabeep_nid == nid)
3300 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003301
3302 /* check for mute support for the the amp */
3303 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003304 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003305 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003306 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3307 if (err < 0)
3308 return err;
3309 }
3310
3311 /* check to see if there is volume support for the amp */
3312 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3313 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003314 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003315 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3316 if (err < 0)
3317 return err;
3318 }
3319 return 0;
3320}
3321
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003322#ifdef CONFIG_SND_HDA_INPUT_BEEP
3323#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3324
3325static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3326 struct snd_ctl_elem_value *ucontrol)
3327{
3328 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3329 ucontrol->value.integer.value[0] = codec->beep->enabled;
3330 return 0;
3331}
3332
3333static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3334 struct snd_ctl_elem_value *ucontrol)
3335{
3336 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003337 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003338}
3339
3340static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3341 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3342 .info = stac92xx_dig_beep_switch_info,
3343 .get = stac92xx_dig_beep_switch_get,
3344 .put = stac92xx_dig_beep_switch_put,
3345};
3346
3347static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3348{
3349 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003350 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003351}
3352#endif
3353
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003354static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3355{
3356 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003357 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003358
3359 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003360 hda_nid_t nid;
3361 unsigned int wcaps;
3362 unsigned long val;
3363
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003364 nid = spec->mux_nids[i];
3365 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003366 if (!(wcaps & AC_WCAP_OUT_AMP))
3367 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003368
Takashi Iwai667067d2009-08-13 18:14:42 +02003369 /* check whether already the same control was created as
3370 * normal Capture Volume.
3371 */
3372 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3373 for (j = 0; j < spec->num_caps; j++) {
3374 if (spec->capvols[j] == val)
3375 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003376 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003377 if (j < spec->num_caps)
3378 continue;
3379
3380 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3381 "Mux Capture Volume", val);
3382 if (err < 0)
3383 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003384 }
3385 return 0;
3386};
3387
Takashi Iwaiea734962011-01-17 11:29:34 +01003388static const char * const stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003389 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003390};
3391
3392static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3393{
3394 struct sigmatel_spec *spec = codec->spec;
3395 struct hda_input_mux *spdif_mux = &spec->private_smux;
Takashi Iwaiea734962011-01-17 11:29:34 +01003396 const char * const *labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003397 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003398 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003399
3400 num_cons = snd_hda_get_connections(codec,
3401 spec->smux_nids[0],
3402 con_lst,
3403 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003404 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003405 return -EINVAL;
3406
Matthew Ranostay65973632008-09-16 10:39:37 -04003407 if (!labels)
3408 labels = stac92xx_spdif_labels;
3409
Takashi Iwai10a20af2010-09-09 16:28:02 +02003410 for (i = 0; i < num_cons; i++)
3411 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003412
3413 return 0;
3414}
3415
Matt Porter8b657272006-10-26 17:12:59 +02003416/* labels for dmic mux inputs */
Takashi Iwaiea734962011-01-17 11:29:34 +01003417static const char * const stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003418 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3419 "Digital Mic 3", "Digital Mic 4"
3420};
3421
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003422static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3423 hda_nid_t nid)
3424{
3425 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3426 int i, nums;
3427
3428 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3429 for (i = 0; i < nums; i++)
3430 if (conn[i] == nid)
3431 return i;
3432 return -1;
3433}
3434
Takashi Iwai667067d2009-08-13 18:14:42 +02003435/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003436/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003437static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003438 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003439{
3440 unsigned int caps, nums;
3441 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003442 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003443
Takashi Iwai96f845d2009-08-29 00:49:36 +02003444 if (direction == HDA_OUTPUT)
3445 caps = AC_WCAP_OUT_AMP;
3446 else
3447 caps = AC_WCAP_IN_AMP;
3448 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003449 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003450 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003451 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3452 if (!nums)
3453 return 0;
3454 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003455 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3456 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003457 if (err < 0)
3458 return err;
3459 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003460}
3461
Matt Porter8b657272006-10-26 17:12:59 +02003462/* create playback/capture controls for input pins on dmic capable codecs */
3463static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3464 const struct auto_pin_cfg *cfg)
3465{
3466 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003467 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003468 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003469 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003470 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003471
Takashi Iwai10a20af2010-09-09 16:28:02 +02003472 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003473
Matt Porter8b657272006-10-26 17:12:59 +02003474 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003475 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003476 int index, type_idx;
Takashi Iwai5207e102009-07-30 13:09:08 +02003477 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003478
Takashi Iwai667067d2009-08-13 18:14:42 +02003479 nid = spec->dmic_nids[i];
3480 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3481 continue;
3482 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003483 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3484 continue;
3485
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003486 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3487 if (index < 0)
3488 continue;
3489
Takashi Iwai10a20af2010-09-09 16:28:02 +02003490 label = hda_get_input_pin_label(codec, nid, 1);
3491 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai2d7ec122010-12-23 10:16:05 +01003492 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3493 snd_hda_add_imux_item(imux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003494
Takashi Iwai10a20af2010-09-09 16:28:02 +02003495 err = create_elem_capture_vol(codec, nid, label, type_idx,
3496 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003497 if (err < 0)
3498 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003499 if (!err) {
3500 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003501 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003502 if (err < 0)
3503 return err;
3504 }
Matt Porter8b657272006-10-26 17:12:59 +02003505 }
3506
3507 return 0;
3508}
3509
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003510static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003511 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003512{
3513 unsigned int cfg;
3514
3515 if (!nid)
3516 return 0;
3517 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003518 switch (snd_hda_get_input_pin_attr(cfg)) {
3519 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003520 if (*fixed)
3521 return 1; /* already occupied */
3522 *fixed = nid;
3523 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003524 case INPUT_PIN_ATTR_UNUSED:
3525 break;
3526 case INPUT_PIN_ATTR_DOCK:
3527 if (*dock)
3528 return 1; /* already occupied */
3529 *dock = nid;
3530 break;
3531 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003532 if (*ext)
3533 return 1; /* already occupied */
3534 *ext = nid;
3535 break;
3536 }
3537 return 0;
3538}
3539
3540static int set_mic_route(struct hda_codec *codec,
3541 struct sigmatel_mic_route *mic,
3542 hda_nid_t pin)
3543{
3544 struct sigmatel_spec *spec = codec->spec;
3545 struct auto_pin_cfg *cfg = &spec->autocfg;
3546 int i;
3547
3548 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003549 if (pin == 0)
3550 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003551 for (i = 0; i < cfg->num_inputs; i++) {
3552 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003553 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003554 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003555 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003556 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003557 i = get_connection_index(codec, spec->mux_nids[0], pin);
3558 if (i < 0)
3559 return -1;
3560 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003561 mic->dmux_idx = -1;
3562 if (spec->dmux_nids)
3563 mic->dmux_idx = get_connection_index(codec,
3564 spec->dmux_nids[0],
3565 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003566 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003567 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003568 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3569 if (i < 0)
3570 return -1;
3571 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003572 mic->mux_idx = -1;
3573 if (spec->mux_nids)
3574 mic->mux_idx = get_connection_index(codec,
3575 spec->mux_nids[0],
3576 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003577 }
3578 return 0;
3579}
3580
3581/* return non-zero if the device is for automatic mic switch */
3582static int stac_check_auto_mic(struct hda_codec *codec)
3583{
3584 struct sigmatel_spec *spec = codec->spec;
3585 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02003586 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003587 int i;
3588
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003589 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003590 if (cfg->inputs[i].type >= AUTO_PIN_LINE_IN)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003591 return 0; /* must be exclusively mics */
3592 }
Charles Chin99077902010-09-17 10:22:32 +02003593 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003594 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02003595 if (check_mic_pin(codec, cfg->inputs[i].pin,
3596 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003597 return 0;
3598 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02003599 if (check_mic_pin(codec, spec->dmic_nids[i],
3600 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003601 return 0;
Takashi Iwai80c67852011-01-13 08:08:08 +01003602 if (!fixed || (!ext && !dock))
Charles Chin99077902010-09-17 10:22:32 +02003603 return 0; /* no input to switch */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003604 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3605 return 0; /* no unsol support */
3606 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02003607 set_mic_route(codec, &spec->int_mic, fixed) ||
3608 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003609 return 0; /* something is wrong */
3610 return 1;
3611}
3612
Mattc7d4b2f2005-06-27 14:59:41 +02003613/* create playback/capture controls for input pins */
3614static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3615{
3616 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003617 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003618 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003619 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02003620
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003621 for (i = 0; i < cfg->num_inputs; i++) {
3622 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003623 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02003624
Takashi Iwai314634b2006-09-21 11:56:18 +02003625 index = -1;
3626 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003627 index = get_connection_index(codec, spec->mux_nids[j],
3628 nid);
3629 if (index >= 0)
3630 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003631 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003632 if (index < 0)
3633 continue;
3634
Takashi Iwai10a20af2010-09-09 16:28:02 +02003635 label = hda_get_autocfg_input_label(codec, cfg, i);
3636 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003637
Takashi Iwai667067d2009-08-13 18:14:42 +02003638 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003639 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003640 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003641 if (err < 0)
3642 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003643 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003644 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003645
Steve Longerbeam7b043892007-05-03 20:50:03 +02003646 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003647 /*
3648 * Set the current input for the muxes.
3649 * The STAC9221 has two input muxes with identical source
3650 * NID lists. Hopefully this won't get confused.
3651 */
3652 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003653 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3654 AC_VERB_SET_CONNECT_SEL,
3655 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003656 }
3657 }
3658
Mattc7d4b2f2005-06-27 14:59:41 +02003659 return 0;
3660}
3661
Mattc7d4b2f2005-06-27 14:59:41 +02003662static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3663{
3664 struct sigmatel_spec *spec = codec->spec;
3665 int i;
3666
3667 for (i = 0; i < spec->autocfg.line_outs; i++) {
3668 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3669 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3670 }
3671}
3672
3673static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3674{
3675 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003676 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003677
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003678 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3679 hda_nid_t pin;
3680 pin = spec->autocfg.hp_pins[i];
3681 if (pin) /* connect to front */
3682 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3683 }
3684 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3685 hda_nid_t pin;
3686 pin = spec->autocfg.speaker_pins[i];
3687 if (pin) /* connect to front */
3688 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3689 }
Mattc7d4b2f2005-06-27 14:59:41 +02003690}
3691
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003692static int is_dual_headphones(struct hda_codec *codec)
3693{
3694 struct sigmatel_spec *spec = codec->spec;
3695 int i, valid_hps;
3696
3697 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3698 spec->autocfg.hp_outs <= 1)
3699 return 0;
3700 valid_hps = 0;
3701 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3702 hda_nid_t nid = spec->autocfg.hp_pins[i];
3703 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3704 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3705 continue;
3706 valid_hps++;
3707 }
3708 return (valid_hps > 1);
3709}
3710
3711
Matt Porter3cc08dc2006-01-23 15:27:49 +01003712static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
Mattc7d4b2f2005-06-27 14:59:41 +02003713{
3714 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003715 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003716 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003717
Matt Porter8b657272006-10-26 17:12:59 +02003718 if ((err = snd_hda_parse_pin_def_config(codec,
3719 &spec->autocfg,
3720 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003721 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003722 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003723 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003724
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003725 /* If we have no real line-out pin and multiple hp-outs, HPs should
3726 * be set up as multi-channel outputs.
3727 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003728 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003729 /* Copy hp_outs to line_outs, backup line_outs in
3730 * speaker_outs so that the following routines can handle
3731 * HP pins as primary outputs.
3732 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003733 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003734 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3735 sizeof(spec->autocfg.line_out_pins));
3736 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3737 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3738 sizeof(spec->autocfg.hp_pins));
3739 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003740 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3741 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003742 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003743 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003744 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003745 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3746 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003747 u32 caps = query_amp_caps(codec,
3748 spec->autocfg.mono_out_pin, dir);
3749 hda_nid_t conn_list[1];
3750
3751 /* get the mixer node and then the mono mux if it exists */
3752 if (snd_hda_get_connections(codec,
3753 spec->autocfg.mono_out_pin, conn_list, 1) &&
3754 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003755 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003756
3757 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003758 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003759 /* LR swap check, some stac925x have a mux that
3760 * changes the DACs output path instead of the
3761 * mono-mux path.
3762 */
3763 if (wid_type == AC_WID_AUD_SEL &&
3764 !(wcaps & AC_WCAP_LR_SWAP))
3765 spec->mono_nid = conn_list[0];
3766 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003767 if (dir) {
3768 hda_nid_t nid = spec->autocfg.mono_out_pin;
3769
3770 /* most mono outs have a least a mute/unmute switch */
3771 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3772 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3773 "Mono Playback Switch",
3774 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003775 if (err < 0)
3776 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003777 /* check for volume support for the amp */
3778 if ((caps & AC_AMPCAP_NUM_STEPS)
3779 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3780 err = stac92xx_add_control(spec,
3781 STAC_CTL_WIDGET_VOL,
3782 "Mono Playback Volume",
3783 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3784 if (err < 0)
3785 return err;
3786 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003787 }
3788
3789 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3790 AC_PINCTL_OUT_EN);
3791 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003792
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003793 if (!spec->multiout.num_dacs) {
3794 err = stac92xx_auto_fill_dac_nids(codec);
3795 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003796 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003797 err = stac92xx_auto_create_multi_out_ctls(codec,
3798 &spec->autocfg);
3799 if (err < 0)
3800 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003801 }
Mattc7d4b2f2005-06-27 14:59:41 +02003802
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003803 /* setup analog beep controls */
3804 if (spec->anabeep_nid > 0) {
3805 err = stac92xx_auto_create_beep_ctls(codec,
3806 spec->anabeep_nid);
3807 if (err < 0)
3808 return err;
3809 }
3810
3811 /* setup digital beep controls and input device */
3812#ifdef CONFIG_SND_HDA_INPUT_BEEP
3813 if (spec->digbeep_nid > 0) {
3814 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003815 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003816
3817 err = stac92xx_auto_create_beep_ctls(codec, nid);
3818 if (err < 0)
3819 return err;
3820 err = snd_hda_attach_beep_device(codec, nid);
3821 if (err < 0)
3822 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003823 if (codec->beep) {
3824 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01003825 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003826 /* if no beep switch is available, make its own one */
3827 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3828 if (!(caps & AC_AMPCAP_MUTE)) {
3829 err = stac92xx_beep_switch_ctl(codec);
3830 if (err < 0)
3831 return err;
3832 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003833 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003834 }
3835#endif
3836
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003837 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003838 if (err < 0)
3839 return err;
3840
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003841 /* All output parsing done, now restore the swapped hp pins */
3842 if (hp_swap) {
3843 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3844 sizeof(spec->autocfg.hp_pins));
3845 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3846 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3847 spec->autocfg.line_outs = 0;
3848 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003849
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003850 if (stac_check_auto_mic(codec)) {
3851 spec->auto_mic = 1;
3852 /* only one capture for auto-mic */
3853 spec->num_adcs = 1;
3854 spec->num_caps = 1;
3855 spec->num_muxes = 1;
3856 }
3857
Takashi Iwai6479c632009-07-28 18:20:25 +02003858 for (i = 0; i < spec->num_caps; i++) {
3859 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3860 spec->capsws[i], i);
3861 if (err < 0)
3862 return err;
3863 }
3864
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003865 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003866 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003867 return err;
3868
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003869 if (spec->mono_nid > 0) {
3870 err = stac92xx_auto_create_mono_output_ctls(codec);
3871 if (err < 0)
3872 return err;
3873 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003874 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003875 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3876 &spec->autocfg)) < 0)
3877 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003878 if (spec->num_muxes > 0) {
3879 err = stac92xx_auto_create_mux_input_ctls(codec);
3880 if (err < 0)
3881 return err;
3882 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003883 if (spec->num_smuxes > 0) {
3884 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3885 if (err < 0)
3886 return err;
3887 }
Matt Porter8b657272006-10-26 17:12:59 +02003888
Takashi Iwaie3c75962009-01-23 11:57:22 +01003889 err = stac92xx_add_input_source(spec);
3890 if (err < 0)
3891 return err;
3892
Mattc7d4b2f2005-06-27 14:59:41 +02003893 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003894 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003895 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003896
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003897 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003898 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003899 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003900 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003901
Takashi Iwai603c4012008-07-30 15:01:44 +02003902 if (spec->kctls.list)
3903 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003904
3905 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003906 if (!spec->dinput_mux)
3907 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003908 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003909 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003910 return 1;
3911}
3912
Takashi Iwai82bc9552006-03-21 11:24:42 +01003913/* add playback controls for HP output */
3914static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3915 struct auto_pin_cfg *cfg)
3916{
3917 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003918 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003919 unsigned int wid_caps;
3920
3921 if (! pin)
3922 return 0;
3923
3924 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003925 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003926 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003927
3928 return 0;
3929}
3930
Richard Fish160ea0d2006-09-06 13:58:25 +02003931/* add playback controls for LFE output */
3932static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3933 struct auto_pin_cfg *cfg)
3934{
3935 struct sigmatel_spec *spec = codec->spec;
3936 int err;
3937 hda_nid_t lfe_pin = 0x0;
3938 int i;
3939
3940 /*
3941 * search speaker outs and line outs for a mono speaker pin
3942 * with an amp. If one is found, add LFE controls
3943 * for it.
3944 */
3945 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3946 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003947 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003948 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3949 if (wcaps == AC_WCAP_OUT_AMP)
3950 /* found a mono speaker with an amp, must be lfe */
3951 lfe_pin = pin;
3952 }
3953
3954 /* if speaker_outs is 0, then speakers may be in line_outs */
3955 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3956 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3957 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003958 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01003959 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01003960 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003961 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003962 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3963 if (wcaps == AC_WCAP_OUT_AMP)
3964 /* found a mono speaker with an amp,
3965 must be lfe */
3966 lfe_pin = pin;
3967 }
3968 }
3969 }
3970
3971 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003972 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003973 if (err < 0)
3974 return err;
3975 }
3976
3977 return 0;
3978}
3979
Mattc7d4b2f2005-06-27 14:59:41 +02003980static int stac9200_parse_auto_config(struct hda_codec *codec)
3981{
3982 struct sigmatel_spec *spec = codec->spec;
3983 int err;
3984
Kailang Yangdf694da2005-12-05 19:42:22 +01003985 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003986 return err;
3987
3988 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3989 return err;
3990
Takashi Iwai82bc9552006-03-21 11:24:42 +01003991 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3992 return err;
3993
Richard Fish160ea0d2006-09-06 13:58:25 +02003994 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3995 return err;
3996
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003997 if (spec->num_muxes > 0) {
3998 err = stac92xx_auto_create_mux_input_ctls(codec);
3999 if (err < 0)
4000 return err;
4001 }
4002
Takashi Iwaie3c75962009-01-23 11:57:22 +01004003 err = stac92xx_add_input_source(spec);
4004 if (err < 0)
4005 return err;
4006
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004007 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004008 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004009 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004010 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004011
Takashi Iwai603c4012008-07-30 15:01:44 +02004012 if (spec->kctls.list)
4013 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004014
4015 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004016 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004017
4018 return 1;
4019}
4020
Sam Revitch62fe78e2006-05-10 15:09:17 +02004021/*
4022 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4023 * funky external mute control using GPIO pins.
4024 */
4025
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004026static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004027 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004028{
4029 unsigned int gpiostate, gpiomask, gpiodir;
4030
4031 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4032 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004033 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004034
4035 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4036 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004037 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004038
4039 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4040 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004041 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004042
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004043 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004044 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4045
4046 snd_hda_codec_write(codec, codec->afg, 0,
4047 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004048 snd_hda_codec_read(codec, codec->afg, 0,
4049 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004050
4051 msleep(1);
4052
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004053 snd_hda_codec_read(codec, codec->afg, 0,
4054 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004055}
4056
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004057#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +02004058static void stac92xx_free_jack_priv(struct snd_jack *jack)
4059{
4060 struct sigmatel_jack *jacks = jack->private_data;
4061 jacks->nid = 0;
4062 jacks->jack = NULL;
4063}
4064#endif
4065
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004066static int stac92xx_add_jack(struct hda_codec *codec,
4067 hda_nid_t nid, int type)
4068{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004069#ifdef CONFIG_SND_HDA_INPUT_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004070 struct sigmatel_spec *spec = codec->spec;
4071 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01004072 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004073 int connectivity = get_defcfg_connect(def_conf);
4074 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02004075 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004076
4077 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4078 return 0;
4079
4080 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4081 jack = snd_array_new(&spec->jacks);
4082 if (!jack)
4083 return -ENOMEM;
4084 jack->nid = nid;
4085 jack->type = type;
4086
Takashi Iwai86de7412009-07-22 16:02:46 +02004087 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004088 snd_hda_get_jack_type(def_conf),
4089 snd_hda_get_jack_connectivity(def_conf),
4090 snd_hda_get_jack_location(def_conf));
4091
Takashi Iwai95c09092009-04-14 16:15:29 +02004092 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4093 if (err < 0) {
4094 jack->nid = 0;
4095 return err;
4096 }
4097 jack->jack->private_data = jack;
4098 jack->jack->private_free = stac92xx_free_jack_priv;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004099#endif
Takashi Iwai95c09092009-04-14 16:15:29 +02004100 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004101}
4102
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004103static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4104 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004105{
4106 struct sigmatel_event *event;
4107
4108 snd_array_init(&spec->events, sizeof(*event), 32);
4109 event = snd_array_new(&spec->events);
4110 if (!event)
4111 return -ENOMEM;
4112 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004113 event->type = type;
4114 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004115 event->data = data;
4116
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004117 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004118}
4119
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004120static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004121 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004122{
4123 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004124 struct sigmatel_event *event = spec->events.list;
4125 int i;
4126
4127 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004128 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004129 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004130 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004131 return NULL;
4132}
4133
4134static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4135 unsigned char tag)
4136{
4137 struct sigmatel_spec *spec = codec->spec;
4138 struct sigmatel_event *event = spec->events.list;
4139 int i;
4140
4141 for (i = 0; i < spec->events.used; i++, event++) {
4142 if (event->tag == tag)
4143 return event;
4144 }
4145 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004146}
4147
Takashi Iwai62558ce2009-07-29 14:23:09 +02004148/* check if given nid is a valid pin and no other events are assigned
4149 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4150 * Otherwise, returns zero.
4151 */
4152static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4153 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004154{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004155 struct sigmatel_event *event;
4156 int tag;
4157
4158 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004159 return 0;
4160 event = stac_get_event(codec, nid);
4161 if (event) {
4162 if (event->type != type)
4163 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004164 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004165 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004166 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004167 if (tag < 0)
4168 return 0;
4169 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004170 snd_hda_codec_write_cache(codec, nid, 0,
4171 AC_VERB_SET_UNSOLICITED_ENABLE,
4172 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004173 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004174}
4175
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004176static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4177{
4178 int i;
4179 for (i = 0; i < cfg->hp_outs; i++)
4180 if (cfg->hp_pins[i] == nid)
4181 return 1; /* nid is a HP-Out */
4182
4183 return 0; /* nid is not a HP-Out */
4184};
4185
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004186static void stac92xx_power_down(struct hda_codec *codec)
4187{
4188 struct sigmatel_spec *spec = codec->spec;
4189
4190 /* power down inactive DACs */
4191 hda_nid_t *dac;
4192 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004193 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004194 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004195 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4196}
4197
Takashi Iwaif73d3582008-11-25 08:21:51 +01004198static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4199 int enable);
4200
Takashi Iwai014c41f2009-12-27 13:53:24 +01004201static inline int get_int_hint(struct hda_codec *codec, const char *key,
4202 int *valp)
4203{
4204 const char *p;
4205 p = snd_hda_get_hint(codec, key);
4206 if (p) {
4207 unsigned long val;
4208 if (!strict_strtoul(p, 0, &val)) {
4209 *valp = val;
4210 return 1;
4211 }
4212 }
4213 return 0;
4214}
4215
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004216/* override some hints from the hwdep entry */
4217static void stac_store_hints(struct hda_codec *codec)
4218{
4219 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004220 int val;
4221
4222 val = snd_hda_get_bool_hint(codec, "hp_detect");
4223 if (val >= 0)
4224 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004225 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004226 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4227 spec->gpio_mask;
4228 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004229 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4230 spec->gpio_mask &= spec->gpio_mask;
4231 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4232 spec->gpio_dir &= spec->gpio_mask;
4233 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4234 spec->eapd_mask &= spec->gpio_mask;
4235 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4236 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004237 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4238 if (val >= 0)
4239 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004240 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4241 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Takashi Iwai043958e2009-12-26 10:36:12 +01004242 spec->gpio_mask |= spec->gpio_led;
4243 spec->gpio_dir |= spec->gpio_led;
4244 if (spec->gpio_led_polarity)
4245 spec->gpio_data |= spec->gpio_led;
4246 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004247}
4248
Mattc7d4b2f2005-06-27 14:59:41 +02004249static int stac92xx_init(struct hda_codec *codec)
4250{
4251 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004252 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004253 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004254 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004255
Mattc7d4b2f2005-06-27 14:59:41 +02004256 snd_hda_sequence_write(codec, spec->init);
4257
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004258 /* power down adcs initially */
4259 if (spec->powerdown_adcs)
4260 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004261 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004262 spec->adc_nids[i], 0,
4263 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004264
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004265 /* override some hints */
4266 stac_store_hints(codec);
4267
Takashi Iwaif73d3582008-11-25 08:21:51 +01004268 /* set up GPIO */
4269 gpio = spec->gpio_data;
4270 /* turn on EAPD statically when spec->eapd_switch isn't set.
4271 * otherwise, unsol event will turn it on/off dynamically
4272 */
4273 if (!spec->eapd_switch)
4274 gpio |= spec->eapd_mask;
4275 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4276
Takashi Iwai82bc9552006-03-21 11:24:42 +01004277 /* set up pins */
4278 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004279 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004280 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004281 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004282 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004283 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004284 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4285 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004286 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004287 for (i = 0; i < cfg->line_outs; i++) {
4288 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004289 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4290 }
4291 }
4292
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004293 /* force to enable the first line-out; the others are set up
4294 * in unsol_event
4295 */
4296 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004297 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004298 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004299 if (cfg->hp_pins[0])
4300 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4301 else if (cfg->line_out_pins[0])
4302 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004303 } else {
4304 stac92xx_auto_init_multi_out(codec);
4305 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004306 for (i = 0; i < cfg->hp_outs; i++)
4307 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004308 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004309 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004310 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004311 if (spec->dmux_nids)
4312 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004313 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004314 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4315 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004316 if (enable_pin_detect(codec, spec->dock_mic.pin,
4317 STAC_MIC_EVENT))
4318 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004319 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004320 for (i = 0; i < cfg->num_inputs; i++) {
4321 hda_nid_t nid = cfg->inputs[i].pin;
4322 int type = cfg->inputs[i].type;
4323 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004324 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004325 /* for mic pins, force to initialize */
4326 pinctl = stac92xx_get_default_vref(codec, nid);
4327 pinctl |= AC_PINCTL_IN_EN;
4328 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4329 } else {
4330 pinctl = snd_hda_codec_read(codec, nid, 0,
4331 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4332 /* if PINCTL already set then skip */
4333 /* Also, if both INPUT and OUTPUT are set,
4334 * it must be a BIOS bug; need to override, too
4335 */
4336 if (!(pinctl & AC_PINCTL_IN_EN) ||
4337 (pinctl & AC_PINCTL_OUT_EN)) {
4338 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004339 pinctl |= AC_PINCTL_IN_EN;
4340 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004341 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004342 }
4343 conf = snd_hda_codec_get_pincfg(codec, nid);
4344 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4345 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4346 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004347 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004348 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004349 for (i = 0; i < spec->num_dmics; i++)
4350 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4351 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004352 if (cfg->dig_out_pins[0])
4353 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004354 AC_PINCTL_OUT_EN);
4355 if (cfg->dig_in_pin)
4356 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4357 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004358 for (i = 0; i < spec->num_pwrs; i++) {
4359 hda_nid_t nid = spec->pwr_nids[i];
4360 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004361
Takashi Iwaieb632122008-12-19 16:39:48 +01004362 /* power on when no jack detection is available */
4363 if (!spec->hp_detect) {
4364 stac_toggle_power_map(codec, nid, 1);
4365 continue;
4366 }
4367
4368 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004369 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004370
Takashi Iwaif73d3582008-11-25 08:21:51 +01004371 pinctl = snd_hda_codec_read(codec, nid, 0,
4372 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4373 /* outputs are only ports capable of power management
4374 * any attempts on powering down a input port cause the
4375 * referenced VREF to act quirky.
4376 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004377 if (pinctl & AC_PINCTL_IN_EN) {
4378 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004379 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004380 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004381 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004382 def_conf = get_defcfg_connect(def_conf);
4383 /* skip any ports that don't have jacks since presence
4384 * detection is useless */
4385 if (def_conf != AC_JACK_PORT_COMPLEX) {
4386 if (def_conf != AC_JACK_PORT_NONE)
4387 stac_toggle_power_map(codec, nid, 1);
4388 continue;
4389 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004390 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4391 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004392 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004393
Takashi Iwaic21bd022010-02-08 15:16:08 +01004394 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004395 if (spec->gpio_led)
4396 hda_call_check_power_status(codec, 0x01);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004397 if (spec->dac_list)
4398 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004399 return 0;
4400}
4401
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004402static void stac92xx_free_jacks(struct hda_codec *codec)
4403{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004404#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01004405 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004406 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01004407 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004408 struct sigmatel_jack *jacks = spec->jacks.list;
4409 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +02004410 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4411 if (jacks->jack)
4412 snd_device_free(codec->bus->card, jacks->jack);
4413 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004414 }
4415 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004416#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004417}
4418
Takashi Iwai603c4012008-07-30 15:01:44 +02004419static void stac92xx_free_kctls(struct hda_codec *codec)
4420{
4421 struct sigmatel_spec *spec = codec->spec;
4422
4423 if (spec->kctls.list) {
4424 struct snd_kcontrol_new *kctl = spec->kctls.list;
4425 int i;
4426 for (i = 0; i < spec->kctls.used; i++)
4427 kfree(kctl[i].name);
4428 }
4429 snd_array_free(&spec->kctls);
4430}
4431
Takashi Iwai167eae52009-11-06 15:47:50 +01004432static void stac92xx_shutup(struct hda_codec *codec)
4433{
4434 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004435
Takashi Iwai92ee6162009-12-27 11:18:59 +01004436 snd_hda_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004437
4438 if (spec->eapd_mask)
4439 stac_gpio_set(codec, spec->gpio_mask,
4440 spec->gpio_dir, spec->gpio_data &
4441 ~spec->eapd_mask);
4442}
4443
Matt2f2f4252005-04-13 14:45:30 +02004444static void stac92xx_free(struct hda_codec *codec)
4445{
Mattc7d4b2f2005-06-27 14:59:41 +02004446 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004447
4448 if (! spec)
4449 return;
4450
Takashi Iwai167eae52009-11-06 15:47:50 +01004451 stac92xx_shutup(codec);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004452 stac92xx_free_jacks(codec);
4453 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004454
Mattc7d4b2f2005-06-27 14:59:41 +02004455 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004456 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004457}
4458
Matt4e550962005-07-04 17:51:39 +02004459static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4460 unsigned int flag)
4461{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004462 unsigned int old_ctl, pin_ctl;
4463
4464 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004465 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004466
Takashi Iwaif9acba42007-05-29 18:01:06 +02004467 if (pin_ctl & AC_PINCTL_IN_EN) {
4468 /*
4469 * we need to check the current set-up direction of
4470 * shared input pins since they can be switched via
4471 * "xxx as Output" mixer switch
4472 */
4473 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004474 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004475 return;
4476 }
4477
Takashi Iwai8ce84192009-01-22 16:59:20 +01004478 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004479 /* if setting pin direction bits, clear the current
4480 direction bits first */
4481 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4482 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4483
Takashi Iwai8ce84192009-01-22 16:59:20 +01004484 pin_ctl |= flag;
4485 if (old_ctl != pin_ctl)
4486 snd_hda_codec_write_cache(codec, nid, 0,
4487 AC_VERB_SET_PIN_WIDGET_CONTROL,
4488 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004489}
4490
4491static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4492 unsigned int flag)
4493{
4494 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4495 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004496 if (pin_ctl & flag)
4497 snd_hda_codec_write_cache(codec, nid, 0,
4498 AC_VERB_SET_PIN_WIDGET_CONTROL,
4499 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004500}
4501
Takashi Iwaid56757a2009-11-18 08:00:14 +01004502static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004503{
4504 if (!nid)
4505 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004506 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004507}
4508
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004509static void stac92xx_line_out_detect(struct hda_codec *codec,
4510 int presence)
4511{
4512 struct sigmatel_spec *spec = codec->spec;
4513 struct auto_pin_cfg *cfg = &spec->autocfg;
4514 int i;
4515
4516 for (i = 0; i < cfg->line_outs; i++) {
4517 if (presence)
4518 break;
4519 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4520 if (presence) {
4521 unsigned int pinctl;
4522 pinctl = snd_hda_codec_read(codec,
4523 cfg->line_out_pins[i], 0,
4524 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4525 if (pinctl & AC_PINCTL_IN_EN)
4526 presence = 0; /* mic- or line-input */
4527 }
4528 }
4529
4530 if (presence) {
4531 /* disable speakers */
4532 for (i = 0; i < cfg->speaker_outs; i++)
4533 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4534 AC_PINCTL_OUT_EN);
4535 if (spec->eapd_mask && spec->eapd_switch)
4536 stac_gpio_set(codec, spec->gpio_mask,
4537 spec->gpio_dir, spec->gpio_data &
4538 ~spec->eapd_mask);
4539 } else {
4540 /* enable speakers */
4541 for (i = 0; i < cfg->speaker_outs; i++)
4542 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4543 AC_PINCTL_OUT_EN);
4544 if (spec->eapd_mask && spec->eapd_switch)
4545 stac_gpio_set(codec, spec->gpio_mask,
4546 spec->gpio_dir, spec->gpio_data |
4547 spec->eapd_mask);
4548 }
4549}
4550
Takashi Iwaid7a89432008-11-12 09:48:04 +01004551/* return non-zero if the hp-pin of the given array index isn't
4552 * a jack-detection target
4553 */
4554static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4555{
4556 struct auto_pin_cfg *cfg = &spec->autocfg;
4557
4558 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004559 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004560 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004561 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004562 return 1;
4563 /* ignore if the pin is set as line-out */
4564 if (cfg->hp_pins[i] == spec->hp_switch)
4565 return 1;
4566 return 0;
4567}
4568
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004569static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004570{
4571 struct sigmatel_spec *spec = codec->spec;
4572 struct auto_pin_cfg *cfg = &spec->autocfg;
4573 int i, presence;
4574
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004575 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004576 if (spec->gpio_mute)
4577 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4578 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4579
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004580 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004581 if (presence)
4582 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004583 if (no_hp_sensing(spec, i))
4584 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004585 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4586 if (presence) {
4587 unsigned int pinctl;
4588 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4589 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4590 if (pinctl & AC_PINCTL_IN_EN)
4591 presence = 0; /* mic- or line-input */
4592 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004593 }
Matt4e550962005-07-04 17:51:39 +02004594
4595 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004596 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004597 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004598 stac92xx_reset_pinctl(codec, spec->hp_switch,
4599 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004600 for (i = 0; i < cfg->line_outs; i++)
4601 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4602 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004603 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004604 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004605 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004606 stac92xx_set_pinctl(codec, spec->hp_switch,
4607 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004608 for (i = 0; i < cfg->line_outs; i++)
4609 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4610 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004611 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004612 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004613 /* toggle hp outs */
4614 for (i = 0; i < cfg->hp_outs; i++) {
4615 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4616 if (no_hp_sensing(spec, i))
4617 continue;
4618 if (presence)
4619 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004620#if 0 /* FIXME */
4621/* Resetting the pinctl like below may lead to (a sort of) regressions
4622 * on some devices since they use the HP pin actually for line/speaker
4623 * outs although the default pin config shows a different pin (that is
4624 * wrong and useless).
4625 *
4626 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4627 * But, disabling the code below just works around it, and I'm too tired of
4628 * bug reports with such devices...
4629 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004630 else
4631 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004632#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004633 }
Matt4e550962005-07-04 17:51:39 +02004634}
4635
Takashi Iwaif73d3582008-11-25 08:21:51 +01004636static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4637 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004638{
4639 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004640 unsigned int idx, val;
4641
4642 for (idx = 0; idx < spec->num_pwrs; idx++) {
4643 if (spec->pwr_nids[idx] == nid)
4644 break;
4645 }
4646 if (idx >= spec->num_pwrs)
4647 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004648
4649 /* several codecs have two power down bits */
4650 if (spec->pwr_mapping)
4651 idx = spec->pwr_mapping[idx];
4652 else
4653 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004654
Takashi Iwaif73d3582008-11-25 08:21:51 +01004655 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4656 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004657 val &= ~idx;
4658 else
4659 val |= idx;
4660
4661 /* power down unused output ports */
4662 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004663}
4664
Takashi Iwaif73d3582008-11-25 08:21:51 +01004665static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4666{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004667 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004668}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004669
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004670static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4671{
4672 struct sigmatel_spec *spec = codec->spec;
4673 struct sigmatel_jack *jacks = spec->jacks.list;
4674
4675 if (jacks) {
4676 int i;
4677 for (i = 0; i < spec->jacks.used; i++) {
4678 if (jacks->nid == nid) {
4679 unsigned int pin_ctl =
4680 snd_hda_codec_read(codec, nid,
4681 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4682 0x00);
4683 int type = jacks->type;
4684 if (type == (SND_JACK_LINEOUT
4685 | SND_JACK_HEADPHONE))
4686 type = (pin_ctl & AC_PINCTL_HP_EN)
4687 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4688 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004689 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004690 ? type : 0);
4691 }
4692 jacks++;
4693 }
4694 }
4695}
Matt2f2f4252005-04-13 14:45:30 +02004696
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004697/* get the pin connection (fixed, none, etc) */
4698static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4699{
4700 struct sigmatel_spec *spec = codec->spec;
4701 unsigned int cfg;
4702
4703 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4704 return get_defcfg_connect(cfg);
4705}
4706
4707static int stac92xx_connected_ports(struct hda_codec *codec,
4708 hda_nid_t *nids, int num_nids)
4709{
4710 struct sigmatel_spec *spec = codec->spec;
4711 int idx, num;
4712 unsigned int def_conf;
4713
4714 for (num = 0; num < num_nids; num++) {
4715 for (idx = 0; idx < spec->num_pins; idx++)
4716 if (spec->pin_nids[idx] == nids[num])
4717 break;
4718 if (idx >= spec->num_pins)
4719 break;
4720 def_conf = stac_get_defcfg_connect(codec, idx);
4721 if (def_conf == AC_JACK_PORT_NONE)
4722 break;
4723 }
4724 return num;
4725}
4726
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004727static void stac92xx_mic_detect(struct hda_codec *codec)
4728{
4729 struct sigmatel_spec *spec = codec->spec;
4730 struct sigmatel_mic_route *mic;
4731
4732 if (get_pin_presence(codec, spec->ext_mic.pin))
4733 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02004734 else if (get_pin_presence(codec, spec->dock_mic.pin))
4735 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004736 else
4737 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004738 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004739 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4740 AC_VERB_SET_CONNECT_SEL,
4741 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004742 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004743 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4744 AC_VERB_SET_CONNECT_SEL,
4745 mic->mux_idx);
4746}
4747
Takashi Iwai62558ce2009-07-29 14:23:09 +02004748static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004749{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004750 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004751 if (!event)
4752 return;
4753 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4754}
4755
Takashi Iwai314634b2006-09-21 11:56:18 +02004756static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4757{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004758 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004759 struct sigmatel_event *event;
4760 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004761
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004762 tag = (res >> 26) & 0x7f;
4763 event = stac_get_event_from_tag(codec, tag);
4764 if (!event)
4765 return;
4766
4767 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004768 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004769 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004770 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004771 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004772 case STAC_MIC_EVENT:
4773 stac92xx_mic_detect(codec);
4774 break;
4775 }
4776
4777 switch (event->type) {
4778 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004779 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004780 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004781 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004782 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004783 if (spec->num_pwrs > 0)
4784 stac92xx_pin_sense(codec, event->nid);
4785 stac92xx_report_jack(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004786
4787 switch (codec->subsystem_id) {
4788 case 0x103c308f:
4789 if (event->nid == 0xb) {
4790 int pin = AC_PINCTL_IN_EN;
4791
4792 if (get_pin_presence(codec, 0xa)
4793 && get_pin_presence(codec, 0xb))
4794 pin |= AC_PINCTL_VREF_80;
4795 if (!get_pin_presence(codec, 0xb))
4796 pin |= AC_PINCTL_VREF_80;
4797
4798 /* toggle VREF state based on mic + hp pin
4799 * status
4800 */
4801 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4802 }
4803 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004804 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004805 case STAC_VREF_EVENT:
4806 data = snd_hda_codec_read(codec, codec->afg, 0,
4807 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004808 /* toggle VREF state based on GPIOx status */
4809 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004810 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004811 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004812 }
4813}
4814
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304815static int hp_blike_system(u32 subsystem_id);
4816
4817static void set_hp_led_gpio(struct hda_codec *codec)
4818{
4819 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004820 unsigned int gpio;
4821
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004822 if (spec->gpio_led)
4823 return;
4824
Takashi Iwai07f80442010-02-08 15:06:13 +01004825 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4826 gpio &= AC_GPIO_IO_COUNT;
4827 if (gpio > 3)
4828 spec->gpio_led = 0x08; /* GPIO 3 */
4829 else
4830 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304831}
4832
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004833/*
4834 * This method searches for the mute LED GPIO configuration
4835 * provided as OEM string in SMBIOS. The format of that string
4836 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4837 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4838 * that corresponds to the NOT muted state of the master volume
4839 * and G is the index of the GPIO to use as the mute LED control (0..9)
4840 * If _G portion is missing it is assigned based on the codec ID
4841 *
4842 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4843 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304844 *
4845 *
4846 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4847 * SMBIOS - at least the ones I have seen do not have them - which include
4848 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4849 * HP Pavilion dv9500t CTO.
4850 * Need more information on whether it is true across the entire series.
4851 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004852 */
Takashi Iwaidce17d42010-02-09 09:25:26 +01004853static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004854{
4855 struct sigmatel_spec *spec = codec->spec;
4856 const struct dmi_device *dev = NULL;
4857
4858 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4859 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4860 NULL, dev))) {
4861 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304862 &spec->gpio_led_polarity,
4863 &spec->gpio_led) == 2) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004864 spec->gpio_led = 1 << spec->gpio_led;
4865 return 1;
4866 }
4867 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304868 &spec->gpio_led_polarity) == 1) {
4869 set_hp_led_gpio(codec);
4870 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004871 }
4872 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304873
4874 /*
4875 * Fallback case - if we don't find the DMI strings,
4876 * we statically set the GPIO - if not a B-series system.
4877 */
4878 if (!hp_blike_system(codec->subsystem_id)) {
4879 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004880 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304881 return 1;
4882 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004883 }
4884 return 0;
4885}
4886
4887static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004888{
4889 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004890 case 0x103c1520:
4891 case 0x103c1521:
4892 case 0x103c1523:
4893 case 0x103c1524:
4894 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004895 case 0x103c1722:
4896 case 0x103c1723:
4897 case 0x103c1724:
4898 case 0x103c1725:
4899 case 0x103c1726:
4900 case 0x103c1727:
4901 case 0x103c1728:
4902 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004903 case 0x103c172a:
4904 case 0x103c172b:
4905 case 0x103c307e:
4906 case 0x103c307f:
4907 case 0x103c3080:
4908 case 0x103c3081:
4909 case 0x103c7007:
4910 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004911 return 1;
4912 }
4913 return 0;
4914}
4915
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004916#ifdef CONFIG_PROC_FS
4917static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4918 struct hda_codec *codec, hda_nid_t nid)
4919{
4920 if (nid == codec->afg)
4921 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4922 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4923}
4924
4925static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4926 struct hda_codec *codec,
4927 unsigned int verb)
4928{
4929 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4930 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4931}
4932
4933/* stac92hd71bxx, stac92hd73xx */
4934static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4935 struct hda_codec *codec, hda_nid_t nid)
4936{
4937 stac92hd_proc_hook(buffer, codec, nid);
4938 if (nid == codec->afg)
4939 analog_loop_proc_hook(buffer, codec, 0xfa0);
4940}
4941
4942static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4943 struct hda_codec *codec, hda_nid_t nid)
4944{
4945 if (nid == codec->afg)
4946 analog_loop_proc_hook(buffer, codec, 0xfe0);
4947}
4948
4949static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4950 struct hda_codec *codec, hda_nid_t nid)
4951{
4952 if (nid == codec->afg)
4953 analog_loop_proc_hook(buffer, codec, 0xfeb);
4954}
4955#else
4956#define stac92hd_proc_hook NULL
4957#define stac92hd7x_proc_hook NULL
4958#define stac9205_proc_hook NULL
4959#define stac927x_proc_hook NULL
4960#endif
4961
Takashi Iwaicb53c622007-08-10 17:21:45 +02004962#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004963static int stac92xx_resume(struct hda_codec *codec)
4964{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004965 struct sigmatel_spec *spec = codec->spec;
4966
Takashi Iwai2c885872008-11-18 09:36:55 +01004967 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004968 snd_hda_codec_resume_amp(codec);
4969 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004970 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004971 if (spec->hp_detect) {
4972 if (spec->autocfg.hp_pins[0])
4973 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4974 else if (spec->autocfg.line_out_pins[0])
4975 stac_issue_unsol_event(codec,
4976 spec->autocfg.line_out_pins[0]);
4977 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004978 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004979 if (spec->gpio_led)
4980 hda_call_check_power_status(codec, 0x01);
Mattff6fdc32005-06-27 15:06:52 +02004981 return 0;
4982}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004983
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004984/*
James Gardiner514bf542009-05-03 04:00:44 -04004985 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004986 * check for mute state only on Speakers (nid = 0x10)
4987 *
4988 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4989 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004990 *
4991 * Changed name to reflect that it now works for any designated
4992 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004993 */
4994
4995#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004996static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004997 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004998{
4999 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21bd022010-02-08 15:16:08 +01005000 int i, muted = 1;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005001
Takashi Iwaic21bd022010-02-08 15:16:08 +01005002 for (i = 0; i < spec->multiout.num_dacs; i++) {
5003 nid = spec->multiout.dac_nids[i];
5004 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
5005 HDA_AMP_MUTE)) {
5006 muted = 0; /* something heard */
5007 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005008 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01005009 }
5010 if (muted)
5011 spec->gpio_data &= ~spec->gpio_led; /* orange */
5012 else
5013 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005014
Takashi Iwaic21bd022010-02-08 15:16:08 +01005015 if (!spec->gpio_led_polarity) {
5016 /* LED state is inverted on these systems */
5017 spec->gpio_data ^= spec->gpio_led;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005018 }
5019
Takashi Iwaib4e81872009-11-18 17:20:24 +01005020 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
Takashi Iwaib4e81872009-11-18 17:20:24 +01005021 return 0;
5022}
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005023#endif
5024
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005025static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
5026{
Takashi Iwai167eae52009-11-06 15:47:50 +01005027 stac92xx_shutup(codec);
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005028 return 0;
5029}
Mattff6fdc32005-06-27 15:06:52 +02005030#endif
5031
Matt2f2f4252005-04-13 14:45:30 +02005032static struct hda_codec_ops stac92xx_patch_ops = {
5033 .build_controls = stac92xx_build_controls,
5034 .build_pcms = stac92xx_build_pcms,
5035 .init = stac92xx_init,
5036 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02005037 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02005038#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005039 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005040 .resume = stac92xx_resume,
5041#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005042 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005043};
5044
5045static int patch_stac9200(struct hda_codec *codec)
5046{
5047 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005048 int err;
Matt2f2f4252005-04-13 14:45:30 +02005049
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005050 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005051 if (spec == NULL)
5052 return -ENOMEM;
5053
Takashi Iwaia252c812009-12-25 22:56:20 +01005054 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005055 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005056 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005057 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005058 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005059 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5060 stac9200_models,
5061 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005062 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005063 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5064 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005065 else
5066 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005067 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005068
5069 spec->multiout.max_channels = 2;
5070 spec->multiout.num_dacs = 1;
5071 spec->multiout.dac_nids = stac9200_dac_nids;
5072 spec->adc_nids = stac9200_adc_nids;
5073 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005074 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005075 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005076 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005077 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005078
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005079 if (spec->board_config == STAC_9200_M4 ||
5080 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005081 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005082 spec->init = stac9200_eapd_init;
5083 else
5084 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005085 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005086
Takashi Iwai117f2572008-03-18 09:53:23 +01005087 if (spec->board_config == STAC_9200_PANASONIC) {
5088 spec->gpio_mask = spec->gpio_dir = 0x09;
5089 spec->gpio_data = 0x00;
5090 }
5091
Mattc7d4b2f2005-06-27 14:59:41 +02005092 err = stac9200_parse_auto_config(codec);
5093 if (err < 0) {
5094 stac92xx_free(codec);
5095 return err;
5096 }
Matt2f2f4252005-04-13 14:45:30 +02005097
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005098 /* CF-74 has no headphone detection, and the driver should *NOT*
5099 * do detection and HP/speaker toggle because the hardware does it.
5100 */
5101 if (spec->board_config == STAC_9200_PANASONIC)
5102 spec->hp_detect = 0;
5103
Matt2f2f4252005-04-13 14:45:30 +02005104 codec->patch_ops = stac92xx_patch_ops;
5105
5106 return 0;
5107}
5108
Tobin Davis8e21c342007-01-08 11:04:17 +01005109static int patch_stac925x(struct hda_codec *codec)
5110{
5111 struct sigmatel_spec *spec;
5112 int err;
5113
5114 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5115 if (spec == NULL)
5116 return -ENOMEM;
5117
Takashi Iwaia252c812009-12-25 22:56:20 +01005118 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005119 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005120 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005121 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005122 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005123
5124 /* Check first for codec ID */
5125 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5126 STAC_925x_MODELS,
5127 stac925x_models,
5128 stac925x_codec_id_cfg_tbl);
5129
5130 /* Now checks for PCI ID, if codec ID is not found */
5131 if (spec->board_config < 0)
5132 spec->board_config = snd_hda_check_board_config(codec,
5133 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005134 stac925x_models,
5135 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005136 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005137 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005138 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5139 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005140 else
5141 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005142 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005143
5144 spec->multiout.max_channels = 2;
5145 spec->multiout.num_dacs = 1;
5146 spec->multiout.dac_nids = stac925x_dac_nids;
5147 spec->adc_nids = stac925x_adc_nids;
5148 spec->mux_nids = stac925x_mux_nids;
5149 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005150 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005151 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005152 switch (codec->vendor_id) {
5153 case 0x83847632: /* STAC9202 */
5154 case 0x83847633: /* STAC9202D */
5155 case 0x83847636: /* STAC9251 */
5156 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005157 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005158 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005159 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5160 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005161 break;
5162 default:
5163 spec->num_dmics = 0;
5164 break;
5165 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005166
5167 spec->init = stac925x_core_init;
5168 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005169 spec->num_caps = 1;
5170 spec->capvols = stac925x_capvols;
5171 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005172
5173 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005174 if (!err) {
5175 if (spec->board_config < 0) {
5176 printk(KERN_WARNING "hda_codec: No auto-config is "
5177 "available, default to model=ref\n");
5178 spec->board_config = STAC_925x_REF;
5179 goto again;
5180 }
5181 err = -EINVAL;
5182 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005183 if (err < 0) {
5184 stac92xx_free(codec);
5185 return err;
5186 }
5187
5188 codec->patch_ops = stac92xx_patch_ops;
5189
5190 return 0;
5191}
5192
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005193static int patch_stac92hd73xx(struct hda_codec *codec)
5194{
5195 struct sigmatel_spec *spec;
5196 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5197 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005198 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005199
5200 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5201 if (spec == NULL)
5202 return -ENOMEM;
5203
Takashi Iwaia252c812009-12-25 22:56:20 +01005204 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005205 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005206 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005207 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005208 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5209 spec->pin_nids = stac92hd73xx_pin_nids;
5210 spec->board_config = snd_hda_check_board_config(codec,
5211 STAC_92HD73XX_MODELS,
5212 stac92hd73xx_models,
5213 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005214 /* check codec subsystem id if not found */
5215 if (spec->board_config < 0)
5216 spec->board_config =
5217 snd_hda_check_board_codec_sid_config(codec,
5218 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5219 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005220again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005221 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005222 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5223 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005224 else
5225 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005226 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005227
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005228 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005229 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5230
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005231 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005232 printk(KERN_WARNING "hda_codec: Could not determine "
5233 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005234 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005235 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005236 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005237 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005238 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005239 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005240 break;
5241 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005242 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005243 break;
5244 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005245 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5246 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005247 }
5248 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005249
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005250 spec->aloopback_mask = 0x01;
5251 spec->aloopback_shift = 8;
5252
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005253 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005254 spec->mux_nids = stac92hd73xx_mux_nids;
5255 spec->adc_nids = stac92hd73xx_adc_nids;
5256 spec->dmic_nids = stac92hd73xx_dmic_nids;
5257 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005258 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005259
5260 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5261 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005262 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005263
Takashi Iwai6479c632009-07-28 18:20:25 +02005264 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5265 spec->capvols = stac92hd73xx_capvols;
5266 spec->capsws = stac92hd73xx_capsws;
5267
Matthew Ranostaya7662642008-02-21 07:51:14 +01005268 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005269 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005270 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005271 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005272 case STAC_DELL_M6_AMIC:
5273 case STAC_DELL_M6_DMIC:
5274 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005275 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005276 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005277
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005278 switch (spec->board_config) {
5279 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005280 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005281 spec->num_dmics = 0;
5282 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005283 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005284 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005285 spec->num_dmics = 1;
5286 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005287 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005288 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5289 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005290 spec->num_dmics = 1;
5291 break;
5292 }
5293 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005294 case STAC_ALIENWARE_M17X:
5295 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5296 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5297 spec->eapd_switch = 0;
5298 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005299 default:
5300 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005301 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005302 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005303 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005304 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005305 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005306 /* GPIO0 High = Enable EAPD */
5307 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5308 spec->gpio_data = 0x01;
5309 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005310
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005311 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5312 spec->pwr_nids = stac92hd73xx_pwr_nids;
5313
Matthew Ranostayd9737752008-09-07 12:03:41 +02005314 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005315
5316 if (!err) {
5317 if (spec->board_config < 0) {
5318 printk(KERN_WARNING "hda_codec: No auto-config is "
5319 "available, default to model=ref\n");
5320 spec->board_config = STAC_92HD73XX_REF;
5321 goto again;
5322 }
5323 err = -EINVAL;
5324 }
5325
5326 if (err < 0) {
5327 stac92xx_free(codec);
5328 return err;
5329 }
5330
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005331 if (spec->board_config == STAC_92HD73XX_NO_JD)
5332 spec->hp_detect = 0;
5333
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005334 codec->patch_ops = stac92xx_patch_ops;
5335
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005336 codec->proc_widget_hook = stac92hd7x_proc_hook;
5337
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005338 return 0;
5339}
5340
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005341static int hp_bnb2011_with_dock(struct hda_codec *codec)
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005342{
5343 if (codec->vendor_id != 0x111d7605 &&
5344 codec->vendor_id != 0x111d76d1)
5345 return 0;
5346
5347 switch (codec->subsystem_id) {
5348 case 0x103c1618:
5349 case 0x103c1619:
5350 case 0x103c161a:
5351 case 0x103c161b:
5352 case 0x103c161c:
5353 case 0x103c161d:
5354 case 0x103c161e:
5355 case 0x103c161f:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005356
5357 case 0x103c162a:
5358 case 0x103c162b:
5359
5360 case 0x103c1630:
5361 case 0x103c1631:
5362
5363 case 0x103c1633:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005364 case 0x103c1634:
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005365 case 0x103c1635:
5366
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005367 case 0x103c3587:
5368 case 0x103c3588:
5369 case 0x103c3589:
5370 case 0x103c358a:
5371
5372 case 0x103c3667:
5373 case 0x103c3668:
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005374 case 0x103c3669:
5375
5376 return 1;
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005377 }
5378 return 0;
5379}
5380
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005381static int patch_stac92hd83xxx(struct hda_codec *codec)
5382{
5383 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005384 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005385 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005386 int num_dacs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005387
5388 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5389 if (spec == NULL)
5390 return -ENOMEM;
5391
Vitaliy Kulikovcbbf50b2011-01-14 17:21:13 -06005392 if (hp_bnb2011_with_dock(codec)) {
5393 snd_hda_codec_set_pincfg(codec, 0xa, 0x2101201f);
5394 snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5395 }
5396
Charles1cc9e8f2010-10-18 16:22:00 +08005397 /* reset pin power-down; Windows may leave these bits after reboot */
5398 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7EC, 0);
5399 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7ED, 0);
Takashi Iwaia252c812009-12-25 22:56:20 +01005400 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005401 codec->spec = spec;
Takashi Iwai1db7ccdb2010-12-03 15:19:14 +01005402 spec->linear_tone_beep = 0;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005403 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005404 spec->digbeep_nid = 0x21;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005405 spec->dmic_nids = stac92hd83xxx_dmic_nids;
5406 spec->dmux_nids = stac92hd83xxx_mux_nids;
Takashi Iwai667067d2009-08-13 18:14:42 +02005407 spec->mux_nids = stac92hd83xxx_mux_nids;
5408 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005409 spec->adc_nids = stac92hd83xxx_adc_nids;
Takashi Iwai7570ef12009-08-15 11:57:53 +02005410 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005411 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5412 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5413 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005414 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005415
5416 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005417 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005418 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005419 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5420 spec->capvols = stac92hd83xxx_capvols;
5421 spec->capsws = stac92hd83xxx_capsws;
5422
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005423 spec->board_config = snd_hda_check_board_config(codec,
5424 STAC_92HD83XXX_MODELS,
5425 stac92hd83xxx_models,
5426 stac92hd83xxx_cfg_tbl);
5427again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005428 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005429 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5430 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005431 else
5432 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005433 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005434
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005435 switch (codec->vendor_id) {
David Henningsson89feca12010-10-13 15:48:24 +02005436 case 0x111d76d1:
5437 case 0x111d76d9:
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06005438 case 0x111d76e5:
David Henningsson89feca12010-10-13 15:48:24 +02005439 spec->dmic_nids = stac92hd87b_dmic_nids;
5440 spec->num_dmics = stac92xx_connected_ports(codec,
5441 stac92hd87b_dmic_nids,
5442 STAC92HD87B_NUM_DMICS);
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06005443 spec->num_pins = ARRAY_SIZE(stac92hd87xxx_pin_nids);
5444 spec->pin_nids = stac92hd87xxx_pin_nids;
David Henningssonbdfe6f42011-01-04 06:30:53 +01005445 spec->mono_nid = 0;
5446 spec->num_pwrs = 0;
5447 break;
Charles Chin36706002010-01-29 12:05:51 +01005448 case 0x111d7666:
5449 case 0x111d7667:
5450 case 0x111d7668:
5451 case 0x111d7669:
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06005452 case 0x111d76e3:
David Henningssonbdfe6f42011-01-04 06:30:53 +01005453 spec->num_dmics = stac92xx_connected_ports(codec,
5454 stac92hd88xxx_dmic_nids,
5455 STAC92HD88XXX_NUM_DMICS);
Charles Chin36706002010-01-29 12:05:51 +01005456 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5457 spec->pin_nids = stac92hd88xxx_pin_nids;
5458 spec->mono_nid = 0;
Charles Chin36706002010-01-29 12:05:51 +01005459 spec->num_pwrs = 0;
5460 break;
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005461 case 0x111d7604:
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01005462 case 0x111d76d4:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005463 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005464 case 0x111d76d5:
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005465 case 0x111d76e7:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005466 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5467 break;
5468 spec->num_pwrs = 0;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005469 spec->num_dmics = stac92xx_connected_ports(codec,
5470 stac92hd83xxx_dmic_nids,
5471 STAC92HD83XXX_NUM_DMICS);
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005472 break;
5473 }
5474
Takashi Iwaib4e81872009-11-18 17:20:24 +01005475 codec->patch_ops = stac92xx_patch_ops;
5476
Takashi Iwaidce17d42010-02-09 09:25:26 +01005477 if (find_mute_led_gpio(codec, 0))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005478 snd_printd("mute LED gpio %d polarity %d\n",
5479 spec->gpio_led,
5480 spec->gpio_led_polarity);
5481
Takashi Iwaib4e81872009-11-18 17:20:24 +01005482#ifdef CONFIG_SND_HDA_POWER_SAVE
5483 if (spec->gpio_led) {
5484 spec->gpio_mask |= spec->gpio_led;
5485 spec->gpio_dir |= spec->gpio_led;
5486 spec->gpio_data |= spec->gpio_led;
5487 /* register check_power_status callback. */
5488 codec->patch_ops.check_power_status =
Takashi Iwaic21bd022010-02-08 15:16:08 +01005489 stac92xx_hp_check_power_status;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005490 }
5491#endif
5492
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005493 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5494 if (!err) {
5495 if (spec->board_config < 0) {
5496 printk(KERN_WARNING "hda_codec: No auto-config is "
5497 "available, default to model=ref\n");
5498 spec->board_config = STAC_92HD83XXX_REF;
5499 goto again;
5500 }
5501 err = -EINVAL;
5502 }
5503
5504 if (err < 0) {
5505 stac92xx_free(codec);
5506 return err;
5507 }
5508
Charles Chin04b5efe2010-02-04 10:28:02 +01005509 /* docking output support */
5510 num_dacs = snd_hda_get_connections(codec, 0xF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005511 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Charles Chin04b5efe2010-02-04 10:28:02 +01005512 /* skip non-DAC connections */
5513 while (num_dacs >= 0 &&
5514 (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5515 != AC_WID_AUD_OUT))
5516 num_dacs--;
5517 /* set port E and F to select the last DAC */
5518 if (num_dacs >= 0) {
5519 snd_hda_codec_write_cache(codec, 0xE, 0,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005520 AC_VERB_SET_CONNECT_SEL, num_dacs);
Charles Chin04b5efe2010-02-04 10:28:02 +01005521 snd_hda_codec_write_cache(codec, 0xF, 0,
5522 AC_VERB_SET_CONNECT_SEL, num_dacs);
5523 }
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005524
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005525 codec->proc_widget_hook = stac92hd_proc_hook;
5526
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005527 return 0;
5528}
5529
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005530static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5531 hda_nid_t dig0pin)
5532{
5533 struct sigmatel_spec *spec = codec->spec;
5534 int idx;
5535
5536 for (idx = 0; idx < spec->num_pins; idx++)
5537 if (spec->pin_nids[idx] == dig0pin)
5538 break;
5539 if ((idx + 2) >= spec->num_pins)
5540 return 0;
5541
5542 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005543 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005544 return 2;
5545
5546 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005547 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005548 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005549 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005550 return 1;
5551 else
5552 return 0;
5553}
5554
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005555/* HP dv7 bass switch - GPIO5 */
5556#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5557static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5558 struct snd_ctl_elem_value *ucontrol)
5559{
5560 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5561 struct sigmatel_spec *spec = codec->spec;
5562 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5563 return 0;
5564}
5565
5566static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5567 struct snd_ctl_elem_value *ucontrol)
5568{
5569 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5570 struct sigmatel_spec *spec = codec->spec;
5571 unsigned int gpio_data;
5572
5573 gpio_data = (spec->gpio_data & ~0x20) |
5574 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5575 if (gpio_data == spec->gpio_data)
5576 return 0;
5577 spec->gpio_data = gpio_data;
5578 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5579 return 1;
5580}
5581
5582static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5583 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5584 .info = stac_hp_bass_gpio_info,
5585 .get = stac_hp_bass_gpio_get,
5586 .put = stac_hp_bass_gpio_put,
5587};
5588
5589static int stac_add_hp_bass_switch(struct hda_codec *codec)
5590{
5591 struct sigmatel_spec *spec = codec->spec;
5592
5593 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5594 "Bass Speaker Playback Switch", 0))
5595 return -ENOMEM;
5596
5597 spec->gpio_mask |= 0x20;
5598 spec->gpio_dir |= 0x20;
5599 spec->gpio_data |= 0x20;
5600 return 0;
5601}
5602
Matthew Ranostaye035b842007-11-06 11:53:55 +01005603static int patch_stac92hd71bxx(struct hda_codec *codec)
5604{
5605 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005606 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005607 unsigned int pin_cfg;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005608 int err = 0;
5609
5610 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5611 if (spec == NULL)
5612 return -ENOMEM;
5613
Takashi Iwaia252c812009-12-25 22:56:20 +01005614 codec->no_trigger_sense = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005615 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005616 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005617 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005618 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5619 switch (codec->vendor_id) {
5620 case 0x111d76b6:
5621 case 0x111d76b7:
5622 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5623 break;
5624 case 0x111d7603:
5625 case 0x111d7608:
5626 /* On 92HD75Bx 0x27 isn't a pin nid */
5627 spec->num_pins--;
5628 /* fallthrough */
5629 default:
5630 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5631 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005632 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005633 spec->board_config = snd_hda_check_board_config(codec,
5634 STAC_92HD71BXX_MODELS,
5635 stac92hd71bxx_models,
5636 stac92hd71bxx_cfg_tbl);
5637again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005638 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005639 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5640 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005641 else
5642 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005643 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005644
Takashi Iwaifc64b262009-09-14 15:33:01 +02005645 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005646 /* GPIO0 = EAPD */
5647 spec->gpio_mask = 0x01;
5648 spec->gpio_dir = 0x01;
5649 spec->gpio_data = 0x01;
5650 }
5651
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005652 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5653 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5654
Takashi Iwai6479c632009-07-28 18:20:25 +02005655 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5656 spec->capvols = stac92hd71bxx_capvols;
5657 spec->capsws = stac92hd71bxx_capsws;
5658
Matthew Ranostay541eee82007-12-14 12:08:04 +01005659 switch (codec->vendor_id) {
5660 case 0x111d76b6: /* 4 Port without Analog Mixer */
5661 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005662 unmute_init++;
5663 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005664 case 0x111d76b4: /* 6 Port without Analog Mixer */
5665 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005666 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005667 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005668 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005669 stac92hd71bxx_dmic_nids,
5670 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005671 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005672 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005673 switch (spec->board_config) {
5674 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005675 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005676 err = stac_add_event(spec, codec->afg,
5677 STAC_VREF_EVENT, 0x02);
5678 if (err < 0)
5679 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005680 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005681 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5682 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005683 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005684 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005685 spec->gpio_mask |= 0x02;
5686 break;
5687 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005688 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005689 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005690 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005691
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005692 /* no output amps */
5693 spec->num_pwrs = 0;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005694 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005695 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005696 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005697 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5698 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005699 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005700 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005701 stac92hd71bxx_dmic_nids,
5702 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005703 break;
5704 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005705 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005706 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005707
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005708 /* no output amps */
5709 spec->num_pwrs = 0;
5710 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005711 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005712 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005713 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005714 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005715 stac92hd71bxx_dmic_nids,
5716 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005717 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005718 }
5719
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005720 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5721 snd_hda_sequence_write_cache(codec, unmute_init);
5722
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005723 /* Some HP machines seem to have unstable codec communications
5724 * especially with ATI fglrx driver. For recovering from the
5725 * CORB/RIRB stall, allow the BUS reset and keep always sync
5726 */
5727 if (spec->board_config == STAC_HP_DV5) {
5728 codec->bus->sync_write = 1;
5729 codec->bus->allow_bus_reset = 1;
5730 }
5731
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005732 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005733 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005734 spec->aloopback_shift = 0;
5735
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005736 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005737 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005738 spec->mux_nids = stac92hd71bxx_mux_nids;
5739 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005740 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005741 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005742
5743 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5744 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005745 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005746 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005747
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305748 snd_printdd("Found board config: %d\n", spec->board_config);
5749
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005750 switch (spec->board_config) {
5751 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005752 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005753 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005754 stac92xx_auto_set_pinctl(codec, 0x0e,
5755 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005756 /* fallthru */
5757 case STAC_DELL_M4_2:
5758 spec->num_dmics = 0;
5759 spec->num_smuxes = 0;
5760 spec->num_dmuxes = 0;
5761 break;
5762 case STAC_DELL_M4_1:
5763 case STAC_DELL_M4_3:
5764 spec->num_dmics = 1;
5765 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005766 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005767 break;
James Gardiner514bf542009-05-03 04:00:44 -04005768 case STAC_HP_DV4_1222NR:
5769 spec->num_dmics = 1;
5770 /* I don't know if it needs 1 or 2 smuxes - will wait for
5771 * bug reports to fix if needed
5772 */
5773 spec->num_smuxes = 1;
5774 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005775 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005776 case STAC_HP_DV4:
5777 spec->gpio_led = 0x01;
5778 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005779 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005780 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005781 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005782 /* HP dv6 gives the headphone pin as a line-out. Thus we
5783 * need to set hp_detect flag here to force to enable HP
5784 * detection.
5785 */
5786 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005787 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005788 case STAC_HP_HDX:
5789 spec->num_dmics = 1;
5790 spec->num_dmuxes = 1;
5791 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005792 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005793 break;
5794 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005795
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005796 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005797 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5798 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5799 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5800 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5801 /* It was changed in the BIOS to just satisfy MS DTM.
5802 * Lets turn it back into slaved HP
5803 */
5804 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5805 | (AC_JACK_HP_OUT <<
5806 AC_DEFCFG_DEVICE_SHIFT);
5807 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5808 | AC_DEFCFG_SEQUENCE)))
5809 | 0x1f;
5810 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5811 }
5812 }
5813
Takashi Iwaidce17d42010-02-09 09:25:26 +01005814 if (find_mute_led_gpio(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005815 snd_printd("mute LED gpio %d polarity %d\n",
5816 spec->gpio_led,
5817 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005818
Takashi Iwai86d190e2009-05-26 15:18:58 +02005819#ifdef CONFIG_SND_HDA_POWER_SAVE
5820 if (spec->gpio_led) {
5821 spec->gpio_mask |= spec->gpio_led;
5822 spec->gpio_dir |= spec->gpio_led;
5823 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005824 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005825 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005826 stac92xx_hp_check_power_status;
5827 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005828#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005829
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005830 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005831
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005832 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005833 if (!err) {
5834 if (spec->board_config < 0) {
5835 printk(KERN_WARNING "hda_codec: No auto-config is "
5836 "available, default to model=ref\n");
5837 spec->board_config = STAC_92HD71BXX_REF;
5838 goto again;
5839 }
5840 err = -EINVAL;
5841 }
5842
5843 if (err < 0) {
5844 stac92xx_free(codec);
5845 return err;
5846 }
5847
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005848 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005849 if (spec->board_config == STAC_HP_DV4 ||
5850 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005851 unsigned int cap;
5852 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5853 cap &= AC_GPIO_IO_COUNT;
5854 if (cap >= 6)
5855 stac_add_hp_bass_switch(codec);
5856 }
5857
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005858 codec->proc_widget_hook = stac92hd7x_proc_hook;
5859
Matthew Ranostaye035b842007-11-06 11:53:55 +01005860 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005861}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005862
Matt2f2f4252005-04-13 14:45:30 +02005863static int patch_stac922x(struct hda_codec *codec)
5864{
5865 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005866 int err;
Matt2f2f4252005-04-13 14:45:30 +02005867
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005868 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005869 if (spec == NULL)
5870 return -ENOMEM;
5871
Takashi Iwaia252c812009-12-25 22:56:20 +01005872 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005873 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005874 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005875 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005876 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005877 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5878 stac922x_models,
5879 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005880 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005881 spec->gpio_mask = spec->gpio_dir = 0x03;
5882 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005883 /* Intel Macs have all same PCI SSID, so we need to check
5884 * codec SSID to distinguish the exact models
5885 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005886 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005887 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005888
5889 case 0x106b0800:
5890 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005891 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005892 case 0x106b0600:
5893 case 0x106b0700:
5894 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005895 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005896 case 0x106b0e00:
5897 case 0x106b0f00:
5898 case 0x106b1600:
5899 case 0x106b1700:
5900 case 0x106b0200:
5901 case 0x106b1e00:
5902 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005903 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005904 case 0x106b1a00:
5905 case 0x00000100:
5906 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005907 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005908 case 0x106b0a00:
5909 case 0x106b2200:
5910 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005911 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005912 default:
5913 spec->board_config = STAC_INTEL_MAC_V3;
5914 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005915 }
5916 }
5917
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005918 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005919 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005920 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5921 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005922 else
5923 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005924 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005925
Matt2f2f4252005-04-13 14:45:30 +02005926 spec->adc_nids = stac922x_adc_nids;
5927 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005928 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005929 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005930 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005931 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005932
5933 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005934
5935 spec->num_caps = STAC922X_NUM_CAPS;
5936 spec->capvols = stac922x_capvols;
5937 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005938
5939 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005940
Matt Porter3cc08dc2006-01-23 15:27:49 +01005941 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005942 if (!err) {
5943 if (spec->board_config < 0) {
5944 printk(KERN_WARNING "hda_codec: No auto-config is "
5945 "available, default to model=ref\n");
5946 spec->board_config = STAC_D945_REF;
5947 goto again;
5948 }
5949 err = -EINVAL;
5950 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005951 if (err < 0) {
5952 stac92xx_free(codec);
5953 return err;
5954 }
5955
5956 codec->patch_ops = stac92xx_patch_ops;
5957
Takashi Iwai807a46362007-05-29 19:01:37 +02005958 /* Fix Mux capture level; max to 2 */
5959 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5960 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5961 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5962 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5963 (0 << AC_AMPCAP_MUTE_SHIFT));
5964
Matt Porter3cc08dc2006-01-23 15:27:49 +01005965 return 0;
5966}
5967
5968static int patch_stac927x(struct hda_codec *codec)
5969{
5970 struct sigmatel_spec *spec;
5971 int err;
5972
5973 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5974 if (spec == NULL)
5975 return -ENOMEM;
5976
Takashi Iwaia252c812009-12-25 22:56:20 +01005977 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005978 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005979 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005980 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005981 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005982 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005983 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5984 stac927x_models,
5985 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005986 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005987 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005988 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5989 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005990 else
5991 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005992 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005993
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005994 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005995 spec->adc_nids = stac927x_adc_nids;
5996 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5997 spec->mux_nids = stac927x_mux_nids;
5998 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005999 spec->smux_nids = stac927x_smux_nids;
6000 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04006001 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01006002 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006003 spec->multiout.dac_nids = spec->dac_nids;
6004
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006005 if (spec->board_config != STAC_D965_REF) {
6006 /* GPIO0 High = Enable EAPD */
6007 spec->eapd_mask = spec->gpio_mask = 0x01;
6008 spec->gpio_dir = spec->gpio_data = 0x01;
6009 }
6010
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006011 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02006012 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006013 case STAC_D965_5ST:
6014 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006015 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02006016 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006017 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006018 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006019 switch (codec->subsystem_id) {
6020 case 0x10280209:
6021 case 0x1028022e:
6022 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006023 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006024 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006025 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01006026 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01006027 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01006028 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006029 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006030 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01006031 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006032 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006033 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006034 if (codec->subsystem_id != 0x1028022f) {
6035 /* GPIO2 High = Enable EAPD */
6036 spec->eapd_mask = spec->gpio_mask = 0x04;
6037 spec->gpio_dir = spec->gpio_data = 0x04;
6038 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006039 spec->dmic_nids = stac927x_dmic_nids;
6040 spec->num_dmics = STAC927X_NUM_DMICS;
6041
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02006042 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006043 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006044 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006045 break;
Takashi Iwai54930532009-10-11 17:38:29 +02006046 case STAC_927X_VOLKNOB:
6047 spec->num_dmics = 0;
6048 spec->init = stac927x_volknob_core_init;
6049 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006050 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006051 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006052 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006053 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006054 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006055
Takashi Iwai6479c632009-07-28 18:20:25 +02006056 spec->num_caps = STAC927X_NUM_CAPS;
6057 spec->capvols = stac927x_capvols;
6058 spec->capsws = stac927x_capsws;
6059
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006060 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006061 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006062 spec->aloopback_mask = 0x40;
6063 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05006064 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006065
Matt Porter3cc08dc2006-01-23 15:27:49 +01006066 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006067 if (!err) {
6068 if (spec->board_config < 0) {
6069 printk(KERN_WARNING "hda_codec: No auto-config is "
6070 "available, default to model=ref\n");
6071 spec->board_config = STAC_D965_REF;
6072 goto again;
6073 }
6074 err = -EINVAL;
6075 }
Mattc7d4b2f2005-06-27 14:59:41 +02006076 if (err < 0) {
6077 stac92xx_free(codec);
6078 return err;
6079 }
Matt2f2f4252005-04-13 14:45:30 +02006080
6081 codec->patch_ops = stac92xx_patch_ops;
6082
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006083 codec->proc_widget_hook = stac927x_proc_hook;
6084
Takashi Iwai52987652008-01-16 16:09:47 +01006085 /*
6086 * !!FIXME!!
6087 * The STAC927x seem to require fairly long delays for certain
6088 * command sequences. With too short delays (even if the answer
6089 * is set to RIRB properly), it results in the silence output
6090 * on some hardwares like Dell.
6091 *
6092 * The below flag enables the longer delay (see get_response
6093 * in hda_intel.c).
6094 */
6095 codec->bus->needs_damn_long_delay = 1;
6096
Takashi Iwaie28d8322008-12-17 13:48:29 +01006097 /* no jack detecion for ref-no-jd model */
6098 if (spec->board_config == STAC_D965_REF_NO_JD)
6099 spec->hp_detect = 0;
6100
Matt2f2f4252005-04-13 14:45:30 +02006101 return 0;
6102}
6103
Matt Porterf3302a52006-07-31 12:49:34 +02006104static int patch_stac9205(struct hda_codec *codec)
6105{
6106 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006107 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006108
6109 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6110 if (spec == NULL)
6111 return -ENOMEM;
6112
Takashi Iwaia252c812009-12-25 22:56:20 +01006113 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006114 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006115 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006116 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006117 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006118 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6119 stac9205_models,
6120 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006121 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006122 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006123 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6124 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006125 else
6126 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006127 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006128
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006129 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006130 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006131 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006132 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006133 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006134 spec->smux_nids = stac9205_smux_nids;
6135 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006136 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006137 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006138 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006139 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006140 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006141
6142 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006143 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006144
Takashi Iwai6479c632009-07-28 18:20:25 +02006145 spec->num_caps = STAC9205_NUM_CAPS;
6146 spec->capvols = stac9205_capvols;
6147 spec->capsws = stac9205_capsws;
6148
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006149 spec->aloopback_mask = 0x40;
6150 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006151 /* Turn on/off EAPD per HP plugging */
6152 if (spec->board_config != STAC_9205_EAPD)
6153 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006154 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006155
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006156 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006157 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006158 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006159 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6160 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006161
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006162 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006163 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6164 if (err < 0)
6165 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006166 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006167 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6168 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006169 AC_VERB_SET_UNSOLICITED_ENABLE,
6170 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006171
6172 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006173 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006174 spec->gpio_mask = 0x1b;
6175 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006176 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006177 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006178 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006179 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006180 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006181 case STAC_9205_REF:
6182 /* SPDIF-In enabled */
6183 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006184 default:
6185 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006186 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006187 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006188 break;
6189 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006190
Matt Porterf3302a52006-07-31 12:49:34 +02006191 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006192 if (!err) {
6193 if (spec->board_config < 0) {
6194 printk(KERN_WARNING "hda_codec: No auto-config is "
6195 "available, default to model=ref\n");
6196 spec->board_config = STAC_9205_REF;
6197 goto again;
6198 }
6199 err = -EINVAL;
6200 }
Matt Porterf3302a52006-07-31 12:49:34 +02006201 if (err < 0) {
6202 stac92xx_free(codec);
6203 return err;
6204 }
6205
6206 codec->patch_ops = stac92xx_patch_ops;
6207
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006208 codec->proc_widget_hook = stac9205_proc_hook;
6209
Matt Porterf3302a52006-07-31 12:49:34 +02006210 return 0;
6211}
6212
Matt2f2f4252005-04-13 14:45:30 +02006213/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006214 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006215 */
6216
Takashi Iwai1e137f92009-01-21 07:41:22 +01006217static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006218 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006219 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6220 {}
6221};
6222
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006223static hda_nid_t stac9872_pin_nids[] = {
6224 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6225 0x11, 0x13, 0x14,
6226};
6227
6228static hda_nid_t stac9872_adc_nids[] = {
6229 0x8 /*,0x6*/
6230};
6231
6232static hda_nid_t stac9872_mux_nids[] = {
6233 0x15
6234};
6235
Takashi Iwai6479c632009-07-28 18:20:25 +02006236static unsigned long stac9872_capvols[] = {
6237 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6238};
6239#define stac9872_capsws stac9872_capvols
6240
Takashi Iwai307282c2009-03-12 18:17:58 +01006241static unsigned int stac9872_vaio_pin_configs[9] = {
6242 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6243 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6244 0x90a7013e
6245};
6246
Takashi Iwaiea734962011-01-17 11:29:34 +01006247static const char * const stac9872_models[STAC_9872_MODELS] = {
Takashi Iwai307282c2009-03-12 18:17:58 +01006248 [STAC_9872_AUTO] = "auto",
6249 [STAC_9872_VAIO] = "vaio",
6250};
6251
6252static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6253 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6254};
6255
6256static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006257 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6258 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006259 {} /* terminator */
6260};
6261
Guillaume Munch6d859062006-08-22 17:15:47 +02006262static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006263{
6264 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006265 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006266
Takashi Iwaidb064e52006-03-16 16:04:58 +01006267 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6268 if (spec == NULL)
6269 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006270 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006271 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006272 spec->linear_tone_beep = 1;
Takashi Iwaib04add92009-07-20 08:01:36 +02006273 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6274 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006275
6276 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6277 stac9872_models,
6278 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006279 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006280 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6281 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006282 else
6283 stac92xx_set_config_regs(codec,
6284 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006285
Takashi Iwai1e137f92009-01-21 07:41:22 +01006286 spec->multiout.dac_nids = spec->dac_nids;
6287 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6288 spec->adc_nids = stac9872_adc_nids;
6289 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6290 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006291 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006292 spec->num_caps = 1;
6293 spec->capvols = stac9872_capvols;
6294 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006295
Takashi Iwai1e137f92009-01-21 07:41:22 +01006296 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6297 if (err < 0) {
6298 stac92xx_free(codec);
6299 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006300 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006301 spec->input_mux = &spec->private_imux;
6302 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006303 return 0;
6304}
6305
6306
6307/*
Matt2f2f4252005-04-13 14:45:30 +02006308 * patch entries
6309 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006310static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006311 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6312 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6313 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6314 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6315 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6316 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6317 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006318 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6319 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6320 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6321 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6322 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6323 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006324 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6325 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6326 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6327 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6328 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6329 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6330 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6331 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6332 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6333 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006334 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6335 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6336 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6337 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6338 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6339 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006340 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6341 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006342 /* The following does not take into account .id=0x83847661 when subsys =
6343 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6344 * currently not fully supported.
6345 */
6346 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6347 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6348 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006349 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006350 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6351 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6352 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6353 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6354 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6355 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6356 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6357 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006358 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006359 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006360 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006361 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006362 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006363 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6364 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006365 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6366 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6367 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6368 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006369 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006370 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6371 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006372 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006373 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6374 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6375 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6376 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6377 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6378 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6379 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6380 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006381 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6382 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6383 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6384 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6385 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6386 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6387 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6388 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6389 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6390 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6391 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6392 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6393 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6394 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6395 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006396 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikov4dfb8a42011-02-22 17:32:19 -06006397 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6398 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006399 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006400 {} /* terminator */
6401};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006402
6403MODULE_ALIAS("snd-hda-codec-id:8384*");
6404MODULE_ALIAS("snd-hda-codec-id:111d*");
6405
6406MODULE_LICENSE("GPL");
6407MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6408
6409static struct hda_codec_preset_list sigmatel_list = {
6410 .preset = snd_hda_preset_sigmatel,
6411 .owner = THIS_MODULE,
6412};
6413
6414static int __init patch_sigmatel_init(void)
6415{
6416 return snd_hda_add_codec_preset(&sigmatel_list);
6417}
6418
6419static void __exit patch_sigmatel_exit(void)
6420{
6421 snd_hda_delete_codec_preset(&sigmatel_list);
6422}
6423
6424module_init(patch_sigmatel_init)
6425module_exit(patch_sigmatel_exit)