blob: 1a563a2fbbec9467ee9069e97b8692d41dfe5196 [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>
Matt2f2f4252005-04-13 14:45:30 +020035#include "hda_codec.h"
36#include "hda_local.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020037#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020038
Takashi Iwaic6e4c662008-11-25 11:58:19 +010039enum {
40 STAC_VREF_EVENT = 1,
41 STAC_INSERT_EVENT,
42 STAC_PWR_EVENT,
43 STAC_HP_EVENT,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020044 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020045 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010046};
Matt4e550962005-07-04 17:51:39 +020047
Takashi Iwaif5fcc132006-11-24 17:07:44 +010048enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010049 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010050 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010051 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020052 STAC_9200_DELL_D21,
53 STAC_9200_DELL_D22,
54 STAC_9200_DELL_D23,
55 STAC_9200_DELL_M21,
56 STAC_9200_DELL_M22,
57 STAC_9200_DELL_M23,
58 STAC_9200_DELL_M24,
59 STAC_9200_DELL_M25,
60 STAC_9200_DELL_M26,
61 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020062 STAC_9200_M4,
63 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010064 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010065 STAC_9200_MODELS
66};
67
68enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010069 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010070 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020071 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020072 STAC_9205_DELL_M43,
73 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010074 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010075 STAC_9205_MODELS
76};
77
78enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010079 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010080 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010081 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080082 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010083 STAC_DELL_M6_AMIC,
84 STAC_DELL_M6_DMIC,
85 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050086 STAC_DELL_EQ,
Takashi Iwai842ae632009-09-02 07:43:08 +020087 STAC_ALIENWARE_M17X,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010088 STAC_92HD73XX_MODELS
89};
90
91enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010092 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020093 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050094 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050095 STAC_DELL_S14,
Takashi Iwaib4e81872009-11-18 17:20:24 +010096 STAC_92HD83XXX_HP,
Steven Eastland48315592010-08-06 15:07:35 -060097 STAC_HP_DV7_4000,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020098 STAC_92HD83XXX_MODELS
99};
100
101enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100102 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100103 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100104 STAC_DELL_M4_1,
105 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500106 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400107 STAC_HP_M4,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +0200108 STAC_HP_DV4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100109 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100110 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400111 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100112 STAC_92HD71BXX_MODELS
113};
114
115enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100116 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100117 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200118 STAC_M1,
119 STAC_M1_2,
120 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100121 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200122 STAC_M3,
123 STAC_M5,
124 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100125 STAC_925x_MODELS
126};
127
128enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100129 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100130 STAC_D945_REF,
131 STAC_D945GTP3,
132 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200133 STAC_INTEL_MAC_V1,
134 STAC_INTEL_MAC_V2,
135 STAC_INTEL_MAC_V3,
136 STAC_INTEL_MAC_V4,
137 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800138 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
139 * is given, one of the above models will be
140 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200141 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100142 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100143 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100144 STAC_MACBOOK_PRO_V1,
145 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200146 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200147 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300148 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200149 STAC_922X_DELL_D81,
150 STAC_922X_DELL_D82,
151 STAC_922X_DELL_M81,
152 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100153 STAC_922X_MODELS
154};
155
156enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100157 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100158 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100159 STAC_D965_REF,
160 STAC_D965_3ST,
161 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200162 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200163 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100164 STAC_DELL_BIOS,
Takashi Iwai54930532009-10-11 17:38:29 +0200165 STAC_927X_VOLKNOB,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100166 STAC_927X_MODELS
167};
Matt Porter403d1942005-11-29 15:00:51 +0100168
Takashi Iwai307282c2009-03-12 18:17:58 +0100169enum {
170 STAC_9872_AUTO,
171 STAC_9872_VAIO,
172 STAC_9872_MODELS
173};
174
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400175struct sigmatel_event {
176 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100177 unsigned char type;
178 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400179 int data;
180};
181
182struct sigmatel_jack {
183 hda_nid_t nid;
184 int type;
185 struct snd_jack *jack;
186};
187
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200188struct sigmatel_mic_route {
189 hda_nid_t pin;
Takashi Iwai02d33322009-10-01 16:38:11 +0200190 signed char mux_idx;
191 signed char dmux_idx;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200192};
193
Matt2f2f4252005-04-13 14:45:30 +0200194struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100195 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200196 unsigned int num_mixers;
197
Matt Porter403d1942005-11-29 15:00:51 +0100198 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500199 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200200 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100201 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100202 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400203 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100204 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200205 unsigned int auto_mic:1;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +0100206 unsigned int linear_tone_beep:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200207
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100208 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200209 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100210 unsigned int gpio_mask;
211 unsigned int gpio_dir;
212 unsigned int gpio_data;
213 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200214 unsigned int gpio_led;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +0100215 unsigned int gpio_led_polarity;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100216
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200217 /* stream */
218 unsigned int stream_delay;
219
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100220 /* analog loopback */
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100221 struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100222 unsigned char aloopback_mask;
223 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200224
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100225 /* power management */
226 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200227 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100228 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100229 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100230
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400231 /* jack detection */
232 struct snd_array jacks;
233
234 /* events */
235 struct snd_array events;
236
Matt2f2f4252005-04-13 14:45:30 +0200237 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100238 struct hda_input_mux *mono_mux;
239 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200240 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100241 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100242 hda_nid_t hp_dacs[5];
243 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200244
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100245 int volume_offset;
246
Matt2f2f4252005-04-13 14:45:30 +0200247 /* capture */
248 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200249 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200250 hda_nid_t *mux_nids;
251 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200252 hda_nid_t *dmic_nids;
253 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100254 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100255 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200256 hda_nid_t *smux_nids;
257 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200258 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200259
260 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
261 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
262 unsigned int num_caps; /* number of capture volume/switch elements */
263
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200264 struct sigmatel_mic_route ext_mic;
265 struct sigmatel_mic_route int_mic;
Charles Chin99077902010-09-17 10:22:32 +0200266 struct sigmatel_mic_route dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200267
Matthew Ranostay65973632008-09-16 10:39:37 -0400268 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200269
Mattdabbed62005-06-14 10:19:34 +0200270 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100271 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200272 hda_nid_t anabeep_nid;
273 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200274
Matt2f2f4252005-04-13 14:45:30 +0200275 /* pin widgets */
276 hda_nid_t *pin_nids;
277 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200278
279 /* codec specific stuff */
280 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100281 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200282
283 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200284 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100285 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200286 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100287 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200288 struct hda_input_mux *sinput_mux;
289 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400290 unsigned int cur_amux;
291 hda_nid_t *amp_nids;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200292 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200293
Matt Porter403d1942005-11-29 15:00:51 +0100294 /* i/o switches */
295 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200296 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100297 hda_nid_t line_switch; /* shared line-in for input and output */
298 hda_nid_t mic_switch; /* shared mic-in for input and output */
299 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200300 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200301
Mattc7d4b2f2005-06-27 14:59:41 +0200302 struct hda_pcm pcm_rec[2]; /* PCM information */
303
304 /* dynamic controls and input_mux */
305 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200306 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200307 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200308 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200309 struct hda_input_mux private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100310 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200311};
312
313static hda_nid_t stac9200_adc_nids[1] = {
314 0x03,
315};
316
317static hda_nid_t stac9200_mux_nids[1] = {
318 0x0c,
319};
320
321static hda_nid_t stac9200_dac_nids[1] = {
322 0x02,
323};
324
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100325static hda_nid_t stac92hd73xx_pwr_nids[8] = {
326 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
327 0x0f, 0x10, 0x11
328};
329
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400330static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
331 0x26, 0,
332};
333
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100334static hda_nid_t stac92hd73xx_adc_nids[2] = {
335 0x1a, 0x1b
336};
337
338#define STAC92HD73XX_NUM_DMICS 2
339static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
340 0x13, 0x14, 0
341};
342
343#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100344
Takashi Iwaie2aec172009-09-02 01:00:05 +0200345static hda_nid_t stac92hd73xx_mux_nids[2] = {
346 0x20, 0x21,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100347};
348
349static hda_nid_t stac92hd73xx_dmux_nids[2] = {
350 0x20, 0x21,
351};
352
Matthew Ranostayd9737752008-09-07 12:03:41 +0200353static hda_nid_t stac92hd73xx_smux_nids[2] = {
354 0x22, 0x23,
355};
356
Takashi Iwai6479c632009-07-28 18:20:25 +0200357#define STAC92HD73XX_NUM_CAPS 2
358static unsigned long stac92hd73xx_capvols[] = {
359 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
360 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
361};
362#define stac92hd73xx_capsws stac92hd73xx_capvols
363
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200364#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200365
Takashi Iwai667067d2009-08-13 18:14:42 +0200366static hda_nid_t stac92hd83xxx_mux_nids[2] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200367 0x17, 0x18,
368};
369
370static hda_nid_t stac92hd83xxx_adc_nids[2] = {
371 0x15, 0x16,
372};
373
374static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
375 0xa, 0xb, 0xd, 0xe,
376};
377
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400378static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
379 0x1e, 0,
380};
381
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200382static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500383 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200384};
385
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +0200386#define STAC92HD83XXX_NUM_DMICS 2
387static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
388 0x11, 0x20, 0
389};
390
Takashi Iwai6479c632009-07-28 18:20:25 +0200391#define STAC92HD83XXX_NUM_CAPS 2
392static unsigned long stac92hd83xxx_capvols[] = {
393 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
394 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
395};
396#define stac92hd83xxx_capsws stac92hd83xxx_capvols
397
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100398static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
399 0x0a, 0x0d, 0x0f
400};
401
Matthew Ranostaye035b842007-11-06 11:53:55 +0100402static hda_nid_t stac92hd71bxx_adc_nids[2] = {
403 0x12, 0x13,
404};
405
406static hda_nid_t stac92hd71bxx_mux_nids[2] = {
407 0x1a, 0x1b
408};
409
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400410static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
411 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100412};
413
Matthew Ranostayd9737752008-09-07 12:03:41 +0200414static hda_nid_t stac92hd71bxx_smux_nids[2] = {
415 0x24, 0x25,
416};
417
Matthew Ranostaye035b842007-11-06 11:53:55 +0100418#define STAC92HD71BXX_NUM_DMICS 2
419static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
420 0x18, 0x19, 0
421};
422
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400423static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
424 0x22, 0
425};
426
Takashi Iwai6479c632009-07-28 18:20:25 +0200427#define STAC92HD71BXX_NUM_CAPS 2
428static unsigned long stac92hd71bxx_capvols[] = {
429 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
430 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
431};
432#define stac92hd71bxx_capsws stac92hd71bxx_capvols
433
Tobin Davis8e21c342007-01-08 11:04:17 +0100434static hda_nid_t stac925x_adc_nids[1] = {
435 0x03,
436};
437
438static hda_nid_t stac925x_mux_nids[1] = {
439 0x0f,
440};
441
442static hda_nid_t stac925x_dac_nids[1] = {
443 0x02,
444};
445
Takashi Iwaif6e98522007-10-16 14:27:04 +0200446#define STAC925X_NUM_DMICS 1
447static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
448 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200449};
450
Takashi Iwai1697055e2007-12-18 18:05:52 +0100451static hda_nid_t stac925x_dmux_nids[1] = {
452 0x14,
453};
454
Takashi Iwai6479c632009-07-28 18:20:25 +0200455static unsigned long stac925x_capvols[] = {
456 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
457};
458static unsigned long stac925x_capsws[] = {
459 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
460};
461
Matt2f2f4252005-04-13 14:45:30 +0200462static hda_nid_t stac922x_adc_nids[2] = {
463 0x06, 0x07,
464};
465
466static hda_nid_t stac922x_mux_nids[2] = {
467 0x12, 0x13,
468};
469
Takashi Iwai6479c632009-07-28 18:20:25 +0200470#define STAC922X_NUM_CAPS 2
471static unsigned long stac922x_capvols[] = {
472 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
473 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
474};
475#define stac922x_capsws stac922x_capvols
476
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500477static hda_nid_t stac927x_slave_dig_outs[2] = {
478 0x1f, 0,
479};
480
Matt Porter3cc08dc2006-01-23 15:27:49 +0100481static hda_nid_t stac927x_adc_nids[3] = {
482 0x07, 0x08, 0x09
483};
484
485static hda_nid_t stac927x_mux_nids[3] = {
486 0x15, 0x16, 0x17
487};
488
Matthew Ranostayd9737752008-09-07 12:03:41 +0200489static hda_nid_t stac927x_smux_nids[1] = {
490 0x21,
491};
492
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100493static hda_nid_t stac927x_dac_nids[6] = {
494 0x02, 0x03, 0x04, 0x05, 0x06, 0
495};
496
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100497static hda_nid_t stac927x_dmux_nids[1] = {
498 0x1b,
499};
500
Matthew Ranostay7f168592007-10-18 17:38:17 +0200501#define STAC927X_NUM_DMICS 2
502static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
503 0x13, 0x14, 0
504};
505
Takashi Iwai6479c632009-07-28 18:20:25 +0200506#define STAC927X_NUM_CAPS 3
507static unsigned long stac927x_capvols[] = {
508 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
509 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
510 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
511};
512static unsigned long stac927x_capsws[] = {
513 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
514 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
515 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
516};
517
Matthew Ranostay65973632008-09-16 10:39:37 -0400518static const char *stac927x_spdif_labels[5] = {
519 "Digital Playback", "ADAT", "Analog Mux 1",
520 "Analog Mux 2", "Analog Mux 3"
521};
522
Matt Porterf3302a52006-07-31 12:49:34 +0200523static hda_nid_t stac9205_adc_nids[2] = {
524 0x12, 0x13
525};
526
527static hda_nid_t stac9205_mux_nids[2] = {
528 0x19, 0x1a
529};
530
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100531static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100532 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100533};
534
Matthew Ranostayd9737752008-09-07 12:03:41 +0200535static hda_nid_t stac9205_smux_nids[1] = {
536 0x21,
537};
538
Takashi Iwaif6e98522007-10-16 14:27:04 +0200539#define STAC9205_NUM_DMICS 2
540static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
541 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200542};
543
Takashi Iwai6479c632009-07-28 18:20:25 +0200544#define STAC9205_NUM_CAPS 2
545static unsigned long stac9205_capvols[] = {
546 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
547 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
548};
549static unsigned long stac9205_capsws[] = {
550 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
551 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
552};
553
Mattc7d4b2f2005-06-27 14:59:41 +0200554static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200555 0x08, 0x09, 0x0d, 0x0e,
556 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200557};
558
Tobin Davis8e21c342007-01-08 11:04:17 +0100559static hda_nid_t stac925x_pin_nids[8] = {
560 0x07, 0x08, 0x0a, 0x0b,
561 0x0c, 0x0d, 0x10, 0x11,
562};
563
Matt2f2f4252005-04-13 14:45:30 +0200564static hda_nid_t stac922x_pin_nids[10] = {
565 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
566 0x0f, 0x10, 0x11, 0x15, 0x1b,
567};
568
Matthew Ranostaya7662642008-02-21 07:51:14 +0100569static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100570 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
571 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200572 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100573};
574
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500575static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200576 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500577 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200578};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500579
Charles Chin36706002010-01-29 12:05:51 +0100580static hda_nid_t stac92hd88xxx_pin_nids[10] = {
581 0x0a, 0x0b, 0x0c, 0x0d,
582 0x0f, 0x11, 0x1f, 0x20,
583};
584
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500585#define STAC92HD71BXX_NUM_PINS 13
586static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
587 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
588 0x00, 0x14, 0x18, 0x19, 0x1e,
589 0x1f, 0x20, 0x27
590};
591static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100592 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
593 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500594 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100595};
596
Matt Porter3cc08dc2006-01-23 15:27:49 +0100597static hda_nid_t stac927x_pin_nids[14] = {
598 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
599 0x0f, 0x10, 0x11, 0x12, 0x13,
600 0x14, 0x21, 0x22, 0x23,
601};
602
Matt Porterf3302a52006-07-31 12:49:34 +0200603static hda_nid_t stac9205_pin_nids[12] = {
604 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
605 0x0f, 0x14, 0x16, 0x17, 0x18,
606 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200607};
608
Matt Porter8b657272006-10-26 17:12:59 +0200609static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
610 struct snd_ctl_elem_info *uinfo)
611{
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 struct sigmatel_spec *spec = codec->spec;
614 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
615}
616
617static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
618 struct snd_ctl_elem_value *ucontrol)
619{
620 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
621 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100622 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200623
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100624 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200625 return 0;
626}
627
628static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
629 struct snd_ctl_elem_value *ucontrol)
630{
631 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
632 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100633 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200634
635 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100636 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200637}
638
Matthew Ranostayd9737752008-09-07 12:03:41 +0200639static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
640 struct snd_ctl_elem_info *uinfo)
641{
642 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
643 struct sigmatel_spec *spec = codec->spec;
644 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
645}
646
647static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_value *ucontrol)
649{
650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651 struct sigmatel_spec *spec = codec->spec;
652 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
653
654 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
655 return 0;
656}
657
658static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
659 struct snd_ctl_elem_value *ucontrol)
660{
661 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
662 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400663 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200664 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400665 int err, val;
666 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200667
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400668 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200669 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400670 if (err < 0)
671 return err;
672
673 if (spec->spdif_mute) {
674 if (smux_idx == 0)
675 nid = spec->multiout.dig_out_nid;
676 else
677 nid = codec->slave_dig_outs[smux_idx - 1];
678 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100679 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400680 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100681 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400682 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100683 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
684 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400685 }
686 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200687}
688
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200689static unsigned int stac92xx_vref_set(struct hda_codec *codec,
690 hda_nid_t nid, unsigned int new_vref)
691{
Takashi Iwaib8621512009-06-22 08:00:10 +0200692 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200693 unsigned int pincfg;
694 pincfg = snd_hda_codec_read(codec, nid, 0,
695 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
696
697 pincfg &= 0xff;
698 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
699 pincfg |= new_vref;
700
701 if (new_vref == AC_PINCTL_VREF_HIZ)
702 pincfg |= AC_PINCTL_OUT_EN;
703 else
704 pincfg |= AC_PINCTL_IN_EN;
705
706 error = snd_hda_codec_write_cache(codec, nid, 0,
707 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
708 if (error < 0)
709 return error;
710 else
711 return 1;
712}
713
714static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
715{
716 unsigned int vref;
717 vref = snd_hda_codec_read(codec, nid, 0,
718 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
719 vref &= AC_PINCTL_VREFEN;
720 return vref;
721}
722
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100723static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200724{
725 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
726 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200727 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200728}
729
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100730static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200731{
732 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
733 struct sigmatel_spec *spec = codec->spec;
734 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
735
736 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
737 return 0;
738}
739
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100740static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200741{
742 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
743 struct sigmatel_spec *spec = codec->spec;
744 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200745 const struct hda_input_mux *imux = spec->input_mux;
746 unsigned int idx, prev_idx;
Matt2f2f4252005-04-13 14:45:30 +0200747
Takashi Iwai5207e102009-07-30 13:09:08 +0200748 idx = ucontrol->value.enumerated.item[0];
749 if (idx >= imux->num_items)
750 idx = imux->num_items - 1;
751 prev_idx = spec->cur_mux[adc_idx];
752 if (prev_idx == idx)
753 return 0;
754 if (idx < spec->num_analog_muxes) {
755 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
756 AC_VERB_SET_CONNECT_SEL,
757 imux->items[idx].index);
758 if (prev_idx >= spec->num_analog_muxes) {
759 imux = spec->dinput_mux;
760 /* 0 = analog */
761 snd_hda_codec_write_cache(codec,
762 spec->dmux_nids[adc_idx], 0,
763 AC_VERB_SET_CONNECT_SEL,
764 imux->items[0].index);
765 }
766 } else {
767 imux = spec->dinput_mux;
768 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
769 AC_VERB_SET_CONNECT_SEL,
770 imux->items[idx - 1].index);
771 }
772 spec->cur_mux[adc_idx] = idx;
773 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200774}
775
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100776static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
777 struct snd_ctl_elem_info *uinfo)
778{
779 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
780 struct sigmatel_spec *spec = codec->spec;
781 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
782}
783
784static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
785 struct snd_ctl_elem_value *ucontrol)
786{
787 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
788 struct sigmatel_spec *spec = codec->spec;
789
790 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
791 return 0;
792}
793
794static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
795 struct snd_ctl_elem_value *ucontrol)
796{
797 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798 struct sigmatel_spec *spec = codec->spec;
799
800 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
801 spec->mono_nid, &spec->cur_mmux);
802}
803
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200804#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
805
806static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
807 struct snd_ctl_elem_value *ucontrol)
808{
809 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100810 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200811 struct sigmatel_spec *spec = codec->spec;
812
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100813 ucontrol->value.integer.value[0] = !!(spec->aloopback &
814 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200815 return 0;
816}
817
818static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
819 struct snd_ctl_elem_value *ucontrol)
820{
821 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
822 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100823 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200824 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100825 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200826
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100827 idx_val = spec->aloopback_mask << idx;
828 if (ucontrol->value.integer.value[0])
829 val = spec->aloopback | idx_val;
830 else
831 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100832 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200833 return 0;
834
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100835 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200836
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100837 /* Only return the bits defined by the shift value of the
838 * first two bytes of the mask
839 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200840 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100841 kcontrol->private_value & 0xFFFF, 0x0);
842 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200843
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100844 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200845 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100846 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200847 } else {
848 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100849 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200850 }
851
852 snd_hda_codec_write_cache(codec, codec->afg, 0,
853 kcontrol->private_value >> 16, dac_mode);
854
855 return 1;
856}
857
Mattc7d4b2f2005-06-27 14:59:41 +0200858static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200859 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200860 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200861 {}
862};
863
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200864static struct hda_verb stac9200_eapd_init[] = {
865 /* set dac0mux for dac converter */
866 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
867 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
868 {}
869};
870
Matthew Ranostayd654a662008-03-14 08:46:51 +0100871static struct hda_verb dell_eq_core_init[] = {
872 /* set master volume to max value without distortion
873 * and direct control */
874 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100875 {}
876};
877
Takashi Iwaie2aec172009-09-02 01:00:05 +0200878static struct hda_verb stac92hd73xx_core_init[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100879 /* set master volume and direct control */
880 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100881 {}
882};
883
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200884static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200885 /* power state controls amps */
886 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200887 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200888};
889
Matthew Ranostaye035b842007-11-06 11:53:55 +0100890static struct hda_verb stac92hd71bxx_core_init[] = {
891 /* set master volume and direct control */
892 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200893 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100894};
895
Matthew Ranostayca8d33f2009-01-26 09:33:52 -0500896static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
897 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
898 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100899 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
900 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100901 {}
902};
903
Tobin Davis8e21c342007-01-08 11:04:17 +0100904static struct hda_verb stac925x_core_init[] = {
905 /* set dac0mux for dac converter */
906 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100907 /* mute the master volume */
908 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100909 {}
910};
911
Mattc7d4b2f2005-06-27 14:59:41 +0200912static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200913 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200914 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200915 {}
916};
917
Tobin Davis93ed1502006-09-01 21:03:12 +0200918static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200919 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200920 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200921 /* unmute node 0x1b */
922 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
923 /* select node 0x03 as DAC */
924 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
925 {}
926};
927
Takashi Iwaiccca7cd2009-10-13 15:32:21 +0200928static struct hda_verb dell_3st_core_init[] = {
929 /* don't set delta bit */
930 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
931 /* unmute node 0x1b */
932 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
933 /* select node 0x03 as DAC */
934 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
935 {}
936};
937
Matt Porter3cc08dc2006-01-23 15:27:49 +0100938static struct hda_verb stac927x_core_init[] = {
939 /* set master volume and direct control */
940 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200941 /* enable analog pc beep path */
942 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100943 {}
944};
945
Takashi Iwai54930532009-10-11 17:38:29 +0200946static struct hda_verb stac927x_volknob_core_init[] = {
947 /* don't set delta bit */
948 {0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0x7f},
949 /* enable analog pc beep path */
950 {0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
951 {}
952};
953
Matt Porterf3302a52006-07-31 12:49:34 +0200954static struct hda_verb stac9205_core_init[] = {
955 /* set master volume and direct control */
956 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200957 /* enable analog pc beep path */
958 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200959 {}
960};
961
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100962#define STAC_MONO_MUX \
963 { \
964 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
965 .name = "Mono Mux", \
966 .count = 1, \
967 .info = stac92xx_mono_mux_enum_info, \
968 .get = stac92xx_mono_mux_enum_get, \
969 .put = stac92xx_mono_mux_enum_put, \
970 }
971
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100972#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200973 { \
974 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
975 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100976 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200977 .info = stac92xx_aloopback_info, \
978 .get = stac92xx_aloopback_get, \
979 .put = stac92xx_aloopback_put, \
980 .private_value = verb_read | (verb_write << 16), \
981 }
982
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200983#define DC_BIAS(xname, idx, nid) \
984 { \
985 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
986 .name = xname, \
987 .index = idx, \
988 .info = stac92xx_dc_bias_info, \
989 .get = stac92xx_dc_bias_get, \
990 .put = stac92xx_dc_bias_put, \
991 .private_value = nid, \
992 }
993
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100994static struct snd_kcontrol_new stac9200_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +0200995 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200996 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200997 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
998 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200999 { } /* end */
1000};
1001
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001002static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1003 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1004 {}
1005};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001006
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001007static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1008 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1009 {}
1010};
1011
1012static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1013 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1014 {}
1015};
1016
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001017
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001018static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1019 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1020};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001021
Tobin Davis8e21c342007-01-08 11:04:17 +01001022static struct snd_kcontrol_new stac925x_mixer[] = {
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001023 HDA_CODEC_VOLUME_MIN_MUTE("Master Playback Volume", 0xe, 0, HDA_OUTPUT),
Takashi Iwaic9280d62009-01-15 17:31:00 +01001024 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001025 { } /* end */
1026};
1027
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001028static struct snd_kcontrol_new stac9205_loopback[] = {
1029 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1030 {}
1031};
1032
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001033static struct snd_kcontrol_new stac927x_loopback[] = {
1034 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1035 {}
1036};
1037
Takashi Iwai1697055e2007-12-18 18:05:52 +01001038static struct snd_kcontrol_new stac_dmux_mixer = {
1039 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1040 .name = "Digital Input Source",
1041 /* count set later */
1042 .info = stac92xx_dmux_enum_info,
1043 .get = stac92xx_dmux_enum_get,
1044 .put = stac92xx_dmux_enum_put,
1045};
1046
Matthew Ranostayd9737752008-09-07 12:03:41 +02001047static struct snd_kcontrol_new stac_smux_mixer = {
1048 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001049 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001050 /* count set later */
1051 .info = stac92xx_smux_enum_info,
1052 .get = stac92xx_smux_enum_get,
1053 .put = stac92xx_smux_enum_put,
1054};
1055
Takashi Iwai2134ea42008-01-10 16:53:55 +01001056static const char *slave_vols[] = {
1057 "Front Playback Volume",
1058 "Surround Playback Volume",
1059 "Center Playback Volume",
1060 "LFE Playback Volume",
1061 "Side Playback Volume",
1062 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001063 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001064 NULL
1065};
1066
1067static const char *slave_sws[] = {
1068 "Front Playback Switch",
1069 "Surround Playback Switch",
1070 "Center Playback Switch",
1071 "LFE Playback Switch",
1072 "Side Playback Switch",
1073 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001074 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001075 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001076 NULL
1077};
1078
Takashi Iwai603c4012008-07-30 15:01:44 +02001079static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001080static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001081
Matt2f2f4252005-04-13 14:45:30 +02001082static int stac92xx_build_controls(struct hda_codec *codec)
1083{
1084 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001085 struct auto_pin_cfg *cfg = &spec->autocfg;
1086 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001087 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001088 int i;
Matt2f2f4252005-04-13 14:45:30 +02001089
Takashi Iwai6479c632009-07-28 18:20:25 +02001090 if (spec->mixer) {
1091 err = snd_hda_add_new_ctls(codec, spec->mixer);
1092 if (err < 0)
1093 return err;
1094 }
Mattc7d4b2f2005-06-27 14:59:41 +02001095
1096 for (i = 0; i < spec->num_mixers; i++) {
1097 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1098 if (err < 0)
1099 return err;
1100 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001101 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1102 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001103 stac_dmux_mixer.count = spec->num_dmuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001104 err = snd_hda_ctl_add(codec, 0,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001105 snd_ctl_new1(&stac_dmux_mixer, codec));
1106 if (err < 0)
1107 return err;
1108 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001109 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001110 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1111 struct hda_input_mux *smux = &spec->private_smux;
1112 /* check for mute support on SPDIF out */
1113 if (wcaps & AC_WCAP_OUT_AMP) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02001114 snd_hda_add_imux_item(smux, "Off", 0, NULL);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001115 spec->spdif_mute = 1;
1116 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001117 stac_smux_mixer.count = spec->num_smuxes;
Jaroslav Kysela3911a4c2009-11-11 13:43:01 +01001118 err = snd_hda_ctl_add(codec, 0,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001119 snd_ctl_new1(&stac_smux_mixer, codec));
1120 if (err < 0)
1121 return err;
1122 }
Mattc7d4b2f2005-06-27 14:59:41 +02001123
Mattdabbed62005-06-14 10:19:34 +02001124 if (spec->multiout.dig_out_nid) {
1125 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1126 if (err < 0)
1127 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001128 err = snd_hda_create_spdif_share_sw(codec,
1129 &spec->multiout);
1130 if (err < 0)
1131 return err;
1132 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001133 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001134 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001135 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1136 if (err < 0)
1137 return err;
1138 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001139
1140 /* if we have no master control, let's create it */
1141 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001142 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001143 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001144 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001145 /* correct volume offset */
1146 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Clemens Ladischde8c85f2010-10-15 10:32:50 +02001147 /* minimum value is actually mute */
1148 vmaster_tlv[3] |= 0x1000;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001149 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001150 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001151 if (err < 0)
1152 return err;
1153 }
1154 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1155 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1156 NULL, slave_sws);
1157 if (err < 0)
1158 return err;
1159 }
1160
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001161 if (spec->aloopback_ctl &&
1162 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1163 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1164 if (err < 0)
1165 return err;
1166 }
1167
Takashi Iwai603c4012008-07-30 15:01:44 +02001168 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001169
1170 /* create jack input elements */
1171 if (spec->hp_detect) {
1172 for (i = 0; i < cfg->hp_outs; i++) {
1173 int type = SND_JACK_HEADPHONE;
1174 nid = cfg->hp_pins[i];
1175 /* jack detection */
1176 if (cfg->hp_outs == i)
1177 type |= SND_JACK_LINEOUT;
1178 err = stac92xx_add_jack(codec, nid, type);
1179 if (err < 0)
1180 return err;
1181 }
1182 }
1183 for (i = 0; i < cfg->line_outs; i++) {
1184 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1185 SND_JACK_LINEOUT);
1186 if (err < 0)
1187 return err;
1188 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02001189 for (i = 0; i < cfg->num_inputs; i++) {
1190 nid = cfg->inputs[i].pin;
1191 err = stac92xx_add_jack(codec, nid, SND_JACK_MICROPHONE);
1192 if (err < 0)
1193 return err;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001194 }
1195
Mattdabbed62005-06-14 10:19:34 +02001196 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001197}
1198
Matt Porter403d1942005-11-29 15:00:51 +01001199static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001200 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001201 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1202};
1203
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001204static unsigned int gateway9200_m4_pin_configs[8] = {
1205 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1206 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1207};
1208static unsigned int gateway9200_m4_2_pin_configs[8] = {
1209 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1210 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1211};
1212
1213/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001214 STAC 9200 pin configs for
1215 102801A8
1216 102801DE
1217 102801E8
1218*/
1219static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001220 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1221 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001222};
1223
1224/*
1225 STAC 9200 pin configs for
1226 102801C0
1227 102801C1
1228*/
1229static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001230 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1231 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001232};
1233
1234/*
1235 STAC 9200 pin configs for
1236 102801C4 (Dell Dimension E310)
1237 102801C5
1238 102801C7
1239 102801D9
1240 102801DA
1241 102801E3
1242*/
1243static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001244 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1245 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001246};
1247
1248
1249/*
1250 STAC 9200-32 pin configs for
1251 102801B5 (Dell Inspiron 630m)
1252 102801D8 (Dell Inspiron 640m)
1253*/
1254static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001255 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1256 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001257};
1258
1259/*
1260 STAC 9200-32 pin configs for
1261 102801C2 (Dell Latitude D620)
1262 102801C8
1263 102801CC (Dell Latitude D820)
1264 102801D4
1265 102801D6
1266*/
1267static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001268 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1269 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001270};
1271
1272/*
1273 STAC 9200-32 pin configs for
1274 102801CE (Dell XPS M1710)
1275 102801CF (Dell Precision M90)
1276*/
1277static unsigned int dell9200_m23_pin_configs[8] = {
1278 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1279 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1280};
1281
1282/*
1283 STAC 9200-32 pin configs for
1284 102801C9
1285 102801CA
1286 102801CB (Dell Latitude 120L)
1287 102801D3
1288*/
1289static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001290 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1291 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001292};
1293
1294/*
1295 STAC 9200-32 pin configs for
1296 102801BD (Dell Inspiron E1505n)
1297 102801EE
1298 102801EF
1299*/
1300static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001301 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1302 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001303};
1304
1305/*
1306 STAC 9200-32 pin configs for
1307 102801F5 (Dell Inspiron 1501)
1308 102801F6
1309*/
1310static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001311 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1312 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001313};
1314
1315/*
1316 STAC 9200-32
1317 102801CD (Dell Inspiron E1705/9400)
1318*/
1319static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001320 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1321 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001322};
1323
Tobin Davisbf277782008-02-03 20:31:47 +01001324static unsigned int oqo9200_pin_configs[8] = {
1325 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1326 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1327};
1328
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001329
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001330static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1331 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001332 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001333 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1334 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1335 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1336 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1337 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1338 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1339 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1340 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1341 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1342 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001343 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1344 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001345 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001346};
1347
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001348static const char *stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001349 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001350 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001351 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001352 [STAC_9200_DELL_D21] = "dell-d21",
1353 [STAC_9200_DELL_D22] = "dell-d22",
1354 [STAC_9200_DELL_D23] = "dell-d23",
1355 [STAC_9200_DELL_M21] = "dell-m21",
1356 [STAC_9200_DELL_M22] = "dell-m22",
1357 [STAC_9200_DELL_M23] = "dell-m23",
1358 [STAC_9200_DELL_M24] = "dell-m24",
1359 [STAC_9200_DELL_M25] = "dell-m25",
1360 [STAC_9200_DELL_M26] = "dell-m26",
1361 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001362 [STAC_9200_M4] = "gateway-m4",
1363 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001364 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001365};
1366
1367static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1368 /* SigmaTel reference board */
1369 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1370 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001371 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1372 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001373 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001374 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1375 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001376 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001377 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1378 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1379 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1380 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1381 "unknown Dell", STAC_9200_DELL_D22),
1382 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1383 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001384 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001385 "Dell Latitude D620", STAC_9200_DELL_M22),
1386 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1387 "unknown Dell", STAC_9200_DELL_D23),
1388 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1389 "unknown Dell", STAC_9200_DELL_D23),
1390 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1391 "unknown Dell", STAC_9200_DELL_M22),
1392 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1393 "unknown Dell", STAC_9200_DELL_M24),
1394 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1395 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001396 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001397 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001398 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001399 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001400 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001401 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001402 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001403 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001404 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001405 "Dell Precision M90", STAC_9200_DELL_M23),
1406 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1407 "unknown Dell", STAC_9200_DELL_M22),
1408 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1409 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001410 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001411 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001412 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001413 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1414 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1415 "unknown Dell", STAC_9200_DELL_D23),
1416 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1417 "unknown Dell", STAC_9200_DELL_D23),
1418 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1419 "unknown Dell", STAC_9200_DELL_D21),
1420 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1421 "unknown Dell", STAC_9200_DELL_D23),
1422 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1423 "unknown Dell", STAC_9200_DELL_D21),
1424 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1425 "unknown Dell", STAC_9200_DELL_M25),
1426 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1427 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001428 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001429 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1430 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1431 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001432 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001433 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001434 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001435 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1436 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1437 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001438 /* OQO Mobile */
1439 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001440 {} /* terminator */
1441};
1442
Tobin Davis8e21c342007-01-08 11:04:17 +01001443static unsigned int ref925x_pin_configs[8] = {
1444 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001445 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001446};
1447
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001448static unsigned int stac925xM1_pin_configs[8] = {
1449 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1450 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001451};
1452
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001453static unsigned int stac925xM1_2_pin_configs[8] = {
1454 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1455 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1456};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001457
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001458static unsigned int stac925xM2_pin_configs[8] = {
1459 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1460 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001461};
1462
Tobin Davis8e21c342007-01-08 11:04:17 +01001463static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001464 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1465 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1466};
1467
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001468static unsigned int stac925xM3_pin_configs[8] = {
1469 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1470 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1471};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001472
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001473static unsigned int stac925xM5_pin_configs[8] = {
1474 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1475 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1476};
1477
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001478static unsigned int stac925xM6_pin_configs[8] = {
1479 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1480 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001481};
1482
1483static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1484 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001485 [STAC_M1] = stac925xM1_pin_configs,
1486 [STAC_M1_2] = stac925xM1_2_pin_configs,
1487 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001488 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001489 [STAC_M3] = stac925xM3_pin_configs,
1490 [STAC_M5] = stac925xM5_pin_configs,
1491 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001492};
1493
1494static const char *stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001495 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001496 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001497 [STAC_M1] = "m1",
1498 [STAC_M1_2] = "m1-2",
1499 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001500 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001501 [STAC_M3] = "m3",
1502 [STAC_M5] = "m5",
1503 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001504};
1505
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001506static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001507 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1508 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1509 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1510 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001511 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001512 /* Not sure about the brand name for those */
1513 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1514 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1515 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1516 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001517 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001518};
1519
1520static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1521 /* SigmaTel reference board */
1522 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001523 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001524 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001525
1526 /* Default table for unknown ID */
1527 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1528
Tobin Davis8e21c342007-01-08 11:04:17 +01001529 {} /* terminator */
1530};
1531
Matthew Ranostaya7662642008-02-21 07:51:14 +01001532static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001533 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1534 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1535 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001536 0x01452050,
1537};
1538
1539static unsigned int dell_m6_pin_configs[13] = {
1540 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001541 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001542 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1543 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001544};
1545
Takashi Iwai842ae632009-09-02 07:43:08 +02001546static unsigned int alienware_m17x_pin_configs[13] = {
1547 0x0321101f, 0x0321101f, 0x03a11020, 0x03014020,
1548 0x90170110, 0x4f0000f0, 0x4f0000f0, 0x4f0000f0,
1549 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1550 0x904601b0,
1551};
1552
Wu Fengguang4d26f442010-05-07 08:47:54 +08001553static unsigned int intel_dg45id_pin_configs[13] = {
Alexey Fisher52dc4382009-12-12 11:16:41 +02001554 0x02214230, 0x02A19240, 0x01013214, 0x01014210,
Wu Fengguang4d26f442010-05-07 08:47:54 +08001555 0x01A19250, 0x01011212, 0x01016211
Alexey Fisher52dc4382009-12-12 11:16:41 +02001556};
1557
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001558static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001559 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001560 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1561 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1562 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001563 [STAC_DELL_EQ] = dell_m6_pin_configs,
Takashi Iwai842ae632009-09-02 07:43:08 +02001564 [STAC_ALIENWARE_M17X] = alienware_m17x_pin_configs,
Alexey Fisher52dc4382009-12-12 11:16:41 +02001565 [STAC_92HD73XX_INTEL] = intel_dg45id_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001566};
1567
1568static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001569 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001570 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001571 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001572 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001573 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1574 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1575 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001576 [STAC_DELL_EQ] = "dell-eq",
Takashi Iwai842ae632009-09-02 07:43:08 +02001577 [STAC_ALIENWARE_M17X] = "alienware",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001578};
1579
1580static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1581 /* SigmaTel reference board */
1582 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001583 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001584 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1585 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001586 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1587 "Intel DG45ID", STAC_92HD73XX_INTEL),
1588 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1589 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001591 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001593 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001595 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001597 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001599 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001601 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001602 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001603 "unknown Dell", STAC_DELL_M6_DMIC),
1604 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1605 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001606 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001607 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001608 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1609 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001610 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1611 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Daniel J Blueman8ef58372009-11-14 18:20:04 +00001612 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1613 "Dell Studio 1557", STAC_DELL_M6_DMIC),
Daniel T Chenaac78da2010-04-21 20:41:52 -04001614 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1615 "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
Daniel T Chen5c1bccf2010-04-22 17:54:45 -04001616 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1617 "Dell Studio 1558", STAC_DELL_M6_BOTH),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001618 {} /* terminator */
1619};
1620
Takashi Iwai842ae632009-09-02 07:43:08 +02001621static struct snd_pci_quirk stac92hd73xx_codec_id_cfg_tbl[] = {
1622 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a1,
1623 "Alienware M17x", STAC_ALIENWARE_M17X),
1624 {} /* terminator */
1625};
1626
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001627static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001628 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1629 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001630 0x01451160, 0x98560170,
1631};
1632
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001633static unsigned int dell_s14_pin_configs[10] = {
Takashi Iwai69b56552009-09-15 12:37:42 +02001634 0x0221403f, 0x0221101f, 0x02a19020, 0x90170110,
1635 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a60160,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001636 0x40f000f0, 0x40f000f0,
1637};
1638
Steven Eastland48315592010-08-06 15:07:35 -06001639static unsigned int hp_dv7_4000_pin_configs[10] = {
1640 0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1641 0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1642 0x40f000f0, 0x40f000f0,
1643};
1644
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001645static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1646 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001647 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001648 [STAC_DELL_S14] = dell_s14_pin_configs,
Steven Eastland48315592010-08-06 15:07:35 -06001649 [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001650};
1651
1652static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001653 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001654 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001655 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001656 [STAC_DELL_S14] = "dell-s14",
Takashi Iwaib4e81872009-11-18 17:20:24 +01001657 [STAC_92HD83XXX_HP] = "hp",
Steven Eastland48315592010-08-06 15:07:35 -06001658 [STAC_HP_DV7_4000] = "hp-dv7-4000",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001659};
1660
1661static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1662 /* SigmaTel reference board */
1663 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001664 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001665 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1666 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001667 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1668 "unknown Dell", STAC_DELL_S14),
Takashi Iwaib4e81872009-11-18 17:20:24 +01001669 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1670 "HP", STAC_92HD83XXX_HP),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001671 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001672};
1673
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001674static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001675 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001676 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001677 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1678 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001679};
1680
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001681static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001682 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001683 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001684 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1685 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001686};
1687
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001688static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001689 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1690 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001691 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1692 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001693};
1694
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001695static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001696 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1697 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001698 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1699 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001700};
1701
Matthew Ranostaye035b842007-11-06 11:53:55 +01001702static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1703 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001704 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1705 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001706 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001707 [STAC_HP_M4] = NULL,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001708 [STAC_HP_DV4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001709 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001710 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001711 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001712};
1713
1714static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001715 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001716 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001717 [STAC_DELL_M4_1] = "dell-m4-1",
1718 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001719 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001720 [STAC_HP_M4] = "hp-m4",
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001721 [STAC_HP_DV4] = "hp-dv4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001722 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001723 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001724 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001725};
1726
1727static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1728 /* SigmaTel reference board */
1729 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1730 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001731 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1732 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001733 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1734 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01001735 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x1720,
1736 "HP", STAC_HP_DV5),
Takashi Iwai58d83952009-03-13 17:04:34 +01001737 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1738 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001739 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02001740 "HP dv4-7", STAC_HP_DV4),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001741 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1742 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001743 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1744 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001745 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001746 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001747 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001748 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai6e34c032009-09-14 15:42:18 +02001749 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3620,
1750 "HP dv6", STAC_HP_DV5),
Kunal Gangakhedkare3d25302010-03-20 23:08:01 +05301751 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3061,
1752 "HP dv6", STAC_HP_DV5), /* HP dv6-1110ax */
Takashi Iwai1972d022009-08-06 08:44:43 +02001753 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1754 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001755 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1756 "unknown Dell", STAC_DELL_M4_1),
1757 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1758 "unknown Dell", STAC_DELL_M4_1),
1759 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1760 "unknown Dell", STAC_DELL_M4_1),
1761 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1762 "unknown Dell", STAC_DELL_M4_1),
1763 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1764 "unknown Dell", STAC_DELL_M4_1),
1765 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1766 "unknown Dell", STAC_DELL_M4_1),
1767 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1768 "unknown Dell", STAC_DELL_M4_1),
1769 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1770 "unknown Dell", STAC_DELL_M4_2),
1771 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1772 "unknown Dell", STAC_DELL_M4_2),
1773 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1774 "unknown Dell", STAC_DELL_M4_2),
1775 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1776 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001777 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1778 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001779 {} /* terminator */
1780};
1781
Matt Porter403d1942005-11-29 15:00:51 +01001782static unsigned int ref922x_pin_configs[10] = {
1783 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1784 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001785 0x40000100, 0x40000100,
1786};
1787
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001788/*
1789 STAC 922X pin configs for
1790 102801A7
1791 102801AB
1792 102801A9
1793 102801D1
1794 102801D2
1795*/
1796static unsigned int dell_922x_d81_pin_configs[10] = {
1797 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1798 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1799 0x01813122, 0x400001f2,
1800};
1801
1802/*
1803 STAC 922X pin configs for
1804 102801AC
1805 102801D0
1806*/
1807static unsigned int dell_922x_d82_pin_configs[10] = {
1808 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1809 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1810 0x01813122, 0x400001f1,
1811};
1812
1813/*
1814 STAC 922X pin configs for
1815 102801BF
1816*/
1817static unsigned int dell_922x_m81_pin_configs[10] = {
1818 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1819 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1820 0x40C003f1, 0x405003f0,
1821};
1822
1823/*
1824 STAC 9221 A1 pin configs for
1825 102801D7 (Dell XPS M1210)
1826*/
1827static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001828 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1829 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001830 0x508003f3, 0x405003f4,
1831};
1832
Matt Porter403d1942005-11-29 15:00:51 +01001833static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001834 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001835 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1836 0x02a19120, 0x40000100,
1837};
1838
1839static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001840 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1841 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001842 0x02a19320, 0x40000100,
1843};
1844
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001845static unsigned int intel_mac_v1_pin_configs[10] = {
1846 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1847 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001848 0x400000fc, 0x400000fb,
1849};
1850
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001851static unsigned int intel_mac_v2_pin_configs[10] = {
1852 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1853 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001854 0x400000fc, 0x400000fb,
1855};
1856
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001857static unsigned int intel_mac_v3_pin_configs[10] = {
1858 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1859 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1860 0x400000fc, 0x400000fb,
1861};
1862
1863static unsigned int intel_mac_v4_pin_configs[10] = {
1864 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1865 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1866 0x400000fc, 0x400000fb,
1867};
1868
1869static unsigned int intel_mac_v5_pin_configs[10] = {
1870 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1871 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1872 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001873};
1874
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001875static unsigned int ecs202_pin_configs[10] = {
1876 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1877 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1878 0x9037012e, 0x40e000f2,
1879};
Takashi Iwai76c08822007-06-19 12:17:42 +02001880
Takashi Iwai19039bd2006-06-28 15:52:16 +02001881static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001882 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001883 [STAC_D945GTP3] = d945gtp3_pin_configs,
1884 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001885 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1886 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1887 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1888 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1889 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001890 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001891 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001892 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1893 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1894 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1895 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1896 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1897 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001898 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001899 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1900 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1901 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1902 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001903};
1904
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001905static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001906 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001907 [STAC_D945_REF] = "ref",
1908 [STAC_D945GTP5] = "5stack",
1909 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001910 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1911 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1912 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1913 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1914 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001915 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001916 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001917 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001918 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001919 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1920 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001921 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001922 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001923 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001924 [STAC_922X_DELL_D81] = "dell-d81",
1925 [STAC_922X_DELL_D82] = "dell-d82",
1926 [STAC_922X_DELL_M81] = "dell-m81",
1927 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001928};
1929
1930static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1931 /* SigmaTel reference board */
1932 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1933 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001934 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1935 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001936 /* Intel 945G based systems */
1937 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1938 "Intel D945G", STAC_D945GTP3),
1939 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1940 "Intel D945G", STAC_D945GTP3),
1941 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1942 "Intel D945G", STAC_D945GTP3),
1943 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1944 "Intel D945G", STAC_D945GTP3),
1945 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1946 "Intel D945G", STAC_D945GTP3),
1947 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1948 "Intel D945G", STAC_D945GTP3),
1949 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1950 "Intel D945G", STAC_D945GTP3),
1951 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1952 "Intel D945G", STAC_D945GTP3),
1953 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1954 "Intel D945G", STAC_D945GTP3),
1955 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1956 "Intel D945G", STAC_D945GTP3),
1957 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1958 "Intel D945G", STAC_D945GTP3),
1959 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1960 "Intel D945G", STAC_D945GTP3),
1961 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1962 "Intel D945G", STAC_D945GTP3),
1963 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1964 "Intel D945G", STAC_D945GTP3),
1965 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1966 "Intel D945G", STAC_D945GTP3),
1967 /* Intel D945G 5-stack systems */
1968 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1969 "Intel D945G", STAC_D945GTP5),
1970 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1971 "Intel D945G", STAC_D945GTP5),
1972 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1973 "Intel D945G", STAC_D945GTP5),
1974 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1975 "Intel D945G", STAC_D945GTP5),
1976 /* Intel 945P based systems */
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1978 "Intel D945P", STAC_D945GTP3),
1979 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1980 "Intel D945P", STAC_D945GTP3),
1981 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1982 "Intel D945P", STAC_D945GTP3),
1983 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1984 "Intel D945P", STAC_D945GTP3),
1985 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1986 "Intel D945P", STAC_D945GTP3),
1987 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1988 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01001989 /* other intel */
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
1991 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001992 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08001993 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001994 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001995 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001996 /* Dell systems */
1997 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1998 "unknown Dell", STAC_922X_DELL_D81),
1999 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2000 "unknown Dell", STAC_922X_DELL_D81),
2001 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2002 "unknown Dell", STAC_922X_DELL_D81),
2003 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2004 "unknown Dell", STAC_922X_DELL_D82),
2005 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2006 "unknown Dell", STAC_922X_DELL_M81),
2007 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2008 "unknown Dell", STAC_922X_DELL_D82),
2009 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2010 "unknown Dell", STAC_922X_DELL_D81),
2011 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2012 "unknown Dell", STAC_922X_DELL_D81),
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2014 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002015 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002016 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002017 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002018 {} /* terminator */
2019};
2020
Matt Porter3cc08dc2006-01-23 15:27:49 +01002021static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002022 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2023 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2024 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2025 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002026};
2027
Tobin Davis93ed1502006-09-01 21:03:12 +02002028static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002029 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2030 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2031 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2032 0x40000100, 0x40000100
2033};
2034
Tobin Davis93ed1502006-09-01 21:03:12 +02002035static unsigned int d965_5st_pin_configs[14] = {
2036 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2037 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2038 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2039 0x40000100, 0x40000100
2040};
2041
Takashi Iwai679d92e2009-05-24 19:00:08 +02002042static unsigned int d965_5st_no_fp_pin_configs[14] = {
2043 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2044 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2045 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2046 0x40000100, 0x40000100
2047};
2048
Tobin Davis4ff076e2007-08-07 11:48:12 +02002049static unsigned int dell_3st_pin_configs[14] = {
2050 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2051 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002052 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002053 0x40c003fc, 0x40000100
2054};
2055
Tobin Davis93ed1502006-09-01 21:03:12 +02002056static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002057 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002058 [STAC_D965_REF] = ref927x_pin_configs,
2059 [STAC_D965_3ST] = d965_3st_pin_configs,
2060 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002061 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002062 [STAC_DELL_3ST] = dell_3st_pin_configs,
2063 [STAC_DELL_BIOS] = NULL,
Takashi Iwai54930532009-10-11 17:38:29 +02002064 [STAC_927X_VOLKNOB] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002065};
2066
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002067static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002068 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002069 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002070 [STAC_D965_REF] = "ref",
2071 [STAC_D965_3ST] = "3stack",
2072 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002073 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002074 [STAC_DELL_3ST] = "dell-3stack",
2075 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwai54930532009-10-11 17:38:29 +02002076 [STAC_927X_VOLKNOB] = "volknob",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002077};
2078
2079static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2080 /* SigmaTel reference board */
2081 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2082 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002083 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2084 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002085 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002086 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2087 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002088 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002089 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2090 "Intel D965", STAC_D965_3ST),
2091 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2092 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002093 /* Dell 3 stack systems */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002094 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002095 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2096 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002097 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002098 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
Daniel T Chen66668b62010-05-23 20:47:45 -04002099 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_BIOS),
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002100 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002101 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002102 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002103 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2104 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2106 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002107 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002108 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2109 "Intel D965", STAC_D965_5ST),
2110 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2111 "Intel D965", STAC_D965_5ST),
Takashi Iwai54930532009-10-11 17:38:29 +02002112 /* volume-knob fixes */
2113 SND_PCI_QUIRK_VENDOR(0x10cf, "FSC", STAC_927X_VOLKNOB),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002114 {} /* terminator */
2115};
2116
Matt Porterf3302a52006-07-31 12:49:34 +02002117static unsigned int ref9205_pin_configs[12] = {
2118 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002119 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002120 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002121};
2122
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002123/*
2124 STAC 9205 pin configs for
2125 102801F1
2126 102801F2
2127 102801FC
2128 102801FD
2129 10280204
2130 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002131 10280228 (Dell Vostro 1500)
Anisse Astier95e70e82009-12-23 17:28:45 +01002132 10280229 (Dell Vostro 1700)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002133*/
2134static unsigned int dell_9205_m42_pin_configs[12] = {
2135 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2136 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2137 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2138};
2139
2140/*
2141 STAC 9205 pin configs for
2142 102801F9
2143 102801FA
2144 102801FE
2145 102801FF (Dell Precision M4300)
2146 10280206
2147 10280200
2148 10280201
2149*/
2150static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002151 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2152 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2153 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2154};
2155
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002156static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002157 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2158 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2159 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2160};
2161
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002162static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002163 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002164 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2165 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2166 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002167 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002168};
2169
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002170static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002171 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002172 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002173 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002174 [STAC_9205_DELL_M43] = "dell-m43",
2175 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002176 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002177};
2178
2179static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2180 /* SigmaTel reference board */
2181 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2182 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002183 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2184 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002185 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2186 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002187 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002188 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2189 "unknown Dell", STAC_9205_DELL_M42),
2190 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2191 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002192 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002193 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002194 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2195 "Dell Precision", STAC_9205_DELL_M43),
2196 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2197 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002198 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2199 "unknown Dell", STAC_9205_DELL_M42),
2200 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2201 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002202 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2203 "Dell Precision", STAC_9205_DELL_M43),
2204 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002205 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002206 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2207 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2209 "Dell Precision", STAC_9205_DELL_M43),
2210 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2211 "Dell Precision", STAC_9205_DELL_M43),
2212 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2213 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002214 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2215 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002216 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2217 "Dell Vostro 1500", STAC_9205_DELL_M42),
Anisse Astier95e70e82009-12-23 17:28:45 +01002218 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0229,
2219 "Dell Vostro 1700", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002220 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002221 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002222 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002223 {} /* terminator */
2224};
2225
Takashi Iwai330ee992009-02-20 14:33:36 +01002226static void stac92xx_set_config_regs(struct hda_codec *codec,
2227 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002228{
2229 int i;
2230 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002231
Takashi Iwai330ee992009-02-20 14:33:36 +01002232 if (!pincfgs)
2233 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002234
Matthew Ranostay87d48362007-07-17 11:52:24 +02002235 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002236 if (spec->pin_nids[i] && pincfgs[i])
2237 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2238 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002239}
2240
Matt2f2f4252005-04-13 14:45:30 +02002241/*
2242 * Analog playback callbacks
2243 */
2244static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2245 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002246 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002247{
2248 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002249 if (spec->stream_delay)
2250 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002251 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2252 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002253}
2254
2255static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2256 struct hda_codec *codec,
2257 unsigned int stream_tag,
2258 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002259 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002260{
2261 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002262 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002263}
2264
2265static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2266 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002267 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002268{
2269 struct sigmatel_spec *spec = codec->spec;
2270 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2271}
2272
2273/*
Mattdabbed62005-06-14 10:19:34 +02002274 * Digital playback callbacks
2275 */
2276static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2277 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002278 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002279{
2280 struct sigmatel_spec *spec = codec->spec;
2281 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2282}
2283
2284static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2285 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002286 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002287{
2288 struct sigmatel_spec *spec = codec->spec;
2289 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2290}
2291
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002292static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2293 struct hda_codec *codec,
2294 unsigned int stream_tag,
2295 unsigned int format,
2296 struct snd_pcm_substream *substream)
2297{
2298 struct sigmatel_spec *spec = codec->spec;
2299 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2300 stream_tag, format, substream);
2301}
2302
Takashi Iwai9411e212009-02-13 11:32:28 +01002303static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2304 struct hda_codec *codec,
2305 struct snd_pcm_substream *substream)
2306{
2307 struct sigmatel_spec *spec = codec->spec;
2308 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2309}
2310
Mattdabbed62005-06-14 10:19:34 +02002311
2312/*
Matt2f2f4252005-04-13 14:45:30 +02002313 * Analog capture callbacks
2314 */
2315static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2316 struct hda_codec *codec,
2317 unsigned int stream_tag,
2318 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002319 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002320{
2321 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002322 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002323
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002324 if (spec->powerdown_adcs) {
2325 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002326 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002327 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2328 }
2329 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002330 return 0;
2331}
2332
2333static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2334 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002335 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002336{
2337 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002338 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002339
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002340 snd_hda_codec_cleanup_stream(codec, nid);
2341 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002342 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002343 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002344 return 0;
2345}
2346
Mattdabbed62005-06-14 10:19:34 +02002347static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2348 .substreams = 1,
2349 .channels_min = 2,
2350 .channels_max = 2,
2351 /* NID is set in stac92xx_build_pcms */
2352 .ops = {
2353 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002354 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002355 .prepare = stac92xx_dig_playback_pcm_prepare,
2356 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002357 },
2358};
2359
2360static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2361 .substreams = 1,
2362 .channels_min = 2,
2363 .channels_max = 2,
2364 /* NID is set in stac92xx_build_pcms */
2365};
2366
Matt2f2f4252005-04-13 14:45:30 +02002367static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2368 .substreams = 1,
2369 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002370 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002371 .nid = 0x02, /* NID to query formats and rates */
2372 .ops = {
2373 .open = stac92xx_playback_pcm_open,
2374 .prepare = stac92xx_playback_pcm_prepare,
2375 .cleanup = stac92xx_playback_pcm_cleanup
2376 },
2377};
2378
Matt Porter3cc08dc2006-01-23 15:27:49 +01002379static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2380 .substreams = 1,
2381 .channels_min = 2,
2382 .channels_max = 2,
2383 .nid = 0x06, /* NID to query formats and rates */
2384 .ops = {
2385 .open = stac92xx_playback_pcm_open,
2386 .prepare = stac92xx_playback_pcm_prepare,
2387 .cleanup = stac92xx_playback_pcm_cleanup
2388 },
2389};
2390
Matt2f2f4252005-04-13 14:45:30 +02002391static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002392 .channels_min = 2,
2393 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002394 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002395 .ops = {
2396 .prepare = stac92xx_capture_pcm_prepare,
2397 .cleanup = stac92xx_capture_pcm_cleanup
2398 },
2399};
2400
2401static int stac92xx_build_pcms(struct hda_codec *codec)
2402{
2403 struct sigmatel_spec *spec = codec->spec;
2404 struct hda_pcm *info = spec->pcm_rec;
2405
2406 codec->num_pcms = 1;
2407 codec->pcm_info = info;
2408
Mattc7d4b2f2005-06-27 14:59:41 +02002409 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002410 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002411 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2412 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002413 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002414 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002415 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002416
2417 if (spec->alt_switch) {
2418 codec->num_pcms++;
2419 info++;
2420 info->name = "STAC92xx Analog Alt";
2421 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2422 }
Matt2f2f4252005-04-13 14:45:30 +02002423
Mattdabbed62005-06-14 10:19:34 +02002424 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2425 codec->num_pcms++;
2426 info++;
2427 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002428 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002429 if (spec->multiout.dig_out_nid) {
2430 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2431 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2432 }
2433 if (spec->dig_in_nid) {
2434 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2435 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2436 }
2437 }
2438
Matt2f2f4252005-04-13 14:45:30 +02002439 return 0;
2440}
2441
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002442static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2443 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002444{
Takashi Iwai1327a322009-03-23 13:07:47 +01002445 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002446 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2447 if (pincap & AC_PINCAP_VREF_100)
2448 return AC_PINCTL_VREF_100;
2449 if (pincap & AC_PINCAP_VREF_80)
2450 return AC_PINCTL_VREF_80;
2451 if (pincap & AC_PINCAP_VREF_50)
2452 return AC_PINCTL_VREF_50;
2453 if (pincap & AC_PINCAP_VREF_GRD)
2454 return AC_PINCTL_VREF_GRD;
2455 return 0;
2456}
2457
Matt Porter403d1942005-11-29 15:00:51 +01002458static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2459
2460{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002461 snd_hda_codec_write_cache(codec, nid, 0,
2462 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002463}
2464
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002465#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2466
2467static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2468 struct snd_ctl_elem_value *ucontrol)
2469{
2470 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2471 struct sigmatel_spec *spec = codec->spec;
2472
Takashi Iwaid7a89432008-11-12 09:48:04 +01002473 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002474 return 0;
2475}
2476
Takashi Iwai62558ce2009-07-29 14:23:09 +02002477static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002478
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002479static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2480 struct snd_ctl_elem_value *ucontrol)
2481{
2482 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2483 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002484 int nid = kcontrol->private_value;
2485
2486 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002487
2488 /* check to be sure that the ports are upto date with
2489 * switch changes
2490 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002491 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002492
2493 return 1;
2494}
2495
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002496static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2497 struct snd_ctl_elem_info *uinfo)
2498{
2499 int i;
2500 static char *texts[] = {
2501 "Mic In", "Line In", "Line Out"
2502 };
2503
2504 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2505 struct sigmatel_spec *spec = codec->spec;
2506 hda_nid_t nid = kcontrol->private_value;
2507
2508 if (nid == spec->mic_switch || nid == spec->line_switch)
2509 i = 3;
2510 else
2511 i = 2;
2512
2513 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2514 uinfo->value.enumerated.items = i;
2515 uinfo->count = 1;
2516 if (uinfo->value.enumerated.item >= i)
2517 uinfo->value.enumerated.item = i-1;
2518 strcpy(uinfo->value.enumerated.name,
2519 texts[uinfo->value.enumerated.item]);
2520
2521 return 0;
2522}
2523
2524static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2525 struct snd_ctl_elem_value *ucontrol)
2526{
2527 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2528 hda_nid_t nid = kcontrol->private_value;
2529 unsigned int vref = stac92xx_vref_get(codec, nid);
2530
2531 if (vref == stac92xx_get_default_vref(codec, nid))
2532 ucontrol->value.enumerated.item[0] = 0;
2533 else if (vref == AC_PINCTL_VREF_GRD)
2534 ucontrol->value.enumerated.item[0] = 1;
2535 else if (vref == AC_PINCTL_VREF_HIZ)
2536 ucontrol->value.enumerated.item[0] = 2;
2537
2538 return 0;
2539}
2540
2541static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2542 struct snd_ctl_elem_value *ucontrol)
2543{
2544 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2545 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002546 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002547 hda_nid_t nid = kcontrol->private_value;
2548
2549 if (ucontrol->value.enumerated.item[0] == 0)
2550 new_vref = stac92xx_get_default_vref(codec, nid);
2551 else if (ucontrol->value.enumerated.item[0] == 1)
2552 new_vref = AC_PINCTL_VREF_GRD;
2553 else if (ucontrol->value.enumerated.item[0] == 2)
2554 new_vref = AC_PINCTL_VREF_HIZ;
2555 else
2556 return 0;
2557
2558 if (new_vref != stac92xx_vref_get(codec, nid)) {
2559 error = stac92xx_vref_set(codec, nid, new_vref);
2560 return error;
2561 }
2562
2563 return 0;
2564}
2565
2566static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2567 struct snd_ctl_elem_info *uinfo)
2568{
2569 static char *texts[2];
2570 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2571 struct sigmatel_spec *spec = codec->spec;
2572
2573 if (kcontrol->private_value == spec->line_switch)
2574 texts[0] = "Line In";
2575 else
2576 texts[0] = "Mic In";
2577 texts[1] = "Line Out";
2578 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2579 uinfo->value.enumerated.items = 2;
2580 uinfo->count = 1;
2581
2582 if (uinfo->value.enumerated.item >= 2)
2583 uinfo->value.enumerated.item = 1;
2584 strcpy(uinfo->value.enumerated.name,
2585 texts[uinfo->value.enumerated.item]);
2586
2587 return 0;
2588}
Matt Porter403d1942005-11-29 15:00:51 +01002589
2590static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2591{
2592 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2593 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002594 hda_nid_t nid = kcontrol->private_value;
2595 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002596
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002597 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002598 return 0;
2599}
2600
2601static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2602{
2603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2604 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002605 hda_nid_t nid = kcontrol->private_value;
2606 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2607 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002608
2609 spec->io_switch[io_idx] = val;
2610
2611 if (val)
2612 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002613 else {
2614 unsigned int pinctl = AC_PINCTL_IN_EN;
2615 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002616 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002617 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2618 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002619
2620 /* check the auto-mute again: we need to mute/unmute the speaker
2621 * appropriately according to the pin direction
2622 */
2623 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002624 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002625
Matt Porter403d1942005-11-29 15:00:51 +01002626 return 1;
2627}
2628
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002629#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2630
2631static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2632 struct snd_ctl_elem_value *ucontrol)
2633{
2634 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2635 struct sigmatel_spec *spec = codec->spec;
2636
2637 ucontrol->value.integer.value[0] = spec->clfe_swap;
2638 return 0;
2639}
2640
2641static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2642 struct snd_ctl_elem_value *ucontrol)
2643{
2644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2645 struct sigmatel_spec *spec = codec->spec;
2646 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002647 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002648
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002649 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002650 return 0;
2651
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002652 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002653
2654 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2655 spec->clfe_swap ? 0x4 : 0x0);
2656
2657 return 1;
2658}
2659
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002660#define STAC_CODEC_HP_SWITCH(xname) \
2661 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2662 .name = xname, \
2663 .index = 0, \
2664 .info = stac92xx_hp_switch_info, \
2665 .get = stac92xx_hp_switch_get, \
2666 .put = stac92xx_hp_switch_put, \
2667 }
2668
Matt Porter403d1942005-11-29 15:00:51 +01002669#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2670 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2671 .name = xname, \
2672 .index = 0, \
2673 .info = stac92xx_io_switch_info, \
2674 .get = stac92xx_io_switch_get, \
2675 .put = stac92xx_io_switch_put, \
2676 .private_value = xpval, \
2677 }
2678
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002679#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2680 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2681 .name = xname, \
2682 .index = 0, \
2683 .info = stac92xx_clfe_switch_info, \
2684 .get = stac92xx_clfe_switch_get, \
2685 .put = stac92xx_clfe_switch_put, \
2686 .private_value = xpval, \
2687 }
Matt Porter403d1942005-11-29 15:00:51 +01002688
Mattc7d4b2f2005-06-27 14:59:41 +02002689enum {
2690 STAC_CTL_WIDGET_VOL,
2691 STAC_CTL_WIDGET_MUTE,
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002692 STAC_CTL_WIDGET_MUTE_BEEP,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002693 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002694 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002695 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002696 STAC_CTL_WIDGET_CLFE_SWITCH,
2697 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002698};
2699
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002700static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002701 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2702 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02002703 HDA_CODEC_MUTE_BEEP(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002704 STAC_MONO_MUX,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002705 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002706 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002707 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002708 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002709};
2710
2711/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002712static struct snd_kcontrol_new *
2713stac_control_new(struct sigmatel_spec *spec,
2714 struct snd_kcontrol_new *ktemp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002715 const char *name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002716 unsigned int subdev)
Mattc7d4b2f2005-06-27 14:59:41 +02002717{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002718 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002719
Takashi Iwai603c4012008-07-30 15:01:44 +02002720 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2721 knew = snd_array_new(&spec->kctls);
2722 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002723 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002724 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002725 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002726 if (!knew->name) {
2727 /* roolback */
2728 memset(knew, 0, sizeof(*knew));
2729 spec->kctls.alloced--;
2730 return NULL;
2731 }
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002732 knew->subdevice = subdev;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002733 return knew;
2734}
2735
2736static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2737 struct snd_kcontrol_new *ktemp,
2738 int idx, const char *name,
2739 unsigned long val)
2740{
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002741 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name,
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002742 HDA_SUBDEV_AMP_FLAG);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002743 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002744 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002745 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002746 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002747 return 0;
2748}
2749
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002750static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2751 int type, int idx, const char *name,
2752 unsigned long val)
2753{
2754 return stac92xx_add_control_temp(spec,
2755 &stac92xx_control_templates[type],
2756 idx, name, val);
2757}
2758
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002759
2760/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002761static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2762 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002763{
2764 return stac92xx_add_control_idx(spec, type, 0, name, val);
2765}
2766
Takashi Iwaie3c75962009-01-23 11:57:22 +01002767static struct snd_kcontrol_new stac_input_src_temp = {
2768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2769 .name = "Input Source",
2770 .info = stac92xx_mux_enum_info,
2771 .get = stac92xx_mux_enum_get,
2772 .put = stac92xx_mux_enum_put,
2773};
2774
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002775static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2776 hda_nid_t nid, int idx)
2777{
2778 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2779 int control = 0;
2780 struct sigmatel_spec *spec = codec->spec;
2781 char name[22];
2782
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002783 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002784 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2785 && nid == spec->line_switch)
2786 control = STAC_CTL_WIDGET_IO_SWITCH;
2787 else if (snd_hda_query_pin_caps(codec, nid)
2788 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2789 control = STAC_CTL_WIDGET_DC_BIAS;
2790 else if (nid == spec->mic_switch)
2791 control = STAC_CTL_WIDGET_IO_SWITCH;
2792 }
2793
2794 if (control) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02002795 strcpy(name, hda_get_input_pin_label(codec, nid, 1));
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002796 return stac92xx_add_control(codec->spec, control,
2797 strcat(name, " Jack Mode"), nid);
2798 }
2799
2800 return 0;
2801}
2802
Takashi Iwaie3c75962009-01-23 11:57:22 +01002803static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2804{
2805 struct snd_kcontrol_new *knew;
2806 struct hda_input_mux *imux = &spec->private_imux;
2807
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002808 if (spec->auto_mic)
2809 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002810 if (!spec->num_adcs || imux->num_items <= 1)
2811 return 0; /* no need for input source control */
2812 knew = stac_control_new(spec, &stac_input_src_temp,
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002813 stac_input_src_temp.name, 0);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002814 if (!knew)
2815 return -ENOMEM;
2816 knew->count = spec->num_adcs;
2817 return 0;
2818}
2819
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002820/* check whether the line-input can be used as line-out */
2821static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002822{
2823 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002824 struct auto_pin_cfg *cfg = &spec->autocfg;
2825 hda_nid_t nid;
2826 unsigned int pincap;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002827 int i;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002828
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002829 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2830 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002831 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02002832 if (cfg->inputs[i].type == AUTO_PIN_LINE_IN) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002833 nid = cfg->inputs[i].pin;
2834 pincap = snd_hda_query_pin_caps(codec, nid);
2835 if (pincap & AC_PINCAP_OUT)
2836 return nid;
2837 }
2838 }
Matt Porter403d1942005-11-29 15:00:51 +01002839 return 0;
2840}
2841
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002842static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid);
2843
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002844/* check whether the mic-input can be used as line-out */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002845static hda_nid_t check_mic_out_switch(struct hda_codec *codec, hda_nid_t *dac)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002846{
2847 struct sigmatel_spec *spec = codec->spec;
2848 struct auto_pin_cfg *cfg = &spec->autocfg;
2849 unsigned int def_conf, pincap;
Takashi Iwai86e29592010-09-09 14:50:17 +02002850 int i;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002851
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002852 *dac = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002853 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2854 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002855 for (i = 0; i < cfg->num_inputs; i++) {
2856 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai86e29592010-09-09 14:50:17 +02002857 if (cfg->inputs[i].type != AUTO_PIN_MIC)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002858 continue;
Takashi Iwai330ee992009-02-20 14:33:36 +01002859 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002860 /* some laptops have an internal analog microphone
2861 * which can't be used as a output */
Takashi Iwai99ae28b2010-09-17 14:42:34 +02002862 if (snd_hda_get_input_pin_attr(def_conf) != INPUT_PIN_ATTR_INT) {
Takashi Iwai1327a322009-03-23 13:07:47 +01002863 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002864 if (pincap & AC_PINCAP_OUT) {
2865 *dac = get_unassigned_dac(codec, nid);
2866 if (*dac)
2867 return nid;
2868 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002869 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02002870 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002871 return 0;
2872}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002873
2874static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2875{
2876 int i;
2877
2878 for (i = 0; i < spec->multiout.num_dacs; i++) {
2879 if (spec->multiout.dac_nids[i] == nid)
2880 return 1;
2881 }
2882
2883 return 0;
2884}
2885
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002886static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2887{
2888 int i;
2889 if (is_in_dac_nids(spec, nid))
2890 return 1;
2891 for (i = 0; i < spec->autocfg.hp_outs; i++)
2892 if (spec->hp_dacs[i] == nid)
2893 return 1;
2894 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2895 if (spec->speaker_dacs[i] == nid)
2896 return 1;
2897 return 0;
2898}
2899
2900static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2901{
2902 struct sigmatel_spec *spec = codec->spec;
2903 int j, conn_len;
2904 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2905 unsigned int wcaps, wtype;
2906
2907 conn_len = snd_hda_get_connections(codec, nid, conn,
2908 HDA_MAX_CONNECTIONS);
Charles Chin36706002010-01-29 12:05:51 +01002909 /* 92HD88: trace back up the link of nids to find the DAC */
2910 while (conn_len == 1 && (get_wcaps_type(get_wcaps(codec, conn[0]))
2911 != AC_WID_AUD_OUT)) {
2912 nid = conn[0];
2913 conn_len = snd_hda_get_connections(codec, nid, conn,
2914 HDA_MAX_CONNECTIONS);
2915 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002916 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01002917 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02002918 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002919 /* we check only analog outputs */
2920 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2921 continue;
2922 /* if this route has a free DAC, assign it */
2923 if (!check_all_dac_nids(spec, conn[j])) {
2924 if (conn_len > 1) {
2925 /* select this DAC in the pin's input mux */
2926 snd_hda_codec_write_cache(codec, nid, 0,
2927 AC_VERB_SET_CONNECT_SEL, j);
2928 }
2929 return conn[j];
2930 }
2931 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01002932 /* if all DACs are already assigned, connect to the primary DAC */
2933 if (conn_len > 1) {
2934 for (j = 0; j < conn_len; j++) {
2935 if (conn[j] == spec->multiout.dac_nids[0]) {
2936 snd_hda_codec_write_cache(codec, nid, 0,
2937 AC_VERB_SET_CONNECT_SEL, j);
2938 break;
2939 }
2940 }
2941 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002942 return 0;
2943}
2944
2945static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2946static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2947
Matt Porter3cc08dc2006-01-23 15:27:49 +01002948/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002949 * Fill in the dac_nids table from the parsed pin configuration
2950 * This function only works when every pin in line_out_pins[]
2951 * contains atleast one DAC in its connection list. Some 92xx
2952 * codecs are not connected directly to a DAC, such as the 9200
2953 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002954 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002955static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002956{
2957 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002958 struct auto_pin_cfg *cfg = &spec->autocfg;
2959 int i;
2960 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002961
Mattc7d4b2f2005-06-27 14:59:41 +02002962 for (i = 0; i < cfg->line_outs; i++) {
2963 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002964 dac = get_unassigned_dac(codec, nid);
2965 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002966 if (spec->multiout.num_dacs > 0) {
2967 /* we have already working output pins,
2968 * so let's drop the broken ones again
2969 */
2970 cfg->line_outs = spec->multiout.num_dacs;
2971 break;
2972 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002973 /* error out, no available DAC found */
2974 snd_printk(KERN_ERR
2975 "%s: No available DAC for pin 0x%x\n",
2976 __func__, nid);
2977 return -ENODEV;
2978 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002979 add_spec_dacs(spec, dac);
2980 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002981
Takashi Iwai139e0712009-03-06 12:10:41 +01002982 for (i = 0; i < cfg->hp_outs; i++) {
2983 nid = cfg->hp_pins[i];
2984 dac = get_unassigned_dac(codec, nid);
2985 if (dac) {
2986 if (!spec->multiout.hp_nid)
2987 spec->multiout.hp_nid = dac;
2988 else
2989 add_spec_extra_dacs(spec, dac);
2990 }
2991 spec->hp_dacs[i] = dac;
2992 }
2993
2994 for (i = 0; i < cfg->speaker_outs; i++) {
2995 nid = cfg->speaker_pins[i];
2996 dac = get_unassigned_dac(codec, nid);
2997 if (dac)
2998 add_spec_extra_dacs(spec, dac);
2999 spec->speaker_dacs[i] = dac;
3000 }
3001
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003002 /* add line-in as output */
3003 nid = check_line_out_switch(codec);
3004 if (nid) {
3005 dac = get_unassigned_dac(codec, nid);
3006 if (dac) {
3007 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3008 nid, cfg->line_outs);
3009 cfg->line_out_pins[cfg->line_outs] = nid;
3010 cfg->line_outs++;
3011 spec->line_switch = nid;
3012 add_spec_dacs(spec, dac);
3013 }
3014 }
3015 /* add mic as output */
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003016 nid = check_mic_out_switch(codec, &dac);
3017 if (nid && dac) {
3018 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3019 nid, cfg->line_outs);
3020 cfg->line_out_pins[cfg->line_outs] = nid;
3021 cfg->line_outs++;
3022 spec->mic_switch = nid;
3023 add_spec_dacs(spec, dac);
Mattc7d4b2f2005-06-27 14:59:41 +02003024 }
3025
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003026 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003027 spec->multiout.num_dacs,
3028 spec->multiout.dac_nids[0],
3029 spec->multiout.dac_nids[1],
3030 spec->multiout.dac_nids[2],
3031 spec->multiout.dac_nids[3],
3032 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003033
Mattc7d4b2f2005-06-27 14:59:41 +02003034 return 0;
3035}
3036
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003037/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003038static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3039 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003040{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003041 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003042 char name[32];
3043 int err;
3044
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003045 if (!spec->check_volume_offset) {
3046 unsigned int caps, step, nums, db_scale;
3047 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3048 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3049 AC_AMPCAP_STEP_SIZE_SHIFT;
3050 step = (step + 1) * 25; /* in .01dB unit */
3051 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3052 AC_AMPCAP_NUM_STEPS_SHIFT;
3053 db_scale = nums * step;
3054 /* if dB scale is over -64dB, and finer enough,
3055 * let's reduce it to half
3056 */
3057 if (db_scale > 6400 && nums >= 0x1f)
3058 spec->volume_offset = nums / 2;
3059 spec->check_volume_offset = 1;
3060 }
3061
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003062 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003063 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003064 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3065 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003066 if (err < 0)
3067 return err;
3068 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003069 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003070 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3071 if (err < 0)
3072 return err;
3073 return 0;
3074}
3075
Takashi Iwai668b9652009-03-06 10:13:24 +01003076#define create_controls(codec, pfx, nid, chs) \
3077 create_controls_idx(codec, pfx, 0, nid, chs)
3078
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003079static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3080{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003081 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003082 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3083 return 1;
3084 } else {
3085 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3086 spec->multiout.num_dacs++;
3087 }
3088 return 0;
3089}
3090
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003091static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003092{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003093 int i;
3094 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3095 if (!spec->multiout.extra_out_nid[i]) {
3096 spec->multiout.extra_out_nid[i] = nid;
3097 return 0;
3098 }
3099 }
3100 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3101 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003102}
3103
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003104/* Create output controls
3105 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3106 */
3107static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3108 const hda_nid_t *pins,
3109 const hda_nid_t *dac_nids,
3110 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003111{
Takashi Iwai76624532008-12-19 10:09:47 +01003112 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003113 static const char *chname[4] = {
3114 "Front", "Surround", NULL /*CLFE*/, "Side"
3115 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003116 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003117 int i, err;
3118 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003119
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003120 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003121 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3122 wid_caps = get_wcaps(codec, pins[i]);
3123 if (wid_caps & AC_WCAP_UNSOL_CAP)
3124 spec->hp_detect = 1;
3125 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003126 nid = dac_nids[i];
3127 if (!nid)
3128 continue;
3129 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003130 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003131 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003132 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003133 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003134 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003135 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003136 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003137
3138 wid_caps = get_wcaps(codec, nid);
3139
3140 if (wid_caps & AC_WCAP_LR_SWAP) {
3141 err = stac92xx_add_control(spec,
3142 STAC_CTL_WIDGET_CLFE_SWITCH,
3143 "Swap Center/LFE Playback Switch", nid);
3144
3145 if (err < 0)
3146 return err;
3147 }
3148
Mattc7d4b2f2005-06-27 14:59:41 +02003149 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003150 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003151 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003152 switch (type) {
3153 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003154 name = "Headphone";
3155 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003156 break;
3157 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003158 name = "Speaker";
3159 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003160 break;
3161 default:
3162 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003163 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003164 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003165 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003166 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003167 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003168 return err;
3169 }
3170 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003171 return 0;
3172}
3173
Takashi Iwai6479c632009-07-28 18:20:25 +02003174static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3175 unsigned long sw, int idx)
3176{
3177 int err;
3178 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003179 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003180 if (err < 0)
3181 return err;
3182 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003183 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003184 if (err < 0)
3185 return err;
3186 return 0;
3187}
3188
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003189/* add playback controls from the parsed DAC table */
3190static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3191 const struct auto_pin_cfg *cfg)
3192{
3193 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003194 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003195 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003196 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003197
3198 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3199 spec->multiout.dac_nids,
3200 cfg->line_out_type);
3201 if (err < 0)
3202 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003203
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003204 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003205 err = stac92xx_add_control(spec,
3206 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003207 "Headphone as Line Out Switch",
3208 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003209 if (err < 0)
3210 return err;
3211 }
3212
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003213 for (idx = 0; idx < cfg->num_inputs; idx++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003214 if (cfg->inputs[idx].type > AUTO_PIN_LINE_IN)
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003215 break;
3216 nid = cfg->inputs[idx].pin;
3217 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3218 if (err < 0)
3219 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003220 }
Matt Porter403d1942005-11-29 15:00:51 +01003221
Mattc7d4b2f2005-06-27 14:59:41 +02003222 return 0;
3223}
3224
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003225/* add playback controls for Speaker and HP outputs */
3226static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3227 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003228{
3229 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003230 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003231
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003232 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3233 spec->hp_dacs, AUTO_PIN_HP_OUT);
3234 if (err < 0)
3235 return err;
3236
3237 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3238 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3239 if (err < 0)
3240 return err;
3241
Mattc7d4b2f2005-06-27 14:59:41 +02003242 return 0;
3243}
3244
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003245/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003246static const char *stac92xx_mono_labels[4] = {
3247 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003248};
3249
3250/* create mono mux for mono out on capable codecs */
3251static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3252{
3253 struct sigmatel_spec *spec = codec->spec;
3254 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3255 int i, num_cons;
3256 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3257
3258 num_cons = snd_hda_get_connections(codec,
3259 spec->mono_nid,
3260 con_lst,
3261 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003262 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003263 return -EINVAL;
3264
Takashi Iwai10a20af2010-09-09 16:28:02 +02003265 for (i = 0; i < num_cons; i++)
3266 snd_hda_add_imux_item(mono_mux, stac92xx_mono_labels[i], i,
3267 NULL);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003268
3269 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3270 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003271}
3272
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003273/* create PC beep volume controls */
3274static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3275 hda_nid_t nid)
3276{
3277 struct sigmatel_spec *spec = codec->spec;
3278 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003279 int err, type = STAC_CTL_WIDGET_MUTE_BEEP;
3280
3281 if (spec->anabeep_nid == nid)
3282 type = STAC_CTL_WIDGET_MUTE;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003283
3284 /* check for mute support for the the amp */
3285 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003286 err = stac92xx_add_control(spec, type,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003287 "Beep Playback Switch",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003288 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3289 if (err < 0)
3290 return err;
3291 }
3292
3293 /* check to see if there is volume support for the amp */
3294 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3295 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003296 "Beep Playback Volume",
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003297 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3298 if (err < 0)
3299 return err;
3300 }
3301 return 0;
3302}
3303
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003304#ifdef CONFIG_SND_HDA_INPUT_BEEP
3305#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3306
3307static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3308 struct snd_ctl_elem_value *ucontrol)
3309{
3310 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3311 ucontrol->value.integer.value[0] = codec->beep->enabled;
3312 return 0;
3313}
3314
3315static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3316 struct snd_ctl_elem_value *ucontrol)
3317{
3318 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02003319 return snd_hda_enable_beep_device(codec, ucontrol->value.integer.value[0]);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003320}
3321
3322static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3323 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3324 .info = stac92xx_dig_beep_switch_info,
3325 .get = stac92xx_dig_beep_switch_get,
3326 .put = stac92xx_dig_beep_switch_put,
3327};
3328
3329static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3330{
3331 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
Jaroslav Kyselad355c82a2009-11-03 15:47:25 +01003332 0, "Beep Playback Switch", 0);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003333}
3334#endif
3335
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003336static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3337{
3338 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003339 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003340
3341 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003342 hda_nid_t nid;
3343 unsigned int wcaps;
3344 unsigned long val;
3345
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003346 nid = spec->mux_nids[i];
3347 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003348 if (!(wcaps & AC_WCAP_OUT_AMP))
3349 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003350
Takashi Iwai667067d2009-08-13 18:14:42 +02003351 /* check whether already the same control was created as
3352 * normal Capture Volume.
3353 */
3354 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3355 for (j = 0; j < spec->num_caps; j++) {
3356 if (spec->capvols[j] == val)
3357 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003358 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003359 if (j < spec->num_caps)
3360 continue;
3361
3362 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3363 "Mux Capture Volume", val);
3364 if (err < 0)
3365 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003366 }
3367 return 0;
3368};
3369
Matthew Ranostayd9737752008-09-07 12:03:41 +02003370static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003371 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003372};
3373
3374static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3375{
3376 struct sigmatel_spec *spec = codec->spec;
3377 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003378 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003379 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003380 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003381
3382 num_cons = snd_hda_get_connections(codec,
3383 spec->smux_nids[0],
3384 con_lst,
3385 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003386 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003387 return -EINVAL;
3388
Matthew Ranostay65973632008-09-16 10:39:37 -04003389 if (!labels)
3390 labels = stac92xx_spdif_labels;
3391
Takashi Iwai10a20af2010-09-09 16:28:02 +02003392 for (i = 0; i < num_cons; i++)
3393 snd_hda_add_imux_item(spdif_mux, labels[i], i, NULL);
Matthew Ranostayd9737752008-09-07 12:03:41 +02003394
3395 return 0;
3396}
3397
Matt Porter8b657272006-10-26 17:12:59 +02003398/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003399static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003400 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3401 "Digital Mic 3", "Digital Mic 4"
3402};
3403
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003404static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3405 hda_nid_t nid)
3406{
3407 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3408 int i, nums;
3409
3410 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3411 for (i = 0; i < nums; i++)
3412 if (conn[i] == nid)
3413 return i;
3414 return -1;
3415}
3416
Takashi Iwai667067d2009-08-13 18:14:42 +02003417/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003418/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003419static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003420 const char *label, int idx, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003421{
3422 unsigned int caps, nums;
3423 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003424 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003425
Takashi Iwai96f845d2009-08-29 00:49:36 +02003426 if (direction == HDA_OUTPUT)
3427 caps = AC_WCAP_OUT_AMP;
3428 else
3429 caps = AC_WCAP_IN_AMP;
3430 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003431 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003432 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003433 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3434 if (!nums)
3435 return 0;
3436 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003437 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx, name,
3438 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
Takashi Iwai96f845d2009-08-29 00:49:36 +02003439 if (err < 0)
3440 return err;
3441 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003442}
3443
Matt Porter8b657272006-10-26 17:12:59 +02003444/* create playback/capture controls for input pins on dmic capable codecs */
3445static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3446 const struct auto_pin_cfg *cfg)
3447{
3448 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003449 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003450 struct hda_input_mux *dimux = &spec->private_dimux;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003451 int err, i;
Takashi Iwai5207e102009-07-30 13:09:08 +02003452 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003453
Takashi Iwai10a20af2010-09-09 16:28:02 +02003454 snd_hda_add_imux_item(dimux, stac92xx_dmic_labels[0], 0, NULL);
Matt Porter8b657272006-10-26 17:12:59 +02003455
3456 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003457 hda_nid_t nid;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003458 int index, type_idx;
Takashi Iwai5207e102009-07-30 13:09:08 +02003459 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003460
Takashi Iwai667067d2009-08-13 18:14:42 +02003461 nid = spec->dmic_nids[i];
3462 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3463 continue;
3464 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003465 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3466 continue;
3467
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003468 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3469 if (index < 0)
3470 continue;
3471
Takashi Iwai10a20af2010-09-09 16:28:02 +02003472 label = hda_get_input_pin_label(codec, nid, 1);
3473 snd_hda_add_imux_item(dimux, label, index, &type_idx);
Takashi Iwai5207e102009-07-30 13:09:08 +02003474
Takashi Iwai10a20af2010-09-09 16:28:02 +02003475 err = create_elem_capture_vol(codec, nid, label, type_idx,
3476 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003477 if (err < 0)
3478 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003479 if (!err) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02003480 err = create_elem_capture_vol(codec, nid, label,
3481 type_idx, HDA_OUTPUT);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003482 if (err < 0)
3483 return err;
3484 }
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003485
Vitaliy Kulikovf41cc2a2010-09-24 16:21:53 -05003486 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
Takashi Iwai10a20af2010-09-09 16:28:02 +02003487 snd_hda_add_imux_item(imux, label, index, NULL);
Vitaliy Kulikovf41cc2a2010-09-24 16:21:53 -05003488 spec->num_analog_muxes++;
3489 }
Matt Porter8b657272006-10-26 17:12:59 +02003490 }
3491
3492 return 0;
3493}
3494
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003495static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
Charles Chin99077902010-09-17 10:22:32 +02003496 hda_nid_t *fixed, hda_nid_t *ext, hda_nid_t *dock)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003497{
3498 unsigned int cfg;
3499
3500 if (!nid)
3501 return 0;
3502 cfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003503 switch (snd_hda_get_input_pin_attr(cfg)) {
3504 case INPUT_PIN_ATTR_INT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003505 if (*fixed)
3506 return 1; /* already occupied */
3507 *fixed = nid;
3508 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02003509 case INPUT_PIN_ATTR_UNUSED:
3510 break;
3511 case INPUT_PIN_ATTR_DOCK:
3512 if (*dock)
3513 return 1; /* already occupied */
3514 *dock = nid;
3515 break;
3516 default:
3517 if (*ext)
3518 return 1; /* already occupied */
3519 *ext = nid;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003520 break;
3521 }
3522 return 0;
3523}
3524
3525static int set_mic_route(struct hda_codec *codec,
3526 struct sigmatel_mic_route *mic,
3527 hda_nid_t pin)
3528{
3529 struct sigmatel_spec *spec = codec->spec;
3530 struct auto_pin_cfg *cfg = &spec->autocfg;
3531 int i;
3532
3533 mic->pin = pin;
Charles Chin99077902010-09-17 10:22:32 +02003534 if (pin == 0)
3535 return 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003536 for (i = 0; i < cfg->num_inputs; i++) {
3537 if (pin == cfg->inputs[i].pin)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003538 break;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003539 }
Takashi Iwai86e29592010-09-09 14:50:17 +02003540 if (i < cfg->num_inputs && cfg->inputs[i].type == AUTO_PIN_MIC) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003541 /* analog pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003542 i = get_connection_index(codec, spec->mux_nids[0], pin);
3543 if (i < 0)
3544 return -1;
3545 mic->mux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003546 mic->dmux_idx = -1;
3547 if (spec->dmux_nids)
3548 mic->dmux_idx = get_connection_index(codec,
3549 spec->dmux_nids[0],
3550 spec->mux_nids[0]);
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003551 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003552 /* digital pin */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003553 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3554 if (i < 0)
3555 return -1;
3556 mic->dmux_idx = i;
Takashi Iwai02d33322009-10-01 16:38:11 +02003557 mic->mux_idx = -1;
3558 if (spec->mux_nids)
3559 mic->mux_idx = get_connection_index(codec,
3560 spec->mux_nids[0],
3561 spec->dmux_nids[0]);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003562 }
3563 return 0;
3564}
3565
3566/* return non-zero if the device is for automatic mic switch */
3567static int stac_check_auto_mic(struct hda_codec *codec)
3568{
3569 struct sigmatel_spec *spec = codec->spec;
3570 struct auto_pin_cfg *cfg = &spec->autocfg;
Charles Chin99077902010-09-17 10:22:32 +02003571 hda_nid_t fixed, ext, dock;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003572 int i;
3573
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003574 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai86e29592010-09-09 14:50:17 +02003575 if (cfg->inputs[i].type >= AUTO_PIN_LINE_IN)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003576 return 0; /* must be exclusively mics */
3577 }
Charles Chin99077902010-09-17 10:22:32 +02003578 fixed = ext = dock = 0;
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003579 for (i = 0; i < cfg->num_inputs; i++)
Charles Chin99077902010-09-17 10:22:32 +02003580 if (check_mic_pin(codec, cfg->inputs[i].pin,
3581 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003582 return 0;
3583 for (i = 0; i < spec->num_dmics; i++)
Charles Chin99077902010-09-17 10:22:32 +02003584 if (check_mic_pin(codec, spec->dmic_nids[i],
3585 &fixed, &ext, &dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003586 return 0;
Charles Chin99077902010-09-17 10:22:32 +02003587 if (!fixed && !ext && !dock)
3588 return 0; /* no input to switch */
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003589 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3590 return 0; /* no unsol support */
3591 if (set_mic_route(codec, &spec->ext_mic, ext) ||
Charles Chin99077902010-09-17 10:22:32 +02003592 set_mic_route(codec, &spec->int_mic, fixed) ||
3593 set_mic_route(codec, &spec->dock_mic, dock))
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003594 return 0; /* something is wrong */
3595 return 1;
3596}
3597
Mattc7d4b2f2005-06-27 14:59:41 +02003598/* create playback/capture controls for input pins */
3599static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3600{
3601 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003602 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003603 int i, j;
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003604 const char *label;
Mattc7d4b2f2005-06-27 14:59:41 +02003605
Takashi Iwaieea7dc92010-08-30 13:06:15 +02003606 for (i = 0; i < cfg->num_inputs; i++) {
3607 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02003608 int index, err, type_idx;
Mattc7d4b2f2005-06-27 14:59:41 +02003609
Takashi Iwai314634b2006-09-21 11:56:18 +02003610 index = -1;
3611 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003612 index = get_connection_index(codec, spec->mux_nids[j],
3613 nid);
3614 if (index >= 0)
3615 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003616 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003617 if (index < 0)
3618 continue;
3619
Takashi Iwai10a20af2010-09-09 16:28:02 +02003620 label = hda_get_autocfg_input_label(codec, cfg, i);
3621 snd_hda_add_imux_item(imux, label, index, &type_idx);
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003622
Takashi Iwai667067d2009-08-13 18:14:42 +02003623 err = create_elem_capture_vol(codec, nid,
Vitaliy Kulikov263d0322010-09-08 08:56:03 +02003624 label, type_idx,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003625 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003626 if (err < 0)
3627 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003628 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003629 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003630
Steve Longerbeam7b043892007-05-03 20:50:03 +02003631 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003632 /*
3633 * Set the current input for the muxes.
3634 * The STAC9221 has two input muxes with identical source
3635 * NID lists. Hopefully this won't get confused.
3636 */
3637 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003638 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3639 AC_VERB_SET_CONNECT_SEL,
3640 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003641 }
3642 }
3643
Mattc7d4b2f2005-06-27 14:59:41 +02003644 return 0;
3645}
3646
Mattc7d4b2f2005-06-27 14:59:41 +02003647static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3648{
3649 struct sigmatel_spec *spec = codec->spec;
3650 int i;
3651
3652 for (i = 0; i < spec->autocfg.line_outs; i++) {
3653 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3654 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3655 }
3656}
3657
3658static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3659{
3660 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003661 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003662
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003663 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3664 hda_nid_t pin;
3665 pin = spec->autocfg.hp_pins[i];
3666 if (pin) /* connect to front */
3667 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3668 }
3669 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3670 hda_nid_t pin;
3671 pin = spec->autocfg.speaker_pins[i];
3672 if (pin) /* connect to front */
3673 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3674 }
Mattc7d4b2f2005-06-27 14:59:41 +02003675}
3676
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003677static int is_dual_headphones(struct hda_codec *codec)
3678{
3679 struct sigmatel_spec *spec = codec->spec;
3680 int i, valid_hps;
3681
3682 if (spec->autocfg.line_out_type != AUTO_PIN_SPEAKER_OUT ||
3683 spec->autocfg.hp_outs <= 1)
3684 return 0;
3685 valid_hps = 0;
3686 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3687 hda_nid_t nid = spec->autocfg.hp_pins[i];
3688 unsigned int cfg = snd_hda_codec_get_pincfg(codec, nid);
3689 if (get_defcfg_location(cfg) & AC_JACK_LOC_SEPARATE)
3690 continue;
3691 valid_hps++;
3692 }
3693 return (valid_hps > 1);
3694}
3695
3696
Matt Porter3cc08dc2006-01-23 15:27:49 +01003697static 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 +02003698{
3699 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003700 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003701 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003702
Matt Porter8b657272006-10-26 17:12:59 +02003703 if ((err = snd_hda_parse_pin_def_config(codec,
3704 &spec->autocfg,
3705 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003706 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003707 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003708 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003709
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003710 /* If we have no real line-out pin and multiple hp-outs, HPs should
3711 * be set up as multi-channel outputs.
3712 */
Takashi Iwai8af3aeb2009-11-18 14:23:37 +01003713 if (is_dual_headphones(codec)) {
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003714 /* Copy hp_outs to line_outs, backup line_outs in
3715 * speaker_outs so that the following routines can handle
3716 * HP pins as primary outputs.
3717 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003718 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003719 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3720 sizeof(spec->autocfg.line_out_pins));
3721 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3722 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3723 sizeof(spec->autocfg.hp_pins));
3724 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003725 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3726 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003727 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003728 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003729 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003730 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3731 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003732 u32 caps = query_amp_caps(codec,
3733 spec->autocfg.mono_out_pin, dir);
3734 hda_nid_t conn_list[1];
3735
3736 /* get the mixer node and then the mono mux if it exists */
3737 if (snd_hda_get_connections(codec,
3738 spec->autocfg.mono_out_pin, conn_list, 1) &&
3739 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003740 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003741
3742 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003743 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003744 /* LR swap check, some stac925x have a mux that
3745 * changes the DACs output path instead of the
3746 * mono-mux path.
3747 */
3748 if (wid_type == AC_WID_AUD_SEL &&
3749 !(wcaps & AC_WCAP_LR_SWAP))
3750 spec->mono_nid = conn_list[0];
3751 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003752 if (dir) {
3753 hda_nid_t nid = spec->autocfg.mono_out_pin;
3754
3755 /* most mono outs have a least a mute/unmute switch */
3756 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3757 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3758 "Mono Playback Switch",
3759 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003760 if (err < 0)
3761 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003762 /* check for volume support for the amp */
3763 if ((caps & AC_AMPCAP_NUM_STEPS)
3764 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3765 err = stac92xx_add_control(spec,
3766 STAC_CTL_WIDGET_VOL,
3767 "Mono Playback Volume",
3768 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3769 if (err < 0)
3770 return err;
3771 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003772 }
3773
3774 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3775 AC_PINCTL_OUT_EN);
3776 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003777
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003778 if (!spec->multiout.num_dacs) {
3779 err = stac92xx_auto_fill_dac_nids(codec);
3780 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003781 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003782 err = stac92xx_auto_create_multi_out_ctls(codec,
3783 &spec->autocfg);
3784 if (err < 0)
3785 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003786 }
Mattc7d4b2f2005-06-27 14:59:41 +02003787
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003788 /* setup analog beep controls */
3789 if (spec->anabeep_nid > 0) {
3790 err = stac92xx_auto_create_beep_ctls(codec,
3791 spec->anabeep_nid);
3792 if (err < 0)
3793 return err;
3794 }
3795
3796 /* setup digital beep controls and input device */
3797#ifdef CONFIG_SND_HDA_INPUT_BEEP
3798 if (spec->digbeep_nid > 0) {
3799 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003800 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003801
3802 err = stac92xx_auto_create_beep_ctls(codec, nid);
3803 if (err < 0)
3804 return err;
3805 err = snd_hda_attach_beep_device(codec, nid);
3806 if (err < 0)
3807 return err;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003808 if (codec->beep) {
3809 /* IDT/STAC codecs have linear beep tone parameter */
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01003810 codec->beep->linear_tone = spec->linear_tone_beep;
Takashi Iwaid8d881d2009-12-22 07:52:49 +01003811 /* if no beep switch is available, make its own one */
3812 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3813 if (!(caps & AC_AMPCAP_MUTE)) {
3814 err = stac92xx_beep_switch_ctl(codec);
3815 if (err < 0)
3816 return err;
3817 }
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003818 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003819 }
3820#endif
3821
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003822 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003823 if (err < 0)
3824 return err;
3825
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003826 /* All output parsing done, now restore the swapped hp pins */
3827 if (hp_swap) {
3828 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3829 sizeof(spec->autocfg.hp_pins));
3830 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3831 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3832 spec->autocfg.line_outs = 0;
3833 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003834
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003835 if (stac_check_auto_mic(codec)) {
3836 spec->auto_mic = 1;
3837 /* only one capture for auto-mic */
3838 spec->num_adcs = 1;
3839 spec->num_caps = 1;
3840 spec->num_muxes = 1;
3841 }
3842
Takashi Iwai6479c632009-07-28 18:20:25 +02003843 for (i = 0; i < spec->num_caps; i++) {
3844 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3845 spec->capsws[i], i);
3846 if (err < 0)
3847 return err;
3848 }
3849
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003850 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003851 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003852 return err;
3853
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003854 if (spec->mono_nid > 0) {
3855 err = stac92xx_auto_create_mono_output_ctls(codec);
3856 if (err < 0)
3857 return err;
3858 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003859 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003860 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3861 &spec->autocfg)) < 0)
3862 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003863 if (spec->num_muxes > 0) {
3864 err = stac92xx_auto_create_mux_input_ctls(codec);
3865 if (err < 0)
3866 return err;
3867 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003868 if (spec->num_smuxes > 0) {
3869 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3870 if (err < 0)
3871 return err;
3872 }
Matt Porter8b657272006-10-26 17:12:59 +02003873
Takashi Iwaie3c75962009-01-23 11:57:22 +01003874 err = stac92xx_add_input_source(spec);
3875 if (err < 0)
3876 return err;
3877
Mattc7d4b2f2005-06-27 14:59:41 +02003878 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003879 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003880 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003881
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003882 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003883 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003884 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003885 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003886
Takashi Iwai603c4012008-07-30 15:01:44 +02003887 if (spec->kctls.list)
3888 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003889
3890 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003891 if (!spec->dinput_mux)
3892 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003893 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003894 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003895 return 1;
3896}
3897
Takashi Iwai82bc9552006-03-21 11:24:42 +01003898/* add playback controls for HP output */
3899static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3900 struct auto_pin_cfg *cfg)
3901{
3902 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003903 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003904 unsigned int wid_caps;
3905
3906 if (! pin)
3907 return 0;
3908
3909 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003910 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003911 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003912
3913 return 0;
3914}
3915
Richard Fish160ea0d2006-09-06 13:58:25 +02003916/* add playback controls for LFE output */
3917static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3918 struct auto_pin_cfg *cfg)
3919{
3920 struct sigmatel_spec *spec = codec->spec;
3921 int err;
3922 hda_nid_t lfe_pin = 0x0;
3923 int i;
3924
3925 /*
3926 * search speaker outs and line outs for a mono speaker pin
3927 * with an amp. If one is found, add LFE controls
3928 * for it.
3929 */
3930 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3931 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003932 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003933 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3934 if (wcaps == AC_WCAP_OUT_AMP)
3935 /* found a mono speaker with an amp, must be lfe */
3936 lfe_pin = pin;
3937 }
3938
3939 /* if speaker_outs is 0, then speakers may be in line_outs */
3940 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3941 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3942 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003943 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01003944 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01003945 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003946 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003947 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3948 if (wcaps == AC_WCAP_OUT_AMP)
3949 /* found a mono speaker with an amp,
3950 must be lfe */
3951 lfe_pin = pin;
3952 }
3953 }
3954 }
3955
3956 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003957 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003958 if (err < 0)
3959 return err;
3960 }
3961
3962 return 0;
3963}
3964
Mattc7d4b2f2005-06-27 14:59:41 +02003965static int stac9200_parse_auto_config(struct hda_codec *codec)
3966{
3967 struct sigmatel_spec *spec = codec->spec;
3968 int err;
3969
Kailang Yangdf694da2005-12-05 19:42:22 +01003970 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003971 return err;
3972
3973 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3974 return err;
3975
Takashi Iwai82bc9552006-03-21 11:24:42 +01003976 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3977 return err;
3978
Richard Fish160ea0d2006-09-06 13:58:25 +02003979 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3980 return err;
3981
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003982 if (spec->num_muxes > 0) {
3983 err = stac92xx_auto_create_mux_input_ctls(codec);
3984 if (err < 0)
3985 return err;
3986 }
3987
Takashi Iwaie3c75962009-01-23 11:57:22 +01003988 err = stac92xx_add_input_source(spec);
3989 if (err < 0)
3990 return err;
3991
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003992 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02003993 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003994 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003995 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003996
Takashi Iwai603c4012008-07-30 15:01:44 +02003997 if (spec->kctls.list)
3998 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003999
4000 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004001 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004002
4003 return 1;
4004}
4005
Sam Revitch62fe78e2006-05-10 15:09:17 +02004006/*
4007 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4008 * funky external mute control using GPIO pins.
4009 */
4010
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004011static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004012 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004013{
4014 unsigned int gpiostate, gpiomask, gpiodir;
4015
4016 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4017 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004018 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004019
4020 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4021 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004022 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004023
4024 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4025 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004026 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004027
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004028 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004029 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4030
4031 snd_hda_codec_write(codec, codec->afg, 0,
4032 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004033 snd_hda_codec_read(codec, codec->afg, 0,
4034 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004035
4036 msleep(1);
4037
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004038 snd_hda_codec_read(codec, codec->afg, 0,
4039 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004040}
4041
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004042#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +02004043static void stac92xx_free_jack_priv(struct snd_jack *jack)
4044{
4045 struct sigmatel_jack *jacks = jack->private_data;
4046 jacks->nid = 0;
4047 jacks->jack = NULL;
4048}
4049#endif
4050
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004051static int stac92xx_add_jack(struct hda_codec *codec,
4052 hda_nid_t nid, int type)
4053{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004054#ifdef CONFIG_SND_HDA_INPUT_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004055 struct sigmatel_spec *spec = codec->spec;
4056 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01004057 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004058 int connectivity = get_defcfg_connect(def_conf);
4059 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02004060 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004061
4062 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4063 return 0;
4064
4065 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4066 jack = snd_array_new(&spec->jacks);
4067 if (!jack)
4068 return -ENOMEM;
4069 jack->nid = nid;
4070 jack->type = type;
4071
Takashi Iwai86de7412009-07-22 16:02:46 +02004072 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004073 snd_hda_get_jack_type(def_conf),
4074 snd_hda_get_jack_connectivity(def_conf),
4075 snd_hda_get_jack_location(def_conf));
4076
Takashi Iwai95c09092009-04-14 16:15:29 +02004077 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4078 if (err < 0) {
4079 jack->nid = 0;
4080 return err;
4081 }
4082 jack->jack->private_data = jack;
4083 jack->jack->private_free = stac92xx_free_jack_priv;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004084#endif
Takashi Iwai95c09092009-04-14 16:15:29 +02004085 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004086}
4087
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004088static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4089 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004090{
4091 struct sigmatel_event *event;
4092
4093 snd_array_init(&spec->events, sizeof(*event), 32);
4094 event = snd_array_new(&spec->events);
4095 if (!event)
4096 return -ENOMEM;
4097 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004098 event->type = type;
4099 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004100 event->data = data;
4101
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004102 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004103}
4104
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004105static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004106 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004107{
4108 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004109 struct sigmatel_event *event = spec->events.list;
4110 int i;
4111
4112 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004113 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004114 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004115 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004116 return NULL;
4117}
4118
4119static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4120 unsigned char tag)
4121{
4122 struct sigmatel_spec *spec = codec->spec;
4123 struct sigmatel_event *event = spec->events.list;
4124 int i;
4125
4126 for (i = 0; i < spec->events.used; i++, event++) {
4127 if (event->tag == tag)
4128 return event;
4129 }
4130 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004131}
4132
Takashi Iwai62558ce2009-07-29 14:23:09 +02004133/* check if given nid is a valid pin and no other events are assigned
4134 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4135 * Otherwise, returns zero.
4136 */
4137static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4138 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004139{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004140 struct sigmatel_event *event;
4141 int tag;
4142
4143 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004144 return 0;
4145 event = stac_get_event(codec, nid);
4146 if (event) {
4147 if (event->type != type)
4148 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004149 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004150 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004151 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004152 if (tag < 0)
4153 return 0;
4154 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004155 snd_hda_codec_write_cache(codec, nid, 0,
4156 AC_VERB_SET_UNSOLICITED_ENABLE,
4157 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004158 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004159}
4160
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004161static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4162{
4163 int i;
4164 for (i = 0; i < cfg->hp_outs; i++)
4165 if (cfg->hp_pins[i] == nid)
4166 return 1; /* nid is a HP-Out */
4167
4168 return 0; /* nid is not a HP-Out */
4169};
4170
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004171static void stac92xx_power_down(struct hda_codec *codec)
4172{
4173 struct sigmatel_spec *spec = codec->spec;
4174
4175 /* power down inactive DACs */
4176 hda_nid_t *dac;
4177 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004178 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004179 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004180 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4181}
4182
Takashi Iwaif73d3582008-11-25 08:21:51 +01004183static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4184 int enable);
4185
Takashi Iwai014c41f2009-12-27 13:53:24 +01004186static inline int get_int_hint(struct hda_codec *codec, const char *key,
4187 int *valp)
4188{
4189 const char *p;
4190 p = snd_hda_get_hint(codec, key);
4191 if (p) {
4192 unsigned long val;
4193 if (!strict_strtoul(p, 0, &val)) {
4194 *valp = val;
4195 return 1;
4196 }
4197 }
4198 return 0;
4199}
4200
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004201/* override some hints from the hwdep entry */
4202static void stac_store_hints(struct hda_codec *codec)
4203{
4204 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004205 int val;
4206
4207 val = snd_hda_get_bool_hint(codec, "hp_detect");
4208 if (val >= 0)
4209 spec->hp_detect = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004210 if (get_int_hint(codec, "gpio_mask", &spec->gpio_mask)) {
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004211 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4212 spec->gpio_mask;
4213 }
Takashi Iwai014c41f2009-12-27 13:53:24 +01004214 if (get_int_hint(codec, "gpio_dir", &spec->gpio_dir))
4215 spec->gpio_mask &= spec->gpio_mask;
4216 if (get_int_hint(codec, "gpio_data", &spec->gpio_data))
4217 spec->gpio_dir &= spec->gpio_mask;
4218 if (get_int_hint(codec, "eapd_mask", &spec->eapd_mask))
4219 spec->eapd_mask &= spec->gpio_mask;
4220 if (get_int_hint(codec, "gpio_mute", &spec->gpio_mute))
4221 spec->gpio_mute &= spec->gpio_mask;
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004222 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4223 if (val >= 0)
4224 spec->eapd_switch = val;
Takashi Iwai014c41f2009-12-27 13:53:24 +01004225 get_int_hint(codec, "gpio_led_polarity", &spec->gpio_led_polarity);
4226 if (get_int_hint(codec, "gpio_led", &spec->gpio_led)) {
Takashi Iwai043958e2009-12-26 10:36:12 +01004227 spec->gpio_mask |= spec->gpio_led;
4228 spec->gpio_dir |= spec->gpio_led;
4229 if (spec->gpio_led_polarity)
4230 spec->gpio_data |= spec->gpio_led;
4231 }
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004232}
4233
Mattc7d4b2f2005-06-27 14:59:41 +02004234static int stac92xx_init(struct hda_codec *codec)
4235{
4236 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004237 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004238 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004239 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004240
Mattc7d4b2f2005-06-27 14:59:41 +02004241 snd_hda_sequence_write(codec, spec->init);
4242
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004243 /* power down adcs initially */
4244 if (spec->powerdown_adcs)
4245 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004246 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004247 spec->adc_nids[i], 0,
4248 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004249
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004250 /* override some hints */
4251 stac_store_hints(codec);
4252
Takashi Iwaif73d3582008-11-25 08:21:51 +01004253 /* set up GPIO */
4254 gpio = spec->gpio_data;
4255 /* turn on EAPD statically when spec->eapd_switch isn't set.
4256 * otherwise, unsol event will turn it on/off dynamically
4257 */
4258 if (!spec->eapd_switch)
4259 gpio |= spec->eapd_mask;
4260 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4261
Takashi Iwai82bc9552006-03-21 11:24:42 +01004262 /* set up pins */
4263 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004264 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004265 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004266 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004267 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004268 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004269 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4270 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004271 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004272 for (i = 0; i < cfg->line_outs; i++) {
4273 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004274 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4275 }
4276 }
4277
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004278 /* force to enable the first line-out; the others are set up
4279 * in unsol_event
4280 */
4281 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004282 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004283 /* fake event to set up pins */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004284 if (cfg->hp_pins[0])
4285 stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4286 else if (cfg->line_out_pins[0])
4287 stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004288 } else {
4289 stac92xx_auto_init_multi_out(codec);
4290 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004291 for (i = 0; i < cfg->hp_outs; i++)
4292 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004293 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004294 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004295 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004296 if (spec->dmux_nids)
4297 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004298 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004299 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4300 stac_issue_unsol_event(codec, spec->ext_mic.pin);
Charles Chin99077902010-09-17 10:22:32 +02004301 if (enable_pin_detect(codec, spec->dock_mic.pin,
4302 STAC_MIC_EVENT))
4303 stac_issue_unsol_event(codec, spec->dock_mic.pin);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004304 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004305 for (i = 0; i < cfg->num_inputs; i++) {
4306 hda_nid_t nid = cfg->inputs[i].pin;
4307 int type = cfg->inputs[i].type;
4308 unsigned int pinctl, conf;
Takashi Iwai86e29592010-09-09 14:50:17 +02004309 if (type == AUTO_PIN_MIC) {
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004310 /* for mic pins, force to initialize */
4311 pinctl = stac92xx_get_default_vref(codec, nid);
4312 pinctl |= AC_PINCTL_IN_EN;
4313 stac92xx_auto_set_pinctl(codec, nid, pinctl);
4314 } else {
4315 pinctl = snd_hda_codec_read(codec, nid, 0,
4316 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4317 /* if PINCTL already set then skip */
4318 /* Also, if both INPUT and OUTPUT are set,
4319 * it must be a BIOS bug; need to override, too
4320 */
4321 if (!(pinctl & AC_PINCTL_IN_EN) ||
4322 (pinctl & AC_PINCTL_OUT_EN)) {
4323 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004324 pinctl |= AC_PINCTL_IN_EN;
4325 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004326 }
Takashi Iwaieea7dc92010-08-30 13:06:15 +02004327 }
4328 conf = snd_hda_codec_get_pincfg(codec, nid);
4329 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4330 if (enable_pin_detect(codec, nid, STAC_INSERT_EVENT))
4331 stac_issue_unsol_event(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01004332 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004333 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004334 for (i = 0; i < spec->num_dmics; i++)
4335 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4336 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004337 if (cfg->dig_out_pins[0])
4338 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004339 AC_PINCTL_OUT_EN);
4340 if (cfg->dig_in_pin)
4341 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4342 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004343 for (i = 0; i < spec->num_pwrs; i++) {
4344 hda_nid_t nid = spec->pwr_nids[i];
4345 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004346
Takashi Iwaieb632122008-12-19 16:39:48 +01004347 /* power on when no jack detection is available */
4348 if (!spec->hp_detect) {
4349 stac_toggle_power_map(codec, nid, 1);
4350 continue;
4351 }
4352
4353 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004354 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004355
Takashi Iwaif73d3582008-11-25 08:21:51 +01004356 pinctl = snd_hda_codec_read(codec, nid, 0,
4357 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4358 /* outputs are only ports capable of power management
4359 * any attempts on powering down a input port cause the
4360 * referenced VREF to act quirky.
4361 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004362 if (pinctl & AC_PINCTL_IN_EN) {
4363 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004364 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004365 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004366 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004367 def_conf = get_defcfg_connect(def_conf);
4368 /* skip any ports that don't have jacks since presence
4369 * detection is useless */
4370 if (def_conf != AC_JACK_PORT_COMPLEX) {
4371 if (def_conf != AC_JACK_PORT_NONE)
4372 stac_toggle_power_map(codec, nid, 1);
4373 continue;
4374 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004375 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4376 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004377 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004378
Takashi Iwaic21bd022010-02-08 15:16:08 +01004379 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004380 if (spec->gpio_led)
4381 hda_call_check_power_status(codec, 0x01);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004382 if (spec->dac_list)
4383 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004384 return 0;
4385}
4386
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004387static void stac92xx_free_jacks(struct hda_codec *codec)
4388{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004389#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01004390 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004391 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01004392 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004393 struct sigmatel_jack *jacks = spec->jacks.list;
4394 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +02004395 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4396 if (jacks->jack)
4397 snd_device_free(codec->bus->card, jacks->jack);
4398 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004399 }
4400 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004401#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004402}
4403
Takashi Iwai603c4012008-07-30 15:01:44 +02004404static void stac92xx_free_kctls(struct hda_codec *codec)
4405{
4406 struct sigmatel_spec *spec = codec->spec;
4407
4408 if (spec->kctls.list) {
4409 struct snd_kcontrol_new *kctl = spec->kctls.list;
4410 int i;
4411 for (i = 0; i < spec->kctls.used; i++)
4412 kfree(kctl[i].name);
4413 }
4414 snd_array_free(&spec->kctls);
4415}
4416
Takashi Iwai167eae52009-11-06 15:47:50 +01004417static void stac92xx_shutup(struct hda_codec *codec)
4418{
4419 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai167eae52009-11-06 15:47:50 +01004420
Takashi Iwai92ee6162009-12-27 11:18:59 +01004421 snd_hda_shutup_pins(codec);
Takashi Iwai167eae52009-11-06 15:47:50 +01004422
4423 if (spec->eapd_mask)
4424 stac_gpio_set(codec, spec->gpio_mask,
4425 spec->gpio_dir, spec->gpio_data &
4426 ~spec->eapd_mask);
4427}
4428
Matt2f2f4252005-04-13 14:45:30 +02004429static void stac92xx_free(struct hda_codec *codec)
4430{
Mattc7d4b2f2005-06-27 14:59:41 +02004431 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004432
4433 if (! spec)
4434 return;
4435
Takashi Iwai167eae52009-11-06 15:47:50 +01004436 stac92xx_shutup(codec);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004437 stac92xx_free_jacks(codec);
4438 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004439
Mattc7d4b2f2005-06-27 14:59:41 +02004440 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004441 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004442}
4443
Matt4e550962005-07-04 17:51:39 +02004444static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4445 unsigned int flag)
4446{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004447 unsigned int old_ctl, pin_ctl;
4448
4449 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004450 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004451
Takashi Iwaif9acba42007-05-29 18:01:06 +02004452 if (pin_ctl & AC_PINCTL_IN_EN) {
4453 /*
4454 * we need to check the current set-up direction of
4455 * shared input pins since they can be switched via
4456 * "xxx as Output" mixer switch
4457 */
4458 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004459 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004460 return;
4461 }
4462
Takashi Iwai8ce84192009-01-22 16:59:20 +01004463 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004464 /* if setting pin direction bits, clear the current
4465 direction bits first */
4466 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4467 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4468
Takashi Iwai8ce84192009-01-22 16:59:20 +01004469 pin_ctl |= flag;
4470 if (old_ctl != pin_ctl)
4471 snd_hda_codec_write_cache(codec, nid, 0,
4472 AC_VERB_SET_PIN_WIDGET_CONTROL,
4473 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004474}
4475
4476static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4477 unsigned int flag)
4478{
4479 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4480 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004481 if (pin_ctl & flag)
4482 snd_hda_codec_write_cache(codec, nid, 0,
4483 AC_VERB_SET_PIN_WIDGET_CONTROL,
4484 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004485}
4486
Takashi Iwaid56757a2009-11-18 08:00:14 +01004487static inline int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004488{
4489 if (!nid)
4490 return 0;
Takashi Iwaia252c812009-12-25 22:56:20 +01004491 return snd_hda_jack_detect(codec, nid);
Takashi Iwai314634b2006-09-21 11:56:18 +02004492}
4493
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004494static void stac92xx_line_out_detect(struct hda_codec *codec,
4495 int presence)
4496{
4497 struct sigmatel_spec *spec = codec->spec;
4498 struct auto_pin_cfg *cfg = &spec->autocfg;
4499 int i;
4500
4501 for (i = 0; i < cfg->line_outs; i++) {
4502 if (presence)
4503 break;
4504 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4505 if (presence) {
4506 unsigned int pinctl;
4507 pinctl = snd_hda_codec_read(codec,
4508 cfg->line_out_pins[i], 0,
4509 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4510 if (pinctl & AC_PINCTL_IN_EN)
4511 presence = 0; /* mic- or line-input */
4512 }
4513 }
4514
4515 if (presence) {
4516 /* disable speakers */
4517 for (i = 0; i < cfg->speaker_outs; i++)
4518 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4519 AC_PINCTL_OUT_EN);
4520 if (spec->eapd_mask && spec->eapd_switch)
4521 stac_gpio_set(codec, spec->gpio_mask,
4522 spec->gpio_dir, spec->gpio_data &
4523 ~spec->eapd_mask);
4524 } else {
4525 /* enable speakers */
4526 for (i = 0; i < cfg->speaker_outs; i++)
4527 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4528 AC_PINCTL_OUT_EN);
4529 if (spec->eapd_mask && spec->eapd_switch)
4530 stac_gpio_set(codec, spec->gpio_mask,
4531 spec->gpio_dir, spec->gpio_data |
4532 spec->eapd_mask);
4533 }
4534}
4535
Takashi Iwaid7a89432008-11-12 09:48:04 +01004536/* return non-zero if the hp-pin of the given array index isn't
4537 * a jack-detection target
4538 */
4539static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4540{
4541 struct auto_pin_cfg *cfg = &spec->autocfg;
4542
4543 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004544 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004545 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004546 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004547 return 1;
4548 /* ignore if the pin is set as line-out */
4549 if (cfg->hp_pins[i] == spec->hp_switch)
4550 return 1;
4551 return 0;
4552}
4553
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004554static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004555{
4556 struct sigmatel_spec *spec = codec->spec;
4557 struct auto_pin_cfg *cfg = &spec->autocfg;
4558 int i, presence;
4559
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004560 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004561 if (spec->gpio_mute)
4562 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4563 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4564
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004565 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004566 if (presence)
4567 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004568 if (no_hp_sensing(spec, i))
4569 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004570 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4571 if (presence) {
4572 unsigned int pinctl;
4573 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4574 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4575 if (pinctl & AC_PINCTL_IN_EN)
4576 presence = 0; /* mic- or line-input */
4577 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004578 }
Matt4e550962005-07-04 17:51:39 +02004579
4580 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004581 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004582 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004583 stac92xx_reset_pinctl(codec, spec->hp_switch,
4584 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004585 for (i = 0; i < cfg->line_outs; i++)
4586 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4587 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004588 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004589 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004590 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004591 stac92xx_set_pinctl(codec, spec->hp_switch,
4592 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004593 for (i = 0; i < cfg->line_outs; i++)
4594 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4595 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004596 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004597 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004598 /* toggle hp outs */
4599 for (i = 0; i < cfg->hp_outs; i++) {
4600 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4601 if (no_hp_sensing(spec, i))
4602 continue;
4603 if (presence)
4604 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004605#if 0 /* FIXME */
4606/* Resetting the pinctl like below may lead to (a sort of) regressions
4607 * on some devices since they use the HP pin actually for line/speaker
4608 * outs although the default pin config shows a different pin (that is
4609 * wrong and useless).
4610 *
4611 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4612 * But, disabling the code below just works around it, and I'm too tired of
4613 * bug reports with such devices...
4614 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004615 else
4616 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004617#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004618 }
Matt4e550962005-07-04 17:51:39 +02004619}
4620
Takashi Iwaif73d3582008-11-25 08:21:51 +01004621static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4622 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004623{
4624 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004625 unsigned int idx, val;
4626
4627 for (idx = 0; idx < spec->num_pwrs; idx++) {
4628 if (spec->pwr_nids[idx] == nid)
4629 break;
4630 }
4631 if (idx >= spec->num_pwrs)
4632 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004633
4634 /* several codecs have two power down bits */
4635 if (spec->pwr_mapping)
4636 idx = spec->pwr_mapping[idx];
4637 else
4638 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004639
Takashi Iwaif73d3582008-11-25 08:21:51 +01004640 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4641 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004642 val &= ~idx;
4643 else
4644 val |= idx;
4645
4646 /* power down unused output ports */
4647 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004648}
4649
Takashi Iwaif73d3582008-11-25 08:21:51 +01004650static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4651{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004652 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004653}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004654
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004655static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4656{
4657 struct sigmatel_spec *spec = codec->spec;
4658 struct sigmatel_jack *jacks = spec->jacks.list;
4659
4660 if (jacks) {
4661 int i;
4662 for (i = 0; i < spec->jacks.used; i++) {
4663 if (jacks->nid == nid) {
4664 unsigned int pin_ctl =
4665 snd_hda_codec_read(codec, nid,
4666 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4667 0x00);
4668 int type = jacks->type;
4669 if (type == (SND_JACK_LINEOUT
4670 | SND_JACK_HEADPHONE))
4671 type = (pin_ctl & AC_PINCTL_HP_EN)
4672 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4673 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004674 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004675 ? type : 0);
4676 }
4677 jacks++;
4678 }
4679 }
4680}
Matt2f2f4252005-04-13 14:45:30 +02004681
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02004682/* get the pin connection (fixed, none, etc) */
4683static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4684{
4685 struct sigmatel_spec *spec = codec->spec;
4686 unsigned int cfg;
4687
4688 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4689 return get_defcfg_connect(cfg);
4690}
4691
4692static int stac92xx_connected_ports(struct hda_codec *codec,
4693 hda_nid_t *nids, int num_nids)
4694{
4695 struct sigmatel_spec *spec = codec->spec;
4696 int idx, num;
4697 unsigned int def_conf;
4698
4699 for (num = 0; num < num_nids; num++) {
4700 for (idx = 0; idx < spec->num_pins; idx++)
4701 if (spec->pin_nids[idx] == nids[num])
4702 break;
4703 if (idx >= spec->num_pins)
4704 break;
4705 def_conf = stac_get_defcfg_connect(codec, idx);
4706 if (def_conf == AC_JACK_PORT_NONE)
4707 break;
4708 }
4709 return num;
4710}
4711
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004712static void stac92xx_mic_detect(struct hda_codec *codec)
4713{
4714 struct sigmatel_spec *spec = codec->spec;
4715 struct sigmatel_mic_route *mic;
4716
4717 if (get_pin_presence(codec, spec->ext_mic.pin))
4718 mic = &spec->ext_mic;
Charles Chin99077902010-09-17 10:22:32 +02004719 else if (get_pin_presence(codec, spec->dock_mic.pin))
4720 mic = &spec->dock_mic;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004721 else
4722 mic = &spec->int_mic;
Takashi Iwai02d33322009-10-01 16:38:11 +02004723 if (mic->dmux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004724 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4725 AC_VERB_SET_CONNECT_SEL,
4726 mic->dmux_idx);
Takashi Iwai02d33322009-10-01 16:38:11 +02004727 if (mic->mux_idx >= 0)
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004728 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4729 AC_VERB_SET_CONNECT_SEL,
4730 mic->mux_idx);
4731}
4732
Takashi Iwai62558ce2009-07-29 14:23:09 +02004733static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004734{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004735 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004736 if (!event)
4737 return;
4738 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4739}
4740
Takashi Iwai314634b2006-09-21 11:56:18 +02004741static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4742{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004743 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004744 struct sigmatel_event *event;
4745 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004746
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004747 tag = (res >> 26) & 0x7f;
4748 event = stac_get_event_from_tag(codec, tag);
4749 if (!event)
4750 return;
4751
4752 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004753 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004754 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004755 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004756 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004757 case STAC_MIC_EVENT:
4758 stac92xx_mic_detect(codec);
4759 break;
4760 }
4761
4762 switch (event->type) {
4763 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004764 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004765 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004766 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004767 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004768 if (spec->num_pwrs > 0)
4769 stac92xx_pin_sense(codec, event->nid);
4770 stac92xx_report_jack(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004771
4772 switch (codec->subsystem_id) {
4773 case 0x103c308f:
4774 if (event->nid == 0xb) {
4775 int pin = AC_PINCTL_IN_EN;
4776
4777 if (get_pin_presence(codec, 0xa)
4778 && get_pin_presence(codec, 0xb))
4779 pin |= AC_PINCTL_VREF_80;
4780 if (!get_pin_presence(codec, 0xb))
4781 pin |= AC_PINCTL_VREF_80;
4782
4783 /* toggle VREF state based on mic + hp pin
4784 * status
4785 */
4786 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4787 }
4788 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004789 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004790 case STAC_VREF_EVENT:
4791 data = snd_hda_codec_read(codec, codec->afg, 0,
4792 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004793 /* toggle VREF state based on GPIOx status */
4794 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004795 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004796 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004797 }
4798}
4799
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304800static int hp_blike_system(u32 subsystem_id);
4801
4802static void set_hp_led_gpio(struct hda_codec *codec)
4803{
4804 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai07f80442010-02-08 15:06:13 +01004805 unsigned int gpio;
4806
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02004807 if (spec->gpio_led)
4808 return;
4809
Takashi Iwai07f80442010-02-08 15:06:13 +01004810 gpio = snd_hda_param_read(codec, codec->afg, AC_PAR_GPIO_CAP);
4811 gpio &= AC_GPIO_IO_COUNT;
4812 if (gpio > 3)
4813 spec->gpio_led = 0x08; /* GPIO 3 */
4814 else
4815 spec->gpio_led = 0x01; /* GPIO 0 */
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304816}
4817
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004818/*
4819 * This method searches for the mute LED GPIO configuration
4820 * provided as OEM string in SMBIOS. The format of that string
4821 * is HP_Mute_LED_P_G or HP_Mute_LED_P
4822 * where P can be 0 or 1 and defines mute LED GPIO control state (low/high)
4823 * that corresponds to the NOT muted state of the master volume
4824 * and G is the index of the GPIO to use as the mute LED control (0..9)
4825 * If _G portion is missing it is assigned based on the codec ID
4826 *
4827 * So, HP B-series like systems may have HP_Mute_LED_0 (current models)
4828 * or HP_Mute_LED_0_3 (future models) OEM SMBIOS strings
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304829 *
4830 *
4831 * The dv-series laptops don't seem to have the HP_Mute_LED* strings in
4832 * SMBIOS - at least the ones I have seen do not have them - which include
4833 * my own system (HP Pavilion dv6-1110ax) and my cousin's
4834 * HP Pavilion dv9500t CTO.
4835 * Need more information on whether it is true across the entire series.
4836 * -- kunal
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004837 */
Takashi Iwaidce17d42010-02-09 09:25:26 +01004838static int find_mute_led_gpio(struct hda_codec *codec, int default_polarity)
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004839{
4840 struct sigmatel_spec *spec = codec->spec;
4841 const struct dmi_device *dev = NULL;
4842
4843 if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4844 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4845 NULL, dev))) {
4846 if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304847 &spec->gpio_led_polarity,
4848 &spec->gpio_led) == 2) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004849 spec->gpio_led = 1 << spec->gpio_led;
4850 return 1;
4851 }
4852 if (sscanf(dev->name, "HP_Mute_LED_%d",
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304853 &spec->gpio_led_polarity) == 1) {
4854 set_hp_led_gpio(codec);
4855 return 1;
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004856 }
4857 }
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304858
4859 /*
4860 * Fallback case - if we don't find the DMI strings,
4861 * we statically set the GPIO - if not a B-series system.
4862 */
4863 if (!hp_blike_system(codec->subsystem_id)) {
4864 set_hp_led_gpio(codec);
Takashi Iwaidce17d42010-02-09 09:25:26 +01004865 spec->gpio_led_polarity = default_polarity;
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05304866 return 1;
4867 }
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004868 }
4869 return 0;
4870}
4871
4872static int hp_blike_system(u32 subsystem_id)
Randy Dunlap78987bd2009-11-05 09:22:30 -08004873{
4874 switch (subsystem_id) {
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004875 case 0x103c1520:
4876 case 0x103c1521:
4877 case 0x103c1523:
4878 case 0x103c1524:
4879 case 0x103c1525:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004880 case 0x103c1722:
4881 case 0x103c1723:
4882 case 0x103c1724:
4883 case 0x103c1725:
4884 case 0x103c1726:
4885 case 0x103c1727:
4886 case 0x103c1728:
4887 case 0x103c1729:
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01004888 case 0x103c172a:
4889 case 0x103c172b:
4890 case 0x103c307e:
4891 case 0x103c307f:
4892 case 0x103c3080:
4893 case 0x103c3081:
4894 case 0x103c7007:
4895 case 0x103c7008:
Randy Dunlap78987bd2009-11-05 09:22:30 -08004896 return 1;
4897 }
4898 return 0;
4899}
4900
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004901#ifdef CONFIG_PROC_FS
4902static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4903 struct hda_codec *codec, hda_nid_t nid)
4904{
4905 if (nid == codec->afg)
4906 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4907 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4908}
4909
4910static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4911 struct hda_codec *codec,
4912 unsigned int verb)
4913{
4914 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4915 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4916}
4917
4918/* stac92hd71bxx, stac92hd73xx */
4919static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4920 struct hda_codec *codec, hda_nid_t nid)
4921{
4922 stac92hd_proc_hook(buffer, codec, nid);
4923 if (nid == codec->afg)
4924 analog_loop_proc_hook(buffer, codec, 0xfa0);
4925}
4926
4927static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4928 struct hda_codec *codec, hda_nid_t nid)
4929{
4930 if (nid == codec->afg)
4931 analog_loop_proc_hook(buffer, codec, 0xfe0);
4932}
4933
4934static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4935 struct hda_codec *codec, hda_nid_t nid)
4936{
4937 if (nid == codec->afg)
4938 analog_loop_proc_hook(buffer, codec, 0xfeb);
4939}
4940#else
4941#define stac92hd_proc_hook NULL
4942#define stac92hd7x_proc_hook NULL
4943#define stac9205_proc_hook NULL
4944#define stac927x_proc_hook NULL
4945#endif
4946
Takashi Iwaicb53c622007-08-10 17:21:45 +02004947#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004948static int stac92xx_resume(struct hda_codec *codec)
4949{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004950 struct sigmatel_spec *spec = codec->spec;
4951
Takashi Iwai2c885872008-11-18 09:36:55 +01004952 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004953 snd_hda_codec_resume_amp(codec);
4954 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004955 /* fake event to set up pins again to override cached values */
Takashi Iwai5f380eb2009-09-14 15:36:14 +02004956 if (spec->hp_detect) {
4957 if (spec->autocfg.hp_pins[0])
4958 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4959 else if (spec->autocfg.line_out_pins[0])
4960 stac_issue_unsol_event(codec,
4961 spec->autocfg.line_out_pins[0]);
4962 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004963 /* sync mute LED */
Takashi Iwai9e5341b2010-09-21 09:57:06 +02004964 if (spec->gpio_led)
4965 hda_call_check_power_status(codec, 0x01);
Mattff6fdc32005-06-27 15:06:52 +02004966 return 0;
4967}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004968
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004969/*
James Gardiner514bf542009-05-03 04:00:44 -04004970 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004971 * check for mute state only on Speakers (nid = 0x10)
4972 *
4973 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4974 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004975 *
4976 * Changed name to reflect that it now works for any designated
4977 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004978 */
4979
4980#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004981static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004982 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004983{
4984 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21bd022010-02-08 15:16:08 +01004985 int i, muted = 1;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004986
Takashi Iwaic21bd022010-02-08 15:16:08 +01004987 for (i = 0; i < spec->multiout.num_dacs; i++) {
4988 nid = spec->multiout.dac_nids[i];
4989 if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4990 HDA_AMP_MUTE)) {
4991 muted = 0; /* something heard */
4992 break;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01004993 }
Takashi Iwaic21bd022010-02-08 15:16:08 +01004994 }
4995 if (muted)
4996 spec->gpio_data &= ~spec->gpio_led; /* orange */
4997 else
4998 spec->gpio_data |= spec->gpio_led; /* white */
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01004999
Takashi Iwaic21bd022010-02-08 15:16:08 +01005000 if (!spec->gpio_led_polarity) {
5001 /* LED state is inverted on these systems */
5002 spec->gpio_data ^= spec->gpio_led;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005003 }
5004
Takashi Iwaib4e81872009-11-18 17:20:24 +01005005 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
Takashi Iwaib4e81872009-11-18 17:20:24 +01005006 return 0;
5007}
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005008#endif
5009
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005010static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
5011{
Takashi Iwai167eae52009-11-06 15:47:50 +01005012 stac92xx_shutup(codec);
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005013 return 0;
5014}
Mattff6fdc32005-06-27 15:06:52 +02005015#endif
5016
Matt2f2f4252005-04-13 14:45:30 +02005017static struct hda_codec_ops stac92xx_patch_ops = {
5018 .build_controls = stac92xx_build_controls,
5019 .build_pcms = stac92xx_build_pcms,
5020 .init = stac92xx_init,
5021 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02005022 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02005023#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005024 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005025 .resume = stac92xx_resume,
5026#endif
Takashi Iwaifb8d1a32009-11-10 16:02:29 +01005027 .reboot_notify = stac92xx_shutup,
Matt2f2f4252005-04-13 14:45:30 +02005028};
5029
5030static int patch_stac9200(struct hda_codec *codec)
5031{
5032 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005033 int err;
Matt2f2f4252005-04-13 14:45:30 +02005034
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005035 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005036 if (spec == NULL)
5037 return -ENOMEM;
5038
Takashi Iwaia252c812009-12-25 22:56:20 +01005039 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005040 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005041 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005042 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005043 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005044 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5045 stac9200_models,
5046 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005047 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005048 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5049 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005050 else
5051 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005052 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005053
5054 spec->multiout.max_channels = 2;
5055 spec->multiout.num_dacs = 1;
5056 spec->multiout.dac_nids = stac9200_dac_nids;
5057 spec->adc_nids = stac9200_adc_nids;
5058 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005059 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005060 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005061 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005062 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005063
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005064 if (spec->board_config == STAC_9200_M4 ||
5065 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005066 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005067 spec->init = stac9200_eapd_init;
5068 else
5069 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005070 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005071
Takashi Iwai117f2572008-03-18 09:53:23 +01005072 if (spec->board_config == STAC_9200_PANASONIC) {
5073 spec->gpio_mask = spec->gpio_dir = 0x09;
5074 spec->gpio_data = 0x00;
5075 }
5076
Mattc7d4b2f2005-06-27 14:59:41 +02005077 err = stac9200_parse_auto_config(codec);
5078 if (err < 0) {
5079 stac92xx_free(codec);
5080 return err;
5081 }
Matt2f2f4252005-04-13 14:45:30 +02005082
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005083 /* CF-74 has no headphone detection, and the driver should *NOT*
5084 * do detection and HP/speaker toggle because the hardware does it.
5085 */
5086 if (spec->board_config == STAC_9200_PANASONIC)
5087 spec->hp_detect = 0;
5088
Matt2f2f4252005-04-13 14:45:30 +02005089 codec->patch_ops = stac92xx_patch_ops;
5090
5091 return 0;
5092}
5093
Tobin Davis8e21c342007-01-08 11:04:17 +01005094static int patch_stac925x(struct hda_codec *codec)
5095{
5096 struct sigmatel_spec *spec;
5097 int err;
5098
5099 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5100 if (spec == NULL)
5101 return -ENOMEM;
5102
Takashi Iwaia252c812009-12-25 22:56:20 +01005103 codec->no_trigger_sense = 1;
Tobin Davis8e21c342007-01-08 11:04:17 +01005104 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005105 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005106 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005107 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005108
5109 /* Check first for codec ID */
5110 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5111 STAC_925x_MODELS,
5112 stac925x_models,
5113 stac925x_codec_id_cfg_tbl);
5114
5115 /* Now checks for PCI ID, if codec ID is not found */
5116 if (spec->board_config < 0)
5117 spec->board_config = snd_hda_check_board_config(codec,
5118 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005119 stac925x_models,
5120 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005121 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005122 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005123 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5124 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005125 else
5126 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005127 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005128
5129 spec->multiout.max_channels = 2;
5130 spec->multiout.num_dacs = 1;
5131 spec->multiout.dac_nids = stac925x_dac_nids;
5132 spec->adc_nids = stac925x_adc_nids;
5133 spec->mux_nids = stac925x_mux_nids;
5134 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005135 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005136 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005137 switch (codec->vendor_id) {
5138 case 0x83847632: /* STAC9202 */
5139 case 0x83847633: /* STAC9202D */
5140 case 0x83847636: /* STAC9251 */
5141 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005142 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005143 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005144 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5145 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005146 break;
5147 default:
5148 spec->num_dmics = 0;
5149 break;
5150 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005151
5152 spec->init = stac925x_core_init;
5153 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005154 spec->num_caps = 1;
5155 spec->capvols = stac925x_capvols;
5156 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005157
5158 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005159 if (!err) {
5160 if (spec->board_config < 0) {
5161 printk(KERN_WARNING "hda_codec: No auto-config is "
5162 "available, default to model=ref\n");
5163 spec->board_config = STAC_925x_REF;
5164 goto again;
5165 }
5166 err = -EINVAL;
5167 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005168 if (err < 0) {
5169 stac92xx_free(codec);
5170 return err;
5171 }
5172
5173 codec->patch_ops = stac92xx_patch_ops;
5174
5175 return 0;
5176}
5177
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005178static int patch_stac92hd73xx(struct hda_codec *codec)
5179{
5180 struct sigmatel_spec *spec;
5181 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5182 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005183 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005184
5185 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5186 if (spec == NULL)
5187 return -ENOMEM;
5188
Takashi Iwaia252c812009-12-25 22:56:20 +01005189 codec->no_trigger_sense = 1;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005190 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005191 spec->linear_tone_beep = 0;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005192 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005193 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5194 spec->pin_nids = stac92hd73xx_pin_nids;
5195 spec->board_config = snd_hda_check_board_config(codec,
5196 STAC_92HD73XX_MODELS,
5197 stac92hd73xx_models,
5198 stac92hd73xx_cfg_tbl);
Takashi Iwai842ae632009-09-02 07:43:08 +02005199 /* check codec subsystem id if not found */
5200 if (spec->board_config < 0)
5201 spec->board_config =
5202 snd_hda_check_board_codec_sid_config(codec,
5203 STAC_92HD73XX_MODELS, stac92hd73xx_models,
5204 stac92hd73xx_codec_id_cfg_tbl);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005205again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005206 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005207 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5208 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005209 else
5210 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005211 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005212
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005213 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005214 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5215
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005216 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005217 printk(KERN_WARNING "hda_codec: Could not determine "
5218 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005219 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005220 }
Takashi Iwaie2aec172009-09-02 01:00:05 +02005221 spec->init = stac92hd73xx_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005222 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005223 case 0x3: /* 6 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005224 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005225 break;
5226 case 0x4: /* 8 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005227 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005228 break;
5229 case 0x5: /* 10 Channel */
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005230 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5231 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005232 }
5233 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005234
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005235 spec->aloopback_mask = 0x01;
5236 spec->aloopback_shift = 8;
5237
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005238 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005239 spec->mux_nids = stac92hd73xx_mux_nids;
5240 spec->adc_nids = stac92hd73xx_adc_nids;
5241 spec->dmic_nids = stac92hd73xx_dmic_nids;
5242 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005243 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005244
5245 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5246 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005247 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005248
Takashi Iwai6479c632009-07-28 18:20:25 +02005249 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5250 spec->capvols = stac92hd73xx_capvols;
5251 spec->capsws = stac92hd73xx_capsws;
5252
Matthew Ranostaya7662642008-02-21 07:51:14 +01005253 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005254 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005255 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005256 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005257 case STAC_DELL_M6_AMIC:
5258 case STAC_DELL_M6_DMIC:
5259 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005260 spec->num_smuxes = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005261 spec->eapd_switch = 0;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005262
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005263 switch (spec->board_config) {
5264 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005265 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005266 spec->num_dmics = 0;
5267 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005268 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005269 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005270 spec->num_dmics = 1;
5271 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005272 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005273 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5274 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005275 spec->num_dmics = 1;
5276 break;
5277 }
5278 break;
Takashi Iwai842ae632009-09-02 07:43:08 +02005279 case STAC_ALIENWARE_M17X:
5280 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
5281 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
5282 spec->eapd_switch = 0;
5283 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005284 default:
5285 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005286 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005287 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005288 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005289 }
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005290 if (spec->board_config != STAC_92HD73XX_REF) {
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005291 /* GPIO0 High = Enable EAPD */
5292 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5293 spec->gpio_data = 0x01;
5294 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005295
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005296 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5297 spec->pwr_nids = stac92hd73xx_pwr_nids;
5298
Matthew Ranostayd9737752008-09-07 12:03:41 +02005299 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005300
5301 if (!err) {
5302 if (spec->board_config < 0) {
5303 printk(KERN_WARNING "hda_codec: No auto-config is "
5304 "available, default to model=ref\n");
5305 spec->board_config = STAC_92HD73XX_REF;
5306 goto again;
5307 }
5308 err = -EINVAL;
5309 }
5310
5311 if (err < 0) {
5312 stac92xx_free(codec);
5313 return err;
5314 }
5315
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005316 if (spec->board_config == STAC_92HD73XX_NO_JD)
5317 spec->hp_detect = 0;
5318
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005319 codec->patch_ops = stac92xx_patch_ops;
5320
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005321 codec->proc_widget_hook = stac92hd7x_proc_hook;
5322
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005323 return 0;
5324}
5325
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005326static int patch_stac92hd83xxx(struct hda_codec *codec)
5327{
5328 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005329 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005330 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005331 int num_dacs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005332
5333 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5334 if (spec == NULL)
5335 return -ENOMEM;
5336
Takashi Iwaia252c812009-12-25 22:56:20 +01005337 codec->no_trigger_sense = 1;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005338 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005339 spec->linear_tone_beep = 1;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005340 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005341 spec->digbeep_nid = 0x21;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005342 spec->dmic_nids = stac92hd83xxx_dmic_nids;
5343 spec->dmux_nids = stac92hd83xxx_mux_nids;
Takashi Iwai667067d2009-08-13 18:14:42 +02005344 spec->mux_nids = stac92hd83xxx_mux_nids;
5345 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005346 spec->adc_nids = stac92hd83xxx_adc_nids;
Takashi Iwai7570ef12009-08-15 11:57:53 +02005347 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005348 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5349 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5350 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005351 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005352
5353 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005354 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005355 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005356 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5357 spec->capvols = stac92hd83xxx_capvols;
5358 spec->capsws = stac92hd83xxx_capsws;
5359
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005360 spec->board_config = snd_hda_check_board_config(codec,
5361 STAC_92HD83XXX_MODELS,
5362 stac92hd83xxx_models,
5363 stac92hd83xxx_cfg_tbl);
5364again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005365 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005366 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5367 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005368 else
5369 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005370 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005371
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005372 switch (codec->vendor_id) {
Charles Chin36706002010-01-29 12:05:51 +01005373 case 0x111d7666:
5374 case 0x111d7667:
5375 case 0x111d7668:
5376 case 0x111d7669:
Charles Chin8a345a02010-08-10 11:43:25 +02005377 case 0x111d76d1:
5378 case 0x111d76d9:
Charles Chin36706002010-01-29 12:05:51 +01005379 spec->num_pins = ARRAY_SIZE(stac92hd88xxx_pin_nids);
5380 spec->pin_nids = stac92hd88xxx_pin_nids;
5381 spec->mono_nid = 0;
5382 spec->digbeep_nid = 0;
5383 spec->num_pwrs = 0;
5384 break;
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005385 case 0x111d7604:
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01005386 case 0x111d76d4:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005387 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005388 case 0x111d76d5:
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005389 case 0x111d76e7:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005390 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5391 break;
5392 spec->num_pwrs = 0;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005393 spec->num_dmics = stac92xx_connected_ports(codec,
5394 stac92hd83xxx_dmic_nids,
5395 STAC92HD83XXX_NUM_DMICS);
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005396 break;
5397 }
5398
Takashi Iwaib4e81872009-11-18 17:20:24 +01005399 codec->patch_ops = stac92xx_patch_ops;
5400
Takashi Iwaidce17d42010-02-09 09:25:26 +01005401 if (find_mute_led_gpio(codec, 0))
Vitaliy Kulikove108c7b2010-01-28 19:21:07 +01005402 snd_printd("mute LED gpio %d polarity %d\n",
5403 spec->gpio_led,
5404 spec->gpio_led_polarity);
5405
Takashi Iwaib4e81872009-11-18 17:20:24 +01005406#ifdef CONFIG_SND_HDA_POWER_SAVE
5407 if (spec->gpio_led) {
5408 spec->gpio_mask |= spec->gpio_led;
5409 spec->gpio_dir |= spec->gpio_led;
5410 spec->gpio_data |= spec->gpio_led;
5411 /* register check_power_status callback. */
5412 codec->patch_ops.check_power_status =
Takashi Iwaic21bd022010-02-08 15:16:08 +01005413 stac92xx_hp_check_power_status;
Takashi Iwaib4e81872009-11-18 17:20:24 +01005414 }
5415#endif
5416
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005417 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5418 if (!err) {
5419 if (spec->board_config < 0) {
5420 printk(KERN_WARNING "hda_codec: No auto-config is "
5421 "available, default to model=ref\n");
5422 spec->board_config = STAC_92HD83XXX_REF;
5423 goto again;
5424 }
5425 err = -EINVAL;
5426 }
5427
5428 if (err < 0) {
5429 stac92xx_free(codec);
5430 return err;
5431 }
5432
Charles Chin04b5efe2010-02-04 10:28:02 +01005433 /* docking output support */
5434 num_dacs = snd_hda_get_connections(codec, 0xF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005435 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Charles Chin04b5efe2010-02-04 10:28:02 +01005436 /* skip non-DAC connections */
5437 while (num_dacs >= 0 &&
5438 (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5439 != AC_WID_AUD_OUT))
5440 num_dacs--;
5441 /* set port E and F to select the last DAC */
5442 if (num_dacs >= 0) {
5443 snd_hda_codec_write_cache(codec, 0xE, 0,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005444 AC_VERB_SET_CONNECT_SEL, num_dacs);
Charles Chin04b5efe2010-02-04 10:28:02 +01005445 snd_hda_codec_write_cache(codec, 0xF, 0,
5446 AC_VERB_SET_CONNECT_SEL, num_dacs);
5447 }
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005448
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005449 codec->proc_widget_hook = stac92hd_proc_hook;
5450
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005451 return 0;
5452}
5453
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005454static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5455 hda_nid_t dig0pin)
5456{
5457 struct sigmatel_spec *spec = codec->spec;
5458 int idx;
5459
5460 for (idx = 0; idx < spec->num_pins; idx++)
5461 if (spec->pin_nids[idx] == dig0pin)
5462 break;
5463 if ((idx + 2) >= spec->num_pins)
5464 return 0;
5465
5466 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005467 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005468 return 2;
5469
5470 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005471 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005472 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005473 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005474 return 1;
5475 else
5476 return 0;
5477}
5478
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005479/* HP dv7 bass switch - GPIO5 */
5480#define stac_hp_bass_gpio_info snd_ctl_boolean_mono_info
5481static int stac_hp_bass_gpio_get(struct snd_kcontrol *kcontrol,
5482 struct snd_ctl_elem_value *ucontrol)
5483{
5484 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5485 struct sigmatel_spec *spec = codec->spec;
5486 ucontrol->value.integer.value[0] = !!(spec->gpio_data & 0x20);
5487 return 0;
5488}
5489
5490static int stac_hp_bass_gpio_put(struct snd_kcontrol *kcontrol,
5491 struct snd_ctl_elem_value *ucontrol)
5492{
5493 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
5494 struct sigmatel_spec *spec = codec->spec;
5495 unsigned int gpio_data;
5496
5497 gpio_data = (spec->gpio_data & ~0x20) |
5498 (ucontrol->value.integer.value[0] ? 0x20 : 0);
5499 if (gpio_data == spec->gpio_data)
5500 return 0;
5501 spec->gpio_data = gpio_data;
5502 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
5503 return 1;
5504}
5505
5506static struct snd_kcontrol_new stac_hp_bass_sw_ctrl = {
5507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5508 .info = stac_hp_bass_gpio_info,
5509 .get = stac_hp_bass_gpio_get,
5510 .put = stac_hp_bass_gpio_put,
5511};
5512
5513static int stac_add_hp_bass_switch(struct hda_codec *codec)
5514{
5515 struct sigmatel_spec *spec = codec->spec;
5516
5517 if (!stac_control_new(spec, &stac_hp_bass_sw_ctrl,
5518 "Bass Speaker Playback Switch", 0))
5519 return -ENOMEM;
5520
5521 spec->gpio_mask |= 0x20;
5522 spec->gpio_dir |= 0x20;
5523 spec->gpio_data |= 0x20;
5524 return 0;
5525}
5526
Matthew Ranostaye035b842007-11-06 11:53:55 +01005527static int patch_stac92hd71bxx(struct hda_codec *codec)
5528{
5529 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005530 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005531 unsigned int pin_cfg;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005532 int err = 0;
5533
5534 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5535 if (spec == NULL)
5536 return -ENOMEM;
5537
Takashi Iwaia252c812009-12-25 22:56:20 +01005538 codec->no_trigger_sense = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005539 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005540 spec->linear_tone_beep = 0;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005541 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005542 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5543 switch (codec->vendor_id) {
5544 case 0x111d76b6:
5545 case 0x111d76b7:
5546 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5547 break;
5548 case 0x111d7603:
5549 case 0x111d7608:
5550 /* On 92HD75Bx 0x27 isn't a pin nid */
5551 spec->num_pins--;
5552 /* fallthrough */
5553 default:
5554 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5555 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005556 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005557 spec->board_config = snd_hda_check_board_config(codec,
5558 STAC_92HD71BXX_MODELS,
5559 stac92hd71bxx_models,
5560 stac92hd71bxx_cfg_tbl);
5561again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005562 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005563 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5564 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005565 else
5566 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005567 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005568
Takashi Iwaifc64b262009-09-14 15:33:01 +02005569 if (spec->board_config != STAC_92HD71BXX_REF) {
Takashi Iwai41c3b642008-11-18 10:45:15 +01005570 /* GPIO0 = EAPD */
5571 spec->gpio_mask = 0x01;
5572 spec->gpio_dir = 0x01;
5573 spec->gpio_data = 0x01;
5574 }
5575
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005576 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5577 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5578
Takashi Iwai6479c632009-07-28 18:20:25 +02005579 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5580 spec->capvols = stac92hd71bxx_capvols;
5581 spec->capsws = stac92hd71bxx_capsws;
5582
Matthew Ranostay541eee82007-12-14 12:08:04 +01005583 switch (codec->vendor_id) {
5584 case 0x111d76b6: /* 4 Port without Analog Mixer */
5585 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005586 unmute_init++;
5587 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005588 case 0x111d76b4: /* 6 Port without Analog Mixer */
5589 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005590 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005591 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005592 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005593 stac92hd71bxx_dmic_nids,
5594 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005595 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005596 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005597 switch (spec->board_config) {
5598 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005599 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005600 err = stac_add_event(spec, codec->afg,
5601 STAC_VREF_EVENT, 0x02);
5602 if (err < 0)
5603 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005604 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005605 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5606 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005607 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005608 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005609 spec->gpio_mask |= 0x02;
5610 break;
5611 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005612 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005613 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005614 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005615
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005616 /* no output amps */
5617 spec->num_pwrs = 0;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005618 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005619 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005620 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005621 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5622 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005623 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005624 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005625 stac92hd71bxx_dmic_nids,
5626 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005627 break;
5628 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005629 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005630 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005631
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005632 /* no output amps */
5633 spec->num_pwrs = 0;
5634 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005635 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005636 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005637 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02005638 spec->num_dmics = stac92xx_connected_ports(codec,
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005639 stac92hd71bxx_dmic_nids,
5640 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005641 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005642 }
5643
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005644 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5645 snd_hda_sequence_write_cache(codec, unmute_init);
5646
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005647 /* Some HP machines seem to have unstable codec communications
5648 * especially with ATI fglrx driver. For recovering from the
5649 * CORB/RIRB stall, allow the BUS reset and keep always sync
5650 */
5651 if (spec->board_config == STAC_HP_DV5) {
5652 codec->bus->sync_write = 1;
5653 codec->bus->allow_bus_reset = 1;
5654 }
5655
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005656 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005657 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005658 spec->aloopback_shift = 0;
5659
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005660 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005661 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005662 spec->mux_nids = stac92hd71bxx_mux_nids;
5663 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005664 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005665 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005666
5667 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5668 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005669 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005670 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005671
Kunal Gangakhedkard38cce72010-01-15 21:01:47 +05305672 snd_printdd("Found board config: %d\n", spec->board_config);
5673
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005674 switch (spec->board_config) {
5675 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005676 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005677 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005678 stac92xx_auto_set_pinctl(codec, 0x0e,
5679 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005680 /* fallthru */
5681 case STAC_DELL_M4_2:
5682 spec->num_dmics = 0;
5683 spec->num_smuxes = 0;
5684 spec->num_dmuxes = 0;
5685 break;
5686 case STAC_DELL_M4_1:
5687 case STAC_DELL_M4_3:
5688 spec->num_dmics = 1;
5689 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005690 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005691 break;
James Gardiner514bf542009-05-03 04:00:44 -04005692 case STAC_HP_DV4_1222NR:
5693 spec->num_dmics = 1;
5694 /* I don't know if it needs 1 or 2 smuxes - will wait for
5695 * bug reports to fix if needed
5696 */
5697 spec->num_smuxes = 1;
5698 spec->num_dmuxes = 1;
James Gardiner514bf542009-05-03 04:00:44 -04005699 /* fallthrough */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005700 case STAC_HP_DV4:
5701 spec->gpio_led = 0x01;
5702 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005703 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005704 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005705 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
Takashi Iwai6e34c032009-09-14 15:42:18 +02005706 /* HP dv6 gives the headphone pin as a line-out. Thus we
5707 * need to set hp_detect flag here to force to enable HP
5708 * detection.
5709 */
5710 spec->hp_detect = 1;
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005711 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005712 case STAC_HP_HDX:
5713 spec->num_dmics = 1;
5714 spec->num_dmuxes = 1;
5715 spec->num_smuxes = 1;
Takashi Iwai26ebe0a2010-05-11 08:36:29 +02005716 spec->gpio_led = 0x08;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005717 break;
5718 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005719
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005720 if (hp_blike_system(codec->subsystem_id)) {
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005721 pin_cfg = snd_hda_codec_get_pincfg(codec, 0x0f);
5722 if (get_defcfg_device(pin_cfg) == AC_JACK_LINE_OUT ||
5723 get_defcfg_device(pin_cfg) == AC_JACK_SPEAKER ||
5724 get_defcfg_device(pin_cfg) == AC_JACK_HP_OUT) {
5725 /* It was changed in the BIOS to just satisfy MS DTM.
5726 * Lets turn it back into slaved HP
5727 */
5728 pin_cfg = (pin_cfg & (~AC_DEFCFG_DEVICE))
5729 | (AC_JACK_HP_OUT <<
5730 AC_DEFCFG_DEVICE_SHIFT);
5731 pin_cfg = (pin_cfg & (~(AC_DEFCFG_DEF_ASSOC
5732 | AC_DEFCFG_SEQUENCE)))
5733 | 0x1f;
5734 snd_hda_codec_set_pincfg(codec, 0x0f, pin_cfg);
5735 }
5736 }
5737
Takashi Iwaidce17d42010-02-09 09:25:26 +01005738 if (find_mute_led_gpio(codec, 1))
Vitaliy Kulikovc357aab2009-12-11 07:51:54 +01005739 snd_printd("mute LED gpio %d polarity %d\n",
5740 spec->gpio_led,
5741 spec->gpio_led_polarity);
Vitaliy Kulikov5bdaaad2009-11-04 07:57:45 +01005742
Takashi Iwai86d190e2009-05-26 15:18:58 +02005743#ifdef CONFIG_SND_HDA_POWER_SAVE
5744 if (spec->gpio_led) {
5745 spec->gpio_mask |= spec->gpio_led;
5746 spec->gpio_dir |= spec->gpio_led;
5747 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005748 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005749 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005750 stac92xx_hp_check_power_status;
5751 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005752#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005753
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005754 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005755
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005756 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005757 if (!err) {
5758 if (spec->board_config < 0) {
5759 printk(KERN_WARNING "hda_codec: No auto-config is "
5760 "available, default to model=ref\n");
5761 spec->board_config = STAC_92HD71BXX_REF;
5762 goto again;
5763 }
5764 err = -EINVAL;
5765 }
5766
5767 if (err < 0) {
5768 stac92xx_free(codec);
5769 return err;
5770 }
5771
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005772 /* enable bass on HP dv7 */
Takashi Iwai2a6ce6e2010-05-12 10:16:20 +02005773 if (spec->board_config == STAC_HP_DV4 ||
5774 spec->board_config == STAC_HP_DV5) {
Takashi Iwai75d1aeb2009-12-22 11:56:32 +01005775 unsigned int cap;
5776 cap = snd_hda_param_read(codec, 0x1, AC_PAR_GPIO_CAP);
5777 cap &= AC_GPIO_IO_COUNT;
5778 if (cap >= 6)
5779 stac_add_hp_bass_switch(codec);
5780 }
5781
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005782 codec->proc_widget_hook = stac92hd7x_proc_hook;
5783
Matthew Ranostaye035b842007-11-06 11:53:55 +01005784 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005785}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005786
Matt2f2f4252005-04-13 14:45:30 +02005787static int patch_stac922x(struct hda_codec *codec)
5788{
5789 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005790 int err;
Matt2f2f4252005-04-13 14:45:30 +02005791
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005792 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005793 if (spec == NULL)
5794 return -ENOMEM;
5795
Takashi Iwaia252c812009-12-25 22:56:20 +01005796 codec->no_trigger_sense = 1;
Matt2f2f4252005-04-13 14:45:30 +02005797 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005798 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005799 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005800 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005801 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5802 stac922x_models,
5803 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005804 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005805 spec->gpio_mask = spec->gpio_dir = 0x03;
5806 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005807 /* Intel Macs have all same PCI SSID, so we need to check
5808 * codec SSID to distinguish the exact models
5809 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005810 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005811 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005812
5813 case 0x106b0800:
5814 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005815 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005816 case 0x106b0600:
5817 case 0x106b0700:
5818 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005819 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005820 case 0x106b0e00:
5821 case 0x106b0f00:
5822 case 0x106b1600:
5823 case 0x106b1700:
5824 case 0x106b0200:
5825 case 0x106b1e00:
5826 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005827 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005828 case 0x106b1a00:
5829 case 0x00000100:
5830 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005831 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005832 case 0x106b0a00:
5833 case 0x106b2200:
5834 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005835 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005836 default:
5837 spec->board_config = STAC_INTEL_MAC_V3;
5838 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005839 }
5840 }
5841
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005842 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005843 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005844 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5845 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005846 else
5847 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005848 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005849
Matt2f2f4252005-04-13 14:45:30 +02005850 spec->adc_nids = stac922x_adc_nids;
5851 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005852 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005853 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005854 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005855 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005856
5857 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005858
5859 spec->num_caps = STAC922X_NUM_CAPS;
5860 spec->capvols = stac922x_capvols;
5861 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005862
5863 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005864
Matt Porter3cc08dc2006-01-23 15:27:49 +01005865 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005866 if (!err) {
5867 if (spec->board_config < 0) {
5868 printk(KERN_WARNING "hda_codec: No auto-config is "
5869 "available, default to model=ref\n");
5870 spec->board_config = STAC_D945_REF;
5871 goto again;
5872 }
5873 err = -EINVAL;
5874 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005875 if (err < 0) {
5876 stac92xx_free(codec);
5877 return err;
5878 }
5879
5880 codec->patch_ops = stac92xx_patch_ops;
5881
Takashi Iwai807a46362007-05-29 19:01:37 +02005882 /* Fix Mux capture level; max to 2 */
5883 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5884 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5885 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5886 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5887 (0 << AC_AMPCAP_MUTE_SHIFT));
5888
Matt Porter3cc08dc2006-01-23 15:27:49 +01005889 return 0;
5890}
5891
5892static int patch_stac927x(struct hda_codec *codec)
5893{
5894 struct sigmatel_spec *spec;
5895 int err;
5896
5897 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5898 if (spec == NULL)
5899 return -ENOMEM;
5900
Takashi Iwaia252c812009-12-25 22:56:20 +01005901 codec->no_trigger_sense = 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005902 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01005903 spec->linear_tone_beep = 1;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005904 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005905 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005906 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005907 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5908 stac927x_models,
5909 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005910 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005911 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005912 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5913 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005914 else
5915 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005916 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005917
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005918 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005919 spec->adc_nids = stac927x_adc_nids;
5920 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5921 spec->mux_nids = stac927x_mux_nids;
5922 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005923 spec->smux_nids = stac927x_smux_nids;
5924 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005925 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005926 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005927 spec->multiout.dac_nids = spec->dac_nids;
5928
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005929 if (spec->board_config != STAC_D965_REF) {
5930 /* GPIO0 High = Enable EAPD */
5931 spec->eapd_mask = spec->gpio_mask = 0x01;
5932 spec->gpio_dir = spec->gpio_data = 0x01;
5933 }
5934
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005935 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005936 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005937 case STAC_D965_5ST:
5938 /* GPIO0 High = Enable EAPD */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005939 spec->num_dmics = 0;
Tobin Davis93ed1502006-09-01 21:03:12 +02005940 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005941 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005942 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005943 switch (codec->subsystem_id) {
5944 case 0x10280209:
5945 case 0x1028022e:
5946 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005947 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005948 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005949 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005950 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005951 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005952 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005953 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005954 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005955 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005956 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005957 case STAC_DELL_3ST:
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005958 if (codec->subsystem_id != 0x1028022f) {
5959 /* GPIO2 High = Enable EAPD */
5960 spec->eapd_mask = spec->gpio_mask = 0x04;
5961 spec->gpio_dir = spec->gpio_data = 0x04;
5962 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005963 spec->dmic_nids = stac927x_dmic_nids;
5964 spec->num_dmics = STAC927X_NUM_DMICS;
5965
Takashi Iwaiccca7cd2009-10-13 15:32:21 +02005966 spec->init = dell_3st_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005967 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005968 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005969 break;
Takashi Iwai54930532009-10-11 17:38:29 +02005970 case STAC_927X_VOLKNOB:
5971 spec->num_dmics = 0;
5972 spec->init = stac927x_volknob_core_init;
5973 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005974 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005975 spec->num_dmics = 0;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005976 spec->init = stac927x_core_init;
Takashi Iwaiaf6ee302009-09-14 15:03:12 +02005977 break;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005978 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005979
Takashi Iwai6479c632009-07-28 18:20:25 +02005980 spec->num_caps = STAC927X_NUM_CAPS;
5981 spec->capvols = stac927x_capvols;
5982 spec->capsws = stac927x_capsws;
5983
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005984 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005985 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005986 spec->aloopback_mask = 0x40;
5987 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005988 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005989
Matt Porter3cc08dc2006-01-23 15:27:49 +01005990 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005991 if (!err) {
5992 if (spec->board_config < 0) {
5993 printk(KERN_WARNING "hda_codec: No auto-config is "
5994 "available, default to model=ref\n");
5995 spec->board_config = STAC_D965_REF;
5996 goto again;
5997 }
5998 err = -EINVAL;
5999 }
Mattc7d4b2f2005-06-27 14:59:41 +02006000 if (err < 0) {
6001 stac92xx_free(codec);
6002 return err;
6003 }
Matt2f2f4252005-04-13 14:45:30 +02006004
6005 codec->patch_ops = stac92xx_patch_ops;
6006
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006007 codec->proc_widget_hook = stac927x_proc_hook;
6008
Takashi Iwai52987652008-01-16 16:09:47 +01006009 /*
6010 * !!FIXME!!
6011 * The STAC927x seem to require fairly long delays for certain
6012 * command sequences. With too short delays (even if the answer
6013 * is set to RIRB properly), it results in the silence output
6014 * on some hardwares like Dell.
6015 *
6016 * The below flag enables the longer delay (see get_response
6017 * in hda_intel.c).
6018 */
6019 codec->bus->needs_damn_long_delay = 1;
6020
Takashi Iwaie28d8322008-12-17 13:48:29 +01006021 /* no jack detecion for ref-no-jd model */
6022 if (spec->board_config == STAC_D965_REF_NO_JD)
6023 spec->hp_detect = 0;
6024
Matt2f2f4252005-04-13 14:45:30 +02006025 return 0;
6026}
6027
Matt Porterf3302a52006-07-31 12:49:34 +02006028static int patch_stac9205(struct hda_codec *codec)
6029{
6030 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02006031 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02006032
6033 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6034 if (spec == NULL)
6035 return -ENOMEM;
6036
Takashi Iwaia252c812009-12-25 22:56:20 +01006037 codec->no_trigger_sense = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006038 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006039 spec->linear_tone_beep = 1;
Takashi Iwaia4eed132007-07-06 18:17:04 +02006040 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02006041 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01006042 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
6043 stac9205_models,
6044 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006045 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01006046 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006047 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6048 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01006049 else
6050 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01006051 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02006052
Matthew Ranostay1cd22242008-07-18 18:20:52 +02006053 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02006054 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02006055 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02006056 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01006057 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02006058 spec->smux_nids = stac9205_smux_nids;
6059 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02006060 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02006061 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006062 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01006063 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01006064 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02006065
6066 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01006067 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02006068
Takashi Iwai6479c632009-07-28 18:20:25 +02006069 spec->num_caps = STAC9205_NUM_CAPS;
6070 spec->capvols = stac9205_capvols;
6071 spec->capsws = stac9205_capsws;
6072
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006073 spec->aloopback_mask = 0x40;
6074 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01006075 /* Turn on/off EAPD per HP plugging */
6076 if (spec->board_config != STAC_9205_EAPD)
6077 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02006078 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02006079
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006080 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006081 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02006082 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01006083 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
6084 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01006085
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006086 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006087 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
6088 if (err < 0)
6089 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01006090 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006091 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6092 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01006093 AC_VERB_SET_UNSOLICITED_ENABLE,
6094 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006095
6096 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006097 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006098 spec->gpio_mask = 0x1b;
6099 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01006100 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006101 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02006102 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006103 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006104 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04006105 case STAC_9205_REF:
6106 /* SPDIF-In enabled */
6107 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006108 default:
6109 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02006110 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01006111 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02006112 break;
6113 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02006114
Matt Porterf3302a52006-07-31 12:49:34 +02006115 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01006116 if (!err) {
6117 if (spec->board_config < 0) {
6118 printk(KERN_WARNING "hda_codec: No auto-config is "
6119 "available, default to model=ref\n");
6120 spec->board_config = STAC_9205_REF;
6121 goto again;
6122 }
6123 err = -EINVAL;
6124 }
Matt Porterf3302a52006-07-31 12:49:34 +02006125 if (err < 0) {
6126 stac92xx_free(codec);
6127 return err;
6128 }
6129
6130 codec->patch_ops = stac92xx_patch_ops;
6131
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006132 codec->proc_widget_hook = stac9205_proc_hook;
6133
Matt Porterf3302a52006-07-31 12:49:34 +02006134 return 0;
6135}
6136
Matt2f2f4252005-04-13 14:45:30 +02006137/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006138 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006139 */
6140
Takashi Iwai1e137f92009-01-21 07:41:22 +01006141static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006142 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006143 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6144 {}
6145};
6146
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006147static hda_nid_t stac9872_pin_nids[] = {
6148 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6149 0x11, 0x13, 0x14,
6150};
6151
6152static hda_nid_t stac9872_adc_nids[] = {
6153 0x8 /*,0x6*/
6154};
6155
6156static hda_nid_t stac9872_mux_nids[] = {
6157 0x15
6158};
6159
Takashi Iwai6479c632009-07-28 18:20:25 +02006160static unsigned long stac9872_capvols[] = {
6161 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6162};
6163#define stac9872_capsws stac9872_capvols
6164
Takashi Iwai307282c2009-03-12 18:17:58 +01006165static unsigned int stac9872_vaio_pin_configs[9] = {
6166 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6167 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6168 0x90a7013e
6169};
6170
6171static const char *stac9872_models[STAC_9872_MODELS] = {
6172 [STAC_9872_AUTO] = "auto",
6173 [STAC_9872_VAIO] = "vaio",
6174};
6175
6176static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6177 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6178};
6179
6180static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006181 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6182 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006183 {} /* terminator */
6184};
6185
Guillaume Munch6d859062006-08-22 17:15:47 +02006186static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006187{
6188 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006189 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006190
Takashi Iwaidb064e52006-03-16 16:04:58 +01006191 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6192 if (spec == NULL)
6193 return -ENOMEM;
Takashi Iwaia252c812009-12-25 22:56:20 +01006194 codec->no_trigger_sense = 1;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006195 codec->spec = spec;
Daniel J Blueman1b0e3722010-08-03 11:09:13 +01006196 spec->linear_tone_beep = 1;
Takashi Iwaib04add92009-07-20 08:01:36 +02006197 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6198 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006199
6200 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6201 stac9872_models,
6202 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006203 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006204 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6205 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006206 else
6207 stac92xx_set_config_regs(codec,
6208 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006209
Takashi Iwai1e137f92009-01-21 07:41:22 +01006210 spec->multiout.dac_nids = spec->dac_nids;
6211 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6212 spec->adc_nids = stac9872_adc_nids;
6213 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6214 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006215 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006216 spec->num_caps = 1;
6217 spec->capvols = stac9872_capvols;
6218 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006219
Takashi Iwai1e137f92009-01-21 07:41:22 +01006220 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6221 if (err < 0) {
6222 stac92xx_free(codec);
6223 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006224 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006225 spec->input_mux = &spec->private_imux;
6226 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006227 return 0;
6228}
6229
6230
6231/*
Matt2f2f4252005-04-13 14:45:30 +02006232 * patch entries
6233 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006234static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006235 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6236 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6237 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6238 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6239 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6240 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6241 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006242 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6243 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6244 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6245 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6246 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6247 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006248 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6249 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6250 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6251 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6252 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6253 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6254 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6255 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6256 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6257 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006258 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6259 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6260 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6261 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6262 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6263 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006264 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6265 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006266 /* The following does not take into account .id=0x83847661 when subsys =
6267 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6268 * currently not fully supported.
6269 */
6270 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6271 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6272 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006273 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006274 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6275 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6276 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6277 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6278 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6279 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6280 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6281 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006282 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006283 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
Vitaliy Kulikova9694fa2010-02-04 08:58:23 +01006284 { .id = 0x111d76d4, .name = "92HD83C1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006285 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006286 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Charles Chin8a345a02010-08-10 11:43:25 +02006287 { .id = 0x111d76d1, .name = "92HD87B1/3", .patch = patch_stac92hd83xxx},
6288 { .id = 0x111d76d9, .name = "92HD87B2/4", .patch = patch_stac92hd83xxx},
Charles Chin36706002010-01-29 12:05:51 +01006289 { .id = 0x111d7666, .name = "92HD88B3", .patch = patch_stac92hd83xxx},
6290 { .id = 0x111d7667, .name = "92HD88B1", .patch = patch_stac92hd83xxx},
6291 { .id = 0x111d7668, .name = "92HD88B2", .patch = patch_stac92hd83xxx},
6292 { .id = 0x111d7669, .name = "92HD88B4", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006293 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006294 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6295 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006296 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006297 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6298 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6299 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6300 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6301 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6302 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6303 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6304 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Charles Chin4d8ec5f2010-08-19 08:06:16 +02006305 { .id = 0x111d76c0, .name = "92HD89C3", .patch = patch_stac92hd73xx },
6306 { .id = 0x111d76c1, .name = "92HD89C2", .patch = patch_stac92hd73xx },
6307 { .id = 0x111d76c2, .name = "92HD89C1", .patch = patch_stac92hd73xx },
6308 { .id = 0x111d76c3, .name = "92HD89B3", .patch = patch_stac92hd73xx },
6309 { .id = 0x111d76c4, .name = "92HD89B2", .patch = patch_stac92hd73xx },
6310 { .id = 0x111d76c5, .name = "92HD89B1", .patch = patch_stac92hd73xx },
6311 { .id = 0x111d76c6, .name = "92HD89E3", .patch = patch_stac92hd73xx },
6312 { .id = 0x111d76c7, .name = "92HD89E2", .patch = patch_stac92hd73xx },
6313 { .id = 0x111d76c8, .name = "92HD89E1", .patch = patch_stac92hd73xx },
6314 { .id = 0x111d76c9, .name = "92HD89D3", .patch = patch_stac92hd73xx },
6315 { .id = 0x111d76ca, .name = "92HD89D2", .patch = patch_stac92hd73xx },
6316 { .id = 0x111d76cb, .name = "92HD89D1", .patch = patch_stac92hd73xx },
6317 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6318 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6319 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
Vitaliy Kulikovab5a6eb2010-09-08 09:00:17 +02006320 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
6321 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
Matt2f2f4252005-04-13 14:45:30 +02006322 {} /* terminator */
6323};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006324
6325MODULE_ALIAS("snd-hda-codec-id:8384*");
6326MODULE_ALIAS("snd-hda-codec-id:111d*");
6327
6328MODULE_LICENSE("GPL");
6329MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6330
6331static struct hda_codec_preset_list sigmatel_list = {
6332 .preset = snd_hda_preset_sigmatel,
6333 .owner = THIS_MODULE,
6334};
6335
6336static int __init patch_sigmatel_init(void)
6337{
6338 return snd_hda_add_codec_preset(&sigmatel_list);
6339}
6340
6341static void __exit patch_sigmatel_exit(void)
6342{
6343 snd_hda_delete_codec_preset(&sigmatel_list);
6344}
6345
6346module_init(patch_sigmatel_init)
6347module_exit(patch_sigmatel_exit)