blob: c878dfa369b7626eb78c38b58b216b028833bf51 [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>
31#include <sound/core.h>
Mattc7d4b2f2005-06-27 14:59:41 +020032#include <sound/asoundef.h>
Matthew Ranostay45a6ac12008-10-15 14:45:38 -040033#include <sound/jack.h>
Matt2f2f4252005-04-13 14:45:30 +020034#include "hda_codec.h"
35#include "hda_local.h"
Matthew Ranostay1cd22242008-07-18 18:20:52 +020036#include "hda_beep.h"
Matt2f2f4252005-04-13 14:45:30 +020037
Takashi Iwaic6e4c662008-11-25 11:58:19 +010038enum {
39 STAC_VREF_EVENT = 1,
40 STAC_INSERT_EVENT,
41 STAC_PWR_EVENT,
42 STAC_HP_EVENT,
Takashi Iwaifefd67f2009-07-30 18:03:05 +020043 STAC_LO_EVENT,
Takashi Iwai3d21d3f2009-07-29 14:32:56 +020044 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010045};
Matt4e550962005-07-04 17:51:39 +020046
Takashi Iwaif5fcc132006-11-24 17:07:44 +010047enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010048 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010049 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010050 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020051 STAC_9200_DELL_D21,
52 STAC_9200_DELL_D22,
53 STAC_9200_DELL_D23,
54 STAC_9200_DELL_M21,
55 STAC_9200_DELL_M22,
56 STAC_9200_DELL_M23,
57 STAC_9200_DELL_M24,
58 STAC_9200_DELL_M25,
59 STAC_9200_DELL_M26,
60 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020061 STAC_9200_M4,
62 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010063 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010064 STAC_9200_MODELS
65};
66
67enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010068 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010069 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020070 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020071 STAC_9205_DELL_M43,
72 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010073 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010074 STAC_9205_MODELS
75};
76
77enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010078 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010079 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010080 STAC_92HD73XX_REF,
Wu Fengguangae709442009-08-19 17:05:11 +080081 STAC_92HD73XX_INTEL,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010082 STAC_DELL_M6_AMIC,
83 STAC_DELL_M6_DMIC,
84 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050085 STAC_DELL_EQ,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010086 STAC_92HD73XX_MODELS
87};
88
89enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010090 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020091 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050092 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050093 STAC_DELL_S14,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020094 STAC_92HD83XXX_MODELS
95};
96
97enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010098 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +010099 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100100 STAC_DELL_M4_1,
101 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500102 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400103 STAC_HP_M4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100104 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100105 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400106 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100107 STAC_92HD71BXX_MODELS
108};
109
110enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100111 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100112 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200113 STAC_M1,
114 STAC_M1_2,
115 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100116 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200117 STAC_M3,
118 STAC_M5,
119 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100120 STAC_925x_MODELS
121};
122
123enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100124 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100125 STAC_D945_REF,
126 STAC_D945GTP3,
127 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200128 STAC_INTEL_MAC_V1,
129 STAC_INTEL_MAC_V2,
130 STAC_INTEL_MAC_V3,
131 STAC_INTEL_MAC_V4,
132 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800133 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
134 * is given, one of the above models will be
135 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200136 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100137 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100138 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100139 STAC_MACBOOK_PRO_V1,
140 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200141 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200142 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300143 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200144 STAC_922X_DELL_D81,
145 STAC_922X_DELL_D82,
146 STAC_922X_DELL_M81,
147 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100148 STAC_922X_MODELS
149};
150
151enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100152 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100153 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100154 STAC_D965_REF,
155 STAC_D965_3ST,
156 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200157 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200158 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100159 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100160 STAC_927X_MODELS
161};
Matt Porter403d1942005-11-29 15:00:51 +0100162
Takashi Iwai307282c2009-03-12 18:17:58 +0100163enum {
164 STAC_9872_AUTO,
165 STAC_9872_VAIO,
166 STAC_9872_MODELS
167};
168
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400169struct sigmatel_event {
170 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100171 unsigned char type;
172 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400173 int data;
174};
175
176struct sigmatel_jack {
177 hda_nid_t nid;
178 int type;
179 struct snd_jack *jack;
180};
181
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200182struct sigmatel_mic_route {
183 hda_nid_t pin;
184 unsigned char mux_idx;
185 unsigned char dmux_idx;
186};
187
Matt2f2f4252005-04-13 14:45:30 +0200188struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100189 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200190 unsigned int num_mixers;
191
Matt Porter403d1942005-11-29 15:00:51 +0100192 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500193 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200194 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100195 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100196 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400197 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100198 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200199 unsigned int auto_mic:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200200
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100201 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200202 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100203 unsigned int gpio_mask;
204 unsigned int gpio_dir;
205 unsigned int gpio_data;
206 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200207 unsigned int gpio_led;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100208
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200209 /* stream */
210 unsigned int stream_delay;
211
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100212 /* analog loopback */
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100213 struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100214 unsigned char aloopback_mask;
215 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200216
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100217 /* power management */
218 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200219 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100220 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100221 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100222
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400223 /* jack detection */
224 struct snd_array jacks;
225
226 /* events */
227 struct snd_array events;
228
Matt2f2f4252005-04-13 14:45:30 +0200229 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100230 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400231 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100232 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200233 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100234 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100235 hda_nid_t hp_dacs[5];
236 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200237
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100238 int volume_offset;
239
Matt2f2f4252005-04-13 14:45:30 +0200240 /* capture */
241 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200242 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200243 hda_nid_t *mux_nids;
244 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200245 hda_nid_t *dmic_nids;
246 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100247 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100248 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200249 hda_nid_t *smux_nids;
250 unsigned int num_smuxes;
Takashi Iwai5207e102009-07-30 13:09:08 +0200251 unsigned int num_analog_muxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200252
253 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
254 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
255 unsigned int num_caps; /* number of capture volume/switch elements */
256
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200257 struct sigmatel_mic_route ext_mic;
258 struct sigmatel_mic_route int_mic;
259
Matthew Ranostay65973632008-09-16 10:39:37 -0400260 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200261
Mattdabbed62005-06-14 10:19:34 +0200262 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100263 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200264 hda_nid_t anabeep_nid;
265 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200266
Matt2f2f4252005-04-13 14:45:30 +0200267 /* pin widgets */
268 hda_nid_t *pin_nids;
269 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200270
271 /* codec specific stuff */
272 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100273 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200274
275 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200276 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100277 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200278 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100279 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200280 struct hda_input_mux *sinput_mux;
281 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400282 unsigned int cur_amux;
283 hda_nid_t *amp_nids;
284 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200285 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200286
Matt Porter403d1942005-11-29 15:00:51 +0100287 /* i/o switches */
288 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200289 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100290 hda_nid_t line_switch; /* shared line-in for input and output */
291 hda_nid_t mic_switch; /* shared mic-in for input and output */
292 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200293 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200294
Mattc7d4b2f2005-06-27 14:59:41 +0200295 struct hda_pcm pcm_rec[2]; /* PCM information */
296
297 /* dynamic controls and input_mux */
298 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200299 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200300 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200301 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200302 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400303 struct hda_input_mux private_amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100304 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200305};
306
307static hda_nid_t stac9200_adc_nids[1] = {
308 0x03,
309};
310
311static hda_nid_t stac9200_mux_nids[1] = {
312 0x0c,
313};
314
315static hda_nid_t stac9200_dac_nids[1] = {
316 0x02,
317};
318
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100319static hda_nid_t stac92hd73xx_pwr_nids[8] = {
320 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
321 0x0f, 0x10, 0x11
322};
323
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400324static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
325 0x26, 0,
326};
327
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100328static hda_nid_t stac92hd73xx_adc_nids[2] = {
329 0x1a, 0x1b
330};
331
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400332#define DELL_M6_AMP 2
333static hda_nid_t stac92hd73xx_amp_nids[3] = {
334 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400335};
336
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100337#define STAC92HD73XX_NUM_DMICS 2
338static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
339 0x13, 0x14, 0
340};
341
342#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100343
344static hda_nid_t stac92hd73xx_mux_nids[4] = {
345 0x28, 0x29, 0x2a, 0x2b,
346};
347
348static hda_nid_t stac92hd73xx_dmux_nids[2] = {
349 0x20, 0x21,
350};
351
Matthew Ranostayd9737752008-09-07 12:03:41 +0200352static hda_nid_t stac92hd73xx_smux_nids[2] = {
353 0x22, 0x23,
354};
355
Takashi Iwai6479c632009-07-28 18:20:25 +0200356#define STAC92HD73XX_NUM_CAPS 2
357static unsigned long stac92hd73xx_capvols[] = {
358 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
359 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
360};
361#define stac92hd73xx_capsws stac92hd73xx_capvols
362
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200363#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200364
Takashi Iwai667067d2009-08-13 18:14:42 +0200365static hda_nid_t stac92hd83xxx_mux_nids[2] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200366 0x17, 0x18,
367};
368
369static hda_nid_t stac92hd83xxx_adc_nids[2] = {
370 0x15, 0x16,
371};
372
373static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
374 0xa, 0xb, 0xd, 0xe,
375};
376
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400377static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
378 0x1e, 0,
379};
380
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200381static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500382 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200383};
384
Takashi Iwai6479c632009-07-28 18:20:25 +0200385#define STAC92HD83XXX_NUM_CAPS 2
386static unsigned long stac92hd83xxx_capvols[] = {
387 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
388 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
389};
390#define stac92hd83xxx_capsws stac92hd83xxx_capvols
391
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100392static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
393 0x0a, 0x0d, 0x0f
394};
395
Matthew Ranostaye035b842007-11-06 11:53:55 +0100396static hda_nid_t stac92hd71bxx_adc_nids[2] = {
397 0x12, 0x13,
398};
399
400static hda_nid_t stac92hd71bxx_mux_nids[2] = {
401 0x1a, 0x1b
402};
403
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400404static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
405 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100406};
407
Matthew Ranostayd9737752008-09-07 12:03:41 +0200408static hda_nid_t stac92hd71bxx_smux_nids[2] = {
409 0x24, 0x25,
410};
411
Matthew Ranostaye035b842007-11-06 11:53:55 +0100412#define STAC92HD71BXX_NUM_DMICS 2
413static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
414 0x18, 0x19, 0
415};
416
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400417static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
418 0x22, 0
419};
420
Takashi Iwai6479c632009-07-28 18:20:25 +0200421#define STAC92HD71BXX_NUM_CAPS 2
422static unsigned long stac92hd71bxx_capvols[] = {
423 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
424 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
425};
426#define stac92hd71bxx_capsws stac92hd71bxx_capvols
427
Tobin Davis8e21c342007-01-08 11:04:17 +0100428static hda_nid_t stac925x_adc_nids[1] = {
429 0x03,
430};
431
432static hda_nid_t stac925x_mux_nids[1] = {
433 0x0f,
434};
435
436static hda_nid_t stac925x_dac_nids[1] = {
437 0x02,
438};
439
Takashi Iwaif6e98522007-10-16 14:27:04 +0200440#define STAC925X_NUM_DMICS 1
441static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
442 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200443};
444
Takashi Iwai1697055e2007-12-18 18:05:52 +0100445static hda_nid_t stac925x_dmux_nids[1] = {
446 0x14,
447};
448
Takashi Iwai6479c632009-07-28 18:20:25 +0200449static unsigned long stac925x_capvols[] = {
450 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
451};
452static unsigned long stac925x_capsws[] = {
453 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
454};
455
Matt2f2f4252005-04-13 14:45:30 +0200456static hda_nid_t stac922x_adc_nids[2] = {
457 0x06, 0x07,
458};
459
460static hda_nid_t stac922x_mux_nids[2] = {
461 0x12, 0x13,
462};
463
Takashi Iwai6479c632009-07-28 18:20:25 +0200464#define STAC922X_NUM_CAPS 2
465static unsigned long stac922x_capvols[] = {
466 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
467 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
468};
469#define stac922x_capsws stac922x_capvols
470
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500471static hda_nid_t stac927x_slave_dig_outs[2] = {
472 0x1f, 0,
473};
474
Matt Porter3cc08dc2006-01-23 15:27:49 +0100475static hda_nid_t stac927x_adc_nids[3] = {
476 0x07, 0x08, 0x09
477};
478
479static hda_nid_t stac927x_mux_nids[3] = {
480 0x15, 0x16, 0x17
481};
482
Matthew Ranostayd9737752008-09-07 12:03:41 +0200483static hda_nid_t stac927x_smux_nids[1] = {
484 0x21,
485};
486
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100487static hda_nid_t stac927x_dac_nids[6] = {
488 0x02, 0x03, 0x04, 0x05, 0x06, 0
489};
490
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100491static hda_nid_t stac927x_dmux_nids[1] = {
492 0x1b,
493};
494
Matthew Ranostay7f168592007-10-18 17:38:17 +0200495#define STAC927X_NUM_DMICS 2
496static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
497 0x13, 0x14, 0
498};
499
Takashi Iwai6479c632009-07-28 18:20:25 +0200500#define STAC927X_NUM_CAPS 3
501static unsigned long stac927x_capvols[] = {
502 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
503 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
504 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
505};
506static unsigned long stac927x_capsws[] = {
507 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
508 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
509 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
510};
511
Matthew Ranostay65973632008-09-16 10:39:37 -0400512static const char *stac927x_spdif_labels[5] = {
513 "Digital Playback", "ADAT", "Analog Mux 1",
514 "Analog Mux 2", "Analog Mux 3"
515};
516
Matt Porterf3302a52006-07-31 12:49:34 +0200517static hda_nid_t stac9205_adc_nids[2] = {
518 0x12, 0x13
519};
520
521static hda_nid_t stac9205_mux_nids[2] = {
522 0x19, 0x1a
523};
524
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100525static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100526 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100527};
528
Matthew Ranostayd9737752008-09-07 12:03:41 +0200529static hda_nid_t stac9205_smux_nids[1] = {
530 0x21,
531};
532
Takashi Iwaif6e98522007-10-16 14:27:04 +0200533#define STAC9205_NUM_DMICS 2
534static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
535 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200536};
537
Takashi Iwai6479c632009-07-28 18:20:25 +0200538#define STAC9205_NUM_CAPS 2
539static unsigned long stac9205_capvols[] = {
540 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
541 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
542};
543static unsigned long stac9205_capsws[] = {
544 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
545 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
546};
547
Mattc7d4b2f2005-06-27 14:59:41 +0200548static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200549 0x08, 0x09, 0x0d, 0x0e,
550 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200551};
552
Tobin Davis8e21c342007-01-08 11:04:17 +0100553static hda_nid_t stac925x_pin_nids[8] = {
554 0x07, 0x08, 0x0a, 0x0b,
555 0x0c, 0x0d, 0x10, 0x11,
556};
557
Matt2f2f4252005-04-13 14:45:30 +0200558static hda_nid_t stac922x_pin_nids[10] = {
559 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
560 0x0f, 0x10, 0x11, 0x15, 0x1b,
561};
562
Matthew Ranostaya7662642008-02-21 07:51:14 +0100563static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100564 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
565 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200566 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100567};
568
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500569static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200570 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500571 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200572};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500573
574#define STAC92HD71BXX_NUM_PINS 13
575static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
576 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
577 0x00, 0x14, 0x18, 0x19, 0x1e,
578 0x1f, 0x20, 0x27
579};
580static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100581 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
582 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500583 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100584};
585
Matt Porter3cc08dc2006-01-23 15:27:49 +0100586static hda_nid_t stac927x_pin_nids[14] = {
587 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
588 0x0f, 0x10, 0x11, 0x12, 0x13,
589 0x14, 0x21, 0x22, 0x23,
590};
591
Matt Porterf3302a52006-07-31 12:49:34 +0200592static hda_nid_t stac9205_pin_nids[12] = {
593 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
594 0x0f, 0x14, 0x16, 0x17, 0x18,
595 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200596};
597
Matthew Ranostay89385032008-09-11 09:49:39 -0400598#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
599
600static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
601 struct snd_ctl_elem_value *ucontrol)
602{
603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
604 struct sigmatel_spec *spec = codec->spec;
605 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
606
607 kcontrol->private_value ^= get_amp_nid(kcontrol);
608 kcontrol->private_value |= nid;
609
610 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
611}
612
613static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
614 struct snd_ctl_elem_value *ucontrol)
615{
616 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
617 struct sigmatel_spec *spec = codec->spec;
618 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
619
620 kcontrol->private_value ^= get_amp_nid(kcontrol);
621 kcontrol->private_value |= nid;
622
623 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
624}
625
Matt Porter8b657272006-10-26 17:12:59 +0200626static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
627 struct snd_ctl_elem_info *uinfo)
628{
629 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
630 struct sigmatel_spec *spec = codec->spec;
631 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
632}
633
634static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
635 struct snd_ctl_elem_value *ucontrol)
636{
637 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
638 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100639 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200640
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100641 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200642 return 0;
643}
644
645static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
646 struct snd_ctl_elem_value *ucontrol)
647{
648 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
649 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100650 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200651
652 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100653 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200654}
655
Matthew Ranostayd9737752008-09-07 12:03:41 +0200656static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
657 struct snd_ctl_elem_info *uinfo)
658{
659 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
660 struct sigmatel_spec *spec = codec->spec;
661 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
662}
663
664static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
665 struct snd_ctl_elem_value *ucontrol)
666{
667 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
668 struct sigmatel_spec *spec = codec->spec;
669 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
670
671 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
672 return 0;
673}
674
675static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
676 struct snd_ctl_elem_value *ucontrol)
677{
678 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
679 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400680 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200681 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400682 int err, val;
683 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200684
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400685 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200686 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400687 if (err < 0)
688 return err;
689
690 if (spec->spdif_mute) {
691 if (smux_idx == 0)
692 nid = spec->multiout.dig_out_nid;
693 else
694 nid = codec->slave_dig_outs[smux_idx - 1];
695 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100696 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400697 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100698 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400699 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100700 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
701 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400702 }
703 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200704}
705
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200706static unsigned int stac92xx_vref_set(struct hda_codec *codec,
707 hda_nid_t nid, unsigned int new_vref)
708{
Takashi Iwaib8621512009-06-22 08:00:10 +0200709 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200710 unsigned int pincfg;
711 pincfg = snd_hda_codec_read(codec, nid, 0,
712 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
713
714 pincfg &= 0xff;
715 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
716 pincfg |= new_vref;
717
718 if (new_vref == AC_PINCTL_VREF_HIZ)
719 pincfg |= AC_PINCTL_OUT_EN;
720 else
721 pincfg |= AC_PINCTL_IN_EN;
722
723 error = snd_hda_codec_write_cache(codec, nid, 0,
724 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
725 if (error < 0)
726 return error;
727 else
728 return 1;
729}
730
731static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
732{
733 unsigned int vref;
734 vref = snd_hda_codec_read(codec, nid, 0,
735 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
736 vref &= AC_PINCTL_VREFEN;
737 return vref;
738}
739
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100740static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200741{
742 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
743 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200744 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200745}
746
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100747static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200748{
749 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
750 struct sigmatel_spec *spec = codec->spec;
751 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
752
753 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
754 return 0;
755}
756
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100757static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200758{
759 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
760 struct sigmatel_spec *spec = codec->spec;
761 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwai5207e102009-07-30 13:09:08 +0200762 const struct hda_input_mux *imux = spec->input_mux;
763 unsigned int idx, prev_idx;
Matt2f2f4252005-04-13 14:45:30 +0200764
Takashi Iwai5207e102009-07-30 13:09:08 +0200765 idx = ucontrol->value.enumerated.item[0];
766 if (idx >= imux->num_items)
767 idx = imux->num_items - 1;
768 prev_idx = spec->cur_mux[adc_idx];
769 if (prev_idx == idx)
770 return 0;
771 if (idx < spec->num_analog_muxes) {
772 snd_hda_codec_write_cache(codec, spec->mux_nids[adc_idx], 0,
773 AC_VERB_SET_CONNECT_SEL,
774 imux->items[idx].index);
775 if (prev_idx >= spec->num_analog_muxes) {
776 imux = spec->dinput_mux;
777 /* 0 = analog */
778 snd_hda_codec_write_cache(codec,
779 spec->dmux_nids[adc_idx], 0,
780 AC_VERB_SET_CONNECT_SEL,
781 imux->items[0].index);
782 }
783 } else {
784 imux = spec->dinput_mux;
785 snd_hda_codec_write_cache(codec, spec->dmux_nids[adc_idx], 0,
786 AC_VERB_SET_CONNECT_SEL,
787 imux->items[idx - 1].index);
788 }
789 spec->cur_mux[adc_idx] = idx;
790 return 1;
Matt2f2f4252005-04-13 14:45:30 +0200791}
792
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100793static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
794 struct snd_ctl_elem_info *uinfo)
795{
796 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
797 struct sigmatel_spec *spec = codec->spec;
798 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
799}
800
801static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
802 struct snd_ctl_elem_value *ucontrol)
803{
804 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
805 struct sigmatel_spec *spec = codec->spec;
806
807 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
808 return 0;
809}
810
811static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
812 struct snd_ctl_elem_value *ucontrol)
813{
814 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
815 struct sigmatel_spec *spec = codec->spec;
816
817 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
818 spec->mono_nid, &spec->cur_mmux);
819}
820
Matthew Ranostay89385032008-09-11 09:49:39 -0400821static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
822 struct snd_ctl_elem_info *uinfo)
823{
824 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
825 struct sigmatel_spec *spec = codec->spec;
826 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
827}
828
829static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
830 struct snd_ctl_elem_value *ucontrol)
831{
832 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
833 struct sigmatel_spec *spec = codec->spec;
834
835 ucontrol->value.enumerated.item[0] = spec->cur_amux;
836 return 0;
837}
838
839static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
840 struct snd_ctl_elem_value *ucontrol)
841{
842 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
843 struct sigmatel_spec *spec = codec->spec;
844 struct snd_kcontrol *ctl =
845 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
846 if (!ctl)
847 return -EINVAL;
848
849 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
850 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
851
852 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
853 0, &spec->cur_amux);
854}
855
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200856#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
857
858static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
859 struct snd_ctl_elem_value *ucontrol)
860{
861 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100862 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200863 struct sigmatel_spec *spec = codec->spec;
864
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100865 ucontrol->value.integer.value[0] = !!(spec->aloopback &
866 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200867 return 0;
868}
869
870static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
871 struct snd_ctl_elem_value *ucontrol)
872{
873 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
874 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100875 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200876 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100877 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200878
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100879 idx_val = spec->aloopback_mask << idx;
880 if (ucontrol->value.integer.value[0])
881 val = spec->aloopback | idx_val;
882 else
883 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100884 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200885 return 0;
886
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100887 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200888
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100889 /* Only return the bits defined by the shift value of the
890 * first two bytes of the mask
891 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200892 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100893 kcontrol->private_value & 0xFFFF, 0x0);
894 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200895
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100896 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200897 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100898 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200899 } else {
900 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100901 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200902 }
903
904 snd_hda_codec_write_cache(codec, codec->afg, 0,
905 kcontrol->private_value >> 16, dac_mode);
906
907 return 1;
908}
909
Mattc7d4b2f2005-06-27 14:59:41 +0200910static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200911 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200912 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200913 {}
914};
915
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200916static struct hda_verb stac9200_eapd_init[] = {
917 /* set dac0mux for dac converter */
918 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
919 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
920 {}
921};
922
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100923static struct hda_verb stac92hd73xx_6ch_core_init[] = {
924 /* set master volume and direct control */
925 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100926 /* setup adcs to point to mixer */
927 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
928 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100929 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
930 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
931 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
932 /* setup import muxs */
933 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
934 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
935 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
936 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
937 {}
938};
939
Matthew Ranostayd654a662008-03-14 08:46:51 +0100940static struct hda_verb dell_eq_core_init[] = {
941 /* set master volume to max value without distortion
942 * and direct control */
943 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100944 /* setup adcs to point to mixer */
945 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
946 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
947 /* setup import muxs */
948 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
949 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
950 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
951 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
952 {}
953};
954
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100955static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500956 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100957 /* setup adcs to point to mixer */
958 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
959 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
960 /* setup import muxs */
961 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
962 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
963 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
964 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
965 {}
966};
967
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100968static struct hda_verb stac92hd73xx_8ch_core_init[] = {
969 /* set master volume and direct control */
970 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100971 /* setup adcs to point to mixer */
972 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
973 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100974 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
975 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
976 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
977 /* setup import muxs */
978 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
979 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
980 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
981 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
982 {}
983};
984
985static struct hda_verb stac92hd73xx_10ch_core_init[] = {
986 /* set master volume and direct control */
987 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100988 /* dac3 is connected to import3 mux */
989 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100990 /* setup adcs to point to mixer */
991 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
992 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100993 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
994 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
995 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
996 /* setup import muxs */
997 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
998 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
999 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
1000 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
1001 {}
1002};
1003
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001004static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001005 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
1006 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
1007 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001008
1009 /* power state controls amps */
1010 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001011 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001012};
1013
Matthew Ranostaye035b842007-11-06 11:53:55 +01001014static struct hda_verb stac92hd71bxx_core_init[] = {
1015 /* set master volume and direct control */
1016 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001017 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +01001018};
1019
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05001020static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
1021 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
1022 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +01001023 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1024 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +01001025 {}
1026};
1027
Tobin Davis8e21c342007-01-08 11:04:17 +01001028static struct hda_verb stac925x_core_init[] = {
1029 /* set dac0mux for dac converter */
1030 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +01001031 /* mute the master volume */
1032 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +01001033 {}
1034};
1035
Mattc7d4b2f2005-06-27 14:59:41 +02001036static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +02001037 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +02001038 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +02001039 {}
1040};
1041
Tobin Davis93ed1502006-09-01 21:03:12 +02001042static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02001043 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +02001044 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +02001045 /* unmute node 0x1b */
1046 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1047 /* select node 0x03 as DAC */
1048 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
1049 {}
1050};
1051
Matt Porter3cc08dc2006-01-23 15:27:49 +01001052static struct hda_verb stac927x_core_init[] = {
1053 /* set master volume and direct control */
1054 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001055 /* enable analog pc beep path */
1056 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +01001057 {}
1058};
1059
Matt Porterf3302a52006-07-31 12:49:34 +02001060static struct hda_verb stac9205_core_init[] = {
1061 /* set master volume and direct control */
1062 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001063 /* enable analog pc beep path */
1064 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +02001065 {}
1066};
1067
Matthew Ranostayb22b4822008-01-22 12:32:30 +01001068#define STAC_MONO_MUX \
1069 { \
1070 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1071 .name = "Mono Mux", \
1072 .count = 1, \
1073 .info = stac92xx_mono_mux_enum_info, \
1074 .get = stac92xx_mono_mux_enum_get, \
1075 .put = stac92xx_mono_mux_enum_put, \
1076 }
1077
Matthew Ranostay89385032008-09-11 09:49:39 -04001078#define STAC_AMP_MUX \
1079 { \
1080 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1081 .name = "Amp Selector Capture Switch", \
1082 .count = 1, \
1083 .info = stac92xx_amp_mux_enum_info, \
1084 .get = stac92xx_amp_mux_enum_get, \
1085 .put = stac92xx_amp_mux_enum_put, \
1086 }
1087
1088#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
1089 { \
1090 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1091 .name = xname, \
1092 .index = 0, \
1093 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1094 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1095 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
1096 .info = stac92xx_amp_volume_info, \
1097 .get = stac92xx_amp_volume_get, \
1098 .put = stac92xx_amp_volume_put, \
1099 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
1100 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
1101 }
1102
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001103#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +02001104 { \
1105 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1106 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001107 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +02001108 .info = stac92xx_aloopback_info, \
1109 .get = stac92xx_aloopback_get, \
1110 .put = stac92xx_aloopback_put, \
1111 .private_value = verb_read | (verb_write << 16), \
1112 }
1113
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02001114#define DC_BIAS(xname, idx, nid) \
1115 { \
1116 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1117 .name = xname, \
1118 .index = idx, \
1119 .info = stac92xx_dc_bias_info, \
1120 .get = stac92xx_dc_bias_get, \
1121 .put = stac92xx_dc_bias_put, \
1122 .private_value = nid, \
1123 }
1124
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001125static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +02001126 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1127 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001128 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1129 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001130 { } /* end */
1131};
1132
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001133#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001134static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001135 /* start of config #1 */
1136 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1137 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1138
1139 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1140 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1141
1142 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1143 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1144
1145 /* start of config #2 */
1146 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1147 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1148
1149 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1150 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1151
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001152 { } /* end */
1153};
1154
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001155static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1156 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1157 {}
1158};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001159
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001160static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1161 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1162 {}
1163};
1164
1165static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1166 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1167 {}
1168};
1169
1170static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001171 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1172 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1173
1174 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1175 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1176
1177 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1178 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1179
1180 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1181 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1182
1183 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1184 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1185 { } /* end */
1186};
1187
1188static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001189 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1190 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1191
1192 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1193 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1194
1195 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1196 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1197
1198 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1199 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1200
1201 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1202 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1203 { } /* end */
1204};
1205
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001206
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001207static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1208 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1209};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001210
Tobin Davis8e21c342007-01-08 11:04:17 +01001211static struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwaic9280d62009-01-15 17:31:00 +01001212 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1213 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001214 { } /* end */
1215};
1216
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001217static struct snd_kcontrol_new stac9205_loopback[] = {
1218 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1219 {}
1220};
1221
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001222static struct snd_kcontrol_new stac927x_loopback[] = {
1223 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1224 {}
1225};
1226
Takashi Iwai1697055e2007-12-18 18:05:52 +01001227static struct snd_kcontrol_new stac_dmux_mixer = {
1228 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1229 .name = "Digital Input Source",
1230 /* count set later */
1231 .info = stac92xx_dmux_enum_info,
1232 .get = stac92xx_dmux_enum_get,
1233 .put = stac92xx_dmux_enum_put,
1234};
1235
Matthew Ranostayd9737752008-09-07 12:03:41 +02001236static struct snd_kcontrol_new stac_smux_mixer = {
1237 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001238 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001239 /* count set later */
1240 .info = stac92xx_smux_enum_info,
1241 .get = stac92xx_smux_enum_get,
1242 .put = stac92xx_smux_enum_put,
1243};
1244
Takashi Iwai2134ea42008-01-10 16:53:55 +01001245static const char *slave_vols[] = {
1246 "Front Playback Volume",
1247 "Surround Playback Volume",
1248 "Center Playback Volume",
1249 "LFE Playback Volume",
1250 "Side Playback Volume",
1251 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001252 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001253 NULL
1254};
1255
1256static const char *slave_sws[] = {
1257 "Front Playback Switch",
1258 "Surround Playback Switch",
1259 "Center Playback Switch",
1260 "LFE Playback Switch",
1261 "Side Playback Switch",
1262 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001263 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001264 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001265 NULL
1266};
1267
Takashi Iwai603c4012008-07-30 15:01:44 +02001268static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001269static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001270
Matt2f2f4252005-04-13 14:45:30 +02001271static int stac92xx_build_controls(struct hda_codec *codec)
1272{
1273 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001274 struct auto_pin_cfg *cfg = &spec->autocfg;
1275 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001276 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001277 int i;
Matt2f2f4252005-04-13 14:45:30 +02001278
Takashi Iwai6479c632009-07-28 18:20:25 +02001279 if (spec->mixer) {
1280 err = snd_hda_add_new_ctls(codec, spec->mixer);
1281 if (err < 0)
1282 return err;
1283 }
Mattc7d4b2f2005-06-27 14:59:41 +02001284
1285 for (i = 0; i < spec->num_mixers; i++) {
1286 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1287 if (err < 0)
1288 return err;
1289 }
Takashi Iwai5207e102009-07-30 13:09:08 +02001290 if (!spec->auto_mic && spec->num_dmuxes > 0 &&
1291 snd_hda_get_bool_hint(codec, "separate_dmux") == 1) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001292 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001293 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001294 snd_ctl_new1(&stac_dmux_mixer, codec));
1295 if (err < 0)
1296 return err;
1297 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001298 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001299 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1300 struct hda_input_mux *smux = &spec->private_smux;
1301 /* check for mute support on SPDIF out */
1302 if (wcaps & AC_WCAP_OUT_AMP) {
1303 smux->items[smux->num_items].label = "Off";
1304 smux->items[smux->num_items].index = 0;
1305 smux->num_items++;
1306 spec->spdif_mute = 1;
1307 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001308 stac_smux_mixer.count = spec->num_smuxes;
Takashi Iwai4f2d23e2008-12-19 10:14:13 +01001309 err = snd_hda_ctl_add(codec,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001310 snd_ctl_new1(&stac_smux_mixer, codec));
1311 if (err < 0)
1312 return err;
1313 }
Mattc7d4b2f2005-06-27 14:59:41 +02001314
Mattdabbed62005-06-14 10:19:34 +02001315 if (spec->multiout.dig_out_nid) {
1316 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1317 if (err < 0)
1318 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001319 err = snd_hda_create_spdif_share_sw(codec,
1320 &spec->multiout);
1321 if (err < 0)
1322 return err;
1323 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001324 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001325 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001326 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1327 if (err < 0)
1328 return err;
1329 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001330
1331 /* if we have no master control, let's create it */
1332 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001333 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001334 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001335 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001336 /* correct volume offset */
1337 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001338 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001339 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001340 if (err < 0)
1341 return err;
1342 }
1343 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1344 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1345 NULL, slave_sws);
1346 if (err < 0)
1347 return err;
1348 }
1349
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001350 if (spec->aloopback_ctl &&
1351 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1352 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1353 if (err < 0)
1354 return err;
1355 }
1356
Takashi Iwai603c4012008-07-30 15:01:44 +02001357 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001358
1359 /* create jack input elements */
1360 if (spec->hp_detect) {
1361 for (i = 0; i < cfg->hp_outs; i++) {
1362 int type = SND_JACK_HEADPHONE;
1363 nid = cfg->hp_pins[i];
1364 /* jack detection */
1365 if (cfg->hp_outs == i)
1366 type |= SND_JACK_LINEOUT;
1367 err = stac92xx_add_jack(codec, nid, type);
1368 if (err < 0)
1369 return err;
1370 }
1371 }
1372 for (i = 0; i < cfg->line_outs; i++) {
1373 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1374 SND_JACK_LINEOUT);
1375 if (err < 0)
1376 return err;
1377 }
1378 for (i = 0; i < AUTO_PIN_LAST; i++) {
1379 nid = cfg->input_pins[i];
1380 if (nid) {
1381 err = stac92xx_add_jack(codec, nid,
1382 SND_JACK_MICROPHONE);
1383 if (err < 0)
1384 return err;
1385 }
1386 }
1387
Mattdabbed62005-06-14 10:19:34 +02001388 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001389}
1390
Matt Porter403d1942005-11-29 15:00:51 +01001391static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001392 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001393 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1394};
1395
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001396static unsigned int gateway9200_m4_pin_configs[8] = {
1397 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1398 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1399};
1400static unsigned int gateway9200_m4_2_pin_configs[8] = {
1401 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1402 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1403};
1404
1405/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001406 STAC 9200 pin configs for
1407 102801A8
1408 102801DE
1409 102801E8
1410*/
1411static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001412 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1413 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001414};
1415
1416/*
1417 STAC 9200 pin configs for
1418 102801C0
1419 102801C1
1420*/
1421static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001422 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1423 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001424};
1425
1426/*
1427 STAC 9200 pin configs for
1428 102801C4 (Dell Dimension E310)
1429 102801C5
1430 102801C7
1431 102801D9
1432 102801DA
1433 102801E3
1434*/
1435static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001436 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1437 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001438};
1439
1440
1441/*
1442 STAC 9200-32 pin configs for
1443 102801B5 (Dell Inspiron 630m)
1444 102801D8 (Dell Inspiron 640m)
1445*/
1446static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001447 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1448 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001449};
1450
1451/*
1452 STAC 9200-32 pin configs for
1453 102801C2 (Dell Latitude D620)
1454 102801C8
1455 102801CC (Dell Latitude D820)
1456 102801D4
1457 102801D6
1458*/
1459static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001460 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1461 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001462};
1463
1464/*
1465 STAC 9200-32 pin configs for
1466 102801CE (Dell XPS M1710)
1467 102801CF (Dell Precision M90)
1468*/
1469static unsigned int dell9200_m23_pin_configs[8] = {
1470 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1471 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1472};
1473
1474/*
1475 STAC 9200-32 pin configs for
1476 102801C9
1477 102801CA
1478 102801CB (Dell Latitude 120L)
1479 102801D3
1480*/
1481static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001482 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1483 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001484};
1485
1486/*
1487 STAC 9200-32 pin configs for
1488 102801BD (Dell Inspiron E1505n)
1489 102801EE
1490 102801EF
1491*/
1492static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001493 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1494 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001495};
1496
1497/*
1498 STAC 9200-32 pin configs for
1499 102801F5 (Dell Inspiron 1501)
1500 102801F6
1501*/
1502static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001503 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1504 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001505};
1506
1507/*
1508 STAC 9200-32
1509 102801CD (Dell Inspiron E1705/9400)
1510*/
1511static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001512 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1513 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001514};
1515
Tobin Davisbf277782008-02-03 20:31:47 +01001516static unsigned int oqo9200_pin_configs[8] = {
1517 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1518 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1519};
1520
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001521
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001522static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1523 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001524 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001525 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1526 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1527 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1528 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1529 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1530 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1531 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1532 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1533 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1534 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001535 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1536 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001537 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001538};
1539
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001540static const char *stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001541 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001542 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001543 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001544 [STAC_9200_DELL_D21] = "dell-d21",
1545 [STAC_9200_DELL_D22] = "dell-d22",
1546 [STAC_9200_DELL_D23] = "dell-d23",
1547 [STAC_9200_DELL_M21] = "dell-m21",
1548 [STAC_9200_DELL_M22] = "dell-m22",
1549 [STAC_9200_DELL_M23] = "dell-m23",
1550 [STAC_9200_DELL_M24] = "dell-m24",
1551 [STAC_9200_DELL_M25] = "dell-m25",
1552 [STAC_9200_DELL_M26] = "dell-m26",
1553 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001554 [STAC_9200_M4] = "gateway-m4",
1555 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001556 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001557};
1558
1559static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1560 /* SigmaTel reference board */
1561 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1562 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001563 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1564 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001565 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1567 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001569 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1571 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1573 "unknown Dell", STAC_9200_DELL_D22),
1574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1575 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001577 "Dell Latitude D620", STAC_9200_DELL_M22),
1578 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1579 "unknown Dell", STAC_9200_DELL_D23),
1580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1581 "unknown Dell", STAC_9200_DELL_D23),
1582 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1583 "unknown Dell", STAC_9200_DELL_M22),
1584 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1585 "unknown Dell", STAC_9200_DELL_M24),
1586 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1587 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001588 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001589 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001591 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001593 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001595 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001597 "Dell Precision M90", STAC_9200_DELL_M23),
1598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1599 "unknown Dell", STAC_9200_DELL_M22),
1600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1601 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001602 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001603 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001604 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001605 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1606 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1607 "unknown Dell", STAC_9200_DELL_D23),
1608 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1609 "unknown Dell", STAC_9200_DELL_D23),
1610 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1611 "unknown Dell", STAC_9200_DELL_D21),
1612 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1613 "unknown Dell", STAC_9200_DELL_D23),
1614 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1615 "unknown Dell", STAC_9200_DELL_D21),
1616 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1617 "unknown Dell", STAC_9200_DELL_M25),
1618 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1619 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001620 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001621 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1622 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1623 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001624 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001625 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001626 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001627 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1628 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1629 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001630 /* OQO Mobile */
1631 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001632 {} /* terminator */
1633};
1634
Tobin Davis8e21c342007-01-08 11:04:17 +01001635static unsigned int ref925x_pin_configs[8] = {
1636 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001637 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001638};
1639
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001640static unsigned int stac925xM1_pin_configs[8] = {
1641 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1642 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001643};
1644
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001645static unsigned int stac925xM1_2_pin_configs[8] = {
1646 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1647 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1648};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001649
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001650static unsigned int stac925xM2_pin_configs[8] = {
1651 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1652 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001653};
1654
Tobin Davis8e21c342007-01-08 11:04:17 +01001655static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001656 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1657 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1658};
1659
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001660static unsigned int stac925xM3_pin_configs[8] = {
1661 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1662 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1663};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001664
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001665static unsigned int stac925xM5_pin_configs[8] = {
1666 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1667 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1668};
1669
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001670static unsigned int stac925xM6_pin_configs[8] = {
1671 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1672 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001673};
1674
1675static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1676 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001677 [STAC_M1] = stac925xM1_pin_configs,
1678 [STAC_M1_2] = stac925xM1_2_pin_configs,
1679 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001680 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001681 [STAC_M3] = stac925xM3_pin_configs,
1682 [STAC_M5] = stac925xM5_pin_configs,
1683 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001684};
1685
1686static const char *stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001687 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001688 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001689 [STAC_M1] = "m1",
1690 [STAC_M1_2] = "m1-2",
1691 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001692 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001693 [STAC_M3] = "m3",
1694 [STAC_M5] = "m5",
1695 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001696};
1697
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001698static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001699 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1700 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1701 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1702 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001703 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001704 /* Not sure about the brand name for those */
1705 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1706 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1707 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1708 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001709 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001710};
1711
1712static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1713 /* SigmaTel reference board */
1714 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001715 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001716 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001717
1718 /* Default table for unknown ID */
1719 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1720
Tobin Davis8e21c342007-01-08 11:04:17 +01001721 {} /* terminator */
1722};
1723
Matthew Ranostaya7662642008-02-21 07:51:14 +01001724static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001725 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1726 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1727 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001728 0x01452050,
1729};
1730
1731static unsigned int dell_m6_pin_configs[13] = {
1732 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001733 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001734 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1735 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001736};
1737
1738static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001739 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001740 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1741 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1742 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001743 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001744};
1745
1746static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001747 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001748 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001749 [STAC_92HD73XX_REF] = "ref",
Wu Fengguangae709442009-08-19 17:05:11 +08001750 [STAC_92HD73XX_INTEL] = "intel",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001751 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1752 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1753 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001754 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001755};
1756
1757static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1758 /* SigmaTel reference board */
1759 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001760 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001761 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1762 "DFI LanParty", STAC_92HD73XX_REF),
Wu Fengguangae709442009-08-19 17:05:11 +08001763 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5002,
1764 "Intel DG45ID", STAC_92HD73XX_INTEL),
1765 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5003,
1766 "Intel DG45FC", STAC_92HD73XX_INTEL),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001767 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001768 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001769 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001770 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001771 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001772 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001773 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001774 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001775 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001776 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001777 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001778 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001779 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001780 "unknown Dell", STAC_DELL_M6_DMIC),
1781 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1782 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001783 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001784 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001785 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1786 "Dell Studio 17", STAC_DELL_M6_DMIC),
Takashi Iwai626f5ce2009-07-28 00:54:39 +02001787 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02be,
1788 "Dell Studio 1555", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001789 {} /* terminator */
1790};
1791
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001792static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001793 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1794 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001795 0x01451160, 0x98560170,
1796};
1797
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001798static unsigned int dell_s14_pin_configs[10] = {
1799 0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1800 0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1801 0x40f000f0, 0x40f000f0,
1802};
1803
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001804static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1805 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001806 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001807 [STAC_DELL_S14] = dell_s14_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001808};
1809
1810static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001811 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001812 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001813 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001814 [STAC_DELL_S14] = "dell-s14",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001815};
1816
1817static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1818 /* SigmaTel reference board */
1819 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001820 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001821 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1822 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001823 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1824 "unknown Dell", STAC_DELL_S14),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001825 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001826};
1827
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001828static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001829 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001830 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001831 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1832 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001833};
1834
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001835static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001836 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001837 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001838 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1839 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001840};
1841
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001842static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001843 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1844 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001845 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1846 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001847};
1848
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001849static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001850 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1851 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001852 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1853 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001854};
1855
Matthew Ranostaye035b842007-11-06 11:53:55 +01001856static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1857 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001858 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1859 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001860 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001861 [STAC_HP_M4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001862 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001863 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001864 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001865};
1866
1867static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001868 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001869 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001870 [STAC_DELL_M4_1] = "dell-m4-1",
1871 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001872 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001873 [STAC_HP_M4] = "hp-m4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001874 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001875 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001876 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001877};
1878
1879static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1880 /* SigmaTel reference board */
1881 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1882 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001883 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1884 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001885 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1886 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Takashi Iwai58d83952009-03-13 17:04:34 +01001887 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1888 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001889 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1890 "HP dv4-7", STAC_HP_DV5),
1891 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1892 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001893 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1894 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001895 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001896 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001897 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001898 "HP HDX", STAC_HP_HDX), /* HDX16 */
Takashi Iwai1972d022009-08-06 08:44:43 +02001899 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x7010,
1900 "HP", STAC_HP_DV5),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001901 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1902 "unknown Dell", STAC_DELL_M4_1),
1903 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1904 "unknown Dell", STAC_DELL_M4_1),
1905 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1906 "unknown Dell", STAC_DELL_M4_1),
1907 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1908 "unknown Dell", STAC_DELL_M4_1),
1909 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1910 "unknown Dell", STAC_DELL_M4_1),
1911 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1912 "unknown Dell", STAC_DELL_M4_1),
1913 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1914 "unknown Dell", STAC_DELL_M4_1),
1915 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1916 "unknown Dell", STAC_DELL_M4_2),
1917 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1918 "unknown Dell", STAC_DELL_M4_2),
1919 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1920 "unknown Dell", STAC_DELL_M4_2),
1921 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1922 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001923 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1924 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001925 {} /* terminator */
1926};
1927
Matt Porter403d1942005-11-29 15:00:51 +01001928static unsigned int ref922x_pin_configs[10] = {
1929 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1930 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001931 0x40000100, 0x40000100,
1932};
1933
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001934/*
1935 STAC 922X pin configs for
1936 102801A7
1937 102801AB
1938 102801A9
1939 102801D1
1940 102801D2
1941*/
1942static unsigned int dell_922x_d81_pin_configs[10] = {
1943 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1944 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1945 0x01813122, 0x400001f2,
1946};
1947
1948/*
1949 STAC 922X pin configs for
1950 102801AC
1951 102801D0
1952*/
1953static unsigned int dell_922x_d82_pin_configs[10] = {
1954 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1955 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1956 0x01813122, 0x400001f1,
1957};
1958
1959/*
1960 STAC 922X pin configs for
1961 102801BF
1962*/
1963static unsigned int dell_922x_m81_pin_configs[10] = {
1964 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1965 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1966 0x40C003f1, 0x405003f0,
1967};
1968
1969/*
1970 STAC 9221 A1 pin configs for
1971 102801D7 (Dell XPS M1210)
1972*/
1973static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001974 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1975 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001976 0x508003f3, 0x405003f4,
1977};
1978
Matt Porter403d1942005-11-29 15:00:51 +01001979static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001980 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001981 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1982 0x02a19120, 0x40000100,
1983};
1984
1985static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001986 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1987 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001988 0x02a19320, 0x40000100,
1989};
1990
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001991static unsigned int intel_mac_v1_pin_configs[10] = {
1992 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1993 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001994 0x400000fc, 0x400000fb,
1995};
1996
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001997static unsigned int intel_mac_v2_pin_configs[10] = {
1998 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1999 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02002000 0x400000fc, 0x400000fb,
2001};
2002
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002003static unsigned int intel_mac_v3_pin_configs[10] = {
2004 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2005 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
2006 0x400000fc, 0x400000fb,
2007};
2008
2009static unsigned int intel_mac_v4_pin_configs[10] = {
2010 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2011 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2012 0x400000fc, 0x400000fb,
2013};
2014
2015static unsigned int intel_mac_v5_pin_configs[10] = {
2016 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2017 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2018 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002019};
2020
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002021static unsigned int ecs202_pin_configs[10] = {
2022 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
2023 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
2024 0x9037012e, 0x40e000f2,
2025};
Takashi Iwai76c08822007-06-19 12:17:42 +02002026
Takashi Iwai19039bd2006-06-28 15:52:16 +02002027static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002028 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002029 [STAC_D945GTP3] = d945gtp3_pin_configs,
2030 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002031 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
2032 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
2033 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
2034 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
2035 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002036 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002037 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002038 [STAC_MACMINI] = intel_mac_v3_pin_configs,
2039 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2040 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2041 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2042 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2043 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002044 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002045 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2046 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2047 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2048 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01002049};
2050
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002051static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002052 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002053 [STAC_D945_REF] = "ref",
2054 [STAC_D945GTP5] = "5stack",
2055 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002056 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2057 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2058 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2059 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2060 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08002061 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002062 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002063 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002064 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002065 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2066 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02002067 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002068 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002069 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002070 [STAC_922X_DELL_D81] = "dell-d81",
2071 [STAC_922X_DELL_D82] = "dell-d82",
2072 [STAC_922X_DELL_M81] = "dell-m81",
2073 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002074};
2075
2076static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2077 /* SigmaTel reference board */
2078 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2079 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002080 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2081 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002082 /* Intel 945G based systems */
2083 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2084 "Intel D945G", STAC_D945GTP3),
2085 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2086 "Intel D945G", STAC_D945GTP3),
2087 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2088 "Intel D945G", STAC_D945GTP3),
2089 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2090 "Intel D945G", STAC_D945GTP3),
2091 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2092 "Intel D945G", STAC_D945GTP3),
2093 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2094 "Intel D945G", STAC_D945GTP3),
2095 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2096 "Intel D945G", STAC_D945GTP3),
2097 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2098 "Intel D945G", STAC_D945GTP3),
2099 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2100 "Intel D945G", STAC_D945GTP3),
2101 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2102 "Intel D945G", STAC_D945GTP3),
2103 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2104 "Intel D945G", STAC_D945GTP3),
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2106 "Intel D945G", STAC_D945GTP3),
2107 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2108 "Intel D945G", STAC_D945GTP3),
2109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2110 "Intel D945G", STAC_D945GTP3),
2111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2112 "Intel D945G", STAC_D945GTP3),
2113 /* Intel D945G 5-stack systems */
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2115 "Intel D945G", STAC_D945GTP5),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2117 "Intel D945G", STAC_D945GTP5),
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2119 "Intel D945G", STAC_D945GTP5),
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2121 "Intel D945G", STAC_D945GTP5),
2122 /* Intel 945P based systems */
2123 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2124 "Intel D945P", STAC_D945GTP3),
2125 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2126 "Intel D945P", STAC_D945GTP3),
2127 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2128 "Intel D945P", STAC_D945GTP3),
2129 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2130 "Intel D945P", STAC_D945GTP3),
2131 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2132 "Intel D945P", STAC_D945GTP3),
2133 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2134 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002135 /* other intel */
2136 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2137 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002138 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002139 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002140 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002141 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002142 /* Dell systems */
2143 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2144 "unknown Dell", STAC_922X_DELL_D81),
2145 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2146 "unknown Dell", STAC_922X_DELL_D81),
2147 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2148 "unknown Dell", STAC_922X_DELL_D81),
2149 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2150 "unknown Dell", STAC_922X_DELL_D82),
2151 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2152 "unknown Dell", STAC_922X_DELL_M81),
2153 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2154 "unknown Dell", STAC_922X_DELL_D82),
2155 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2156 "unknown Dell", STAC_922X_DELL_D81),
2157 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2158 "unknown Dell", STAC_922X_DELL_D81),
2159 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2160 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002161 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002162 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002163 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002164 {} /* terminator */
2165};
2166
Matt Porter3cc08dc2006-01-23 15:27:49 +01002167static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002168 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2169 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2170 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2171 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002172};
2173
Tobin Davis93ed1502006-09-01 21:03:12 +02002174static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002175 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2176 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2177 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2178 0x40000100, 0x40000100
2179};
2180
Tobin Davis93ed1502006-09-01 21:03:12 +02002181static unsigned int d965_5st_pin_configs[14] = {
2182 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2183 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2184 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2185 0x40000100, 0x40000100
2186};
2187
Takashi Iwai679d92e2009-05-24 19:00:08 +02002188static unsigned int d965_5st_no_fp_pin_configs[14] = {
2189 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2190 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2191 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2192 0x40000100, 0x40000100
2193};
2194
Tobin Davis4ff076e2007-08-07 11:48:12 +02002195static unsigned int dell_3st_pin_configs[14] = {
2196 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2197 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002198 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002199 0x40c003fc, 0x40000100
2200};
2201
Tobin Davis93ed1502006-09-01 21:03:12 +02002202static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002203 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002204 [STAC_D965_REF] = ref927x_pin_configs,
2205 [STAC_D965_3ST] = d965_3st_pin_configs,
2206 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002207 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002208 [STAC_DELL_3ST] = dell_3st_pin_configs,
2209 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002210};
2211
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002212static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002213 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002214 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002215 [STAC_D965_REF] = "ref",
2216 [STAC_D965_3ST] = "3stack",
2217 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002218 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002219 [STAC_DELL_3ST] = "dell-3stack",
2220 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002221};
2222
2223static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2224 /* SigmaTel reference board */
2225 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2226 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002227 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2228 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002229 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002230 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2231 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002232 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002233 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2234 "Intel D965", STAC_D965_3ST),
2235 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2236 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002237 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002238 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002239 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002240 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2241 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002242 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002243 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2244 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002245 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Chengu Wang84d3dc22009-07-30 19:43:55 +08002246 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002247 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2248 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2249 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2250 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002251 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002252 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2253 "Intel D965", STAC_D965_5ST),
2254 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2255 "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002256 {} /* terminator */
2257};
2258
Matt Porterf3302a52006-07-31 12:49:34 +02002259static unsigned int ref9205_pin_configs[12] = {
2260 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002261 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002262 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002263};
2264
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002265/*
2266 STAC 9205 pin configs for
2267 102801F1
2268 102801F2
2269 102801FC
2270 102801FD
2271 10280204
2272 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002273 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002274*/
2275static unsigned int dell_9205_m42_pin_configs[12] = {
2276 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2277 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2278 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2279};
2280
2281/*
2282 STAC 9205 pin configs for
2283 102801F9
2284 102801FA
2285 102801FE
2286 102801FF (Dell Precision M4300)
2287 10280206
2288 10280200
2289 10280201
2290*/
2291static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002292 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2293 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2294 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2295};
2296
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002297static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002298 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2299 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2300 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2301};
2302
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002303static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002304 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002305 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2306 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2307 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002308 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002309};
2310
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002311static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002312 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002313 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002314 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002315 [STAC_9205_DELL_M43] = "dell-m43",
2316 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002317 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002318};
2319
2320static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2321 /* SigmaTel reference board */
2322 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2323 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002324 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2325 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002326 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2327 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002328 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002329 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2330 "unknown Dell", STAC_9205_DELL_M42),
2331 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2332 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002333 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002334 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002335 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2336 "Dell Precision", STAC_9205_DELL_M43),
2337 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2338 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002339 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2340 "unknown Dell", STAC_9205_DELL_M42),
2341 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2342 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002343 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2344 "Dell Precision", STAC_9205_DELL_M43),
2345 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002346 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002347 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2348 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002349 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2350 "Dell Precision", STAC_9205_DELL_M43),
2351 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2352 "Dell Precision", STAC_9205_DELL_M43),
2353 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2354 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002355 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2356 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002357 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2358 "Dell Vostro 1500", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002359 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002360 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002361 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002362 {} /* terminator */
2363};
2364
Takashi Iwai330ee992009-02-20 14:33:36 +01002365static void stac92xx_set_config_regs(struct hda_codec *codec,
2366 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002367{
2368 int i;
2369 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002370
Takashi Iwai330ee992009-02-20 14:33:36 +01002371 if (!pincfgs)
2372 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002373
Matthew Ranostay87d48362007-07-17 11:52:24 +02002374 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002375 if (spec->pin_nids[i] && pincfgs[i])
2376 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2377 pincfgs[i]);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002378}
2379
Matt2f2f4252005-04-13 14:45:30 +02002380/*
2381 * Analog playback callbacks
2382 */
2383static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2384 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002385 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002386{
2387 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002388 if (spec->stream_delay)
2389 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002390 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2391 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002392}
2393
2394static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2395 struct hda_codec *codec,
2396 unsigned int stream_tag,
2397 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002398 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002399{
2400 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002401 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002402}
2403
2404static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2405 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002406 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002407{
2408 struct sigmatel_spec *spec = codec->spec;
2409 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2410}
2411
2412/*
Mattdabbed62005-06-14 10:19:34 +02002413 * Digital playback callbacks
2414 */
2415static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2416 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002417 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002418{
2419 struct sigmatel_spec *spec = codec->spec;
2420 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2421}
2422
2423static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2424 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002425 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002426{
2427 struct sigmatel_spec *spec = codec->spec;
2428 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2429}
2430
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002431static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2432 struct hda_codec *codec,
2433 unsigned int stream_tag,
2434 unsigned int format,
2435 struct snd_pcm_substream *substream)
2436{
2437 struct sigmatel_spec *spec = codec->spec;
2438 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2439 stream_tag, format, substream);
2440}
2441
Takashi Iwai9411e212009-02-13 11:32:28 +01002442static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2443 struct hda_codec *codec,
2444 struct snd_pcm_substream *substream)
2445{
2446 struct sigmatel_spec *spec = codec->spec;
2447 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2448}
2449
Mattdabbed62005-06-14 10:19:34 +02002450
2451/*
Matt2f2f4252005-04-13 14:45:30 +02002452 * Analog capture callbacks
2453 */
2454static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2455 struct hda_codec *codec,
2456 unsigned int stream_tag,
2457 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002458 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002459{
2460 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002461 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002462
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002463 if (spec->powerdown_adcs) {
2464 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002465 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002466 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2467 }
2468 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002469 return 0;
2470}
2471
2472static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2473 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002474 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002475{
2476 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002477 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002478
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002479 snd_hda_codec_cleanup_stream(codec, nid);
2480 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002481 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002482 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002483 return 0;
2484}
2485
Mattdabbed62005-06-14 10:19:34 +02002486static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2487 .substreams = 1,
2488 .channels_min = 2,
2489 .channels_max = 2,
2490 /* NID is set in stac92xx_build_pcms */
2491 .ops = {
2492 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002493 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002494 .prepare = stac92xx_dig_playback_pcm_prepare,
2495 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002496 },
2497};
2498
2499static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2500 .substreams = 1,
2501 .channels_min = 2,
2502 .channels_max = 2,
2503 /* NID is set in stac92xx_build_pcms */
2504};
2505
Matt2f2f4252005-04-13 14:45:30 +02002506static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2507 .substreams = 1,
2508 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002509 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002510 .nid = 0x02, /* NID to query formats and rates */
2511 .ops = {
2512 .open = stac92xx_playback_pcm_open,
2513 .prepare = stac92xx_playback_pcm_prepare,
2514 .cleanup = stac92xx_playback_pcm_cleanup
2515 },
2516};
2517
Matt Porter3cc08dc2006-01-23 15:27:49 +01002518static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2519 .substreams = 1,
2520 .channels_min = 2,
2521 .channels_max = 2,
2522 .nid = 0x06, /* NID to query formats and rates */
2523 .ops = {
2524 .open = stac92xx_playback_pcm_open,
2525 .prepare = stac92xx_playback_pcm_prepare,
2526 .cleanup = stac92xx_playback_pcm_cleanup
2527 },
2528};
2529
Matt2f2f4252005-04-13 14:45:30 +02002530static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002531 .channels_min = 2,
2532 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002533 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002534 .ops = {
2535 .prepare = stac92xx_capture_pcm_prepare,
2536 .cleanup = stac92xx_capture_pcm_cleanup
2537 },
2538};
2539
2540static int stac92xx_build_pcms(struct hda_codec *codec)
2541{
2542 struct sigmatel_spec *spec = codec->spec;
2543 struct hda_pcm *info = spec->pcm_rec;
2544
2545 codec->num_pcms = 1;
2546 codec->pcm_info = info;
2547
Mattc7d4b2f2005-06-27 14:59:41 +02002548 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002549 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002550 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2551 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002552 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002553 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002554 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002555
2556 if (spec->alt_switch) {
2557 codec->num_pcms++;
2558 info++;
2559 info->name = "STAC92xx Analog Alt";
2560 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2561 }
Matt2f2f4252005-04-13 14:45:30 +02002562
Mattdabbed62005-06-14 10:19:34 +02002563 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2564 codec->num_pcms++;
2565 info++;
2566 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002567 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002568 if (spec->multiout.dig_out_nid) {
2569 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2570 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2571 }
2572 if (spec->dig_in_nid) {
2573 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2574 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2575 }
2576 }
2577
Matt2f2f4252005-04-13 14:45:30 +02002578 return 0;
2579}
2580
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002581static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2582 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002583{
Takashi Iwai1327a322009-03-23 13:07:47 +01002584 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002585 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2586 if (pincap & AC_PINCAP_VREF_100)
2587 return AC_PINCTL_VREF_100;
2588 if (pincap & AC_PINCAP_VREF_80)
2589 return AC_PINCTL_VREF_80;
2590 if (pincap & AC_PINCAP_VREF_50)
2591 return AC_PINCTL_VREF_50;
2592 if (pincap & AC_PINCAP_VREF_GRD)
2593 return AC_PINCTL_VREF_GRD;
2594 return 0;
2595}
2596
Matt Porter403d1942005-11-29 15:00:51 +01002597static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2598
2599{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002600 snd_hda_codec_write_cache(codec, nid, 0,
2601 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002602}
2603
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002604#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2605
2606static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2607 struct snd_ctl_elem_value *ucontrol)
2608{
2609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2610 struct sigmatel_spec *spec = codec->spec;
2611
Takashi Iwaid7a89432008-11-12 09:48:04 +01002612 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002613 return 0;
2614}
2615
Takashi Iwai62558ce2009-07-29 14:23:09 +02002616static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002617
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002618static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2619 struct snd_ctl_elem_value *ucontrol)
2620{
2621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2622 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002623 int nid = kcontrol->private_value;
2624
2625 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002626
2627 /* check to be sure that the ports are upto date with
2628 * switch changes
2629 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002630 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002631
2632 return 1;
2633}
2634
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002635static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2636 struct snd_ctl_elem_info *uinfo)
2637{
2638 int i;
2639 static char *texts[] = {
2640 "Mic In", "Line In", "Line Out"
2641 };
2642
2643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2644 struct sigmatel_spec *spec = codec->spec;
2645 hda_nid_t nid = kcontrol->private_value;
2646
2647 if (nid == spec->mic_switch || nid == spec->line_switch)
2648 i = 3;
2649 else
2650 i = 2;
2651
2652 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2653 uinfo->value.enumerated.items = i;
2654 uinfo->count = 1;
2655 if (uinfo->value.enumerated.item >= i)
2656 uinfo->value.enumerated.item = i-1;
2657 strcpy(uinfo->value.enumerated.name,
2658 texts[uinfo->value.enumerated.item]);
2659
2660 return 0;
2661}
2662
2663static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2664 struct snd_ctl_elem_value *ucontrol)
2665{
2666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2667 hda_nid_t nid = kcontrol->private_value;
2668 unsigned int vref = stac92xx_vref_get(codec, nid);
2669
2670 if (vref == stac92xx_get_default_vref(codec, nid))
2671 ucontrol->value.enumerated.item[0] = 0;
2672 else if (vref == AC_PINCTL_VREF_GRD)
2673 ucontrol->value.enumerated.item[0] = 1;
2674 else if (vref == AC_PINCTL_VREF_HIZ)
2675 ucontrol->value.enumerated.item[0] = 2;
2676
2677 return 0;
2678}
2679
2680static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2681 struct snd_ctl_elem_value *ucontrol)
2682{
2683 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2684 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002685 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002686 hda_nid_t nid = kcontrol->private_value;
2687
2688 if (ucontrol->value.enumerated.item[0] == 0)
2689 new_vref = stac92xx_get_default_vref(codec, nid);
2690 else if (ucontrol->value.enumerated.item[0] == 1)
2691 new_vref = AC_PINCTL_VREF_GRD;
2692 else if (ucontrol->value.enumerated.item[0] == 2)
2693 new_vref = AC_PINCTL_VREF_HIZ;
2694 else
2695 return 0;
2696
2697 if (new_vref != stac92xx_vref_get(codec, nid)) {
2698 error = stac92xx_vref_set(codec, nid, new_vref);
2699 return error;
2700 }
2701
2702 return 0;
2703}
2704
2705static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2706 struct snd_ctl_elem_info *uinfo)
2707{
2708 static char *texts[2];
2709 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2710 struct sigmatel_spec *spec = codec->spec;
2711
2712 if (kcontrol->private_value == spec->line_switch)
2713 texts[0] = "Line In";
2714 else
2715 texts[0] = "Mic In";
2716 texts[1] = "Line Out";
2717 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2718 uinfo->value.enumerated.items = 2;
2719 uinfo->count = 1;
2720
2721 if (uinfo->value.enumerated.item >= 2)
2722 uinfo->value.enumerated.item = 1;
2723 strcpy(uinfo->value.enumerated.name,
2724 texts[uinfo->value.enumerated.item]);
2725
2726 return 0;
2727}
Matt Porter403d1942005-11-29 15:00:51 +01002728
2729static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2730{
2731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2732 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002733 hda_nid_t nid = kcontrol->private_value;
2734 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002735
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002736 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002737 return 0;
2738}
2739
2740static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2741{
2742 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2743 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002744 hda_nid_t nid = kcontrol->private_value;
2745 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2746 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002747
2748 spec->io_switch[io_idx] = val;
2749
2750 if (val)
2751 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002752 else {
2753 unsigned int pinctl = AC_PINCTL_IN_EN;
2754 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002755 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002756 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2757 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002758
2759 /* check the auto-mute again: we need to mute/unmute the speaker
2760 * appropriately according to the pin direction
2761 */
2762 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002763 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002764
Matt Porter403d1942005-11-29 15:00:51 +01002765 return 1;
2766}
2767
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002768#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2769
2770static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2771 struct snd_ctl_elem_value *ucontrol)
2772{
2773 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2774 struct sigmatel_spec *spec = codec->spec;
2775
2776 ucontrol->value.integer.value[0] = spec->clfe_swap;
2777 return 0;
2778}
2779
2780static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2781 struct snd_ctl_elem_value *ucontrol)
2782{
2783 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2784 struct sigmatel_spec *spec = codec->spec;
2785 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002786 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002787
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002788 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002789 return 0;
2790
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002791 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002792
2793 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2794 spec->clfe_swap ? 0x4 : 0x0);
2795
2796 return 1;
2797}
2798
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002799#define STAC_CODEC_HP_SWITCH(xname) \
2800 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2801 .name = xname, \
2802 .index = 0, \
2803 .info = stac92xx_hp_switch_info, \
2804 .get = stac92xx_hp_switch_get, \
2805 .put = stac92xx_hp_switch_put, \
2806 }
2807
Matt Porter403d1942005-11-29 15:00:51 +01002808#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2809 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2810 .name = xname, \
2811 .index = 0, \
2812 .info = stac92xx_io_switch_info, \
2813 .get = stac92xx_io_switch_get, \
2814 .put = stac92xx_io_switch_put, \
2815 .private_value = xpval, \
2816 }
2817
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002818#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2819 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2820 .name = xname, \
2821 .index = 0, \
2822 .info = stac92xx_clfe_switch_info, \
2823 .get = stac92xx_clfe_switch_get, \
2824 .put = stac92xx_clfe_switch_put, \
2825 .private_value = xpval, \
2826 }
Matt Porter403d1942005-11-29 15:00:51 +01002827
Mattc7d4b2f2005-06-27 14:59:41 +02002828enum {
2829 STAC_CTL_WIDGET_VOL,
2830 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002831 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002832 STAC_CTL_WIDGET_AMP_MUX,
2833 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002834 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002835 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002836 STAC_CTL_WIDGET_CLFE_SWITCH,
2837 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002838};
2839
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002840static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002841 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2842 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002843 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002844 STAC_AMP_MUX,
2845 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002846 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002847 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002848 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002849 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002850};
2851
2852/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002853static struct snd_kcontrol_new *
2854stac_control_new(struct sigmatel_spec *spec,
2855 struct snd_kcontrol_new *ktemp,
2856 const char *name)
Mattc7d4b2f2005-06-27 14:59:41 +02002857{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002858 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002859
Takashi Iwai603c4012008-07-30 15:01:44 +02002860 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2861 knew = snd_array_new(&spec->kctls);
2862 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002863 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002864 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002865 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002866 if (!knew->name) {
2867 /* roolback */
2868 memset(knew, 0, sizeof(*knew));
2869 spec->kctls.alloced--;
2870 return NULL;
2871 }
2872 return knew;
2873}
2874
2875static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2876 struct snd_kcontrol_new *ktemp,
2877 int idx, const char *name,
2878 unsigned long val)
2879{
2880 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2881 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002882 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002883 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002884 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002885 return 0;
2886}
2887
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002888static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2889 int type, int idx, const char *name,
2890 unsigned long val)
2891{
2892 return stac92xx_add_control_temp(spec,
2893 &stac92xx_control_templates[type],
2894 idx, name, val);
2895}
2896
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002897
2898/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002899static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2900 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002901{
2902 return stac92xx_add_control_idx(spec, type, 0, name, val);
2903}
2904
Takashi Iwaie3c75962009-01-23 11:57:22 +01002905static struct snd_kcontrol_new stac_input_src_temp = {
2906 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2907 .name = "Input Source",
2908 .info = stac92xx_mux_enum_info,
2909 .get = stac92xx_mux_enum_get,
2910 .put = stac92xx_mux_enum_put,
2911};
2912
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002913static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2914 hda_nid_t nid, int idx)
2915{
2916 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2917 int control = 0;
2918 struct sigmatel_spec *spec = codec->spec;
2919 char name[22];
2920
2921 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2922 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2923 && nid == spec->line_switch)
2924 control = STAC_CTL_WIDGET_IO_SWITCH;
2925 else if (snd_hda_query_pin_caps(codec, nid)
2926 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2927 control = STAC_CTL_WIDGET_DC_BIAS;
2928 else if (nid == spec->mic_switch)
2929 control = STAC_CTL_WIDGET_IO_SWITCH;
2930 }
2931
2932 if (control) {
2933 strcpy(name, auto_pin_cfg_labels[idx]);
2934 return stac92xx_add_control(codec->spec, control,
2935 strcat(name, " Jack Mode"), nid);
2936 }
2937
2938 return 0;
2939}
2940
Takashi Iwaie3c75962009-01-23 11:57:22 +01002941static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2942{
2943 struct snd_kcontrol_new *knew;
2944 struct hda_input_mux *imux = &spec->private_imux;
2945
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002946 if (spec->auto_mic)
2947 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002948 if (!spec->num_adcs || imux->num_items <= 1)
2949 return 0; /* no need for input source control */
2950 knew = stac_control_new(spec, &stac_input_src_temp,
2951 stac_input_src_temp.name);
2952 if (!knew)
2953 return -ENOMEM;
2954 knew->count = spec->num_adcs;
2955 return 0;
2956}
2957
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002958/* check whether the line-input can be used as line-out */
2959static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002960{
2961 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002962 struct auto_pin_cfg *cfg = &spec->autocfg;
2963 hda_nid_t nid;
2964 unsigned int pincap;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002965
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002966 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2967 return 0;
2968 nid = cfg->input_pins[AUTO_PIN_LINE];
Takashi Iwai1327a322009-03-23 13:07:47 +01002969 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002970 if (pincap & AC_PINCAP_OUT)
2971 return nid;
Matt Porter403d1942005-11-29 15:00:51 +01002972 return 0;
2973}
2974
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002975/* check whether the mic-input can be used as line-out */
2976static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2977{
2978 struct sigmatel_spec *spec = codec->spec;
2979 struct auto_pin_cfg *cfg = &spec->autocfg;
2980 unsigned int def_conf, pincap;
2981 unsigned int mic_pin;
2982
2983 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2984 return 0;
2985 mic_pin = AUTO_PIN_MIC;
2986 for (;;) {
2987 hda_nid_t nid = cfg->input_pins[mic_pin];
Takashi Iwai330ee992009-02-20 14:33:36 +01002988 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002989 /* some laptops have an internal analog microphone
2990 * which can't be used as a output */
2991 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai1327a322009-03-23 13:07:47 +01002992 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002993 if (pincap & AC_PINCAP_OUT)
2994 return nid;
2995 }
2996 if (mic_pin == AUTO_PIN_MIC)
2997 mic_pin = AUTO_PIN_FRONT_MIC;
2998 else
2999 break;
3000 }
3001 return 0;
3002}
Steve Longerbeam7b043892007-05-03 20:50:03 +02003003
3004static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3005{
3006 int i;
3007
3008 for (i = 0; i < spec->multiout.num_dacs; i++) {
3009 if (spec->multiout.dac_nids[i] == nid)
3010 return 1;
3011 }
3012
3013 return 0;
3014}
3015
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003016static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3017{
3018 int i;
3019 if (is_in_dac_nids(spec, nid))
3020 return 1;
3021 for (i = 0; i < spec->autocfg.hp_outs; i++)
3022 if (spec->hp_dacs[i] == nid)
3023 return 1;
3024 for (i = 0; i < spec->autocfg.speaker_outs; i++)
3025 if (spec->speaker_dacs[i] == nid)
3026 return 1;
3027 return 0;
3028}
3029
3030static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
3031{
3032 struct sigmatel_spec *spec = codec->spec;
3033 int j, conn_len;
3034 hda_nid_t conn[HDA_MAX_CONNECTIONS];
3035 unsigned int wcaps, wtype;
3036
3037 conn_len = snd_hda_get_connections(codec, nid, conn,
3038 HDA_MAX_CONNECTIONS);
3039 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01003040 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003041 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003042 /* we check only analog outputs */
3043 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3044 continue;
3045 /* if this route has a free DAC, assign it */
3046 if (!check_all_dac_nids(spec, conn[j])) {
3047 if (conn_len > 1) {
3048 /* select this DAC in the pin's input mux */
3049 snd_hda_codec_write_cache(codec, nid, 0,
3050 AC_VERB_SET_CONNECT_SEL, j);
3051 }
3052 return conn[j];
3053 }
3054 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003055 /* if all DACs are already assigned, connect to the primary DAC */
3056 if (conn_len > 1) {
3057 for (j = 0; j < conn_len; j++) {
3058 if (conn[j] == spec->multiout.dac_nids[0]) {
3059 snd_hda_codec_write_cache(codec, nid, 0,
3060 AC_VERB_SET_CONNECT_SEL, j);
3061 break;
3062 }
3063 }
3064 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003065 return 0;
3066}
3067
3068static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3069static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3070
Matt Porter3cc08dc2006-01-23 15:27:49 +01003071/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02003072 * Fill in the dac_nids table from the parsed pin configuration
3073 * This function only works when every pin in line_out_pins[]
3074 * contains atleast one DAC in its connection list. Some 92xx
3075 * codecs are not connected directly to a DAC, such as the 9200
3076 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01003077 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003078static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003079{
3080 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003081 struct auto_pin_cfg *cfg = &spec->autocfg;
3082 int i;
3083 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02003084
Mattc7d4b2f2005-06-27 14:59:41 +02003085 for (i = 0; i < cfg->line_outs; i++) {
3086 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003087 dac = get_unassigned_dac(codec, nid);
3088 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003089 if (spec->multiout.num_dacs > 0) {
3090 /* we have already working output pins,
3091 * so let's drop the broken ones again
3092 */
3093 cfg->line_outs = spec->multiout.num_dacs;
3094 break;
3095 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003096 /* error out, no available DAC found */
3097 snd_printk(KERN_ERR
3098 "%s: No available DAC for pin 0x%x\n",
3099 __func__, nid);
3100 return -ENODEV;
3101 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003102 add_spec_dacs(spec, dac);
3103 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003104
Takashi Iwai139e0712009-03-06 12:10:41 +01003105 for (i = 0; i < cfg->hp_outs; i++) {
3106 nid = cfg->hp_pins[i];
3107 dac = get_unassigned_dac(codec, nid);
3108 if (dac) {
3109 if (!spec->multiout.hp_nid)
3110 spec->multiout.hp_nid = dac;
3111 else
3112 add_spec_extra_dacs(spec, dac);
3113 }
3114 spec->hp_dacs[i] = dac;
3115 }
3116
3117 for (i = 0; i < cfg->speaker_outs; i++) {
3118 nid = cfg->speaker_pins[i];
3119 dac = get_unassigned_dac(codec, nid);
3120 if (dac)
3121 add_spec_extra_dacs(spec, dac);
3122 spec->speaker_dacs[i] = dac;
3123 }
3124
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003125 /* add line-in as output */
3126 nid = check_line_out_switch(codec);
3127 if (nid) {
3128 dac = get_unassigned_dac(codec, nid);
3129 if (dac) {
3130 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3131 nid, cfg->line_outs);
3132 cfg->line_out_pins[cfg->line_outs] = nid;
3133 cfg->line_outs++;
3134 spec->line_switch = nid;
3135 add_spec_dacs(spec, dac);
3136 }
3137 }
3138 /* add mic as output */
3139 nid = check_mic_out_switch(codec);
3140 if (nid) {
3141 dac = get_unassigned_dac(codec, nid);
3142 if (dac) {
3143 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3144 nid, cfg->line_outs);
3145 cfg->line_out_pins[cfg->line_outs] = nid;
3146 cfg->line_outs++;
3147 spec->mic_switch = nid;
3148 add_spec_dacs(spec, dac);
Steve Longerbeam7b043892007-05-03 20:50:03 +02003149 }
Mattc7d4b2f2005-06-27 14:59:41 +02003150 }
3151
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003152 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003153 spec->multiout.num_dacs,
3154 spec->multiout.dac_nids[0],
3155 spec->multiout.dac_nids[1],
3156 spec->multiout.dac_nids[2],
3157 spec->multiout.dac_nids[3],
3158 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003159
Mattc7d4b2f2005-06-27 14:59:41 +02003160 return 0;
3161}
3162
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003163/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003164static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3165 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003166{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003167 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003168 char name[32];
3169 int err;
3170
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003171 if (!spec->check_volume_offset) {
3172 unsigned int caps, step, nums, db_scale;
3173 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3174 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3175 AC_AMPCAP_STEP_SIZE_SHIFT;
3176 step = (step + 1) * 25; /* in .01dB unit */
3177 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3178 AC_AMPCAP_NUM_STEPS_SHIFT;
3179 db_scale = nums * step;
3180 /* if dB scale is over -64dB, and finer enough,
3181 * let's reduce it to half
3182 */
3183 if (db_scale > 6400 && nums >= 0x1f)
3184 spec->volume_offset = nums / 2;
3185 spec->check_volume_offset = 1;
3186 }
3187
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003188 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003189 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003190 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3191 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003192 if (err < 0)
3193 return err;
3194 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003195 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003196 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3197 if (err < 0)
3198 return err;
3199 return 0;
3200}
3201
Takashi Iwai668b9652009-03-06 10:13:24 +01003202#define create_controls(codec, pfx, nid, chs) \
3203 create_controls_idx(codec, pfx, 0, nid, chs)
3204
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003205static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3206{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003207 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003208 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3209 return 1;
3210 } else {
3211 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3212 spec->multiout.num_dacs++;
3213 }
3214 return 0;
3215}
3216
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003217static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003218{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003219 int i;
3220 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3221 if (!spec->multiout.extra_out_nid[i]) {
3222 spec->multiout.extra_out_nid[i] = nid;
3223 return 0;
3224 }
3225 }
3226 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3227 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003228}
3229
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003230/* Create output controls
3231 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3232 */
3233static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3234 const hda_nid_t *pins,
3235 const hda_nid_t *dac_nids,
3236 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003237{
Takashi Iwai76624532008-12-19 10:09:47 +01003238 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003239 static const char *chname[4] = {
3240 "Front", "Surround", NULL /*CLFE*/, "Side"
3241 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003242 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003243 int i, err;
3244 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003245
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003246 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003247 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3248 wid_caps = get_wcaps(codec, pins[i]);
3249 if (wid_caps & AC_WCAP_UNSOL_CAP)
3250 spec->hp_detect = 1;
3251 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003252 nid = dac_nids[i];
3253 if (!nid)
3254 continue;
3255 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003256 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003257 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003258 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003259 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003260 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003261 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003262 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003263
3264 wid_caps = get_wcaps(codec, nid);
3265
3266 if (wid_caps & AC_WCAP_LR_SWAP) {
3267 err = stac92xx_add_control(spec,
3268 STAC_CTL_WIDGET_CLFE_SWITCH,
3269 "Swap Center/LFE Playback Switch", nid);
3270
3271 if (err < 0)
3272 return err;
3273 }
3274
Mattc7d4b2f2005-06-27 14:59:41 +02003275 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003276 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003277 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003278 switch (type) {
3279 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003280 name = "Headphone";
3281 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003282 break;
3283 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003284 name = "Speaker";
3285 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003286 break;
3287 default:
3288 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003289 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003290 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003291 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003292 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003293 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003294 return err;
3295 }
3296 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003297 return 0;
3298}
3299
Takashi Iwai6479c632009-07-28 18:20:25 +02003300static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3301 unsigned long sw, int idx)
3302{
3303 int err;
3304 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003305 "Capture Volume", vol);
Takashi Iwai6479c632009-07-28 18:20:25 +02003306 if (err < 0)
3307 return err;
3308 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
Takashi Iwaibf677bd2009-07-30 09:24:29 +02003309 "Capture Switch", sw);
Takashi Iwai6479c632009-07-28 18:20:25 +02003310 if (err < 0)
3311 return err;
3312 return 0;
3313}
3314
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003315/* add playback controls from the parsed DAC table */
3316static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3317 const struct auto_pin_cfg *cfg)
3318{
3319 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003320 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003321 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003322 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003323
3324 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3325 spec->multiout.dac_nids,
3326 cfg->line_out_type);
3327 if (err < 0)
3328 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003329
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003330 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003331 err = stac92xx_add_control(spec,
3332 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003333 "Headphone as Line Out Switch",
3334 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003335 if (err < 0)
3336 return err;
3337 }
3338
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003339 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3340 nid = cfg->input_pins[idx];
3341 if (nid) {
3342 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3343 if (err < 0)
3344 return err;
3345 }
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003346 }
Matt Porter403d1942005-11-29 15:00:51 +01003347
Mattc7d4b2f2005-06-27 14:59:41 +02003348 return 0;
3349}
3350
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003351/* add playback controls for Speaker and HP outputs */
3352static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3353 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003354{
3355 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003356 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003357
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003358 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3359 spec->hp_dacs, AUTO_PIN_HP_OUT);
3360 if (err < 0)
3361 return err;
3362
3363 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3364 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3365 if (err < 0)
3366 return err;
3367
Mattc7d4b2f2005-06-27 14:59:41 +02003368 return 0;
3369}
3370
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003371/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003372static const char *stac92xx_mono_labels[4] = {
3373 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003374};
3375
3376/* create mono mux for mono out on capable codecs */
3377static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3378{
3379 struct sigmatel_spec *spec = codec->spec;
3380 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3381 int i, num_cons;
3382 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3383
3384 num_cons = snd_hda_get_connections(codec,
3385 spec->mono_nid,
3386 con_lst,
3387 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003388 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003389 return -EINVAL;
3390
3391 for (i = 0; i < num_cons; i++) {
3392 mono_mux->items[mono_mux->num_items].label =
3393 stac92xx_mono_labels[i];
3394 mono_mux->items[mono_mux->num_items].index = i;
3395 mono_mux->num_items++;
3396 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003397
3398 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3399 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003400}
3401
Matthew Ranostay89385032008-09-11 09:49:39 -04003402/* labels for amp mux outputs */
3403static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003404 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003405};
3406
3407/* create amp out controls mux on capable codecs */
3408static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3409{
3410 struct sigmatel_spec *spec = codec->spec;
3411 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3412 int i, err;
3413
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003414 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003415 amp_mux->items[amp_mux->num_items].label =
3416 stac92xx_amp_labels[i];
3417 amp_mux->items[amp_mux->num_items].index = i;
3418 amp_mux->num_items++;
3419 }
3420
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003421 if (spec->num_amps > 1) {
3422 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3423 "Amp Selector Capture Switch", 0);
3424 if (err < 0)
3425 return err;
3426 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003427 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3428 "Amp Capture Volume",
3429 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3430}
3431
3432
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003433/* create PC beep volume controls */
3434static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3435 hda_nid_t nid)
3436{
3437 struct sigmatel_spec *spec = codec->spec;
3438 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3439 int err;
3440
3441 /* check for mute support for the the amp */
3442 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3443 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3444 "PC Beep Playback Switch",
3445 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3446 if (err < 0)
3447 return err;
3448 }
3449
3450 /* check to see if there is volume support for the amp */
3451 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3452 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3453 "PC Beep Playback Volume",
3454 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3455 if (err < 0)
3456 return err;
3457 }
3458 return 0;
3459}
3460
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003461#ifdef CONFIG_SND_HDA_INPUT_BEEP
3462#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3463
3464static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3465 struct snd_ctl_elem_value *ucontrol)
3466{
3467 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3468 ucontrol->value.integer.value[0] = codec->beep->enabled;
3469 return 0;
3470}
3471
3472static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3473 struct snd_ctl_elem_value *ucontrol)
3474{
3475 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3476 int enabled = !!ucontrol->value.integer.value[0];
3477 if (codec->beep->enabled != enabled) {
3478 codec->beep->enabled = enabled;
3479 return 1;
3480 }
3481 return 0;
3482}
3483
3484static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3485 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3486 .info = stac92xx_dig_beep_switch_info,
3487 .get = stac92xx_dig_beep_switch_get,
3488 .put = stac92xx_dig_beep_switch_put,
3489};
3490
3491static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3492{
3493 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3494 0, "PC Beep Playback Switch", 0);
3495}
3496#endif
3497
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003498static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3499{
3500 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai667067d2009-08-13 18:14:42 +02003501 int i, j, err = 0;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003502
3503 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003504 hda_nid_t nid;
3505 unsigned int wcaps;
3506 unsigned long val;
3507
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003508 nid = spec->mux_nids[i];
3509 wcaps = get_wcaps(codec, nid);
Takashi Iwai667067d2009-08-13 18:14:42 +02003510 if (!(wcaps & AC_WCAP_OUT_AMP))
3511 continue;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003512
Takashi Iwai667067d2009-08-13 18:14:42 +02003513 /* check whether already the same control was created as
3514 * normal Capture Volume.
3515 */
3516 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3517 for (j = 0; j < spec->num_caps; j++) {
3518 if (spec->capvols[j] == val)
3519 break;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003520 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003521 if (j < spec->num_caps)
3522 continue;
3523
3524 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, i,
3525 "Mux Capture Volume", val);
3526 if (err < 0)
3527 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003528 }
3529 return 0;
3530};
3531
Matthew Ranostayd9737752008-09-07 12:03:41 +02003532static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003533 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003534};
3535
3536static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3537{
3538 struct sigmatel_spec *spec = codec->spec;
3539 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003540 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003541 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003542 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003543
3544 num_cons = snd_hda_get_connections(codec,
3545 spec->smux_nids[0],
3546 con_lst,
3547 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003548 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003549 return -EINVAL;
3550
Matthew Ranostay65973632008-09-16 10:39:37 -04003551 if (!labels)
3552 labels = stac92xx_spdif_labels;
3553
Matthew Ranostayd9737752008-09-07 12:03:41 +02003554 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003555 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003556 spdif_mux->items[spdif_mux->num_items].index = i;
3557 spdif_mux->num_items++;
3558 }
3559
3560 return 0;
3561}
3562
Matt Porter8b657272006-10-26 17:12:59 +02003563/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003564static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003565 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3566 "Digital Mic 3", "Digital Mic 4"
3567};
3568
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003569static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3570 hda_nid_t nid)
3571{
3572 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3573 int i, nums;
3574
3575 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3576 for (i = 0; i < nums; i++)
3577 if (conn[i] == nid)
3578 return i;
3579 return -1;
3580}
3581
Takashi Iwai667067d2009-08-13 18:14:42 +02003582/* create a volume assigned to the given pin (only if supported) */
Takashi Iwai96f845d2009-08-29 00:49:36 +02003583/* return 1 if the volume control is created */
Takashi Iwai667067d2009-08-13 18:14:42 +02003584static int create_elem_capture_vol(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003585 const char *label, int direction)
Takashi Iwai667067d2009-08-13 18:14:42 +02003586{
3587 unsigned int caps, nums;
3588 char name[32];
Takashi Iwai96f845d2009-08-29 00:49:36 +02003589 int err;
Takashi Iwai667067d2009-08-13 18:14:42 +02003590
Takashi Iwai96f845d2009-08-29 00:49:36 +02003591 if (direction == HDA_OUTPUT)
3592 caps = AC_WCAP_OUT_AMP;
3593 else
3594 caps = AC_WCAP_IN_AMP;
3595 if (!(get_wcaps(codec, nid) & caps))
Takashi Iwai667067d2009-08-13 18:14:42 +02003596 return 0;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003597 caps = query_amp_caps(codec, nid, direction);
Takashi Iwai667067d2009-08-13 18:14:42 +02003598 nums = (caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT;
3599 if (!nums)
3600 return 0;
3601 snprintf(name, sizeof(name), "%s Capture Volume", label);
Takashi Iwai96f845d2009-08-29 00:49:36 +02003602 err = stac92xx_add_control(codec->spec, STAC_CTL_WIDGET_VOL, name,
3603 HDA_COMPOSE_AMP_VAL(nid, 3, 0, direction));
3604 if (err < 0)
3605 return err;
3606 return 1;
Takashi Iwai667067d2009-08-13 18:14:42 +02003607}
3608
Matt Porter8b657272006-10-26 17:12:59 +02003609/* create playback/capture controls for input pins on dmic capable codecs */
3610static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3611 const struct auto_pin_cfg *cfg)
3612{
3613 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai5207e102009-07-30 13:09:08 +02003614 struct hda_input_mux *imux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003615 struct hda_input_mux *dimux = &spec->private_dimux;
Takashi Iwai5207e102009-07-30 13:09:08 +02003616 int err, i, active_mics;
3617 unsigned int def_conf;
Matt Porter8b657272006-10-26 17:12:59 +02003618
3619 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3620 dimux->items[dimux->num_items].index = 0;
3621 dimux->num_items++;
3622
Takashi Iwai5207e102009-07-30 13:09:08 +02003623 active_mics = 0;
3624 for (i = 0; i < spec->num_dmics; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003625 /* check the validity: sometimes it's a dead vendor-spec node */
3626 if (get_wcaps_type(get_wcaps(codec, spec->dmic_nids[i]))
3627 != AC_WID_PIN)
3628 continue;
Takashi Iwai5207e102009-07-30 13:09:08 +02003629 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3630 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
3631 active_mics++;
3632 }
3633
Matt Porter8b657272006-10-26 17:12:59 +02003634 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003635 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003636 int index;
Takashi Iwai5207e102009-07-30 13:09:08 +02003637 const char *label;
Matt Porter8b657272006-10-26 17:12:59 +02003638
Takashi Iwai667067d2009-08-13 18:14:42 +02003639 nid = spec->dmic_nids[i];
3640 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3641 continue;
3642 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matt Porter8b657272006-10-26 17:12:59 +02003643 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3644 continue;
3645
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003646 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3647 if (index < 0)
3648 continue;
3649
Takashi Iwai5207e102009-07-30 13:09:08 +02003650 if (active_mics == 1)
3651 label = "Digital Mic";
3652 else
3653 label = stac92xx_dmic_labels[dimux->num_items];
3654
Takashi Iwai96f845d2009-08-29 00:49:36 +02003655 err = create_elem_capture_vol(codec, nid, label, HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003656 if (err < 0)
3657 return err;
Takashi Iwai96f845d2009-08-29 00:49:36 +02003658 if (!err) {
3659 err = create_elem_capture_vol(codec, nid, label,
3660 HDA_OUTPUT);
3661 if (err < 0)
3662 return err;
3663 }
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003664
Takashi Iwai5207e102009-07-30 13:09:08 +02003665 dimux->items[dimux->num_items].label = label;
Matt Porter8b657272006-10-26 17:12:59 +02003666 dimux->items[dimux->num_items].index = index;
3667 dimux->num_items++;
Takashi Iwai5207e102009-07-30 13:09:08 +02003668 if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1) {
3669 imux->items[imux->num_items].label = label;
3670 imux->items[imux->num_items].index = index;
3671 imux->num_items++;
3672 }
Matt Porter8b657272006-10-26 17:12:59 +02003673 }
3674
3675 return 0;
3676}
3677
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003678static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3679 hda_nid_t *fixed, hda_nid_t *ext)
3680{
3681 unsigned int cfg;
3682
3683 if (!nid)
3684 return 0;
3685 cfg = snd_hda_codec_get_pincfg(codec, nid);
3686 switch (get_defcfg_connect(cfg)) {
3687 case AC_JACK_PORT_FIXED:
3688 if (*fixed)
3689 return 1; /* already occupied */
3690 *fixed = nid;
3691 break;
3692 case AC_JACK_PORT_COMPLEX:
3693 if (*ext)
3694 return 1; /* already occupied */
3695 *ext = nid;
3696 break;
3697 }
3698 return 0;
3699}
3700
3701static int set_mic_route(struct hda_codec *codec,
3702 struct sigmatel_mic_route *mic,
3703 hda_nid_t pin)
3704{
3705 struct sigmatel_spec *spec = codec->spec;
3706 struct auto_pin_cfg *cfg = &spec->autocfg;
3707 int i;
3708
3709 mic->pin = pin;
3710 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3711 if (pin == cfg->input_pins[i])
3712 break;
3713 if (i <= AUTO_PIN_FRONT_MIC) {
3714 /* analog pin */
3715 mic->dmux_idx = 0;
3716 i = get_connection_index(codec, spec->mux_nids[0], pin);
3717 if (i < 0)
3718 return -1;
3719 mic->mux_idx = i;
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02003720 } else if (spec->dmux_nids) {
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003721 /* digital pin */
3722 mic->mux_idx = 0;
3723 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3724 if (i < 0)
3725 return -1;
3726 mic->dmux_idx = i;
3727 }
3728 return 0;
3729}
3730
3731/* return non-zero if the device is for automatic mic switch */
3732static int stac_check_auto_mic(struct hda_codec *codec)
3733{
3734 struct sigmatel_spec *spec = codec->spec;
3735 struct auto_pin_cfg *cfg = &spec->autocfg;
3736 hda_nid_t fixed, ext;
3737 int i;
3738
3739 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3740 if (cfg->input_pins[i])
3741 return 0; /* must be exclusively mics */
3742 }
3743 fixed = ext = 0;
3744 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3745 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3746 return 0;
3747 for (i = 0; i < spec->num_dmics; i++)
3748 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3749 return 0;
3750 if (!fixed || !ext)
3751 return 0;
3752 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3753 return 0; /* no unsol support */
3754 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3755 set_mic_route(codec, &spec->int_mic, fixed))
3756 return 0; /* something is wrong */
3757 return 1;
3758}
3759
Mattc7d4b2f2005-06-27 14:59:41 +02003760/* create playback/capture controls for input pins */
3761static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3762{
3763 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003764 struct hda_input_mux *imux = &spec->private_imux;
Takashi Iwai667067d2009-08-13 18:14:42 +02003765 int i, j;
Mattc7d4b2f2005-06-27 14:59:41 +02003766
3767 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003768 hda_nid_t nid = cfg->input_pins[i];
3769 int index, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003770
Takashi Iwai667067d2009-08-13 18:14:42 +02003771 if (!nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02003772 continue;
3773 index = -1;
3774 for (j = 0; j < spec->num_muxes; j++) {
Takashi Iwai667067d2009-08-13 18:14:42 +02003775 index = get_connection_index(codec, spec->mux_nids[j],
3776 nid);
3777 if (index >= 0)
3778 break;
Mattc7d4b2f2005-06-27 14:59:41 +02003779 }
Takashi Iwai667067d2009-08-13 18:14:42 +02003780 if (index < 0)
3781 continue;
3782
3783 err = create_elem_capture_vol(codec, nid,
Takashi Iwai96f845d2009-08-29 00:49:36 +02003784 auto_pin_cfg_labels[i],
3785 HDA_INPUT);
Takashi Iwai667067d2009-08-13 18:14:42 +02003786 if (err < 0)
3787 return err;
3788
Takashi Iwai314634b2006-09-21 11:56:18 +02003789 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3790 imux->items[imux->num_items].index = index;
3791 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003792 }
Takashi Iwai5207e102009-07-30 13:09:08 +02003793 spec->num_analog_muxes = imux->num_items;
Mattc7d4b2f2005-06-27 14:59:41 +02003794
Steve Longerbeam7b043892007-05-03 20:50:03 +02003795 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003796 /*
3797 * Set the current input for the muxes.
3798 * The STAC9221 has two input muxes with identical source
3799 * NID lists. Hopefully this won't get confused.
3800 */
3801 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003802 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3803 AC_VERB_SET_CONNECT_SEL,
3804 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003805 }
3806 }
3807
Mattc7d4b2f2005-06-27 14:59:41 +02003808 return 0;
3809}
3810
Mattc7d4b2f2005-06-27 14:59:41 +02003811static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3812{
3813 struct sigmatel_spec *spec = codec->spec;
3814 int i;
3815
3816 for (i = 0; i < spec->autocfg.line_outs; i++) {
3817 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3818 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3819 }
3820}
3821
3822static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3823{
3824 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003825 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003826
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003827 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3828 hda_nid_t pin;
3829 pin = spec->autocfg.hp_pins[i];
3830 if (pin) /* connect to front */
3831 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3832 }
3833 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3834 hda_nid_t pin;
3835 pin = spec->autocfg.speaker_pins[i];
3836 if (pin) /* connect to front */
3837 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3838 }
Mattc7d4b2f2005-06-27 14:59:41 +02003839}
3840
Matt Porter3cc08dc2006-01-23 15:27:49 +01003841static 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 +02003842{
3843 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003844 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003845 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003846
Matt Porter8b657272006-10-26 17:12:59 +02003847 if ((err = snd_hda_parse_pin_def_config(codec,
3848 &spec->autocfg,
3849 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003850 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003851 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003852 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003853
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003854 /* If we have no real line-out pin and multiple hp-outs, HPs should
3855 * be set up as multi-channel outputs.
3856 */
3857 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3858 spec->autocfg.hp_outs > 1) {
3859 /* Copy hp_outs to line_outs, backup line_outs in
3860 * speaker_outs so that the following routines can handle
3861 * HP pins as primary outputs.
3862 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003863 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003864 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3865 sizeof(spec->autocfg.line_out_pins));
3866 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3867 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3868 sizeof(spec->autocfg.hp_pins));
3869 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003870 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3871 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003872 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003873 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003874 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003875 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3876 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003877 u32 caps = query_amp_caps(codec,
3878 spec->autocfg.mono_out_pin, dir);
3879 hda_nid_t conn_list[1];
3880
3881 /* get the mixer node and then the mono mux if it exists */
3882 if (snd_hda_get_connections(codec,
3883 spec->autocfg.mono_out_pin, conn_list, 1) &&
3884 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003885 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003886
3887 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003888 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003889 /* LR swap check, some stac925x have a mux that
3890 * changes the DACs output path instead of the
3891 * mono-mux path.
3892 */
3893 if (wid_type == AC_WID_AUD_SEL &&
3894 !(wcaps & AC_WCAP_LR_SWAP))
3895 spec->mono_nid = conn_list[0];
3896 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003897 if (dir) {
3898 hda_nid_t nid = spec->autocfg.mono_out_pin;
3899
3900 /* most mono outs have a least a mute/unmute switch */
3901 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3902 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3903 "Mono Playback Switch",
3904 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003905 if (err < 0)
3906 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003907 /* check for volume support for the amp */
3908 if ((caps & AC_AMPCAP_NUM_STEPS)
3909 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3910 err = stac92xx_add_control(spec,
3911 STAC_CTL_WIDGET_VOL,
3912 "Mono Playback Volume",
3913 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3914 if (err < 0)
3915 return err;
3916 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003917 }
3918
3919 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3920 AC_PINCTL_OUT_EN);
3921 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003922
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003923 if (!spec->multiout.num_dacs) {
3924 err = stac92xx_auto_fill_dac_nids(codec);
3925 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003926 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003927 err = stac92xx_auto_create_multi_out_ctls(codec,
3928 &spec->autocfg);
3929 if (err < 0)
3930 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003931 }
Mattc7d4b2f2005-06-27 14:59:41 +02003932
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003933 /* setup analog beep controls */
3934 if (spec->anabeep_nid > 0) {
3935 err = stac92xx_auto_create_beep_ctls(codec,
3936 spec->anabeep_nid);
3937 if (err < 0)
3938 return err;
3939 }
3940
3941 /* setup digital beep controls and input device */
3942#ifdef CONFIG_SND_HDA_INPUT_BEEP
3943 if (spec->digbeep_nid > 0) {
3944 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003945 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003946
3947 err = stac92xx_auto_create_beep_ctls(codec, nid);
3948 if (err < 0)
3949 return err;
3950 err = snd_hda_attach_beep_device(codec, nid);
3951 if (err < 0)
3952 return err;
Takashi Iwaifa797962009-05-19 12:50:04 +02003953 /* IDT/STAC codecs have linear beep tone parameter */
3954 codec->beep->linear_tone = 1;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003955 /* if no beep switch is available, make its own one */
3956 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3957 if (codec->beep &&
3958 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3959 err = stac92xx_beep_switch_ctl(codec);
3960 if (err < 0)
3961 return err;
3962 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003963 }
3964#endif
3965
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003966 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003967 if (err < 0)
3968 return err;
3969
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003970 /* All output parsing done, now restore the swapped hp pins */
3971 if (hp_swap) {
3972 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3973 sizeof(spec->autocfg.hp_pins));
3974 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3975 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3976 spec->autocfg.line_outs = 0;
3977 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003978
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003979 if (stac_check_auto_mic(codec)) {
3980 spec->auto_mic = 1;
3981 /* only one capture for auto-mic */
3982 spec->num_adcs = 1;
3983 spec->num_caps = 1;
3984 spec->num_muxes = 1;
3985 }
3986
Takashi Iwai6479c632009-07-28 18:20:25 +02003987 for (i = 0; i < spec->num_caps; i++) {
3988 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3989 spec->capsws[i], i);
3990 if (err < 0)
3991 return err;
3992 }
3993
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003994 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003995 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003996 return err;
3997
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003998 if (spec->mono_nid > 0) {
3999 err = stac92xx_auto_create_mono_output_ctls(codec);
4000 if (err < 0)
4001 return err;
4002 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004003 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04004004 err = stac92xx_auto_create_amp_output_ctls(codec);
4005 if (err < 0)
4006 return err;
4007 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004008 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02004009 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
4010 &spec->autocfg)) < 0)
4011 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02004012 if (spec->num_muxes > 0) {
4013 err = stac92xx_auto_create_mux_input_ctls(codec);
4014 if (err < 0)
4015 return err;
4016 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02004017 if (spec->num_smuxes > 0) {
4018 err = stac92xx_auto_create_spdif_mux_ctls(codec);
4019 if (err < 0)
4020 return err;
4021 }
Matt Porter8b657272006-10-26 17:12:59 +02004022
Takashi Iwaie3c75962009-01-23 11:57:22 +01004023 err = stac92xx_add_input_source(spec);
4024 if (err < 0)
4025 return err;
4026
Mattc7d4b2f2005-06-27 14:59:41 +02004027 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01004028 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02004029 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02004030
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004031 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004032 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004033 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01004034 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02004035
Takashi Iwai603c4012008-07-30 15:01:44 +02004036 if (spec->kctls.list)
4037 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004038
4039 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05004040 if (!spec->dinput_mux)
4041 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004042 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01004043 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04004044 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02004045 return 1;
4046}
4047
Takashi Iwai82bc9552006-03-21 11:24:42 +01004048/* add playback controls for HP output */
4049static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
4050 struct auto_pin_cfg *cfg)
4051{
4052 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004053 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01004054 unsigned int wid_caps;
4055
4056 if (! pin)
4057 return 0;
4058
4059 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02004060 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01004061 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004062
4063 return 0;
4064}
4065
Richard Fish160ea0d2006-09-06 13:58:25 +02004066/* add playback controls for LFE output */
4067static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4068 struct auto_pin_cfg *cfg)
4069{
4070 struct sigmatel_spec *spec = codec->spec;
4071 int err;
4072 hda_nid_t lfe_pin = 0x0;
4073 int i;
4074
4075 /*
4076 * search speaker outs and line outs for a mono speaker pin
4077 * with an amp. If one is found, add LFE controls
4078 * for it.
4079 */
4080 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4081 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004082 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004083 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4084 if (wcaps == AC_WCAP_OUT_AMP)
4085 /* found a mono speaker with an amp, must be lfe */
4086 lfe_pin = pin;
4087 }
4088
4089 /* if speaker_outs is 0, then speakers may be in line_outs */
4090 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4091 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4092 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004093 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004094 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004095 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004096 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004097 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4098 if (wcaps == AC_WCAP_OUT_AMP)
4099 /* found a mono speaker with an amp,
4100 must be lfe */
4101 lfe_pin = pin;
4102 }
4103 }
4104 }
4105
4106 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004107 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004108 if (err < 0)
4109 return err;
4110 }
4111
4112 return 0;
4113}
4114
Mattc7d4b2f2005-06-27 14:59:41 +02004115static int stac9200_parse_auto_config(struct hda_codec *codec)
4116{
4117 struct sigmatel_spec *spec = codec->spec;
4118 int err;
4119
Kailang Yangdf694da2005-12-05 19:42:22 +01004120 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004121 return err;
4122
4123 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4124 return err;
4125
Takashi Iwai82bc9552006-03-21 11:24:42 +01004126 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4127 return err;
4128
Richard Fish160ea0d2006-09-06 13:58:25 +02004129 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4130 return err;
4131
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004132 if (spec->num_muxes > 0) {
4133 err = stac92xx_auto_create_mux_input_ctls(codec);
4134 if (err < 0)
4135 return err;
4136 }
4137
Takashi Iwaie3c75962009-01-23 11:57:22 +01004138 err = stac92xx_add_input_source(spec);
4139 if (err < 0)
4140 return err;
4141
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004142 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004143 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004144 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004145 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004146
Takashi Iwai603c4012008-07-30 15:01:44 +02004147 if (spec->kctls.list)
4148 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004149
4150 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004151 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004152
4153 return 1;
4154}
4155
Sam Revitch62fe78e2006-05-10 15:09:17 +02004156/*
4157 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4158 * funky external mute control using GPIO pins.
4159 */
4160
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004161static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004162 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004163{
4164 unsigned int gpiostate, gpiomask, gpiodir;
4165
4166 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4167 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004168 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004169
4170 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4171 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004172 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004173
4174 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4175 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004176 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004177
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004178 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004179 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4180
4181 snd_hda_codec_write(codec, codec->afg, 0,
4182 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004183 snd_hda_codec_read(codec, codec->afg, 0,
4184 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004185
4186 msleep(1);
4187
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004188 snd_hda_codec_read(codec, codec->afg, 0,
4189 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004190}
4191
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004192#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +02004193static void stac92xx_free_jack_priv(struct snd_jack *jack)
4194{
4195 struct sigmatel_jack *jacks = jack->private_data;
4196 jacks->nid = 0;
4197 jacks->jack = NULL;
4198}
4199#endif
4200
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004201static int stac92xx_add_jack(struct hda_codec *codec,
4202 hda_nid_t nid, int type)
4203{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004204#ifdef CONFIG_SND_HDA_INPUT_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004205 struct sigmatel_spec *spec = codec->spec;
4206 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01004207 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004208 int connectivity = get_defcfg_connect(def_conf);
4209 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02004210 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004211
4212 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4213 return 0;
4214
4215 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4216 jack = snd_array_new(&spec->jacks);
4217 if (!jack)
4218 return -ENOMEM;
4219 jack->nid = nid;
4220 jack->type = type;
4221
Takashi Iwai86de7412009-07-22 16:02:46 +02004222 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004223 snd_hda_get_jack_type(def_conf),
4224 snd_hda_get_jack_connectivity(def_conf),
4225 snd_hda_get_jack_location(def_conf));
4226
Takashi Iwai95c09092009-04-14 16:15:29 +02004227 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4228 if (err < 0) {
4229 jack->nid = 0;
4230 return err;
4231 }
4232 jack->jack->private_data = jack;
4233 jack->jack->private_free = stac92xx_free_jack_priv;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004234#endif
Takashi Iwai95c09092009-04-14 16:15:29 +02004235 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004236}
4237
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004238static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4239 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004240{
4241 struct sigmatel_event *event;
4242
4243 snd_array_init(&spec->events, sizeof(*event), 32);
4244 event = snd_array_new(&spec->events);
4245 if (!event)
4246 return -ENOMEM;
4247 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004248 event->type = type;
4249 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004250 event->data = data;
4251
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004252 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004253}
4254
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004255static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004256 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004257{
4258 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004259 struct sigmatel_event *event = spec->events.list;
4260 int i;
4261
4262 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004263 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004264 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004265 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004266 return NULL;
4267}
4268
4269static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4270 unsigned char tag)
4271{
4272 struct sigmatel_spec *spec = codec->spec;
4273 struct sigmatel_event *event = spec->events.list;
4274 int i;
4275
4276 for (i = 0; i < spec->events.used; i++, event++) {
4277 if (event->tag == tag)
4278 return event;
4279 }
4280 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004281}
4282
Takashi Iwai62558ce2009-07-29 14:23:09 +02004283/* check if given nid is a valid pin and no other events are assigned
4284 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4285 * Otherwise, returns zero.
4286 */
4287static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4288 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004289{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004290 struct sigmatel_event *event;
4291 int tag;
4292
4293 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004294 return 0;
4295 event = stac_get_event(codec, nid);
4296 if (event) {
4297 if (event->type != type)
4298 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004299 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004300 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004301 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004302 if (tag < 0)
4303 return 0;
4304 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004305 snd_hda_codec_write_cache(codec, nid, 0,
4306 AC_VERB_SET_UNSOLICITED_ENABLE,
4307 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004308 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004309}
4310
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004311static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4312{
4313 int i;
4314 for (i = 0; i < cfg->hp_outs; i++)
4315 if (cfg->hp_pins[i] == nid)
4316 return 1; /* nid is a HP-Out */
4317
4318 return 0; /* nid is not a HP-Out */
4319};
4320
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004321static void stac92xx_power_down(struct hda_codec *codec)
4322{
4323 struct sigmatel_spec *spec = codec->spec;
4324
4325 /* power down inactive DACs */
4326 hda_nid_t *dac;
4327 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004328 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004329 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004330 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4331}
4332
Takashi Iwaif73d3582008-11-25 08:21:51 +01004333static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4334 int enable);
4335
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004336/* override some hints from the hwdep entry */
4337static void stac_store_hints(struct hda_codec *codec)
4338{
4339 struct sigmatel_spec *spec = codec->spec;
4340 const char *p;
4341 int val;
4342
4343 val = snd_hda_get_bool_hint(codec, "hp_detect");
4344 if (val >= 0)
4345 spec->hp_detect = val;
4346 p = snd_hda_get_hint(codec, "gpio_mask");
4347 if (p) {
4348 spec->gpio_mask = simple_strtoul(p, NULL, 0);
4349 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4350 spec->gpio_mask;
4351 }
4352 p = snd_hda_get_hint(codec, "gpio_dir");
4353 if (p)
4354 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4355 p = snd_hda_get_hint(codec, "gpio_data");
4356 if (p)
4357 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4358 p = snd_hda_get_hint(codec, "eapd_mask");
4359 if (p)
4360 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4361 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4362 if (val >= 0)
4363 spec->eapd_switch = val;
4364}
4365
Mattc7d4b2f2005-06-27 14:59:41 +02004366static int stac92xx_init(struct hda_codec *codec)
4367{
4368 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004369 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004370 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004371 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004372
Mattc7d4b2f2005-06-27 14:59:41 +02004373 snd_hda_sequence_write(codec, spec->init);
4374
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004375 /* power down adcs initially */
4376 if (spec->powerdown_adcs)
4377 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004378 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004379 spec->adc_nids[i], 0,
4380 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004381
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004382 /* override some hints */
4383 stac_store_hints(codec);
4384
Takashi Iwaif73d3582008-11-25 08:21:51 +01004385 /* set up GPIO */
4386 gpio = spec->gpio_data;
4387 /* turn on EAPD statically when spec->eapd_switch isn't set.
4388 * otherwise, unsol event will turn it on/off dynamically
4389 */
4390 if (!spec->eapd_switch)
4391 gpio |= spec->eapd_mask;
4392 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4393
Takashi Iwai82bc9552006-03-21 11:24:42 +01004394 /* set up pins */
4395 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004396 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004397 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004398 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004399 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004400 }
Takashi Iwai1c4bdf92009-08-13 08:23:24 +02004401 if (cfg->line_out_type == AUTO_PIN_LINE_OUT &&
4402 cfg->speaker_outs > 0) {
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004403 /* enable pin-detect for line-outs as well */
Takashi Iwai15cfa2b2009-08-03 14:23:33 +02004404 for (i = 0; i < cfg->line_outs; i++) {
4405 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004406 enable_pin_detect(codec, nid, STAC_LO_EVENT);
4407 }
4408 }
4409
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004410 /* force to enable the first line-out; the others are set up
4411 * in unsol_event
4412 */
4413 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004414 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004415 /* fake event to set up pins */
Takashi Iwai62558ce2009-07-29 14:23:09 +02004416 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004417 } else {
4418 stac92xx_auto_init_multi_out(codec);
4419 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004420 for (i = 0; i < cfg->hp_outs; i++)
4421 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004422 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004423 if (spec->auto_mic) {
Takashi Iwai15b4f292009-07-29 16:32:55 +02004424 /* initialize connection to analog input */
Takashi Iwaida2a2aa2009-08-10 07:44:09 +02004425 if (spec->dmux_nids)
4426 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
Takashi Iwai15b4f292009-07-29 16:32:55 +02004427 AC_VERB_SET_CONNECT_SEL, 0);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004428 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4429 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4430 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004431 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01004432 hda_nid_t nid = cfg->input_pins[i];
4433 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004434 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004435 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4436 /* for mic pins, force to initialize */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02004437 pinctl = stac92xx_get_default_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004438 pinctl |= AC_PINCTL_IN_EN;
4439 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004440 } else {
4441 pinctl = snd_hda_codec_read(codec, nid, 0,
4442 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4443 /* if PINCTL already set then skip */
Takashi Iwai5dd17cb2009-05-07 16:22:53 +02004444 /* Also, if both INPUT and OUTPUT are set,
4445 * it must be a BIOS bug; need to override, too
4446 */
4447 if (!(pinctl & AC_PINCTL_IN_EN) ||
4448 (pinctl & AC_PINCTL_OUT_EN)) {
4449 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004450 pinctl |= AC_PINCTL_IN_EN;
4451 stac92xx_auto_set_pinctl(codec, nid,
4452 pinctl);
4453 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004454 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004455 conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004456 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004457 if (enable_pin_detect(codec, nid,
4458 STAC_INSERT_EVENT))
4459 stac_issue_unsol_event(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004460 }
Takashi Iwaic960a032006-03-23 17:06:28 +01004461 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004462 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004463 for (i = 0; i < spec->num_dmics; i++)
4464 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4465 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004466 if (cfg->dig_out_pins[0])
4467 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004468 AC_PINCTL_OUT_EN);
4469 if (cfg->dig_in_pin)
4470 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4471 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004472 for (i = 0; i < spec->num_pwrs; i++) {
4473 hda_nid_t nid = spec->pwr_nids[i];
4474 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004475
Takashi Iwaieb632122008-12-19 16:39:48 +01004476 /* power on when no jack detection is available */
4477 if (!spec->hp_detect) {
4478 stac_toggle_power_map(codec, nid, 1);
4479 continue;
4480 }
4481
4482 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004483 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004484
Takashi Iwaif73d3582008-11-25 08:21:51 +01004485 pinctl = snd_hda_codec_read(codec, nid, 0,
4486 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4487 /* outputs are only ports capable of power management
4488 * any attempts on powering down a input port cause the
4489 * referenced VREF to act quirky.
4490 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004491 if (pinctl & AC_PINCTL_IN_EN) {
4492 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004493 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004494 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004495 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004496 def_conf = get_defcfg_connect(def_conf);
4497 /* skip any ports that don't have jacks since presence
4498 * detection is useless */
4499 if (def_conf != AC_JACK_PORT_COMPLEX) {
4500 if (def_conf != AC_JACK_PORT_NONE)
4501 stac_toggle_power_map(codec, nid, 1);
4502 continue;
4503 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004504 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4505 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004506 }
4507 if (spec->dac_list)
4508 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004509 return 0;
4510}
4511
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004512static void stac92xx_free_jacks(struct hda_codec *codec)
4513{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004514#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01004515 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004516 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01004517 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004518 struct sigmatel_jack *jacks = spec->jacks.list;
4519 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +02004520 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4521 if (jacks->jack)
4522 snd_device_free(codec->bus->card, jacks->jack);
4523 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004524 }
4525 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004526#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004527}
4528
Takashi Iwai603c4012008-07-30 15:01:44 +02004529static void stac92xx_free_kctls(struct hda_codec *codec)
4530{
4531 struct sigmatel_spec *spec = codec->spec;
4532
4533 if (spec->kctls.list) {
4534 struct snd_kcontrol_new *kctl = spec->kctls.list;
4535 int i;
4536 for (i = 0; i < spec->kctls.used; i++)
4537 kfree(kctl[i].name);
4538 }
4539 snd_array_free(&spec->kctls);
4540}
4541
Matt2f2f4252005-04-13 14:45:30 +02004542static void stac92xx_free(struct hda_codec *codec)
4543{
Mattc7d4b2f2005-06-27 14:59:41 +02004544 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004545
4546 if (! spec)
4547 return;
4548
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004549 stac92xx_free_jacks(codec);
4550 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004551
Mattc7d4b2f2005-06-27 14:59:41 +02004552 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004553 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004554}
4555
Matt4e550962005-07-04 17:51:39 +02004556static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4557 unsigned int flag)
4558{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004559 unsigned int old_ctl, pin_ctl;
4560
4561 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004562 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004563
Takashi Iwaif9acba42007-05-29 18:01:06 +02004564 if (pin_ctl & AC_PINCTL_IN_EN) {
4565 /*
4566 * we need to check the current set-up direction of
4567 * shared input pins since they can be switched via
4568 * "xxx as Output" mixer switch
4569 */
4570 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004571 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004572 return;
4573 }
4574
Takashi Iwai8ce84192009-01-22 16:59:20 +01004575 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004576 /* if setting pin direction bits, clear the current
4577 direction bits first */
4578 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4579 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4580
Takashi Iwai8ce84192009-01-22 16:59:20 +01004581 pin_ctl |= flag;
4582 if (old_ctl != pin_ctl)
4583 snd_hda_codec_write_cache(codec, nid, 0,
4584 AC_VERB_SET_PIN_WIDGET_CONTROL,
4585 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004586}
4587
4588static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4589 unsigned int flag)
4590{
4591 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4592 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004593 if (pin_ctl & flag)
4594 snd_hda_codec_write_cache(codec, nid, 0,
4595 AC_VERB_SET_PIN_WIDGET_CONTROL,
4596 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004597}
4598
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004599static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004600{
4601 if (!nid)
4602 return 0;
4603 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004604 & (1 << 31))
4605 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004606 return 0;
4607}
4608
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004609static void stac92xx_line_out_detect(struct hda_codec *codec,
4610 int presence)
4611{
4612 struct sigmatel_spec *spec = codec->spec;
4613 struct auto_pin_cfg *cfg = &spec->autocfg;
4614 int i;
4615
4616 for (i = 0; i < cfg->line_outs; i++) {
4617 if (presence)
4618 break;
4619 presence = get_pin_presence(codec, cfg->line_out_pins[i]);
4620 if (presence) {
4621 unsigned int pinctl;
4622 pinctl = snd_hda_codec_read(codec,
4623 cfg->line_out_pins[i], 0,
4624 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4625 if (pinctl & AC_PINCTL_IN_EN)
4626 presence = 0; /* mic- or line-input */
4627 }
4628 }
4629
4630 if (presence) {
4631 /* disable speakers */
4632 for (i = 0; i < cfg->speaker_outs; i++)
4633 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4634 AC_PINCTL_OUT_EN);
4635 if (spec->eapd_mask && spec->eapd_switch)
4636 stac_gpio_set(codec, spec->gpio_mask,
4637 spec->gpio_dir, spec->gpio_data &
4638 ~spec->eapd_mask);
4639 } else {
4640 /* enable speakers */
4641 for (i = 0; i < cfg->speaker_outs; i++)
4642 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4643 AC_PINCTL_OUT_EN);
4644 if (spec->eapd_mask && spec->eapd_switch)
4645 stac_gpio_set(codec, spec->gpio_mask,
4646 spec->gpio_dir, spec->gpio_data |
4647 spec->eapd_mask);
4648 }
4649}
4650
Takashi Iwaid7a89432008-11-12 09:48:04 +01004651/* return non-zero if the hp-pin of the given array index isn't
4652 * a jack-detection target
4653 */
4654static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4655{
4656 struct auto_pin_cfg *cfg = &spec->autocfg;
4657
4658 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004659 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004660 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004661 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004662 return 1;
4663 /* ignore if the pin is set as line-out */
4664 if (cfg->hp_pins[i] == spec->hp_switch)
4665 return 1;
4666 return 0;
4667}
4668
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004669static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004670{
4671 struct sigmatel_spec *spec = codec->spec;
4672 struct auto_pin_cfg *cfg = &spec->autocfg;
4673 int i, presence;
4674
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004675 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004676 if (spec->gpio_mute)
4677 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4678 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4679
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004680 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004681 if (presence)
4682 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004683 if (no_hp_sensing(spec, i))
4684 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004685 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4686 if (presence) {
4687 unsigned int pinctl;
4688 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4689 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4690 if (pinctl & AC_PINCTL_IN_EN)
4691 presence = 0; /* mic- or line-input */
4692 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004693 }
Matt4e550962005-07-04 17:51:39 +02004694
4695 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004696 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004697 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004698 stac92xx_reset_pinctl(codec, spec->hp_switch,
4699 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004700 for (i = 0; i < cfg->line_outs; i++)
4701 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4702 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004703 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004704 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004705 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004706 stac92xx_set_pinctl(codec, spec->hp_switch,
4707 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004708 for (i = 0; i < cfg->line_outs; i++)
4709 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4710 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004711 }
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004712 stac92xx_line_out_detect(codec, presence);
Takashi Iwaid7a89432008-11-12 09:48:04 +01004713 /* toggle hp outs */
4714 for (i = 0; i < cfg->hp_outs; i++) {
4715 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4716 if (no_hp_sensing(spec, i))
4717 continue;
4718 if (presence)
4719 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004720#if 0 /* FIXME */
4721/* Resetting the pinctl like below may lead to (a sort of) regressions
4722 * on some devices since they use the HP pin actually for line/speaker
4723 * outs although the default pin config shows a different pin (that is
4724 * wrong and useless).
4725 *
4726 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4727 * But, disabling the code below just works around it, and I'm too tired of
4728 * bug reports with such devices...
4729 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004730 else
4731 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004732#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004733 }
Matt4e550962005-07-04 17:51:39 +02004734}
4735
Takashi Iwaif73d3582008-11-25 08:21:51 +01004736static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4737 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004738{
4739 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004740 unsigned int idx, val;
4741
4742 for (idx = 0; idx < spec->num_pwrs; idx++) {
4743 if (spec->pwr_nids[idx] == nid)
4744 break;
4745 }
4746 if (idx >= spec->num_pwrs)
4747 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004748
4749 /* several codecs have two power down bits */
4750 if (spec->pwr_mapping)
4751 idx = spec->pwr_mapping[idx];
4752 else
4753 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004754
Takashi Iwaif73d3582008-11-25 08:21:51 +01004755 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4756 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004757 val &= ~idx;
4758 else
4759 val |= idx;
4760
4761 /* power down unused output ports */
4762 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004763}
4764
Takashi Iwaif73d3582008-11-25 08:21:51 +01004765static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4766{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004767 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004768}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004769
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004770static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4771{
4772 struct sigmatel_spec *spec = codec->spec;
4773 struct sigmatel_jack *jacks = spec->jacks.list;
4774
4775 if (jacks) {
4776 int i;
4777 for (i = 0; i < spec->jacks.used; i++) {
4778 if (jacks->nid == nid) {
4779 unsigned int pin_ctl =
4780 snd_hda_codec_read(codec, nid,
4781 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4782 0x00);
4783 int type = jacks->type;
4784 if (type == (SND_JACK_LINEOUT
4785 | SND_JACK_HEADPHONE))
4786 type = (pin_ctl & AC_PINCTL_HP_EN)
4787 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4788 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004789 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004790 ? type : 0);
4791 }
4792 jacks++;
4793 }
4794 }
4795}
Matt2f2f4252005-04-13 14:45:30 +02004796
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004797static void stac92xx_mic_detect(struct hda_codec *codec)
4798{
4799 struct sigmatel_spec *spec = codec->spec;
4800 struct sigmatel_mic_route *mic;
4801
4802 if (get_pin_presence(codec, spec->ext_mic.pin))
4803 mic = &spec->ext_mic;
4804 else
4805 mic = &spec->int_mic;
4806 if (mic->dmux_idx)
4807 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4808 AC_VERB_SET_CONNECT_SEL,
4809 mic->dmux_idx);
4810 else
4811 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4812 AC_VERB_SET_CONNECT_SEL,
4813 mic->mux_idx);
4814}
4815
Takashi Iwai62558ce2009-07-29 14:23:09 +02004816static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004817{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004818 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004819 if (!event)
4820 return;
4821 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4822}
4823
Takashi Iwai314634b2006-09-21 11:56:18 +02004824static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4825{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004826 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004827 struct sigmatel_event *event;
4828 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004829
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004830 tag = (res >> 26) & 0x7f;
4831 event = stac_get_event_from_tag(codec, tag);
4832 if (!event)
4833 return;
4834
4835 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004836 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004837 case STAC_LO_EVENT:
Takashi Iwai16ffe322009-08-04 13:40:54 +02004838 stac92xx_hp_detect(codec);
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004839 break;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004840 case STAC_MIC_EVENT:
4841 stac92xx_mic_detect(codec);
4842 break;
4843 }
4844
4845 switch (event->type) {
4846 case STAC_HP_EVENT:
Takashi Iwaifefd67f2009-07-30 18:03:05 +02004847 case STAC_LO_EVENT:
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004848 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004849 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004850 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004851 if (spec->num_pwrs > 0)
4852 stac92xx_pin_sense(codec, event->nid);
4853 stac92xx_report_jack(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004854
4855 switch (codec->subsystem_id) {
4856 case 0x103c308f:
4857 if (event->nid == 0xb) {
4858 int pin = AC_PINCTL_IN_EN;
4859
4860 if (get_pin_presence(codec, 0xa)
4861 && get_pin_presence(codec, 0xb))
4862 pin |= AC_PINCTL_VREF_80;
4863 if (!get_pin_presence(codec, 0xb))
4864 pin |= AC_PINCTL_VREF_80;
4865
4866 /* toggle VREF state based on mic + hp pin
4867 * status
4868 */
4869 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4870 }
4871 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004872 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004873 case STAC_VREF_EVENT:
4874 data = snd_hda_codec_read(codec, codec->afg, 0,
4875 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004876 /* toggle VREF state based on GPIOx status */
4877 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004878 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004879 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004880 }
4881}
4882
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004883#ifdef CONFIG_PROC_FS
4884static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4885 struct hda_codec *codec, hda_nid_t nid)
4886{
4887 if (nid == codec->afg)
4888 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4889 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4890}
4891
4892static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4893 struct hda_codec *codec,
4894 unsigned int verb)
4895{
4896 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4897 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4898}
4899
4900/* stac92hd71bxx, stac92hd73xx */
4901static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4902 struct hda_codec *codec, hda_nid_t nid)
4903{
4904 stac92hd_proc_hook(buffer, codec, nid);
4905 if (nid == codec->afg)
4906 analog_loop_proc_hook(buffer, codec, 0xfa0);
4907}
4908
4909static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4910 struct hda_codec *codec, hda_nid_t nid)
4911{
4912 if (nid == codec->afg)
4913 analog_loop_proc_hook(buffer, codec, 0xfe0);
4914}
4915
4916static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4917 struct hda_codec *codec, hda_nid_t nid)
4918{
4919 if (nid == codec->afg)
4920 analog_loop_proc_hook(buffer, codec, 0xfeb);
4921}
4922#else
4923#define stac92hd_proc_hook NULL
4924#define stac92hd7x_proc_hook NULL
4925#define stac9205_proc_hook NULL
4926#define stac927x_proc_hook NULL
4927#endif
4928
Takashi Iwaicb53c622007-08-10 17:21:45 +02004929#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004930static int stac92xx_resume(struct hda_codec *codec)
4931{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004932 struct sigmatel_spec *spec = codec->spec;
4933
Takashi Iwai2c885872008-11-18 09:36:55 +01004934 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004935 snd_hda_codec_resume_amp(codec);
4936 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004937 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004938 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02004939 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
Mattff6fdc32005-06-27 15:06:52 +02004940 return 0;
4941}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004942
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004943/*
James Gardiner514bf542009-05-03 04:00:44 -04004944 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004945 * check for mute state only on Speakers (nid = 0x10)
4946 *
4947 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4948 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004949 *
4950 * Changed name to reflect that it now works for any designated
4951 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004952 */
4953
4954#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004955static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004956 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004957{
4958 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004959
4960 if (nid == 0x10) {
4961 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004962 HDA_AMP_MUTE)
Takashi Iwai86d190e2009-05-26 15:18:58 +02004963 spec->gpio_data &= ~spec->gpio_led; /* orange */
Takashi Iwaiba84bfc2009-05-30 08:59:03 +02004964 else
4965 spec->gpio_data |= spec->gpio_led; /* white */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004966
4967 stac_gpio_set(codec, spec->gpio_mask,
4968 spec->gpio_dir,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004969 spec->gpio_data);
4970 }
4971
4972 return 0;
4973}
4974#endif
4975
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004976static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4977{
4978 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004979 int i;
4980 hda_nid_t nid;
4981
4982 /* reset each pin before powering down DAC/ADC to avoid click noise */
4983 nid = codec->start_nid;
4984 for (i = 0; i < codec->num_nodes; i++, nid++) {
4985 unsigned int wcaps = get_wcaps(codec, nid);
Takashi Iwaia22d5432009-07-27 12:54:26 +02004986 unsigned int wid_type = get_wcaps_type(wcaps);
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004987 if (wid_type == AC_WID_PIN)
4988 snd_hda_codec_read(codec, nid, 0,
4989 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4990 }
4991
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004992 if (spec->eapd_mask)
4993 stac_gpio_set(codec, spec->gpio_mask,
4994 spec->gpio_dir, spec->gpio_data &
4995 ~spec->eapd_mask);
4996 return 0;
4997}
Mattff6fdc32005-06-27 15:06:52 +02004998#endif
4999
Matt2f2f4252005-04-13 14:45:30 +02005000static struct hda_codec_ops stac92xx_patch_ops = {
5001 .build_controls = stac92xx_build_controls,
5002 .build_pcms = stac92xx_build_pcms,
5003 .init = stac92xx_init,
5004 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02005005 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02005006#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05005007 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02005008 .resume = stac92xx_resume,
5009#endif
Matt2f2f4252005-04-13 14:45:30 +02005010};
5011
5012static int patch_stac9200(struct hda_codec *codec)
5013{
5014 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005015 int err;
Matt2f2f4252005-04-13 14:45:30 +02005016
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005017 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005018 if (spec == NULL)
5019 return -ENOMEM;
5020
5021 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005022 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005023 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005024 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
5025 stac9200_models,
5026 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01005027 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005028 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5029 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005030 else
5031 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005032 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005033
5034 spec->multiout.max_channels = 2;
5035 spec->multiout.num_dacs = 1;
5036 spec->multiout.dac_nids = stac9200_dac_nids;
5037 spec->adc_nids = stac9200_adc_nids;
5038 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02005039 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02005040 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005041 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005042 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005043
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02005044 if (spec->board_config == STAC_9200_M4 ||
5045 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01005046 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02005047 spec->init = stac9200_eapd_init;
5048 else
5049 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005050 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005051
Takashi Iwai117f2572008-03-18 09:53:23 +01005052 if (spec->board_config == STAC_9200_PANASONIC) {
5053 spec->gpio_mask = spec->gpio_dir = 0x09;
5054 spec->gpio_data = 0x00;
5055 }
5056
Mattc7d4b2f2005-06-27 14:59:41 +02005057 err = stac9200_parse_auto_config(codec);
5058 if (err < 0) {
5059 stac92xx_free(codec);
5060 return err;
5061 }
Matt2f2f4252005-04-13 14:45:30 +02005062
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01005063 /* CF-74 has no headphone detection, and the driver should *NOT*
5064 * do detection and HP/speaker toggle because the hardware does it.
5065 */
5066 if (spec->board_config == STAC_9200_PANASONIC)
5067 spec->hp_detect = 0;
5068
Matt2f2f4252005-04-13 14:45:30 +02005069 codec->patch_ops = stac92xx_patch_ops;
5070
5071 return 0;
5072}
5073
Tobin Davis8e21c342007-01-08 11:04:17 +01005074static int patch_stac925x(struct hda_codec *codec)
5075{
5076 struct sigmatel_spec *spec;
5077 int err;
5078
5079 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5080 if (spec == NULL)
5081 return -ENOMEM;
5082
5083 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005084 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01005085 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02005086
5087 /* Check first for codec ID */
5088 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
5089 STAC_925x_MODELS,
5090 stac925x_models,
5091 stac925x_codec_id_cfg_tbl);
5092
5093 /* Now checks for PCI ID, if codec ID is not found */
5094 if (spec->board_config < 0)
5095 spec->board_config = snd_hda_check_board_config(codec,
5096 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005097 stac925x_models,
5098 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005099 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005100 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005101 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5102 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005103 else
5104 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005105 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005106
5107 spec->multiout.max_channels = 2;
5108 spec->multiout.num_dacs = 1;
5109 spec->multiout.dac_nids = stac925x_dac_nids;
5110 spec->adc_nids = stac925x_adc_nids;
5111 spec->mux_nids = stac925x_mux_nids;
5112 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005113 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005114 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005115 switch (codec->vendor_id) {
5116 case 0x83847632: /* STAC9202 */
5117 case 0x83847633: /* STAC9202D */
5118 case 0x83847636: /* STAC9251 */
5119 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005120 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005121 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005122 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5123 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005124 break;
5125 default:
5126 spec->num_dmics = 0;
5127 break;
5128 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005129
5130 spec->init = stac925x_core_init;
5131 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005132 spec->num_caps = 1;
5133 spec->capvols = stac925x_capvols;
5134 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005135
5136 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005137 if (!err) {
5138 if (spec->board_config < 0) {
5139 printk(KERN_WARNING "hda_codec: No auto-config is "
5140 "available, default to model=ref\n");
5141 spec->board_config = STAC_925x_REF;
5142 goto again;
5143 }
5144 err = -EINVAL;
5145 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005146 if (err < 0) {
5147 stac92xx_free(codec);
5148 return err;
5149 }
5150
5151 codec->patch_ops = stac92xx_patch_ops;
5152
5153 return 0;
5154}
5155
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005156static int patch_stac92hd73xx(struct hda_codec *codec)
5157{
5158 struct sigmatel_spec *spec;
5159 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5160 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005161 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005162
5163 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5164 if (spec == NULL)
5165 return -ENOMEM;
5166
5167 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005168 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005169 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5170 spec->pin_nids = stac92hd73xx_pin_nids;
5171 spec->board_config = snd_hda_check_board_config(codec,
5172 STAC_92HD73XX_MODELS,
5173 stac92hd73xx_models,
5174 stac92hd73xx_cfg_tbl);
5175again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005176 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005177 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5178 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005179 else
5180 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005181 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005182
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005183 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005184 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5185
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005186 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005187 printk(KERN_WARNING "hda_codec: Could not determine "
5188 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005189 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005190 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005191 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005192 case 0x3: /* 6 Channel */
5193 spec->mixer = stac92hd73xx_6ch_mixer;
5194 spec->init = stac92hd73xx_6ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005195 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005196 break;
5197 case 0x4: /* 8 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005198 spec->mixer = stac92hd73xx_8ch_mixer;
5199 spec->init = stac92hd73xx_8ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005200 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005201 break;
5202 case 0x5: /* 10 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005203 spec->mixer = stac92hd73xx_10ch_mixer;
5204 spec->init = stac92hd73xx_10ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005205 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5206 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005207 }
5208 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005209
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005210 spec->aloopback_mask = 0x01;
5211 spec->aloopback_shift = 8;
5212
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005213 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005214 spec->mux_nids = stac92hd73xx_mux_nids;
5215 spec->adc_nids = stac92hd73xx_adc_nids;
5216 spec->dmic_nids = stac92hd73xx_dmic_nids;
5217 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005218 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04005219 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005220 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005221
5222 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5223 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005224 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005225
Takashi Iwai6479c632009-07-28 18:20:25 +02005226 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5227 spec->capvols = stac92hd73xx_capvols;
5228 spec->capsws = stac92hd73xx_capsws;
5229
Matthew Ranostaya7662642008-02-21 07:51:14 +01005230 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005231 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005232 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005233 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005234 case STAC_DELL_M6_AMIC:
5235 case STAC_DELL_M6_DMIC:
5236 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005237 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005238 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
5239 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005240 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005241 spec->num_amps = 1;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005242
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005243 if (spec->board_config != STAC_DELL_EQ)
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005244 spec->init = dell_m6_core_init;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005245 switch (spec->board_config) {
5246 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005247 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005248 spec->num_dmics = 0;
5249 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005250 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005251 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005252 spec->num_dmics = 1;
5253 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005254 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005255 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5256 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005257 spec->num_dmics = 1;
5258 break;
5259 }
5260 break;
5261 default:
5262 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005263 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005264 spec->eapd_switch = 1;
Takashi Iwai5207e102009-07-30 13:09:08 +02005265 break;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005266 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005267 if (spec->board_config > STAC_92HD73XX_REF) {
5268 /* GPIO0 High = Enable EAPD */
5269 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5270 spec->gpio_data = 0x01;
5271 }
Matthew Ranostaya7662642008-02-21 07:51:14 +01005272
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005273 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5274 spec->pwr_nids = stac92hd73xx_pwr_nids;
5275
Matthew Ranostayd9737752008-09-07 12:03:41 +02005276 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005277
5278 if (!err) {
5279 if (spec->board_config < 0) {
5280 printk(KERN_WARNING "hda_codec: No auto-config is "
5281 "available, default to model=ref\n");
5282 spec->board_config = STAC_92HD73XX_REF;
5283 goto again;
5284 }
5285 err = -EINVAL;
5286 }
5287
5288 if (err < 0) {
5289 stac92xx_free(codec);
5290 return err;
5291 }
5292
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005293 if (spec->board_config == STAC_92HD73XX_NO_JD)
5294 spec->hp_detect = 0;
5295
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005296 codec->patch_ops = stac92xx_patch_ops;
5297
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005298 codec->proc_widget_hook = stac92hd7x_proc_hook;
5299
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005300 return 0;
5301}
5302
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005303static int patch_stac92hd83xxx(struct hda_codec *codec)
5304{
5305 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005306 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005307 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005308 int num_dacs;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005309 hda_nid_t nid;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005310
5311 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5312 if (spec == NULL)
5313 return -ENOMEM;
5314
5315 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005316 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005317 spec->mono_nid = 0x19;
5318 spec->digbeep_nid = 0x21;
Takashi Iwai667067d2009-08-13 18:14:42 +02005319 spec->mux_nids = stac92hd83xxx_mux_nids;
5320 spec->num_muxes = ARRAY_SIZE(stac92hd83xxx_mux_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005321 spec->adc_nids = stac92hd83xxx_adc_nids;
Takashi Iwai7570ef12009-08-15 11:57:53 +02005322 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005323 spec->pwr_nids = stac92hd83xxx_pwr_nids;
5324 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5325 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005326 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005327
5328 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005329 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005330 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005331 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5332 spec->capvols = stac92hd83xxx_capvols;
5333 spec->capsws = stac92hd83xxx_capsws;
5334
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005335 spec->board_config = snd_hda_check_board_config(codec,
5336 STAC_92HD83XXX_MODELS,
5337 stac92hd83xxx_models,
5338 stac92hd83xxx_cfg_tbl);
5339again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005340 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005341 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5342 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005343 else
5344 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005345 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005346
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005347 switch (codec->vendor_id) {
5348 case 0x111d7604:
5349 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005350 case 0x111d76d5:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005351 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5352 break;
5353 spec->num_pwrs = 0;
5354 break;
5355 }
5356
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005357 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5358 if (!err) {
5359 if (spec->board_config < 0) {
5360 printk(KERN_WARNING "hda_codec: No auto-config is "
5361 "available, default to model=ref\n");
5362 spec->board_config = STAC_92HD83XXX_REF;
5363 goto again;
5364 }
5365 err = -EINVAL;
5366 }
5367
5368 if (err < 0) {
5369 stac92xx_free(codec);
5370 return err;
5371 }
5372
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005373 switch (spec->board_config) {
5374 case STAC_DELL_S14:
5375 nid = 0xf;
5376 break;
5377 default:
5378 nid = 0xe;
5379 break;
5380 }
5381
5382 num_dacs = snd_hda_get_connections(codec, nid,
5383 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02005384 if (num_dacs < 0)
5385 num_dacs = STAC92HD83_DAC_COUNT;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005386
5387 /* set port X to select the last DAC
5388 */
5389 snd_hda_codec_write_cache(codec, nid, 0,
5390 AC_VERB_SET_CONNECT_SEL, num_dacs);
5391
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005392 codec->patch_ops = stac92xx_patch_ops;
5393
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005394 codec->proc_widget_hook = stac92hd_proc_hook;
5395
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005396 return 0;
5397}
5398
Takashi Iwai330ee992009-02-20 14:33:36 +01005399/* get the pin connection (fixed, none, etc) */
5400static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5401{
5402 struct sigmatel_spec *spec = codec->spec;
5403 unsigned int cfg;
5404
5405 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5406 return get_defcfg_connect(cfg);
5407}
5408
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005409static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5410 hda_nid_t *nids, int num_nids)
5411{
5412 struct sigmatel_spec *spec = codec->spec;
5413 int idx, num;
5414 unsigned int def_conf;
5415
5416 for (num = 0; num < num_nids; num++) {
5417 for (idx = 0; idx < spec->num_pins; idx++)
5418 if (spec->pin_nids[idx] == nids[num])
5419 break;
5420 if (idx >= spec->num_pins)
5421 break;
Takashi Iwai330ee992009-02-20 14:33:36 +01005422 def_conf = stac_get_defcfg_connect(codec, idx);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005423 if (def_conf == AC_JACK_PORT_NONE)
5424 break;
5425 }
5426 return num;
5427}
5428
5429static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5430 hda_nid_t dig0pin)
5431{
5432 struct sigmatel_spec *spec = codec->spec;
5433 int idx;
5434
5435 for (idx = 0; idx < spec->num_pins; idx++)
5436 if (spec->pin_nids[idx] == dig0pin)
5437 break;
5438 if ((idx + 2) >= spec->num_pins)
5439 return 0;
5440
5441 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005442 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005443 return 2;
5444
5445 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005446 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005447 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005448 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005449 return 1;
5450 else
5451 return 0;
5452}
5453
Matthew Ranostaye035b842007-11-06 11:53:55 +01005454static int patch_stac92hd71bxx(struct hda_codec *codec)
5455{
5456 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005457 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005458 int err = 0;
5459
5460 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5461 if (spec == NULL)
5462 return -ENOMEM;
5463
5464 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005465 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005466 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5467 switch (codec->vendor_id) {
5468 case 0x111d76b6:
5469 case 0x111d76b7:
5470 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5471 break;
5472 case 0x111d7603:
5473 case 0x111d7608:
5474 /* On 92HD75Bx 0x27 isn't a pin nid */
5475 spec->num_pins--;
5476 /* fallthrough */
5477 default:
5478 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5479 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005480 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005481 spec->board_config = snd_hda_check_board_config(codec,
5482 STAC_92HD71BXX_MODELS,
5483 stac92hd71bxx_models,
5484 stac92hd71bxx_cfg_tbl);
5485again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005486 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005487 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5488 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005489 else
5490 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005491 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005492
Takashi Iwai41c3b642008-11-18 10:45:15 +01005493 if (spec->board_config > STAC_92HD71BXX_REF) {
5494 /* GPIO0 = EAPD */
5495 spec->gpio_mask = 0x01;
5496 spec->gpio_dir = 0x01;
5497 spec->gpio_data = 0x01;
5498 }
5499
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005500 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5501 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5502
Takashi Iwai6479c632009-07-28 18:20:25 +02005503 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5504 spec->capvols = stac92hd71bxx_capvols;
5505 spec->capsws = stac92hd71bxx_capsws;
5506
Matthew Ranostay541eee82007-12-14 12:08:04 +01005507 switch (codec->vendor_id) {
5508 case 0x111d76b6: /* 4 Port without Analog Mixer */
5509 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005510 unmute_init++;
5511 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005512 case 0x111d76b4: /* 6 Port without Analog Mixer */
5513 case 0x111d76b5:
Matthew Ranostay541eee82007-12-14 12:08:04 +01005514 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005515 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005516 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5517 stac92hd71bxx_dmic_nids,
5518 STAC92HD71BXX_NUM_DMICS);
Matthew Ranostay541eee82007-12-14 12:08:04 +01005519 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005520 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005521 switch (spec->board_config) {
5522 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005523 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005524 err = stac_add_event(spec, codec->afg,
5525 STAC_VREF_EVENT, 0x02);
5526 if (err < 0)
5527 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005528 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005529 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5530 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005531 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005532 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005533 spec->gpio_mask |= 0x02;
5534 break;
5535 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005536 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005537 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005538 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005539
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005540 /* no output amps */
5541 spec->num_pwrs = 0;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005542 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005543 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005544 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005545 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5546 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005547 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5548 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5549 stac92hd71bxx_dmic_nids,
5550 STAC92HD71BXX_NUM_DMICS - 1);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005551 break;
5552 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005553 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005554 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005555
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005556 /* no output amps */
5557 spec->num_pwrs = 0;
5558 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005559 default:
Takashi Iwai26a27982009-07-29 16:28:09 +02005560 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005561 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005562 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5563 stac92hd71bxx_dmic_nids,
5564 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai5207e102009-07-30 13:09:08 +02005565 break;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005566 }
5567
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005568 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5569 snd_hda_sequence_write_cache(codec, unmute_init);
5570
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005571 /* Some HP machines seem to have unstable codec communications
5572 * especially with ATI fglrx driver. For recovering from the
5573 * CORB/RIRB stall, allow the BUS reset and keep always sync
5574 */
5575 if (spec->board_config == STAC_HP_DV5) {
5576 codec->bus->sync_write = 1;
5577 codec->bus->allow_bus_reset = 1;
5578 }
5579
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005580 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005581 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005582 spec->aloopback_shift = 0;
5583
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005584 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005585 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005586 spec->mux_nids = stac92hd71bxx_mux_nids;
5587 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005588 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005589 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005590
5591 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5592 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Takashi Iwai5207e102009-07-30 13:09:08 +02005593 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005594 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005595
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005596 switch (spec->board_config) {
5597 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005598 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005599 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005600 stac92xx_auto_set_pinctl(codec, 0x0e,
5601 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005602 /* fallthru */
5603 case STAC_DELL_M4_2:
5604 spec->num_dmics = 0;
5605 spec->num_smuxes = 0;
5606 spec->num_dmuxes = 0;
5607 break;
5608 case STAC_DELL_M4_1:
5609 case STAC_DELL_M4_3:
5610 spec->num_dmics = 1;
5611 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005612 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005613 break;
James Gardiner514bf542009-05-03 04:00:44 -04005614 case STAC_HP_DV4_1222NR:
5615 spec->num_dmics = 1;
5616 /* I don't know if it needs 1 or 2 smuxes - will wait for
5617 * bug reports to fix if needed
5618 */
5619 spec->num_smuxes = 1;
5620 spec->num_dmuxes = 1;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005621 spec->gpio_led = 0x01;
James Gardiner514bf542009-05-03 04:00:44 -04005622 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005623 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005624 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005625 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5626 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005627 case STAC_HP_HDX:
5628 spec->num_dmics = 1;
5629 spec->num_dmuxes = 1;
5630 spec->num_smuxes = 1;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005631 /* orange/white mute led on GPIO3, orange=0, white=1 */
Takashi Iwai86d190e2009-05-26 15:18:58 +02005632 spec->gpio_led = 0x08;
5633 break;
5634 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005635
Takashi Iwai86d190e2009-05-26 15:18:58 +02005636#ifdef CONFIG_SND_HDA_POWER_SAVE
5637 if (spec->gpio_led) {
5638 spec->gpio_mask |= spec->gpio_led;
5639 spec->gpio_dir |= spec->gpio_led;
5640 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005641 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005642 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005643 stac92xx_hp_check_power_status;
5644 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005645#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005646
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005647 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005648
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005649 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005650 if (!err) {
5651 if (spec->board_config < 0) {
5652 printk(KERN_WARNING "hda_codec: No auto-config is "
5653 "available, default to model=ref\n");
5654 spec->board_config = STAC_92HD71BXX_REF;
5655 goto again;
5656 }
5657 err = -EINVAL;
5658 }
5659
5660 if (err < 0) {
5661 stac92xx_free(codec);
5662 return err;
5663 }
5664
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005665 codec->proc_widget_hook = stac92hd7x_proc_hook;
5666
Matthew Ranostaye035b842007-11-06 11:53:55 +01005667 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005668}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005669
Matt2f2f4252005-04-13 14:45:30 +02005670static int patch_stac922x(struct hda_codec *codec)
5671{
5672 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005673 int err;
Matt2f2f4252005-04-13 14:45:30 +02005674
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005675 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005676 if (spec == NULL)
5677 return -ENOMEM;
5678
5679 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005680 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005681 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005682 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5683 stac922x_models,
5684 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005685 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005686 spec->gpio_mask = spec->gpio_dir = 0x03;
5687 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005688 /* Intel Macs have all same PCI SSID, so we need to check
5689 * codec SSID to distinguish the exact models
5690 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005691 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005692 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005693
5694 case 0x106b0800:
5695 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005696 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005697 case 0x106b0600:
5698 case 0x106b0700:
5699 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005700 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005701 case 0x106b0e00:
5702 case 0x106b0f00:
5703 case 0x106b1600:
5704 case 0x106b1700:
5705 case 0x106b0200:
5706 case 0x106b1e00:
5707 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005708 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005709 case 0x106b1a00:
5710 case 0x00000100:
5711 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005712 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005713 case 0x106b0a00:
5714 case 0x106b2200:
5715 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005716 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005717 default:
5718 spec->board_config = STAC_INTEL_MAC_V3;
5719 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005720 }
5721 }
5722
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005723 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005724 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005725 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5726 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005727 else
5728 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005729 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005730
Matt2f2f4252005-04-13 14:45:30 +02005731 spec->adc_nids = stac922x_adc_nids;
5732 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005733 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005734 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005735 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005736 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005737
5738 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005739
5740 spec->num_caps = STAC922X_NUM_CAPS;
5741 spec->capvols = stac922x_capvols;
5742 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005743
5744 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005745
Matt Porter3cc08dc2006-01-23 15:27:49 +01005746 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005747 if (!err) {
5748 if (spec->board_config < 0) {
5749 printk(KERN_WARNING "hda_codec: No auto-config is "
5750 "available, default to model=ref\n");
5751 spec->board_config = STAC_D945_REF;
5752 goto again;
5753 }
5754 err = -EINVAL;
5755 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005756 if (err < 0) {
5757 stac92xx_free(codec);
5758 return err;
5759 }
5760
5761 codec->patch_ops = stac92xx_patch_ops;
5762
Takashi Iwai807a46362007-05-29 19:01:37 +02005763 /* Fix Mux capture level; max to 2 */
5764 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5765 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5766 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5767 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5768 (0 << AC_AMPCAP_MUTE_SHIFT));
5769
Matt Porter3cc08dc2006-01-23 15:27:49 +01005770 return 0;
5771}
5772
5773static int patch_stac927x(struct hda_codec *codec)
5774{
5775 struct sigmatel_spec *spec;
5776 int err;
5777
5778 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5779 if (spec == NULL)
5780 return -ENOMEM;
5781
5782 codec->spec = spec;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005783 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005784 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005785 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005786 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5787 stac927x_models,
5788 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005789 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005790 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005791 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5792 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005793 else
5794 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005795 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005796
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005797 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005798 spec->adc_nids = stac927x_adc_nids;
5799 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5800 spec->mux_nids = stac927x_mux_nids;
5801 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005802 spec->smux_nids = stac927x_smux_nids;
5803 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005804 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005805 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005806 spec->multiout.dac_nids = spec->dac_nids;
5807
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005808 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005809 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005810 case STAC_D965_5ST:
5811 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005812 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005813 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005814 spec->num_dmics = 0;
5815
Tobin Davis93ed1502006-09-01 21:03:12 +02005816 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005817 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005818 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005819 switch (codec->subsystem_id) {
5820 case 0x10280209:
5821 case 0x1028022e:
5822 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005823 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005824 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005825 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005826 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005827 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005828 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005829 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005830 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005831 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005832 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005833 case STAC_DELL_3ST:
5834 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005835 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005836 spec->gpio_data = 0x04;
Chengu Wang84d3dc22009-07-30 19:43:55 +08005837 switch (codec->subsystem_id) {
5838 case 0x1028022f:
5839 /* correct EAPD to be GPIO0 */
5840 spec->eapd_mask = spec->gpio_mask = 0x01;
5841 spec->gpio_dir = spec->gpio_data = 0x01;
5842 break;
5843 };
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005844 spec->dmic_nids = stac927x_dmic_nids;
5845 spec->num_dmics = STAC927X_NUM_DMICS;
5846
Tobin Davis93ed1502006-09-01 21:03:12 +02005847 spec->init = d965_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005848 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005849 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005850 break;
5851 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005852 if (spec->board_config > STAC_D965_REF) {
5853 /* GPIO0 High = Enable EAPD */
5854 spec->eapd_mask = spec->gpio_mask = 0x01;
5855 spec->gpio_dir = spec->gpio_data = 0x01;
5856 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005857 spec->num_dmics = 0;
5858
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005859 spec->init = stac927x_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005860 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005861
Takashi Iwai6479c632009-07-28 18:20:25 +02005862 spec->num_caps = STAC927X_NUM_CAPS;
5863 spec->capvols = stac927x_capvols;
5864 spec->capsws = stac927x_capsws;
5865
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005866 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005867 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005868 spec->aloopback_mask = 0x40;
5869 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005870 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005871
Matt Porter3cc08dc2006-01-23 15:27:49 +01005872 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005873 if (!err) {
5874 if (spec->board_config < 0) {
5875 printk(KERN_WARNING "hda_codec: No auto-config is "
5876 "available, default to model=ref\n");
5877 spec->board_config = STAC_D965_REF;
5878 goto again;
5879 }
5880 err = -EINVAL;
5881 }
Mattc7d4b2f2005-06-27 14:59:41 +02005882 if (err < 0) {
5883 stac92xx_free(codec);
5884 return err;
5885 }
Matt2f2f4252005-04-13 14:45:30 +02005886
5887 codec->patch_ops = stac92xx_patch_ops;
5888
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005889 codec->proc_widget_hook = stac927x_proc_hook;
5890
Takashi Iwai52987652008-01-16 16:09:47 +01005891 /*
5892 * !!FIXME!!
5893 * The STAC927x seem to require fairly long delays for certain
5894 * command sequences. With too short delays (even if the answer
5895 * is set to RIRB properly), it results in the silence output
5896 * on some hardwares like Dell.
5897 *
5898 * The below flag enables the longer delay (see get_response
5899 * in hda_intel.c).
5900 */
5901 codec->bus->needs_damn_long_delay = 1;
5902
Takashi Iwaie28d8322008-12-17 13:48:29 +01005903 /* no jack detecion for ref-no-jd model */
5904 if (spec->board_config == STAC_D965_REF_NO_JD)
5905 spec->hp_detect = 0;
5906
Matt2f2f4252005-04-13 14:45:30 +02005907 return 0;
5908}
5909
Matt Porterf3302a52006-07-31 12:49:34 +02005910static int patch_stac9205(struct hda_codec *codec)
5911{
5912 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005913 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005914
5915 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5916 if (spec == NULL)
5917 return -ENOMEM;
5918
5919 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005920 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005921 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005922 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5923 stac9205_models,
5924 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005925 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005926 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005927 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5928 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005929 else
5930 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005931 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02005932
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005933 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005934 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005935 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005936 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005937 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005938 spec->smux_nids = stac9205_smux_nids;
5939 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005940 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005941 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005942 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005943 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005944 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005945
5946 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005947 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02005948
Takashi Iwai6479c632009-07-28 18:20:25 +02005949 spec->num_caps = STAC9205_NUM_CAPS;
5950 spec->capvols = stac9205_capvols;
5951 spec->capsws = stac9205_capsws;
5952
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005953 spec->aloopback_mask = 0x40;
5954 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01005955 /* Turn on/off EAPD per HP plugging */
5956 if (spec->board_config != STAC_9205_EAPD)
5957 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005958 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005959
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005960 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005961 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005962 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005963 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5964 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005965
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005966 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005967 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5968 if (err < 0)
5969 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005970 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005971 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5972 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005973 AC_VERB_SET_UNSOLICITED_ENABLE,
5974 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005975
5976 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005977 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005978 spec->gpio_mask = 0x1b;
5979 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005980 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005981 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005982 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005983 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005984 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005985 case STAC_9205_REF:
5986 /* SPDIF-In enabled */
5987 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005988 default:
5989 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005990 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005991 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005992 break;
5993 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005994
Matt Porterf3302a52006-07-31 12:49:34 +02005995 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005996 if (!err) {
5997 if (spec->board_config < 0) {
5998 printk(KERN_WARNING "hda_codec: No auto-config is "
5999 "available, default to model=ref\n");
6000 spec->board_config = STAC_9205_REF;
6001 goto again;
6002 }
6003 err = -EINVAL;
6004 }
Matt Porterf3302a52006-07-31 12:49:34 +02006005 if (err < 0) {
6006 stac92xx_free(codec);
6007 return err;
6008 }
6009
6010 codec->patch_ops = stac92xx_patch_ops;
6011
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01006012 codec->proc_widget_hook = stac9205_proc_hook;
6013
Matt Porterf3302a52006-07-31 12:49:34 +02006014 return 0;
6015}
6016
Matt2f2f4252005-04-13 14:45:30 +02006017/*
Guillaume Munch6d859062006-08-22 17:15:47 +02006018 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01006019 */
6020
Takashi Iwai1e137f92009-01-21 07:41:22 +01006021static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02006022 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01006023 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
6024 {}
6025};
6026
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006027static hda_nid_t stac9872_pin_nids[] = {
6028 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6029 0x11, 0x13, 0x14,
6030};
6031
6032static hda_nid_t stac9872_adc_nids[] = {
6033 0x8 /*,0x6*/
6034};
6035
6036static hda_nid_t stac9872_mux_nids[] = {
6037 0x15
6038};
6039
Takashi Iwai6479c632009-07-28 18:20:25 +02006040static unsigned long stac9872_capvols[] = {
6041 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6042};
6043#define stac9872_capsws stac9872_capvols
6044
Takashi Iwai307282c2009-03-12 18:17:58 +01006045static unsigned int stac9872_vaio_pin_configs[9] = {
6046 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6047 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6048 0x90a7013e
6049};
6050
6051static const char *stac9872_models[STAC_9872_MODELS] = {
6052 [STAC_9872_AUTO] = "auto",
6053 [STAC_9872_VAIO] = "vaio",
6054};
6055
6056static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6057 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6058};
6059
6060static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006061 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6062 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006063 {} /* terminator */
6064};
6065
Guillaume Munch6d859062006-08-22 17:15:47 +02006066static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006067{
6068 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006069 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006070
Takashi Iwaidb064e52006-03-16 16:04:58 +01006071 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6072 if (spec == NULL)
6073 return -ENOMEM;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006074 codec->spec = spec;
Takashi Iwaib04add92009-07-20 08:01:36 +02006075 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6076 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006077
6078 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6079 stac9872_models,
6080 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006081 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006082 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6083 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006084 else
6085 stac92xx_set_config_regs(codec,
6086 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006087
Takashi Iwai1e137f92009-01-21 07:41:22 +01006088 spec->multiout.dac_nids = spec->dac_nids;
6089 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6090 spec->adc_nids = stac9872_adc_nids;
6091 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6092 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006093 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006094 spec->num_caps = 1;
6095 spec->capvols = stac9872_capvols;
6096 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006097
Takashi Iwai1e137f92009-01-21 07:41:22 +01006098 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6099 if (err < 0) {
6100 stac92xx_free(codec);
6101 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006102 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006103 spec->input_mux = &spec->private_imux;
6104 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006105 return 0;
6106}
6107
6108
6109/*
Matt2f2f4252005-04-13 14:45:30 +02006110 * patch entries
6111 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006112static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006113 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6114 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6115 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6116 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6117 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6118 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6119 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006120 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6121 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6122 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6123 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6124 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6125 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006126 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6127 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6128 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6129 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6130 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6131 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6132 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6133 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6134 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6135 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006136 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6137 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6138 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6139 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6140 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6141 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006142 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6143 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006144 /* The following does not take into account .id=0x83847661 when subsys =
6145 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6146 * currently not fully supported.
6147 */
6148 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6149 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6150 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006151 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006152 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6153 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6154 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6155 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6156 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6157 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6158 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6159 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006160 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006161 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
6162 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006163 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006164 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006165 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6166 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006167 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006168 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6169 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6170 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6171 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6172 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6173 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6174 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6175 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02006176 {} /* terminator */
6177};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006178
6179MODULE_ALIAS("snd-hda-codec-id:8384*");
6180MODULE_ALIAS("snd-hda-codec-id:111d*");
6181
6182MODULE_LICENSE("GPL");
6183MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6184
6185static struct hda_codec_preset_list sigmatel_list = {
6186 .preset = snd_hda_preset_sigmatel,
6187 .owner = THIS_MODULE,
6188};
6189
6190static int __init patch_sigmatel_init(void)
6191{
6192 return snd_hda_add_codec_preset(&sigmatel_list);
6193}
6194
6195static void __exit patch_sigmatel_exit(void)
6196{
6197 snd_hda_delete_codec_preset(&sigmatel_list);
6198}
6199
6200module_init(patch_sigmatel_init)
6201module_exit(patch_sigmatel_exit)