blob: 7f487ab4dad4ab89ddc035eef0e992a1fd1d59e2 [file] [log] [blame]
Matt2f2f4252005-04-13 14:45:30 +02001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
4 * HD audio interface patch for SigmaTel STAC92xx
5 *
6 * Copyright (c) 2005 Embedded Alley Solutions, Inc.
Matt Porter403d1942005-11-29 15:00:51 +01007 * Matt Porter <mporter@embeddedalley.com>
Matt2f2f4252005-04-13 14:45:30 +02008 *
9 * Based on patch_cmedia.c and patch_realtek.c
10 * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
11 *
12 * This driver is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This driver is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
Matt2f2f4252005-04-13 14:45:30 +020027#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/slab.h>
30#include <linux/pci.h>
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +010031#include <linux/dmi.h>
Matt2f2f4252005-04-13 14:45:30 +020032#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020033#include <sound/asoundef.h>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040034#include <sound/jack.h>
Clemens Ladischa74ccea2010-10-22 15:52:34 +020035#include <sound/tlv.h>
Matt2f2f4252005-04-13 14:45:30 +020036#include "hda_codec.h"
37#include "hda_local.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020038#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020039
Takashi Iwaic6e4c662008-11-25 11:58:19 +010040enum {
41 STAC_VREF_EVENT = 1,
42 STAC_INSERT_EVENT,
43 STAC_PWR_EVENT,
44 STAC_HP_EVENT,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020045 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020046 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010047};
Matt4e550962005-07-04 17:51:39 +020048
Takashi Iwaif5fcc132006-11-24 17:07:44 +010049enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010050 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010051 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010052 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020053 STAC_9200_DELL_D21,
54 STAC_9200_DELL_D22,
55 STAC_9200_DELL_D23,
56 STAC_9200_DELL_M21,
57 STAC_9200_DELL_M22,
58 STAC_9200_DELL_M23,
59 STAC_9200_DELL_M24,
60 STAC_9200_DELL_M25,
61 STAC_9200_DELL_M26,
62 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020063 STAC_9200_M4,
64 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010065 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010066 STAC_9200_MODELS
67};
68
69enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010070 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010071 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020072 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020073 STAC_9205_DELL_M43,
74 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010075 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010076 STAC_9205_MODELS
77};
78
79enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010080 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010081 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010082 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080083 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010084 STAC_DELL_M6_AMIC,
85 STAC_DELL_M6_DMIC,
86 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050087 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020088 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010089 STAC_92HD73XX_MODELS
90};
91
92enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010093 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020094 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050095 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050096 STAC_DELL_S14,
Takashi Iwaib4e81872009-11-18 17:20:24 +010097 STAC_92HD83XXX_HP,
Steven Eastland48315592010-08-06 15:07:35 -060098 STAC_HP_DV7_4000,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020099 STAC_92HD83XXX_MODELS
100};
101
102enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100103 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100104 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100105 STAC_DELL_M4_1,
106 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500107 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400108 STAC_HP_M4,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +0200109 STAC_HP_DV4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100110 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100111 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400112 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100113 STAC_92HD71BXX_MODELS
114};
115
116enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100117 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100118 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200119 STAC_M1,
120 STAC_M1_2,
121 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100122 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200123 STAC_M3,
124 STAC_M5,
125 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100126 STAC_925x_MODELS
127};
128
129enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100130 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100131 STAC_D945_REF,
132 STAC_D945GTP3,
133 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200134 STAC_INTEL_MAC_V1,
135 STAC_INTEL_MAC_V2,
136 STAC_INTEL_MAC_V3,
137 STAC_INTEL_MAC_V4,
138 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800139 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
140 * is given, one of the above models will be
141 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200142 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100143 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100144 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100145 STAC_MACBOOK_PRO_V1,
146 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200147 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200148 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300149 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200150 STAC_922X_DELL_D81,
151 STAC_922X_DELL_D82,
152 STAC_922X_DELL_M81,
153 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100154 STAC_922X_MODELS
155};
156
157enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100158 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100159 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100160 STAC_D965_REF,
161 STAC_D965_3ST,
162 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200163 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200164 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100165 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200166 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100167 STAC_927X_MODELS
168};
Matt Porter403d1942005-11-29 15:00:51 +0100169
Takashi Iwai307282c2009-03-12 18:17:58 +0100170enum {
171 STAC_9872_AUTO,
172 STAC_9872_VAIO,
173 STAC_9872_MODELS
174};
175
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400176struct sigmatel_event {
177 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100178 unsigned char type;
179 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400180 int data;
181};
182
183struct sigmatel_jack {
184 hda_nid_t nid;
185 int type;
186 struct snd_jack *jack;
187};
188
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200189struct sigmatel_mic_route {
190 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200191 signed char mux_idx;
192 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200193};
194
Matt2f2f4252005-04-13 14:45:30 +0200195struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100196 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200197 unsigned int num_mixers;
198
Matt Porter403d1942005-11-29 15:00:51 +0100199 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500200 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200201 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100202 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100203 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400204 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100205 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200206 unsigned int auto_mic:1;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +0100207 unsigned int linear_tone_beep:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200208
Matthew 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 Iwai1697055e2007-12-18 18:05:52 +0100256 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200257 hda_nid_t *smux_nids;
258 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200259 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200260
261 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
262 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
263 unsigned int num_caps; /* number of capture volume/switch elements */
264
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200265 struct sigmatel_mic_route ext_mic;
266 struct sigmatel_mic_route int_mic;
Charles Chin99077902010-09-17 10:22:32 +0200267 struct sigmatel_mic_route dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200268
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 Iwaic8b6bf92005-11-17 14:57:47 +0100282 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200283
284 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200285 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100286 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200287 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100288 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200289 struct hda_input_mux *sinput_mux;
290 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400291 unsigned int cur_amux;
292 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200293 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200294
Matt Porter403d1942005-11-29 15:00:51 +0100295 /* i/o switches */
296 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200297 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100298 hda_nid_t line_switch; /* shared line-in for input and output */
299 hda_nid_t mic_switch; /* shared mic-in for input and output */
300 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200301 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200302
Mattc7d4b2f2005-06-27 14:59:41 +0200303 struct hda_pcm pcm_rec[2]; /* PCM information */
304
305 /* dynamic controls and input_mux */
306 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200307 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200308 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200309 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200310 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100311 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200312};
313
314static hda_nid_t stac9200_adc_nids[1] = {
315 0x03,
316};
317
318static hda_nid_t stac9200_mux_nids[1] = {
319 0x0c,
320};
321
322static hda_nid_t stac9200_dac_nids[1] = {
323 0x02,
324};
325
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100326static hda_nid_t stac92hd73xx_pwr_nids[8] = {
327 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
328 0x0f, 0x10, 0x11
329};
330
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400331static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
332 0x26, 0,
333};
334
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100335static hda_nid_t stac92hd73xx_adc_nids[2] = {
336 0x1a, 0x1b
337};
338
339#define STAC92HD73XX_NUM_DMICS 2
340static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
341 0x13, 0x14, 0
342};
343
344#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100345
Takashi Iwaie2aec172009-09-02 01:00:05 +0200346static hda_nid_t stac92hd73xx_mux_nids[2] = {
347 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100348};
349
350static hda_nid_t stac92hd73xx_dmux_nids[2] = {
351 0x20, 0x21,
352};
353
Matthew Ranostayd9737752008-09-07 12:03:41 +0200354static hda_nid_t stac92hd73xx_smux_nids[2] = {
355 0x22, 0x23,
356};
357
Takashi Iwai6479c632009-07-28 18:20:25 +0200358#define STAC92HD73XX_NUM_CAPS 2
359static unsigned long stac92hd73xx_capvols[] = {
360 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
361 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
362};
363#define stac92hd73xx_capsws stac92hd73xx_capvols
364
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200365#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200366
Takashi Iwai667067d2009-08-13 18:14:42 +0200367static hda_nid_t stac92hd83xxx_mux_nids[2] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200368 0x17, 0x18,
369};
370
371static hda_nid_t stac92hd83xxx_adc_nids[2] = {
372 0x15, 0x16,
373};
374
375static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
376 0xa, 0xb, 0xd, 0xe,
377};
378
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400379static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
380 0x1e, 0,
381};
382
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200383static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500384 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200385};
386
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +0200387#define STAC92HD83XXX_NUM_DMICS 2
388static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
389 0x11, 0x20, 0
390};
391
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 Iwai1697055e2007-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 Iwai1697055e2007-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwaic8b6bf92005-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 Iwai1697055e2007-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 Iwai1697055e2007-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 Iwai1697055e2007-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 */
Takashi Iwai1972d022009-08-06 08:44:43 +02001754 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1755 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001756 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1757 "unknown Dell", STAC_DELL_M4_1),
1758 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1759 "unknown Dell", STAC_DELL_M4_1),
1760 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1761 "unknown Dell", STAC_DELL_M4_1),
1762 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1763 "unknown Dell", STAC_DELL_M4_1),
1764 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1765 "unknown Dell", STAC_DELL_M4_1),
1766 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1767 "unknown Dell", STAC_DELL_M4_1),
1768 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1769 "unknown Dell", STAC_DELL_M4_1),
1770 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1771 "unknown Dell", STAC_DELL_M4_2),
1772 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1773 "unknown Dell", STAC_DELL_M4_2),
1774 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1775 "unknown Dell", STAC_DELL_M4_2),
1776 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1777 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001778 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1779 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001780 {} /* terminator */
1781};
1782
Matt Porter403d1942005-11-29 15:00:51 +01001783static unsigned int ref922x_pin_configs[10] = {
1784 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1785 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001786 0x40000100, 0x40000100,
1787};
1788
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001789/*
1790 STAC 922X pin configs for
1791 102801A7
1792 102801AB
1793 102801A9
1794 102801D1
1795 102801D2
1796*/
1797static unsigned int dell_922x_d81_pin_configs[10] = {
1798 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1799 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1800 0x01813122, 0x400001f2,
1801};
1802
1803/*
1804 STAC 922X pin configs for
1805 102801AC
1806 102801D0
1807*/
1808static unsigned int dell_922x_d82_pin_configs[10] = {
1809 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1810 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1811 0x01813122, 0x400001f1,
1812};
1813
1814/*
1815 STAC 922X pin configs for
1816 102801BF
1817*/
1818static unsigned int dell_922x_m81_pin_configs[10] = {
1819 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1820 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1821 0x40C003f1, 0x405003f0,
1822};
1823
1824/*
1825 STAC 9221 A1 pin configs for
1826 102801D7 (Dell XPS M1210)
1827*/
1828static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001829 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1830 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001831 0x508003f3, 0x405003f4,
1832};
1833
Matt Porter403d1942005-11-29 15:00:51 +01001834static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001835 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001836 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1837 0x02a19120, 0x40000100,
1838};
1839
1840static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001841 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1842 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001843 0x02a19320, 0x40000100,
1844};
1845
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001846static unsigned int intel_mac_v1_pin_configs[10] = {
1847 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1848 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001849 0x400000fc, 0x400000fb,
1850};
1851
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001852static unsigned int intel_mac_v2_pin_configs[10] = {
1853 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1854 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001855 0x400000fc, 0x400000fb,
1856};
1857
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001858static unsigned int intel_mac_v3_pin_configs[10] = {
1859 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1860 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1861 0x400000fc, 0x400000fb,
1862};
1863
1864static unsigned int intel_mac_v4_pin_configs[10] = {
1865 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1866 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1867 0x400000fc, 0x400000fb,
1868};
1869
1870static unsigned int intel_mac_v5_pin_configs[10] = {
1871 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1872 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1873 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001874};
1875
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001876static unsigned int ecs202_pin_configs[10] = {
1877 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1878 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1879 0x9037012e, 0x40e000f2,
1880};
Takashi Iwai76c08822007-06-19 12:17:42 +02001881
Takashi Iwai19039bd2006-06-28 15:52:16 +02001882static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001883 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001884 [STAC_D945GTP3] = d945gtp3_pin_configs,
1885 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001886 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1887 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1888 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1889 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1890 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001891 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001892 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001893 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1894 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1895 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1896 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1897 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1898 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001899 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001900 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1901 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1902 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1903 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001904};
1905
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001906static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001907 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001908 [STAC_D945_REF] = "ref",
1909 [STAC_D945GTP5] = "5stack",
1910 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001911 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1912 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1913 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1914 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1915 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001916 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001917 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001918 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001919 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001920 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1921 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001922 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001923 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001924 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001925 [STAC_922X_DELL_D81] = "dell-d81",
1926 [STAC_922X_DELL_D82] = "dell-d82",
1927 [STAC_922X_DELL_M81] = "dell-m81",
1928 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001929};
1930
1931static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1932 /* SigmaTel reference board */
1933 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1934 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001935 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1936 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001937 /* Intel 945G based systems */
1938 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1939 "Intel D945G", STAC_D945GTP3),
1940 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1941 "Intel D945G", STAC_D945GTP3),
1942 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1943 "Intel D945G", STAC_D945GTP3),
1944 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1945 "Intel D945G", STAC_D945GTP3),
1946 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1947 "Intel D945G", STAC_D945GTP3),
1948 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1949 "Intel D945G", STAC_D945GTP3),
1950 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1951 "Intel D945G", STAC_D945GTP3),
1952 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1953 "Intel D945G", STAC_D945GTP3),
1954 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1955 "Intel D945G", STAC_D945GTP3),
1956 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1957 "Intel D945G", STAC_D945GTP3),
1958 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1959 "Intel D945G", STAC_D945GTP3),
1960 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1961 "Intel D945G", STAC_D945GTP3),
1962 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1963 "Intel D945G", STAC_D945GTP3),
1964 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1965 "Intel D945G", STAC_D945GTP3),
1966 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1967 "Intel D945G", STAC_D945GTP3),
1968 /* Intel D945G 5-stack systems */
1969 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1970 "Intel D945G", STAC_D945GTP5),
1971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1972 "Intel D945G", STAC_D945GTP5),
1973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1974 "Intel D945G", STAC_D945GTP5),
1975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1976 "Intel D945G", STAC_D945GTP5),
1977 /* Intel 945P based systems */
1978 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1979 "Intel D945P", STAC_D945GTP3),
1980 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1981 "Intel D945P", STAC_D945GTP3),
1982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1983 "Intel D945P", STAC_D945GTP3),
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1985 "Intel D945P", STAC_D945GTP3),
1986 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1987 "Intel D945P", STAC_D945GTP3),
1988 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1989 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01001990 /* other intel */
1991 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
1992 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001993 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08001994 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001995 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001996 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001997 /* Dell systems */
1998 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1999 "unknown Dell", STAC_922X_DELL_D81),
2000 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2001 "unknown Dell", STAC_922X_DELL_D81),
2002 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2003 "unknown Dell", STAC_922X_DELL_D81),
2004 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2005 "unknown Dell", STAC_922X_DELL_D82),
2006 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2007 "unknown Dell", STAC_922X_DELL_M81),
2008 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2009 "unknown Dell", STAC_922X_DELL_D82),
2010 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2011 "unknown Dell", STAC_922X_DELL_D81),
2012 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2013 "unknown Dell", STAC_922X_DELL_D81),
2014 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2015 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002016 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002017 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002018 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002019 {} /* terminator */
2020};
2021
Matt Porter3cc08dc2006-01-23 15:27:49 +01002022static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002023 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2024 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2025 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2026 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002027};
2028
Tobin Davis93ed1502006-09-01 21:03:12 +02002029static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002030 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2031 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2032 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2033 0x40000100, 0x40000100
2034};
2035
Tobin Davis93ed1502006-09-01 21:03:12 +02002036static unsigned int d965_5st_pin_configs[14] = {
2037 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2038 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2039 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2040 0x40000100, 0x40000100
2041};
2042
Takashi Iwai679d92e2009-05-24 19:00:08 +02002043static unsigned int d965_5st_no_fp_pin_configs[14] = {
2044 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2045 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2046 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2047 0x40000100, 0x40000100
2048};
2049
Tobin Davis4ff076e2007-08-07 11:48:12 +02002050static unsigned int dell_3st_pin_configs[14] = {
2051 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2052 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002053 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002054 0x40c003fc, 0x40000100
2055};
2056
Tobin Davis93ed1502006-09-01 21:03:12 +02002057static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002058 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002059 [STAC_D965_REF] = ref927x_pin_configs,
2060 [STAC_D965_3ST] = d965_3st_pin_configs,
2061 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002062 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002063 [STAC_DELL_3ST] = dell_3st_pin_configs,
2064 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002065 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002066};
2067
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002068static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002069 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002070 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002071 [STAC_D965_REF] = "ref",
2072 [STAC_D965_3ST] = "3stack",
2073 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002074 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002075 [STAC_DELL_3ST] = "dell-3stack",
2076 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002077 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002078};
2079
2080static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2081 /* SigmaTel reference board */
2082 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2083 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002084 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2085 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002086 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002087 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2088 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002089 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002090 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2091 "Intel D965", STAC_D965_3ST),
2092 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2093 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002094 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002095 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002096 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2097 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002098 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002099 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002100 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002101 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002102 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002103 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002104 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2106 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2107 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002108 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002109 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2110 "Intel D965", STAC_D965_5ST),
2111 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2112 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002113 /* volume-knob fixes */
2114 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002115 {} /* terminator */
2116};
2117
Matt Porterf3302a52006-07-31 12:49:34 +02002118static unsigned int ref9205_pin_configs[12] = {
2119 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002120 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002121 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002122};
2123
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002124/*
2125 STAC 9205 pin configs for
2126 102801F1
2127 102801F2
2128 102801FC
2129 102801FD
2130 10280204
2131 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002132 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002133 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002134*/
2135static unsigned int dell_9205_m42_pin_configs[12] = {
2136 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2137 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2138 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2139};
2140
2141/*
2142 STAC 9205 pin configs for
2143 102801F9
2144 102801FA
2145 102801FE
2146 102801FF (Dell Precision M4300)
2147 10280206
2148 10280200
2149 10280201
2150*/
2151static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002152 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2153 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2154 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2155};
2156
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002157static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002158 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2159 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2160 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2161};
2162
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002163static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002164 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002165 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2166 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2167 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002168 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002169};
2170
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002171static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002172 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002173 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002174 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002175 [STAC_9205_DELL_M43] = "dell-m43",
2176 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002177 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002178};
2179
2180static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2181 /* SigmaTel reference board */
2182 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2183 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002184 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2185 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002186 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2187 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002188 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002189 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2190 "unknown Dell", STAC_9205_DELL_M42),
2191 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2192 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002193 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002194 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002195 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2196 "Dell Precision", STAC_9205_DELL_M43),
2197 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2198 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002199 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2200 "unknown Dell", STAC_9205_DELL_M42),
2201 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2202 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002203 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2204 "Dell Precision", STAC_9205_DELL_M43),
2205 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002206 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002207 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2208 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002209 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2210 "Dell Precision", STAC_9205_DELL_M43),
2211 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2212 "Dell Precision", STAC_9205_DELL_M43),
2213 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2214 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002215 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2216 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002217 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2218 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002219 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2220 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002221 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002222 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002223 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002224 {} /* terminator */
2225};
2226
Takashi Iwai330ee992009-02-20 14:33:36 +01002227static void stac92xx_set_config_regs(struct hda_codec *codec,
2228 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002229{
2230 int i;
2231 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002232
Takashi Iwai330ee992009-02-20 14:33:36 +01002233 if (!pincfgs)
2234 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002235
Matthew Ranostay87d48362007-07-17 11:52:24 +02002236 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002237 if (spec->pin_nids[i] && pincfgs[i])
2238 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2239 pincfgs[i]);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002240}
2241
Matt2f2f4252005-04-13 14:45:30 +02002242/*
2243 * Analog playback callbacks
2244 */
2245static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2246 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002247 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002248{
2249 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002250 if (spec->stream_delay)
2251 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002252 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2253 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002254}
2255
2256static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2257 struct hda_codec *codec,
2258 unsigned int stream_tag,
2259 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002260 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002261{
2262 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002263 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002264}
2265
2266static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2267 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002268 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002269{
2270 struct sigmatel_spec *spec = codec->spec;
2271 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2272}
2273
2274/*
Mattdabbed62005-06-14 10:19:34 +02002275 * Digital playback callbacks
2276 */
2277static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2278 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002279 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002280{
2281 struct sigmatel_spec *spec = codec->spec;
2282 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2283}
2284
2285static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2286 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002287 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002288{
2289 struct sigmatel_spec *spec = codec->spec;
2290 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2291}
2292
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002293static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2294 struct hda_codec *codec,
2295 unsigned int stream_tag,
2296 unsigned int format,
2297 struct snd_pcm_substream *substream)
2298{
2299 struct sigmatel_spec *spec = codec->spec;
2300 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2301 stream_tag, format, substream);
2302}
2303
Takashi Iwai9411e212009-02-13 11:32:28 +01002304static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2305 struct hda_codec *codec,
2306 struct snd_pcm_substream *substream)
2307{
2308 struct sigmatel_spec *spec = codec->spec;
2309 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2310}
2311
Mattdabbed62005-06-14 10:19:34 +02002312
2313/*
Matt2f2f4252005-04-13 14:45:30 +02002314 * Analog capture callbacks
2315 */
2316static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2317 struct hda_codec *codec,
2318 unsigned int stream_tag,
2319 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002320 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002321{
2322 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002323 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002324
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002325 if (spec->powerdown_adcs) {
2326 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002327 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002328 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2329 }
2330 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002331 return 0;
2332}
2333
2334static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2335 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002336 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002337{
2338 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002339 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002340
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002341 snd_hda_codec_cleanup_stream(codec, nid);
2342 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002343 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002344 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002345 return 0;
2346}
2347
Mattdabbed62005-06-14 10:19:34 +02002348static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2349 .substreams = 1,
2350 .channels_min = 2,
2351 .channels_max = 2,
2352 /* NID is set in stac92xx_build_pcms */
2353 .ops = {
2354 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002355 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002356 .prepare = stac92xx_dig_playback_pcm_prepare,
2357 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002358 },
2359};
2360
2361static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2362 .substreams = 1,
2363 .channels_min = 2,
2364 .channels_max = 2,
2365 /* NID is set in stac92xx_build_pcms */
2366};
2367
Matt2f2f4252005-04-13 14:45:30 +02002368static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2369 .substreams = 1,
2370 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002371 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002372 .nid = 0x02, /* NID to query formats and rates */
2373 .ops = {
2374 .open = stac92xx_playback_pcm_open,
2375 .prepare = stac92xx_playback_pcm_prepare,
2376 .cleanup = stac92xx_playback_pcm_cleanup
2377 },
2378};
2379
Matt Porter3cc08dc2006-01-23 15:27:49 +01002380static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2381 .substreams = 1,
2382 .channels_min = 2,
2383 .channels_max = 2,
2384 .nid = 0x06, /* NID to query formats and rates */
2385 .ops = {
2386 .open = stac92xx_playback_pcm_open,
2387 .prepare = stac92xx_playback_pcm_prepare,
2388 .cleanup = stac92xx_playback_pcm_cleanup
2389 },
2390};
2391
Matt2f2f4252005-04-13 14:45:30 +02002392static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002393 .channels_min = 2,
2394 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002395 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002396 .ops = {
2397 .prepare = stac92xx_capture_pcm_prepare,
2398 .cleanup = stac92xx_capture_pcm_cleanup
2399 },
2400};
2401
2402static int stac92xx_build_pcms(struct hda_codec *codec)
2403{
2404 struct sigmatel_spec *spec = codec->spec;
2405 struct hda_pcm *info = spec->pcm_rec;
2406
2407 codec->num_pcms = 1;
2408 codec->pcm_info = info;
2409
Mattc7d4b2f2005-06-27 14:59:41 +02002410 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002411 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002412 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2413 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002414 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002415 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002416 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002417
2418 if (spec->alt_switch) {
2419 codec->num_pcms++;
2420 info++;
2421 info->name = "STAC92xx Analog Alt";
2422 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2423 }
Matt2f2f4252005-04-13 14:45:30 +02002424
Mattdabbed62005-06-14 10:19:34 +02002425 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2426 codec->num_pcms++;
2427 info++;
2428 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002429 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002430 if (spec->multiout.dig_out_nid) {
2431 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2432 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2433 }
2434 if (spec->dig_in_nid) {
2435 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2436 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2437 }
2438 }
2439
Matt2f2f4252005-04-13 14:45:30 +02002440 return 0;
2441}
2442
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002443static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2444 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002445{
Takashi Iwai1327a322009-03-23 13:07:47 +01002446 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002447 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2448 if (pincap & AC_PINCAP_VREF_100)
2449 return AC_PINCTL_VREF_100;
2450 if (pincap & AC_PINCAP_VREF_80)
2451 return AC_PINCTL_VREF_80;
2452 if (pincap & AC_PINCAP_VREF_50)
2453 return AC_PINCTL_VREF_50;
2454 if (pincap & AC_PINCAP_VREF_GRD)
2455 return AC_PINCTL_VREF_GRD;
2456 return 0;
2457}
2458
Matt Porter403d1942005-11-29 15:00:51 +01002459static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2460
2461{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002462 snd_hda_codec_write_cache(codec, nid, 0,
2463 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002464}
2465
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002466#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2467
2468static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2469 struct snd_ctl_elem_value *ucontrol)
2470{
2471 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2472 struct sigmatel_spec *spec = codec->spec;
2473
Takashi Iwaid7a89432008-11-12 09:48:04 +01002474 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002475 return 0;
2476}
2477
Takashi Iwai62558ce2009-07-29 14:23:09 +02002478static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002479
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002480static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2481 struct snd_ctl_elem_value *ucontrol)
2482{
2483 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2484 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002485 int nid = kcontrol->private_value;
2486
2487 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002488
2489 /* check to be sure that the ports are upto date with
2490 * switch changes
2491 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002492 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002493
2494 return 1;
2495}
2496
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002497static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2498 struct snd_ctl_elem_info *uinfo)
2499{
2500 int i;
2501 static char *texts[] = {
2502 "Mic In", "Line In", "Line Out"
2503 };
2504
2505 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2506 struct sigmatel_spec *spec = codec->spec;
2507 hda_nid_t nid = kcontrol->private_value;
2508
2509 if (nid == spec->mic_switch || nid == spec->line_switch)
2510 i = 3;
2511 else
2512 i = 2;
2513
2514 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2515 uinfo->value.enumerated.items = i;
2516 uinfo->count = 1;
2517 if (uinfo->value.enumerated.item >= i)
2518 uinfo->value.enumerated.item = i-1;
2519 strcpy(uinfo->value.enumerated.name,
2520 texts[uinfo->value.enumerated.item]);
2521
2522 return 0;
2523}
2524
2525static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2526 struct snd_ctl_elem_value *ucontrol)
2527{
2528 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2529 hda_nid_t nid = kcontrol->private_value;
2530 unsigned int vref = stac92xx_vref_get(codec, nid);
2531
2532 if (vref == stac92xx_get_default_vref(codec, nid))
2533 ucontrol->value.enumerated.item[0] = 0;
2534 else if (vref == AC_PINCTL_VREF_GRD)
2535 ucontrol->value.enumerated.item[0] = 1;
2536 else if (vref == AC_PINCTL_VREF_HIZ)
2537 ucontrol->value.enumerated.item[0] = 2;
2538
2539 return 0;
2540}
2541
2542static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2543 struct snd_ctl_elem_value *ucontrol)
2544{
2545 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2546 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002547 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002548 hda_nid_t nid = kcontrol->private_value;
2549
2550 if (ucontrol->value.enumerated.item[0] == 0)
2551 new_vref = stac92xx_get_default_vref(codec, nid);
2552 else if (ucontrol->value.enumerated.item[0] == 1)
2553 new_vref = AC_PINCTL_VREF_GRD;
2554 else if (ucontrol->value.enumerated.item[0] == 2)
2555 new_vref = AC_PINCTL_VREF_HIZ;
2556 else
2557 return 0;
2558
2559 if (new_vref != stac92xx_vref_get(codec, nid)) {
2560 error = stac92xx_vref_set(codec, nid, new_vref);
2561 return error;
2562 }
2563
2564 return 0;
2565}
2566
2567static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2568 struct snd_ctl_elem_info *uinfo)
2569{
2570 static char *texts[2];
2571 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2572 struct sigmatel_spec *spec = codec->spec;
2573
2574 if (kcontrol->private_value == spec->line_switch)
2575 texts[0] = "Line In";
2576 else
2577 texts[0] = "Mic In";
2578 texts[1] = "Line Out";
2579 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2580 uinfo->value.enumerated.items = 2;
2581 uinfo->count = 1;
2582
2583 if (uinfo->value.enumerated.item >= 2)
2584 uinfo->value.enumerated.item = 1;
2585 strcpy(uinfo->value.enumerated.name,
2586 texts[uinfo->value.enumerated.item]);
2587
2588 return 0;
2589}
Matt Porter403d1942005-11-29 15:00:51 +01002590
2591static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2592{
2593 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2594 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002595 hda_nid_t nid = kcontrol->private_value;
2596 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002597
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002598 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002599 return 0;
2600}
2601
2602static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2603{
2604 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2605 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002606 hda_nid_t nid = kcontrol->private_value;
2607 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2608 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002609
2610 spec->io_switch[io_idx] = val;
2611
2612 if (val)
2613 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002614 else {
2615 unsigned int pinctl = AC_PINCTL_IN_EN;
2616 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002617 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002618 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2619 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002620
2621 /* check the auto-mute again: we need to mute/unmute the speaker
2622 * appropriately according to the pin direction
2623 */
2624 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002625 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002626
Matt Porter403d1942005-11-29 15:00:51 +01002627 return 1;
2628}
2629
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002630#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2631
2632static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2633 struct snd_ctl_elem_value *ucontrol)
2634{
2635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2636 struct sigmatel_spec *spec = codec->spec;
2637
2638 ucontrol->value.integer.value[0] = spec->clfe_swap;
2639 return 0;
2640}
2641
2642static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2643 struct snd_ctl_elem_value *ucontrol)
2644{
2645 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2646 struct sigmatel_spec *spec = codec->spec;
2647 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002648 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002649
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002650 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002651 return 0;
2652
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002653 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002654
2655 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2656 spec->clfe_swap ? 0x4 : 0x0);
2657
2658 return 1;
2659}
2660
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002661#define STAC_CODEC_HP_SWITCH(xname) \
2662 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2663 .name = xname, \
2664 .index = 0, \
2665 .info = stac92xx_hp_switch_info, \
2666 .get = stac92xx_hp_switch_get, \
2667 .put = stac92xx_hp_switch_put, \
2668 }
2669
Matt Porter403d1942005-11-29 15:00:51 +01002670#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2671 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2672 .name = xname, \
2673 .index = 0, \
2674 .info = stac92xx_io_switch_info, \
2675 .get = stac92xx_io_switch_get, \
2676 .put = stac92xx_io_switch_put, \
2677 .private_value = xpval, \
2678 }
2679
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002680#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2681 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2682 .name = xname, \
2683 .index = 0, \
2684 .info = stac92xx_clfe_switch_info, \
2685 .get = stac92xx_clfe_switch_get, \
2686 .put = stac92xx_clfe_switch_put, \
2687 .private_value = xpval, \
2688 }
Matt Porter403d1942005-11-29 15:00:51 +01002689
Mattc7d4b2f2005-06-27 14:59:41 +02002690enum {
2691 STAC_CTL_WIDGET_VOL,
2692 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002693 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002694 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002695 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002696 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002697 STAC_CTL_WIDGET_CLFE_SWITCH,
2698 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002699};
2700
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002701static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002702 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2703 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002704 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002705 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002706 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002707 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002708 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002709 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002710};
2711
2712/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002713static struct snd_kcontrol_new *
2714stac_control_new(struct sigmatel_spec *spec,
2715 struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002716 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002717 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002718{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002719 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002720
Takashi Iwai603c4012008-07-30 15:01:44 +02002721 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2722 knew = snd_array_new(&spec->kctls);
2723 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002724 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002725 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002726 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002727 if (!knew->name) {
2728 /* roolback */
2729 memset(knew, 0, sizeof(*knew));
2730 spec->kctls.alloced--;
2731 return NULL;
2732 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002733 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002734 return knew;
2735}
2736
2737static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2738 struct snd_kcontrol_new *ktemp,
2739 int idx, const char *name,
2740 unsigned long val)
2741{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002742 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002743 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002744 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002745 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002746 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002747 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002748 return 0;
2749}
2750
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002751static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2752 int type, int idx, const char *name,
2753 unsigned long val)
2754{
2755 return stac92xx_add_control_temp(spec,
2756 &stac92xx_control_templates[type],
2757 idx, name, val);
2758}
2759
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002760
2761/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002762static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2763 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002764{
2765 return stac92xx_add_control_idx(spec, type, 0, name, val);
2766}
2767
Takashi Iwaie3c75962009-01-23 11:57:22 +01002768static struct snd_kcontrol_new stac_input_src_temp = {
2769 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2770 .name = "Input Source",
2771 .info = stac92xx_mux_enum_info,
2772 .get = stac92xx_mux_enum_get,
2773 .put = stac92xx_mux_enum_put,
2774};
2775
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002776static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2777 hda_nid_t nid, int idx)
2778{
2779 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2780 int control = 0;
2781 struct sigmatel_spec *spec = codec->spec;
2782 char name[22];
2783
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002784 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002785 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2786 && nid == spec->line_switch)
2787 control = STAC_CTL_WIDGET_IO_SWITCH;
2788 else if (snd_hda_query_pin_caps(codec, nid)
2789 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2790 control = STAC_CTL_WIDGET_DC_BIAS;
2791 else if (nid == spec->mic_switch)
2792 control = STAC_CTL_WIDGET_IO_SWITCH;
2793 }
2794
2795 if (control) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002796 strcpy(name, hda_get_input_pin_label(codec, nid, 1));
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002797 return stac92xx_add_control(codec->spec, control,
2798 strcat(name, " Jack Mode"), nid);
2799 }
2800
2801 return 0;
2802}
2803
Takashi Iwaie3c75962009-01-23 11:57:22 +01002804static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2805{
2806 struct snd_kcontrol_new *knew;
2807 struct hda_input_mux *imux = &spec->private_imux;
2808
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002809 if (spec->auto_mic)
2810 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002811 if (!spec->num_adcs || imux->num_items <= 1)
2812 return 0; /* no need for input source control */
2813 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002814 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002815 if (!knew)
2816 return -ENOMEM;
2817 knew->count = spec->num_adcs;
2818 return 0;
2819}
2820
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002821/* check whether the line-input can be used as line-out */
2822static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002823{
2824 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002825 struct auto_pin_cfg *cfg = &spec->autocfg;
2826 hda_nid_t nid;
2827 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002828 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002829
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002830 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2831 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002832 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02002833 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002834 nid = cfg->inputs[i].pin;
2835 pincap = snd_hda_query_pin_caps(codec, nid);
2836 if (pincap & AC_PINCAP_OUT)
2837 return nid;
2838 }
2839 }
Matt Porter403d1942005-11-29 15:00:51 +01002840 return 0;
2841}
2842
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002843static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2844
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002845/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002846static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002847{
2848 struct sigmatel_spec *spec = codec->spec;
2849 struct auto_pin_cfg *cfg = &spec->autocfg;
2850 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02002851 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002852
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002853 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002854 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2855 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002856 for (i = 0; i < cfg->num_inputs; i++) {
2857 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02002858 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002859 continue;
Takashi Iwai330ee992009-02-20 14:33:36 +01002860 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002861 /* some laptops have an internal analog microphone
2862 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002863 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwai1327a322009-03-23 13:07:47 +01002864 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002865 if (pincap & AC_PINCAP_OUT) {
2866 *dac = get_unassigned_dac(codec, nid);
2867 if (*dac)
2868 return nid;
2869 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002870 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002871 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002872 return 0;
2873}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002874
2875static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2876{
2877 int i;
2878
2879 for (i = 0; i < spec->multiout.num_dacs; i++) {
2880 if (spec->multiout.dac_nids[i] == nid)
2881 return 1;
2882 }
2883
2884 return 0;
2885}
2886
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002887static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2888{
2889 int i;
2890 if (is_in_dac_nids(spec, nid))
2891 return 1;
2892 for (i = 0; i < spec->autocfg.hp_outs; i++)
2893 if (spec->hp_dacs[i] == nid)
2894 return 1;
2895 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2896 if (spec->speaker_dacs[i] == nid)
2897 return 1;
2898 return 0;
2899}
2900
2901static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2902{
2903 struct sigmatel_spec *spec = codec->spec;
2904 int j, conn_len;
2905 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2906 unsigned int wcaps, wtype;
2907
2908 conn_len = snd_hda_get_connections(codec, nid, conn,
2909 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002910 /* 92HD88: trace back up the link of nids to find the DAC */
2911 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2912 != AC_WID_AUD_OUT)) {
2913 nid = conn[0];
2914 conn_len = snd_hda_get_connections(codec, nid, conn,
2915 HDA_MAX_CONNECTIONS);
2916 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002917 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002918 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002919 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002920 /* we check only analog outputs */
2921 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2922 continue;
2923 /* if this route has a free DAC, assign it */
2924 if (!check_all_dac_nids(spec, conn[j])) {
2925 if (conn_len > 1) {
2926 /* select this DAC in the pin's input mux */
2927 snd_hda_codec_write_cache(codec, nid, 0,
2928 AC_VERB_SET_CONNECT_SEL, j);
2929 }
2930 return conn[j];
2931 }
2932 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002933 /* if all DACs are already assigned, connect to the primary DAC */
2934 if (conn_len > 1) {
2935 for (j = 0; j < conn_len; j++) {
2936 if (conn[j] == spec->multiout.dac_nids[0]) {
2937 snd_hda_codec_write_cache(codec, nid, 0,
2938 AC_VERB_SET_CONNECT_SEL, j);
2939 break;
2940 }
2941 }
2942 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002943 return 0;
2944}
2945
2946static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2947static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2948
Matt Porter3cc08dc2006-01-23 15:27:49 +01002949/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002950 * Fill in the dac_nids table from the parsed pin configuration
2951 * This function only works when every pin in line_out_pins[]
2952 * contains atleast one DAC in its connection list. Some 92xx
2953 * codecs are not connected directly to a DAC, such as the 9200
2954 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002955 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002956static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002957{
2958 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002959 struct auto_pin_cfg *cfg = &spec->autocfg;
2960 int i;
2961 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002962
Mattc7d4b2f2005-06-27 14:59:41 +02002963 for (i = 0; i < cfg->line_outs; i++) {
2964 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002965 dac = get_unassigned_dac(codec, nid);
2966 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002967 if (spec->multiout.num_dacs > 0) {
2968 /* we have already working output pins,
2969 * so let's drop the broken ones again
2970 */
2971 cfg->line_outs = spec->multiout.num_dacs;
2972 break;
2973 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002974 /* error out, no available DAC found */
2975 snd_printk(KERN_ERR
2976 "%s: No available DAC for pin 0x%x\n",
2977 __func__, nid);
2978 return -ENODEV;
2979 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002980 add_spec_dacs(spec, dac);
2981 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002982
Takashi Iwai139e0712009-03-06 12:10:41 +01002983 for (i = 0; i < cfg->hp_outs; i++) {
2984 nid = cfg->hp_pins[i];
2985 dac = get_unassigned_dac(codec, nid);
2986 if (dac) {
2987 if (!spec->multiout.hp_nid)
2988 spec->multiout.hp_nid = dac;
2989 else
2990 add_spec_extra_dacs(spec, dac);
2991 }
2992 spec->hp_dacs[i] = dac;
2993 }
2994
2995 for (i = 0; i < cfg->speaker_outs; i++) {
2996 nid = cfg->speaker_pins[i];
2997 dac = get_unassigned_dac(codec, nid);
2998 if (dac)
2999 add_spec_extra_dacs(spec, dac);
3000 spec->speaker_dacs[i] = dac;
3001 }
3002
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003003 /* add line-in as output */
3004 nid = check_line_out_switch(codec);
3005 if (nid) {
3006 dac = get_unassigned_dac(codec, nid);
3007 if (dac) {
3008 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3009 nid, cfg->line_outs);
3010 cfg->line_out_pins[cfg->line_outs] = nid;
3011 cfg->line_outs++;
3012 spec->line_switch = nid;
3013 add_spec_dacs(spec, dac);
3014 }
3015 }
3016 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003017 nid = check_mic_out_switch(codec, &dac);
3018 if (nid && dac) {
3019 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3020 nid, cfg->line_outs);
3021 cfg->line_out_pins[cfg->line_outs] = nid;
3022 cfg->line_outs++;
3023 spec->mic_switch = nid;
3024 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003025 }
3026
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003027 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003028 spec->multiout.num_dacs,
3029 spec->multiout.dac_nids[0],
3030 spec->multiout.dac_nids[1],
3031 spec->multiout.dac_nids[2],
3032 spec->multiout.dac_nids[3],
3033 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003034
Mattc7d4b2f2005-06-27 14:59:41 +02003035 return 0;
3036}
3037
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003038/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003039static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3040 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003041{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003042 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003043 char name[32];
3044 int err;
3045
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003046 if (!spec->check_volume_offset) {
3047 unsigned int caps, step, nums, db_scale;
3048 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3049 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3050 AC_AMPCAP_STEP_SIZE_SHIFT;
3051 step = (step + 1) * 25; /* in .01dB unit */
3052 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3053 AC_AMPCAP_NUM_STEPS_SHIFT;
3054 db_scale = nums * step;
3055 /* if dB scale is over -64dB, and finer enough,
3056 * let's reduce it to half
3057 */
3058 if (db_scale > 6400 && nums >= 0x1f)
3059 spec->volume_offset = nums / 2;
3060 spec->check_volume_offset = 1;
3061 }
3062
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003063 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003064 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003065 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3066 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003067 if (err < 0)
3068 return err;
3069 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003070 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003071 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3072 if (err < 0)
3073 return err;
3074 return 0;
3075}
3076
Takashi Iwai668b9652009-03-06 10:13:24 +01003077#define create_controls(codec, pfx, nid, chs) \
3078 create_controls_idx(codec, pfx, 0, nid, chs)
3079
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003080static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3081{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003082 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003083 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3084 return 1;
3085 } else {
3086 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3087 spec->multiout.num_dacs++;
3088 }
3089 return 0;
3090}
3091
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003092static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003093{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003094 int i;
3095 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3096 if (!spec->multiout.extra_out_nid[i]) {
3097 spec->multiout.extra_out_nid[i] = nid;
3098 return 0;
3099 }
3100 }
3101 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3102 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003103}
3104
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003105/* Create output controls
3106 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3107 */
3108static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3109 const hda_nid_t *pins,
3110 const hda_nid_t *dac_nids,
3111 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003112{
Takashi Iwai76624532008-12-19 10:09:47 +01003113 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003114 static const char *chname[4] = {
3115 "Front", "Surround", NULL /*CLFE*/, "Side"
3116 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003117 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003118 int i, err;
3119 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003120
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003121 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003122 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3123 wid_caps = get_wcaps(codec, pins[i]);
3124 if (wid_caps & AC_WCAP_UNSOL_CAP)
3125 spec->hp_detect = 1;
3126 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003127 nid = dac_nids[i];
3128 if (!nid)
3129 continue;
3130 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003131 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003132 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003133 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003134 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003135 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003136 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003137 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003138
3139 wid_caps = get_wcaps(codec, nid);
3140
3141 if (wid_caps & AC_WCAP_LR_SWAP) {
3142 err = stac92xx_add_control(spec,
3143 STAC_CTL_WIDGET_CLFE_SWITCH,
3144 "Swap Center/LFE Playback Switch", nid);
3145
3146 if (err < 0)
3147 return err;
3148 }
3149
Mattc7d4b2f2005-06-27 14:59:41 +02003150 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003151 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003152 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003153 switch (type) {
3154 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003155 name = "Headphone";
3156 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003157 break;
3158 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003159 name = "Speaker";
3160 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003161 break;
3162 default:
3163 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003164 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003165 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003166 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003167 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003168 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003169 return err;
3170 }
3171 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003172 return 0;
3173}
3174
Takashi Iwai6479c632009-07-28 18:20:25 +02003175static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3176 unsigned long sw, int idx)
3177{
3178 int err;
3179 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003180 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003181 if (err < 0)
3182 return err;
3183 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003184 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003185 if (err < 0)
3186 return err;
3187 return 0;
3188}
3189
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003190/* add playback controls from the parsed DAC table */
3191static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3192 const struct auto_pin_cfg *cfg)
3193{
3194 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003195 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003196 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003197 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003198
3199 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3200 spec->multiout.dac_nids,
3201 cfg->line_out_type);
3202 if (err < 0)
3203 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003204
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003205 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003206 err = stac92xx_add_control(spec,
3207 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003208 "Headphone as Line Out Switch",
3209 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003210 if (err < 0)
3211 return err;
3212 }
3213
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003214 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003215 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003216 break;
3217 nid = cfg->inputs[idx].pin;
3218 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3219 if (err < 0)
3220 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003221 }
Matt Porter403d1942005-11-29 15:00:51 +01003222
Mattc7d4b2f2005-06-27 14:59:41 +02003223 return 0;
3224}
3225
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003226/* add playback controls for Speaker and HP outputs */
3227static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3228 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003229{
3230 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003231 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003232
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003233 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3234 spec->hp_dacs, AUTO_PIN_HP_OUT);
3235 if (err < 0)
3236 return err;
3237
3238 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3239 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3240 if (err < 0)
3241 return err;
3242
Mattc7d4b2f2005-06-27 14:59:41 +02003243 return 0;
3244}
3245
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003246/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003247static const char *stac92xx_mono_labels[4] = {
3248 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003249};
3250
3251/* create mono mux for mono out on capable codecs */
3252static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3253{
3254 struct sigmatel_spec *spec = codec->spec;
3255 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3256 int i, num_cons;
3257 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3258
3259 num_cons = snd_hda_get_connections(codec,
3260 spec->mono_nid,
3261 con_lst,
3262 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003263 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003264 return -EINVAL;
3265
Takashi Iwai10a20af2010-09-09 16:28:02 +02003266 for (i = 0; i < num_cons; i++)
3267 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3268 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003269
3270 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3271 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003272}
3273
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003274/* create PC beep volume controls */
3275static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3276 hda_nid_t nid)
3277{
3278 struct sigmatel_spec *spec = codec->spec;
3279 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003280 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3281
3282 if (spec->anabeep_nid == nid)
3283 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003284
3285 /* check for mute support for the the amp */
3286 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003287 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003288 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003289 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3290 if (err < 0)
3291 return err;
3292 }
3293
3294 /* check to see if there is volume support for the amp */
3295 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3296 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003297 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003298 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3299 if (err < 0)
3300 return err;
3301 }
3302 return 0;
3303}
3304
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003305#ifdef CONFIG_SND_HDA_INPUT_BEEP
3306#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3307
3308static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3309 struct snd_ctl_elem_value *ucontrol)
3310{
3311 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3312 ucontrol->value.integer.value[0] = codec->beep->enabled;
3313 return 0;
3314}
3315
3316static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3317 struct snd_ctl_elem_value *ucontrol)
3318{
3319 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003320 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003321}
3322
3323static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3324 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3325 .info = stac92xx_dig_beep_switch_info,
3326 .get = stac92xx_dig_beep_switch_get,
3327 .put = stac92xx_dig_beep_switch_put,
3328};
3329
3330static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3331{
3332 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003333 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003334}
3335#endif
3336
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003337static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3338{
3339 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003340 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003341
3342 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003343 hda_nid_t nid;
3344 unsigned int wcaps;
3345 unsigned long val;
3346
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003347 nid = spec->mux_nids[i];
3348 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003349 if (!(wcaps & AC_WCAP_OUT_AMP))
3350 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003351
Takashi Iwai667067d2009-08-13 18:14:42 +02003352 /* check whether already the same control was created as
3353 * normal Capture Volume.
3354 */
3355 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3356 for (j = 0; j < spec->num_caps; j++) {
3357 if (spec->capvols[j] == val)
3358 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003359 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003360 if (j < spec->num_caps)
3361 continue;
3362
3363 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3364 "Mux Capture Volume", val);
3365 if (err < 0)
3366 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003367 }
3368 return 0;
3369};
3370
Matthew Ranostayd9737752008-09-07 12:03:41 +02003371static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003372 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003373};
3374
3375static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3376{
3377 struct sigmatel_spec *spec = codec->spec;
3378 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003379 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003380 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003381 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003382
3383 num_cons = snd_hda_get_connections(codec,
3384 spec->smux_nids[0],
3385 con_lst,
3386 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003387 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003388 return -EINVAL;
3389
Matthew Ranostay65973632008-09-16 10:39:37 -04003390 if (!labels)
3391 labels = stac92xx_spdif_labels;
3392
Takashi Iwai10a20af2010-09-09 16:28:02 +02003393 for (i = 0; i < num_cons; i++)
3394 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003395
3396 return 0;
3397}
3398
Matt Porter8b657272006-10-26 17:12:59 +02003399/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003400static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003401 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3402 "Digital Mic 3", "Digital Mic 4"
3403};
3404
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003405static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3406 hda_nid_t nid)
3407{
3408 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3409 int i, nums;
3410
3411 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3412 for (i = 0; i < nums; i++)
3413 if (conn[i] == nid)
3414 return i;
3415 return -1;
3416}
3417
Takashi Iwai667067d2009-08-13 18:14:42 +02003418/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003419/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003420static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003421 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003422{
3423 unsigned int caps, nums;
3424 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003425 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003426
Takashi Iwai96f845d2009-08-29 00:49:36 +02003427 if (direction == HDA_OUTPUT)
3428 caps = AC_WCAP_OUT_AMP;
3429 else
3430 caps = AC_WCAP_IN_AMP;
3431 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003432 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003433 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003434 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3435 if (!nums)
3436 return 0;
3437 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003438 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3439 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003440 if (err < 0)
3441 return err;
3442 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003443}
3444
Matt Porter8b657272006-10-26 17:12:59 +02003445/* create playback/capture controls for input pins on dmic capable codecs */
3446static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3447 const struct auto_pin_cfg *cfg)
3448{
3449 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003450 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003451 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003452 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003453 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003454
Takashi Iwai10a20af2010-09-09 16:28:02 +02003455 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Matt Porter8b657272006-10-26 17:12:59 +02003456
3457 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003458 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003459 int index, type_idx;
Takashi Iwai5207e102009-07-30 13:09:08 +02003460 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003461
Takashi Iwai667067d2009-08-13 18:14:42 +02003462 nid = spec->dmic_nids[i];
3463 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3464 continue;
3465 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003466 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3467 continue;
3468
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003469 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3470 if (index < 0)
3471 continue;
3472
Takashi Iwai10a20af2010-09-09 16:28:02 +02003473 label = hda_get_input_pin_label(codec, nid, 1);
3474 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003475
Takashi Iwai10a20af2010-09-09 16:28:02 +02003476 err = create_elem_capture_vol(codec, nid, label, type_idx,
3477 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003478 if (err < 0)
3479 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003480 if (!err) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02003481 err = create_elem_capture_vol(codec, nid, label,
3482 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003483 if (err < 0)
3484 return err;
3485 }
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003486
Vitaliy Kulikovf41cc2a2010-09-24 16:21:53 -05003487 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02003488 snd_hda_add_imux_item(imux, label, index, NULL);
Vitaliy Kulikovf41cc2a2010-09-24 16:21:53 -05003489 spec->num_analog_muxes++;
3490 }
Matt Porter8b657272006-10-26 17:12:59 +02003491 }
3492
3493 return 0;
3494}
3495
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003496static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003497 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003498{
3499 unsigned int cfg;
3500
3501 if (!nid)
3502 return 0;
3503 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003504 switch (snd_hda_get_input_pin_attr(cfg)) {
3505 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003506 if (*fixed)
3507 return 1; /* already occupied */
3508 *fixed = nid;
3509 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003510 case INPUT_PIN_ATTR_UNUSED:
3511 break;
3512 case INPUT_PIN_ATTR_DOCK:
3513 if (*dock)
3514 return 1; /* already occupied */
3515 *dock = nid;
3516 break;
3517 default:
3518 if (*ext)
3519 return 1; /* already occupied */
3520 *ext = nid;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003521 break;
3522 }
3523 return 0;
3524}
3525
3526static int set_mic_route(struct hda_codec *codec,
3527 struct sigmatel_mic_route *mic,
3528 hda_nid_t pin)
3529{
3530 struct sigmatel_spec *spec = codec->spec;
3531 struct auto_pin_cfg *cfg = &spec->autocfg;
3532 int i;
3533
3534 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003535 if (pin == 0)
3536 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003537 for (i = 0; i < cfg->num_inputs; i++) {
3538 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003539 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003540 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003541 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003542 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003543 i = get_connection_index(codec, spec->mux_nids[0], pin);
3544 if (i < 0)
3545 return -1;
3546 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003547 mic->dmux_idx = -1;
3548 if (spec->dmux_nids)
3549 mic->dmux_idx = get_connection_index(codec,
3550 spec->dmux_nids[0],
3551 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003552 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003553 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003554 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3555 if (i < 0)
3556 return -1;
3557 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003558 mic->mux_idx = -1;
3559 if (spec->mux_nids)
3560 mic->mux_idx = get_connection_index(codec,
3561 spec->mux_nids[0],
3562 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003563 }
3564 return 0;
3565}
3566
3567/* return non-zero if the device is for automatic mic switch */
3568static int stac_check_auto_mic(struct hda_codec *codec)
3569{
3570 struct sigmatel_spec *spec = codec->spec;
3571 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02003572 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003573 int i;
3574
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003575 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003576 if (cfg->inputs[i].type >= AUTO_PIN_LINE_IN)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003577 return 0; /* must be exclusively mics */
3578 }
Charles Chin99077902010-09-17 10:22:32 +02003579 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003580 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02003581 if (check_mic_pin(codec, cfg->inputs[i].pin,
3582 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003583 return 0;
3584 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02003585 if (check_mic_pin(codec, spec->dmic_nids[i],
3586 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003587 return 0;
Charles Chin99077902010-09-17 10:22:32 +02003588 if (!fixed && !ext && !dock)
3589 return 0; /* no input to switch */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003590 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3591 return 0; /* no unsol support */
3592 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02003593 set_mic_route(codec, &spec->int_mic, fixed) ||
3594 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003595 return 0; /* something is wrong */
3596 return 1;
3597}
3598
Mattc7d4b2f2005-06-27 14:59:41 +02003599/* create playback/capture controls for input pins */
3600static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3601{
3602 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003603 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003604 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003605 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02003606
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003607 for (i = 0; i < cfg->num_inputs; i++) {
3608 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003609 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02003610
Takashi Iwai314634b2006-09-21 11:56:18 +02003611 index = -1;
3612 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003613 index = get_connection_index(codec, spec->mux_nids[j],
3614 nid);
3615 if (index >= 0)
3616 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003617 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003618 if (index < 0)
3619 continue;
3620
Takashi Iwai10a20af2010-09-09 16:28:02 +02003621 label = hda_get_autocfg_input_label(codec, cfg, i);
3622 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003623
Takashi Iwai667067d2009-08-13 18:14:42 +02003624 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003625 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003626 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003627 if (err < 0)
3628 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003629 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003630 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003631
Steve Longerbeam7b043892007-05-03 20:50:03 +02003632 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003633 /*
3634 * Set the current input for the muxes.
3635 * The STAC9221 has two input muxes with identical source
3636 * NID lists. Hopefully this won't get confused.
3637 */
3638 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003639 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3640 AC_VERB_SET_CONNECT_SEL,
3641 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003642 }
3643 }
3644
Mattc7d4b2f2005-06-27 14:59:41 +02003645 return 0;
3646}
3647
Mattc7d4b2f2005-06-27 14:59:41 +02003648static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3649{
3650 struct sigmatel_spec *spec = codec->spec;
3651 int i;
3652
3653 for (i = 0; i < spec->autocfg.line_outs; i++) {
3654 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3655 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3656 }
3657}
3658
3659static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3660{
3661 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003662 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003663
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003664 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3665 hda_nid_t pin;
3666 pin = spec->autocfg.hp_pins[i];
3667 if (pin) /* connect to front */
3668 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3669 }
3670 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3671 hda_nid_t pin;
3672 pin = spec->autocfg.speaker_pins[i];
3673 if (pin) /* connect to front */
3674 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3675 }
Mattc7d4b2f2005-06-27 14:59:41 +02003676}
3677
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003678static int is_dual_headphones(struct hda_codec *codec)
3679{
3680 struct sigmatel_spec *spec = codec->spec;
3681 int i, valid_hps;
3682
3683 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3684 spec->autocfg.hp_outs <= 1)
3685 return 0;
3686 valid_hps = 0;
3687 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3688 hda_nid_t nid = spec->autocfg.hp_pins[i];
3689 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3690 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3691 continue;
3692 valid_hps++;
3693 }
3694 return (valid_hps > 1);
3695}
3696
3697
Matt Porter3cc08dc2006-01-23 15:27:49 +01003698static 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 +02003699{
3700 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003701 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003702 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003703
Matt Porter8b657272006-10-26 17:12:59 +02003704 if ((err = snd_hda_parse_pin_def_config(codec,
3705 &spec->autocfg,
3706 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003707 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003708 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003709 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003710
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003711 /* If we have no real line-out pin and multiple hp-outs, HPs should
3712 * be set up as multi-channel outputs.
3713 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003714 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003715 /* Copy hp_outs to line_outs, backup line_outs in
3716 * speaker_outs so that the following routines can handle
3717 * HP pins as primary outputs.
3718 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003719 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003720 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3721 sizeof(spec->autocfg.line_out_pins));
3722 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3723 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3724 sizeof(spec->autocfg.hp_pins));
3725 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003726 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3727 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003728 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003729 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003730 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003731 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3732 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003733 u32 caps = query_amp_caps(codec,
3734 spec->autocfg.mono_out_pin, dir);
3735 hda_nid_t conn_list[1];
3736
3737 /* get the mixer node and then the mono mux if it exists */
3738 if (snd_hda_get_connections(codec,
3739 spec->autocfg.mono_out_pin, conn_list, 1) &&
3740 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003741 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003742
3743 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003744 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003745 /* LR swap check, some stac925x have a mux that
3746 * changes the DACs output path instead of the
3747 * mono-mux path.
3748 */
3749 if (wid_type == AC_WID_AUD_SEL &&
3750 !(wcaps & AC_WCAP_LR_SWAP))
3751 spec->mono_nid = conn_list[0];
3752 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003753 if (dir) {
3754 hda_nid_t nid = spec->autocfg.mono_out_pin;
3755
3756 /* most mono outs have a least a mute/unmute switch */
3757 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3758 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3759 "Mono Playback Switch",
3760 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003761 if (err < 0)
3762 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003763 /* check for volume support for the amp */
3764 if ((caps & AC_AMPCAP_NUM_STEPS)
3765 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3766 err = stac92xx_add_control(spec,
3767 STAC_CTL_WIDGET_VOL,
3768 "Mono Playback Volume",
3769 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3770 if (err < 0)
3771 return err;
3772 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003773 }
3774
3775 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3776 AC_PINCTL_OUT_EN);
3777 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003778
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003779 if (!spec->multiout.num_dacs) {
3780 err = stac92xx_auto_fill_dac_nids(codec);
3781 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003782 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003783 err = stac92xx_auto_create_multi_out_ctls(codec,
3784 &spec->autocfg);
3785 if (err < 0)
3786 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003787 }
Mattc7d4b2f2005-06-27 14:59:41 +02003788
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003789 /* setup analog beep controls */
3790 if (spec->anabeep_nid > 0) {
3791 err = stac92xx_auto_create_beep_ctls(codec,
3792 spec->anabeep_nid);
3793 if (err < 0)
3794 return err;
3795 }
3796
3797 /* setup digital beep controls and input device */
3798#ifdef CONFIG_SND_HDA_INPUT_BEEP
3799 if (spec->digbeep_nid > 0) {
3800 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003801 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003802
3803 err = stac92xx_auto_create_beep_ctls(codec, nid);
3804 if (err < 0)
3805 return err;
3806 err = snd_hda_attach_beep_device(codec, nid);
3807 if (err < 0)
3808 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003809 if (codec->beep) {
3810 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01003811 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003812 /* if no beep switch is available, make its own one */
3813 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3814 if (!(caps & AC_AMPCAP_MUTE)) {
3815 err = stac92xx_beep_switch_ctl(codec);
3816 if (err < 0)
3817 return err;
3818 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003819 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003820 }
3821#endif
3822
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003823 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003824 if (err < 0)
3825 return err;
3826
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003827 /* All output parsing done, now restore the swapped hp pins */
3828 if (hp_swap) {
3829 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3830 sizeof(spec->autocfg.hp_pins));
3831 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3832 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3833 spec->autocfg.line_outs = 0;
3834 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003835
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003836 if (stac_check_auto_mic(codec)) {
3837 spec->auto_mic = 1;
3838 /* only one capture for auto-mic */
3839 spec->num_adcs = 1;
3840 spec->num_caps = 1;
3841 spec->num_muxes = 1;
3842 }
3843
Takashi Iwai6479c632009-07-28 18:20:25 +02003844 for (i = 0; i < spec->num_caps; i++) {
3845 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3846 spec->capsws[i], i);
3847 if (err < 0)
3848 return err;
3849 }
3850
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003851 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003852 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003853 return err;
3854
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003855 if (spec->mono_nid > 0) {
3856 err = stac92xx_auto_create_mono_output_ctls(codec);
3857 if (err < 0)
3858 return err;
3859 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003860 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003861 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3862 &spec->autocfg)) < 0)
3863 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003864 if (spec->num_muxes > 0) {
3865 err = stac92xx_auto_create_mux_input_ctls(codec);
3866 if (err < 0)
3867 return err;
3868 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003869 if (spec->num_smuxes > 0) {
3870 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3871 if (err < 0)
3872 return err;
3873 }
Matt Porter8b657272006-10-26 17:12:59 +02003874
Takashi Iwaie3c75962009-01-23 11:57:22 +01003875 err = stac92xx_add_input_source(spec);
3876 if (err < 0)
3877 return err;
3878
Mattc7d4b2f2005-06-27 14:59:41 +02003879 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003880 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003881 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003882
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003883 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003884 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003885 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003886 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003887
Takashi Iwai603c4012008-07-30 15:01:44 +02003888 if (spec->kctls.list)
3889 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003890
3891 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003892 if (!spec->dinput_mux)
3893 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003894 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003895 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003896 return 1;
3897}
3898
Takashi Iwai82bc9552006-03-21 11:24:42 +01003899/* add playback controls for HP output */
3900static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3901 struct auto_pin_cfg *cfg)
3902{
3903 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003904 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003905 unsigned int wid_caps;
3906
3907 if (! pin)
3908 return 0;
3909
3910 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003911 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003912 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003913
3914 return 0;
3915}
3916
Richard Fish160ea0d2006-09-06 13:58:25 +02003917/* add playback controls for LFE output */
3918static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3919 struct auto_pin_cfg *cfg)
3920{
3921 struct sigmatel_spec *spec = codec->spec;
3922 int err;
3923 hda_nid_t lfe_pin = 0x0;
3924 int i;
3925
3926 /*
3927 * search speaker outs and line outs for a mono speaker pin
3928 * with an amp. If one is found, add LFE controls
3929 * for it.
3930 */
3931 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3932 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003933 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003934 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3935 if (wcaps == AC_WCAP_OUT_AMP)
3936 /* found a mono speaker with an amp, must be lfe */
3937 lfe_pin = pin;
3938 }
3939
3940 /* if speaker_outs is 0, then speakers may be in line_outs */
3941 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3942 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3943 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003944 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01003945 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01003946 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003947 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003948 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3949 if (wcaps == AC_WCAP_OUT_AMP)
3950 /* found a mono speaker with an amp,
3951 must be lfe */
3952 lfe_pin = pin;
3953 }
3954 }
3955 }
3956
3957 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003958 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003959 if (err < 0)
3960 return err;
3961 }
3962
3963 return 0;
3964}
3965
Mattc7d4b2f2005-06-27 14:59:41 +02003966static int stac9200_parse_auto_config(struct hda_codec *codec)
3967{
3968 struct sigmatel_spec *spec = codec->spec;
3969 int err;
3970
Kailang Yangdf694da2005-12-05 19:42:22 +01003971 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003972 return err;
3973
3974 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3975 return err;
3976
Takashi Iwai82bc9552006-03-21 11:24:42 +01003977 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3978 return err;
3979
Richard Fish160ea0d2006-09-06 13:58:25 +02003980 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3981 return err;
3982
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003983 if (spec->num_muxes > 0) {
3984 err = stac92xx_auto_create_mux_input_ctls(codec);
3985 if (err < 0)
3986 return err;
3987 }
3988
Takashi Iwaie3c75962009-01-23 11:57:22 +01003989 err = stac92xx_add_input_source(spec);
3990 if (err < 0)
3991 return err;
3992
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003993 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02003994 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003995 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003996 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003997
Takashi Iwai603c4012008-07-30 15:01:44 +02003998 if (spec->kctls.list)
3999 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004000
4001 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004002 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004003
4004 return 1;
4005}
4006
Sam Revitch62fe78e2006-05-10 15:09:17 +02004007/*
4008 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4009 * funky external mute control using GPIO pins.
4010 */
4011
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004012static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004013 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004014{
4015 unsigned int gpiostate, gpiomask, gpiodir;
4016
4017 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4018 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004019 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004020
4021 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4022 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004023 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004024
4025 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4026 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004027 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004028
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004029 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004030 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4031
4032 snd_hda_codec_write(codec, codec->afg, 0,
4033 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004034 snd_hda_codec_read(codec, codec->afg, 0,
4035 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004036
4037 msleep(1);
4038
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004039 snd_hda_codec_read(codec, codec->afg, 0,
4040 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004041}
4042
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004043#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +02004044static void stac92xx_free_jack_priv(struct snd_jack *jack)
4045{
4046 struct sigmatel_jack *jacks = jack->private_data;
4047 jacks->nid = 0;
4048 jacks->jack = NULL;
4049}
4050#endif
4051
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004052static int stac92xx_add_jack(struct hda_codec *codec,
4053 hda_nid_t nid, int type)
4054{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004055#ifdef CONFIG_SND_HDA_INPUT_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004056 struct sigmatel_spec *spec = codec->spec;
4057 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01004058 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004059 int connectivity = get_defcfg_connect(def_conf);
4060 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02004061 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004062
4063 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4064 return 0;
4065
4066 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4067 jack = snd_array_new(&spec->jacks);
4068 if (!jack)
4069 return -ENOMEM;
4070 jack->nid = nid;
4071 jack->type = type;
4072
Takashi Iwai86de74162009-07-22 16:02:46 +02004073 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004074 snd_hda_get_jack_type(def_conf),
4075 snd_hda_get_jack_connectivity(def_conf),
4076 snd_hda_get_jack_location(def_conf));
4077
Takashi Iwai95c09092009-04-14 16:15:29 +02004078 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4079 if (err < 0) {
4080 jack->nid = 0;
4081 return err;
4082 }
4083 jack->jack->private_data = jack;
4084 jack->jack->private_free = stac92xx_free_jack_priv;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004085#endif
Takashi Iwai95c09092009-04-14 16:15:29 +02004086 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004087}
4088
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004089static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4090 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004091{
4092 struct sigmatel_event *event;
4093
4094 snd_array_init(&spec->events, sizeof(*event), 32);
4095 event = snd_array_new(&spec->events);
4096 if (!event)
4097 return -ENOMEM;
4098 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004099 event->type = type;
4100 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004101 event->data = data;
4102
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004103 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004104}
4105
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004106static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004107 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004108{
4109 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004110 struct sigmatel_event *event = spec->events.list;
4111 int i;
4112
4113 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004114 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004115 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004116 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004117 return NULL;
4118}
4119
4120static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4121 unsigned char tag)
4122{
4123 struct sigmatel_spec *spec = codec->spec;
4124 struct sigmatel_event *event = spec->events.list;
4125 int i;
4126
4127 for (i = 0; i < spec->events.used; i++, event++) {
4128 if (event->tag == tag)
4129 return event;
4130 }
4131 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004132}
4133
Takashi Iwai62558ce2009-07-29 14:23:09 +02004134/* check if given nid is a valid pin and no other events are assigned
4135 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4136 * Otherwise, returns zero.
4137 */
4138static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4139 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004140{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004141 struct sigmatel_event *event;
4142 int tag;
4143
4144 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004145 return 0;
4146 event = stac_get_event(codec, nid);
4147 if (event) {
4148 if (event->type != type)
4149 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004150 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004151 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004152 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004153 if (tag < 0)
4154 return 0;
4155 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004156 snd_hda_codec_write_cache(codec, nid, 0,
4157 AC_VERB_SET_UNSOLICITED_ENABLE,
4158 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004159 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004160}
4161
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004162static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4163{
4164 int i;
4165 for (i = 0; i < cfg->hp_outs; i++)
4166 if (cfg->hp_pins[i] == nid)
4167 return 1; /* nid is a HP-Out */
4168
4169 return 0; /* nid is not a HP-Out */
4170};
4171
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004172static void stac92xx_power_down(struct hda_codec *codec)
4173{
4174 struct sigmatel_spec *spec = codec->spec;
4175
4176 /* power down inactive DACs */
4177 hda_nid_t *dac;
4178 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004179 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004180 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004181 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4182}
4183
Takashi Iwaif73d3582008-11-25 08:21:51 +01004184static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4185 int enable);
4186
Takashi Iwai014c41f2009-12-27 13:53:24 +01004187static inline int get_int_hint(struct hda_codec *codec, const char *key,
4188 int *valp)
4189{
4190 const char *p;
4191 p = snd_hda_get_hint(codec, key);
4192 if (p) {
4193 unsigned long val;
4194 if (!strict_strtoul(p, 0, &val)) {
4195 *valp = val;
4196 return 1;
4197 }
4198 }
4199 return 0;
4200}
4201
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004202/* override some hints from the hwdep entry */
4203static void stac_store_hints(struct hda_codec *codec)
4204{
4205 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004206 int val;
4207
4208 val = snd_hda_get_bool_hint(codec, "hp_detect");
4209 if (val >= 0)
4210 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004211 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004212 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4213 spec->gpio_mask;
4214 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004215 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4216 spec->gpio_mask &= spec->gpio_mask;
4217 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4218 spec->gpio_dir &= spec->gpio_mask;
4219 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4220 spec->eapd_mask &= spec->gpio_mask;
4221 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4222 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004223 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4224 if (val >= 0)
4225 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004226 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4227 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Takashi Iwai043958e2009-12-26 10:36:12 +01004228 spec->gpio_mask |= spec->gpio_led;
4229 spec->gpio_dir |= spec->gpio_led;
4230 if (spec->gpio_led_polarity)
4231 spec->gpio_data |= spec->gpio_led;
4232 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004233}
4234
Mattc7d4b2f2005-06-27 14:59:41 +02004235static int stac92xx_init(struct hda_codec *codec)
4236{
4237 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004238 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004239 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004240 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004241
Mattc7d4b2f2005-06-27 14:59:41 +02004242 snd_hda_sequence_write(codec, spec->init);
4243
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004244 /* power down adcs initially */
4245 if (spec->powerdown_adcs)
4246 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004247 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004248 spec->adc_nids[i], 0,
4249 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004250
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004251 /* override some hints */
4252 stac_store_hints(codec);
4253
Takashi Iwaif73d3582008-11-25 08:21:51 +01004254 /* set up GPIO */
4255 gpio = spec->gpio_data;
4256 /* turn on EAPD statically when spec->eapd_switch isn't set.
4257 * otherwise, unsol event will turn it on/off dynamically
4258 */
4259 if (!spec->eapd_switch)
4260 gpio |= spec->eapd_mask;
4261 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4262
Takashi Iwai82bc9552006-03-21 11:24:42 +01004263 /* set up pins */
4264 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004265 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004266 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004267 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004268 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004269 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004270 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4271 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004272 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004273 for (i = 0; i < cfg->line_outs; i++) {
4274 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004275 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4276 }
4277 }
4278
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004279 /* force to enable the first line-out; the others are set up
4280 * in unsol_event
4281 */
4282 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004283 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004284 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004285 if (cfg->hp_pins[0])
4286 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4287 else if (cfg->line_out_pins[0])
4288 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004289 } else {
4290 stac92xx_auto_init_multi_out(codec);
4291 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004292 for (i = 0; i < cfg->hp_outs; i++)
4293 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004294 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004295 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004296 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004297 if (spec->dmux_nids)
4298 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004299 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004300 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4301 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004302 if (enable_pin_detect(codec, spec->dock_mic.pin,
4303 STAC_MIC_EVENT))
4304 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004305 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004306 for (i = 0; i < cfg->num_inputs; i++) {
4307 hda_nid_t nid = cfg->inputs[i].pin;
4308 int type = cfg->inputs[i].type;
4309 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004310 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004311 /* for mic pins, force to initialize */
4312 pinctl = stac92xx_get_default_vref(codec, nid);
4313 pinctl |= AC_PINCTL_IN_EN;
4314 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4315 } else {
4316 pinctl = snd_hda_codec_read(codec, nid, 0,
4317 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4318 /* if PINCTL already set then skip */
4319 /* Also, if both INPUT and OUTPUT are set,
4320 * it must be a BIOS bug; need to override, too
4321 */
4322 if (!(pinctl & AC_PINCTL_IN_EN) ||
4323 (pinctl & AC_PINCTL_OUT_EN)) {
4324 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004325 pinctl |= AC_PINCTL_IN_EN;
4326 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004327 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004328 }
4329 conf = snd_hda_codec_get_pincfg(codec, nid);
4330 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4331 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4332 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004333 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004334 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004335 for (i = 0; i < spec->num_dmics; i++)
4336 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4337 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004338 if (cfg->dig_out_pins[0])
4339 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004340 AC_PINCTL_OUT_EN);
4341 if (cfg->dig_in_pin)
4342 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4343 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004344 for (i = 0; i < spec->num_pwrs; i++) {
4345 hda_nid_t nid = spec->pwr_nids[i];
4346 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004347
Takashi Iwaieb632122008-12-19 16:39:48 +01004348 /* power on when no jack detection is available */
4349 if (!spec->hp_detect) {
4350 stac_toggle_power_map(codec, nid, 1);
4351 continue;
4352 }
4353
4354 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004355 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004356
Takashi Iwaif73d3582008-11-25 08:21:51 +01004357 pinctl = snd_hda_codec_read(codec, nid, 0,
4358 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4359 /* outputs are only ports capable of power management
4360 * any attempts on powering down a input port cause the
4361 * referenced VREF to act quirky.
4362 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004363 if (pinctl & AC_PINCTL_IN_EN) {
4364 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004365 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004366 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004367 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004368 def_conf = get_defcfg_connect(def_conf);
4369 /* skip any ports that don't have jacks since presence
4370 * detection is useless */
4371 if (def_conf != AC_JACK_PORT_COMPLEX) {
4372 if (def_conf != AC_JACK_PORT_NONE)
4373 stac_toggle_power_map(codec, nid, 1);
4374 continue;
4375 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004376 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4377 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004378 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004379
Takashi Iwaic21bd022010-02-08 15:16:08 +01004380 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004381 if (spec->gpio_led)
4382 hda_call_check_power_status(codec, 0x01);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004383 if (spec->dac_list)
4384 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004385 return 0;
4386}
4387
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004388static void stac92xx_free_jacks(struct hda_codec *codec)
4389{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004390#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwaib94d3532008-11-21 09:08:06 +01004391 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004392 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d3532008-11-21 09:08:06 +01004393 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004394 struct sigmatel_jack *jacks = spec->jacks.list;
4395 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +02004396 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4397 if (jacks->jack)
4398 snd_device_free(codec->bus->card, jacks->jack);
4399 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004400 }
4401 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004402#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004403}
4404
Takashi Iwai603c4012008-07-30 15:01:44 +02004405static void stac92xx_free_kctls(struct hda_codec *codec)
4406{
4407 struct sigmatel_spec *spec = codec->spec;
4408
4409 if (spec->kctls.list) {
4410 struct snd_kcontrol_new *kctl = spec->kctls.list;
4411 int i;
4412 for (i = 0; i < spec->kctls.used; i++)
4413 kfree(kctl[i].name);
4414 }
4415 snd_array_free(&spec->kctls);
4416}
4417
Takashi Iwai167eae52009-11-06 15:47:50 +01004418static void stac92xx_shutup(struct hda_codec *codec)
4419{
4420 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004421
Takashi Iwai92ee6162009-12-27 11:18:59 +01004422 snd_hda_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004423
4424 if (spec->eapd_mask)
4425 stac_gpio_set(codec, spec->gpio_mask,
4426 spec->gpio_dir, spec->gpio_data &
4427 ~spec->eapd_mask);
4428}
4429
Matt2f2f4252005-04-13 14:45:30 +02004430static void stac92xx_free(struct hda_codec *codec)
4431{
Mattc7d4b2f2005-06-27 14:59:41 +02004432 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004433
4434 if (! spec)
4435 return;
4436
Takashi Iwai167eae52009-11-06 15:47:50 +01004437 stac92xx_shutup(codec);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004438 stac92xx_free_jacks(codec);
4439 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004440
Mattc7d4b2f2005-06-27 14:59:41 +02004441 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004442 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004443}
4444
Matt4e550962005-07-04 17:51:39 +02004445static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4446 unsigned int flag)
4447{
Takashi Iwai8ce841982009-01-22 16:59:20 +01004448 unsigned int old_ctl, pin_ctl;
4449
4450 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004451 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004452
Takashi Iwaif9acba42007-05-29 18:01:06 +02004453 if (pin_ctl & AC_PINCTL_IN_EN) {
4454 /*
4455 * we need to check the current set-up direction of
4456 * shared input pins since they can be switched via
4457 * "xxx as Output" mixer switch
4458 */
4459 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004460 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004461 return;
4462 }
4463
Takashi Iwai8ce841982009-01-22 16:59:20 +01004464 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004465 /* if setting pin direction bits, clear the current
4466 direction bits first */
4467 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4468 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4469
Takashi Iwai8ce841982009-01-22 16:59:20 +01004470 pin_ctl |= flag;
4471 if (old_ctl != pin_ctl)
4472 snd_hda_codec_write_cache(codec, nid, 0,
4473 AC_VERB_SET_PIN_WIDGET_CONTROL,
4474 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004475}
4476
4477static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4478 unsigned int flag)
4479{
4480 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4481 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce841982009-01-22 16:59:20 +01004482 if (pin_ctl & flag)
4483 snd_hda_codec_write_cache(codec, nid, 0,
4484 AC_VERB_SET_PIN_WIDGET_CONTROL,
4485 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004486}
4487
Takashi Iwaid56757a2009-11-18 08:00:14 +01004488static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004489{
4490 if (!nid)
4491 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004492 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004493}
4494
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004495static void stac92xx_line_out_detect(struct hda_codec *codec,
4496 int presence)
4497{
4498 struct sigmatel_spec *spec = codec->spec;
4499 struct auto_pin_cfg *cfg = &spec->autocfg;
4500 int i;
4501
4502 for (i = 0; i < cfg->line_outs; i++) {
4503 if (presence)
4504 break;
4505 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4506 if (presence) {
4507 unsigned int pinctl;
4508 pinctl = snd_hda_codec_read(codec,
4509 cfg->line_out_pins[i], 0,
4510 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4511 if (pinctl & AC_PINCTL_IN_EN)
4512 presence = 0; /* mic- or line-input */
4513 }
4514 }
4515
4516 if (presence) {
4517 /* disable speakers */
4518 for (i = 0; i < cfg->speaker_outs; i++)
4519 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4520 AC_PINCTL_OUT_EN);
4521 if (spec->eapd_mask && spec->eapd_switch)
4522 stac_gpio_set(codec, spec->gpio_mask,
4523 spec->gpio_dir, spec->gpio_data &
4524 ~spec->eapd_mask);
4525 } else {
4526 /* enable speakers */
4527 for (i = 0; i < cfg->speaker_outs; i++)
4528 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4529 AC_PINCTL_OUT_EN);
4530 if (spec->eapd_mask && spec->eapd_switch)
4531 stac_gpio_set(codec, spec->gpio_mask,
4532 spec->gpio_dir, spec->gpio_data |
4533 spec->eapd_mask);
4534 }
4535}
4536
Takashi Iwaid7a89432008-11-12 09:48:04 +01004537/* return non-zero if the hp-pin of the given array index isn't
4538 * a jack-detection target
4539 */
4540static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4541{
4542 struct auto_pin_cfg *cfg = &spec->autocfg;
4543
4544 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004545 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004546 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004547 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004548 return 1;
4549 /* ignore if the pin is set as line-out */
4550 if (cfg->hp_pins[i] == spec->hp_switch)
4551 return 1;
4552 return 0;
4553}
4554
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004555static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004556{
4557 struct sigmatel_spec *spec = codec->spec;
4558 struct auto_pin_cfg *cfg = &spec->autocfg;
4559 int i, presence;
4560
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004561 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004562 if (spec->gpio_mute)
4563 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4564 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4565
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004566 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004567 if (presence)
4568 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004569 if (no_hp_sensing(spec, i))
4570 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004571 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4572 if (presence) {
4573 unsigned int pinctl;
4574 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4575 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4576 if (pinctl & AC_PINCTL_IN_EN)
4577 presence = 0; /* mic- or line-input */
4578 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004579 }
Matt4e550962005-07-04 17:51:39 +02004580
4581 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004582 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004583 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004584 stac92xx_reset_pinctl(codec, spec->hp_switch,
4585 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004586 for (i = 0; i < cfg->line_outs; i++)
4587 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4588 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004589 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004590 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004591 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004592 stac92xx_set_pinctl(codec, spec->hp_switch,
4593 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004594 for (i = 0; i < cfg->line_outs; i++)
4595 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4596 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004597 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004598 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004599 /* toggle hp outs */
4600 for (i = 0; i < cfg->hp_outs; i++) {
4601 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4602 if (no_hp_sensing(spec, i))
4603 continue;
4604 if (presence)
4605 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004606#if 0 /* FIXME */
4607/* Resetting the pinctl like below may lead to (a sort of) regressions
4608 * on some devices since they use the HP pin actually for line/speaker
4609 * outs although the default pin config shows a different pin (that is
4610 * wrong and useless).
4611 *
4612 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4613 * But, disabling the code below just works around it, and I'm too tired of
4614 * bug reports with such devices...
4615 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004616 else
4617 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004618#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004619 }
Matt4e550962005-07-04 17:51:39 +02004620}
4621
Takashi Iwaif73d3582008-11-25 08:21:51 +01004622static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4623 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004624{
4625 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004626 unsigned int idx, val;
4627
4628 for (idx = 0; idx < spec->num_pwrs; idx++) {
4629 if (spec->pwr_nids[idx] == nid)
4630 break;
4631 }
4632 if (idx >= spec->num_pwrs)
4633 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004634
4635 /* several codecs have two power down bits */
4636 if (spec->pwr_mapping)
4637 idx = spec->pwr_mapping[idx];
4638 else
4639 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004640
Takashi Iwaif73d3582008-11-25 08:21:51 +01004641 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4642 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004643 val &= ~idx;
4644 else
4645 val |= idx;
4646
4647 /* power down unused output ports */
4648 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004649}
4650
Takashi Iwaif73d3582008-11-25 08:21:51 +01004651static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4652{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004653 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004654}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004655
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004656static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4657{
4658 struct sigmatel_spec *spec = codec->spec;
4659 struct sigmatel_jack *jacks = spec->jacks.list;
4660
4661 if (jacks) {
4662 int i;
4663 for (i = 0; i < spec->jacks.used; i++) {
4664 if (jacks->nid == nid) {
4665 unsigned int pin_ctl =
4666 snd_hda_codec_read(codec, nid,
4667 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4668 0x00);
4669 int type = jacks->type;
4670 if (type == (SND_JACK_LINEOUT
4671 | SND_JACK_HEADPHONE))
4672 type = (pin_ctl & AC_PINCTL_HP_EN)
4673 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4674 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004675 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004676 ? type : 0);
4677 }
4678 jacks++;
4679 }
4680 }
4681}
Matt2f2f4252005-04-13 14:45:30 +02004682
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004683/* get the pin connection (fixed, none, etc) */
4684static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4685{
4686 struct sigmatel_spec *spec = codec->spec;
4687 unsigned int cfg;
4688
4689 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4690 return get_defcfg_connect(cfg);
4691}
4692
4693static int stac92xx_connected_ports(struct hda_codec *codec,
4694 hda_nid_t *nids, int num_nids)
4695{
4696 struct sigmatel_spec *spec = codec->spec;
4697 int idx, num;
4698 unsigned int def_conf;
4699
4700 for (num = 0; num < num_nids; num++) {
4701 for (idx = 0; idx < spec->num_pins; idx++)
4702 if (spec->pin_nids[idx] == nids[num])
4703 break;
4704 if (idx >= spec->num_pins)
4705 break;
4706 def_conf = stac_get_defcfg_connect(codec, idx);
4707 if (def_conf == AC_JACK_PORT_NONE)
4708 break;
4709 }
4710 return num;
4711}
4712
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004713static void stac92xx_mic_detect(struct hda_codec *codec)
4714{
4715 struct sigmatel_spec *spec = codec->spec;
4716 struct sigmatel_mic_route *mic;
4717
4718 if (get_pin_presence(codec, spec->ext_mic.pin))
4719 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02004720 else if (get_pin_presence(codec, spec->dock_mic.pin))
4721 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004722 else
4723 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004724 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004725 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4726 AC_VERB_SET_CONNECT_SEL,
4727 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004728 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004729 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4730 AC_VERB_SET_CONNECT_SEL,
4731 mic->mux_idx);
4732}
4733
Takashi Iwai62558ce2009-07-29 14:23:09 +02004734static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004735{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004736 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004737 if (!event)
4738 return;
4739 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4740}
4741
Takashi Iwai314634b2006-09-21 11:56:18 +02004742static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4743{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004744 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004745 struct sigmatel_event *event;
4746 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004747
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004748 tag = (res >> 26) & 0x7f;
4749 event = stac_get_event_from_tag(codec, tag);
4750 if (!event)
4751 return;
4752
4753 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004754 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004755 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004756 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004757 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004758 case STAC_MIC_EVENT:
4759 stac92xx_mic_detect(codec);
4760 break;
4761 }
4762
4763 switch (event->type) {
4764 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004765 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004766 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004767 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004768 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004769 if (spec->num_pwrs > 0)
4770 stac92xx_pin_sense(codec, event->nid);
4771 stac92xx_report_jack(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004772
4773 switch (codec->subsystem_id) {
4774 case 0x103c308f:
4775 if (event->nid == 0xb) {
4776 int pin = AC_PINCTL_IN_EN;
4777
4778 if (get_pin_presence(codec, 0xa)
4779 && get_pin_presence(codec, 0xb))
4780 pin |= AC_PINCTL_VREF_80;
4781 if (!get_pin_presence(codec, 0xb))
4782 pin |= AC_PINCTL_VREF_80;
4783
4784 /* toggle VREF state based on mic + hp pin
4785 * status
4786 */
4787 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4788 }
4789 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004790 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004791 case STAC_VREF_EVENT:
4792 data = snd_hda_codec_read(codec, codec->afg, 0,
4793 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004794 /* toggle VREF state based on GPIOx status */
4795 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004796 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004797 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004798 }
4799}
4800
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304801static int hp_blike_system(u32 subsystem_id);
4802
4803static void set_hp_led_gpio(struct hda_codec *codec)
4804{
4805 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004806 unsigned int gpio;
4807
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004808 if (spec->gpio_led)
4809 return;
4810
Takashi Iwai07f80442010-02-08 15:06:13 +01004811 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4812 gpio &= AC_GPIO_IO_COUNT;
4813 if (gpio > 3)
4814 spec->gpio_led = 0x08; /* GPIO 3 */
4815 else
4816 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304817}
4818
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004819/*
4820 * This method searches for the mute LED GPIO configuration
4821 * provided as OEM string in SMBIOS. The format of that string
4822 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4823 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4824 * that corresponds to the NOT muted state of the master volume
4825 * and G is the index of the GPIO to use as the mute LED control (0..9)
4826 * If _G portion is missing it is assigned based on the codec ID
4827 *
4828 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4829 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304830 *
4831 *
4832 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4833 * SMBIOS - at least the ones I have seen do not have them - which include
4834 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4835 * HP Pavilion dv9500t CTO.
4836 * Need more information on whether it is true across the entire series.
4837 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004838 */
Takashi Iwaidce17d42010-02-09 09:25:26 +01004839static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004840{
4841 struct sigmatel_spec *spec = codec->spec;
4842 const struct dmi_device *dev = NULL;
4843
4844 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4845 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4846 NULL, dev))) {
4847 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304848 &spec->gpio_led_polarity,
4849 &spec->gpio_led) == 2) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004850 spec->gpio_led = 1 << spec->gpio_led;
4851 return 1;
4852 }
4853 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304854 &spec->gpio_led_polarity) == 1) {
4855 set_hp_led_gpio(codec);
4856 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004857 }
4858 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304859
4860 /*
4861 * Fallback case - if we don't find the DMI strings,
4862 * we statically set the GPIO - if not a B-series system.
4863 */
4864 if (!hp_blike_system(codec->subsystem_id)) {
4865 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004866 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304867 return 1;
4868 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004869 }
4870 return 0;
4871}
4872
4873static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004874{
4875 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004876 case 0x103c1520:
4877 case 0x103c1521:
4878 case 0x103c1523:
4879 case 0x103c1524:
4880 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004881 case 0x103c1722:
4882 case 0x103c1723:
4883 case 0x103c1724:
4884 case 0x103c1725:
4885 case 0x103c1726:
4886 case 0x103c1727:
4887 case 0x103c1728:
4888 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004889 case 0x103c172a:
4890 case 0x103c172b:
4891 case 0x103c307e:
4892 case 0x103c307f:
4893 case 0x103c3080:
4894 case 0x103c3081:
4895 case 0x103c7007:
4896 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004897 return 1;
4898 }
4899 return 0;
4900}
4901
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004902#ifdef CONFIG_PROC_FS
4903static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4904 struct hda_codec *codec, hda_nid_t nid)
4905{
4906 if (nid == codec->afg)
4907 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4908 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4909}
4910
4911static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4912 struct hda_codec *codec,
4913 unsigned int verb)
4914{
4915 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4916 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4917}
4918
4919/* stac92hd71bxx, stac92hd73xx */
4920static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4921 struct hda_codec *codec, hda_nid_t nid)
4922{
4923 stac92hd_proc_hook(buffer, codec, nid);
4924 if (nid == codec->afg)
4925 analog_loop_proc_hook(buffer, codec, 0xfa0);
4926}
4927
4928static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4929 struct hda_codec *codec, hda_nid_t nid)
4930{
4931 if (nid == codec->afg)
4932 analog_loop_proc_hook(buffer, codec, 0xfe0);
4933}
4934
4935static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4936 struct hda_codec *codec, hda_nid_t nid)
4937{
4938 if (nid == codec->afg)
4939 analog_loop_proc_hook(buffer, codec, 0xfeb);
4940}
4941#else
4942#define stac92hd_proc_hook NULL
4943#define stac92hd7x_proc_hook NULL
4944#define stac9205_proc_hook NULL
4945#define stac927x_proc_hook NULL
4946#endif
4947
Takashi Iwaicb53c622007-08-10 17:21:45 +02004948#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004949static int stac92xx_resume(struct hda_codec *codec)
4950{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004951 struct sigmatel_spec *spec = codec->spec;
4952
Takashi Iwai2c885872008-11-18 09:36:55 +01004953 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004954 snd_hda_codec_resume_amp(codec);
4955 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004956 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004957 if (spec->hp_detect) {
4958 if (spec->autocfg.hp_pins[0])
4959 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4960 else if (spec->autocfg.line_out_pins[0])
4961 stac_issue_unsol_event(codec,
4962 spec->autocfg.line_out_pins[0]);
4963 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004964 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004965 if (spec->gpio_led)
4966 hda_call_check_power_status(codec, 0x01);
Mattff6fdc32005-06-27 15:06:52 +02004967 return 0;
4968}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004969
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004970/*
James Gardiner514bf542009-05-03 04:00:44 -04004971 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004972 * check for mute state only on Speakers (nid = 0x10)
4973 *
4974 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4975 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004976 *
4977 * Changed name to reflect that it now works for any designated
4978 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004979 */
4980
4981#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004982static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004983 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004984{
4985 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21bd022010-02-08 15:16:08 +01004986 int i, muted = 1;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004987
Takashi Iwaic21bd022010-02-08 15:16:08 +01004988 for (i = 0; i < spec->multiout.num_dacs; i++) {
4989 nid = spec->multiout.dac_nids[i];
4990 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4991 HDA_AMP_MUTE)) {
4992 muted = 0; /* something heard */
4993 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01004994 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004995 }
4996 if (muted)
4997 spec->gpio_data &= ~spec->gpio_led; /* orange */
4998 else
4999 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005000
Takashi Iwaic21bd022010-02-08 15:16:08 +01005001 if (!spec->gpio_led_polarity) {
5002 /* LED state is inverted on these systems */
5003 spec->gpio_data ^= spec->gpio_led;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005004 }
5005
Takashi Iwaib4e81872009-11-18 17:20:24 +01005006 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
Takashi Iwaib4e81872009-11-18 17:20:24 +01005007 return 0;
5008}
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005009#endif
5010
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005011static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
5012{
Takashi Iwai167eae52009-11-06 15:47:50 +01005013 stac92xx_shutup(codec);
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005014 return 0;
5015}
Mattff6fdc32005-06-27 15:06:52 +02005016#endif
5017
Matt2f2f4252005-04-13 14:45:30 +02005018static struct hda_codec_ops stac92xx_patch_ops = {
5019 .build_controls = stac92xx_build_controls,
5020 .build_pcms = stac92xx_build_pcms,
5021 .init = stac92xx_init,
5022 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02005023 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02005024#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005025 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005026 .resume = stac92xx_resume,
5027#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005028 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005029};
5030
5031static int patch_stac9200(struct hda_codec *codec)
5032{
5033 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005034 int err;
Matt2f2f4252005-04-13 14:45:30 +02005035
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005036 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005037 if (spec == NULL)
5038 return -ENOMEM;
5039
Takashi Iwaia252c812009-12-25 22:56:20 +01005040 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005041 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005042 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005043 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005044 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005045 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5046 stac9200_models,
5047 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005048 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005049 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5050 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005051 else
5052 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005053 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005054
5055 spec->multiout.max_channels = 2;
5056 spec->multiout.num_dacs = 1;
5057 spec->multiout.dac_nids = stac9200_dac_nids;
5058 spec->adc_nids = stac9200_adc_nids;
5059 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005060 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005061 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005062 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005063 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005064
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005065 if (spec->board_config == STAC_9200_M4 ||
5066 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005067 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005068 spec->init = stac9200_eapd_init;
5069 else
5070 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005071 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005072
Takashi Iwai117f2572008-03-18 09:53:23 +01005073 if (spec->board_config == STAC_9200_PANASONIC) {
5074 spec->gpio_mask = spec->gpio_dir = 0x09;
5075 spec->gpio_data = 0x00;
5076 }
5077
Mattc7d4b2f2005-06-27 14:59:41 +02005078 err = stac9200_parse_auto_config(codec);
5079 if (err < 0) {
5080 stac92xx_free(codec);
5081 return err;
5082 }
Matt2f2f4252005-04-13 14:45:30 +02005083
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005084 /* CF-74 has no headphone detection, and the driver should *NOT*
5085 * do detection and HP/speaker toggle because the hardware does it.
5086 */
5087 if (spec->board_config == STAC_9200_PANASONIC)
5088 spec->hp_detect = 0;
5089
Matt2f2f4252005-04-13 14:45:30 +02005090 codec->patch_ops = stac92xx_patch_ops;
5091
5092 return 0;
5093}
5094
Tobin Davis8e21c342007-01-08 11:04:17 +01005095static int patch_stac925x(struct hda_codec *codec)
5096{
5097 struct sigmatel_spec *spec;
5098 int err;
5099
5100 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5101 if (spec == NULL)
5102 return -ENOMEM;
5103
Takashi Iwaia252c812009-12-25 22:56:20 +01005104 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005105 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005106 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005107 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005108 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005109
5110 /* Check first for codec ID */
5111 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5112 STAC_925x_MODELS,
5113 stac925x_models,
5114 stac925x_codec_id_cfg_tbl);
5115
5116 /* Now checks for PCI ID, if codec ID is not found */
5117 if (spec->board_config < 0)
5118 spec->board_config = snd_hda_check_board_config(codec,
5119 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005120 stac925x_models,
5121 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005122 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005123 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005124 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5125 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005126 else
5127 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005128 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005129
5130 spec->multiout.max_channels = 2;
5131 spec->multiout.num_dacs = 1;
5132 spec->multiout.dac_nids = stac925x_dac_nids;
5133 spec->adc_nids = stac925x_adc_nids;
5134 spec->mux_nids = stac925x_mux_nids;
5135 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005136 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005137 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005138 switch (codec->vendor_id) {
5139 case 0x83847632: /* STAC9202 */
5140 case 0x83847633: /* STAC9202D */
5141 case 0x83847636: /* STAC9251 */
5142 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005143 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005144 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005145 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5146 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005147 break;
5148 default:
5149 spec->num_dmics = 0;
5150 break;
5151 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005152
5153 spec->init = stac925x_core_init;
5154 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005155 spec->num_caps = 1;
5156 spec->capvols = stac925x_capvols;
5157 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005158
5159 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005160 if (!err) {
5161 if (spec->board_config < 0) {
5162 printk(KERN_WARNING "hda_codec: No auto-config is "
5163 "available, default to model=ref\n");
5164 spec->board_config = STAC_925x_REF;
5165 goto again;
5166 }
5167 err = -EINVAL;
5168 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005169 if (err < 0) {
5170 stac92xx_free(codec);
5171 return err;
5172 }
5173
5174 codec->patch_ops = stac92xx_patch_ops;
5175
5176 return 0;
5177}
5178
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005179static int patch_stac92hd73xx(struct hda_codec *codec)
5180{
5181 struct sigmatel_spec *spec;
5182 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5183 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005184 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005185
5186 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5187 if (spec == NULL)
5188 return -ENOMEM;
5189
Takashi Iwaia252c812009-12-25 22:56:20 +01005190 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005191 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005192 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005193 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005194 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5195 spec->pin_nids = stac92hd73xx_pin_nids;
5196 spec->board_config = snd_hda_check_board_config(codec,
5197 STAC_92HD73XX_MODELS,
5198 stac92hd73xx_models,
5199 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005200 /* check codec subsystem id if not found */
5201 if (spec->board_config < 0)
5202 spec->board_config =
5203 snd_hda_check_board_codec_sid_config(codec,
5204 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5205 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005206again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005207 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005208 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5209 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005210 else
5211 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005212 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005213
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005214 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005215 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5216
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005217 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005218 printk(KERN_WARNING "hda_codec: Could not determine "
5219 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005220 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005221 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005222 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005223 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005224 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005225 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005226 break;
5227 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005228 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005229 break;
5230 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005231 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5232 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005233 }
5234 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005235
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005236 spec->aloopback_mask = 0x01;
5237 spec->aloopback_shift = 8;
5238
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005239 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005240 spec->mux_nids = stac92hd73xx_mux_nids;
5241 spec->adc_nids = stac92hd73xx_adc_nids;
5242 spec->dmic_nids = stac92hd73xx_dmic_nids;
5243 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005244 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005245
5246 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5247 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005248 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005249
Takashi Iwai6479c632009-07-28 18:20:25 +02005250 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5251 spec->capvols = stac92hd73xx_capvols;
5252 spec->capsws = stac92hd73xx_capsws;
5253
Matthew Ranostaya7662642008-02-21 07:51:14 +01005254 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005255 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005256 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005257 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005258 case STAC_DELL_M6_AMIC:
5259 case STAC_DELL_M6_DMIC:
5260 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005261 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005262 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005263
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005264 switch (spec->board_config) {
5265 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005266 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005267 spec->num_dmics = 0;
5268 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005269 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005270 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005271 spec->num_dmics = 1;
5272 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005273 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005274 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5275 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005276 spec->num_dmics = 1;
5277 break;
5278 }
5279 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005280 case STAC_ALIENWARE_M17X:
5281 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5282 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5283 spec->eapd_switch = 0;
5284 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005285 default:
5286 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005287 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005288 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005289 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005290 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005291 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005292 /* GPIO0 High = Enable EAPD */
5293 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5294 spec->gpio_data = 0x01;
5295 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005296
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005297 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5298 spec->pwr_nids = stac92hd73xx_pwr_nids;
5299
Matthew Ranostayd9737752008-09-07 12:03:41 +02005300 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005301
5302 if (!err) {
5303 if (spec->board_config < 0) {
5304 printk(KERN_WARNING "hda_codec: No auto-config is "
5305 "available, default to model=ref\n");
5306 spec->board_config = STAC_92HD73XX_REF;
5307 goto again;
5308 }
5309 err = -EINVAL;
5310 }
5311
5312 if (err < 0) {
5313 stac92xx_free(codec);
5314 return err;
5315 }
5316
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005317 if (spec->board_config == STAC_92HD73XX_NO_JD)
5318 spec->hp_detect = 0;
5319
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005320 codec->patch_ops = stac92xx_patch_ops;
5321
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005322 codec->proc_widget_hook = stac92hd7x_proc_hook;
5323
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005324 return 0;
5325}
5326
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005327static int patch_stac92hd83xxx(struct hda_codec *codec)
5328{
5329 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005330 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005331 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005332 int num_dacs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005333
5334 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5335 if (spec == NULL)
5336 return -ENOMEM;
5337
Charles1cc9e8f2010-10-18 16:22:00 +08005338 /* reset pin power-down; Windows may leave these bits after reboot */
5339 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7EC, 0);
5340 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7ED, 0);
Takashi Iwaia252c812009-12-25 22:56:20 +01005341 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005342 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005343 spec->linear_tone_beep = 1;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005344 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005345 spec->digbeep_nid = 0x21;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005346 spec->dmic_nids = stac92hd83xxx_dmic_nids;
5347 spec->dmux_nids = stac92hd83xxx_mux_nids;
Takashi Iwai667067d2009-08-13 18:14:42 +02005348 spec->mux_nids = stac92hd83xxx_mux_nids;
5349 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005350 spec->adc_nids = stac92hd83xxx_adc_nids;
Takashi Iwai7570ef12009-08-15 11:57:53 +02005351 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005352 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5353 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5354 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005355 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005356
5357 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005358 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005359 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005360 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5361 spec->capvols = stac92hd83xxx_capvols;
5362 spec->capsws = stac92hd83xxx_capsws;
5363
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005364 spec->board_config = snd_hda_check_board_config(codec,
5365 STAC_92HD83XXX_MODELS,
5366 stac92hd83xxx_models,
5367 stac92hd83xxx_cfg_tbl);
5368again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005369 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005370 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5371 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005372 else
5373 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005374 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005375
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005376 switch (codec->vendor_id) {
Charles Chin36706002010-01-29 12:05:51 +01005377 case 0x111d7666:
5378 case 0x111d7667:
5379 case 0x111d7668:
5380 case 0x111d7669:
Charles Chin8a345a02010-08-10 11:43:25 +02005381 case 0x111d76d1:
5382 case 0x111d76d9:
Charles Chin36706002010-01-29 12:05:51 +01005383 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5384 spec->pin_nids = stac92hd88xxx_pin_nids;
5385 spec->mono_nid = 0;
5386 spec->digbeep_nid = 0;
5387 spec->num_pwrs = 0;
5388 break;
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005389 case 0x111d7604:
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01005390 case 0x111d76d4:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005391 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005392 case 0x111d76d5:
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005393 case 0x111d76e7:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005394 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5395 break;
5396 spec->num_pwrs = 0;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005397 spec->num_dmics = stac92xx_connected_ports(codec,
5398 stac92hd83xxx_dmic_nids,
5399 STAC92HD83XXX_NUM_DMICS);
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005400 break;
5401 }
5402
Takashi Iwaib4e81872009-11-18 17:20:24 +01005403 codec->patch_ops = stac92xx_patch_ops;
5404
Takashi Iwaidce17d42010-02-09 09:25:26 +01005405 if (find_mute_led_gpio(codec, 0))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005406 snd_printd("mute LED gpio %d polarity %d\n",
5407 spec->gpio_led,
5408 spec->gpio_led_polarity);
5409
Takashi Iwaib4e81872009-11-18 17:20:24 +01005410#ifdef CONFIG_SND_HDA_POWER_SAVE
5411 if (spec->gpio_led) {
5412 spec->gpio_mask |= spec->gpio_led;
5413 spec->gpio_dir |= spec->gpio_led;
5414 spec->gpio_data |= spec->gpio_led;
5415 /* register check_power_status callback. */
5416 codec->patch_ops.check_power_status =
Takashi Iwaic21bd022010-02-08 15:16:08 +01005417 stac92xx_hp_check_power_status;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005418 }
5419#endif
5420
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005421 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5422 if (!err) {
5423 if (spec->board_config < 0) {
5424 printk(KERN_WARNING "hda_codec: No auto-config is "
5425 "available, default to model=ref\n");
5426 spec->board_config = STAC_92HD83XXX_REF;
5427 goto again;
5428 }
5429 err = -EINVAL;
5430 }
5431
5432 if (err < 0) {
5433 stac92xx_free(codec);
5434 return err;
5435 }
5436
Charles Chin04b5efe2010-02-04 10:28:02 +01005437 /* docking output support */
5438 num_dacs = snd_hda_get_connections(codec, 0xF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005439 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Charles Chin04b5efe2010-02-04 10:28:02 +01005440 /* skip non-DAC connections */
5441 while (num_dacs >= 0 &&
5442 (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5443 != AC_WID_AUD_OUT))
5444 num_dacs--;
5445 /* set port E and F to select the last DAC */
5446 if (num_dacs >= 0) {
5447 snd_hda_codec_write_cache(codec, 0xE, 0,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005448 AC_VERB_SET_CONNECT_SEL, num_dacs);
Charles Chin04b5efe2010-02-04 10:28:02 +01005449 snd_hda_codec_write_cache(codec, 0xF, 0,
5450 AC_VERB_SET_CONNECT_SEL, num_dacs);
5451 }
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005452
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005453 codec->proc_widget_hook = stac92hd_proc_hook;
5454
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005455 return 0;
5456}
5457
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005458static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5459 hda_nid_t dig0pin)
5460{
5461 struct sigmatel_spec *spec = codec->spec;
5462 int idx;
5463
5464 for (idx = 0; idx < spec->num_pins; idx++)
5465 if (spec->pin_nids[idx] == dig0pin)
5466 break;
5467 if ((idx + 2) >= spec->num_pins)
5468 return 0;
5469
5470 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005471 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005472 return 2;
5473
5474 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005475 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005476 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005477 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005478 return 1;
5479 else
5480 return 0;
5481}
5482
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005483/* HP dv7 bass switch - GPIO5 */
5484#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5485static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5486 struct snd_ctl_elem_value *ucontrol)
5487{
5488 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5489 struct sigmatel_spec *spec = codec->spec;
5490 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5491 return 0;
5492}
5493
5494static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5495 struct snd_ctl_elem_value *ucontrol)
5496{
5497 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5498 struct sigmatel_spec *spec = codec->spec;
5499 unsigned int gpio_data;
5500
5501 gpio_data = (spec->gpio_data & ~0x20) |
5502 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5503 if (gpio_data == spec->gpio_data)
5504 return 0;
5505 spec->gpio_data = gpio_data;
5506 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5507 return 1;
5508}
5509
5510static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5511 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5512 .info = stac_hp_bass_gpio_info,
5513 .get = stac_hp_bass_gpio_get,
5514 .put = stac_hp_bass_gpio_put,
5515};
5516
5517static int stac_add_hp_bass_switch(struct hda_codec *codec)
5518{
5519 struct sigmatel_spec *spec = codec->spec;
5520
5521 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5522 "Bass Speaker Playback Switch", 0))
5523 return -ENOMEM;
5524
5525 spec->gpio_mask |= 0x20;
5526 spec->gpio_dir |= 0x20;
5527 spec->gpio_data |= 0x20;
5528 return 0;
5529}
5530
Matthew Ranostaye035b842007-11-06 11:53:55 +01005531static int patch_stac92hd71bxx(struct hda_codec *codec)
5532{
5533 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005534 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005535 unsigned int pin_cfg;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005536 int err = 0;
5537
5538 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5539 if (spec == NULL)
5540 return -ENOMEM;
5541
Takashi Iwaia252c812009-12-25 22:56:20 +01005542 codec->no_trigger_sense = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005543 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005544 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005545 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005546 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5547 switch (codec->vendor_id) {
5548 case 0x111d76b6:
5549 case 0x111d76b7:
5550 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5551 break;
5552 case 0x111d7603:
5553 case 0x111d7608:
5554 /* On 92HD75Bx 0x27 isn't a pin nid */
5555 spec->num_pins--;
5556 /* fallthrough */
5557 default:
5558 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5559 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005560 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005561 spec->board_config = snd_hda_check_board_config(codec,
5562 STAC_92HD71BXX_MODELS,
5563 stac92hd71bxx_models,
5564 stac92hd71bxx_cfg_tbl);
5565again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005566 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005567 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5568 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005569 else
5570 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005571 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005572
Takashi Iwaifc64b262009-09-14 15:33:01 +02005573 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005574 /* GPIO0 = EAPD */
5575 spec->gpio_mask = 0x01;
5576 spec->gpio_dir = 0x01;
5577 spec->gpio_data = 0x01;
5578 }
5579
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005580 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5581 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5582
Takashi Iwai6479c632009-07-28 18:20:25 +02005583 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5584 spec->capvols = stac92hd71bxx_capvols;
5585 spec->capsws = stac92hd71bxx_capsws;
5586
Matthew Ranostay541eee82007-12-14 12:08:04 +01005587 switch (codec->vendor_id) {
5588 case 0x111d76b6: /* 4 Port without Analog Mixer */
5589 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005590 unmute_init++;
5591 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005592 case 0x111d76b4: /* 6 Port without Analog Mixer */
5593 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005594 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005595 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005596 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005597 stac92hd71bxx_dmic_nids,
5598 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005599 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005600 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005601 switch (spec->board_config) {
5602 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005603 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005604 err = stac_add_event(spec, codec->afg,
5605 STAC_VREF_EVENT, 0x02);
5606 if (err < 0)
5607 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005608 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005609 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5610 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005611 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005612 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005613 spec->gpio_mask |= 0x02;
5614 break;
5615 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005616 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005617 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005618 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005619
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005620 /* no output amps */
5621 spec->num_pwrs = 0;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005622 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005623 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005624 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005625 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5626 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005627 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005628 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005629 stac92hd71bxx_dmic_nids,
5630 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005631 break;
5632 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005633 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005634 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005635
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005636 /* no output amps */
5637 spec->num_pwrs = 0;
5638 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005639 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005640 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005641 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005642 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005643 stac92hd71bxx_dmic_nids,
5644 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005645 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005646 }
5647
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005648 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5649 snd_hda_sequence_write_cache(codec, unmute_init);
5650
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005651 /* Some HP machines seem to have unstable codec communications
5652 * especially with ATI fglrx driver. For recovering from the
5653 * CORB/RIRB stall, allow the BUS reset and keep always sync
5654 */
5655 if (spec->board_config == STAC_HP_DV5) {
5656 codec->bus->sync_write = 1;
5657 codec->bus->allow_bus_reset = 1;
5658 }
5659
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005660 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005661 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005662 spec->aloopback_shift = 0;
5663
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005664 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005665 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005666 spec->mux_nids = stac92hd71bxx_mux_nids;
5667 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005668 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005669 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005670
5671 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5672 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005673 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005674 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005675
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305676 snd_printdd("Found board config: %d\n", spec->board_config);
5677
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005678 switch (spec->board_config) {
5679 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005680 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005681 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005682 stac92xx_auto_set_pinctl(codec, 0x0e,
5683 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005684 /* fallthru */
5685 case STAC_DELL_M4_2:
5686 spec->num_dmics = 0;
5687 spec->num_smuxes = 0;
5688 spec->num_dmuxes = 0;
5689 break;
5690 case STAC_DELL_M4_1:
5691 case STAC_DELL_M4_3:
5692 spec->num_dmics = 1;
5693 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005694 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005695 break;
James Gardiner514bf542009-05-03 04:00:44 -04005696 case STAC_HP_DV4_1222NR:
5697 spec->num_dmics = 1;
5698 /* I don't know if it needs 1 or 2 smuxes - will wait for
5699 * bug reports to fix if needed
5700 */
5701 spec->num_smuxes = 1;
5702 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005703 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005704 case STAC_HP_DV4:
5705 spec->gpio_led = 0x01;
5706 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005707 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005708 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005709 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005710 /* HP dv6 gives the headphone pin as a line-out. Thus we
5711 * need to set hp_detect flag here to force to enable HP
5712 * detection.
5713 */
5714 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005715 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005716 case STAC_HP_HDX:
5717 spec->num_dmics = 1;
5718 spec->num_dmuxes = 1;
5719 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005720 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005721 break;
5722 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005723
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005724 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005725 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5726 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5727 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5728 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5729 /* It was changed in the BIOS to just satisfy MS DTM.
5730 * Lets turn it back into slaved HP
5731 */
5732 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5733 | (AC_JACK_HP_OUT <<
5734 AC_DEFCFG_DEVICE_SHIFT);
5735 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5736 | AC_DEFCFG_SEQUENCE)))
5737 | 0x1f;
5738 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5739 }
5740 }
5741
Takashi Iwaidce17d42010-02-09 09:25:26 +01005742 if (find_mute_led_gpio(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005743 snd_printd("mute LED gpio %d polarity %d\n",
5744 spec->gpio_led,
5745 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005746
Takashi Iwai86d190e2009-05-26 15:18:58 +02005747#ifdef CONFIG_SND_HDA_POWER_SAVE
5748 if (spec->gpio_led) {
5749 spec->gpio_mask |= spec->gpio_led;
5750 spec->gpio_dir |= spec->gpio_led;
5751 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005752 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005753 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005754 stac92xx_hp_check_power_status;
5755 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005756#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005757
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005758 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005759
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005760 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005761 if (!err) {
5762 if (spec->board_config < 0) {
5763 printk(KERN_WARNING "hda_codec: No auto-config is "
5764 "available, default to model=ref\n");
5765 spec->board_config = STAC_92HD71BXX_REF;
5766 goto again;
5767 }
5768 err = -EINVAL;
5769 }
5770
5771 if (err < 0) {
5772 stac92xx_free(codec);
5773 return err;
5774 }
5775
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005776 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005777 if (spec->board_config == STAC_HP_DV4 ||
5778 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005779 unsigned int cap;
5780 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5781 cap &= AC_GPIO_IO_COUNT;
5782 if (cap >= 6)
5783 stac_add_hp_bass_switch(codec);
5784 }
5785
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005786 codec->proc_widget_hook = stac92hd7x_proc_hook;
5787
Matthew Ranostaye035b842007-11-06 11:53:55 +01005788 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005789}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005790
Matt2f2f4252005-04-13 14:45:30 +02005791static int patch_stac922x(struct hda_codec *codec)
5792{
5793 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005794 int err;
Matt2f2f4252005-04-13 14:45:30 +02005795
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005796 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005797 if (spec == NULL)
5798 return -ENOMEM;
5799
Takashi Iwaia252c812009-12-25 22:56:20 +01005800 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005801 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005802 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005803 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005804 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005805 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5806 stac922x_models,
5807 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005808 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005809 spec->gpio_mask = spec->gpio_dir = 0x03;
5810 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005811 /* Intel Macs have all same PCI SSID, so we need to check
5812 * codec SSID to distinguish the exact models
5813 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005814 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005815 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005816
5817 case 0x106b0800:
5818 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005819 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005820 case 0x106b0600:
5821 case 0x106b0700:
5822 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005823 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005824 case 0x106b0e00:
5825 case 0x106b0f00:
5826 case 0x106b1600:
5827 case 0x106b1700:
5828 case 0x106b0200:
5829 case 0x106b1e00:
5830 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005831 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005832 case 0x106b1a00:
5833 case 0x00000100:
5834 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005835 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005836 case 0x106b0a00:
5837 case 0x106b2200:
5838 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005839 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005840 default:
5841 spec->board_config = STAC_INTEL_MAC_V3;
5842 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005843 }
5844 }
5845
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005846 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005847 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005848 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5849 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005850 else
5851 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005852 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005853
Matt2f2f4252005-04-13 14:45:30 +02005854 spec->adc_nids = stac922x_adc_nids;
5855 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005856 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005857 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005858 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005859 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005860
5861 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005862
5863 spec->num_caps = STAC922X_NUM_CAPS;
5864 spec->capvols = stac922x_capvols;
5865 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005866
5867 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005868
Matt Porter3cc08dc2006-01-23 15:27:49 +01005869 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005870 if (!err) {
5871 if (spec->board_config < 0) {
5872 printk(KERN_WARNING "hda_codec: No auto-config is "
5873 "available, default to model=ref\n");
5874 spec->board_config = STAC_D945_REF;
5875 goto again;
5876 }
5877 err = -EINVAL;
5878 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005879 if (err < 0) {
5880 stac92xx_free(codec);
5881 return err;
5882 }
5883
5884 codec->patch_ops = stac92xx_patch_ops;
5885
Takashi Iwai807a46362007-05-29 19:01:37 +02005886 /* Fix Mux capture level; max to 2 */
5887 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5888 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5889 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5890 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5891 (0 << AC_AMPCAP_MUTE_SHIFT));
5892
Matt Porter3cc08dc2006-01-23 15:27:49 +01005893 return 0;
5894}
5895
5896static int patch_stac927x(struct hda_codec *codec)
5897{
5898 struct sigmatel_spec *spec;
5899 int err;
5900
5901 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5902 if (spec == NULL)
5903 return -ENOMEM;
5904
Takashi Iwaia252c812009-12-25 22:56:20 +01005905 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005906 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005907 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005908 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005909 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005910 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005911 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5912 stac927x_models,
5913 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005914 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005915 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005916 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5917 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005918 else
5919 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005920 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005921
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005922 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005923 spec->adc_nids = stac927x_adc_nids;
5924 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5925 spec->mux_nids = stac927x_mux_nids;
5926 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005927 spec->smux_nids = stac927x_smux_nids;
5928 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005929 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005930 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005931 spec->multiout.dac_nids = spec->dac_nids;
5932
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005933 if (spec->board_config != STAC_D965_REF) {
5934 /* GPIO0 High = Enable EAPD */
5935 spec->eapd_mask = spec->gpio_mask = 0x01;
5936 spec->gpio_dir = spec->gpio_data = 0x01;
5937 }
5938
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005939 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005940 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005941 case STAC_D965_5ST:
5942 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005943 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02005944 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005945 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005946 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005947 switch (codec->subsystem_id) {
5948 case 0x10280209:
5949 case 0x1028022e:
5950 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005951 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005952 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005953 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005954 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005955 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005956 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005957 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005958 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005959 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005960 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005961 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005962 if (codec->subsystem_id != 0x1028022f) {
5963 /* GPIO2 High = Enable EAPD */
5964 spec->eapd_mask = spec->gpio_mask = 0x04;
5965 spec->gpio_dir = spec->gpio_data = 0x04;
5966 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005967 spec->dmic_nids = stac927x_dmic_nids;
5968 spec->num_dmics = STAC927X_NUM_DMICS;
5969
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02005970 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005971 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005972 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005973 break;
Takashi Iwai54930532009-10-11 17:38:29 +02005974 case STAC_927X_VOLKNOB:
5975 spec->num_dmics = 0;
5976 spec->init = stac927x_volknob_core_init;
5977 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005978 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005979 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005980 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005981 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005982 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005983
Takashi Iwai6479c632009-07-28 18:20:25 +02005984 spec->num_caps = STAC927X_NUM_CAPS;
5985 spec->capvols = stac927x_capvols;
5986 spec->capsws = stac927x_capsws;
5987
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005988 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005989 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005990 spec->aloopback_mask = 0x40;
5991 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005992 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005993
Matt Porter3cc08dc2006-01-23 15:27:49 +01005994 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005995 if (!err) {
5996 if (spec->board_config < 0) {
5997 printk(KERN_WARNING "hda_codec: No auto-config is "
5998 "available, default to model=ref\n");
5999 spec->board_config = STAC_D965_REF;
6000 goto again;
6001 }
6002 err = -EINVAL;
6003 }
Mattc7d4b2f2005-06-27 14:59:41 +02006004 if (err < 0) {
6005 stac92xx_free(codec);
6006 return err;
6007 }
Matt2f2f4252005-04-13 14:45:30 +02006008
6009 codec->patch_ops = stac92xx_patch_ops;
6010
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006011 codec->proc_widget_hook = stac927x_proc_hook;
6012
Takashi Iwai52987652008-01-16 16:09:47 +01006013 /*
6014 * !!FIXME!!
6015 * The STAC927x seem to require fairly long delays for certain
6016 * command sequences. With too short delays (even if the answer
6017 * is set to RIRB properly), it results in the silence output
6018 * on some hardwares like Dell.
6019 *
6020 * The below flag enables the longer delay (see get_response
6021 * in hda_intel.c).
6022 */
6023 codec->bus->needs_damn_long_delay = 1;
6024
Takashi Iwaie28d8322008-12-17 13:48:29 +01006025 /* no jack detecion for ref-no-jd model */
6026 if (spec->board_config == STAC_D965_REF_NO_JD)
6027 spec->hp_detect = 0;
6028
Matt2f2f4252005-04-13 14:45:30 +02006029 return 0;
6030}
6031
Matt Porterf3302a52006-07-31 12:49:34 +02006032static int patch_stac9205(struct hda_codec *codec)
6033{
6034 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006035 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006036
6037 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6038 if (spec == NULL)
6039 return -ENOMEM;
6040
Takashi Iwaia252c812009-12-25 22:56:20 +01006041 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006042 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006043 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006044 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006045 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006046 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6047 stac9205_models,
6048 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006049 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006050 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006051 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6052 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006053 else
6054 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01006055 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006056
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006057 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006058 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006059 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006060 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006061 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006062 spec->smux_nids = stac9205_smux_nids;
6063 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006064 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006065 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006066 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006067 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006068 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006069
6070 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006071 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006072
Takashi Iwai6479c632009-07-28 18:20:25 +02006073 spec->num_caps = STAC9205_NUM_CAPS;
6074 spec->capvols = stac9205_capvols;
6075 spec->capsws = stac9205_capsws;
6076
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006077 spec->aloopback_mask = 0x40;
6078 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006079 /* Turn on/off EAPD per HP plugging */
6080 if (spec->board_config != STAC_9205_EAPD)
6081 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006082 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006083
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006084 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006085 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006086 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006087 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6088 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006089
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006090 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006091 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6092 if (err < 0)
6093 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006094 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006095 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6096 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006097 AC_VERB_SET_UNSOLICITED_ENABLE,
6098 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006099
6100 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006101 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006102 spec->gpio_mask = 0x1b;
6103 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006104 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006105 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006106 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006107 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006108 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006109 case STAC_9205_REF:
6110 /* SPDIF-In enabled */
6111 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006112 default:
6113 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006114 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01006115 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006116 break;
6117 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006118
Matt Porterf3302a52006-07-31 12:49:34 +02006119 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006120 if (!err) {
6121 if (spec->board_config < 0) {
6122 printk(KERN_WARNING "hda_codec: No auto-config is "
6123 "available, default to model=ref\n");
6124 spec->board_config = STAC_9205_REF;
6125 goto again;
6126 }
6127 err = -EINVAL;
6128 }
Matt Porterf3302a52006-07-31 12:49:34 +02006129 if (err < 0) {
6130 stac92xx_free(codec);
6131 return err;
6132 }
6133
6134 codec->patch_ops = stac92xx_patch_ops;
6135
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006136 codec->proc_widget_hook = stac9205_proc_hook;
6137
Matt Porterf3302a52006-07-31 12:49:34 +02006138 return 0;
6139}
6140
Matt2f2f4252005-04-13 14:45:30 +02006141/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006142 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006143 */
6144
Takashi Iwai1e137f92009-01-21 07:41:22 +01006145static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006146 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006147 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6148 {}
6149};
6150
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006151static hda_nid_t stac9872_pin_nids[] = {
6152 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6153 0x11, 0x13, 0x14,
6154};
6155
6156static hda_nid_t stac9872_adc_nids[] = {
6157 0x8 /*,0x6*/
6158};
6159
6160static hda_nid_t stac9872_mux_nids[] = {
6161 0x15
6162};
6163
Takashi Iwai6479c632009-07-28 18:20:25 +02006164static unsigned long stac9872_capvols[] = {
6165 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6166};
6167#define stac9872_capsws stac9872_capvols
6168
Takashi Iwai307282c2009-03-12 18:17:58 +01006169static unsigned int stac9872_vaio_pin_configs[9] = {
6170 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6171 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6172 0x90a7013e
6173};
6174
6175static const char *stac9872_models[STAC_9872_MODELS] = {
6176 [STAC_9872_AUTO] = "auto",
6177 [STAC_9872_VAIO] = "vaio",
6178};
6179
6180static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6181 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6182};
6183
6184static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006185 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6186 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006187 {} /* terminator */
6188};
6189
Guillaume Munch6d859062006-08-22 17:15:47 +02006190static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006191{
6192 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006193 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006194
Takashi Iwaidb064e52006-03-16 16:04:58 +01006195 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6196 if (spec == NULL)
6197 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006198 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006199 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006200 spec->linear_tone_beep = 1;
Takashi Iwaib04add92009-07-20 08:01:36 +02006201 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6202 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006203
6204 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6205 stac9872_models,
6206 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006207 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006208 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6209 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006210 else
6211 stac92xx_set_config_regs(codec,
6212 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006213
Takashi Iwai1e137f92009-01-21 07:41:22 +01006214 spec->multiout.dac_nids = spec->dac_nids;
6215 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6216 spec->adc_nids = stac9872_adc_nids;
6217 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6218 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006219 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006220 spec->num_caps = 1;
6221 spec->capvols = stac9872_capvols;
6222 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006223
Takashi Iwai1e137f92009-01-21 07:41:22 +01006224 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6225 if (err < 0) {
6226 stac92xx_free(codec);
6227 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006228 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006229 spec->input_mux = &spec->private_imux;
6230 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006231 return 0;
6232}
6233
6234
6235/*
Matt2f2f4252005-04-13 14:45:30 +02006236 * patch entries
6237 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006238static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006239 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6240 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6241 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6242 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6243 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6244 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6245 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006246 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6247 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6248 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6249 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6250 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6251 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006252 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6253 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6254 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6255 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6256 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6257 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6258 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6259 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6260 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6261 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006262 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6263 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6264 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6265 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6266 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6267 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006268 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6269 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006270 /* The following does not take into account .id=0x83847661 when subsys =
6271 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6272 * currently not fully supported.
6273 */
6274 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6275 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6276 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006277 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006278 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6279 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6280 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6281 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6282 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6283 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6284 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6285 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006286 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006287 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006288 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006289 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006290 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006291 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6292 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006293 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6294 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6295 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6296 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006297 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006298 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6299 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006300 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006301 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6302 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6303 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6304 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6305 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6306 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6307 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6308 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006309 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6310 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6311 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6312 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6313 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6314 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6315 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6316 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6317 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6318 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6319 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6320 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6321 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6322 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6323 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006324 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
6325 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006326 {} /* terminator */
6327};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006328
6329MODULE_ALIAS("snd-hda-codec-id:8384*");
6330MODULE_ALIAS("snd-hda-codec-id:111d*");
6331
6332MODULE_LICENSE("GPL");
6333MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6334
6335static struct hda_codec_preset_list sigmatel_list = {
6336 .preset = snd_hda_preset_sigmatel,
6337 .owner = THIS_MODULE,
6338};
6339
6340static int __init patch_sigmatel_init(void)
6341{
6342 return snd_hda_add_codec_preset(&sigmatel_list);
6343}
6344
6345static void __exit patch_sigmatel_exit(void)
6346{
6347 snd_hda_delete_codec_preset(&sigmatel_list);
6348}
6349
6350module_init(patch_sigmatel_init)
6351module_exit(patch_sigmatel_exit)