blob: 93fa59cc60ef9ba0f5b2315c6461d3966608994c [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 Iwaic8b6bf9b2005-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 Ranostay4fe51952008-01-29 15:28:44 +0100209 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200210 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100211 unsigned int gpio_mask;
212 unsigned int gpio_dir;
213 unsigned int gpio_data;
214 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200215 unsigned int gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +0100216 unsigned int gpio_led_polarity;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100217
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200218 /* stream */
219 unsigned int stream_delay;
220
Matthew Ranostay4fe51952008-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 Iwai16970552007-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
Matthew Ranostay65973632008-09-16 10:39:37 -0400269 const char **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 Iwaic8b6bf9b2005-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
Takashi Iwai6479c632009-07-28 18:20:25 +0200392#define STAC92HD83XXX_NUM_CAPS 2
393static unsigned long stac92hd83xxx_capvols[] = {
394 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
395 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
396};
397#define stac92hd83xxx_capsws stac92hd83xxx_capvols
398
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100399static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
400 0x0a, 0x0d, 0x0f
401};
402
Matthew Ranostaye035b842007-11-06 11:53:55 +0100403static hda_nid_t stac92hd71bxx_adc_nids[2] = {
404 0x12, 0x13,
405};
406
407static hda_nid_t stac92hd71bxx_mux_nids[2] = {
408 0x1a, 0x1b
409};
410
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400411static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
412 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100413};
414
Matthew Ranostayd9737752008-09-07 12:03:41 +0200415static hda_nid_t stac92hd71bxx_smux_nids[2] = {
416 0x24, 0x25,
417};
418
Matthew Ranostaye035b842007-11-06 11:53:55 +0100419#define STAC92HD71BXX_NUM_DMICS 2
420static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
421 0x18, 0x19, 0
422};
423
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400424static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
425 0x22, 0
426};
427
Takashi Iwai6479c632009-07-28 18:20:25 +0200428#define STAC92HD71BXX_NUM_CAPS 2
429static unsigned long stac92hd71bxx_capvols[] = {
430 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
431 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
432};
433#define stac92hd71bxx_capsws stac92hd71bxx_capvols
434
Tobin Davis8e21c342007-01-08 11:04:17 +0100435static hda_nid_t stac925x_adc_nids[1] = {
436 0x03,
437};
438
439static hda_nid_t stac925x_mux_nids[1] = {
440 0x0f,
441};
442
443static hda_nid_t stac925x_dac_nids[1] = {
444 0x02,
445};
446
Takashi Iwaif6e98522007-10-16 14:27:04 +0200447#define STAC925X_NUM_DMICS 1
448static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
449 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200450};
451
Takashi Iwai16970552007-12-18 18:05:52 +0100452static hda_nid_t stac925x_dmux_nids[1] = {
453 0x14,
454};
455
Takashi Iwai6479c632009-07-28 18:20:25 +0200456static unsigned long stac925x_capvols[] = {
457 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
458};
459static unsigned long stac925x_capsws[] = {
460 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
461};
462
Matt2f2f4252005-04-13 14:45:30 +0200463static hda_nid_t stac922x_adc_nids[2] = {
464 0x06, 0x07,
465};
466
467static hda_nid_t stac922x_mux_nids[2] = {
468 0x12, 0x13,
469};
470
Takashi Iwai6479c632009-07-28 18:20:25 +0200471#define STAC922X_NUM_CAPS 2
472static unsigned long stac922x_capvols[] = {
473 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
474 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
475};
476#define stac922x_capsws stac922x_capvols
477
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500478static hda_nid_t stac927x_slave_dig_outs[2] = {
479 0x1f, 0,
480};
481
Matt Porter3cc08dc2006-01-23 15:27:49 +0100482static hda_nid_t stac927x_adc_nids[3] = {
483 0x07, 0x08, 0x09
484};
485
486static hda_nid_t stac927x_mux_nids[3] = {
487 0x15, 0x16, 0x17
488};
489
Matthew Ranostayd9737752008-09-07 12:03:41 +0200490static hda_nid_t stac927x_smux_nids[1] = {
491 0x21,
492};
493
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100494static hda_nid_t stac927x_dac_nids[6] = {
495 0x02, 0x03, 0x04, 0x05, 0x06, 0
496};
497
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100498static hda_nid_t stac927x_dmux_nids[1] = {
499 0x1b,
500};
501
Matthew Ranostay7f168592007-10-18 17:38:17 +0200502#define STAC927X_NUM_DMICS 2
503static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
504 0x13, 0x14, 0
505};
506
Takashi Iwai6479c632009-07-28 18:20:25 +0200507#define STAC927X_NUM_CAPS 3
508static unsigned long stac927x_capvols[] = {
509 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
510 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
511 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
512};
513static unsigned long stac927x_capsws[] = {
514 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
515 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
516 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
517};
518
Matthew Ranostay65973632008-09-16 10:39:37 -0400519static const char *stac927x_spdif_labels[5] = {
520 "Digital Playback", "ADAT", "Analog Mux 1",
521 "Analog Mux 2", "Analog Mux 3"
522};
523
Matt Porterf3302a52006-07-31 12:49:34 +0200524static hda_nid_t stac9205_adc_nids[2] = {
525 0x12, 0x13
526};
527
528static hda_nid_t stac9205_mux_nids[2] = {
529 0x19, 0x1a
530};
531
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100532static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai16970552007-12-18 18:05:52 +0100533 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100534};
535
Matthew Ranostayd9737752008-09-07 12:03:41 +0200536static hda_nid_t stac9205_smux_nids[1] = {
537 0x21,
538};
539
Takashi Iwaif6e98522007-10-16 14:27:04 +0200540#define STAC9205_NUM_DMICS 2
541static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
542 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200543};
544
Takashi Iwai6479c632009-07-28 18:20:25 +0200545#define STAC9205_NUM_CAPS 2
546static unsigned long stac9205_capvols[] = {
547 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
548 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
549};
550static unsigned long stac9205_capsws[] = {
551 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
552 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
553};
554
Mattc7d4b2f2005-06-27 14:59:41 +0200555static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200556 0x08, 0x09, 0x0d, 0x0e,
557 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200558};
559
Tobin Davis8e21c342007-01-08 11:04:17 +0100560static hda_nid_t stac925x_pin_nids[8] = {
561 0x07, 0x08, 0x0a, 0x0b,
562 0x0c, 0x0d, 0x10, 0x11,
563};
564
Matt2f2f4252005-04-13 14:45:30 +0200565static hda_nid_t stac922x_pin_nids[10] = {
566 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
567 0x0f, 0x10, 0x11, 0x15, 0x1b,
568};
569
Matthew Ranostaya7662642008-02-21 07:51:14 +0100570static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100571 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
572 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200573 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100574};
575
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500576static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200577 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500578 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200579};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500580
Charles Chin36706002010-01-29 12:05:51 +0100581static hda_nid_t stac92hd88xxx_pin_nids[10] = {
582 0x0a, 0x0b, 0x0c, 0x0d,
583 0x0f, 0x11, 0x1f, 0x20,
584};
585
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500586#define STAC92HD71BXX_NUM_PINS 13
587static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
588 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
589 0x00, 0x14, 0x18, 0x19, 0x1e,
590 0x1f, 0x20, 0x27
591};
592static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100593 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
594 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500595 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100596};
597
Matt Porter3cc08dc2006-01-23 15:27:49 +0100598static hda_nid_t stac927x_pin_nids[14] = {
599 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
600 0x0f, 0x10, 0x11, 0x12, 0x13,
601 0x14, 0x21, 0x22, 0x23,
602};
603
Matt Porterf3302a52006-07-31 12:49:34 +0200604static hda_nid_t stac9205_pin_nids[12] = {
605 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
606 0x0f, 0x14, 0x16, 0x17, 0x18,
607 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200608};
609
Matt Porter8b657272006-10-26 17:12:59 +0200610static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
611 struct snd_ctl_elem_info *uinfo)
612{
613 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
614 struct sigmatel_spec *spec = codec->spec;
615 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
616}
617
618static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
619 struct snd_ctl_elem_value *ucontrol)
620{
621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
622 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100623 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200624
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100625 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200626 return 0;
627}
628
629static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
630 struct snd_ctl_elem_value *ucontrol)
631{
632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100634 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200635
636 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100637 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200638}
639
Matthew Ranostayd9737752008-09-07 12:03:41 +0200640static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
641 struct snd_ctl_elem_info *uinfo)
642{
643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
644 struct sigmatel_spec *spec = codec->spec;
645 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
646}
647
648static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
649 struct snd_ctl_elem_value *ucontrol)
650{
651 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
652 struct sigmatel_spec *spec = codec->spec;
653 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
654
655 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
656 return 0;
657}
658
659static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
660 struct snd_ctl_elem_value *ucontrol)
661{
662 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
663 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400664 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200665 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400666 int err, val;
667 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200668
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400669 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200670 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400671 if (err < 0)
672 return err;
673
674 if (spec->spdif_mute) {
675 if (smux_idx == 0)
676 nid = spec->multiout.dig_out_nid;
677 else
678 nid = codec->slave_dig_outs[smux_idx - 1];
679 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100680 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400681 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100682 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400683 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100684 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
685 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400686 }
687 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200688}
689
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200690static unsigned int stac92xx_vref_set(struct hda_codec *codec,
691 hda_nid_t nid, unsigned int new_vref)
692{
Takashi Iwaib8621512009-06-22 08:00:10 +0200693 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200694 unsigned int pincfg;
695 pincfg = snd_hda_codec_read(codec, nid, 0,
696 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
697
698 pincfg &= 0xff;
699 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
700 pincfg |= new_vref;
701
702 if (new_vref == AC_PINCTL_VREF_HIZ)
703 pincfg |= AC_PINCTL_OUT_EN;
704 else
705 pincfg |= AC_PINCTL_IN_EN;
706
707 error = snd_hda_codec_write_cache(codec, nid, 0,
708 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
709 if (error < 0)
710 return error;
711 else
712 return 1;
713}
714
715static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
716{
717 unsigned int vref;
718 vref = snd_hda_codec_read(codec, nid, 0,
719 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
720 vref &= AC_PINCTL_VREFEN;
721 return vref;
722}
723
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100724static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200725{
726 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
727 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200728 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200729}
730
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100731static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200732{
733 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
734 struct sigmatel_spec *spec = codec->spec;
735 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
736
737 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
738 return 0;
739}
740
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100741static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200742{
743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
744 struct sigmatel_spec *spec = codec->spec;
745 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200746 const struct hda_input_mux *imux = spec->input_mux;
747 unsigned int idx, prev_idx;
Matt2f2f4252005-04-13 14:45:30 +0200748
Takashi Iwai5207e102009-07-30 13:09:08 +0200749 idx = ucontrol->value.enumerated.item[0];
750 if (idx >= imux->num_items)
751 idx = imux->num_items - 1;
752 prev_idx = spec->cur_mux[adc_idx];
753 if (prev_idx == idx)
754 return 0;
755 if (idx < spec->num_analog_muxes) {
756 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
757 AC_VERB_SET_CONNECT_SEL,
758 imux->items[idx].index);
759 if (prev_idx >= spec->num_analog_muxes) {
760 imux = spec->dinput_mux;
761 /* 0 = analog */
762 snd_hda_codec_write_cache(codec,
763 spec->dmux_nids[adc_idx], 0,
764 AC_VERB_SET_CONNECT_SEL,
765 imux->items[0].index);
766 }
767 } else {
768 imux = spec->dinput_mux;
769 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
770 AC_VERB_SET_CONNECT_SEL,
771 imux->items[idx - 1].index);
772 }
773 spec->cur_mux[adc_idx] = idx;
774 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200775}
776
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100777static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
778 struct snd_ctl_elem_info *uinfo)
779{
780 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
781 struct sigmatel_spec *spec = codec->spec;
782 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
783}
784
785static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
786 struct snd_ctl_elem_value *ucontrol)
787{
788 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
789 struct sigmatel_spec *spec = codec->spec;
790
791 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
792 return 0;
793}
794
795static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
796 struct snd_ctl_elem_value *ucontrol)
797{
798 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
799 struct sigmatel_spec *spec = codec->spec;
800
801 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
802 spec->mono_nid, &spec->cur_mmux);
803}
804
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200805#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
806
807static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
808 struct snd_ctl_elem_value *ucontrol)
809{
810 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100811 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200812 struct sigmatel_spec *spec = codec->spec;
813
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100814 ucontrol->value.integer.value[0] = !!(spec->aloopback &
815 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200816 return 0;
817}
818
819static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
820 struct snd_ctl_elem_value *ucontrol)
821{
822 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
823 struct sigmatel_spec *spec = codec->spec;
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 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100826 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200827
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100828 idx_val = spec->aloopback_mask << idx;
829 if (ucontrol->value.integer.value[0])
830 val = spec->aloopback | idx_val;
831 else
832 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100833 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200834 return 0;
835
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100836 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200837
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100838 /* Only return the bits defined by the shift value of the
839 * first two bytes of the mask
840 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200841 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100842 kcontrol->private_value & 0xFFFF, 0x0);
843 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200844
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100845 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200846 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100847 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200848 } else {
849 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100850 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200851 }
852
853 snd_hda_codec_write_cache(codec, codec->afg, 0,
854 kcontrol->private_value >> 16, dac_mode);
855
856 return 1;
857}
858
Mattc7d4b2f2005-06-27 14:59:41 +0200859static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200860 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200861 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200862 {}
863};
864
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200865static struct hda_verb stac9200_eapd_init[] = {
866 /* set dac0mux for dac converter */
867 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
868 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
869 {}
870};
871
Matthew Ranostayd654a662008-03-14 08:46:51 +0100872static struct hda_verb dell_eq_core_init[] = {
873 /* set master volume to max value without distortion
874 * and direct control */
875 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100876 {}
877};
878
Takashi Iwaie2aec172009-09-02 01:00:05 +0200879static struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100880 /* set master volume and direct control */
881 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100882 {}
883};
884
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200885static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200886 /* power state controls amps */
887 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200888 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200889};
890
Matthew Ranostaye035b842007-11-06 11:53:55 +0100891static struct hda_verb stac92hd71bxx_core_init[] = {
892 /* set master volume and direct control */
893 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200894 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100895};
896
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500897static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
898 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
899 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100900 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
901 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100902 {}
903};
904
Tobin Davis8e21c342007-01-08 11:04:17 +0100905static struct hda_verb stac925x_core_init[] = {
906 /* set dac0mux for dac converter */
907 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100908 /* mute the master volume */
909 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100910 {}
911};
912
Mattc7d4b2f2005-06-27 14:59:41 +0200913static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200914 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200915 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200916 {}
917};
918
Tobin Davis93ed1502006-09-01 21:03:12 +0200919static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200920 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200921 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200922 /* unmute node 0x1b */
923 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
924 /* select node 0x03 as DAC */
925 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
926 {}
927};
928
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200929static struct hda_verb dell_3st_core_init[] = {
930 /* don't set delta bit */
931 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
932 /* unmute node 0x1b */
933 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
934 /* select node 0x03 as DAC */
935 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
936 {}
937};
938
Matt Porter3cc08dc2006-01-23 15:27:49 +0100939static struct hda_verb stac927x_core_init[] = {
940 /* set master volume and direct control */
941 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200942 /* enable analog pc beep path */
943 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100944 {}
945};
946
Takashi Iwai54930532009-10-11 17:38:29 +0200947static struct hda_verb stac927x_volknob_core_init[] = {
948 /* don't set delta bit */
949 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
950 /* enable analog pc beep path */
951 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
952 {}
953};
954
Matt Porterf3302a52006-07-31 12:49:34 +0200955static struct hda_verb stac9205_core_init[] = {
956 /* set master volume and direct control */
957 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200958 /* enable analog pc beep path */
959 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200960 {}
961};
962
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100963#define STAC_MONO_MUX \
964 { \
965 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
966 .name = "Mono Mux", \
967 .count = 1, \
968 .info = stac92xx_mono_mux_enum_info, \
969 .get = stac92xx_mono_mux_enum_get, \
970 .put = stac92xx_mono_mux_enum_put, \
971 }
972
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100973#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200974 { \
975 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
976 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100977 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200978 .info = stac92xx_aloopback_info, \
979 .get = stac92xx_aloopback_get, \
980 .put = stac92xx_aloopback_put, \
981 .private_value = verb_read | (verb_write << 16), \
982 }
983
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200984#define DC_BIAS(xname, idx, nid) \
985 { \
986 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
987 .name = xname, \
988 .index = idx, \
989 .info = stac92xx_dc_bias_info, \
990 .get = stac92xx_dc_bias_get, \
991 .put = stac92xx_dc_bias_put, \
992 .private_value = nid, \
993 }
994
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +0100995static struct snd_kcontrol_new stac9200_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +0200996 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200997 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200998 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
999 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001000 { } /* end */
1001};
1002
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001003static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1004 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1005 {}
1006};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001007
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001008static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1009 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1010 {}
1011};
1012
1013static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1014 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1015 {}
1016};
1017
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001018
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001019static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1020 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1021};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001022
Tobin Davis8e21c342007-01-08 11:04:17 +01001023static struct snd_kcontrol_new stac925x_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001024 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
Takashi Iwaic9280d62009-01-15 17:31:00 +01001025 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001026 { } /* end */
1027};
1028
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001029static struct snd_kcontrol_new stac9205_loopback[] = {
1030 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1031 {}
1032};
1033
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001034static struct snd_kcontrol_new stac927x_loopback[] = {
1035 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1036 {}
1037};
1038
Takashi Iwai16970552007-12-18 18:05:52 +01001039static struct snd_kcontrol_new stac_dmux_mixer = {
1040 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1041 .name = "Digital Input Source",
1042 /* count set later */
1043 .info = stac92xx_dmux_enum_info,
1044 .get = stac92xx_dmux_enum_get,
1045 .put = stac92xx_dmux_enum_put,
1046};
1047
Matthew Ranostayd9737752008-09-07 12:03:41 +02001048static struct snd_kcontrol_new stac_smux_mixer = {
1049 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001050 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001051 /* count set later */
1052 .info = stac92xx_smux_enum_info,
1053 .get = stac92xx_smux_enum_get,
1054 .put = stac92xx_smux_enum_put,
1055};
1056
Takashi Iwai2134ea42008-01-10 16:53:55 +01001057static const char *slave_vols[] = {
1058 "Front Playback Volume",
1059 "Surround Playback Volume",
1060 "Center Playback Volume",
1061 "LFE Playback Volume",
1062 "Side Playback Volume",
1063 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001064 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001065 NULL
1066};
1067
1068static const char *slave_sws[] = {
1069 "Front Playback Switch",
1070 "Surround Playback Switch",
1071 "Center Playback Switch",
1072 "LFE Playback Switch",
1073 "Side Playback Switch",
1074 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001075 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001076 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001077 NULL
1078};
1079
Takashi Iwai603c4012008-07-30 15:01:44 +02001080static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001081static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001082
Matt2f2f4252005-04-13 14:45:30 +02001083static int stac92xx_build_controls(struct hda_codec *codec)
1084{
1085 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001086 struct auto_pin_cfg *cfg = &spec->autocfg;
1087 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001088 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001089 int i;
Matt2f2f4252005-04-13 14:45:30 +02001090
Takashi Iwai6479c632009-07-28 18:20:25 +02001091 if (spec->mixer) {
1092 err = snd_hda_add_new_ctls(codec, spec->mixer);
1093 if (err < 0)
1094 return err;
1095 }
Mattc7d4b2f2005-06-27 14:59:41 +02001096
1097 for (i = 0; i < spec->num_mixers; i++) {
1098 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1099 if (err < 0)
1100 return err;
1101 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001102 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1103 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai16970552007-12-18 18:05:52 +01001104 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001105 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai16970552007-12-18 18:05:52 +01001106 snd_ctl_new1(&stac_dmux_mixer, codec));
1107 if (err < 0)
1108 return err;
1109 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001110 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001111 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1112 struct hda_input_mux *smux = &spec->private_smux;
1113 /* check for mute support on SPDIF out */
1114 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001115 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001116 spec->spdif_mute = 1;
1117 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001118 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001119 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001120 snd_ctl_new1(&stac_smux_mixer, codec));
1121 if (err < 0)
1122 return err;
1123 }
Mattc7d4b2f2005-06-27 14:59:41 +02001124
Mattdabbed62005-06-14 10:19:34 +02001125 if (spec->multiout.dig_out_nid) {
1126 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1127 if (err < 0)
1128 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001129 err = snd_hda_create_spdif_share_sw(codec,
1130 &spec->multiout);
1131 if (err < 0)
1132 return err;
1133 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001134 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001135 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001136 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1137 if (err < 0)
1138 return err;
1139 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001140
1141 /* if we have no master control, let's create it */
1142 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001143 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001144 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001145 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001146 /* correct volume offset */
1147 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001148 /* minimum value is actually mute */
Clemens Ladischa74ccea2010-10-22 15:52:34 +02001149 vmaster_tlv[3] |= TLV_DB_SCALE_MUTE;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001150 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001151 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001152 if (err < 0)
1153 return err;
1154 }
1155 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1156 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1157 NULL, slave_sws);
1158 if (err < 0)
1159 return err;
1160 }
1161
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001162 if (spec->aloopback_ctl &&
1163 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1164 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1165 if (err < 0)
1166 return err;
1167 }
1168
Takashi Iwai603c4012008-07-30 15:01:44 +02001169 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001170
1171 /* create jack input elements */
1172 if (spec->hp_detect) {
1173 for (i = 0; i < cfg->hp_outs; i++) {
1174 int type = SND_JACK_HEADPHONE;
1175 nid = cfg->hp_pins[i];
1176 /* jack detection */
1177 if (cfg->hp_outs == i)
1178 type |= SND_JACK_LINEOUT;
1179 err = stac92xx_add_jack(codec, nid, type);
1180 if (err < 0)
1181 return err;
1182 }
1183 }
1184 for (i = 0; i < cfg->line_outs; i++) {
1185 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1186 SND_JACK_LINEOUT);
1187 if (err < 0)
1188 return err;
1189 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02001190 for (i = 0; i < cfg->num_inputs; i++) {
1191 nid = cfg->inputs[i].pin;
1192 err = stac92xx_add_jack(codec, nid, SND_JACK_MICROPHONE);
1193 if (err < 0)
1194 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001195 }
1196
Mattdabbed62005-06-14 10:19:34 +02001197 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001198}
1199
Matt Porter403d1942005-11-29 15:00:51 +01001200static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001201 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001202 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1203};
1204
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001205static unsigned int gateway9200_m4_pin_configs[8] = {
1206 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1207 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1208};
1209static unsigned int gateway9200_m4_2_pin_configs[8] = {
1210 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1211 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1212};
1213
1214/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001215 STAC 9200 pin configs for
1216 102801A8
1217 102801DE
1218 102801E8
1219*/
1220static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001221 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1222 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001223};
1224
1225/*
1226 STAC 9200 pin configs for
1227 102801C0
1228 102801C1
1229*/
1230static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001231 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1232 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001233};
1234
1235/*
1236 STAC 9200 pin configs for
1237 102801C4 (Dell Dimension E310)
1238 102801C5
1239 102801C7
1240 102801D9
1241 102801DA
1242 102801E3
1243*/
1244static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001245 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1246 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001247};
1248
1249
1250/*
1251 STAC 9200-32 pin configs for
1252 102801B5 (Dell Inspiron 630m)
1253 102801D8 (Dell Inspiron 640m)
1254*/
1255static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001256 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1257 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001258};
1259
1260/*
1261 STAC 9200-32 pin configs for
1262 102801C2 (Dell Latitude D620)
1263 102801C8
1264 102801CC (Dell Latitude D820)
1265 102801D4
1266 102801D6
1267*/
1268static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001269 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1270 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001271};
1272
1273/*
1274 STAC 9200-32 pin configs for
1275 102801CE (Dell XPS M1710)
1276 102801CF (Dell Precision M90)
1277*/
1278static unsigned int dell9200_m23_pin_configs[8] = {
1279 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1280 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1281};
1282
1283/*
1284 STAC 9200-32 pin configs for
1285 102801C9
1286 102801CA
1287 102801CB (Dell Latitude 120L)
1288 102801D3
1289*/
1290static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001291 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1292 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001293};
1294
1295/*
1296 STAC 9200-32 pin configs for
1297 102801BD (Dell Inspiron E1505n)
1298 102801EE
1299 102801EF
1300*/
1301static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001302 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1303 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001304};
1305
1306/*
1307 STAC 9200-32 pin configs for
1308 102801F5 (Dell Inspiron 1501)
1309 102801F6
1310*/
1311static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001312 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1313 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001314};
1315
1316/*
1317 STAC 9200-32
1318 102801CD (Dell Inspiron E1705/9400)
1319*/
1320static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001321 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1322 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001323};
1324
Tobin Davisbf277782008-02-03 20:31:47 +01001325static unsigned int oqo9200_pin_configs[8] = {
1326 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1327 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1328};
1329
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001330
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001331static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1332 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001333 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001334 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1335 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1336 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1337 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1338 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1339 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1340 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1341 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1342 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1343 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001344 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1345 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001346 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001347};
1348
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001349static const char *stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001350 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001351 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001352 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001353 [STAC_9200_DELL_D21] = "dell-d21",
1354 [STAC_9200_DELL_D22] = "dell-d22",
1355 [STAC_9200_DELL_D23] = "dell-d23",
1356 [STAC_9200_DELL_M21] = "dell-m21",
1357 [STAC_9200_DELL_M22] = "dell-m22",
1358 [STAC_9200_DELL_M23] = "dell-m23",
1359 [STAC_9200_DELL_M24] = "dell-m24",
1360 [STAC_9200_DELL_M25] = "dell-m25",
1361 [STAC_9200_DELL_M26] = "dell-m26",
1362 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001363 [STAC_9200_M4] = "gateway-m4",
1364 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001365 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001366};
1367
1368static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1369 /* SigmaTel reference board */
1370 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1371 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001372 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1373 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001374 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001375 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1376 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001377 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001378 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1379 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1380 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1381 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1382 "unknown Dell", STAC_9200_DELL_D22),
1383 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1384 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001385 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001386 "Dell Latitude D620", STAC_9200_DELL_M22),
1387 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1388 "unknown Dell", STAC_9200_DELL_D23),
1389 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1390 "unknown Dell", STAC_9200_DELL_D23),
1391 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1392 "unknown Dell", STAC_9200_DELL_M22),
1393 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1394 "unknown Dell", STAC_9200_DELL_M24),
1395 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1396 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001397 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001398 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001399 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001400 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001401 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001402 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001403 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001404 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001405 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001406 "Dell Precision M90", STAC_9200_DELL_M23),
1407 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1408 "unknown Dell", STAC_9200_DELL_M22),
1409 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1410 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001411 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001412 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001413 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001414 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1415 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1416 "unknown Dell", STAC_9200_DELL_D23),
1417 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1418 "unknown Dell", STAC_9200_DELL_D23),
1419 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1420 "unknown Dell", STAC_9200_DELL_D21),
1421 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1422 "unknown Dell", STAC_9200_DELL_D23),
1423 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1424 "unknown Dell", STAC_9200_DELL_D21),
1425 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1426 "unknown Dell", STAC_9200_DELL_M25),
1427 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1428 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001429 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001430 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1431 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1432 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001433 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001434 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001435 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001436 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1437 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1438 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001439 /* OQO Mobile */
1440 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001441 {} /* terminator */
1442};
1443
Tobin Davis8e21c342007-01-08 11:04:17 +01001444static unsigned int ref925x_pin_configs[8] = {
1445 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001446 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001447};
1448
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001449static unsigned int stac925xM1_pin_configs[8] = {
1450 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1451 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001452};
1453
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001454static unsigned int stac925xM1_2_pin_configs[8] = {
1455 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1456 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1457};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001458
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001459static unsigned int stac925xM2_pin_configs[8] = {
1460 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1461 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001462};
1463
Tobin Davis8e21c342007-01-08 11:04:17 +01001464static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001465 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1466 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1467};
1468
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001469static unsigned int stac925xM3_pin_configs[8] = {
1470 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1471 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1472};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001473
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001474static unsigned int stac925xM5_pin_configs[8] = {
1475 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1476 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1477};
1478
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001479static unsigned int stac925xM6_pin_configs[8] = {
1480 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1481 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001482};
1483
1484static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1485 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001486 [STAC_M1] = stac925xM1_pin_configs,
1487 [STAC_M1_2] = stac925xM1_2_pin_configs,
1488 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001489 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001490 [STAC_M3] = stac925xM3_pin_configs,
1491 [STAC_M5] = stac925xM5_pin_configs,
1492 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001493};
1494
1495static const char *stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001496 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001497 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001498 [STAC_M1] = "m1",
1499 [STAC_M1_2] = "m1-2",
1500 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001501 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001502 [STAC_M3] = "m3",
1503 [STAC_M5] = "m5",
1504 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001505};
1506
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001507static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001508 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1509 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1510 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1511 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001512 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001513 /* Not sure about the brand name for those */
1514 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1515 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1516 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1517 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001518 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001519};
1520
1521static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1522 /* SigmaTel reference board */
1523 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001524 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001525 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001526
1527 /* Default table for unknown ID */
1528 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1529
Tobin Davis8e21c342007-01-08 11:04:17 +01001530 {} /* terminator */
1531};
1532
Matthew Ranostaya7662642008-02-21 07:51:14 +01001533static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001534 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1535 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1536 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001537 0x01452050,
1538};
1539
1540static unsigned int dell_m6_pin_configs[13] = {
1541 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001542 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001543 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1544 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001545};
1546
Takashi Iwai842ae632009-09-02 07:43:08 +02001547static unsigned int alienware_m17x_pin_configs[13] = {
1548 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1549 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1550 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1551 0x904601b0,
1552};
1553
Wu Fengguang4d26f442010-05-07 08:47:54 +08001554static unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001555 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001556 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001557};
1558
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001559static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001560 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001561 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1562 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1563 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001564 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001565 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001566 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001567};
1568
1569static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001570 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001571 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001572 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001573 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001574 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1575 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1576 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001577 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001578 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001579};
1580
1581static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1582 /* SigmaTel reference board */
1583 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001584 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001585 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1586 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001587 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1588 "Intel DG45ID", STAC_92HD73XX_INTEL),
1589 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1590 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001591 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001592 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001593 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001594 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001595 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001596 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001597 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001598 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001599 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001600 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001601 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001602 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001603 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001604 "unknown Dell", STAC_DELL_M6_DMIC),
1605 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1606 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001607 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001608 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001609 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1610 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001611 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1612 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001613 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1614 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001615 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1616 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001617 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1618 "Dell Studio 1558", STAC_DELL_M6_BOTH),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001619 {} /* terminator */
1620};
1621
Takashi Iwai842ae632009-09-02 07:43:08 +02001622static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1623 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1624 "Alienware M17x", STAC_ALIENWARE_M17X),
1625 {} /* terminator */
1626};
1627
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001628static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001629 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1630 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001631 0x01451160, 0x98560170,
1632};
1633
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001634static unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001635 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1636 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001637 0x40f000f0, 0x40f000f0,
1638};
1639
Steven Eastland48315592010-08-06 15:07:35 -06001640static unsigned int hp_dv7_4000_pin_configs[10] = {
1641 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1642 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1643 0x40f000f0, 0x40f000f0,
1644};
1645
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001646static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1647 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001648 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001649 [STAC_DELL_S14] = dell_s14_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001650 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001651};
1652
1653static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001654 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001655 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001656 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001657 [STAC_DELL_S14] = "dell-s14",
Takashi Iwaib4e81872009-11-18 17:20:24 +01001658 [STAC_92HD83XXX_HP] = "hp",
Steven Eastland48315592010-08-06 15:07:35 -06001659 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001660};
1661
1662static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1663 /* SigmaTel reference board */
1664 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001665 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001666 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1667 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001668 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1669 "unknown Dell", STAC_DELL_S14),
Takashi Iwaib4e81872009-11-18 17:20:24 +01001670 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1671 "HP", STAC_92HD83XXX_HP),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001672 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001673};
1674
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001675static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001676 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001677 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001678 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1679 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001680};
1681
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001682static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001683 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001684 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001685 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1686 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001687};
1688
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001689static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001690 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1691 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001692 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1693 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001694};
1695
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001696static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001697 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1698 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001699 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1700 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001701};
1702
Matthew Ranostaye035b842007-11-06 11:53:55 +01001703static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1704 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001705 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1706 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001707 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001708 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001709 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001710 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001711 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001712 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001713};
1714
1715static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001716 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001717 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001718 [STAC_DELL_M4_1] = "dell-m4-1",
1719 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001720 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001721 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001722 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001723 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001724 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001725 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001726};
1727
1728static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1729 /* SigmaTel reference board */
1730 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1731 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001732 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1733 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001734 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1735 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01001736 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1737 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01001738 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1739 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001740 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001741 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001742 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1743 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001744 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1745 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001746 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001747 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001748 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001749 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001750 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1751 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05301752 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1753 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Luke Yelavich9b2167d2010-10-06 15:45:46 +11001754 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x363e,
1755 "HP DV6", STAC_HP_DV5),
Takashi Iwai1972d022009-08-06 08:44:43 +02001756 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1757 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001758 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1759 "unknown Dell", STAC_DELL_M4_1),
1760 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1761 "unknown Dell", STAC_DELL_M4_1),
1762 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1763 "unknown Dell", STAC_DELL_M4_1),
1764 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1765 "unknown Dell", STAC_DELL_M4_1),
1766 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1767 "unknown Dell", STAC_DELL_M4_1),
1768 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1769 "unknown Dell", STAC_DELL_M4_1),
1770 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1771 "unknown Dell", STAC_DELL_M4_1),
1772 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1773 "unknown Dell", STAC_DELL_M4_2),
1774 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1775 "unknown Dell", STAC_DELL_M4_2),
1776 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1777 "unknown Dell", STAC_DELL_M4_2),
1778 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1779 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001780 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1781 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001782 {} /* terminator */
1783};
1784
Matt Porter403d1942005-11-29 15:00:51 +01001785static unsigned int ref922x_pin_configs[10] = {
1786 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1787 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001788 0x40000100, 0x40000100,
1789};
1790
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001791/*
1792 STAC 922X pin configs for
1793 102801A7
1794 102801AB
1795 102801A9
1796 102801D1
1797 102801D2
1798*/
1799static unsigned int dell_922x_d81_pin_configs[10] = {
1800 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1801 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1802 0x01813122, 0x400001f2,
1803};
1804
1805/*
1806 STAC 922X pin configs for
1807 102801AC
1808 102801D0
1809*/
1810static unsigned int dell_922x_d82_pin_configs[10] = {
1811 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1812 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1813 0x01813122, 0x400001f1,
1814};
1815
1816/*
1817 STAC 922X pin configs for
1818 102801BF
1819*/
1820static unsigned int dell_922x_m81_pin_configs[10] = {
1821 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1822 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1823 0x40C003f1, 0x405003f0,
1824};
1825
1826/*
1827 STAC 9221 A1 pin configs for
1828 102801D7 (Dell XPS M1210)
1829*/
1830static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001831 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1832 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001833 0x508003f3, 0x405003f4,
1834};
1835
Matt Porter403d1942005-11-29 15:00:51 +01001836static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001837 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001838 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1839 0x02a19120, 0x40000100,
1840};
1841
1842static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001843 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1844 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001845 0x02a19320, 0x40000100,
1846};
1847
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001848static unsigned int intel_mac_v1_pin_configs[10] = {
1849 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1850 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001851 0x400000fc, 0x400000fb,
1852};
1853
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001854static unsigned int intel_mac_v2_pin_configs[10] = {
1855 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1856 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001857 0x400000fc, 0x400000fb,
1858};
1859
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001860static unsigned int intel_mac_v3_pin_configs[10] = {
1861 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1862 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1863 0x400000fc, 0x400000fb,
1864};
1865
1866static unsigned int intel_mac_v4_pin_configs[10] = {
1867 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1868 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1869 0x400000fc, 0x400000fb,
1870};
1871
1872static unsigned int intel_mac_v5_pin_configs[10] = {
1873 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1874 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1875 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001876};
1877
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001878static unsigned int ecs202_pin_configs[10] = {
1879 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1880 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1881 0x9037012e, 0x40e000f2,
1882};
Takashi Iwai76c08822007-06-19 12:17:42 +02001883
Takashi Iwai19039bd2006-06-28 15:52:16 +02001884static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001885 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001886 [STAC_D945GTP3] = d945gtp3_pin_configs,
1887 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001888 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1889 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1890 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1891 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1892 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001893 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001894 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001895 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1896 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1897 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1898 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1899 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1900 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001901 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001902 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1903 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1904 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1905 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001906};
1907
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001908static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001909 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001910 [STAC_D945_REF] = "ref",
1911 [STAC_D945GTP5] = "5stack",
1912 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001913 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1914 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1915 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1916 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1917 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001918 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001919 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001920 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001921 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001922 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1923 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001924 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001925 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001926 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001927 [STAC_922X_DELL_D81] = "dell-d81",
1928 [STAC_922X_DELL_D82] = "dell-d82",
1929 [STAC_922X_DELL_M81] = "dell-m81",
1930 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001931};
1932
1933static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1934 /* SigmaTel reference board */
1935 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1936 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001937 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1938 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001939 /* Intel 945G based systems */
1940 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1941 "Intel D945G", STAC_D945GTP3),
1942 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1943 "Intel D945G", STAC_D945GTP3),
1944 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1945 "Intel D945G", STAC_D945GTP3),
1946 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1947 "Intel D945G", STAC_D945GTP3),
1948 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1949 "Intel D945G", STAC_D945GTP3),
1950 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1951 "Intel D945G", STAC_D945GTP3),
1952 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1953 "Intel D945G", STAC_D945GTP3),
1954 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1955 "Intel D945G", STAC_D945GTP3),
1956 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1957 "Intel D945G", STAC_D945GTP3),
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1959 "Intel D945G", STAC_D945GTP3),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1961 "Intel D945G", STAC_D945GTP3),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1963 "Intel D945G", STAC_D945GTP3),
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1965 "Intel D945G", STAC_D945GTP3),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1967 "Intel D945G", STAC_D945GTP3),
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1969 "Intel D945G", STAC_D945GTP3),
1970 /* Intel D945G 5-stack systems */
1971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1972 "Intel D945G", STAC_D945GTP5),
1973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1974 "Intel D945G", STAC_D945GTP5),
1975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1976 "Intel D945G", STAC_D945GTP5),
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1978 "Intel D945G", STAC_D945GTP5),
1979 /* Intel 945P based systems */
1980 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1981 "Intel D945P", STAC_D945GTP3),
1982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1983 "Intel D945P", STAC_D945GTP3),
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1985 "Intel D945P", STAC_D945GTP3),
1986 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1987 "Intel D945P", STAC_D945GTP3),
1988 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1989 "Intel D945P", STAC_D945GTP3),
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1991 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01001992 /* other intel */
1993 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
1994 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001995 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08001996 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001997 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001998 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001999 /* Dell systems */
2000 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2001 "unknown Dell", STAC_922X_DELL_D81),
2002 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2003 "unknown Dell", STAC_922X_DELL_D81),
2004 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2005 "unknown Dell", STAC_922X_DELL_D81),
2006 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2007 "unknown Dell", STAC_922X_DELL_D82),
2008 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2009 "unknown Dell", STAC_922X_DELL_M81),
2010 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2011 "unknown Dell", STAC_922X_DELL_D82),
2012 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2013 "unknown Dell", STAC_922X_DELL_D81),
2014 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2015 "unknown Dell", STAC_922X_DELL_D81),
2016 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2017 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002018 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002019 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002020 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002021 {} /* terminator */
2022};
2023
Matt Porter3cc08dc2006-01-23 15:27:49 +01002024static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002025 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2026 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2027 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2028 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002029};
2030
Tobin Davis93ed1502006-09-01 21:03:12 +02002031static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002032 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2033 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2034 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2035 0x40000100, 0x40000100
2036};
2037
Tobin Davis93ed1502006-09-01 21:03:12 +02002038static unsigned int d965_5st_pin_configs[14] = {
2039 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2040 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2041 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2042 0x40000100, 0x40000100
2043};
2044
Takashi Iwai679d92e2009-05-24 19:00:08 +02002045static unsigned int d965_5st_no_fp_pin_configs[14] = {
2046 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2047 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2048 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2049 0x40000100, 0x40000100
2050};
2051
Tobin Davis4ff076e2007-08-07 11:48:12 +02002052static unsigned int dell_3st_pin_configs[14] = {
2053 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2054 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002055 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002056 0x40c003fc, 0x40000100
2057};
2058
Tobin Davis93ed1502006-09-01 21:03:12 +02002059static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002060 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002061 [STAC_D965_REF] = ref927x_pin_configs,
2062 [STAC_D965_3ST] = d965_3st_pin_configs,
2063 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002064 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002065 [STAC_DELL_3ST] = dell_3st_pin_configs,
2066 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002067 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002068};
2069
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002070static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002071 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002072 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002073 [STAC_D965_REF] = "ref",
2074 [STAC_D965_3ST] = "3stack",
2075 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002076 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002077 [STAC_DELL_3ST] = "dell-3stack",
2078 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002079 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002080};
2081
2082static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2083 /* SigmaTel reference board */
2084 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2085 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002086 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2087 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002088 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002089 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2090 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002091 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002092 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2093 "Intel D965", STAC_D965_3ST),
2094 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2095 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002096 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002097 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002098 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2099 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002100 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002101 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002102 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002103 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002104 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002105 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002106 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2107 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2108 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2109 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002110 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002111 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2112 "Intel D965", STAC_D965_5ST),
2113 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2114 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002115 /* volume-knob fixes */
2116 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002117 {} /* terminator */
2118};
2119
Matt Porterf3302a52006-07-31 12:49:34 +02002120static unsigned int ref9205_pin_configs[12] = {
2121 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002122 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002123 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002124};
2125
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002126/*
2127 STAC 9205 pin configs for
2128 102801F1
2129 102801F2
2130 102801FC
2131 102801FD
2132 10280204
2133 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002134 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002135 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002136*/
2137static unsigned int dell_9205_m42_pin_configs[12] = {
2138 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2139 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2140 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2141};
2142
2143/*
2144 STAC 9205 pin configs for
2145 102801F9
2146 102801FA
2147 102801FE
2148 102801FF (Dell Precision M4300)
2149 10280206
2150 10280200
2151 10280201
2152*/
2153static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002154 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2155 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2156 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2157};
2158
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002159static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002160 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2161 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2162 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2163};
2164
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002165static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002166 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002167 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2168 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2169 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002170 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002171};
2172
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002173static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002174 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002175 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002176 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002177 [STAC_9205_DELL_M43] = "dell-m43",
2178 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002179 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002180};
2181
2182static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2183 /* SigmaTel reference board */
2184 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2185 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002186 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2187 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002188 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2189 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002190 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002191 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2192 "unknown Dell", STAC_9205_DELL_M42),
2193 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2194 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002195 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002196 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002197 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2198 "Dell Precision", STAC_9205_DELL_M43),
2199 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2200 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002201 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2202 "unknown Dell", STAC_9205_DELL_M42),
2203 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2204 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002205 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2206 "Dell Precision", STAC_9205_DELL_M43),
2207 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002208 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002209 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2210 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002211 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2212 "Dell Precision", STAC_9205_DELL_M43),
2213 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2214 "Dell Precision", STAC_9205_DELL_M43),
2215 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2216 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002217 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2218 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002219 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2220 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002221 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2222 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002223 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002224 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002225 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002226 {} /* terminator */
2227};
2228
Takashi Iwai330ee992009-02-20 14:33:36 +01002229static void stac92xx_set_config_regs(struct hda_codec *codec,
2230 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002231{
2232 int i;
2233 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002234
Takashi Iwai330ee992009-02-20 14:33:36 +01002235 if (!pincfgs)
2236 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002237
Matthew Ranostay87d48362007-07-17 11:52:24 +02002238 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002239 if (spec->pin_nids[i] && pincfgs[i])
2240 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2241 pincfgs[i]);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002242}
2243
Matt2f2f4252005-04-13 14:45:30 +02002244/*
2245 * Analog playback callbacks
2246 */
2247static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2248 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002249 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002250{
2251 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002252 if (spec->stream_delay)
2253 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002254 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2255 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002256}
2257
2258static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2259 struct hda_codec *codec,
2260 unsigned int stream_tag,
2261 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002262 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002263{
2264 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002265 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002266}
2267
2268static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2269 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002270 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002271{
2272 struct sigmatel_spec *spec = codec->spec;
2273 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2274}
2275
2276/*
Mattdabbed62005-06-14 10:19:34 +02002277 * Digital playback callbacks
2278 */
2279static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2280 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002281 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002282{
2283 struct sigmatel_spec *spec = codec->spec;
2284 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2285}
2286
2287static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2288 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002289 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002290{
2291 struct sigmatel_spec *spec = codec->spec;
2292 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2293}
2294
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002295static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2296 struct hda_codec *codec,
2297 unsigned int stream_tag,
2298 unsigned int format,
2299 struct snd_pcm_substream *substream)
2300{
2301 struct sigmatel_spec *spec = codec->spec;
2302 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2303 stream_tag, format, substream);
2304}
2305
Takashi Iwai9411e212009-02-13 11:32:28 +01002306static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2307 struct hda_codec *codec,
2308 struct snd_pcm_substream *substream)
2309{
2310 struct sigmatel_spec *spec = codec->spec;
2311 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2312}
2313
Mattdabbed62005-06-14 10:19:34 +02002314
2315/*
Matt2f2f4252005-04-13 14:45:30 +02002316 * Analog capture callbacks
2317 */
2318static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2319 struct hda_codec *codec,
2320 unsigned int stream_tag,
2321 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002322 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002323{
2324 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002325 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002326
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002327 if (spec->powerdown_adcs) {
2328 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002329 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002330 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2331 }
2332 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002333 return 0;
2334}
2335
2336static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2337 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002338 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002339{
2340 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002341 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002342
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002343 snd_hda_codec_cleanup_stream(codec, nid);
2344 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002345 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002346 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002347 return 0;
2348}
2349
Mattdabbed62005-06-14 10:19:34 +02002350static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2351 .substreams = 1,
2352 .channels_min = 2,
2353 .channels_max = 2,
2354 /* NID is set in stac92xx_build_pcms */
2355 .ops = {
2356 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002357 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002358 .prepare = stac92xx_dig_playback_pcm_prepare,
2359 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002360 },
2361};
2362
2363static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2364 .substreams = 1,
2365 .channels_min = 2,
2366 .channels_max = 2,
2367 /* NID is set in stac92xx_build_pcms */
2368};
2369
Matt2f2f4252005-04-13 14:45:30 +02002370static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2371 .substreams = 1,
2372 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002373 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002374 .nid = 0x02, /* NID to query formats and rates */
2375 .ops = {
2376 .open = stac92xx_playback_pcm_open,
2377 .prepare = stac92xx_playback_pcm_prepare,
2378 .cleanup = stac92xx_playback_pcm_cleanup
2379 },
2380};
2381
Matt Porter3cc08dc2006-01-23 15:27:49 +01002382static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2383 .substreams = 1,
2384 .channels_min = 2,
2385 .channels_max = 2,
2386 .nid = 0x06, /* NID to query formats and rates */
2387 .ops = {
2388 .open = stac92xx_playback_pcm_open,
2389 .prepare = stac92xx_playback_pcm_prepare,
2390 .cleanup = stac92xx_playback_pcm_cleanup
2391 },
2392};
2393
Matt2f2f4252005-04-13 14:45:30 +02002394static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002395 .channels_min = 2,
2396 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002397 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002398 .ops = {
2399 .prepare = stac92xx_capture_pcm_prepare,
2400 .cleanup = stac92xx_capture_pcm_cleanup
2401 },
2402};
2403
2404static int stac92xx_build_pcms(struct hda_codec *codec)
2405{
2406 struct sigmatel_spec *spec = codec->spec;
2407 struct hda_pcm *info = spec->pcm_rec;
2408
2409 codec->num_pcms = 1;
2410 codec->pcm_info = info;
2411
Mattc7d4b2f2005-06-27 14:59:41 +02002412 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002413 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002414 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2415 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002416 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002417 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002418 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002419
2420 if (spec->alt_switch) {
2421 codec->num_pcms++;
2422 info++;
2423 info->name = "STAC92xx Analog Alt";
2424 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2425 }
Matt2f2f4252005-04-13 14:45:30 +02002426
Mattdabbed62005-06-14 10:19:34 +02002427 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2428 codec->num_pcms++;
2429 info++;
2430 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002431 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002432 if (spec->multiout.dig_out_nid) {
2433 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2434 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2435 }
2436 if (spec->dig_in_nid) {
2437 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2438 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2439 }
2440 }
2441
Matt2f2f4252005-04-13 14:45:30 +02002442 return 0;
2443}
2444
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002445static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2446 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002447{
Takashi Iwai1327a322009-03-23 13:07:47 +01002448 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002449 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2450 if (pincap & AC_PINCAP_VREF_100)
2451 return AC_PINCTL_VREF_100;
2452 if (pincap & AC_PINCAP_VREF_80)
2453 return AC_PINCTL_VREF_80;
2454 if (pincap & AC_PINCAP_VREF_50)
2455 return AC_PINCTL_VREF_50;
2456 if (pincap & AC_PINCAP_VREF_GRD)
2457 return AC_PINCTL_VREF_GRD;
2458 return 0;
2459}
2460
Matt Porter403d1942005-11-29 15:00:51 +01002461static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2462
2463{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002464 snd_hda_codec_write_cache(codec, nid, 0,
2465 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002466}
2467
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002468#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2469
2470static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2471 struct snd_ctl_elem_value *ucontrol)
2472{
2473 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2474 struct sigmatel_spec *spec = codec->spec;
2475
Takashi Iwaid7a89432008-11-12 09:48:04 +01002476 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002477 return 0;
2478}
2479
Takashi Iwai62558ce2009-07-29 14:23:09 +02002480static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002481
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002482static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2483 struct snd_ctl_elem_value *ucontrol)
2484{
2485 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2486 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002487 int nid = kcontrol->private_value;
2488
2489 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002490
2491 /* check to be sure that the ports are upto date with
2492 * switch changes
2493 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002494 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002495
2496 return 1;
2497}
2498
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002499static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2500 struct snd_ctl_elem_info *uinfo)
2501{
2502 int i;
2503 static char *texts[] = {
2504 "Mic In", "Line In", "Line Out"
2505 };
2506
2507 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2508 struct sigmatel_spec *spec = codec->spec;
2509 hda_nid_t nid = kcontrol->private_value;
2510
2511 if (nid == spec->mic_switch || nid == spec->line_switch)
2512 i = 3;
2513 else
2514 i = 2;
2515
2516 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2517 uinfo->value.enumerated.items = i;
2518 uinfo->count = 1;
2519 if (uinfo->value.enumerated.item >= i)
2520 uinfo->value.enumerated.item = i-1;
2521 strcpy(uinfo->value.enumerated.name,
2522 texts[uinfo->value.enumerated.item]);
2523
2524 return 0;
2525}
2526
2527static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2528 struct snd_ctl_elem_value *ucontrol)
2529{
2530 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2531 hda_nid_t nid = kcontrol->private_value;
2532 unsigned int vref = stac92xx_vref_get(codec, nid);
2533
2534 if (vref == stac92xx_get_default_vref(codec, nid))
2535 ucontrol->value.enumerated.item[0] = 0;
2536 else if (vref == AC_PINCTL_VREF_GRD)
2537 ucontrol->value.enumerated.item[0] = 1;
2538 else if (vref == AC_PINCTL_VREF_HIZ)
2539 ucontrol->value.enumerated.item[0] = 2;
2540
2541 return 0;
2542}
2543
2544static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2545 struct snd_ctl_elem_value *ucontrol)
2546{
2547 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2548 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002549 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002550 hda_nid_t nid = kcontrol->private_value;
2551
2552 if (ucontrol->value.enumerated.item[0] == 0)
2553 new_vref = stac92xx_get_default_vref(codec, nid);
2554 else if (ucontrol->value.enumerated.item[0] == 1)
2555 new_vref = AC_PINCTL_VREF_GRD;
2556 else if (ucontrol->value.enumerated.item[0] == 2)
2557 new_vref = AC_PINCTL_VREF_HIZ;
2558 else
2559 return 0;
2560
2561 if (new_vref != stac92xx_vref_get(codec, nid)) {
2562 error = stac92xx_vref_set(codec, nid, new_vref);
2563 return error;
2564 }
2565
2566 return 0;
2567}
2568
2569static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2570 struct snd_ctl_elem_info *uinfo)
2571{
2572 static char *texts[2];
2573 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2574 struct sigmatel_spec *spec = codec->spec;
2575
2576 if (kcontrol->private_value == spec->line_switch)
2577 texts[0] = "Line In";
2578 else
2579 texts[0] = "Mic In";
2580 texts[1] = "Line Out";
2581 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2582 uinfo->value.enumerated.items = 2;
2583 uinfo->count = 1;
2584
2585 if (uinfo->value.enumerated.item >= 2)
2586 uinfo->value.enumerated.item = 1;
2587 strcpy(uinfo->value.enumerated.name,
2588 texts[uinfo->value.enumerated.item]);
2589
2590 return 0;
2591}
Matt Porter403d1942005-11-29 15:00:51 +01002592
2593static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2594{
2595 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2596 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002597 hda_nid_t nid = kcontrol->private_value;
2598 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002599
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002600 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002601 return 0;
2602}
2603
2604static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2605{
2606 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2607 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002608 hda_nid_t nid = kcontrol->private_value;
2609 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2610 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002611
2612 spec->io_switch[io_idx] = val;
2613
2614 if (val)
2615 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002616 else {
2617 unsigned int pinctl = AC_PINCTL_IN_EN;
2618 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002619 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002620 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2621 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002622
2623 /* check the auto-mute again: we need to mute/unmute the speaker
2624 * appropriately according to the pin direction
2625 */
2626 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002627 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002628
Matt Porter403d1942005-11-29 15:00:51 +01002629 return 1;
2630}
2631
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002632#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2633
2634static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2635 struct snd_ctl_elem_value *ucontrol)
2636{
2637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2638 struct sigmatel_spec *spec = codec->spec;
2639
2640 ucontrol->value.integer.value[0] = spec->clfe_swap;
2641 return 0;
2642}
2643
2644static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2645 struct snd_ctl_elem_value *ucontrol)
2646{
2647 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2648 struct sigmatel_spec *spec = codec->spec;
2649 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002650 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002651
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002652 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002653 return 0;
2654
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002655 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002656
2657 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2658 spec->clfe_swap ? 0x4 : 0x0);
2659
2660 return 1;
2661}
2662
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002663#define STAC_CODEC_HP_SWITCH(xname) \
2664 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2665 .name = xname, \
2666 .index = 0, \
2667 .info = stac92xx_hp_switch_info, \
2668 .get = stac92xx_hp_switch_get, \
2669 .put = stac92xx_hp_switch_put, \
2670 }
2671
Matt Porter403d1942005-11-29 15:00:51 +01002672#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2673 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2674 .name = xname, \
2675 .index = 0, \
2676 .info = stac92xx_io_switch_info, \
2677 .get = stac92xx_io_switch_get, \
2678 .put = stac92xx_io_switch_put, \
2679 .private_value = xpval, \
2680 }
2681
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002682#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2683 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2684 .name = xname, \
2685 .index = 0, \
2686 .info = stac92xx_clfe_switch_info, \
2687 .get = stac92xx_clfe_switch_get, \
2688 .put = stac92xx_clfe_switch_put, \
2689 .private_value = xpval, \
2690 }
Matt Porter403d1942005-11-29 15:00:51 +01002691
Mattc7d4b2f2005-06-27 14:59:41 +02002692enum {
2693 STAC_CTL_WIDGET_VOL,
2694 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002695 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002696 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002697 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002698 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002699 STAC_CTL_WIDGET_CLFE_SWITCH,
2700 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002701};
2702
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002703static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002704 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2705 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002706 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002707 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002708 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002709 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002710 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002711 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002712};
2713
2714/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002715static struct snd_kcontrol_new *
2716stac_control_new(struct sigmatel_spec *spec,
2717 struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002718 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002719 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002720{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002721 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002722
Takashi Iwai603c4012008-07-30 15:01:44 +02002723 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2724 knew = snd_array_new(&spec->kctls);
2725 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002726 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002727 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002728 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002729 if (!knew->name) {
2730 /* roolback */
2731 memset(knew, 0, sizeof(*knew));
2732 spec->kctls.alloced--;
2733 return NULL;
2734 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002735 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002736 return knew;
2737}
2738
2739static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2740 struct snd_kcontrol_new *ktemp,
2741 int idx, const char *name,
2742 unsigned long val)
2743{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002744 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002745 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002746 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002747 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002748 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002749 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002750 return 0;
2751}
2752
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002753static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2754 int type, int idx, const char *name,
2755 unsigned long val)
2756{
2757 return stac92xx_add_control_temp(spec,
2758 &stac92xx_control_templates[type],
2759 idx, name, val);
2760}
2761
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002762
2763/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002764static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2765 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002766{
2767 return stac92xx_add_control_idx(spec, type, 0, name, val);
2768}
2769
Takashi Iwaie3c75962009-01-23 11:57:22 +01002770static struct snd_kcontrol_new stac_input_src_temp = {
2771 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2772 .name = "Input Source",
2773 .info = stac92xx_mux_enum_info,
2774 .get = stac92xx_mux_enum_get,
2775 .put = stac92xx_mux_enum_put,
2776};
2777
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002778static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2779 hda_nid_t nid, int idx)
2780{
2781 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2782 int control = 0;
2783 struct sigmatel_spec *spec = codec->spec;
2784 char name[22];
2785
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002786 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002787 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2788 && nid == spec->line_switch)
2789 control = STAC_CTL_WIDGET_IO_SWITCH;
2790 else if (snd_hda_query_pin_caps(codec, nid)
2791 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2792 control = STAC_CTL_WIDGET_DC_BIAS;
2793 else if (nid == spec->mic_switch)
2794 control = STAC_CTL_WIDGET_IO_SWITCH;
2795 }
2796
2797 if (control) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002798 strcpy(name, hda_get_input_pin_label(codec, nid, 1));
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002799 return stac92xx_add_control(codec->spec, control,
2800 strcat(name, " Jack Mode"), nid);
2801 }
2802
2803 return 0;
2804}
2805
Takashi Iwaie3c75962009-01-23 11:57:22 +01002806static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2807{
2808 struct snd_kcontrol_new *knew;
2809 struct hda_input_mux *imux = &spec->private_imux;
2810
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002811 if (spec->auto_mic)
2812 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002813 if (!spec->num_adcs || imux->num_items <= 1)
2814 return 0; /* no need for input source control */
2815 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002816 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002817 if (!knew)
2818 return -ENOMEM;
2819 knew->count = spec->num_adcs;
2820 return 0;
2821}
2822
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002823/* check whether the line-input can be used as line-out */
2824static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002825{
2826 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002827 struct auto_pin_cfg *cfg = &spec->autocfg;
2828 hda_nid_t nid;
2829 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002830 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002831
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002832 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2833 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002834 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02002835 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002836 nid = cfg->inputs[i].pin;
Takashi Iwai1327a322009-03-23 13:07:47 +01002837 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002838 if (pincap & AC_PINCAP_OUT)
2839 return nid;
2840 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002841 }
Matt Porter403d1942005-11-29 15:00:51 +01002842 return 0;
2843}
2844
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002845static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2846
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002847/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002848static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002849{
2850 struct sigmatel_spec *spec = codec->spec;
2851 struct auto_pin_cfg *cfg = &spec->autocfg;
2852 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02002853 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002854
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002855 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002856 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2857 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002858 for (i = 0; i < cfg->num_inputs; i++) {
2859 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02002860 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002861 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002862 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2863 /* some laptops have an internal analog microphone
2864 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002865 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002866 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002867 if (pincap & AC_PINCAP_OUT) {
2868 *dac = get_unassigned_dac(codec, nid);
2869 if (*dac)
2870 return nid;
2871 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002872 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002873 }
2874 return 0;
2875}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002876
2877static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2878{
2879 int i;
2880
2881 for (i = 0; i < spec->multiout.num_dacs; i++) {
2882 if (spec->multiout.dac_nids[i] == nid)
2883 return 1;
2884 }
2885
2886 return 0;
2887}
2888
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002889static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2890{
2891 int i;
2892 if (is_in_dac_nids(spec, nid))
2893 return 1;
2894 for (i = 0; i < spec->autocfg.hp_outs; i++)
2895 if (spec->hp_dacs[i] == nid)
2896 return 1;
2897 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2898 if (spec->speaker_dacs[i] == nid)
2899 return 1;
2900 return 0;
2901}
2902
2903static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2904{
2905 struct sigmatel_spec *spec = codec->spec;
2906 int j, conn_len;
2907 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2908 unsigned int wcaps, wtype;
2909
2910 conn_len = snd_hda_get_connections(codec, nid, conn,
2911 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002912 /* 92HD88: trace back up the link of nids to find the DAC */
2913 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2914 != AC_WID_AUD_OUT)) {
2915 nid = conn[0];
2916 conn_len = snd_hda_get_connections(codec, nid, conn,
2917 HDA_MAX_CONNECTIONS);
2918 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002919 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002920 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002921 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002922 /* we check only analog outputs */
2923 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2924 continue;
2925 /* if this route has a free DAC, assign it */
2926 if (!check_all_dac_nids(spec, conn[j])) {
2927 if (conn_len > 1) {
2928 /* select this DAC in the pin's input mux */
2929 snd_hda_codec_write_cache(codec, nid, 0,
2930 AC_VERB_SET_CONNECT_SEL, j);
2931 }
2932 return conn[j];
2933 }
2934 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002935 /* if all DACs are already assigned, connect to the primary DAC */
2936 if (conn_len > 1) {
2937 for (j = 0; j < conn_len; j++) {
2938 if (conn[j] == spec->multiout.dac_nids[0]) {
2939 snd_hda_codec_write_cache(codec, nid, 0,
2940 AC_VERB_SET_CONNECT_SEL, j);
2941 break;
2942 }
2943 }
2944 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002945 return 0;
2946}
2947
2948static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2949static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2950
Matt Porter3cc08dc2006-01-23 15:27:49 +01002951/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002952 * Fill in the dac_nids table from the parsed pin configuration
2953 * This function only works when every pin in line_out_pins[]
2954 * contains atleast one DAC in its connection list. Some 92xx
2955 * codecs are not connected directly to a DAC, such as the 9200
2956 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002957 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002958static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002959{
2960 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002961 struct auto_pin_cfg *cfg = &spec->autocfg;
2962 int i;
2963 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002964
Mattc7d4b2f2005-06-27 14:59:41 +02002965 for (i = 0; i < cfg->line_outs; i++) {
2966 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002967 dac = get_unassigned_dac(codec, nid);
2968 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002969 if (spec->multiout.num_dacs > 0) {
2970 /* we have already working output pins,
2971 * so let's drop the broken ones again
2972 */
2973 cfg->line_outs = spec->multiout.num_dacs;
2974 break;
2975 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002976 /* error out, no available DAC found */
2977 snd_printk(KERN_ERR
2978 "%s: No available DAC for pin 0x%x\n",
2979 __func__, nid);
2980 return -ENODEV;
2981 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002982 add_spec_dacs(spec, dac);
2983 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002984
Takashi Iwai139e0712009-03-06 12:10:41 +01002985 for (i = 0; i < cfg->hp_outs; i++) {
2986 nid = cfg->hp_pins[i];
2987 dac = get_unassigned_dac(codec, nid);
2988 if (dac) {
2989 if (!spec->multiout.hp_nid)
2990 spec->multiout.hp_nid = dac;
2991 else
2992 add_spec_extra_dacs(spec, dac);
2993 }
2994 spec->hp_dacs[i] = dac;
2995 }
2996
2997 for (i = 0; i < cfg->speaker_outs; i++) {
2998 nid = cfg->speaker_pins[i];
2999 dac = get_unassigned_dac(codec, nid);
3000 if (dac)
3001 add_spec_extra_dacs(spec, dac);
3002 spec->speaker_dacs[i] = dac;
3003 }
3004
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003005 /* add line-in as output */
3006 nid = check_line_out_switch(codec);
3007 if (nid) {
3008 dac = get_unassigned_dac(codec, nid);
3009 if (dac) {
3010 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3011 nid, cfg->line_outs);
3012 cfg->line_out_pins[cfg->line_outs] = nid;
3013 cfg->line_outs++;
3014 spec->line_switch = nid;
3015 add_spec_dacs(spec, dac);
3016 }
3017 }
3018 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003019 nid = check_mic_out_switch(codec, &dac);
3020 if (nid && dac) {
3021 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3022 nid, cfg->line_outs);
3023 cfg->line_out_pins[cfg->line_outs] = nid;
3024 cfg->line_outs++;
3025 spec->mic_switch = nid;
3026 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003027 }
3028
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003029 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003030 spec->multiout.num_dacs,
3031 spec->multiout.dac_nids[0],
3032 spec->multiout.dac_nids[1],
3033 spec->multiout.dac_nids[2],
3034 spec->multiout.dac_nids[3],
3035 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003036
Mattc7d4b2f2005-06-27 14:59:41 +02003037 return 0;
3038}
3039
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003040/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003041static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3042 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003043{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003044 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003045 char name[32];
3046 int err;
3047
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003048 if (!spec->check_volume_offset) {
3049 unsigned int caps, step, nums, db_scale;
3050 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3051 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3052 AC_AMPCAP_STEP_SIZE_SHIFT;
3053 step = (step + 1) * 25; /* in .01dB unit */
3054 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3055 AC_AMPCAP_NUM_STEPS_SHIFT;
3056 db_scale = nums * step;
3057 /* if dB scale is over -64dB, and finer enough,
3058 * let's reduce it to half
3059 */
3060 if (db_scale > 6400 && nums >= 0x1f)
3061 spec->volume_offset = nums / 2;
3062 spec->check_volume_offset = 1;
3063 }
3064
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003065 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003066 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003067 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3068 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003069 if (err < 0)
3070 return err;
3071 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003072 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003073 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3074 if (err < 0)
3075 return err;
3076 return 0;
3077}
3078
Takashi Iwai668b9652009-03-06 10:13:24 +01003079#define create_controls(codec, pfx, nid, chs) \
3080 create_controls_idx(codec, pfx, 0, nid, chs)
3081
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003082static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3083{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003084 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003085 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3086 return 1;
3087 } else {
3088 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3089 spec->multiout.num_dacs++;
3090 }
3091 return 0;
3092}
3093
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003094static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003095{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003096 int i;
3097 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3098 if (!spec->multiout.extra_out_nid[i]) {
3099 spec->multiout.extra_out_nid[i] = nid;
3100 return 0;
3101 }
3102 }
3103 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3104 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003105}
3106
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003107/* Create output controls
3108 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3109 */
3110static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3111 const hda_nid_t *pins,
3112 const hda_nid_t *dac_nids,
3113 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003114{
Takashi Iwai76624532008-12-19 10:09:47 +01003115 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003116 static const char *chname[4] = {
3117 "Front", "Surround", NULL /*CLFE*/, "Side"
3118 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003119 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003120 int i, err;
3121 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003122
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003123 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003124 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3125 wid_caps = get_wcaps(codec, pins[i]);
3126 if (wid_caps & AC_WCAP_UNSOL_CAP)
3127 spec->hp_detect = 1;
3128 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003129 nid = dac_nids[i];
3130 if (!nid)
3131 continue;
3132 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003133 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003134 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003135 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003136 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003137 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003138 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003139 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003140
3141 wid_caps = get_wcaps(codec, nid);
3142
3143 if (wid_caps & AC_WCAP_LR_SWAP) {
3144 err = stac92xx_add_control(spec,
3145 STAC_CTL_WIDGET_CLFE_SWITCH,
3146 "Swap Center/LFE Playback Switch", nid);
3147
3148 if (err < 0)
3149 return err;
3150 }
3151
Mattc7d4b2f2005-06-27 14:59:41 +02003152 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003153 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003154 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003155 switch (type) {
3156 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003157 name = "Headphone";
3158 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003159 break;
3160 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003161 name = "Speaker";
3162 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003163 break;
3164 default:
3165 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003166 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003167 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003168 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003169 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003170 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003171 return err;
3172 }
3173 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003174 return 0;
3175}
3176
Takashi Iwai6479c632009-07-28 18:20:25 +02003177static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3178 unsigned long sw, int idx)
3179{
3180 int err;
3181 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003182 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003183 if (err < 0)
3184 return err;
3185 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003186 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003187 if (err < 0)
3188 return err;
3189 return 0;
3190}
3191
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003192/* add playback controls from the parsed DAC table */
3193static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3194 const struct auto_pin_cfg *cfg)
3195{
3196 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003197 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003198 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003199 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003200
3201 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3202 spec->multiout.dac_nids,
3203 cfg->line_out_type);
3204 if (err < 0)
3205 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003206
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003207 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003208 err = stac92xx_add_control(spec,
3209 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003210 "Headphone as Line Out Switch",
3211 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003212 if (err < 0)
3213 return err;
3214 }
3215
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003216 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003217 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003218 break;
3219 nid = cfg->inputs[idx].pin;
3220 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3221 if (err < 0)
3222 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003223 }
Matt Porter403d1942005-11-29 15:00:51 +01003224
Mattc7d4b2f2005-06-27 14:59:41 +02003225 return 0;
3226}
3227
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003228/* add playback controls for Speaker and HP outputs */
3229static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3230 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003231{
3232 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003233 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003234
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003235 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3236 spec->hp_dacs, AUTO_PIN_HP_OUT);
3237 if (err < 0)
3238 return err;
3239
3240 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3241 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3242 if (err < 0)
3243 return err;
3244
Mattc7d4b2f2005-06-27 14:59:41 +02003245 return 0;
3246}
3247
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003248/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003249static const char *stac92xx_mono_labels[4] = {
3250 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003251};
3252
3253/* create mono mux for mono out on capable codecs */
3254static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3255{
3256 struct sigmatel_spec *spec = codec->spec;
3257 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3258 int i, num_cons;
3259 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3260
3261 num_cons = snd_hda_get_connections(codec,
3262 spec->mono_nid,
3263 con_lst,
3264 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003265 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003266 return -EINVAL;
3267
Takashi Iwai10a20af2010-09-09 16:28:02 +02003268 for (i = 0; i < num_cons; i++)
3269 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3270 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003271
3272 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3273 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003274}
3275
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003276/* create PC beep volume controls */
3277static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3278 hda_nid_t nid)
3279{
3280 struct sigmatel_spec *spec = codec->spec;
3281 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003282 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3283
3284 if (spec->anabeep_nid == nid)
3285 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003286
3287 /* check for mute support for the the amp */
3288 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003289 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003290 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003291 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3292 if (err < 0)
3293 return err;
3294 }
3295
3296 /* check to see if there is volume support for the amp */
3297 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3298 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003299 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003300 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3301 if (err < 0)
3302 return err;
3303 }
3304 return 0;
3305}
3306
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003307#ifdef CONFIG_SND_HDA_INPUT_BEEP
3308#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3309
3310static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3311 struct snd_ctl_elem_value *ucontrol)
3312{
3313 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3314 ucontrol->value.integer.value[0] = codec->beep->enabled;
3315 return 0;
3316}
3317
3318static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3319 struct snd_ctl_elem_value *ucontrol)
3320{
3321 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003322 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003323}
3324
3325static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3326 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3327 .info = stac92xx_dig_beep_switch_info,
3328 .get = stac92xx_dig_beep_switch_get,
3329 .put = stac92xx_dig_beep_switch_put,
3330};
3331
3332static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3333{
3334 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003335 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003336}
3337#endif
3338
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003339static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3340{
3341 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003342 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003343
3344 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003345 hda_nid_t nid;
3346 unsigned int wcaps;
3347 unsigned long val;
3348
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003349 nid = spec->mux_nids[i];
3350 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003351 if (!(wcaps & AC_WCAP_OUT_AMP))
3352 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003353
Takashi Iwai667067d2009-08-13 18:14:42 +02003354 /* check whether already the same control was created as
3355 * normal Capture Volume.
3356 */
3357 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3358 for (j = 0; j < spec->num_caps; j++) {
3359 if (spec->capvols[j] == val)
3360 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003361 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003362 if (j < spec->num_caps)
3363 continue;
3364
3365 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3366 "Mux Capture Volume", val);
3367 if (err < 0)
3368 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003369 }
3370 return 0;
3371};
3372
Matthew Ranostayd9737752008-09-07 12:03:41 +02003373static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003374 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003375};
3376
3377static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3378{
3379 struct sigmatel_spec *spec = codec->spec;
3380 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003381 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003382 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003383 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003384
3385 num_cons = snd_hda_get_connections(codec,
3386 spec->smux_nids[0],
3387 con_lst,
3388 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003389 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003390 return -EINVAL;
3391
Matthew Ranostay65973632008-09-16 10:39:37 -04003392 if (!labels)
3393 labels = stac92xx_spdif_labels;
3394
Takashi Iwai10a20af2010-09-09 16:28:02 +02003395 for (i = 0; i < num_cons; i++)
3396 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003397
3398 return 0;
3399}
3400
Matt Porter8b657272006-10-26 17:12:59 +02003401/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003402static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003403 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3404 "Digital Mic 3", "Digital Mic 4"
3405};
3406
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003407static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3408 hda_nid_t nid)
3409{
3410 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3411 int i, nums;
3412
3413 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3414 for (i = 0; i < nums; i++)
3415 if (conn[i] == nid)
3416 return i;
3417 return -1;
3418}
3419
Takashi Iwai667067d2009-08-13 18:14:42 +02003420/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003421/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003422static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003423 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003424{
3425 unsigned int caps, nums;
3426 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003427 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003428
Takashi Iwai96f845d2009-08-29 00:49:36 +02003429 if (direction == HDA_OUTPUT)
3430 caps = AC_WCAP_OUT_AMP;
3431 else
3432 caps = AC_WCAP_IN_AMP;
3433 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003434 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003435 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003436 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3437 if (!nums)
3438 return 0;
3439 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003440 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3441 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003442 if (err < 0)
3443 return err;
3444 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003445}
3446
Matt Porter8b657272006-10-26 17:12:59 +02003447/* create playback/capture controls for input pins on dmic capable codecs */
3448static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3449 const struct auto_pin_cfg *cfg)
3450{
3451 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003452 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003453 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003454 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003455 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003456
Takashi Iwai10a20af2010-09-09 16:28:02 +02003457 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Takashi Iwai5207e102009-07-30 13:09:08 +02003458
Matt Porter8b657272006-10-26 17:12:59 +02003459 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003460 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003461 int index, type_idx;
Takashi Iwai5207e102009-07-30 13:09:08 +02003462 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003463
Takashi Iwai667067d2009-08-13 18:14:42 +02003464 nid = spec->dmic_nids[i];
3465 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3466 continue;
3467 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003468 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3469 continue;
3470
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003471 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3472 if (index < 0)
3473 continue;
3474
Takashi Iwai10a20af2010-09-09 16:28:02 +02003475 label = hda_get_input_pin_label(codec, nid, 1);
3476 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003477
Takashi Iwai10a20af2010-09-09 16:28:02 +02003478 err = create_elem_capture_vol(codec, nid, label, type_idx,
3479 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003480 if (err < 0)
3481 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003482 if (!err) {
3483 err = create_elem_capture_vol(codec, nid, label,
Takashi Iwai10a20af2010-09-09 16:28:02 +02003484 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003485 if (err < 0)
3486 return err;
3487 }
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003488
Takashi Iwai5207e102009-07-30 13:09:08 +02003489 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02003490 snd_hda_add_imux_item(imux, label, index, NULL);
Vitaliy Kulikovf41cc2a2010-09-24 16:21:53 -05003491 spec->num_analog_muxes++;
Takashi Iwai5207e102009-07-30 13:09:08 +02003492 }
Matt Porter8b657272006-10-26 17:12:59 +02003493 }
3494
3495 return 0;
3496}
3497
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003498static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003499 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003500{
3501 unsigned int cfg;
3502
3503 if (!nid)
3504 return 0;
3505 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003506 switch (snd_hda_get_input_pin_attr(cfg)) {
3507 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003508 if (*fixed)
3509 return 1; /* already occupied */
3510 *fixed = nid;
3511 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003512 case INPUT_PIN_ATTR_UNUSED:
3513 break;
3514 case INPUT_PIN_ATTR_DOCK:
3515 if (*dock)
3516 return 1; /* already occupied */
3517 *dock = nid;
3518 break;
3519 default:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003520 if (*ext)
3521 return 1; /* already occupied */
3522 *ext = nid;
3523 break;
3524 }
3525 return 0;
3526}
3527
3528static int set_mic_route(struct hda_codec *codec,
3529 struct sigmatel_mic_route *mic,
3530 hda_nid_t pin)
3531{
3532 struct sigmatel_spec *spec = codec->spec;
3533 struct auto_pin_cfg *cfg = &spec->autocfg;
3534 int i;
3535
3536 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003537 if (pin == 0)
3538 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003539 for (i = 0; i < cfg->num_inputs; i++) {
3540 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003541 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003542 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003543 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003544 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003545 i = get_connection_index(codec, spec->mux_nids[0], pin);
3546 if (i < 0)
3547 return -1;
3548 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003549 mic->dmux_idx = -1;
3550 if (spec->dmux_nids)
3551 mic->dmux_idx = get_connection_index(codec,
3552 spec->dmux_nids[0],
3553 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003554 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003555 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003556 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3557 if (i < 0)
3558 return -1;
3559 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003560 mic->mux_idx = -1;
3561 if (spec->mux_nids)
3562 mic->mux_idx = get_connection_index(codec,
3563 spec->mux_nids[0],
3564 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003565 }
3566 return 0;
3567}
3568
3569/* return non-zero if the device is for automatic mic switch */
3570static int stac_check_auto_mic(struct hda_codec *codec)
3571{
3572 struct sigmatel_spec *spec = codec->spec;
3573 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02003574 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003575 int i;
3576
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003577 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003578 if (cfg->inputs[i].type >= AUTO_PIN_LINE_IN)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003579 return 0; /* must be exclusively mics */
3580 }
Charles Chin99077902010-09-17 10:22:32 +02003581 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003582 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02003583 if (check_mic_pin(codec, cfg->inputs[i].pin,
3584 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003585 return 0;
3586 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02003587 if (check_mic_pin(codec, spec->dmic_nids[i],
3588 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003589 return 0;
Charles Chin99077902010-09-17 10:22:32 +02003590 if (!fixed && !ext && !dock)
3591 return 0; /* no input to switch */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003592 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3593 return 0; /* no unsol support */
3594 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02003595 set_mic_route(codec, &spec->int_mic, fixed) ||
3596 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003597 return 0; /* something is wrong */
3598 return 1;
3599}
3600
Mattc7d4b2f2005-06-27 14:59:41 +02003601/* create playback/capture controls for input pins */
3602static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3603{
3604 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003605 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003606 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003607 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02003608
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003609 for (i = 0; i < cfg->num_inputs; i++) {
3610 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003611 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02003612
Takashi Iwai314634b2006-09-21 11:56:18 +02003613 index = -1;
3614 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003615 index = get_connection_index(codec, spec->mux_nids[j],
3616 nid);
3617 if (index >= 0)
3618 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003619 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003620 if (index < 0)
3621 continue;
3622
Takashi Iwai10a20af2010-09-09 16:28:02 +02003623 label = hda_get_autocfg_input_label(codec, cfg, i);
3624 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003625
Takashi Iwai667067d2009-08-13 18:14:42 +02003626 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003627 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003628 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003629 if (err < 0)
3630 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003631 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003632 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003633
Steve Longerbeam7b043892007-05-03 20:50:03 +02003634 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003635 /*
3636 * Set the current input for the muxes.
3637 * The STAC9221 has two input muxes with identical source
3638 * NID lists. Hopefully this won't get confused.
3639 */
3640 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003641 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3642 AC_VERB_SET_CONNECT_SEL,
3643 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003644 }
3645 }
3646
Mattc7d4b2f2005-06-27 14:59:41 +02003647 return 0;
3648}
3649
Mattc7d4b2f2005-06-27 14:59:41 +02003650static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3651{
3652 struct sigmatel_spec *spec = codec->spec;
3653 int i;
3654
3655 for (i = 0; i < spec->autocfg.line_outs; i++) {
3656 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3657 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3658 }
3659}
3660
3661static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3662{
3663 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003664 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003665
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003666 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3667 hda_nid_t pin;
3668 pin = spec->autocfg.hp_pins[i];
3669 if (pin) /* connect to front */
3670 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3671 }
3672 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3673 hda_nid_t pin;
3674 pin = spec->autocfg.speaker_pins[i];
3675 if (pin) /* connect to front */
3676 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3677 }
Mattc7d4b2f2005-06-27 14:59:41 +02003678}
3679
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003680static int is_dual_headphones(struct hda_codec *codec)
3681{
3682 struct sigmatel_spec *spec = codec->spec;
3683 int i, valid_hps;
3684
3685 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3686 spec->autocfg.hp_outs <= 1)
3687 return 0;
3688 valid_hps = 0;
3689 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3690 hda_nid_t nid = spec->autocfg.hp_pins[i];
3691 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3692 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3693 continue;
3694 valid_hps++;
3695 }
3696 return (valid_hps > 1);
3697}
3698
3699
Matt Porter3cc08dc2006-01-23 15:27:49 +01003700static 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 +02003701{
3702 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003703 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003704 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003705
Matt Porter8b657272006-10-26 17:12:59 +02003706 if ((err = snd_hda_parse_pin_def_config(codec,
3707 &spec->autocfg,
3708 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003709 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003710 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003711 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003712
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003713 /* If we have no real line-out pin and multiple hp-outs, HPs should
3714 * be set up as multi-channel outputs.
3715 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003716 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003717 /* Copy hp_outs to line_outs, backup line_outs in
3718 * speaker_outs so that the following routines can handle
3719 * HP pins as primary outputs.
3720 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003721 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003722 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3723 sizeof(spec->autocfg.line_out_pins));
3724 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3725 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3726 sizeof(spec->autocfg.hp_pins));
3727 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003728 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3729 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003730 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003731 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003732 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003733 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3734 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003735 u32 caps = query_amp_caps(codec,
3736 spec->autocfg.mono_out_pin, dir);
3737 hda_nid_t conn_list[1];
3738
3739 /* get the mixer node and then the mono mux if it exists */
3740 if (snd_hda_get_connections(codec,
3741 spec->autocfg.mono_out_pin, conn_list, 1) &&
3742 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003743 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003744
3745 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003746 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003747 /* LR swap check, some stac925x have a mux that
3748 * changes the DACs output path instead of the
3749 * mono-mux path.
3750 */
3751 if (wid_type == AC_WID_AUD_SEL &&
3752 !(wcaps & AC_WCAP_LR_SWAP))
3753 spec->mono_nid = conn_list[0];
3754 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003755 if (dir) {
3756 hda_nid_t nid = spec->autocfg.mono_out_pin;
3757
3758 /* most mono outs have a least a mute/unmute switch */
3759 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3760 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3761 "Mono Playback Switch",
3762 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003763 if (err < 0)
3764 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003765 /* check for volume support for the amp */
3766 if ((caps & AC_AMPCAP_NUM_STEPS)
3767 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3768 err = stac92xx_add_control(spec,
3769 STAC_CTL_WIDGET_VOL,
3770 "Mono Playback Volume",
3771 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3772 if (err < 0)
3773 return err;
3774 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003775 }
3776
3777 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3778 AC_PINCTL_OUT_EN);
3779 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003780
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003781 if (!spec->multiout.num_dacs) {
3782 err = stac92xx_auto_fill_dac_nids(codec);
3783 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003784 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003785 err = stac92xx_auto_create_multi_out_ctls(codec,
3786 &spec->autocfg);
3787 if (err < 0)
3788 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003789 }
Mattc7d4b2f2005-06-27 14:59:41 +02003790
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003791 /* setup analog beep controls */
3792 if (spec->anabeep_nid > 0) {
3793 err = stac92xx_auto_create_beep_ctls(codec,
3794 spec->anabeep_nid);
3795 if (err < 0)
3796 return err;
3797 }
3798
3799 /* setup digital beep controls and input device */
3800#ifdef CONFIG_SND_HDA_INPUT_BEEP
3801 if (spec->digbeep_nid > 0) {
3802 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003803 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003804
3805 err = stac92xx_auto_create_beep_ctls(codec, nid);
3806 if (err < 0)
3807 return err;
3808 err = snd_hda_attach_beep_device(codec, nid);
3809 if (err < 0)
3810 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003811 if (codec->beep) {
3812 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01003813 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003814 /* if no beep switch is available, make its own one */
3815 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3816 if (!(caps & AC_AMPCAP_MUTE)) {
3817 err = stac92xx_beep_switch_ctl(codec);
3818 if (err < 0)
3819 return err;
3820 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003821 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003822 }
3823#endif
3824
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003825 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003826 if (err < 0)
3827 return err;
3828
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003829 /* All output parsing done, now restore the swapped hp pins */
3830 if (hp_swap) {
3831 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3832 sizeof(spec->autocfg.hp_pins));
3833 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3834 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3835 spec->autocfg.line_outs = 0;
3836 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003837
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003838 if (stac_check_auto_mic(codec)) {
3839 spec->auto_mic = 1;
3840 /* only one capture for auto-mic */
3841 spec->num_adcs = 1;
3842 spec->num_caps = 1;
3843 spec->num_muxes = 1;
3844 }
3845
Takashi Iwai6479c632009-07-28 18:20:25 +02003846 for (i = 0; i < spec->num_caps; i++) {
3847 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3848 spec->capsws[i], i);
3849 if (err < 0)
3850 return err;
3851 }
3852
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003853 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003854 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003855 return err;
3856
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003857 if (spec->mono_nid > 0) {
3858 err = stac92xx_auto_create_mono_output_ctls(codec);
3859 if (err < 0)
3860 return err;
3861 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003862 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003863 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3864 &spec->autocfg)) < 0)
3865 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003866 if (spec->num_muxes > 0) {
3867 err = stac92xx_auto_create_mux_input_ctls(codec);
3868 if (err < 0)
3869 return err;
3870 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003871 if (spec->num_smuxes > 0) {
3872 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3873 if (err < 0)
3874 return err;
3875 }
Matt Porter8b657272006-10-26 17:12:59 +02003876
Takashi Iwaie3c75962009-01-23 11:57:22 +01003877 err = stac92xx_add_input_source(spec);
3878 if (err < 0)
3879 return err;
3880
Mattc7d4b2f2005-06-27 14:59:41 +02003881 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003882 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003883 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003884
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003885 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003886 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003887 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003888 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003889
Takashi Iwai603c4012008-07-30 15:01:44 +02003890 if (spec->kctls.list)
3891 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003892
3893 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003894 if (!spec->dinput_mux)
3895 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003896 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003897 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003898 return 1;
3899}
3900
Takashi Iwai82bc9552006-03-21 11:24:42 +01003901/* add playback controls for HP output */
3902static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3903 struct auto_pin_cfg *cfg)
3904{
3905 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003906 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003907 unsigned int wid_caps;
3908
3909 if (! pin)
3910 return 0;
3911
3912 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003913 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003914 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003915
3916 return 0;
3917}
3918
Richard Fish160ea0d2006-09-06 13:58:25 +02003919/* add playback controls for LFE output */
3920static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3921 struct auto_pin_cfg *cfg)
3922{
3923 struct sigmatel_spec *spec = codec->spec;
3924 int err;
3925 hda_nid_t lfe_pin = 0x0;
3926 int i;
3927
3928 /*
3929 * search speaker outs and line outs for a mono speaker pin
3930 * with an amp. If one is found, add LFE controls
3931 * for it.
3932 */
3933 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3934 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003935 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003936 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3937 if (wcaps == AC_WCAP_OUT_AMP)
3938 /* found a mono speaker with an amp, must be lfe */
3939 lfe_pin = pin;
3940 }
3941
3942 /* if speaker_outs is 0, then speakers may be in line_outs */
3943 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3944 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3945 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003946 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01003947 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01003948 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003949 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003950 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3951 if (wcaps == AC_WCAP_OUT_AMP)
3952 /* found a mono speaker with an amp,
3953 must be lfe */
3954 lfe_pin = pin;
3955 }
3956 }
3957 }
3958
3959 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003960 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003961 if (err < 0)
3962 return err;
3963 }
3964
3965 return 0;
3966}
3967
Mattc7d4b2f2005-06-27 14:59:41 +02003968static int stac9200_parse_auto_config(struct hda_codec *codec)
3969{
3970 struct sigmatel_spec *spec = codec->spec;
3971 int err;
3972
Kailang Yangdf694da2005-12-05 19:42:22 +01003973 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003974 return err;
3975
3976 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3977 return err;
3978
Takashi Iwai82bc9552006-03-21 11:24:42 +01003979 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3980 return err;
3981
Richard Fish160ea0d2006-09-06 13:58:25 +02003982 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3983 return err;
3984
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003985 if (spec->num_muxes > 0) {
3986 err = stac92xx_auto_create_mux_input_ctls(codec);
3987 if (err < 0)
3988 return err;
3989 }
3990
Takashi Iwaie3c75962009-01-23 11:57:22 +01003991 err = stac92xx_add_input_source(spec);
3992 if (err < 0)
3993 return err;
3994
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003995 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02003996 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003997 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003998 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003999
Takashi Iwai603c4012008-07-30 15:01:44 +02004000 if (spec->kctls.list)
4001 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004002
4003 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004004 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004005
4006 return 1;
4007}
4008
Sam Revitch62fe78e2006-05-10 15:09:17 +02004009/*
4010 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4011 * funky external mute control using GPIO pins.
4012 */
4013
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004014static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004015 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004016{
4017 unsigned int gpiostate, gpiomask, gpiodir;
4018
4019 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4020 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004021 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004022
4023 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4024 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004025 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004026
4027 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4028 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004029 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004030
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004031 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004032 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4033
4034 snd_hda_codec_write(codec, codec->afg, 0,
4035 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004036 snd_hda_codec_read(codec, codec->afg, 0,
4037 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004038
4039 msleep(1);
4040
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004041 snd_hda_codec_read(codec, codec->afg, 0,
4042 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004043}
4044
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004045#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +02004046static void stac92xx_free_jack_priv(struct snd_jack *jack)
4047{
4048 struct sigmatel_jack *jacks = jack->private_data;
4049 jacks->nid = 0;
4050 jacks->jack = NULL;
4051}
4052#endif
4053
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004054static int stac92xx_add_jack(struct hda_codec *codec,
4055 hda_nid_t nid, int type)
4056{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004057#ifdef CONFIG_SND_HDA_INPUT_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004058 struct sigmatel_spec *spec = codec->spec;
4059 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01004060 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004061 int connectivity = get_defcfg_connect(def_conf);
4062 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02004063 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004064
4065 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4066 return 0;
4067
4068 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4069 jack = snd_array_new(&spec->jacks);
4070 if (!jack)
4071 return -ENOMEM;
4072 jack->nid = nid;
4073 jack->type = type;
4074
Takashi Iwai86de7412009-07-22 16:02:46 +02004075 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004076 snd_hda_get_jack_type(def_conf),
4077 snd_hda_get_jack_connectivity(def_conf),
4078 snd_hda_get_jack_location(def_conf));
4079
Takashi Iwai95c09092009-04-14 16:15:29 +02004080 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4081 if (err < 0) {
4082 jack->nid = 0;
4083 return err;
4084 }
4085 jack->jack->private_data = jack;
4086 jack->jack->private_free = stac92xx_free_jack_priv;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004087#endif
Takashi Iwai95c09092009-04-14 16:15:29 +02004088 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004089}
4090
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004091static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4092 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004093{
4094 struct sigmatel_event *event;
4095
4096 snd_array_init(&spec->events, sizeof(*event), 32);
4097 event = snd_array_new(&spec->events);
4098 if (!event)
4099 return -ENOMEM;
4100 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004101 event->type = type;
4102 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004103 event->data = data;
4104
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004105 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004106}
4107
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004108static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004109 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004110{
4111 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004112 struct sigmatel_event *event = spec->events.list;
4113 int i;
4114
4115 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004116 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004117 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004118 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004119 return NULL;
4120}
4121
4122static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4123 unsigned char tag)
4124{
4125 struct sigmatel_spec *spec = codec->spec;
4126 struct sigmatel_event *event = spec->events.list;
4127 int i;
4128
4129 for (i = 0; i < spec->events.used; i++, event++) {
4130 if (event->tag == tag)
4131 return event;
4132 }
4133 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004134}
4135
Takashi Iwai62558ce2009-07-29 14:23:09 +02004136/* check if given nid is a valid pin and no other events are assigned
4137 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4138 * Otherwise, returns zero.
4139 */
4140static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4141 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004142{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004143 struct sigmatel_event *event;
4144 int tag;
4145
4146 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004147 return 0;
4148 event = stac_get_event(codec, nid);
4149 if (event) {
4150 if (event->type != type)
4151 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004152 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004153 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004154 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004155 if (tag < 0)
4156 return 0;
4157 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004158 snd_hda_codec_write_cache(codec, nid, 0,
4159 AC_VERB_SET_UNSOLICITED_ENABLE,
4160 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004161 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004162}
4163
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004164static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4165{
4166 int i;
4167 for (i = 0; i < cfg->hp_outs; i++)
4168 if (cfg->hp_pins[i] == nid)
4169 return 1; /* nid is a HP-Out */
4170
4171 return 0; /* nid is not a HP-Out */
4172};
4173
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004174static void stac92xx_power_down(struct hda_codec *codec)
4175{
4176 struct sigmatel_spec *spec = codec->spec;
4177
4178 /* power down inactive DACs */
4179 hda_nid_t *dac;
4180 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004181 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004182 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004183 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4184}
4185
Takashi Iwaif73d3582008-11-25 08:21:51 +01004186static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4187 int enable);
4188
Takashi Iwai014c41f2009-12-27 13:53:24 +01004189static inline int get_int_hint(struct hda_codec *codec, const char *key,
4190 int *valp)
4191{
4192 const char *p;
4193 p = snd_hda_get_hint(codec, key);
4194 if (p) {
4195 unsigned long val;
4196 if (!strict_strtoul(p, 0, &val)) {
4197 *valp = val;
4198 return 1;
4199 }
4200 }
4201 return 0;
4202}
4203
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004204/* override some hints from the hwdep entry */
4205static void stac_store_hints(struct hda_codec *codec)
4206{
4207 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004208 int val;
4209
4210 val = snd_hda_get_bool_hint(codec, "hp_detect");
4211 if (val >= 0)
4212 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004213 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004214 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4215 spec->gpio_mask;
4216 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004217 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4218 spec->gpio_mask &= spec->gpio_mask;
4219 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4220 spec->gpio_dir &= spec->gpio_mask;
4221 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4222 spec->eapd_mask &= spec->gpio_mask;
4223 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4224 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004225 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4226 if (val >= 0)
4227 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004228 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4229 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Takashi Iwai043958e2009-12-26 10:36:12 +01004230 spec->gpio_mask |= spec->gpio_led;
4231 spec->gpio_dir |= spec->gpio_led;
4232 if (spec->gpio_led_polarity)
4233 spec->gpio_data |= spec->gpio_led;
4234 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004235}
4236
Mattc7d4b2f2005-06-27 14:59:41 +02004237static int stac92xx_init(struct hda_codec *codec)
4238{
4239 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004240 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004241 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004242 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004243
Mattc7d4b2f2005-06-27 14:59:41 +02004244 snd_hda_sequence_write(codec, spec->init);
4245
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004246 /* power down adcs initially */
4247 if (spec->powerdown_adcs)
4248 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004249 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004250 spec->adc_nids[i], 0,
4251 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004252
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004253 /* override some hints */
4254 stac_store_hints(codec);
4255
Takashi Iwaif73d3582008-11-25 08:21:51 +01004256 /* set up GPIO */
4257 gpio = spec->gpio_data;
4258 /* turn on EAPD statically when spec->eapd_switch isn't set.
4259 * otherwise, unsol event will turn it on/off dynamically
4260 */
4261 if (!spec->eapd_switch)
4262 gpio |= spec->eapd_mask;
4263 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4264
Takashi Iwai82bc9552006-03-21 11:24:42 +01004265 /* set up pins */
4266 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004267 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004268 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004269 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004270 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004271 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004272 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4273 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004274 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004275 for (i = 0; i < cfg->line_outs; i++) {
4276 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004277 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4278 }
4279 }
4280
Takashi Iwai0a07aca2007-03-13 10:40:23 +01004281 /* force to enable the first line-out; the others are set up
4282 * in unsol_event
4283 */
4284 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004285 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004286 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004287 if (cfg->hp_pins[0])
4288 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4289 else if (cfg->line_out_pins[0])
4290 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004291 } else {
4292 stac92xx_auto_init_multi_out(codec);
4293 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004294 for (i = 0; i < cfg->hp_outs; i++)
4295 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004296 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004297 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004298 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004299 if (spec->dmux_nids)
4300 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004301 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004302 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4303 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004304 if (enable_pin_detect(codec, spec->dock_mic.pin,
4305 STAC_MIC_EVENT))
4306 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004307 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004308 for (i = 0; i < cfg->num_inputs; i++) {
4309 hda_nid_t nid = cfg->inputs[i].pin;
4310 int type = cfg->inputs[i].type;
4311 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004312 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004313 /* for mic pins, force to initialize */
4314 pinctl = stac92xx_get_default_vref(codec, nid);
4315 pinctl |= AC_PINCTL_IN_EN;
4316 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4317 } else {
4318 pinctl = snd_hda_codec_read(codec, nid, 0,
4319 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4320 /* if PINCTL already set then skip */
4321 /* Also, if both INPUT and OUTPUT are set,
4322 * it must be a BIOS bug; need to override, too
4323 */
4324 if (!(pinctl & AC_PINCTL_IN_EN) ||
4325 (pinctl & AC_PINCTL_OUT_EN)) {
4326 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004327 pinctl |= AC_PINCTL_IN_EN;
4328 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004329 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004330 }
4331 conf = snd_hda_codec_get_pincfg(codec, nid);
4332 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4333 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4334 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004335 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004336 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004337 for (i = 0; i < spec->num_dmics; i++)
4338 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4339 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004340 if (cfg->dig_out_pins[0])
4341 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004342 AC_PINCTL_OUT_EN);
4343 if (cfg->dig_in_pin)
4344 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4345 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004346 for (i = 0; i < spec->num_pwrs; i++) {
4347 hda_nid_t nid = spec->pwr_nids[i];
4348 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004349
Takashi Iwaieb632122008-12-19 16:39:48 +01004350 /* power on when no jack detection is available */
4351 if (!spec->hp_detect) {
4352 stac_toggle_power_map(codec, nid, 1);
4353 continue;
4354 }
4355
4356 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004357 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004358
Takashi Iwaif73d3582008-11-25 08:21:51 +01004359 pinctl = snd_hda_codec_read(codec, nid, 0,
4360 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4361 /* outputs are only ports capable of power management
4362 * any attempts on powering down a input port cause the
4363 * referenced VREF to act quirky.
4364 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004365 if (pinctl & AC_PINCTL_IN_EN) {
4366 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004367 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004368 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004369 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004370 def_conf = get_defcfg_connect(def_conf);
4371 /* skip any ports that don't have jacks since presence
4372 * detection is useless */
4373 if (def_conf != AC_JACK_PORT_COMPLEX) {
4374 if (def_conf != AC_JACK_PORT_NONE)
4375 stac_toggle_power_map(codec, nid, 1);
4376 continue;
4377 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004378 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4379 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004380 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004381
Takashi Iwaic21bd022010-02-08 15:16:08 +01004382 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004383 if (spec->gpio_led)
4384 hda_call_check_power_status(codec, 0x01);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004385 if (spec->dac_list)
4386 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004387 return 0;
4388}
4389
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004390static void stac92xx_free_jacks(struct hda_codec *codec)
4391{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004392#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwaib94d3532008-11-21 09:08:06 +01004393 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004394 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d3532008-11-21 09:08:06 +01004395 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004396 struct sigmatel_jack *jacks = spec->jacks.list;
4397 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +02004398 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4399 if (jacks->jack)
4400 snd_device_free(codec->bus->card, jacks->jack);
4401 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004402 }
4403 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004404#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004405}
4406
Takashi Iwai603c4012008-07-30 15:01:44 +02004407static void stac92xx_free_kctls(struct hda_codec *codec)
4408{
4409 struct sigmatel_spec *spec = codec->spec;
4410
4411 if (spec->kctls.list) {
4412 struct snd_kcontrol_new *kctl = spec->kctls.list;
4413 int i;
4414 for (i = 0; i < spec->kctls.used; i++)
4415 kfree(kctl[i].name);
4416 }
4417 snd_array_free(&spec->kctls);
4418}
4419
Takashi Iwai167eae52009-11-06 15:47:50 +01004420static void stac92xx_shutup(struct hda_codec *codec)
4421{
4422 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004423
Takashi Iwai92ee6162009-12-27 11:18:59 +01004424 snd_hda_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004425
4426 if (spec->eapd_mask)
4427 stac_gpio_set(codec, spec->gpio_mask,
4428 spec->gpio_dir, spec->gpio_data &
4429 ~spec->eapd_mask);
4430}
4431
Matt2f2f4252005-04-13 14:45:30 +02004432static void stac92xx_free(struct hda_codec *codec)
4433{
Mattc7d4b2f2005-06-27 14:59:41 +02004434 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004435
4436 if (! spec)
4437 return;
4438
Takashi Iwai167eae52009-11-06 15:47:50 +01004439 stac92xx_shutup(codec);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004440 stac92xx_free_jacks(codec);
4441 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004442
Mattc7d4b2f2005-06-27 14:59:41 +02004443 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004444 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004445}
4446
Matt4e550962005-07-04 17:51:39 +02004447static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4448 unsigned int flag)
4449{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004450 unsigned int old_ctl, pin_ctl;
4451
4452 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004453 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004454
Takashi Iwaif9acba42007-05-29 18:01:06 +02004455 if (pin_ctl & AC_PINCTL_IN_EN) {
4456 /*
4457 * we need to check the current set-up direction of
4458 * shared input pins since they can be switched via
4459 * "xxx as Output" mixer switch
4460 */
4461 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004462 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004463 return;
4464 }
4465
Takashi Iwai8ce84192009-01-22 16:59:20 +01004466 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004467 /* if setting pin direction bits, clear the current
4468 direction bits first */
4469 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4470 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4471
Takashi Iwai8ce84192009-01-22 16:59:20 +01004472 pin_ctl |= flag;
4473 if (old_ctl != pin_ctl)
4474 snd_hda_codec_write_cache(codec, nid, 0,
4475 AC_VERB_SET_PIN_WIDGET_CONTROL,
4476 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004477}
4478
4479static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4480 unsigned int flag)
4481{
4482 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4483 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004484 if (pin_ctl & flag)
4485 snd_hda_codec_write_cache(codec, nid, 0,
4486 AC_VERB_SET_PIN_WIDGET_CONTROL,
4487 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004488}
4489
Takashi Iwaid56757a2009-11-18 08:00:14 +01004490static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004491{
4492 if (!nid)
4493 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004494 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004495}
4496
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004497static void stac92xx_line_out_detect(struct hda_codec *codec,
4498 int presence)
4499{
4500 struct sigmatel_spec *spec = codec->spec;
4501 struct auto_pin_cfg *cfg = &spec->autocfg;
4502 int i;
4503
4504 for (i = 0; i < cfg->line_outs; i++) {
4505 if (presence)
4506 break;
4507 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4508 if (presence) {
4509 unsigned int pinctl;
4510 pinctl = snd_hda_codec_read(codec,
4511 cfg->line_out_pins[i], 0,
4512 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4513 if (pinctl & AC_PINCTL_IN_EN)
4514 presence = 0; /* mic- or line-input */
4515 }
4516 }
4517
4518 if (presence) {
4519 /* disable speakers */
4520 for (i = 0; i < cfg->speaker_outs; i++)
4521 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4522 AC_PINCTL_OUT_EN);
4523 if (spec->eapd_mask && spec->eapd_switch)
4524 stac_gpio_set(codec, spec->gpio_mask,
4525 spec->gpio_dir, spec->gpio_data &
4526 ~spec->eapd_mask);
4527 } else {
4528 /* enable speakers */
4529 for (i = 0; i < cfg->speaker_outs; i++)
4530 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4531 AC_PINCTL_OUT_EN);
4532 if (spec->eapd_mask && spec->eapd_switch)
4533 stac_gpio_set(codec, spec->gpio_mask,
4534 spec->gpio_dir, spec->gpio_data |
4535 spec->eapd_mask);
4536 }
4537}
4538
Takashi Iwaid7a89432008-11-12 09:48:04 +01004539/* return non-zero if the hp-pin of the given array index isn't
4540 * a jack-detection target
4541 */
4542static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4543{
4544 struct auto_pin_cfg *cfg = &spec->autocfg;
4545
4546 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004547 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004548 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004549 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004550 return 1;
4551 /* ignore if the pin is set as line-out */
4552 if (cfg->hp_pins[i] == spec->hp_switch)
4553 return 1;
4554 return 0;
4555}
4556
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004557static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004558{
4559 struct sigmatel_spec *spec = codec->spec;
4560 struct auto_pin_cfg *cfg = &spec->autocfg;
4561 int i, presence;
4562
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004563 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004564 if (spec->gpio_mute)
4565 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4566 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4567
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004568 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004569 if (presence)
4570 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004571 if (no_hp_sensing(spec, i))
4572 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004573 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4574 if (presence) {
4575 unsigned int pinctl;
4576 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4577 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4578 if (pinctl & AC_PINCTL_IN_EN)
4579 presence = 0; /* mic- or line-input */
4580 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004581 }
Matt4e550962005-07-04 17:51:39 +02004582
4583 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004584 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004585 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004586 stac92xx_reset_pinctl(codec, spec->hp_switch,
4587 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004588 for (i = 0; i < cfg->line_outs; i++)
4589 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4590 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004591 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004592 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004593 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004594 stac92xx_set_pinctl(codec, spec->hp_switch,
4595 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004596 for (i = 0; i < cfg->line_outs; i++)
4597 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4598 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004599 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004600 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004601 /* toggle hp outs */
4602 for (i = 0; i < cfg->hp_outs; i++) {
4603 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4604 if (no_hp_sensing(spec, i))
4605 continue;
4606 if (presence)
4607 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004608#if 0 /* FIXME */
4609/* Resetting the pinctl like below may lead to (a sort of) regressions
4610 * on some devices since they use the HP pin actually for line/speaker
4611 * outs although the default pin config shows a different pin (that is
4612 * wrong and useless).
4613 *
4614 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4615 * But, disabling the code below just works around it, and I'm too tired of
4616 * bug reports with such devices...
4617 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004618 else
4619 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004620#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004621 }
Matt4e550962005-07-04 17:51:39 +02004622}
4623
Takashi Iwaif73d3582008-11-25 08:21:51 +01004624static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4625 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004626{
4627 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004628 unsigned int idx, val;
4629
4630 for (idx = 0; idx < spec->num_pwrs; idx++) {
4631 if (spec->pwr_nids[idx] == nid)
4632 break;
4633 }
4634 if (idx >= spec->num_pwrs)
4635 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004636
4637 /* several codecs have two power down bits */
4638 if (spec->pwr_mapping)
4639 idx = spec->pwr_mapping[idx];
4640 else
4641 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004642
Takashi Iwaif73d3582008-11-25 08:21:51 +01004643 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4644 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004645 val &= ~idx;
4646 else
4647 val |= idx;
4648
4649 /* power down unused output ports */
4650 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004651}
4652
Takashi Iwaif73d3582008-11-25 08:21:51 +01004653static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4654{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004655 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004656}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004657
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004658static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4659{
4660 struct sigmatel_spec *spec = codec->spec;
4661 struct sigmatel_jack *jacks = spec->jacks.list;
4662
4663 if (jacks) {
4664 int i;
4665 for (i = 0; i < spec->jacks.used; i++) {
4666 if (jacks->nid == nid) {
4667 unsigned int pin_ctl =
4668 snd_hda_codec_read(codec, nid,
4669 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4670 0x00);
4671 int type = jacks->type;
4672 if (type == (SND_JACK_LINEOUT
4673 | SND_JACK_HEADPHONE))
4674 type = (pin_ctl & AC_PINCTL_HP_EN)
4675 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4676 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004677 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004678 ? type : 0);
4679 }
4680 jacks++;
4681 }
4682 }
4683}
Matt2f2f4252005-04-13 14:45:30 +02004684
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004685/* get the pin connection (fixed, none, etc) */
4686static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4687{
4688 struct sigmatel_spec *spec = codec->spec;
4689 unsigned int cfg;
4690
4691 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4692 return get_defcfg_connect(cfg);
4693}
4694
4695static int stac92xx_connected_ports(struct hda_codec *codec,
4696 hda_nid_t *nids, int num_nids)
4697{
4698 struct sigmatel_spec *spec = codec->spec;
4699 int idx, num;
4700 unsigned int def_conf;
4701
4702 for (num = 0; num < num_nids; num++) {
4703 for (idx = 0; idx < spec->num_pins; idx++)
4704 if (spec->pin_nids[idx] == nids[num])
4705 break;
4706 if (idx >= spec->num_pins)
4707 break;
4708 def_conf = stac_get_defcfg_connect(codec, idx);
4709 if (def_conf == AC_JACK_PORT_NONE)
4710 break;
4711 }
4712 return num;
4713}
4714
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004715static void stac92xx_mic_detect(struct hda_codec *codec)
4716{
4717 struct sigmatel_spec *spec = codec->spec;
4718 struct sigmatel_mic_route *mic;
4719
4720 if (get_pin_presence(codec, spec->ext_mic.pin))
4721 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02004722 else if (get_pin_presence(codec, spec->dock_mic.pin))
4723 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004724 else
4725 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004726 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004727 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4728 AC_VERB_SET_CONNECT_SEL,
4729 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004730 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004731 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4732 AC_VERB_SET_CONNECT_SEL,
4733 mic->mux_idx);
4734}
4735
Takashi Iwai62558ce2009-07-29 14:23:09 +02004736static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004737{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004738 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004739 if (!event)
4740 return;
4741 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4742}
4743
Takashi Iwai314634b2006-09-21 11:56:18 +02004744static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4745{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004746 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004747 struct sigmatel_event *event;
4748 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004749
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004750 tag = (res >> 26) & 0x7f;
4751 event = stac_get_event_from_tag(codec, tag);
4752 if (!event)
4753 return;
4754
4755 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004756 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004757 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004758 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004759 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004760 case STAC_MIC_EVENT:
4761 stac92xx_mic_detect(codec);
4762 break;
4763 }
4764
4765 switch (event->type) {
4766 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004767 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004768 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004769 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004770 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004771 if (spec->num_pwrs > 0)
4772 stac92xx_pin_sense(codec, event->nid);
4773 stac92xx_report_jack(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004774
4775 switch (codec->subsystem_id) {
4776 case 0x103c308f:
4777 if (event->nid == 0xb) {
4778 int pin = AC_PINCTL_IN_EN;
4779
4780 if (get_pin_presence(codec, 0xa)
4781 && get_pin_presence(codec, 0xb))
4782 pin |= AC_PINCTL_VREF_80;
4783 if (!get_pin_presence(codec, 0xb))
4784 pin |= AC_PINCTL_VREF_80;
4785
4786 /* toggle VREF state based on mic + hp pin
4787 * status
4788 */
4789 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4790 }
4791 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004792 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004793 case STAC_VREF_EVENT:
4794 data = snd_hda_codec_read(codec, codec->afg, 0,
4795 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004796 /* toggle VREF state based on GPIOx status */
4797 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004798 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004799 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004800 }
4801}
4802
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304803static int hp_blike_system(u32 subsystem_id);
4804
4805static void set_hp_led_gpio(struct hda_codec *codec)
4806{
4807 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004808 unsigned int gpio;
4809
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004810 if (spec->gpio_led)
4811 return;
4812
Takashi Iwai07f80442010-02-08 15:06:13 +01004813 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4814 gpio &= AC_GPIO_IO_COUNT;
4815 if (gpio > 3)
4816 spec->gpio_led = 0x08; /* GPIO 3 */
4817 else
4818 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304819}
4820
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004821/*
4822 * This method searches for the mute LED GPIO configuration
4823 * provided as OEM string in SMBIOS. The format of that string
4824 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4825 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4826 * that corresponds to the NOT muted state of the master volume
4827 * and G is the index of the GPIO to use as the mute LED control (0..9)
4828 * If _G portion is missing it is assigned based on the codec ID
4829 *
4830 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4831 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304832 *
4833 *
4834 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4835 * SMBIOS - at least the ones I have seen do not have them - which include
4836 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4837 * HP Pavilion dv9500t CTO.
4838 * Need more information on whether it is true across the entire series.
4839 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004840 */
Takashi Iwaidce17d42010-02-09 09:25:26 +01004841static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004842{
4843 struct sigmatel_spec *spec = codec->spec;
4844 const struct dmi_device *dev = NULL;
4845
4846 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4847 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4848 NULL, dev))) {
4849 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304850 &spec->gpio_led_polarity,
4851 &spec->gpio_led) == 2) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004852 spec->gpio_led = 1 << spec->gpio_led;
4853 return 1;
4854 }
4855 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304856 &spec->gpio_led_polarity) == 1) {
4857 set_hp_led_gpio(codec);
4858 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004859 }
4860 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304861
4862 /*
4863 * Fallback case - if we don't find the DMI strings,
4864 * we statically set the GPIO - if not a B-series system.
4865 */
4866 if (!hp_blike_system(codec->subsystem_id)) {
4867 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004868 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304869 return 1;
4870 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004871 }
4872 return 0;
4873}
4874
4875static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004876{
4877 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004878 case 0x103c1520:
4879 case 0x103c1521:
4880 case 0x103c1523:
4881 case 0x103c1524:
4882 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004883 case 0x103c1722:
4884 case 0x103c1723:
4885 case 0x103c1724:
4886 case 0x103c1725:
4887 case 0x103c1726:
4888 case 0x103c1727:
4889 case 0x103c1728:
4890 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004891 case 0x103c172a:
4892 case 0x103c172b:
4893 case 0x103c307e:
4894 case 0x103c307f:
4895 case 0x103c3080:
4896 case 0x103c3081:
4897 case 0x103c7007:
4898 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004899 return 1;
4900 }
4901 return 0;
4902}
4903
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004904#ifdef CONFIG_PROC_FS
4905static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4906 struct hda_codec *codec, hda_nid_t nid)
4907{
4908 if (nid == codec->afg)
4909 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4910 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4911}
4912
4913static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4914 struct hda_codec *codec,
4915 unsigned int verb)
4916{
4917 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4918 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4919}
4920
4921/* stac92hd71bxx, stac92hd73xx */
4922static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4923 struct hda_codec *codec, hda_nid_t nid)
4924{
4925 stac92hd_proc_hook(buffer, codec, nid);
4926 if (nid == codec->afg)
4927 analog_loop_proc_hook(buffer, codec, 0xfa0);
4928}
4929
4930static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4931 struct hda_codec *codec, hda_nid_t nid)
4932{
4933 if (nid == codec->afg)
4934 analog_loop_proc_hook(buffer, codec, 0xfe0);
4935}
4936
4937static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4938 struct hda_codec *codec, hda_nid_t nid)
4939{
4940 if (nid == codec->afg)
4941 analog_loop_proc_hook(buffer, codec, 0xfeb);
4942}
4943#else
4944#define stac92hd_proc_hook NULL
4945#define stac92hd7x_proc_hook NULL
4946#define stac9205_proc_hook NULL
4947#define stac927x_proc_hook NULL
4948#endif
4949
Takashi Iwaicb53c622007-08-10 17:21:45 +02004950#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004951static int stac92xx_resume(struct hda_codec *codec)
4952{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004953 struct sigmatel_spec *spec = codec->spec;
4954
Takashi Iwai2c885872008-11-18 09:36:55 +01004955 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004956 snd_hda_codec_resume_amp(codec);
4957 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004958 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004959 if (spec->hp_detect) {
4960 if (spec->autocfg.hp_pins[0])
4961 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4962 else if (spec->autocfg.line_out_pins[0])
4963 stac_issue_unsol_event(codec,
4964 spec->autocfg.line_out_pins[0]);
4965 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004966 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004967 if (spec->gpio_led)
4968 hda_call_check_power_status(codec, 0x01);
Mattff6fdc32005-06-27 15:06:52 +02004969 return 0;
4970}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004971
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004972/*
James Gardiner514bf542009-05-03 04:00:44 -04004973 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004974 * check for mute state only on Speakers (nid = 0x10)
4975 *
4976 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4977 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004978 *
4979 * Changed name to reflect that it now works for any designated
4980 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004981 */
4982
4983#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004984static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004985 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004986{
4987 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21bd022010-02-08 15:16:08 +01004988 int i, muted = 1;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004989
Takashi Iwaic21bd022010-02-08 15:16:08 +01004990 for (i = 0; i < spec->multiout.num_dacs; i++) {
4991 nid = spec->multiout.dac_nids[i];
4992 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4993 HDA_AMP_MUTE)) {
4994 muted = 0; /* something heard */
4995 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01004996 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004997 }
4998 if (muted)
4999 spec->gpio_data &= ~spec->gpio_led; /* orange */
5000 else
5001 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005002
Takashi Iwaic21bd022010-02-08 15:16:08 +01005003 if (!spec->gpio_led_polarity) {
5004 /* LED state is inverted on these systems */
5005 spec->gpio_data ^= spec->gpio_led;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005006 }
5007
Takashi Iwaib4e81872009-11-18 17:20:24 +01005008 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
Takashi Iwaib4e81872009-11-18 17:20:24 +01005009 return 0;
5010}
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005011#endif
5012
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005013static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
5014{
Takashi Iwai167eae52009-11-06 15:47:50 +01005015 stac92xx_shutup(codec);
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005016 return 0;
5017}
Mattff6fdc32005-06-27 15:06:52 +02005018#endif
5019
Matt2f2f4252005-04-13 14:45:30 +02005020static struct hda_codec_ops stac92xx_patch_ops = {
5021 .build_controls = stac92xx_build_controls,
5022 .build_pcms = stac92xx_build_pcms,
5023 .init = stac92xx_init,
5024 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02005025 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02005026#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005027 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005028 .resume = stac92xx_resume,
5029#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005030 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005031};
5032
5033static int patch_stac9200(struct hda_codec *codec)
5034{
5035 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005036 int err;
Matt2f2f4252005-04-13 14:45:30 +02005037
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005038 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005039 if (spec == NULL)
5040 return -ENOMEM;
5041
Takashi Iwaia252c812009-12-25 22:56:20 +01005042 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005043 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005044 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005045 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005046 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005047 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5048 stac9200_models,
5049 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005050 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005051 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5052 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005053 else
5054 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005055 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005056
5057 spec->multiout.max_channels = 2;
5058 spec->multiout.num_dacs = 1;
5059 spec->multiout.dac_nids = stac9200_dac_nids;
5060 spec->adc_nids = stac9200_adc_nids;
5061 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005062 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005063 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005064 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005065 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005066
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005067 if (spec->board_config == STAC_9200_M4 ||
5068 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005069 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005070 spec->init = stac9200_eapd_init;
5071 else
5072 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005073 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005074
Takashi Iwai117f2572008-03-18 09:53:23 +01005075 if (spec->board_config == STAC_9200_PANASONIC) {
5076 spec->gpio_mask = spec->gpio_dir = 0x09;
5077 spec->gpio_data = 0x00;
5078 }
5079
Mattc7d4b2f2005-06-27 14:59:41 +02005080 err = stac9200_parse_auto_config(codec);
5081 if (err < 0) {
5082 stac92xx_free(codec);
5083 return err;
5084 }
Matt2f2f4252005-04-13 14:45:30 +02005085
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005086 /* CF-74 has no headphone detection, and the driver should *NOT*
5087 * do detection and HP/speaker toggle because the hardware does it.
5088 */
5089 if (spec->board_config == STAC_9200_PANASONIC)
5090 spec->hp_detect = 0;
5091
Matt2f2f4252005-04-13 14:45:30 +02005092 codec->patch_ops = stac92xx_patch_ops;
5093
5094 return 0;
5095}
5096
Tobin Davis8e21c342007-01-08 11:04:17 +01005097static int patch_stac925x(struct hda_codec *codec)
5098{
5099 struct sigmatel_spec *spec;
5100 int err;
5101
5102 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5103 if (spec == NULL)
5104 return -ENOMEM;
5105
Takashi Iwaia252c812009-12-25 22:56:20 +01005106 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005107 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005108 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005109 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005110 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005111
5112 /* Check first for codec ID */
5113 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5114 STAC_925x_MODELS,
5115 stac925x_models,
5116 stac925x_codec_id_cfg_tbl);
5117
5118 /* Now checks for PCI ID, if codec ID is not found */
5119 if (spec->board_config < 0)
5120 spec->board_config = snd_hda_check_board_config(codec,
5121 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005122 stac925x_models,
5123 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005124 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005125 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005126 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5127 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005128 else
5129 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005130 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005131
5132 spec->multiout.max_channels = 2;
5133 spec->multiout.num_dacs = 1;
5134 spec->multiout.dac_nids = stac925x_dac_nids;
5135 spec->adc_nids = stac925x_adc_nids;
5136 spec->mux_nids = stac925x_mux_nids;
5137 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005138 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005139 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005140 switch (codec->vendor_id) {
5141 case 0x83847632: /* STAC9202 */
5142 case 0x83847633: /* STAC9202D */
5143 case 0x83847636: /* STAC9251 */
5144 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005145 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005146 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai16970552007-12-18 18:05:52 +01005147 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5148 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005149 break;
5150 default:
5151 spec->num_dmics = 0;
5152 break;
5153 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005154
5155 spec->init = stac925x_core_init;
5156 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005157 spec->num_caps = 1;
5158 spec->capvols = stac925x_capvols;
5159 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005160
5161 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005162 if (!err) {
5163 if (spec->board_config < 0) {
5164 printk(KERN_WARNING "hda_codec: No auto-config is "
5165 "available, default to model=ref\n");
5166 spec->board_config = STAC_925x_REF;
5167 goto again;
5168 }
5169 err = -EINVAL;
5170 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005171 if (err < 0) {
5172 stac92xx_free(codec);
5173 return err;
5174 }
5175
5176 codec->patch_ops = stac92xx_patch_ops;
5177
5178 return 0;
5179}
5180
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005181static int patch_stac92hd73xx(struct hda_codec *codec)
5182{
5183 struct sigmatel_spec *spec;
5184 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5185 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005186 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005187
5188 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5189 if (spec == NULL)
5190 return -ENOMEM;
5191
Takashi Iwaia252c812009-12-25 22:56:20 +01005192 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005193 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005194 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005195 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005196 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5197 spec->pin_nids = stac92hd73xx_pin_nids;
5198 spec->board_config = snd_hda_check_board_config(codec,
5199 STAC_92HD73XX_MODELS,
5200 stac92hd73xx_models,
5201 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005202 /* check codec subsystem id if not found */
5203 if (spec->board_config < 0)
5204 spec->board_config =
5205 snd_hda_check_board_codec_sid_config(codec,
5206 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5207 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005208again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005209 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005210 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5211 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005212 else
5213 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005214 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005215
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005216 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005217 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5218
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005219 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005220 printk(KERN_WARNING "hda_codec: Could not determine "
5221 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005222 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005223 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005224 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005225 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005226 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005227 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005228 break;
5229 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005230 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005231 break;
5232 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005233 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5234 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005235 }
5236 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005237
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005238 spec->aloopback_mask = 0x01;
5239 spec->aloopback_shift = 8;
5240
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005241 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005242 spec->mux_nids = stac92hd73xx_mux_nids;
5243 spec->adc_nids = stac92hd73xx_adc_nids;
5244 spec->dmic_nids = stac92hd73xx_dmic_nids;
5245 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005246 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005247
5248 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5249 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai16970552007-12-18 18:05:52 +01005250 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005251
Takashi Iwai6479c632009-07-28 18:20:25 +02005252 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5253 spec->capvols = stac92hd73xx_capvols;
5254 spec->capsws = stac92hd73xx_capsws;
5255
Matthew Ranostaya7662642008-02-21 07:51:14 +01005256 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005257 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005258 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005259 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005260 case STAC_DELL_M6_AMIC:
5261 case STAC_DELL_M6_DMIC:
5262 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005263 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005264 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005265
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005266 switch (spec->board_config) {
5267 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005268 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005269 spec->num_dmics = 0;
5270 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005271 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005272 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005273 spec->num_dmics = 1;
5274 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005275 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005276 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5277 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005278 spec->num_dmics = 1;
5279 break;
5280 }
5281 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005282 case STAC_ALIENWARE_M17X:
5283 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5284 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5285 spec->eapd_switch = 0;
5286 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005287 default:
5288 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005289 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005290 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005291 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005292 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005293 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005294 /* GPIO0 High = Enable EAPD */
5295 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5296 spec->gpio_data = 0x01;
5297 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005298
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005299 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5300 spec->pwr_nids = stac92hd73xx_pwr_nids;
5301
Matthew Ranostayd9737752008-09-07 12:03:41 +02005302 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005303
5304 if (!err) {
5305 if (spec->board_config < 0) {
5306 printk(KERN_WARNING "hda_codec: No auto-config is "
5307 "available, default to model=ref\n");
5308 spec->board_config = STAC_92HD73XX_REF;
5309 goto again;
5310 }
5311 err = -EINVAL;
5312 }
5313
5314 if (err < 0) {
5315 stac92xx_free(codec);
5316 return err;
5317 }
5318
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005319 if (spec->board_config == STAC_92HD73XX_NO_JD)
5320 spec->hp_detect = 0;
5321
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005322 codec->patch_ops = stac92xx_patch_ops;
5323
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005324 codec->proc_widget_hook = stac92hd7x_proc_hook;
5325
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005326 return 0;
5327}
5328
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005329static int stac92hd83xxx_set_system_btl_amp(struct hda_codec *codec)
5330{
5331 if (codec->vendor_id != 0x111d7605 &&
5332 codec->vendor_id != 0x111d76d1)
5333 return 0;
5334
5335 switch (codec->subsystem_id) {
5336 case 0x103c1618:
5337 case 0x103c1619:
5338 case 0x103c161a:
5339 case 0x103c161b:
5340 case 0x103c161c:
5341 case 0x103c161d:
5342 case 0x103c161e:
5343 case 0x103c161f:
5344 case 0x103c1620:
5345 case 0x103c1621:
5346 case 0x103c1622:
5347 case 0x103c1623:
5348
5349 case 0x103c162a:
5350 case 0x103c162b:
5351
5352 case 0x103c1630:
5353 case 0x103c1631:
5354
5355 case 0x103c1633:
5356
5357 case 0x103c1635:
5358
5359 case 0x103c164f:
5360
5361 case 0x103c1676:
5362 case 0x103c1677:
5363 case 0x103c1678:
5364 case 0x103c1679:
5365 case 0x103c167a:
5366 case 0x103c167b:
5367 case 0x103c167c:
5368 case 0x103c167d:
5369 case 0x103c167e:
5370 case 0x103c167f:
5371 case 0x103c1680:
5372 case 0x103c1681:
5373 case 0x103c1682:
5374 case 0x103c1683:
5375 case 0x103c1684:
5376 case 0x103c1685:
5377 case 0x103c1686:
5378 case 0x103c1687:
5379 case 0x103c1688:
5380 case 0x103c1689:
5381 case 0x103c168a:
5382 case 0x103c168b:
5383 case 0x103c168c:
5384 case 0x103c168d:
5385 case 0x103c168e:
5386 case 0x103c168f:
5387 case 0x103c1690:
5388 case 0x103c1691:
5389 case 0x103c1692:
5390
5391 case 0x103c3587:
5392 case 0x103c3588:
5393 case 0x103c3589:
5394 case 0x103c358a:
5395
5396 case 0x103c3667:
5397 case 0x103c3668:
5398 /* set BTL amp level to 13.43dB for louder speaker output */
5399 return snd_hda_codec_write_cache(codec, codec->afg, 0,
5400 0x7F4, 0x14);
5401 }
5402 return 0;
5403}
5404
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005405static int patch_stac92hd83xxx(struct hda_codec *codec)
5406{
5407 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005408 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005409 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005410 int num_dacs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005411
5412 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5413 if (spec == NULL)
5414 return -ENOMEM;
5415
Charles1cc9e8f2010-10-18 16:22:00 +08005416 /* reset pin power-down; Windows may leave these bits after reboot */
5417 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7EC, 0);
5418 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7ED, 0);
Takashi Iwaia252c812009-12-25 22:56:20 +01005419 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005420 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005421 spec->linear_tone_beep = 1;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005422 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005423 spec->digbeep_nid = 0x21;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005424 spec->dmic_nids = stac92hd83xxx_dmic_nids;
5425 spec->dmux_nids = stac92hd83xxx_mux_nids;
Takashi Iwai667067d2009-08-13 18:14:42 +02005426 spec->mux_nids = stac92hd83xxx_mux_nids;
5427 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005428 spec->adc_nids = stac92hd83xxx_adc_nids;
Takashi Iwai7570ef12009-08-15 11:57:53 +02005429 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005430 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5431 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5432 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005433 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005434
5435 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005436 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005437 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005438 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5439 spec->capvols = stac92hd83xxx_capvols;
5440 spec->capsws = stac92hd83xxx_capsws;
5441
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005442 spec->board_config = snd_hda_check_board_config(codec,
5443 STAC_92HD83XXX_MODELS,
5444 stac92hd83xxx_models,
5445 stac92hd83xxx_cfg_tbl);
5446again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005447 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005448 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5449 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005450 else
5451 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005452 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005453
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005454 switch (codec->vendor_id) {
Charles Chin36706002010-01-29 12:05:51 +01005455 case 0x111d7666:
5456 case 0x111d7667:
5457 case 0x111d7668:
5458 case 0x111d7669:
Charles Chin8a345a02010-08-10 11:43:25 +02005459 case 0x111d76d1:
5460 case 0x111d76d9:
Charles Chin36706002010-01-29 12:05:51 +01005461 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5462 spec->pin_nids = stac92hd88xxx_pin_nids;
5463 spec->mono_nid = 0;
5464 spec->digbeep_nid = 0;
5465 spec->num_pwrs = 0;
5466 break;
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005467 case 0x111d7604:
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01005468 case 0x111d76d4:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005469 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005470 case 0x111d76d5:
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005471 case 0x111d76e7:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005472 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5473 break;
5474 spec->num_pwrs = 0;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005475 spec->num_dmics = stac92xx_connected_ports(codec,
5476 stac92hd83xxx_dmic_nids,
5477 STAC92HD83XXX_NUM_DMICS);
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005478 break;
5479 }
5480
Takashi Iwaib4e81872009-11-18 17:20:24 +01005481 codec->patch_ops = stac92xx_patch_ops;
5482
Takashi Iwaidce17d42010-02-09 09:25:26 +01005483 if (find_mute_led_gpio(codec, 0))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005484 snd_printd("mute LED gpio %d polarity %d\n",
5485 spec->gpio_led,
5486 spec->gpio_led_polarity);
5487
Takashi Iwaib4e81872009-11-18 17:20:24 +01005488#ifdef CONFIG_SND_HDA_POWER_SAVE
5489 if (spec->gpio_led) {
5490 spec->gpio_mask |= spec->gpio_led;
5491 spec->gpio_dir |= spec->gpio_led;
5492 spec->gpio_data |= spec->gpio_led;
5493 /* register check_power_status callback. */
5494 codec->patch_ops.check_power_status =
Takashi Iwaic21bd022010-02-08 15:16:08 +01005495 stac92xx_hp_check_power_status;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005496 }
5497#endif
5498
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005499 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5500 if (!err) {
5501 if (spec->board_config < 0) {
5502 printk(KERN_WARNING "hda_codec: No auto-config is "
5503 "available, default to model=ref\n");
5504 spec->board_config = STAC_92HD83XXX_REF;
5505 goto again;
5506 }
5507 err = -EINVAL;
5508 }
5509
5510 if (err < 0) {
5511 stac92xx_free(codec);
5512 return err;
5513 }
5514
Charles Chin04b5efe2010-02-04 10:28:02 +01005515 /* docking output support */
5516 num_dacs = snd_hda_get_connections(codec, 0xF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005517 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Charles Chin04b5efe2010-02-04 10:28:02 +01005518 /* skip non-DAC connections */
5519 while (num_dacs >= 0 &&
5520 (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5521 != AC_WID_AUD_OUT))
5522 num_dacs--;
5523 /* set port E and F to select the last DAC */
5524 if (num_dacs >= 0) {
5525 snd_hda_codec_write_cache(codec, 0xE, 0,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005526 AC_VERB_SET_CONNECT_SEL, num_dacs);
Charles Chin04b5efe2010-02-04 10:28:02 +01005527 snd_hda_codec_write_cache(codec, 0xF, 0,
5528 AC_VERB_SET_CONNECT_SEL, num_dacs);
5529 }
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005530
Vitaliy Kulikov335e3b82010-10-22 18:38:31 -05005531 stac92hd83xxx_set_system_btl_amp(codec);
5532
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005533 codec->proc_widget_hook = stac92hd_proc_hook;
5534
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005535 return 0;
5536}
5537
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005538static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5539 hda_nid_t dig0pin)
5540{
5541 struct sigmatel_spec *spec = codec->spec;
5542 int idx;
5543
5544 for (idx = 0; idx < spec->num_pins; idx++)
5545 if (spec->pin_nids[idx] == dig0pin)
5546 break;
5547 if ((idx + 2) >= spec->num_pins)
5548 return 0;
5549
5550 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005551 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005552 return 2;
5553
5554 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005555 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005556 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005557 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005558 return 1;
5559 else
5560 return 0;
5561}
5562
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005563/* HP dv7 bass switch - GPIO5 */
5564#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5565static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5566 struct snd_ctl_elem_value *ucontrol)
5567{
5568 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5569 struct sigmatel_spec *spec = codec->spec;
5570 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5571 return 0;
5572}
5573
5574static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5575 struct snd_ctl_elem_value *ucontrol)
5576{
5577 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5578 struct sigmatel_spec *spec = codec->spec;
5579 unsigned int gpio_data;
5580
5581 gpio_data = (spec->gpio_data & ~0x20) |
5582 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5583 if (gpio_data == spec->gpio_data)
5584 return 0;
5585 spec->gpio_data = gpio_data;
5586 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5587 return 1;
5588}
5589
5590static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5591 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5592 .info = stac_hp_bass_gpio_info,
5593 .get = stac_hp_bass_gpio_get,
5594 .put = stac_hp_bass_gpio_put,
5595};
5596
5597static int stac_add_hp_bass_switch(struct hda_codec *codec)
5598{
5599 struct sigmatel_spec *spec = codec->spec;
5600
5601 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5602 "Bass Speaker Playback Switch", 0))
5603 return -ENOMEM;
5604
5605 spec->gpio_mask |= 0x20;
5606 spec->gpio_dir |= 0x20;
5607 spec->gpio_data |= 0x20;
5608 return 0;
5609}
5610
Matthew Ranostaye035b842007-11-06 11:53:55 +01005611static int patch_stac92hd71bxx(struct hda_codec *codec)
5612{
5613 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005614 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005615 unsigned int pin_cfg;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005616 int err = 0;
5617
5618 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5619 if (spec == NULL)
5620 return -ENOMEM;
5621
Takashi Iwaia252c812009-12-25 22:56:20 +01005622 codec->no_trigger_sense = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005623 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005624 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005625 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005626 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5627 switch (codec->vendor_id) {
5628 case 0x111d76b6:
5629 case 0x111d76b7:
5630 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5631 break;
5632 case 0x111d7603:
5633 case 0x111d7608:
5634 /* On 92HD75Bx 0x27 isn't a pin nid */
5635 spec->num_pins--;
5636 /* fallthrough */
5637 default:
5638 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5639 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005640 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005641 spec->board_config = snd_hda_check_board_config(codec,
5642 STAC_92HD71BXX_MODELS,
5643 stac92hd71bxx_models,
5644 stac92hd71bxx_cfg_tbl);
5645again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005646 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005647 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5648 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005649 else
5650 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005651 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005652
Takashi Iwaifc64b262009-09-14 15:33:01 +02005653 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005654 /* GPIO0 = EAPD */
5655 spec->gpio_mask = 0x01;
5656 spec->gpio_dir = 0x01;
5657 spec->gpio_data = 0x01;
5658 }
5659
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005660 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5661 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5662
Takashi Iwai6479c632009-07-28 18:20:25 +02005663 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5664 spec->capvols = stac92hd71bxx_capvols;
5665 spec->capsws = stac92hd71bxx_capsws;
5666
Matthew Ranostay541eee82007-12-14 12:08:04 +01005667 switch (codec->vendor_id) {
5668 case 0x111d76b6: /* 4 Port without Analog Mixer */
5669 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005670 unmute_init++;
5671 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005672 case 0x111d76b4: /* 6 Port without Analog Mixer */
5673 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005674 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005675 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005676 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005677 stac92hd71bxx_dmic_nids,
5678 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005679 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005680 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005681 switch (spec->board_config) {
5682 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005683 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005684 err = stac_add_event(spec, codec->afg,
5685 STAC_VREF_EVENT, 0x02);
5686 if (err < 0)
5687 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005688 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005689 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5690 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005691 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005692 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005693 spec->gpio_mask |= 0x02;
5694 break;
5695 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005696 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005697 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005698 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005699
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005700 /* no output amps */
5701 spec->num_pwrs = 0;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005702 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005703 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005704 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005705 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5706 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005707 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005708 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005709 stac92hd71bxx_dmic_nids,
5710 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005711 break;
5712 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005713 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005714 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005715
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005716 /* no output amps */
5717 spec->num_pwrs = 0;
5718 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005719 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005720 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005721 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005722 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005723 stac92hd71bxx_dmic_nids,
5724 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005725 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005726 }
5727
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005728 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5729 snd_hda_sequence_write_cache(codec, unmute_init);
5730
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005731 /* Some HP machines seem to have unstable codec communications
5732 * especially with ATI fglrx driver. For recovering from the
5733 * CORB/RIRB stall, allow the BUS reset and keep always sync
5734 */
5735 if (spec->board_config == STAC_HP_DV5) {
5736 codec->bus->sync_write = 1;
5737 codec->bus->allow_bus_reset = 1;
5738 }
5739
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005740 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005741 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005742 spec->aloopback_shift = 0;
5743
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005744 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005745 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005746 spec->mux_nids = stac92hd71bxx_mux_nids;
5747 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005748 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005749 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005750
5751 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5752 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005753 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005754 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005755
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305756 snd_printdd("Found board config: %d\n", spec->board_config);
5757
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005758 switch (spec->board_config) {
5759 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005760 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005761 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005762 stac92xx_auto_set_pinctl(codec, 0x0e,
5763 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005764 /* fallthru */
5765 case STAC_DELL_M4_2:
5766 spec->num_dmics = 0;
5767 spec->num_smuxes = 0;
5768 spec->num_dmuxes = 0;
5769 break;
5770 case STAC_DELL_M4_1:
5771 case STAC_DELL_M4_3:
5772 spec->num_dmics = 1;
5773 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005774 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005775 break;
James Gardiner514bf542009-05-03 04:00:44 -04005776 case STAC_HP_DV4_1222NR:
5777 spec->num_dmics = 1;
5778 /* I don't know if it needs 1 or 2 smuxes - will wait for
5779 * bug reports to fix if needed
5780 */
5781 spec->num_smuxes = 1;
5782 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005783 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005784 case STAC_HP_DV4:
5785 spec->gpio_led = 0x01;
5786 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005787 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005788 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005789 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005790 /* HP dv6 gives the headphone pin as a line-out. Thus we
5791 * need to set hp_detect flag here to force to enable HP
5792 * detection.
5793 */
5794 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005795 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005796 case STAC_HP_HDX:
5797 spec->num_dmics = 1;
5798 spec->num_dmuxes = 1;
5799 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005800 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005801 break;
5802 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005803
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005804 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005805 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5806 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5807 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5808 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5809 /* It was changed in the BIOS to just satisfy MS DTM.
5810 * Lets turn it back into slaved HP
5811 */
5812 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5813 | (AC_JACK_HP_OUT <<
5814 AC_DEFCFG_DEVICE_SHIFT);
5815 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5816 | AC_DEFCFG_SEQUENCE)))
5817 | 0x1f;
5818 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5819 }
5820 }
5821
Takashi Iwaidce17d42010-02-09 09:25:26 +01005822 if (find_mute_led_gpio(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005823 snd_printd("mute LED gpio %d polarity %d\n",
5824 spec->gpio_led,
5825 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005826
Takashi Iwai86d190e2009-05-26 15:18:58 +02005827#ifdef CONFIG_SND_HDA_POWER_SAVE
5828 if (spec->gpio_led) {
5829 spec->gpio_mask |= spec->gpio_led;
5830 spec->gpio_dir |= spec->gpio_led;
5831 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005832 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005833 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005834 stac92xx_hp_check_power_status;
5835 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005836#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005837
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005838 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005839
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005840 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005841 if (!err) {
5842 if (spec->board_config < 0) {
5843 printk(KERN_WARNING "hda_codec: No auto-config is "
5844 "available, default to model=ref\n");
5845 spec->board_config = STAC_92HD71BXX_REF;
5846 goto again;
5847 }
5848 err = -EINVAL;
5849 }
5850
5851 if (err < 0) {
5852 stac92xx_free(codec);
5853 return err;
5854 }
5855
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005856 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005857 if (spec->board_config == STAC_HP_DV4 ||
5858 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005859 unsigned int cap;
5860 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5861 cap &= AC_GPIO_IO_COUNT;
5862 if (cap >= 6)
5863 stac_add_hp_bass_switch(codec);
5864 }
5865
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005866 codec->proc_widget_hook = stac92hd7x_proc_hook;
5867
Matthew Ranostaye035b842007-11-06 11:53:55 +01005868 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005869}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005870
Matt2f2f4252005-04-13 14:45:30 +02005871static int patch_stac922x(struct hda_codec *codec)
5872{
5873 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005874 int err;
Matt2f2f4252005-04-13 14:45:30 +02005875
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005876 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005877 if (spec == NULL)
5878 return -ENOMEM;
5879
Takashi Iwaia252c812009-12-25 22:56:20 +01005880 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005881 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005882 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005883 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005884 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005885 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5886 stac922x_models,
5887 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005888 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005889 spec->gpio_mask = spec->gpio_dir = 0x03;
5890 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005891 /* Intel Macs have all same PCI SSID, so we need to check
5892 * codec SSID to distinguish the exact models
5893 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005894 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005895 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005896
5897 case 0x106b0800:
5898 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005899 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005900 case 0x106b0600:
5901 case 0x106b0700:
5902 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005903 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005904 case 0x106b0e00:
5905 case 0x106b0f00:
5906 case 0x106b1600:
5907 case 0x106b1700:
5908 case 0x106b0200:
5909 case 0x106b1e00:
5910 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005911 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005912 case 0x106b1a00:
5913 case 0x00000100:
5914 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005915 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005916 case 0x106b0a00:
5917 case 0x106b2200:
5918 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005919 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005920 default:
5921 spec->board_config = STAC_INTEL_MAC_V3;
5922 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005923 }
5924 }
5925
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005926 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005927 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005928 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5929 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005930 else
5931 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005932 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005933
Matt2f2f4252005-04-13 14:45:30 +02005934 spec->adc_nids = stac922x_adc_nids;
5935 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005936 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005937 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005938 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005939 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005940
5941 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005942
5943 spec->num_caps = STAC922X_NUM_CAPS;
5944 spec->capvols = stac922x_capvols;
5945 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005946
5947 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005948
Matt Porter3cc08dc2006-01-23 15:27:49 +01005949 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005950 if (!err) {
5951 if (spec->board_config < 0) {
5952 printk(KERN_WARNING "hda_codec: No auto-config is "
5953 "available, default to model=ref\n");
5954 spec->board_config = STAC_D945_REF;
5955 goto again;
5956 }
5957 err = -EINVAL;
5958 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005959 if (err < 0) {
5960 stac92xx_free(codec);
5961 return err;
5962 }
5963
5964 codec->patch_ops = stac92xx_patch_ops;
5965
Takashi Iwai807a46362007-05-29 19:01:37 +02005966 /* Fix Mux capture level; max to 2 */
5967 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5968 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5969 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5970 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5971 (0 << AC_AMPCAP_MUTE_SHIFT));
5972
Matt Porter3cc08dc2006-01-23 15:27:49 +01005973 return 0;
5974}
5975
5976static int patch_stac927x(struct hda_codec *codec)
5977{
5978 struct sigmatel_spec *spec;
5979 int err;
5980
5981 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5982 if (spec == NULL)
5983 return -ENOMEM;
5984
Takashi Iwaia252c812009-12-25 22:56:20 +01005985 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005986 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005987 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005988 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005989 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005990 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005991 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5992 stac927x_models,
5993 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005994 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005995 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005996 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5997 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005998 else
5999 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006000 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01006001
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006002 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006003 spec->adc_nids = stac927x_adc_nids;
6004 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
6005 spec->mux_nids = stac927x_mux_nids;
6006 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006007 spec->smux_nids = stac927x_smux_nids;
6008 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04006009 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01006010 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006011 spec->multiout.dac_nids = spec->dac_nids;
6012
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006013 if (spec->board_config != STAC_D965_REF) {
6014 /* GPIO0 High = Enable EAPD */
6015 spec->eapd_mask = spec->gpio_mask = 0x01;
6016 spec->gpio_dir = spec->gpio_data = 0x01;
6017 }
6018
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006019 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02006020 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006021 case STAC_D965_5ST:
6022 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006023 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02006024 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006025 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006026 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006027 switch (codec->subsystem_id) {
6028 case 0x10280209:
6029 case 0x1028022e:
6030 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006031 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02006032 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02006033 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01006034 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01006035 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01006036 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006037 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006038 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01006039 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01006040 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006041 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006042 if (codec->subsystem_id != 0x1028022f) {
6043 /* GPIO2 High = Enable EAPD */
6044 spec->eapd_mask = spec->gpio_mask = 0x04;
6045 spec->gpio_dir = spec->gpio_data = 0x04;
6046 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006047 spec->dmic_nids = stac927x_dmic_nids;
6048 spec->num_dmics = STAC927X_NUM_DMICS;
6049
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02006050 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006051 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai16970552007-12-18 18:05:52 +01006052 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006053 break;
Takashi Iwai54930532009-10-11 17:38:29 +02006054 case STAC_927X_VOLKNOB:
6055 spec->num_dmics = 0;
6056 spec->init = stac927x_volknob_core_init;
6057 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006058 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006059 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006060 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02006061 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02006062 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01006063
Takashi Iwai6479c632009-07-28 18:20:25 +02006064 spec->num_caps = STAC927X_NUM_CAPS;
6065 spec->capvols = stac927x_capvols;
6066 spec->capsws = stac927x_capsws;
6067
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006068 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006069 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006070 spec->aloopback_mask = 0x40;
6071 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05006072 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01006073
Matt Porter3cc08dc2006-01-23 15:27:49 +01006074 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006075 if (!err) {
6076 if (spec->board_config < 0) {
6077 printk(KERN_WARNING "hda_codec: No auto-config is "
6078 "available, default to model=ref\n");
6079 spec->board_config = STAC_D965_REF;
6080 goto again;
6081 }
6082 err = -EINVAL;
6083 }
Mattc7d4b2f2005-06-27 14:59:41 +02006084 if (err < 0) {
6085 stac92xx_free(codec);
6086 return err;
6087 }
Matt2f2f4252005-04-13 14:45:30 +02006088
6089 codec->patch_ops = stac92xx_patch_ops;
6090
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006091 codec->proc_widget_hook = stac927x_proc_hook;
6092
Takashi Iwai52987652008-01-16 16:09:47 +01006093 /*
6094 * !!FIXME!!
6095 * The STAC927x seem to require fairly long delays for certain
6096 * command sequences. With too short delays (even if the answer
6097 * is set to RIRB properly), it results in the silence output
6098 * on some hardwares like Dell.
6099 *
6100 * The below flag enables the longer delay (see get_response
6101 * in hda_intel.c).
6102 */
6103 codec->bus->needs_damn_long_delay = 1;
6104
Takashi Iwaie28d8322008-12-17 13:48:29 +01006105 /* no jack detecion for ref-no-jd model */
6106 if (spec->board_config == STAC_D965_REF_NO_JD)
6107 spec->hp_detect = 0;
6108
Matt2f2f4252005-04-13 14:45:30 +02006109 return 0;
6110}
6111
Matt Porterf3302a52006-07-31 12:49:34 +02006112static int patch_stac9205(struct hda_codec *codec)
6113{
6114 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006115 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006116
6117 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6118 if (spec == NULL)
6119 return -ENOMEM;
6120
Takashi Iwaia252c812009-12-25 22:56:20 +01006121 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006122 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006123 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006124 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006125 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006126 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6127 stac9205_models,
6128 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006129 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006130 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006131 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6132 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006133 else
6134 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006135 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006136
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006137 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006138 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006139 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006140 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006141 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006142 spec->smux_nids = stac9205_smux_nids;
6143 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006144 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006145 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006146 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai16970552007-12-18 18:05:52 +01006147 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006148 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006149
6150 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006151 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006152
Takashi Iwai6479c632009-07-28 18:20:25 +02006153 spec->num_caps = STAC9205_NUM_CAPS;
6154 spec->capvols = stac9205_capvols;
6155 spec->capsws = stac9205_capsws;
6156
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006157 spec->aloopback_mask = 0x40;
6158 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006159 /* Turn on/off EAPD per HP plugging */
6160 if (spec->board_config != STAC_9205_EAPD)
6161 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006162 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006163
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006164 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006165 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006166 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006167 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6168 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006169
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006170 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006171 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6172 if (err < 0)
6173 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006174 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006175 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6176 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006177 AC_VERB_SET_UNSOLICITED_ENABLE,
6178 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006179
6180 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006181 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006182 spec->gpio_mask = 0x1b;
6183 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006184 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006185 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006186 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006187 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006188 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006189 case STAC_9205_REF:
6190 /* SPDIF-In enabled */
6191 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006192 default:
6193 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006194 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006195 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006196 break;
6197 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006198
Matt Porterf3302a52006-07-31 12:49:34 +02006199 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006200 if (!err) {
6201 if (spec->board_config < 0) {
6202 printk(KERN_WARNING "hda_codec: No auto-config is "
6203 "available, default to model=ref\n");
6204 spec->board_config = STAC_9205_REF;
6205 goto again;
6206 }
6207 err = -EINVAL;
6208 }
Matt Porterf3302a52006-07-31 12:49:34 +02006209 if (err < 0) {
6210 stac92xx_free(codec);
6211 return err;
6212 }
6213
6214 codec->patch_ops = stac92xx_patch_ops;
6215
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006216 codec->proc_widget_hook = stac9205_proc_hook;
6217
Matt Porterf3302a52006-07-31 12:49:34 +02006218 return 0;
6219}
6220
Matt2f2f4252005-04-13 14:45:30 +02006221/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006222 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006223 */
6224
Takashi Iwai1e137f92009-01-21 07:41:22 +01006225static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006226 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006227 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6228 {}
6229};
6230
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006231static hda_nid_t stac9872_pin_nids[] = {
6232 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6233 0x11, 0x13, 0x14,
6234};
6235
6236static hda_nid_t stac9872_adc_nids[] = {
6237 0x8 /*,0x6*/
6238};
6239
6240static hda_nid_t stac9872_mux_nids[] = {
6241 0x15
6242};
6243
Takashi Iwai6479c632009-07-28 18:20:25 +02006244static unsigned long stac9872_capvols[] = {
6245 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6246};
6247#define stac9872_capsws stac9872_capvols
6248
Takashi Iwai307282c2009-03-12 18:17:58 +01006249static unsigned int stac9872_vaio_pin_configs[9] = {
6250 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6251 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6252 0x90a7013e
6253};
6254
6255static const char *stac9872_models[STAC_9872_MODELS] = {
6256 [STAC_9872_AUTO] = "auto",
6257 [STAC_9872_VAIO] = "vaio",
6258};
6259
6260static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6261 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6262};
6263
6264static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006265 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6266 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006267 {} /* terminator */
6268};
6269
Guillaume Munch6d859062006-08-22 17:15:47 +02006270static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006271{
6272 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006273 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006274
Takashi Iwaidb064e52006-03-16 16:04:58 +01006275 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6276 if (spec == NULL)
6277 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006278 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006279 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006280 spec->linear_tone_beep = 1;
Takashi Iwaib04add92009-07-20 08:01:36 +02006281 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6282 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006283
6284 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6285 stac9872_models,
6286 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006287 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006288 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6289 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006290 else
6291 stac92xx_set_config_regs(codec,
6292 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006293
Takashi Iwai1e137f92009-01-21 07:41:22 +01006294 spec->multiout.dac_nids = spec->dac_nids;
6295 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6296 spec->adc_nids = stac9872_adc_nids;
6297 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6298 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006299 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006300 spec->num_caps = 1;
6301 spec->capvols = stac9872_capvols;
6302 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006303
Takashi Iwai1e137f92009-01-21 07:41:22 +01006304 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6305 if (err < 0) {
6306 stac92xx_free(codec);
6307 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006308 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006309 spec->input_mux = &spec->private_imux;
6310 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006311 return 0;
6312}
6313
6314
6315/*
Matt2f2f4252005-04-13 14:45:30 +02006316 * patch entries
6317 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006318static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006319 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6320 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6321 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6322 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6323 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6324 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6325 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006326 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6327 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6328 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6329 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6330 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6331 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006332 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6333 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6334 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6335 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6336 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6337 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6338 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6339 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6340 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6341 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006342 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6343 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6344 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6345 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6346 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6347 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006348 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6349 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006350 /* The following does not take into account .id=0x83847661 when subsys =
6351 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6352 * currently not fully supported.
6353 */
6354 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6355 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6356 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006357 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006358 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6359 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6360 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6361 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6362 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6363 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6364 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6365 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006366 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006367 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006368 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006369 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006370 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006371 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6372 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006373 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6374 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6375 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6376 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006377 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006378 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6379 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006380 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006381 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6382 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6383 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6384 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6385 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6386 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6387 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6388 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006389 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6390 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6391 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6392 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6393 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6394 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6395 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6396 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6397 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6398 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6399 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6400 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6401 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6402 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6403 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006404 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
6405 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006406 {} /* terminator */
6407};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006408
6409MODULE_ALIAS("snd-hda-codec-id:8384*");
6410MODULE_ALIAS("snd-hda-codec-id:111d*");
6411
6412MODULE_LICENSE("GPL");
6413MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6414
6415static struct hda_codec_preset_list sigmatel_list = {
6416 .preset = snd_hda_preset_sigmatel,
6417 .owner = THIS_MODULE,
6418};
6419
6420static int __init patch_sigmatel_init(void)
6421{
6422 return snd_hda_add_codec_preset(&sigmatel_list);
6423}
6424
6425static void __exit patch_sigmatel_exit(void)
6426{
6427 snd_hda_delete_codec_preset(&sigmatel_list);
6428}
6429
6430module_init(patch_sigmatel_init)
6431module_exit(patch_sigmatel_exit)