blob: abc44dbe0ab93fa0b4cfaa8a185d7fb81b52ebab [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 Iwai3d21d3f2009-07-29 14:32:56 +020043 STAC_MIC_EVENT,
Takashi Iwaic6e4c662008-11-25 11:58:19 +010044};
Matt4e550962005-07-04 17:51:39 +020045
Takashi Iwaif5fcc132006-11-24 17:07:44 +010046enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010047 STAC_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010048 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010049 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020050 STAC_9200_DELL_D21,
51 STAC_9200_DELL_D22,
52 STAC_9200_DELL_D23,
53 STAC_9200_DELL_M21,
54 STAC_9200_DELL_M22,
55 STAC_9200_DELL_M23,
56 STAC_9200_DELL_M24,
57 STAC_9200_DELL_M25,
58 STAC_9200_DELL_M26,
59 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020060 STAC_9200_M4,
61 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010062 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010063 STAC_9200_MODELS
64};
65
66enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010067 STAC_9205_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010068 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020069 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020070 STAC_9205_DELL_M43,
71 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010072 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010073 STAC_9205_MODELS
74};
75
76enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010077 STAC_92HD73XX_AUTO,
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010078 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010079 STAC_92HD73XX_REF,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010080 STAC_DELL_M6_AMIC,
81 STAC_DELL_M6_DMIC,
82 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050083 STAC_DELL_EQ,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010084 STAC_92HD73XX_MODELS
85};
86
87enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010088 STAC_92HD83XXX_AUTO,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020089 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050090 STAC_92HD83XXX_PWR_REF,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -050091 STAC_DELL_S14,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020092 STAC_92HD83XXX_MODELS
93};
94
95enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +010096 STAC_92HD71BXX_AUTO,
Matthew Ranostaye035b842007-11-06 11:53:55 +010097 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010098 STAC_DELL_M4_1,
99 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -0500100 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -0400101 STAC_HP_M4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +0100102 STAC_HP_DV5,
Christoph Plattnerae6241f2009-03-08 23:19:05 +0100103 STAC_HP_HDX,
James Gardiner514bf542009-05-03 04:00:44 -0400104 STAC_HP_DV4_1222NR,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100105 STAC_92HD71BXX_MODELS
106};
107
108enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100109 STAC_925x_AUTO,
Tobin Davis8e21c342007-01-08 11:04:17 +0100110 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200111 STAC_M1,
112 STAC_M1_2,
113 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100114 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200115 STAC_M3,
116 STAC_M5,
117 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100118 STAC_925x_MODELS
119};
120
121enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100122 STAC_922X_AUTO,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100123 STAC_D945_REF,
124 STAC_D945GTP3,
125 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200126 STAC_INTEL_MAC_V1,
127 STAC_INTEL_MAC_V2,
128 STAC_INTEL_MAC_V3,
129 STAC_INTEL_MAC_V4,
130 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800131 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
132 * is given, one of the above models will be
133 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200134 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100135 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100136 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100137 STAC_MACBOOK_PRO_V1,
138 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200139 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200140 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300141 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200142 STAC_922X_DELL_D81,
143 STAC_922X_DELL_D82,
144 STAC_922X_DELL_M81,
145 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100146 STAC_922X_MODELS
147};
148
149enum {
Takashi Iwai1607b8e2009-02-26 16:50:43 +0100150 STAC_927X_AUTO,
Takashi Iwaie28d8322008-12-17 13:48:29 +0100151 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100152 STAC_D965_REF,
153 STAC_D965_3ST,
154 STAC_D965_5ST,
Takashi Iwai679d92e2009-05-24 19:00:08 +0200155 STAC_D965_5ST_NO_FP,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200156 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100157 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100158 STAC_927X_MODELS
159};
Matt Porter403d1942005-11-29 15:00:51 +0100160
Takashi Iwai307282c2009-03-12 18:17:58 +0100161enum {
162 STAC_9872_AUTO,
163 STAC_9872_VAIO,
164 STAC_9872_MODELS
165};
166
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400167struct sigmatel_event {
168 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100169 unsigned char type;
170 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400171 int data;
172};
173
174struct sigmatel_jack {
175 hda_nid_t nid;
176 int type;
177 struct snd_jack *jack;
178};
179
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200180struct sigmatel_mic_route {
181 hda_nid_t pin;
182 unsigned char mux_idx;
183 unsigned char dmux_idx;
184};
185
Matt2f2f4252005-04-13 14:45:30 +0200186struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100187 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200188 unsigned int num_mixers;
189
Matt Porter403d1942005-11-29 15:00:51 +0100190 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500191 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200192 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100193 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100194 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400195 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100196 unsigned int check_volume_offset:1;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200197 unsigned int auto_mic:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200198
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100199 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200200 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100201 unsigned int gpio_mask;
202 unsigned int gpio_dir;
203 unsigned int gpio_data;
204 unsigned int gpio_mute;
Takashi Iwai86d190e2009-05-26 15:18:58 +0200205 unsigned int gpio_led;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100206
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200207 /* stream */
208 unsigned int stream_delay;
209
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100210 /* analog loopback */
Takashi Iwaid78d7a92009-03-02 14:26:25 +0100211 struct snd_kcontrol_new *aloopback_ctl;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100212 unsigned char aloopback_mask;
213 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200214
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100215 /* power management */
216 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200217 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100218 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100219 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100220
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400221 /* jack detection */
222 struct snd_array jacks;
223
224 /* events */
225 struct snd_array events;
226
Matt2f2f4252005-04-13 14:45:30 +0200227 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100228 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400229 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100230 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200231 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100232 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100233 hda_nid_t hp_dacs[5];
234 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200235
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100236 int volume_offset;
237
Matt2f2f4252005-04-13 14:45:30 +0200238 /* capture */
239 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200240 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200241 hda_nid_t *mux_nids;
242 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200243 hda_nid_t *dmic_nids;
244 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100245 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100246 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200247 hda_nid_t *smux_nids;
248 unsigned int num_smuxes;
Takashi Iwai6479c632009-07-28 18:20:25 +0200249
250 unsigned long *capvols; /* amp-volume attr: HDA_COMPOSE_AMP_VAL() */
251 unsigned long *capsws; /* amp-mute attr: HDA_COMPOSE_AMP_VAL() */
252 unsigned int num_caps; /* number of capture volume/switch elements */
253
Takashi Iwai3d21d3f2009-07-29 14:32:56 +0200254 struct sigmatel_mic_route ext_mic;
255 struct sigmatel_mic_route int_mic;
256
Matthew Ranostay65973632008-09-16 10:39:37 -0400257 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200258
Mattdabbed62005-06-14 10:19:34 +0200259 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100260 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200261 hda_nid_t anabeep_nid;
262 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200263
Matt2f2f4252005-04-13 14:45:30 +0200264 /* pin widgets */
265 hda_nid_t *pin_nids;
266 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200267
268 /* codec specific stuff */
269 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100270 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200271
272 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200273 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100274 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200275 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100276 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200277 struct hda_input_mux *sinput_mux;
278 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400279 unsigned int cur_amux;
280 hda_nid_t *amp_nids;
281 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200282 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200283
Matt Porter403d1942005-11-29 15:00:51 +0100284 /* i/o switches */
285 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200286 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100287 hda_nid_t line_switch; /* shared line-in for input and output */
288 hda_nid_t mic_switch; /* shared mic-in for input and output */
289 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200290 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200291
Mattc7d4b2f2005-06-27 14:59:41 +0200292 struct hda_pcm pcm_rec[2]; /* PCM information */
293
294 /* dynamic controls and input_mux */
295 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200296 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200297 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200298 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200299 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400300 struct hda_input_mux private_amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100301 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200302};
303
304static hda_nid_t stac9200_adc_nids[1] = {
305 0x03,
306};
307
308static hda_nid_t stac9200_mux_nids[1] = {
309 0x0c,
310};
311
312static hda_nid_t stac9200_dac_nids[1] = {
313 0x02,
314};
315
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100316static hda_nid_t stac92hd73xx_pwr_nids[8] = {
317 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
318 0x0f, 0x10, 0x11
319};
320
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400321static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
322 0x26, 0,
323};
324
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100325static hda_nid_t stac92hd73xx_adc_nids[2] = {
326 0x1a, 0x1b
327};
328
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400329#define DELL_M6_AMP 2
330static hda_nid_t stac92hd73xx_amp_nids[3] = {
331 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400332};
333
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100334#define STAC92HD73XX_NUM_DMICS 2
335static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
336 0x13, 0x14, 0
337};
338
339#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100340
341static hda_nid_t stac92hd73xx_mux_nids[4] = {
342 0x28, 0x29, 0x2a, 0x2b,
343};
344
345static hda_nid_t stac92hd73xx_dmux_nids[2] = {
346 0x20, 0x21,
347};
348
Matthew Ranostayd9737752008-09-07 12:03:41 +0200349static hda_nid_t stac92hd73xx_smux_nids[2] = {
350 0x22, 0x23,
351};
352
Takashi Iwai6479c632009-07-28 18:20:25 +0200353#define STAC92HD73XX_NUM_CAPS 2
354static unsigned long stac92hd73xx_capvols[] = {
355 HDA_COMPOSE_AMP_VAL(0x20, 3, 0, HDA_OUTPUT),
356 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
357};
358#define stac92hd73xx_capsws stac92hd73xx_capvols
359
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200360#define STAC92HD83XXX_NUM_DMICS 2
361static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
362 0x11, 0x12, 0
363};
364
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200365#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200366
367static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
368 0x17, 0x18,
369};
370
371static hda_nid_t stac92hd83xxx_adc_nids[2] = {
372 0x15, 0x16,
373};
374
375static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
376 0xa, 0xb, 0xd, 0xe,
377};
378
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400379static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
380 0x1e, 0,
381};
382
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200383static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500384 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200385};
386
Takashi Iwai9248f262009-01-14 09:40:25 +0100387static hda_nid_t stac92hd83xxx_amp_nids[1] = {
Matthew Ranostayc15c5062009-01-13 13:30:07 -0500388 0xc,
389};
390
Takashi Iwai6479c632009-07-28 18:20:25 +0200391#define STAC92HD83XXX_NUM_CAPS 2
392static unsigned long stac92hd83xxx_capvols[] = {
393 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
394 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_OUTPUT),
395};
396#define stac92hd83xxx_capsws stac92hd83xxx_capvols
397
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100398static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
399 0x0a, 0x0d, 0x0f
400};
401
Matthew Ranostaye035b842007-11-06 11:53:55 +0100402static hda_nid_t stac92hd71bxx_adc_nids[2] = {
403 0x12, 0x13,
404};
405
406static hda_nid_t stac92hd71bxx_mux_nids[2] = {
407 0x1a, 0x1b
408};
409
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400410static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
411 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100412};
413
Matthew Ranostayd9737752008-09-07 12:03:41 +0200414static hda_nid_t stac92hd71bxx_smux_nids[2] = {
415 0x24, 0x25,
416};
417
Matthew Ranostaye035b842007-11-06 11:53:55 +0100418#define STAC92HD71BXX_NUM_DMICS 2
419static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
420 0x18, 0x19, 0
421};
422
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400423static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
424 0x22, 0
425};
426
Takashi Iwai6479c632009-07-28 18:20:25 +0200427#define STAC92HD71BXX_NUM_CAPS 2
428static unsigned long stac92hd71bxx_capvols[] = {
429 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
430 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
431};
432#define stac92hd71bxx_capsws stac92hd71bxx_capvols
433
Tobin Davis8e21c342007-01-08 11:04:17 +0100434static hda_nid_t stac925x_adc_nids[1] = {
435 0x03,
436};
437
438static hda_nid_t stac925x_mux_nids[1] = {
439 0x0f,
440};
441
442static hda_nid_t stac925x_dac_nids[1] = {
443 0x02,
444};
445
Takashi Iwaif6e98522007-10-16 14:27:04 +0200446#define STAC925X_NUM_DMICS 1
447static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
448 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200449};
450
Takashi Iwai1697055e2007-12-18 18:05:52 +0100451static hda_nid_t stac925x_dmux_nids[1] = {
452 0x14,
453};
454
Takashi Iwai6479c632009-07-28 18:20:25 +0200455static unsigned long stac925x_capvols[] = {
456 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
457};
458static unsigned long stac925x_capsws[] = {
459 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
460};
461
Matt2f2f4252005-04-13 14:45:30 +0200462static hda_nid_t stac922x_adc_nids[2] = {
463 0x06, 0x07,
464};
465
466static hda_nid_t stac922x_mux_nids[2] = {
467 0x12, 0x13,
468};
469
Takashi Iwai6479c632009-07-28 18:20:25 +0200470#define STAC922X_NUM_CAPS 2
471static unsigned long stac922x_capvols[] = {
472 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_INPUT),
473 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
474};
475#define stac922x_capsws stac922x_capvols
476
Matthew Ranostay45c1d852009-02-04 17:49:41 -0500477static hda_nid_t stac927x_slave_dig_outs[2] = {
478 0x1f, 0,
479};
480
Matt Porter3cc08dc2006-01-23 15:27:49 +0100481static hda_nid_t stac927x_adc_nids[3] = {
482 0x07, 0x08, 0x09
483};
484
485static hda_nid_t stac927x_mux_nids[3] = {
486 0x15, 0x16, 0x17
487};
488
Matthew Ranostayd9737752008-09-07 12:03:41 +0200489static hda_nid_t stac927x_smux_nids[1] = {
490 0x21,
491};
492
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100493static hda_nid_t stac927x_dac_nids[6] = {
494 0x02, 0x03, 0x04, 0x05, 0x06, 0
495};
496
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100497static hda_nid_t stac927x_dmux_nids[1] = {
498 0x1b,
499};
500
Matthew Ranostay7f168592007-10-18 17:38:17 +0200501#define STAC927X_NUM_DMICS 2
502static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
503 0x13, 0x14, 0
504};
505
Takashi Iwai6479c632009-07-28 18:20:25 +0200506#define STAC927X_NUM_CAPS 3
507static unsigned long stac927x_capvols[] = {
508 HDA_COMPOSE_AMP_VAL(0x18, 3, 0, HDA_INPUT),
509 HDA_COMPOSE_AMP_VAL(0x19, 3, 0, HDA_INPUT),
510 HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_INPUT),
511};
512static unsigned long stac927x_capsws[] = {
513 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
514 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_OUTPUT),
515 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
516};
517
Matthew Ranostay65973632008-09-16 10:39:37 -0400518static const char *stac927x_spdif_labels[5] = {
519 "Digital Playback", "ADAT", "Analog Mux 1",
520 "Analog Mux 2", "Analog Mux 3"
521};
522
Matt Porterf3302a52006-07-31 12:49:34 +0200523static hda_nid_t stac9205_adc_nids[2] = {
524 0x12, 0x13
525};
526
527static hda_nid_t stac9205_mux_nids[2] = {
528 0x19, 0x1a
529};
530
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100531static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100532 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100533};
534
Matthew Ranostayd9737752008-09-07 12:03:41 +0200535static hda_nid_t stac9205_smux_nids[1] = {
536 0x21,
537};
538
Takashi Iwaif6e98522007-10-16 14:27:04 +0200539#define STAC9205_NUM_DMICS 2
540static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
541 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200542};
543
Takashi Iwai6479c632009-07-28 18:20:25 +0200544#define STAC9205_NUM_CAPS 2
545static unsigned long stac9205_capvols[] = {
546 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_INPUT),
547 HDA_COMPOSE_AMP_VAL(0x1c, 3, 0, HDA_INPUT),
548};
549static unsigned long stac9205_capsws[] = {
550 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
551 HDA_COMPOSE_AMP_VAL(0x1e, 3, 0, HDA_OUTPUT),
552};
553
Mattc7d4b2f2005-06-27 14:59:41 +0200554static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200555 0x08, 0x09, 0x0d, 0x0e,
556 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200557};
558
Tobin Davis8e21c342007-01-08 11:04:17 +0100559static hda_nid_t stac925x_pin_nids[8] = {
560 0x07, 0x08, 0x0a, 0x0b,
561 0x0c, 0x0d, 0x10, 0x11,
562};
563
Matt2f2f4252005-04-13 14:45:30 +0200564static hda_nid_t stac922x_pin_nids[10] = {
565 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
566 0x0f, 0x10, 0x11, 0x15, 0x1b,
567};
568
Matthew Ranostaya7662642008-02-21 07:51:14 +0100569static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100570 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
571 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200572 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100573};
574
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500575static hda_nid_t stac92hd83xxx_pin_nids[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200576 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500577 0x0f, 0x10, 0x11, 0x1f, 0x20,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200578};
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500579
580#define STAC92HD71BXX_NUM_PINS 13
581static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
582 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
583 0x00, 0x14, 0x18, 0x19, 0x1e,
584 0x1f, 0x20, 0x27
585};
586static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100587 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
588 0x0f, 0x14, 0x18, 0x19, 0x1e,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -0500589 0x1f, 0x20, 0x27
Matthew Ranostaye035b842007-11-06 11:53:55 +0100590};
591
Matt Porter3cc08dc2006-01-23 15:27:49 +0100592static hda_nid_t stac927x_pin_nids[14] = {
593 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
594 0x0f, 0x10, 0x11, 0x12, 0x13,
595 0x14, 0x21, 0x22, 0x23,
596};
597
Matt Porterf3302a52006-07-31 12:49:34 +0200598static hda_nid_t stac9205_pin_nids[12] = {
599 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
600 0x0f, 0x14, 0x16, 0x17, 0x18,
601 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200602};
603
Matthew Ranostay89385032008-09-11 09:49:39 -0400604#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
605
606static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
607 struct snd_ctl_elem_value *ucontrol)
608{
609 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
610 struct sigmatel_spec *spec = codec->spec;
611 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
612
613 kcontrol->private_value ^= get_amp_nid(kcontrol);
614 kcontrol->private_value |= nid;
615
616 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
617}
618
619static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
620 struct snd_ctl_elem_value *ucontrol)
621{
622 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
623 struct sigmatel_spec *spec = codec->spec;
624 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
625
626 kcontrol->private_value ^= get_amp_nid(kcontrol);
627 kcontrol->private_value |= nid;
628
629 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
630}
631
Matt Porter8b657272006-10-26 17:12:59 +0200632static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
633 struct snd_ctl_elem_info *uinfo)
634{
635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
636 struct sigmatel_spec *spec = codec->spec;
637 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
638}
639
640static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
641 struct snd_ctl_elem_value *ucontrol)
642{
643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
644 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100645 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200646
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100647 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200648 return 0;
649}
650
651static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
652 struct snd_ctl_elem_value *ucontrol)
653{
654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
655 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100656 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200657
658 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100659 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200660}
661
Matthew Ranostayd9737752008-09-07 12:03:41 +0200662static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
663 struct snd_ctl_elem_info *uinfo)
664{
665 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
666 struct sigmatel_spec *spec = codec->spec;
667 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
668}
669
670static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
671 struct snd_ctl_elem_value *ucontrol)
672{
673 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
674 struct sigmatel_spec *spec = codec->spec;
675 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
676
677 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
678 return 0;
679}
680
681static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
682 struct snd_ctl_elem_value *ucontrol)
683{
684 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
685 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400686 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200687 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400688 int err, val;
689 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200690
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400691 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200692 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400693 if (err < 0)
694 return err;
695
696 if (spec->spdif_mute) {
697 if (smux_idx == 0)
698 nid = spec->multiout.dig_out_nid;
699 else
700 nid = codec->slave_dig_outs[smux_idx - 1];
701 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100702 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400703 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100704 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400705 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100706 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
707 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400708 }
709 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200710}
711
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200712static unsigned int stac92xx_vref_set(struct hda_codec *codec,
713 hda_nid_t nid, unsigned int new_vref)
714{
Takashi Iwaib8621512009-06-22 08:00:10 +0200715 int error;
Nickolas Lloyd2fc99892009-05-15 15:33:30 +0200716 unsigned int pincfg;
717 pincfg = snd_hda_codec_read(codec, nid, 0,
718 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
719
720 pincfg &= 0xff;
721 pincfg &= ~(AC_PINCTL_VREFEN | AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
722 pincfg |= new_vref;
723
724 if (new_vref == AC_PINCTL_VREF_HIZ)
725 pincfg |= AC_PINCTL_OUT_EN;
726 else
727 pincfg |= AC_PINCTL_IN_EN;
728
729 error = snd_hda_codec_write_cache(codec, nid, 0,
730 AC_VERB_SET_PIN_WIDGET_CONTROL, pincfg);
731 if (error < 0)
732 return error;
733 else
734 return 1;
735}
736
737static unsigned int stac92xx_vref_get(struct hda_codec *codec, hda_nid_t nid)
738{
739 unsigned int vref;
740 vref = snd_hda_codec_read(codec, nid, 0,
741 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
742 vref &= AC_PINCTL_VREFEN;
743 return vref;
744}
745
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100746static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200747{
748 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
749 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200750 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200751}
752
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100753static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200754{
755 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
756 struct sigmatel_spec *spec = codec->spec;
757 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
758
759 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
760 return 0;
761}
762
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100763static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200764{
765 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
766 struct sigmatel_spec *spec = codec->spec;
767 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
768
Mattc7d4b2f2005-06-27 14:59:41 +0200769 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200770 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
771}
772
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100773static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
774 struct snd_ctl_elem_info *uinfo)
775{
776 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
777 struct sigmatel_spec *spec = codec->spec;
778 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
779}
780
781static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
782 struct snd_ctl_elem_value *ucontrol)
783{
784 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
785 struct sigmatel_spec *spec = codec->spec;
786
787 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
788 return 0;
789}
790
791static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
792 struct snd_ctl_elem_value *ucontrol)
793{
794 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
795 struct sigmatel_spec *spec = codec->spec;
796
797 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
798 spec->mono_nid, &spec->cur_mmux);
799}
800
Matthew Ranostay89385032008-09-11 09:49:39 -0400801static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
802 struct snd_ctl_elem_info *uinfo)
803{
804 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
805 struct sigmatel_spec *spec = codec->spec;
806 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
807}
808
809static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
810 struct snd_ctl_elem_value *ucontrol)
811{
812 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
813 struct sigmatel_spec *spec = codec->spec;
814
815 ucontrol->value.enumerated.item[0] = spec->cur_amux;
816 return 0;
817}
818
819static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
820 struct snd_ctl_elem_value *ucontrol)
821{
822 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
823 struct sigmatel_spec *spec = codec->spec;
824 struct snd_kcontrol *ctl =
825 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
826 if (!ctl)
827 return -EINVAL;
828
829 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
830 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
831
832 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
833 0, &spec->cur_amux);
834}
835
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200836#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
837
838static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
839 struct snd_ctl_elem_value *ucontrol)
840{
841 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100842 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200843 struct sigmatel_spec *spec = codec->spec;
844
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100845 ucontrol->value.integer.value[0] = !!(spec->aloopback &
846 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200847 return 0;
848}
849
850static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
851 struct snd_ctl_elem_value *ucontrol)
852{
853 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
854 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100855 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200856 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100857 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200858
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100859 idx_val = spec->aloopback_mask << idx;
860 if (ucontrol->value.integer.value[0])
861 val = spec->aloopback | idx_val;
862 else
863 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100864 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200865 return 0;
866
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100867 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200868
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100869 /* Only return the bits defined by the shift value of the
870 * first two bytes of the mask
871 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200872 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100873 kcontrol->private_value & 0xFFFF, 0x0);
874 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200875
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100876 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200877 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100878 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200879 } else {
880 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100881 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200882 }
883
884 snd_hda_codec_write_cache(codec, codec->afg, 0,
885 kcontrol->private_value >> 16, dac_mode);
886
887 return 1;
888}
889
Mattc7d4b2f2005-06-27 14:59:41 +0200890static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200891 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200892 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200893 {}
894};
895
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200896static struct hda_verb stac9200_eapd_init[] = {
897 /* set dac0mux for dac converter */
898 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
899 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
900 {}
901};
902
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100903static struct hda_verb stac92hd73xx_6ch_core_init[] = {
904 /* set master volume and direct control */
905 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100906 /* setup adcs to point to mixer */
907 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
908 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100909 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
910 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
911 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
912 /* setup import muxs */
913 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
914 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
915 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
916 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
917 {}
918};
919
Matthew Ranostayd654a662008-03-14 08:46:51 +0100920static struct hda_verb dell_eq_core_init[] = {
921 /* set master volume to max value without distortion
922 * and direct control */
923 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100924 /* setup adcs to point to mixer */
925 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
926 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
927 /* setup import muxs */
928 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
929 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
930 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
931 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
932 {}
933};
934
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100935static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500936 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100937 /* setup adcs to point to mixer */
938 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
939 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
940 /* setup import muxs */
941 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
942 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
943 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
944 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
945 {}
946};
947
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100948static struct hda_verb stac92hd73xx_8ch_core_init[] = {
949 /* set master volume and direct control */
950 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100951 /* setup adcs to point to mixer */
952 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
953 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100954 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
955 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
956 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
957 /* setup import muxs */
958 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
959 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
960 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
961 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
962 {}
963};
964
965static struct hda_verb stac92hd73xx_10ch_core_init[] = {
966 /* set master volume and direct control */
967 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100968 /* dac3 is connected to import3 mux */
969 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100970 /* setup adcs to point to mixer */
971 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
972 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100973 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
974 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
975 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
976 /* setup import muxs */
977 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
978 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
979 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
980 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
981 {}
982};
983
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200984static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -0500985 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
986 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
987 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200988
989 /* power state controls amps */
990 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200991 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200992};
993
Matthew Ranostaye035b842007-11-06 11:53:55 +0100994static struct hda_verb stac92hd71bxx_core_init[] = {
995 /* set master volume and direct control */
996 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200997 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100998};
999
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05001000static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
1001 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
1002 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +01001003 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1004 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +01001005 {}
1006};
1007
Tobin Davis8e21c342007-01-08 11:04:17 +01001008static struct hda_verb stac925x_core_init[] = {
1009 /* set dac0mux for dac converter */
1010 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +01001011 /* mute the master volume */
1012 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +01001013 {}
1014};
1015
Mattc7d4b2f2005-06-27 14:59:41 +02001016static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +02001017 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +02001018 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +02001019 {}
1020};
1021
Tobin Davis93ed1502006-09-01 21:03:12 +02001022static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +02001023 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +02001024 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +02001025 /* unmute node 0x1b */
1026 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1027 /* select node 0x03 as DAC */
1028 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
1029 {}
1030};
1031
Matt Porter3cc08dc2006-01-23 15:27:49 +01001032static struct hda_verb stac927x_core_init[] = {
1033 /* set master volume and direct control */
1034 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001035 /* enable analog pc beep path */
1036 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +01001037 {}
1038};
1039
Matt Porterf3302a52006-07-31 12:49:34 +02001040static struct hda_verb stac9205_core_init[] = {
1041 /* set master volume and direct control */
1042 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001043 /* enable analog pc beep path */
1044 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +02001045 {}
1046};
1047
Matthew Ranostayb22b4822008-01-22 12:32:30 +01001048#define STAC_MONO_MUX \
1049 { \
1050 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1051 .name = "Mono Mux", \
1052 .count = 1, \
1053 .info = stac92xx_mono_mux_enum_info, \
1054 .get = stac92xx_mono_mux_enum_get, \
1055 .put = stac92xx_mono_mux_enum_put, \
1056 }
1057
Matthew Ranostay89385032008-09-11 09:49:39 -04001058#define STAC_AMP_MUX \
1059 { \
1060 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1061 .name = "Amp Selector Capture Switch", \
1062 .count = 1, \
1063 .info = stac92xx_amp_mux_enum_info, \
1064 .get = stac92xx_amp_mux_enum_get, \
1065 .put = stac92xx_amp_mux_enum_put, \
1066 }
1067
1068#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
1069 { \
1070 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1071 .name = xname, \
1072 .index = 0, \
1073 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1074 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1075 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
1076 .info = stac92xx_amp_volume_info, \
1077 .get = stac92xx_amp_volume_get, \
1078 .put = stac92xx_amp_volume_put, \
1079 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
1080 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
1081 }
1082
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001083#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +02001084 { \
1085 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1086 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001087 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +02001088 .info = stac92xx_aloopback_info, \
1089 .get = stac92xx_aloopback_get, \
1090 .put = stac92xx_aloopback_put, \
1091 .private_value = verb_read | (verb_write << 16), \
1092 }
1093
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02001094#define DC_BIAS(xname, idx, nid) \
1095 { \
1096 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1097 .name = xname, \
1098 .index = idx, \
1099 .info = stac92xx_dc_bias_info, \
1100 .get = stac92xx_dc_bias_get, \
1101 .put = stac92xx_dc_bias_put, \
1102 .private_value = nid, \
1103 }
1104
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001105static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +02001106 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1107 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001108 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1109 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001110 { } /* end */
1111};
1112
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001113#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001114static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001115 /* start of config #1 */
1116 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1117 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1118
1119 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1120 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1121
1122 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1123 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1124
1125 /* start of config #2 */
1126 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1127 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1128
1129 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1130 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1131
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001132 { } /* end */
1133};
1134
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001135static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1136 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1137 {}
1138};
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001139
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001140static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1141 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1142 {}
1143};
1144
1145static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1146 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1147 {}
1148};
1149
1150static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001151 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1152 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1153
1154 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1155 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1156
1157 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1158 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1159
1160 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1161 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1162
1163 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1164 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1165 { } /* end */
1166};
1167
1168static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001169 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1170 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1171
1172 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1173 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1174
1175 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1176 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1177
1178 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1179 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1180
1181 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1182 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1183 { } /* end */
1184};
1185
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001186
1187static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001188 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1189 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001190
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001191 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1192 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001193
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001194 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1195 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001196
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001197 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1198 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001199
1200 /*
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001201 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1202 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001203 */
1204 { } /* end */
1205};
1206
Matthew Ranostay541eee82007-12-14 12:08:04 +01001207static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostay687cb982008-10-11 13:52:43 -04001208 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1209 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001210
Matthew Ranostay687cb982008-10-11 13:52:43 -04001211 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1212 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001213
1214 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1215 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1216
1217 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1218 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001219 { } /* end */
1220};
1221
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001222static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1223 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1224};
Matthew Ranostay541eee82007-12-14 12:08:04 +01001225
Tobin Davis8e21c342007-01-08 11:04:17 +01001226static struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwaic9280d62009-01-15 17:31:00 +01001227 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1228 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001229 { } /* end */
1230};
1231
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001232static struct snd_kcontrol_new stac9205_loopback[] = {
1233 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1234 {}
1235};
1236
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001237static struct snd_kcontrol_new stac927x_loopback[] = {
1238 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1239 {}
1240};
1241
Takashi Iwai1697055e2007-12-18 18:05:52 +01001242static struct snd_kcontrol_new stac_dmux_mixer = {
1243 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1244 .name = "Digital Input Source",
1245 /* count set later */
1246 .info = stac92xx_dmux_enum_info,
1247 .get = stac92xx_dmux_enum_get,
1248 .put = stac92xx_dmux_enum_put,
1249};
1250
Matthew Ranostayd9737752008-09-07 12:03:41 +02001251static struct snd_kcontrol_new stac_smux_mixer = {
1252 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001253 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001254 /* count set later */
1255 .info = stac92xx_smux_enum_info,
1256 .get = stac92xx_smux_enum_get,
1257 .put = stac92xx_smux_enum_put,
1258};
1259
Takashi Iwai2134ea42008-01-10 16:53:55 +01001260static const char *slave_vols[] = {
1261 "Front Playback Volume",
1262 "Surround Playback Volume",
1263 "Center Playback Volume",
1264 "LFE Playback Volume",
1265 "Side Playback Volume",
1266 "Headphone Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001267 "Speaker Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001268 NULL
1269};
1270
1271static const char *slave_sws[] = {
1272 "Front Playback Switch",
1273 "Surround Playback Switch",
1274 "Center Playback Switch",
1275 "LFE Playback Switch",
1276 "Side Playback Switch",
1277 "Headphone Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001278 "Speaker Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001279 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001280 NULL
1281};
1282
Takashi Iwai603c4012008-07-30 15:01:44 +02001283static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001284static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001285
Matt2f2f4252005-04-13 14:45:30 +02001286static int stac92xx_build_controls(struct hda_codec *codec)
1287{
1288 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001289 struct auto_pin_cfg *cfg = &spec->autocfg;
1290 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001291 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001292 int i;
Matt2f2f4252005-04-13 14:45:30 +02001293
Takashi Iwai6479c632009-07-28 18:20:25 +02001294 if (spec->mixer) {
1295 err = snd_hda_add_new_ctls(codec, spec->mixer);
1296 if (err < 0)
1297 return err;
1298 }
Mattc7d4b2f2005-06-27 14:59:41 +02001299
1300 for (i = 0; i < spec->num_mixers; i++) {
1301 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1302 if (err < 0)
1303 return err;
1304 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02001305 if (!spec->auto_mic && spec->num_dmuxes > 0) {
Takashi Iwai1697055e2007-12-18 18:05:52 +01001306 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001307 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001308 snd_ctl_new1(&stac_dmux_mixer, codec));
1309 if (err < 0)
1310 return err;
1311 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001312 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001313 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1314 struct hda_input_mux *smux = &spec->private_smux;
1315 /* check for mute support on SPDIF out */
1316 if (wcaps & AC_WCAP_OUT_AMP) {
1317 smux->items[smux->num_items].label = "Off";
1318 smux->items[smux->num_items].index = 0;
1319 smux->num_items++;
1320 spec->spdif_mute = 1;
1321 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001322 stac_smux_mixer.count = spec->num_smuxes;
Takashi Iwai4f2d23e2008-12-19 10:14:13 +01001323 err = snd_hda_ctl_add(codec,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001324 snd_ctl_new1(&stac_smux_mixer, codec));
1325 if (err < 0)
1326 return err;
1327 }
Mattc7d4b2f2005-06-27 14:59:41 +02001328
Mattdabbed62005-06-14 10:19:34 +02001329 if (spec->multiout.dig_out_nid) {
1330 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1331 if (err < 0)
1332 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001333 err = snd_hda_create_spdif_share_sw(codec,
1334 &spec->multiout);
1335 if (err < 0)
1336 return err;
1337 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001338 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001339 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001340 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1341 if (err < 0)
1342 return err;
1343 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001344
1345 /* if we have no master control, let's create it */
1346 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001347 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001348 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001349 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001350 /* correct volume offset */
1351 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001352 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001353 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001354 if (err < 0)
1355 return err;
1356 }
1357 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1358 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1359 NULL, slave_sws);
1360 if (err < 0)
1361 return err;
1362 }
1363
Takashi Iwaid78d7a92009-03-02 14:26:25 +01001364 if (spec->aloopback_ctl &&
1365 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1366 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1367 if (err < 0)
1368 return err;
1369 }
1370
Takashi Iwai603c4012008-07-30 15:01:44 +02001371 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001372
1373 /* create jack input elements */
1374 if (spec->hp_detect) {
1375 for (i = 0; i < cfg->hp_outs; i++) {
1376 int type = SND_JACK_HEADPHONE;
1377 nid = cfg->hp_pins[i];
1378 /* jack detection */
1379 if (cfg->hp_outs == i)
1380 type |= SND_JACK_LINEOUT;
1381 err = stac92xx_add_jack(codec, nid, type);
1382 if (err < 0)
1383 return err;
1384 }
1385 }
1386 for (i = 0; i < cfg->line_outs; i++) {
1387 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1388 SND_JACK_LINEOUT);
1389 if (err < 0)
1390 return err;
1391 }
1392 for (i = 0; i < AUTO_PIN_LAST; i++) {
1393 nid = cfg->input_pins[i];
1394 if (nid) {
1395 err = stac92xx_add_jack(codec, nid,
1396 SND_JACK_MICROPHONE);
1397 if (err < 0)
1398 return err;
1399 }
1400 }
1401
Mattdabbed62005-06-14 10:19:34 +02001402 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001403}
1404
Matt Porter403d1942005-11-29 15:00:51 +01001405static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001406 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001407 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1408};
1409
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001410static unsigned int gateway9200_m4_pin_configs[8] = {
1411 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1412 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1413};
1414static unsigned int gateway9200_m4_2_pin_configs[8] = {
1415 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1416 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1417};
1418
1419/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001420 STAC 9200 pin configs for
1421 102801A8
1422 102801DE
1423 102801E8
1424*/
1425static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001426 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1427 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001428};
1429
1430/*
1431 STAC 9200 pin configs for
1432 102801C0
1433 102801C1
1434*/
1435static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001436 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1437 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001438};
1439
1440/*
1441 STAC 9200 pin configs for
1442 102801C4 (Dell Dimension E310)
1443 102801C5
1444 102801C7
1445 102801D9
1446 102801DA
1447 102801E3
1448*/
1449static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001450 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1451 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001452};
1453
1454
1455/*
1456 STAC 9200-32 pin configs for
1457 102801B5 (Dell Inspiron 630m)
1458 102801D8 (Dell Inspiron 640m)
1459*/
1460static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001461 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1462 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001463};
1464
1465/*
1466 STAC 9200-32 pin configs for
1467 102801C2 (Dell Latitude D620)
1468 102801C8
1469 102801CC (Dell Latitude D820)
1470 102801D4
1471 102801D6
1472*/
1473static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001474 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1475 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001476};
1477
1478/*
1479 STAC 9200-32 pin configs for
1480 102801CE (Dell XPS M1710)
1481 102801CF (Dell Precision M90)
1482*/
1483static unsigned int dell9200_m23_pin_configs[8] = {
1484 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1485 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1486};
1487
1488/*
1489 STAC 9200-32 pin configs for
1490 102801C9
1491 102801CA
1492 102801CB (Dell Latitude 120L)
1493 102801D3
1494*/
1495static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001496 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1497 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001498};
1499
1500/*
1501 STAC 9200-32 pin configs for
1502 102801BD (Dell Inspiron E1505n)
1503 102801EE
1504 102801EF
1505*/
1506static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001507 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1508 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001509};
1510
1511/*
1512 STAC 9200-32 pin configs for
1513 102801F5 (Dell Inspiron 1501)
1514 102801F6
1515*/
1516static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001517 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1518 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001519};
1520
1521/*
1522 STAC 9200-32
1523 102801CD (Dell Inspiron E1705/9400)
1524*/
1525static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001526 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1527 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001528};
1529
Tobin Davisbf277782008-02-03 20:31:47 +01001530static unsigned int oqo9200_pin_configs[8] = {
1531 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1532 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1533};
1534
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001535
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001536static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1537 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001538 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001539 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1540 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1541 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1542 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1543 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1544 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1545 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1546 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1547 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1548 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001549 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1550 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001551 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001552};
1553
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001554static const char *stac9200_models[STAC_9200_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001555 [STAC_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001556 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001557 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001558 [STAC_9200_DELL_D21] = "dell-d21",
1559 [STAC_9200_DELL_D22] = "dell-d22",
1560 [STAC_9200_DELL_D23] = "dell-d23",
1561 [STAC_9200_DELL_M21] = "dell-m21",
1562 [STAC_9200_DELL_M22] = "dell-m22",
1563 [STAC_9200_DELL_M23] = "dell-m23",
1564 [STAC_9200_DELL_M24] = "dell-m24",
1565 [STAC_9200_DELL_M25] = "dell-m25",
1566 [STAC_9200_DELL_M26] = "dell-m26",
1567 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001568 [STAC_9200_M4] = "gateway-m4",
1569 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001570 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001571};
1572
1573static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1574 /* SigmaTel reference board */
1575 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1576 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001577 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1578 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001579 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001580 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1581 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001582 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001583 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1584 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1585 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1586 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1587 "unknown Dell", STAC_9200_DELL_D22),
1588 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1589 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001590 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001591 "Dell Latitude D620", STAC_9200_DELL_M22),
1592 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1593 "unknown Dell", STAC_9200_DELL_D23),
1594 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1595 "unknown Dell", STAC_9200_DELL_D23),
1596 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1597 "unknown Dell", STAC_9200_DELL_M22),
1598 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1599 "unknown Dell", STAC_9200_DELL_M24),
1600 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1601 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001602 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001603 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001604 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001605 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001606 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001607 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001608 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001609 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001610 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001611 "Dell Precision M90", STAC_9200_DELL_M23),
1612 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1613 "unknown Dell", STAC_9200_DELL_M22),
1614 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1615 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001616 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001617 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001618 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001619 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1620 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1621 "unknown Dell", STAC_9200_DELL_D23),
1622 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1623 "unknown Dell", STAC_9200_DELL_D23),
1624 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1625 "unknown Dell", STAC_9200_DELL_D21),
1626 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1627 "unknown Dell", STAC_9200_DELL_D23),
1628 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1629 "unknown Dell", STAC_9200_DELL_D21),
1630 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1631 "unknown Dell", STAC_9200_DELL_M25),
1632 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1633 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001634 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001635 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1636 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1637 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001638 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001639 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001640 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001641 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1642 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1643 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001644 /* OQO Mobile */
1645 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001646 {} /* terminator */
1647};
1648
Tobin Davis8e21c342007-01-08 11:04:17 +01001649static unsigned int ref925x_pin_configs[8] = {
1650 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001651 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001652};
1653
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001654static unsigned int stac925xM1_pin_configs[8] = {
1655 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1656 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001657};
1658
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001659static unsigned int stac925xM1_2_pin_configs[8] = {
1660 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1661 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1662};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001663
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001664static unsigned int stac925xM2_pin_configs[8] = {
1665 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1666 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001667};
1668
Tobin Davis8e21c342007-01-08 11:04:17 +01001669static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001670 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1671 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1672};
1673
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001674static unsigned int stac925xM3_pin_configs[8] = {
1675 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1676 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1677};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001678
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001679static unsigned int stac925xM5_pin_configs[8] = {
1680 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1681 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1682};
1683
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001684static unsigned int stac925xM6_pin_configs[8] = {
1685 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1686 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001687};
1688
1689static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1690 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001691 [STAC_M1] = stac925xM1_pin_configs,
1692 [STAC_M1_2] = stac925xM1_2_pin_configs,
1693 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001694 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001695 [STAC_M3] = stac925xM3_pin_configs,
1696 [STAC_M5] = stac925xM5_pin_configs,
1697 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001698};
1699
1700static const char *stac925x_models[STAC_925x_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001701 [STAC_925x_AUTO] = "auto",
Tobin Davis8e21c342007-01-08 11:04:17 +01001702 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001703 [STAC_M1] = "m1",
1704 [STAC_M1_2] = "m1-2",
1705 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001706 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001707 [STAC_M3] = "m3",
1708 [STAC_M5] = "m5",
1709 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001710};
1711
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001712static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001713 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1714 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1715 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1716 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001717 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001718 /* Not sure about the brand name for those */
1719 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1720 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1721 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1722 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001723 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001724};
1725
1726static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1727 /* SigmaTel reference board */
1728 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001729 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001730 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001731
1732 /* Default table for unknown ID */
1733 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1734
Tobin Davis8e21c342007-01-08 11:04:17 +01001735 {} /* terminator */
1736};
1737
Matthew Ranostaya7662642008-02-21 07:51:14 +01001738static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001739 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1740 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1741 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001742 0x01452050,
1743};
1744
1745static unsigned int dell_m6_pin_configs[13] = {
1746 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001747 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001748 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1749 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001750};
1751
1752static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001753 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001754 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1755 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1756 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001757 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001758};
1759
1760static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001761 [STAC_92HD73XX_AUTO] = "auto",
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001762 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001763 [STAC_92HD73XX_REF] = "ref",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001764 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1765 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1766 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001767 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001768};
1769
1770static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1771 /* SigmaTel reference board */
1772 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001773 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001774 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1775 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001776 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001777 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001778 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001779 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001780 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001781 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001782 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001783 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001784 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001785 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001786 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001787 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001788 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001789 "unknown Dell", STAC_DELL_M6_DMIC),
1790 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1791 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001792 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001793 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001794 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1795 "Dell Studio 17", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001796 {} /* terminator */
1797};
1798
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001799static unsigned int ref92hd83xxx_pin_configs[10] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001800 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1801 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001802 0x01451160, 0x98560170,
1803};
1804
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001805static unsigned int dell_s14_pin_configs[10] = {
1806 0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1807 0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1808 0x40f000f0, 0x40f000f0,
1809};
1810
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001811static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1812 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001813 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001814 [STAC_DELL_S14] = dell_s14_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001815};
1816
1817static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001818 [STAC_92HD83XXX_AUTO] = "auto",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001819 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001820 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001821 [STAC_DELL_S14] = "dell-s14",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001822};
1823
1824static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1825 /* SigmaTel reference board */
1826 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001827 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001828 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1829 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05001830 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1831 "unknown Dell", STAC_DELL_S14),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001832 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001833};
1834
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001835static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001836 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001837 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001838 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1839 0x00000000
Matthew Ranostaye035b842007-11-06 11:53:55 +01001840};
1841
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001842static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001843 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001844 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001845 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 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_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001850 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1851 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001852 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1853 0x00000000
Matthew Ranostaya7662642008-02-21 07:51:14 +01001854};
1855
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001856static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001857 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1858 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05001859 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1860 0x00000000
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001861};
1862
Matthew Ranostaye035b842007-11-06 11:53:55 +01001863static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1864 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001865 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1866 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001867 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001868 [STAC_HP_M4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001869 [STAC_HP_DV5] = NULL,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001870 [STAC_HP_HDX] = NULL,
James Gardiner514bf542009-05-03 04:00:44 -04001871 [STAC_HP_DV4_1222NR] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001872};
1873
1874static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01001875 [STAC_92HD71BXX_AUTO] = "auto",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001876 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001877 [STAC_DELL_M4_1] = "dell-m4-1",
1878 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001879 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001880 [STAC_HP_M4] = "hp-m4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001881 [STAC_HP_DV5] = "hp-dv5",
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001882 [STAC_HP_HDX] = "hp-hdx",
James Gardiner514bf542009-05-03 04:00:44 -04001883 [STAC_HP_DV4_1222NR] = "hp-dv4-1222nr",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001884};
1885
1886static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1887 /* SigmaTel reference board */
1888 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1889 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001890 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1891 "DFI LanParty", STAC_92HD71BXX_REF),
James Gardiner514bf542009-05-03 04:00:44 -04001892 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fb,
1893 "HP dv4-1222nr", STAC_HP_DV4_1222NR),
Takashi Iwai58d83952009-03-13 17:04:34 +01001894 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1895 "HP", STAC_HP_DV5),
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001896 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1897 "HP dv4-7", STAC_HP_DV5),
1898 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1899 "HP dv4-7", STAC_HP_DV5),
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001900 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1901 "HP HDX", STAC_HP_HDX), /* HDX18 */
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001902 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
Takashi Iwai2ae466f2009-02-16 14:16:36 +01001903 "HP mini 1000", STAC_HP_M4),
Christoph Plattnerae6241f2009-03-08 23:19:05 +01001904 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01001905 "HP HDX", STAC_HP_HDX), /* HDX16 */
Matthew Ranostaya7662642008-02-21 07:51:14 +01001906 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1907 "unknown Dell", STAC_DELL_M4_1),
1908 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1909 "unknown Dell", STAC_DELL_M4_1),
1910 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1911 "unknown Dell", STAC_DELL_M4_1),
1912 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1913 "unknown Dell", STAC_DELL_M4_1),
1914 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1915 "unknown Dell", STAC_DELL_M4_1),
1916 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1917 "unknown Dell", STAC_DELL_M4_1),
1918 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1919 "unknown Dell", STAC_DELL_M4_1),
1920 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1921 "unknown Dell", STAC_DELL_M4_2),
1922 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1923 "unknown Dell", STAC_DELL_M4_2),
1924 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1925 "unknown Dell", STAC_DELL_M4_2),
1926 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1927 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001928 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1929 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001930 {} /* terminator */
1931};
1932
Matt Porter403d1942005-11-29 15:00:51 +01001933static unsigned int ref922x_pin_configs[10] = {
1934 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1935 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001936 0x40000100, 0x40000100,
1937};
1938
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001939/*
1940 STAC 922X pin configs for
1941 102801A7
1942 102801AB
1943 102801A9
1944 102801D1
1945 102801D2
1946*/
1947static unsigned int dell_922x_d81_pin_configs[10] = {
1948 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1949 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1950 0x01813122, 0x400001f2,
1951};
1952
1953/*
1954 STAC 922X pin configs for
1955 102801AC
1956 102801D0
1957*/
1958static unsigned int dell_922x_d82_pin_configs[10] = {
1959 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1960 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1961 0x01813122, 0x400001f1,
1962};
1963
1964/*
1965 STAC 922X pin configs for
1966 102801BF
1967*/
1968static unsigned int dell_922x_m81_pin_configs[10] = {
1969 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1970 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1971 0x40C003f1, 0x405003f0,
1972};
1973
1974/*
1975 STAC 9221 A1 pin configs for
1976 102801D7 (Dell XPS M1210)
1977*/
1978static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001979 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1980 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001981 0x508003f3, 0x405003f4,
1982};
1983
Matt Porter403d1942005-11-29 15:00:51 +01001984static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001985 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001986 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1987 0x02a19120, 0x40000100,
1988};
1989
1990static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001991 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1992 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001993 0x02a19320, 0x40000100,
1994};
1995
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001996static unsigned int intel_mac_v1_pin_configs[10] = {
1997 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1998 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001999 0x400000fc, 0x400000fb,
2000};
2001
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002002static unsigned int intel_mac_v2_pin_configs[10] = {
2003 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2004 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02002005 0x400000fc, 0x400000fb,
2006};
2007
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002008static unsigned int intel_mac_v3_pin_configs[10] = {
2009 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
2010 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
2011 0x400000fc, 0x400000fb,
2012};
2013
2014static unsigned int intel_mac_v4_pin_configs[10] = {
2015 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2016 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2017 0x400000fc, 0x400000fb,
2018};
2019
2020static unsigned int intel_mac_v5_pin_configs[10] = {
2021 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
2022 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
2023 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002024};
2025
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002026static unsigned int ecs202_pin_configs[10] = {
2027 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
2028 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
2029 0x9037012e, 0x40e000f2,
2030};
Takashi Iwai76c08822007-06-19 12:17:42 +02002031
Takashi Iwai19039bd2006-06-28 15:52:16 +02002032static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002033 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002034 [STAC_D945GTP3] = d945gtp3_pin_configs,
2035 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002036 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
2037 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
2038 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
2039 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
2040 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002041 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002042 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002043 [STAC_MACMINI] = intel_mac_v3_pin_configs,
2044 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
2045 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
2046 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
2047 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
2048 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002049 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002050 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
2051 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
2052 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
2053 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01002054};
2055
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002056static const char *stac922x_models[STAC_922X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002057 [STAC_922X_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002058 [STAC_D945_REF] = "ref",
2059 [STAC_D945GTP5] = "5stack",
2060 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02002061 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
2062 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
2063 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
2064 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
2065 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08002066 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002067 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002068 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01002069 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01002070 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
2071 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02002072 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02002073 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002074 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002075 [STAC_922X_DELL_D81] = "dell-d81",
2076 [STAC_922X_DELL_D82] = "dell-d82",
2077 [STAC_922X_DELL_M81] = "dell-m81",
2078 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002079};
2080
2081static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2082 /* SigmaTel reference board */
2083 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2084 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002085 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2086 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002087 /* Intel 945G based systems */
2088 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2089 "Intel D945G", STAC_D945GTP3),
2090 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2091 "Intel D945G", STAC_D945GTP3),
2092 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2093 "Intel D945G", STAC_D945GTP3),
2094 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2095 "Intel D945G", STAC_D945GTP3),
2096 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2097 "Intel D945G", STAC_D945GTP3),
2098 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2099 "Intel D945G", STAC_D945GTP3),
2100 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2101 "Intel D945G", STAC_D945GTP3),
2102 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2103 "Intel D945G", STAC_D945GTP3),
2104 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2105 "Intel D945G", STAC_D945GTP3),
2106 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2107 "Intel D945G", STAC_D945GTP3),
2108 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2109 "Intel D945G", STAC_D945GTP3),
2110 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2111 "Intel D945G", STAC_D945GTP3),
2112 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2113 "Intel D945G", STAC_D945GTP3),
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2115 "Intel D945G", STAC_D945GTP3),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2117 "Intel D945G", STAC_D945GTP3),
2118 /* Intel D945G 5-stack systems */
2119 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2120 "Intel D945G", STAC_D945GTP5),
2121 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2122 "Intel D945G", STAC_D945GTP5),
2123 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2124 "Intel D945G", STAC_D945GTP5),
2125 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2126 "Intel D945G", STAC_D945GTP5),
2127 /* Intel 945P based systems */
2128 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2129 "Intel D945P", STAC_D945GTP3),
2130 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2131 "Intel D945P", STAC_D945GTP3),
2132 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2133 "Intel D945P", STAC_D945GTP3),
2134 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2135 "Intel D945P", STAC_D945GTP3),
2136 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2137 "Intel D945P", STAC_D945GTP3),
2138 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2139 "Intel D945P", STAC_D945GTP5),
Takashi Iwai8056d472009-01-23 09:09:43 +01002140 /* other intel */
2141 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2142 "Intel D945", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002143 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002144 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002145 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002146 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002147 /* Dell systems */
2148 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2149 "unknown Dell", STAC_922X_DELL_D81),
2150 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2151 "unknown Dell", STAC_922X_DELL_D81),
2152 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2153 "unknown Dell", STAC_922X_DELL_D81),
2154 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2155 "unknown Dell", STAC_922X_DELL_D82),
2156 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2157 "unknown Dell", STAC_922X_DELL_M81),
2158 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2159 "unknown Dell", STAC_922X_DELL_D82),
2160 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2161 "unknown Dell", STAC_922X_DELL_D81),
2162 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2163 "unknown Dell", STAC_922X_DELL_D81),
2164 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2165 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002166 /* ECS/PC Chips boards */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002167 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
Herton Ronaldo Krzesinski8663ae52009-02-08 19:50:34 -02002168 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002169 {} /* terminator */
2170};
2171
Matt Porter3cc08dc2006-01-23 15:27:49 +01002172static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002173 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2174 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2175 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2176 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002177};
2178
Tobin Davis93ed1502006-09-01 21:03:12 +02002179static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002180 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2181 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2182 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2183 0x40000100, 0x40000100
2184};
2185
Tobin Davis93ed1502006-09-01 21:03:12 +02002186static unsigned int d965_5st_pin_configs[14] = {
2187 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2188 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2189 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2190 0x40000100, 0x40000100
2191};
2192
Takashi Iwai679d92e2009-05-24 19:00:08 +02002193static unsigned int d965_5st_no_fp_pin_configs[14] = {
2194 0x40000100, 0x40000100, 0x0181304e, 0x01014010,
2195 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2196 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2197 0x40000100, 0x40000100
2198};
2199
Tobin Davis4ff076e2007-08-07 11:48:12 +02002200static unsigned int dell_3st_pin_configs[14] = {
2201 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2202 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002203 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002204 0x40c003fc, 0x40000100
2205};
2206
Tobin Davis93ed1502006-09-01 21:03:12 +02002207static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002208 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002209 [STAC_D965_REF] = ref927x_pin_configs,
2210 [STAC_D965_3ST] = d965_3st_pin_configs,
2211 [STAC_D965_5ST] = d965_5st_pin_configs,
Takashi Iwai679d92e2009-05-24 19:00:08 +02002212 [STAC_D965_5ST_NO_FP] = d965_5st_no_fp_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002213 [STAC_DELL_3ST] = dell_3st_pin_configs,
2214 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002215};
2216
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002217static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002218 [STAC_927X_AUTO] = "auto",
Takashi Iwaie28d8322008-12-17 13:48:29 +01002219 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002220 [STAC_D965_REF] = "ref",
2221 [STAC_D965_3ST] = "3stack",
2222 [STAC_D965_5ST] = "5stack",
Takashi Iwai679d92e2009-05-24 19:00:08 +02002223 [STAC_D965_5ST_NO_FP] = "5stack-no-fp",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002224 [STAC_DELL_3ST] = "dell-3stack",
2225 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002226};
2227
2228static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2229 /* SigmaTel reference board */
2230 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2231 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002232 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2233 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002234 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002235 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2236 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002237 /* 965 based 3 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002238 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2239 "Intel D965", STAC_D965_3ST),
2240 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2241 "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002242 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002243 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002244 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002245 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2246 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002247 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002248 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2249 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002250 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Takashi Iwai24918b62008-09-30 12:58:54 +02002251 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002252 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2253 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2254 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2255 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002256 /* 965 based 5 stack systems */
Takashi Iwaidea0a502009-02-09 17:14:52 +01002257 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2258 "Intel D965", STAC_D965_5ST),
2259 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2260 "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002261 {} /* terminator */
2262};
2263
Matt Porterf3302a52006-07-31 12:49:34 +02002264static unsigned int ref9205_pin_configs[12] = {
2265 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002266 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002267 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002268};
2269
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002270/*
2271 STAC 9205 pin configs for
2272 102801F1
2273 102801F2
2274 102801FC
2275 102801FD
2276 10280204
2277 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002278 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002279*/
2280static unsigned int dell_9205_m42_pin_configs[12] = {
2281 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2282 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2283 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2284};
2285
2286/*
2287 STAC 9205 pin configs for
2288 102801F9
2289 102801FA
2290 102801FE
2291 102801FF (Dell Precision M4300)
2292 10280206
2293 10280200
2294 10280201
2295*/
2296static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002297 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2298 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2299 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2300};
2301
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002302static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002303 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2304 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2305 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2306};
2307
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002308static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002309 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002310 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2311 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2312 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002313 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002314};
2315
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002316static const char *stac9205_models[STAC_9205_MODELS] = {
Takashi Iwai1607b8e2009-02-26 16:50:43 +01002317 [STAC_9205_AUTO] = "auto",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002318 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002319 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002320 [STAC_9205_DELL_M43] = "dell-m43",
2321 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002322 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002323};
2324
2325static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2326 /* SigmaTel reference board */
2327 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2328 "DFI LanParty", STAC_9205_REF),
Herton Ronaldo Krzesinski02358fc2009-07-04 01:44:59 -03002329 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xfb30,
2330 "SigmaTel", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002331 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2332 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002333 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002334 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2335 "unknown Dell", STAC_9205_DELL_M42),
2336 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2337 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002338 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002339 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002340 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2341 "Dell Precision", STAC_9205_DELL_M43),
2342 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2343 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002344 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2345 "unknown Dell", STAC_9205_DELL_M42),
2346 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2347 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002348 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2349 "Dell Precision", STAC_9205_DELL_M43),
2350 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002351 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002352 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2353 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002354 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2355 "Dell Precision", STAC_9205_DELL_M43),
2356 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2357 "Dell Precision", STAC_9205_DELL_M43),
2358 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2359 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002360 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2361 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002362 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2363 "Dell Vostro 1500", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002364 /* Gateway */
Hao Song42b95f02009-07-20 15:01:16 +08002365 SND_PCI_QUIRK(0x107b, 0x0560, "Gateway T6834c", STAC_9205_EAPD),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002366 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002367 {} /* terminator */
2368};
2369
Takashi Iwai330ee992009-02-20 14:33:36 +01002370static void stac92xx_set_config_regs(struct hda_codec *codec,
2371 unsigned int *pincfgs)
Matt2f2f4252005-04-13 14:45:30 +02002372{
2373 int i;
2374 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002375
Takashi Iwai330ee992009-02-20 14:33:36 +01002376 if (!pincfgs)
2377 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002378
Matthew Ranostay87d48362007-07-17 11:52:24 +02002379 for (i = 0; i < spec->num_pins; i++)
Takashi Iwai330ee992009-02-20 14:33:36 +01002380 if (spec->pin_nids[i] && pincfgs[i])
2381 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2382 pincfgs[i]);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002383}
2384
Matt2f2f4252005-04-13 14:45:30 +02002385/*
2386 * Analog playback callbacks
2387 */
2388static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2389 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002390 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002391{
2392 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002393 if (spec->stream_delay)
2394 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002395 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2396 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002397}
2398
2399static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2400 struct hda_codec *codec,
2401 unsigned int stream_tag,
2402 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002403 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002404{
2405 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002406 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002407}
2408
2409static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2410 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002411 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002412{
2413 struct sigmatel_spec *spec = codec->spec;
2414 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2415}
2416
2417/*
Mattdabbed62005-06-14 10:19:34 +02002418 * Digital playback callbacks
2419 */
2420static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2421 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002422 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002423{
2424 struct sigmatel_spec *spec = codec->spec;
2425 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2426}
2427
2428static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2429 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002430 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002431{
2432 struct sigmatel_spec *spec = codec->spec;
2433 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2434}
2435
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002436static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2437 struct hda_codec *codec,
2438 unsigned int stream_tag,
2439 unsigned int format,
2440 struct snd_pcm_substream *substream)
2441{
2442 struct sigmatel_spec *spec = codec->spec;
2443 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2444 stream_tag, format, substream);
2445}
2446
Takashi Iwai9411e212009-02-13 11:32:28 +01002447static int stac92xx_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2448 struct hda_codec *codec,
2449 struct snd_pcm_substream *substream)
2450{
2451 struct sigmatel_spec *spec = codec->spec;
2452 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2453}
2454
Mattdabbed62005-06-14 10:19:34 +02002455
2456/*
Matt2f2f4252005-04-13 14:45:30 +02002457 * Analog capture callbacks
2458 */
2459static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2460 struct hda_codec *codec,
2461 unsigned int stream_tag,
2462 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002463 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002464{
2465 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002466 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002467
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002468 if (spec->powerdown_adcs) {
2469 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002470 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002471 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2472 }
2473 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002474 return 0;
2475}
2476
2477static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2478 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002479 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002480{
2481 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002482 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002483
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002484 snd_hda_codec_cleanup_stream(codec, nid);
2485 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002486 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002487 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002488 return 0;
2489}
2490
Mattdabbed62005-06-14 10:19:34 +02002491static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2492 .substreams = 1,
2493 .channels_min = 2,
2494 .channels_max = 2,
2495 /* NID is set in stac92xx_build_pcms */
2496 .ops = {
2497 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002498 .close = stac92xx_dig_playback_pcm_close,
Takashi Iwai9411e212009-02-13 11:32:28 +01002499 .prepare = stac92xx_dig_playback_pcm_prepare,
2500 .cleanup = stac92xx_dig_playback_pcm_cleanup
Mattdabbed62005-06-14 10:19:34 +02002501 },
2502};
2503
2504static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2505 .substreams = 1,
2506 .channels_min = 2,
2507 .channels_max = 2,
2508 /* NID is set in stac92xx_build_pcms */
2509};
2510
Matt2f2f4252005-04-13 14:45:30 +02002511static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2512 .substreams = 1,
2513 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002514 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002515 .nid = 0x02, /* NID to query formats and rates */
2516 .ops = {
2517 .open = stac92xx_playback_pcm_open,
2518 .prepare = stac92xx_playback_pcm_prepare,
2519 .cleanup = stac92xx_playback_pcm_cleanup
2520 },
2521};
2522
Matt Porter3cc08dc2006-01-23 15:27:49 +01002523static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2524 .substreams = 1,
2525 .channels_min = 2,
2526 .channels_max = 2,
2527 .nid = 0x06, /* NID to query formats and rates */
2528 .ops = {
2529 .open = stac92xx_playback_pcm_open,
2530 .prepare = stac92xx_playback_pcm_prepare,
2531 .cleanup = stac92xx_playback_pcm_cleanup
2532 },
2533};
2534
Matt2f2f4252005-04-13 14:45:30 +02002535static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002536 .channels_min = 2,
2537 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002538 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002539 .ops = {
2540 .prepare = stac92xx_capture_pcm_prepare,
2541 .cleanup = stac92xx_capture_pcm_cleanup
2542 },
2543};
2544
2545static int stac92xx_build_pcms(struct hda_codec *codec)
2546{
2547 struct sigmatel_spec *spec = codec->spec;
2548 struct hda_pcm *info = spec->pcm_rec;
2549
2550 codec->num_pcms = 1;
2551 codec->pcm_info = info;
2552
Mattc7d4b2f2005-06-27 14:59:41 +02002553 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002554 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Takashi Iwai00a602d2009-01-23 11:55:42 +01002555 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2556 spec->multiout.dac_nids[0];
Matt2f2f4252005-04-13 14:45:30 +02002557 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002558 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002559 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002560
2561 if (spec->alt_switch) {
2562 codec->num_pcms++;
2563 info++;
2564 info->name = "STAC92xx Analog Alt";
2565 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2566 }
Matt2f2f4252005-04-13 14:45:30 +02002567
Mattdabbed62005-06-14 10:19:34 +02002568 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2569 codec->num_pcms++;
2570 info++;
2571 info->name = "STAC92xx Digital";
Takashi Iwai0852d7a2009-02-11 11:35:15 +01002572 info->pcm_type = spec->autocfg.dig_out_type[0];
Mattdabbed62005-06-14 10:19:34 +02002573 if (spec->multiout.dig_out_nid) {
2574 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2575 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2576 }
2577 if (spec->dig_in_nid) {
2578 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2579 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2580 }
2581 }
2582
Matt2f2f4252005-04-13 14:45:30 +02002583 return 0;
2584}
2585
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002586static unsigned int stac92xx_get_default_vref(struct hda_codec *codec,
2587 hda_nid_t nid)
Takashi Iwaic960a032006-03-23 17:06:28 +01002588{
Takashi Iwai1327a322009-03-23 13:07:47 +01002589 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002590 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2591 if (pincap & AC_PINCAP_VREF_100)
2592 return AC_PINCTL_VREF_100;
2593 if (pincap & AC_PINCAP_VREF_80)
2594 return AC_PINCTL_VREF_80;
2595 if (pincap & AC_PINCAP_VREF_50)
2596 return AC_PINCTL_VREF_50;
2597 if (pincap & AC_PINCAP_VREF_GRD)
2598 return AC_PINCTL_VREF_GRD;
2599 return 0;
2600}
2601
Matt Porter403d1942005-11-29 15:00:51 +01002602static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2603
2604{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002605 snd_hda_codec_write_cache(codec, nid, 0,
2606 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002607}
2608
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002609#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2610
2611static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2612 struct snd_ctl_elem_value *ucontrol)
2613{
2614 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2615 struct sigmatel_spec *spec = codec->spec;
2616
Takashi Iwaid7a89432008-11-12 09:48:04 +01002617 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002618 return 0;
2619}
2620
Takashi Iwai62558ce2009-07-29 14:23:09 +02002621static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002622
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002623static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2624 struct snd_ctl_elem_value *ucontrol)
2625{
2626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2627 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002628 int nid = kcontrol->private_value;
2629
2630 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002631
2632 /* check to be sure that the ports are upto date with
2633 * switch changes
2634 */
Takashi Iwai62558ce2009-07-29 14:23:09 +02002635 stac_issue_unsol_event(codec, nid);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002636
2637 return 1;
2638}
2639
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002640static int stac92xx_dc_bias_info(struct snd_kcontrol *kcontrol,
2641 struct snd_ctl_elem_info *uinfo)
2642{
2643 int i;
2644 static char *texts[] = {
2645 "Mic In", "Line In", "Line Out"
2646 };
2647
2648 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2649 struct sigmatel_spec *spec = codec->spec;
2650 hda_nid_t nid = kcontrol->private_value;
2651
2652 if (nid == spec->mic_switch || nid == spec->line_switch)
2653 i = 3;
2654 else
2655 i = 2;
2656
2657 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2658 uinfo->value.enumerated.items = i;
2659 uinfo->count = 1;
2660 if (uinfo->value.enumerated.item >= i)
2661 uinfo->value.enumerated.item = i-1;
2662 strcpy(uinfo->value.enumerated.name,
2663 texts[uinfo->value.enumerated.item]);
2664
2665 return 0;
2666}
2667
2668static int stac92xx_dc_bias_get(struct snd_kcontrol *kcontrol,
2669 struct snd_ctl_elem_value *ucontrol)
2670{
2671 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2672 hda_nid_t nid = kcontrol->private_value;
2673 unsigned int vref = stac92xx_vref_get(codec, nid);
2674
2675 if (vref == stac92xx_get_default_vref(codec, nid))
2676 ucontrol->value.enumerated.item[0] = 0;
2677 else if (vref == AC_PINCTL_VREF_GRD)
2678 ucontrol->value.enumerated.item[0] = 1;
2679 else if (vref == AC_PINCTL_VREF_HIZ)
2680 ucontrol->value.enumerated.item[0] = 2;
2681
2682 return 0;
2683}
2684
2685static int stac92xx_dc_bias_put(struct snd_kcontrol *kcontrol,
2686 struct snd_ctl_elem_value *ucontrol)
2687{
2688 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2689 unsigned int new_vref = 0;
Takashi Iwaib8621512009-06-22 08:00:10 +02002690 int error;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002691 hda_nid_t nid = kcontrol->private_value;
2692
2693 if (ucontrol->value.enumerated.item[0] == 0)
2694 new_vref = stac92xx_get_default_vref(codec, nid);
2695 else if (ucontrol->value.enumerated.item[0] == 1)
2696 new_vref = AC_PINCTL_VREF_GRD;
2697 else if (ucontrol->value.enumerated.item[0] == 2)
2698 new_vref = AC_PINCTL_VREF_HIZ;
2699 else
2700 return 0;
2701
2702 if (new_vref != stac92xx_vref_get(codec, nid)) {
2703 error = stac92xx_vref_set(codec, nid, new_vref);
2704 return error;
2705 }
2706
2707 return 0;
2708}
2709
2710static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol,
2711 struct snd_ctl_elem_info *uinfo)
2712{
2713 static char *texts[2];
2714 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2715 struct sigmatel_spec *spec = codec->spec;
2716
2717 if (kcontrol->private_value == spec->line_switch)
2718 texts[0] = "Line In";
2719 else
2720 texts[0] = "Mic In";
2721 texts[1] = "Line Out";
2722 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2723 uinfo->value.enumerated.items = 2;
2724 uinfo->count = 1;
2725
2726 if (uinfo->value.enumerated.item >= 2)
2727 uinfo->value.enumerated.item = 1;
2728 strcpy(uinfo->value.enumerated.name,
2729 texts[uinfo->value.enumerated.item]);
2730
2731 return 0;
2732}
Matt Porter403d1942005-11-29 15:00:51 +01002733
2734static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2735{
2736 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2737 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002738 hda_nid_t nid = kcontrol->private_value;
2739 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
Matt Porter403d1942005-11-29 15:00:51 +01002740
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002741 ucontrol->value.enumerated.item[0] = spec->io_switch[io_idx];
Matt Porter403d1942005-11-29 15:00:51 +01002742 return 0;
2743}
2744
2745static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2746{
2747 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2748 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002749 hda_nid_t nid = kcontrol->private_value;
2750 int io_idx = (nid == spec->mic_switch) ? 1 : 0;
2751 unsigned short val = !!ucontrol->value.enumerated.item[0];
Matt Porter403d1942005-11-29 15:00:51 +01002752
2753 spec->io_switch[io_idx] = val;
2754
2755 if (val)
2756 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002757 else {
2758 unsigned int pinctl = AC_PINCTL_IN_EN;
2759 if (io_idx) /* set VREF for mic */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002760 pinctl |= stac92xx_get_default_vref(codec, nid);
Takashi Iwaic960a032006-03-23 17:06:28 +01002761 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2762 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002763
2764 /* check the auto-mute again: we need to mute/unmute the speaker
2765 * appropriately according to the pin direction
2766 */
2767 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02002768 stac_issue_unsol_event(codec, nid);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002769
Matt Porter403d1942005-11-29 15:00:51 +01002770 return 1;
2771}
2772
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002773#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2774
2775static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2776 struct snd_ctl_elem_value *ucontrol)
2777{
2778 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2779 struct sigmatel_spec *spec = codec->spec;
2780
2781 ucontrol->value.integer.value[0] = spec->clfe_swap;
2782 return 0;
2783}
2784
2785static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2786 struct snd_ctl_elem_value *ucontrol)
2787{
2788 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2789 struct sigmatel_spec *spec = codec->spec;
2790 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002791 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002792
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002793 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002794 return 0;
2795
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002796 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002797
2798 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2799 spec->clfe_swap ? 0x4 : 0x0);
2800
2801 return 1;
2802}
2803
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002804#define STAC_CODEC_HP_SWITCH(xname) \
2805 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2806 .name = xname, \
2807 .index = 0, \
2808 .info = stac92xx_hp_switch_info, \
2809 .get = stac92xx_hp_switch_get, \
2810 .put = stac92xx_hp_switch_put, \
2811 }
2812
Matt Porter403d1942005-11-29 15:00:51 +01002813#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2814 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2815 .name = xname, \
2816 .index = 0, \
2817 .info = stac92xx_io_switch_info, \
2818 .get = stac92xx_io_switch_get, \
2819 .put = stac92xx_io_switch_put, \
2820 .private_value = xpval, \
2821 }
2822
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002823#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2824 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2825 .name = xname, \
2826 .index = 0, \
2827 .info = stac92xx_clfe_switch_info, \
2828 .get = stac92xx_clfe_switch_get, \
2829 .put = stac92xx_clfe_switch_put, \
2830 .private_value = xpval, \
2831 }
Matt Porter403d1942005-11-29 15:00:51 +01002832
Mattc7d4b2f2005-06-27 14:59:41 +02002833enum {
2834 STAC_CTL_WIDGET_VOL,
2835 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002836 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002837 STAC_CTL_WIDGET_AMP_MUX,
2838 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002839 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002840 STAC_CTL_WIDGET_IO_SWITCH,
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002841 STAC_CTL_WIDGET_CLFE_SWITCH,
2842 STAC_CTL_WIDGET_DC_BIAS
Mattc7d4b2f2005-06-27 14:59:41 +02002843};
2844
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002845static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002846 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2847 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002848 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002849 STAC_AMP_MUX,
2850 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002851 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002852 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002853 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Nickolas Lloyd2fc99892009-05-15 15:33:30 +02002854 DC_BIAS(NULL, 0, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002855};
2856
2857/* add dynamic controls */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002858static struct snd_kcontrol_new *
2859stac_control_new(struct sigmatel_spec *spec,
2860 struct snd_kcontrol_new *ktemp,
2861 const char *name)
Mattc7d4b2f2005-06-27 14:59:41 +02002862{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002863 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002864
Takashi Iwai603c4012008-07-30 15:01:44 +02002865 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2866 knew = snd_array_new(&spec->kctls);
2867 if (!knew)
Takashi Iwaie3c75962009-01-23 11:57:22 +01002868 return NULL;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002869 *knew = *ktemp;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002870 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaie3c75962009-01-23 11:57:22 +01002871 if (!knew->name) {
2872 /* roolback */
2873 memset(knew, 0, sizeof(*knew));
2874 spec->kctls.alloced--;
2875 return NULL;
2876 }
2877 return knew;
2878}
2879
2880static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2881 struct snd_kcontrol_new *ktemp,
2882 int idx, const char *name,
2883 unsigned long val)
2884{
2885 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2886 if (!knew)
Mattc7d4b2f2005-06-27 14:59:41 +02002887 return -ENOMEM;
Takashi Iwaie3c75962009-01-23 11:57:22 +01002888 knew->index = idx;
Mattc7d4b2f2005-06-27 14:59:41 +02002889 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002890 return 0;
2891}
2892
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002893static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2894 int type, int idx, const char *name,
2895 unsigned long val)
2896{
2897 return stac92xx_add_control_temp(spec,
2898 &stac92xx_control_templates[type],
2899 idx, name, val);
2900}
2901
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002902
2903/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002904static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2905 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002906{
2907 return stac92xx_add_control_idx(spec, type, 0, name, val);
2908}
2909
Takashi Iwaie3c75962009-01-23 11:57:22 +01002910static struct snd_kcontrol_new stac_input_src_temp = {
2911 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2912 .name = "Input Source",
2913 .info = stac92xx_mux_enum_info,
2914 .get = stac92xx_mux_enum_get,
2915 .put = stac92xx_mux_enum_put,
2916};
2917
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02002918static inline int stac92xx_add_jack_mode_control(struct hda_codec *codec,
2919 hda_nid_t nid, int idx)
2920{
2921 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
2922 int control = 0;
2923 struct sigmatel_spec *spec = codec->spec;
2924 char name[22];
2925
2926 if (!((get_defcfg_connect(def_conf)) & AC_JACK_PORT_FIXED)) {
2927 if (stac92xx_get_default_vref(codec, nid) == AC_PINCTL_VREF_GRD
2928 && nid == spec->line_switch)
2929 control = STAC_CTL_WIDGET_IO_SWITCH;
2930 else if (snd_hda_query_pin_caps(codec, nid)
2931 & (AC_PINCAP_VREF_GRD << AC_PINCAP_VREF_SHIFT))
2932 control = STAC_CTL_WIDGET_DC_BIAS;
2933 else if (nid == spec->mic_switch)
2934 control = STAC_CTL_WIDGET_IO_SWITCH;
2935 }
2936
2937 if (control) {
2938 strcpy(name, auto_pin_cfg_labels[idx]);
2939 return stac92xx_add_control(codec->spec, control,
2940 strcat(name, " Jack Mode"), nid);
2941 }
2942
2943 return 0;
2944}
2945
Takashi Iwaie3c75962009-01-23 11:57:22 +01002946static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2947{
2948 struct snd_kcontrol_new *knew;
2949 struct hda_input_mux *imux = &spec->private_imux;
2950
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02002951 if (spec->auto_mic)
2952 return 0; /* no need for input source */
Takashi Iwaie3c75962009-01-23 11:57:22 +01002953 if (!spec->num_adcs || imux->num_items <= 1)
2954 return 0; /* no need for input source control */
2955 knew = stac_control_new(spec, &stac_input_src_temp,
2956 stac_input_src_temp.name);
2957 if (!knew)
2958 return -ENOMEM;
2959 knew->count = spec->num_adcs;
2960 return 0;
2961}
2962
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002963/* check whether the line-input can be used as line-out */
2964static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002965{
2966 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002967 struct auto_pin_cfg *cfg = &spec->autocfg;
2968 hda_nid_t nid;
2969 unsigned int pincap;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002970
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002971 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2972 return 0;
2973 nid = cfg->input_pins[AUTO_PIN_LINE];
Takashi Iwai1327a322009-03-23 13:07:47 +01002974 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002975 if (pincap & AC_PINCAP_OUT)
2976 return nid;
Matt Porter403d1942005-11-29 15:00:51 +01002977 return 0;
2978}
2979
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002980/* check whether the mic-input can be used as line-out */
2981static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2982{
2983 struct sigmatel_spec *spec = codec->spec;
2984 struct auto_pin_cfg *cfg = &spec->autocfg;
2985 unsigned int def_conf, pincap;
2986 unsigned int mic_pin;
2987
2988 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2989 return 0;
2990 mic_pin = AUTO_PIN_MIC;
2991 for (;;) {
2992 hda_nid_t nid = cfg->input_pins[mic_pin];
Takashi Iwai330ee992009-02-20 14:33:36 +01002993 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002994 /* some laptops have an internal analog microphone
2995 * which can't be used as a output */
2996 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai1327a322009-03-23 13:07:47 +01002997 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002998 if (pincap & AC_PINCAP_OUT)
2999 return nid;
3000 }
3001 if (mic_pin == AUTO_PIN_MIC)
3002 mic_pin = AUTO_PIN_FRONT_MIC;
3003 else
3004 break;
3005 }
3006 return 0;
3007}
Steve Longerbeam7b043892007-05-03 20:50:03 +02003008
3009static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3010{
3011 int i;
3012
3013 for (i = 0; i < spec->multiout.num_dacs; i++) {
3014 if (spec->multiout.dac_nids[i] == nid)
3015 return 1;
3016 }
3017
3018 return 0;
3019}
3020
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003021static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
3022{
3023 int i;
3024 if (is_in_dac_nids(spec, nid))
3025 return 1;
3026 for (i = 0; i < spec->autocfg.hp_outs; i++)
3027 if (spec->hp_dacs[i] == nid)
3028 return 1;
3029 for (i = 0; i < spec->autocfg.speaker_outs; i++)
3030 if (spec->speaker_dacs[i] == nid)
3031 return 1;
3032 return 0;
3033}
3034
3035static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
3036{
3037 struct sigmatel_spec *spec = codec->spec;
3038 int j, conn_len;
3039 hda_nid_t conn[HDA_MAX_CONNECTIONS];
3040 unsigned int wcaps, wtype;
3041
3042 conn_len = snd_hda_get_connections(codec, nid, conn,
3043 HDA_MAX_CONNECTIONS);
3044 for (j = 0; j < conn_len; j++) {
Takashi Iwai14bafe32009-03-23 16:35:39 +01003045 wcaps = get_wcaps(codec, conn[j]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003046 wtype = get_wcaps_type(wcaps);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003047 /* we check only analog outputs */
3048 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
3049 continue;
3050 /* if this route has a free DAC, assign it */
3051 if (!check_all_dac_nids(spec, conn[j])) {
3052 if (conn_len > 1) {
3053 /* select this DAC in the pin's input mux */
3054 snd_hda_codec_write_cache(codec, nid, 0,
3055 AC_VERB_SET_CONNECT_SEL, j);
3056 }
3057 return conn[j];
3058 }
3059 }
Takashi Iwaiee58a7c2009-03-06 12:00:24 +01003060 /* if all DACs are already assigned, connect to the primary DAC */
3061 if (conn_len > 1) {
3062 for (j = 0; j < conn_len; j++) {
3063 if (conn[j] == spec->multiout.dac_nids[0]) {
3064 snd_hda_codec_write_cache(codec, nid, 0,
3065 AC_VERB_SET_CONNECT_SEL, j);
3066 break;
3067 }
3068 }
3069 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003070 return 0;
3071}
3072
3073static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3074static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
3075
Matt Porter3cc08dc2006-01-23 15:27:49 +01003076/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02003077 * Fill in the dac_nids table from the parsed pin configuration
3078 * This function only works when every pin in line_out_pins[]
3079 * contains atleast one DAC in its connection list. Some 92xx
3080 * codecs are not connected directly to a DAC, such as the 9200
3081 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01003082 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003083static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02003084{
3085 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003086 struct auto_pin_cfg *cfg = &spec->autocfg;
3087 int i;
3088 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02003089
Mattc7d4b2f2005-06-27 14:59:41 +02003090 for (i = 0; i < cfg->line_outs; i++) {
3091 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003092 dac = get_unassigned_dac(codec, nid);
3093 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02003094 if (spec->multiout.num_dacs > 0) {
3095 /* we have already working output pins,
3096 * so let's drop the broken ones again
3097 */
3098 cfg->line_outs = spec->multiout.num_dacs;
3099 break;
3100 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003101 /* error out, no available DAC found */
3102 snd_printk(KERN_ERR
3103 "%s: No available DAC for pin 0x%x\n",
3104 __func__, nid);
3105 return -ENODEV;
3106 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003107 add_spec_dacs(spec, dac);
3108 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02003109
Takashi Iwai139e0712009-03-06 12:10:41 +01003110 for (i = 0; i < cfg->hp_outs; i++) {
3111 nid = cfg->hp_pins[i];
3112 dac = get_unassigned_dac(codec, nid);
3113 if (dac) {
3114 if (!spec->multiout.hp_nid)
3115 spec->multiout.hp_nid = dac;
3116 else
3117 add_spec_extra_dacs(spec, dac);
3118 }
3119 spec->hp_dacs[i] = dac;
3120 }
3121
3122 for (i = 0; i < cfg->speaker_outs; i++) {
3123 nid = cfg->speaker_pins[i];
3124 dac = get_unassigned_dac(codec, nid);
3125 if (dac)
3126 add_spec_extra_dacs(spec, dac);
3127 spec->speaker_dacs[i] = dac;
3128 }
3129
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003130 /* add line-in as output */
3131 nid = check_line_out_switch(codec);
3132 if (nid) {
3133 dac = get_unassigned_dac(codec, nid);
3134 if (dac) {
3135 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
3136 nid, cfg->line_outs);
3137 cfg->line_out_pins[cfg->line_outs] = nid;
3138 cfg->line_outs++;
3139 spec->line_switch = nid;
3140 add_spec_dacs(spec, dac);
3141 }
3142 }
3143 /* add mic as output */
3144 nid = check_mic_out_switch(codec);
3145 if (nid) {
3146 dac = get_unassigned_dac(codec, nid);
3147 if (dac) {
3148 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
3149 nid, cfg->line_outs);
3150 cfg->line_out_pins[cfg->line_outs] = nid;
3151 cfg->line_outs++;
3152 spec->mic_switch = nid;
3153 add_spec_dacs(spec, dac);
Steve Longerbeam7b043892007-05-03 20:50:03 +02003154 }
Mattc7d4b2f2005-06-27 14:59:41 +02003155 }
3156
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003157 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02003158 spec->multiout.num_dacs,
3159 spec->multiout.dac_nids[0],
3160 spec->multiout.dac_nids[1],
3161 spec->multiout.dac_nids[2],
3162 spec->multiout.dac_nids[3],
3163 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003164
Mattc7d4b2f2005-06-27 14:59:41 +02003165 return 0;
3166}
3167
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003168/* create volume control/switch for the given prefx type */
Takashi Iwai668b9652009-03-06 10:13:24 +01003169static int create_controls_idx(struct hda_codec *codec, const char *pfx,
3170 int idx, hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003171{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003172 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003173 char name[32];
3174 int err;
3175
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003176 if (!spec->check_volume_offset) {
3177 unsigned int caps, step, nums, db_scale;
3178 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3179 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3180 AC_AMPCAP_STEP_SIZE_SHIFT;
3181 step = (step + 1) * 25; /* in .01dB unit */
3182 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3183 AC_AMPCAP_NUM_STEPS_SHIFT;
3184 db_scale = nums * step;
3185 /* if dB scale is over -64dB, and finer enough,
3186 * let's reduce it to half
3187 */
3188 if (db_scale > 6400 && nums >= 0x1f)
3189 spec->volume_offset = nums / 2;
3190 spec->check_volume_offset = 1;
3191 }
3192
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003193 sprintf(name, "%s Playback Volume", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003194 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003195 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3196 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003197 if (err < 0)
3198 return err;
3199 sprintf(name, "%s Playback Switch", pfx);
Takashi Iwai668b9652009-03-06 10:13:24 +01003200 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003201 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3202 if (err < 0)
3203 return err;
3204 return 0;
3205}
3206
Takashi Iwai668b9652009-03-06 10:13:24 +01003207#define create_controls(codec, pfx, nid, chs) \
3208 create_controls_idx(codec, pfx, 0, nid, chs)
3209
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003210static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3211{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003212 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003213 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3214 return 1;
3215 } else {
3216 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3217 spec->multiout.num_dacs++;
3218 }
3219 return 0;
3220}
3221
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003222static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003223{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003224 int i;
3225 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3226 if (!spec->multiout.extra_out_nid[i]) {
3227 spec->multiout.extra_out_nid[i] = nid;
3228 return 0;
3229 }
3230 }
3231 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3232 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003233}
3234
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003235/* Create output controls
3236 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3237 */
3238static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3239 const hda_nid_t *pins,
3240 const hda_nid_t *dac_nids,
3241 int type)
Mattc7d4b2f2005-06-27 14:59:41 +02003242{
Takashi Iwai76624532008-12-19 10:09:47 +01003243 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003244 static const char *chname[4] = {
3245 "Front", "Surround", NULL /*CLFE*/, "Side"
3246 };
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003247 hda_nid_t nid;
Takashi Iwai91589232008-12-19 15:59:40 +01003248 int i, err;
3249 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003250
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003251 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
Takashi Iwaiffd0e562009-04-16 12:20:24 +02003252 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3253 wid_caps = get_wcaps(codec, pins[i]);
3254 if (wid_caps & AC_WCAP_UNSOL_CAP)
3255 spec->hp_detect = 1;
3256 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003257 nid = dac_nids[i];
3258 if (!nid)
3259 continue;
3260 if (type != AUTO_PIN_HP_OUT && i == 2) {
Mattc7d4b2f2005-06-27 14:59:41 +02003261 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003262 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003263 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003264 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003265 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003266 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003267 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003268
3269 wid_caps = get_wcaps(codec, nid);
3270
3271 if (wid_caps & AC_WCAP_LR_SWAP) {
3272 err = stac92xx_add_control(spec,
3273 STAC_CTL_WIDGET_CLFE_SWITCH,
3274 "Swap Center/LFE Playback Switch", nid);
3275
3276 if (err < 0)
3277 return err;
3278 }
3279
Mattc7d4b2f2005-06-27 14:59:41 +02003280 } else {
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003281 const char *name;
Takashi Iwai668b9652009-03-06 10:13:24 +01003282 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003283 switch (type) {
3284 case AUTO_PIN_HP_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003285 name = "Headphone";
3286 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003287 break;
3288 case AUTO_PIN_SPEAKER_OUT:
Takashi Iwai668b9652009-03-06 10:13:24 +01003289 name = "Speaker";
3290 idx = i;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003291 break;
3292 default:
3293 name = chname[i];
Takashi Iwai668b9652009-03-06 10:13:24 +01003294 idx = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003295 break;
Takashi Iwai76624532008-12-19 10:09:47 +01003296 }
Takashi Iwai668b9652009-03-06 10:13:24 +01003297 err = create_controls_idx(codec, name, idx, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003298 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003299 return err;
3300 }
3301 }
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003302 return 0;
3303}
3304
Takashi Iwai6479c632009-07-28 18:20:25 +02003305static int stac92xx_add_capvol_ctls(struct hda_codec *codec, unsigned long vol,
3306 unsigned long sw, int idx)
3307{
3308 int err;
3309 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_VOL, idx,
3310 "Captuer Volume", vol);
3311 if (err < 0)
3312 return err;
3313 err = stac92xx_add_control_idx(codec->spec, STAC_CTL_WIDGET_MUTE, idx,
3314 "Captuer Switch", sw);
3315 if (err < 0)
3316 return err;
3317 return 0;
3318}
3319
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003320/* add playback controls from the parsed DAC table */
3321static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3322 const struct auto_pin_cfg *cfg)
3323{
3324 struct sigmatel_spec *spec = codec->spec;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003325 hda_nid_t nid;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003326 int err;
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003327 int idx;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003328
3329 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3330 spec->multiout.dac_nids,
3331 cfg->line_out_type);
3332 if (err < 0)
3333 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003334
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003335 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003336 err = stac92xx_add_control(spec,
3337 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003338 "Headphone as Line Out Switch",
3339 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003340 if (err < 0)
3341 return err;
3342 }
3343
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02003344 for (idx = AUTO_PIN_MIC; idx <= AUTO_PIN_FRONT_LINE; idx++) {
3345 nid = cfg->input_pins[idx];
3346 if (nid) {
3347 err = stac92xx_add_jack_mode_control(codec, nid, idx);
3348 if (err < 0)
3349 return err;
3350 }
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003351 }
Matt Porter403d1942005-11-29 15:00:51 +01003352
Mattc7d4b2f2005-06-27 14:59:41 +02003353 return 0;
3354}
3355
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003356/* add playback controls for Speaker and HP outputs */
3357static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3358 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003359{
3360 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003361 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02003362
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003363 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3364 spec->hp_dacs, AUTO_PIN_HP_OUT);
3365 if (err < 0)
3366 return err;
3367
3368 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3369 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3370 if (err < 0)
3371 return err;
3372
Mattc7d4b2f2005-06-27 14:59:41 +02003373 return 0;
3374}
3375
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003376/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003377static const char *stac92xx_mono_labels[4] = {
3378 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003379};
3380
3381/* create mono mux for mono out on capable codecs */
3382static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3383{
3384 struct sigmatel_spec *spec = codec->spec;
3385 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3386 int i, num_cons;
3387 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3388
3389 num_cons = snd_hda_get_connections(codec,
3390 spec->mono_nid,
3391 con_lst,
3392 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003393 if (num_cons <= 0 || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003394 return -EINVAL;
3395
3396 for (i = 0; i < num_cons; i++) {
3397 mono_mux->items[mono_mux->num_items].label =
3398 stac92xx_mono_labels[i];
3399 mono_mux->items[mono_mux->num_items].index = i;
3400 mono_mux->num_items++;
3401 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003402
3403 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3404 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003405}
3406
Matthew Ranostay89385032008-09-11 09:49:39 -04003407/* labels for amp mux outputs */
3408static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003409 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003410};
3411
3412/* create amp out controls mux on capable codecs */
3413static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3414{
3415 struct sigmatel_spec *spec = codec->spec;
3416 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3417 int i, err;
3418
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003419 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003420 amp_mux->items[amp_mux->num_items].label =
3421 stac92xx_amp_labels[i];
3422 amp_mux->items[amp_mux->num_items].index = i;
3423 amp_mux->num_items++;
3424 }
3425
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003426 if (spec->num_amps > 1) {
3427 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3428 "Amp Selector Capture Switch", 0);
3429 if (err < 0)
3430 return err;
3431 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003432 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3433 "Amp Capture Volume",
3434 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3435}
3436
3437
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003438/* create PC beep volume controls */
3439static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3440 hda_nid_t nid)
3441{
3442 struct sigmatel_spec *spec = codec->spec;
3443 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3444 int err;
3445
3446 /* check for mute support for the the amp */
3447 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3448 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3449 "PC Beep Playback Switch",
3450 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3451 if (err < 0)
3452 return err;
3453 }
3454
3455 /* check to see if there is volume support for the amp */
3456 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3457 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3458 "PC Beep Playback Volume",
3459 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3460 if (err < 0)
3461 return err;
3462 }
3463 return 0;
3464}
3465
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003466#ifdef CONFIG_SND_HDA_INPUT_BEEP
3467#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3468
3469static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3470 struct snd_ctl_elem_value *ucontrol)
3471{
3472 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3473 ucontrol->value.integer.value[0] = codec->beep->enabled;
3474 return 0;
3475}
3476
3477static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3478 struct snd_ctl_elem_value *ucontrol)
3479{
3480 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3481 int enabled = !!ucontrol->value.integer.value[0];
3482 if (codec->beep->enabled != enabled) {
3483 codec->beep->enabled = enabled;
3484 return 1;
3485 }
3486 return 0;
3487}
3488
3489static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3490 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3491 .info = stac92xx_dig_beep_switch_info,
3492 .get = stac92xx_dig_beep_switch_get,
3493 .put = stac92xx_dig_beep_switch_put,
3494};
3495
3496static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3497{
3498 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3499 0, "PC Beep Playback Switch", 0);
3500}
3501#endif
3502
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003503static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3504{
3505 struct sigmatel_spec *spec = codec->spec;
3506 int wcaps, nid, i, err = 0;
3507
3508 for (i = 0; i < spec->num_muxes; i++) {
3509 nid = spec->mux_nids[i];
3510 wcaps = get_wcaps(codec, nid);
3511
3512 if (wcaps & AC_WCAP_OUT_AMP) {
3513 err = stac92xx_add_control_idx(spec,
3514 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3515 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3516 if (err < 0)
3517 return err;
3518 }
3519 }
3520 return 0;
3521};
3522
Matthew Ranostayd9737752008-09-07 12:03:41 +02003523static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003524 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003525};
3526
3527static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3528{
3529 struct sigmatel_spec *spec = codec->spec;
3530 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003531 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003532 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003533 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003534
3535 num_cons = snd_hda_get_connections(codec,
3536 spec->smux_nids[0],
3537 con_lst,
3538 HDA_MAX_NUM_INPUTS);
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003539 if (num_cons <= 0)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003540 return -EINVAL;
3541
Matthew Ranostay65973632008-09-16 10:39:37 -04003542 if (!labels)
3543 labels = stac92xx_spdif_labels;
3544
Matthew Ranostayd9737752008-09-07 12:03:41 +02003545 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003546 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003547 spdif_mux->items[spdif_mux->num_items].index = i;
3548 spdif_mux->num_items++;
3549 }
3550
3551 return 0;
3552}
3553
Matt Porter8b657272006-10-26 17:12:59 +02003554/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003555static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003556 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3557 "Digital Mic 3", "Digital Mic 4"
3558};
3559
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003560static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3561 hda_nid_t nid)
3562{
3563 hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3564 int i, nums;
3565
3566 nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3567 for (i = 0; i < nums; i++)
3568 if (conn[i] == nid)
3569 return i;
3570 return -1;
3571}
3572
Matt Porter8b657272006-10-26 17:12:59 +02003573/* create playback/capture controls for input pins on dmic capable codecs */
3574static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3575 const struct auto_pin_cfg *cfg)
3576{
3577 struct sigmatel_spec *spec = codec->spec;
3578 struct hda_input_mux *dimux = &spec->private_dimux;
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003579 int err, i;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003580 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02003581
3582 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3583 dimux->items[dimux->num_items].index = 0;
3584 dimux->num_items++;
3585
3586 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003587 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003588 int index;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003589 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02003590 unsigned int def_conf;
3591
Takashi Iwai330ee992009-02-20 14:33:36 +01003592 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
Matt Porter8b657272006-10-26 17:12:59 +02003593 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3594 continue;
3595
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003596 nid = spec->dmic_nids[i];
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003597 index = get_connection_index(codec, spec->dmux_nids[0], nid);
3598 if (index < 0)
3599 continue;
3600
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003601 wcaps = get_wcaps(codec, nid) &
3602 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003603
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003604 if (wcaps) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003605 sprintf(name, "%s Capture Volume",
3606 stac92xx_dmic_labels[dimux->num_items]);
3607
3608 err = stac92xx_add_control(spec,
3609 STAC_CTL_WIDGET_VOL,
3610 name,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003611 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3612 (wcaps & AC_WCAP_OUT_AMP) ?
3613 HDA_OUTPUT : HDA_INPUT));
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003614 if (err < 0)
3615 return err;
3616 }
3617
Matt Porter8b657272006-10-26 17:12:59 +02003618 dimux->items[dimux->num_items].label =
3619 stac92xx_dmic_labels[dimux->num_items];
3620 dimux->items[dimux->num_items].index = index;
3621 dimux->num_items++;
3622 }
3623
3624 return 0;
3625}
3626
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003627static int check_mic_pin(struct hda_codec *codec, hda_nid_t nid,
3628 hda_nid_t *fixed, hda_nid_t *ext)
3629{
3630 unsigned int cfg;
3631
3632 if (!nid)
3633 return 0;
3634 cfg = snd_hda_codec_get_pincfg(codec, nid);
3635 switch (get_defcfg_connect(cfg)) {
3636 case AC_JACK_PORT_FIXED:
3637 if (*fixed)
3638 return 1; /* already occupied */
3639 *fixed = nid;
3640 break;
3641 case AC_JACK_PORT_COMPLEX:
3642 if (*ext)
3643 return 1; /* already occupied */
3644 *ext = nid;
3645 break;
3646 }
3647 return 0;
3648}
3649
3650static int set_mic_route(struct hda_codec *codec,
3651 struct sigmatel_mic_route *mic,
3652 hda_nid_t pin)
3653{
3654 struct sigmatel_spec *spec = codec->spec;
3655 struct auto_pin_cfg *cfg = &spec->autocfg;
3656 int i;
3657
3658 mic->pin = pin;
3659 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3660 if (pin == cfg->input_pins[i])
3661 break;
3662 if (i <= AUTO_PIN_FRONT_MIC) {
3663 /* analog pin */
3664 mic->dmux_idx = 0;
3665 i = get_connection_index(codec, spec->mux_nids[0], pin);
3666 if (i < 0)
3667 return -1;
3668 mic->mux_idx = i;
3669 } else {
3670 /* digital pin */
3671 mic->mux_idx = 0;
3672 i = get_connection_index(codec, spec->dmux_nids[0], pin);
3673 if (i < 0)
3674 return -1;
3675 mic->dmux_idx = i;
3676 }
3677 return 0;
3678}
3679
3680/* return non-zero if the device is for automatic mic switch */
3681static int stac_check_auto_mic(struct hda_codec *codec)
3682{
3683 struct sigmatel_spec *spec = codec->spec;
3684 struct auto_pin_cfg *cfg = &spec->autocfg;
3685 hda_nid_t fixed, ext;
3686 int i;
3687
3688 for (i = AUTO_PIN_LINE; i < AUTO_PIN_LAST; i++) {
3689 if (cfg->input_pins[i])
3690 return 0; /* must be exclusively mics */
3691 }
3692 fixed = ext = 0;
3693 for (i = AUTO_PIN_MIC; i <= AUTO_PIN_FRONT_MIC; i++)
3694 if (check_mic_pin(codec, cfg->input_pins[i], &fixed, &ext))
3695 return 0;
3696 for (i = 0; i < spec->num_dmics; i++)
3697 if (check_mic_pin(codec, spec->dmic_nids[i], &fixed, &ext))
3698 return 0;
3699 if (!fixed || !ext)
3700 return 0;
3701 if (!(get_wcaps(codec, ext) & AC_WCAP_UNSOL_CAP))
3702 return 0; /* no unsol support */
3703 if (set_mic_route(codec, &spec->ext_mic, ext) ||
3704 set_mic_route(codec, &spec->int_mic, fixed))
3705 return 0; /* something is wrong */
3706 return 1;
3707}
3708
Mattc7d4b2f2005-06-27 14:59:41 +02003709/* create playback/capture controls for input pins */
3710static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3711{
3712 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003713 struct hda_input_mux *imux = &spec->private_imux;
3714 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3715 int i, j, k;
3716
3717 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003718 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02003719
Takashi Iwai314634b2006-09-21 11:56:18 +02003720 if (!cfg->input_pins[i])
3721 continue;
3722 index = -1;
3723 for (j = 0; j < spec->num_muxes; j++) {
3724 int num_cons;
3725 num_cons = snd_hda_get_connections(codec,
3726 spec->mux_nids[j],
3727 con_lst,
3728 HDA_MAX_NUM_INPUTS);
3729 for (k = 0; k < num_cons; k++)
3730 if (con_lst[k] == cfg->input_pins[i]) {
3731 index = k;
3732 goto found;
3733 }
Mattc7d4b2f2005-06-27 14:59:41 +02003734 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003735 continue;
3736 found:
3737 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3738 imux->items[imux->num_items].index = index;
3739 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003740 }
3741
Steve Longerbeam7b043892007-05-03 20:50:03 +02003742 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003743 /*
3744 * Set the current input for the muxes.
3745 * The STAC9221 has two input muxes with identical source
3746 * NID lists. Hopefully this won't get confused.
3747 */
3748 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003749 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3750 AC_VERB_SET_CONNECT_SEL,
3751 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003752 }
3753 }
3754
Mattc7d4b2f2005-06-27 14:59:41 +02003755 return 0;
3756}
3757
Mattc7d4b2f2005-06-27 14:59:41 +02003758static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3759{
3760 struct sigmatel_spec *spec = codec->spec;
3761 int i;
3762
3763 for (i = 0; i < spec->autocfg.line_outs; i++) {
3764 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3765 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3766 }
3767}
3768
3769static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3770{
3771 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003772 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003773
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003774 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3775 hda_nid_t pin;
3776 pin = spec->autocfg.hp_pins[i];
3777 if (pin) /* connect to front */
3778 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3779 }
3780 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3781 hda_nid_t pin;
3782 pin = spec->autocfg.speaker_pins[i];
3783 if (pin) /* connect to front */
3784 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3785 }
Mattc7d4b2f2005-06-27 14:59:41 +02003786}
3787
Matt Porter3cc08dc2006-01-23 15:27:49 +01003788static 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 +02003789{
3790 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003791 int hp_swap = 0;
Takashi Iwai6479c632009-07-28 18:20:25 +02003792 int i, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003793
Matt Porter8b657272006-10-26 17:12:59 +02003794 if ((err = snd_hda_parse_pin_def_config(codec,
3795 &spec->autocfg,
3796 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003797 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003798 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003799 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003800
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003801 /* If we have no real line-out pin and multiple hp-outs, HPs should
3802 * be set up as multi-channel outputs.
3803 */
3804 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3805 spec->autocfg.hp_outs > 1) {
3806 /* Copy hp_outs to line_outs, backup line_outs in
3807 * speaker_outs so that the following routines can handle
3808 * HP pins as primary outputs.
3809 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003810 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003811 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3812 sizeof(spec->autocfg.line_out_pins));
3813 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3814 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3815 sizeof(spec->autocfg.hp_pins));
3816 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003817 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3818 spec->autocfg.hp_outs = 0;
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003819 hp_swap = 1;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003820 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003821 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003822 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3823 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003824 u32 caps = query_amp_caps(codec,
3825 spec->autocfg.mono_out_pin, dir);
3826 hda_nid_t conn_list[1];
3827
3828 /* get the mixer node and then the mono mux if it exists */
3829 if (snd_hda_get_connections(codec,
3830 spec->autocfg.mono_out_pin, conn_list, 1) &&
3831 snd_hda_get_connections(codec, conn_list[0],
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02003832 conn_list, 1) > 0) {
Matthew Ranostay09a99952008-01-24 11:49:21 +01003833
3834 int wcaps = get_wcaps(codec, conn_list[0]);
Takashi Iwaia22d5432009-07-27 12:54:26 +02003835 int wid_type = get_wcaps_type(wcaps);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003836 /* LR swap check, some stac925x have a mux that
3837 * changes the DACs output path instead of the
3838 * mono-mux path.
3839 */
3840 if (wid_type == AC_WID_AUD_SEL &&
3841 !(wcaps & AC_WCAP_LR_SWAP))
3842 spec->mono_nid = conn_list[0];
3843 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003844 if (dir) {
3845 hda_nid_t nid = spec->autocfg.mono_out_pin;
3846
3847 /* most mono outs have a least a mute/unmute switch */
3848 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3849 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3850 "Mono Playback Switch",
3851 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003852 if (err < 0)
3853 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003854 /* check for volume support for the amp */
3855 if ((caps & AC_AMPCAP_NUM_STEPS)
3856 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3857 err = stac92xx_add_control(spec,
3858 STAC_CTL_WIDGET_VOL,
3859 "Mono Playback Volume",
3860 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3861 if (err < 0)
3862 return err;
3863 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003864 }
3865
3866 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3867 AC_PINCTL_OUT_EN);
3868 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003869
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003870 if (!spec->multiout.num_dacs) {
3871 err = stac92xx_auto_fill_dac_nids(codec);
3872 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003873 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003874 err = stac92xx_auto_create_multi_out_ctls(codec,
3875 &spec->autocfg);
3876 if (err < 0)
3877 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003878 }
Mattc7d4b2f2005-06-27 14:59:41 +02003879
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003880 /* setup analog beep controls */
3881 if (spec->anabeep_nid > 0) {
3882 err = stac92xx_auto_create_beep_ctls(codec,
3883 spec->anabeep_nid);
3884 if (err < 0)
3885 return err;
3886 }
3887
3888 /* setup digital beep controls and input device */
3889#ifdef CONFIG_SND_HDA_INPUT_BEEP
3890 if (spec->digbeep_nid > 0) {
3891 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003892 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003893
3894 err = stac92xx_auto_create_beep_ctls(codec, nid);
3895 if (err < 0)
3896 return err;
3897 err = snd_hda_attach_beep_device(codec, nid);
3898 if (err < 0)
3899 return err;
Takashi Iwaifa797962009-05-19 12:50:04 +02003900 /* IDT/STAC codecs have linear beep tone parameter */
3901 codec->beep->linear_tone = 1;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003902 /* if no beep switch is available, make its own one */
3903 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3904 if (codec->beep &&
3905 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3906 err = stac92xx_beep_switch_ctl(codec);
3907 if (err < 0)
3908 return err;
3909 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003910 }
3911#endif
3912
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003913 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003914 if (err < 0)
3915 return err;
3916
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003917 /* All output parsing done, now restore the swapped hp pins */
3918 if (hp_swap) {
3919 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3920 sizeof(spec->autocfg.hp_pins));
3921 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3922 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3923 spec->autocfg.line_outs = 0;
3924 }
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003925
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02003926 if (stac_check_auto_mic(codec)) {
3927 spec->auto_mic = 1;
3928 /* only one capture for auto-mic */
3929 spec->num_adcs = 1;
3930 spec->num_caps = 1;
3931 spec->num_muxes = 1;
3932 }
3933
Takashi Iwai6479c632009-07-28 18:20:25 +02003934 for (i = 0; i < spec->num_caps; i++) {
3935 err = stac92xx_add_capvol_ctls(codec, spec->capvols[i],
3936 spec->capsws[i], i);
3937 if (err < 0)
3938 return err;
3939 }
3940
Takashi Iwaidc04d1b2009-03-06 10:00:05 +01003941 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003942 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003943 return err;
3944
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003945 if (spec->mono_nid > 0) {
3946 err = stac92xx_auto_create_mono_output_ctls(codec);
3947 if (err < 0)
3948 return err;
3949 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003950 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003951 err = stac92xx_auto_create_amp_output_ctls(codec);
3952 if (err < 0)
3953 return err;
3954 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003955 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003956 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3957 &spec->autocfg)) < 0)
3958 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003959 if (spec->num_muxes > 0) {
3960 err = stac92xx_auto_create_mux_input_ctls(codec);
3961 if (err < 0)
3962 return err;
3963 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003964 if (spec->num_smuxes > 0) {
3965 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3966 if (err < 0)
3967 return err;
3968 }
Matt Porter8b657272006-10-26 17:12:59 +02003969
Takashi Iwaie3c75962009-01-23 11:57:22 +01003970 err = stac92xx_add_input_source(spec);
3971 if (err < 0)
3972 return err;
3973
Mattc7d4b2f2005-06-27 14:59:41 +02003974 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003975 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003976 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003977
Takashi Iwai0852d7a2009-02-11 11:35:15 +01003978 if (spec->autocfg.dig_outs)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003979 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003980 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003981 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003982
Takashi Iwai603c4012008-07-30 15:01:44 +02003983 if (spec->kctls.list)
3984 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003985
3986 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003987 if (!spec->dinput_mux)
3988 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003989 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003990 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04003991 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003992 return 1;
3993}
3994
Takashi Iwai82bc9552006-03-21 11:24:42 +01003995/* add playback controls for HP output */
3996static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3997 struct auto_pin_cfg *cfg)
3998{
3999 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004000 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01004001 unsigned int wid_caps;
4002
4003 if (! pin)
4004 return 0;
4005
4006 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02004007 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01004008 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004009
4010 return 0;
4011}
4012
Richard Fish160ea0d2006-09-06 13:58:25 +02004013/* add playback controls for LFE output */
4014static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
4015 struct auto_pin_cfg *cfg)
4016{
4017 struct sigmatel_spec *spec = codec->spec;
4018 int err;
4019 hda_nid_t lfe_pin = 0x0;
4020 int i;
4021
4022 /*
4023 * search speaker outs and line outs for a mono speaker pin
4024 * with an amp. If one is found, add LFE controls
4025 * for it.
4026 */
4027 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
4028 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004029 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004030 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4031 if (wcaps == AC_WCAP_OUT_AMP)
4032 /* found a mono speaker with an amp, must be lfe */
4033 lfe_pin = pin;
4034 }
4035
4036 /* if speaker_outs is 0, then speakers may be in line_outs */
4037 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
4038 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
4039 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004040 unsigned int defcfg;
Takashi Iwai330ee992009-02-20 14:33:36 +01004041 defcfg = snd_hda_codec_get_pincfg(codec, pin);
Harvey Harrison8b551782008-02-29 11:56:48 +01004042 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01004043 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02004044 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
4045 if (wcaps == AC_WCAP_OUT_AMP)
4046 /* found a mono speaker with an amp,
4047 must be lfe */
4048 lfe_pin = pin;
4049 }
4050 }
4051 }
4052
4053 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01004054 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02004055 if (err < 0)
4056 return err;
4057 }
4058
4059 return 0;
4060}
4061
Mattc7d4b2f2005-06-27 14:59:41 +02004062static int stac9200_parse_auto_config(struct hda_codec *codec)
4063{
4064 struct sigmatel_spec *spec = codec->spec;
4065 int err;
4066
Kailang Yangdf694da2005-12-05 19:42:22 +01004067 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02004068 return err;
4069
4070 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
4071 return err;
4072
Takashi Iwai82bc9552006-03-21 11:24:42 +01004073 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
4074 return err;
4075
Richard Fish160ea0d2006-09-06 13:58:25 +02004076 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
4077 return err;
4078
Takashi Iwai355a0ec2008-11-11 16:46:19 +01004079 if (spec->num_muxes > 0) {
4080 err = stac92xx_auto_create_mux_input_ctls(codec);
4081 if (err < 0)
4082 return err;
4083 }
4084
Takashi Iwaie3c75962009-01-23 11:57:22 +01004085 err = stac92xx_add_input_source(spec);
4086 if (err < 0)
4087 return err;
4088
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004089 if (spec->autocfg.dig_outs)
Mattc7d4b2f2005-06-27 14:59:41 +02004090 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004091 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02004092 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02004093
Takashi Iwai603c4012008-07-30 15:01:44 +02004094 if (spec->kctls.list)
4095 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02004096
4097 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02004098 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02004099
4100 return 1;
4101}
4102
Sam Revitch62fe78e2006-05-10 15:09:17 +02004103/*
4104 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
4105 * funky external mute control using GPIO pins.
4106 */
4107
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004108static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004109 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02004110{
4111 unsigned int gpiostate, gpiomask, gpiodir;
4112
4113 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4114 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004115 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02004116
4117 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4118 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004119 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004120
4121 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4122 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004123 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02004124
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004125 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004126 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
4127
4128 snd_hda_codec_write(codec, codec->afg, 0,
4129 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004130 snd_hda_codec_read(codec, codec->afg, 0,
4131 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004132
4133 msleep(1);
4134
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01004135 snd_hda_codec_read(codec, codec->afg, 0,
4136 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004137}
4138
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004139#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwai95c09092009-04-14 16:15:29 +02004140static void stac92xx_free_jack_priv(struct snd_jack *jack)
4141{
4142 struct sigmatel_jack *jacks = jack->private_data;
4143 jacks->nid = 0;
4144 jacks->jack = NULL;
4145}
4146#endif
4147
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004148static int stac92xx_add_jack(struct hda_codec *codec,
4149 hda_nid_t nid, int type)
4150{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004151#ifdef CONFIG_SND_HDA_INPUT_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004152 struct sigmatel_spec *spec = codec->spec;
4153 struct sigmatel_jack *jack;
Takashi Iwai330ee992009-02-20 14:33:36 +01004154 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004155 int connectivity = get_defcfg_connect(def_conf);
4156 char name[32];
Takashi Iwai95c09092009-04-14 16:15:29 +02004157 int err;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004158
4159 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4160 return 0;
4161
4162 snd_array_init(&spec->jacks, sizeof(*jack), 32);
4163 jack = snd_array_new(&spec->jacks);
4164 if (!jack)
4165 return -ENOMEM;
4166 jack->nid = nid;
4167 jack->type = type;
4168
Takashi Iwai86de7412009-07-22 16:02:46 +02004169 snprintf(name, sizeof(name), "%s at %s %s Jack",
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004170 snd_hda_get_jack_type(def_conf),
4171 snd_hda_get_jack_connectivity(def_conf),
4172 snd_hda_get_jack_location(def_conf));
4173
Takashi Iwai95c09092009-04-14 16:15:29 +02004174 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
4175 if (err < 0) {
4176 jack->nid = 0;
4177 return err;
4178 }
4179 jack->jack->private_data = jack;
4180 jack->jack->private_free = stac92xx_free_jack_priv;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004181#endif
Takashi Iwai95c09092009-04-14 16:15:29 +02004182 return 0;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004183}
4184
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004185static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
4186 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004187{
4188 struct sigmatel_event *event;
4189
4190 snd_array_init(&spec->events, sizeof(*event), 32);
4191 event = snd_array_new(&spec->events);
4192 if (!event)
4193 return -ENOMEM;
4194 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004195 event->type = type;
4196 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004197 event->data = data;
4198
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004199 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004200}
4201
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004202static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
Takashi Iwai62558ce2009-07-29 14:23:09 +02004203 hda_nid_t nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004204{
4205 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004206 struct sigmatel_event *event = spec->events.list;
4207 int i;
4208
4209 for (i = 0; i < spec->events.used; i++, event++) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004210 if (event->nid == nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004211 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004212 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004213 return NULL;
4214}
4215
4216static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4217 unsigned char tag)
4218{
4219 struct sigmatel_spec *spec = codec->spec;
4220 struct sigmatel_event *event = spec->events.list;
4221 int i;
4222
4223 for (i = 0; i < spec->events.used; i++, event++) {
4224 if (event->tag == tag)
4225 return event;
4226 }
4227 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004228}
4229
Takashi Iwai62558ce2009-07-29 14:23:09 +02004230/* check if given nid is a valid pin and no other events are assigned
4231 * to it. If OK, assign the event, set the unsol flag, and returns 1.
4232 * Otherwise, returns zero.
4233 */
4234static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4235 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02004236{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004237 struct sigmatel_event *event;
4238 int tag;
4239
4240 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
Takashi Iwai62558ce2009-07-29 14:23:09 +02004241 return 0;
4242 event = stac_get_event(codec, nid);
4243 if (event) {
4244 if (event->type != type)
4245 return 0;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004246 tag = event->tag;
Takashi Iwai62558ce2009-07-29 14:23:09 +02004247 } else {
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004248 tag = stac_add_event(codec->spec, nid, type, 0);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004249 if (tag < 0)
4250 return 0;
4251 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004252 snd_hda_codec_write_cache(codec, nid, 0,
4253 AC_VERB_SET_UNSOLICITED_ENABLE,
4254 AC_USRSP_EN | tag);
Takashi Iwai62558ce2009-07-29 14:23:09 +02004255 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004256}
4257
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004258static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4259{
4260 int i;
4261 for (i = 0; i < cfg->hp_outs; i++)
4262 if (cfg->hp_pins[i] == nid)
4263 return 1; /* nid is a HP-Out */
4264
4265 return 0; /* nid is not a HP-Out */
4266};
4267
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004268static void stac92xx_power_down(struct hda_codec *codec)
4269{
4270 struct sigmatel_spec *spec = codec->spec;
4271
4272 /* power down inactive DACs */
4273 hda_nid_t *dac;
4274 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004275 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004276 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01004277 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
4278}
4279
Takashi Iwaif73d3582008-11-25 08:21:51 +01004280static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4281 int enable);
4282
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004283/* override some hints from the hwdep entry */
4284static void stac_store_hints(struct hda_codec *codec)
4285{
4286 struct sigmatel_spec *spec = codec->spec;
4287 const char *p;
4288 int val;
4289
4290 val = snd_hda_get_bool_hint(codec, "hp_detect");
4291 if (val >= 0)
4292 spec->hp_detect = val;
4293 p = snd_hda_get_hint(codec, "gpio_mask");
4294 if (p) {
4295 spec->gpio_mask = simple_strtoul(p, NULL, 0);
4296 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
4297 spec->gpio_mask;
4298 }
4299 p = snd_hda_get_hint(codec, "gpio_dir");
4300 if (p)
4301 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4302 p = snd_hda_get_hint(codec, "gpio_data");
4303 if (p)
4304 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4305 p = snd_hda_get_hint(codec, "eapd_mask");
4306 if (p)
4307 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4308 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4309 if (val >= 0)
4310 spec->eapd_switch = val;
4311}
4312
Mattc7d4b2f2005-06-27 14:59:41 +02004313static int stac92xx_init(struct hda_codec *codec)
4314{
4315 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004316 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004317 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01004318 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02004319
Mattc7d4b2f2005-06-27 14:59:41 +02004320 snd_hda_sequence_write(codec, spec->init);
4321
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004322 /* power down adcs initially */
4323 if (spec->powerdown_adcs)
4324 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004325 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004326 spec->adc_nids[i], 0,
4327 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004328
Takashi Iwai6565e4f2009-03-02 14:38:35 +01004329 /* override some hints */
4330 stac_store_hints(codec);
4331
Takashi Iwaif73d3582008-11-25 08:21:51 +01004332 /* set up GPIO */
4333 gpio = spec->gpio_data;
4334 /* turn on EAPD statically when spec->eapd_switch isn't set.
4335 * otherwise, unsol event will turn it on/off dynamically
4336 */
4337 if (!spec->eapd_switch)
4338 gpio |= spec->eapd_mask;
4339 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4340
Takashi Iwai82bc9552006-03-21 11:24:42 +01004341 /* set up pins */
4342 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004343 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004344 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004345 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004346 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004347 }
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004348 /* force to enable the first line-out; the others are set up
4349 * in unsol_event
4350 */
4351 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004352 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004353 /* fake event to set up pins */
Takashi Iwai62558ce2009-07-29 14:23:09 +02004354 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004355 } else {
4356 stac92xx_auto_init_multi_out(codec);
4357 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004358 for (i = 0; i < cfg->hp_outs; i++)
4359 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004360 }
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004361 if (spec->auto_mic) {
4362 if (enable_pin_detect(codec, spec->ext_mic.pin, STAC_MIC_EVENT))
4363 stac_issue_unsol_event(codec, spec->ext_mic.pin);
4364 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004365 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01004366 hda_nid_t nid = cfg->input_pins[i];
4367 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004368 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004369 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4370 /* for mic pins, force to initialize */
Nickolas Lloyd7c922de2009-06-01 11:12:29 +02004371 pinctl = stac92xx_get_default_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004372 pinctl |= AC_PINCTL_IN_EN;
4373 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004374 } else {
4375 pinctl = snd_hda_codec_read(codec, nid, 0,
4376 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4377 /* if PINCTL already set then skip */
Takashi Iwai5dd17cb2009-05-07 16:22:53 +02004378 /* Also, if both INPUT and OUTPUT are set,
4379 * it must be a BIOS bug; need to override, too
4380 */
4381 if (!(pinctl & AC_PINCTL_IN_EN) ||
4382 (pinctl & AC_PINCTL_OUT_EN)) {
4383 pinctl &= ~AC_PINCTL_OUT_EN;
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004384 pinctl |= AC_PINCTL_IN_EN;
4385 stac92xx_auto_set_pinctl(codec, nid,
4386 pinctl);
4387 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004388 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004389 conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004390 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
Takashi Iwai62558ce2009-07-29 14:23:09 +02004391 if (enable_pin_detect(codec, nid,
4392 STAC_INSERT_EVENT))
4393 stac_issue_unsol_event(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004394 }
Takashi Iwaic960a032006-03-23 17:06:28 +01004395 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004396 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004397 for (i = 0; i < spec->num_dmics; i++)
4398 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4399 AC_PINCTL_IN_EN);
Takashi Iwai0852d7a2009-02-11 11:35:15 +01004400 if (cfg->dig_out_pins[0])
4401 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
Takashi Iwai82bc9552006-03-21 11:24:42 +01004402 AC_PINCTL_OUT_EN);
4403 if (cfg->dig_in_pin)
4404 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4405 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004406 for (i = 0; i < spec->num_pwrs; i++) {
4407 hda_nid_t nid = spec->pwr_nids[i];
4408 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004409
Takashi Iwaieb632122008-12-19 16:39:48 +01004410 /* power on when no jack detection is available */
4411 if (!spec->hp_detect) {
4412 stac_toggle_power_map(codec, nid, 1);
4413 continue;
4414 }
4415
4416 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004417 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004418
Takashi Iwaif73d3582008-11-25 08:21:51 +01004419 pinctl = snd_hda_codec_read(codec, nid, 0,
4420 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4421 /* outputs are only ports capable of power management
4422 * any attempts on powering down a input port cause the
4423 * referenced VREF to act quirky.
4424 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004425 if (pinctl & AC_PINCTL_IN_EN) {
4426 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004427 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004428 }
Takashi Iwai330ee992009-02-20 14:33:36 +01004429 def_conf = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004430 def_conf = get_defcfg_connect(def_conf);
4431 /* skip any ports that don't have jacks since presence
4432 * detection is useless */
4433 if (def_conf != AC_JACK_PORT_COMPLEX) {
4434 if (def_conf != AC_JACK_PORT_NONE)
4435 stac_toggle_power_map(codec, nid, 1);
4436 continue;
4437 }
Takashi Iwai62558ce2009-07-29 14:23:09 +02004438 if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
4439 stac_issue_unsol_event(codec, nid);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004440 }
4441 if (spec->dac_list)
4442 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004443 return 0;
4444}
4445
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004446static void stac92xx_free_jacks(struct hda_codec *codec)
4447{
Takashi Iwai8c8145b2009-06-22 17:00:38 +02004448#ifdef CONFIG_SND_HDA_INPUT_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01004449 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004450 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01004451 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004452 struct sigmatel_jack *jacks = spec->jacks.list;
4453 int i;
Takashi Iwai95c09092009-04-14 16:15:29 +02004454 for (i = 0; i < spec->jacks.used; i++, jacks++) {
4455 if (jacks->jack)
4456 snd_device_free(codec->bus->card, jacks->jack);
4457 }
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004458 }
4459 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004460#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004461}
4462
Takashi Iwai603c4012008-07-30 15:01:44 +02004463static void stac92xx_free_kctls(struct hda_codec *codec)
4464{
4465 struct sigmatel_spec *spec = codec->spec;
4466
4467 if (spec->kctls.list) {
4468 struct snd_kcontrol_new *kctl = spec->kctls.list;
4469 int i;
4470 for (i = 0; i < spec->kctls.used; i++)
4471 kfree(kctl[i].name);
4472 }
4473 snd_array_free(&spec->kctls);
4474}
4475
Matt2f2f4252005-04-13 14:45:30 +02004476static void stac92xx_free(struct hda_codec *codec)
4477{
Mattc7d4b2f2005-06-27 14:59:41 +02004478 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004479
4480 if (! spec)
4481 return;
4482
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004483 stac92xx_free_jacks(codec);
4484 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004485
Mattc7d4b2f2005-06-27 14:59:41 +02004486 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004487 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004488}
4489
Matt4e550962005-07-04 17:51:39 +02004490static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4491 unsigned int flag)
4492{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004493 unsigned int old_ctl, pin_ctl;
4494
4495 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004496 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004497
Takashi Iwaif9acba42007-05-29 18:01:06 +02004498 if (pin_ctl & AC_PINCTL_IN_EN) {
4499 /*
4500 * we need to check the current set-up direction of
4501 * shared input pins since they can be switched via
4502 * "xxx as Output" mixer switch
4503 */
4504 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004505 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004506 return;
4507 }
4508
Takashi Iwai8ce84192009-01-22 16:59:20 +01004509 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004510 /* if setting pin direction bits, clear the current
4511 direction bits first */
4512 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4513 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4514
Takashi Iwai8ce84192009-01-22 16:59:20 +01004515 pin_ctl |= flag;
4516 if (old_ctl != pin_ctl)
4517 snd_hda_codec_write_cache(codec, nid, 0,
4518 AC_VERB_SET_PIN_WIDGET_CONTROL,
4519 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004520}
4521
4522static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4523 unsigned int flag)
4524{
4525 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4526 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004527 if (pin_ctl & flag)
4528 snd_hda_codec_write_cache(codec, nid, 0,
4529 AC_VERB_SET_PIN_WIDGET_CONTROL,
4530 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004531}
4532
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004533static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004534{
4535 if (!nid)
4536 return 0;
4537 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004538 & (1 << 31))
4539 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004540 return 0;
4541}
4542
Takashi Iwaid7a89432008-11-12 09:48:04 +01004543/* return non-zero if the hp-pin of the given array index isn't
4544 * a jack-detection target
4545 */
4546static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4547{
4548 struct auto_pin_cfg *cfg = &spec->autocfg;
4549
4550 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004551 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004552 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004553 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004554 return 1;
4555 /* ignore if the pin is set as line-out */
4556 if (cfg->hp_pins[i] == spec->hp_switch)
4557 return 1;
4558 return 0;
4559}
4560
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004561static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004562{
4563 struct sigmatel_spec *spec = codec->spec;
4564 struct auto_pin_cfg *cfg = &spec->autocfg;
4565 int i, presence;
4566
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004567 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004568 if (spec->gpio_mute)
4569 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4570 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4571
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004572 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004573 if (presence)
4574 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004575 if (no_hp_sensing(spec, i))
4576 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004577 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4578 if (presence) {
4579 unsigned int pinctl;
4580 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4581 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4582 if (pinctl & AC_PINCTL_IN_EN)
4583 presence = 0; /* mic- or line-input */
4584 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004585 }
Matt4e550962005-07-04 17:51:39 +02004586
4587 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004588 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004589 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004590 stac92xx_reset_pinctl(codec, spec->hp_switch,
4591 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004592 for (i = 0; i < cfg->line_outs; i++)
4593 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4594 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004595 for (i = 0; i < cfg->speaker_outs; i++)
4596 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4597 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004598 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004599 stac_gpio_set(codec, spec->gpio_mask,
4600 spec->gpio_dir, spec->gpio_data &
4601 ~spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004602 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004603 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004604 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004605 stac92xx_set_pinctl(codec, spec->hp_switch,
4606 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004607 for (i = 0; i < cfg->line_outs; i++)
4608 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4609 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004610 for (i = 0; i < cfg->speaker_outs; i++)
4611 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4612 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004613 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004614 stac_gpio_set(codec, spec->gpio_mask,
4615 spec->gpio_dir, spec->gpio_data |
4616 spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004617 }
Takashi Iwaid7a89432008-11-12 09:48:04 +01004618 /* toggle hp outs */
4619 for (i = 0; i < cfg->hp_outs; i++) {
4620 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4621 if (no_hp_sensing(spec, i))
4622 continue;
4623 if (presence)
4624 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004625#if 0 /* FIXME */
4626/* Resetting the pinctl like below may lead to (a sort of) regressions
4627 * on some devices since they use the HP pin actually for line/speaker
4628 * outs although the default pin config shows a different pin (that is
4629 * wrong and useless).
4630 *
4631 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4632 * But, disabling the code below just works around it, and I'm too tired of
4633 * bug reports with such devices...
4634 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004635 else
4636 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004637#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004638 }
Matt4e550962005-07-04 17:51:39 +02004639}
4640
Takashi Iwaif73d3582008-11-25 08:21:51 +01004641static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4642 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004643{
4644 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004645 unsigned int idx, val;
4646
4647 for (idx = 0; idx < spec->num_pwrs; idx++) {
4648 if (spec->pwr_nids[idx] == nid)
4649 break;
4650 }
4651 if (idx >= spec->num_pwrs)
4652 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004653
4654 /* several codecs have two power down bits */
4655 if (spec->pwr_mapping)
4656 idx = spec->pwr_mapping[idx];
4657 else
4658 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004659
Takashi Iwaif73d3582008-11-25 08:21:51 +01004660 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4661 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004662 val &= ~idx;
4663 else
4664 val |= idx;
4665
4666 /* power down unused output ports */
4667 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004668}
4669
Takashi Iwaif73d3582008-11-25 08:21:51 +01004670static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4671{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004672 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004673}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004674
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004675static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4676{
4677 struct sigmatel_spec *spec = codec->spec;
4678 struct sigmatel_jack *jacks = spec->jacks.list;
4679
4680 if (jacks) {
4681 int i;
4682 for (i = 0; i < spec->jacks.used; i++) {
4683 if (jacks->nid == nid) {
4684 unsigned int pin_ctl =
4685 snd_hda_codec_read(codec, nid,
4686 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4687 0x00);
4688 int type = jacks->type;
4689 if (type == (SND_JACK_LINEOUT
4690 | SND_JACK_HEADPHONE))
4691 type = (pin_ctl & AC_PINCTL_HP_EN)
4692 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4693 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004694 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004695 ? type : 0);
4696 }
4697 jacks++;
4698 }
4699 }
4700}
Matt2f2f4252005-04-13 14:45:30 +02004701
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004702static void stac92xx_mic_detect(struct hda_codec *codec)
4703{
4704 struct sigmatel_spec *spec = codec->spec;
4705 struct sigmatel_mic_route *mic;
4706
4707 if (get_pin_presence(codec, spec->ext_mic.pin))
4708 mic = &spec->ext_mic;
4709 else
4710 mic = &spec->int_mic;
4711 if (mic->dmux_idx)
4712 snd_hda_codec_write_cache(codec, spec->dmux_nids[0], 0,
4713 AC_VERB_SET_CONNECT_SEL,
4714 mic->dmux_idx);
4715 else
4716 snd_hda_codec_write_cache(codec, spec->mux_nids[0], 0,
4717 AC_VERB_SET_CONNECT_SEL,
4718 mic->mux_idx);
4719}
4720
Takashi Iwai62558ce2009-07-29 14:23:09 +02004721static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004722{
Takashi Iwai62558ce2009-07-29 14:23:09 +02004723 struct sigmatel_event *event = stac_get_event(codec, nid);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004724 if (!event)
4725 return;
4726 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4727}
4728
Takashi Iwai314634b2006-09-21 11:56:18 +02004729static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4730{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004731 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004732 struct sigmatel_event *event;
4733 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004734
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004735 tag = (res >> 26) & 0x7f;
4736 event = stac_get_event_from_tag(codec, tag);
4737 if (!event)
4738 return;
4739
4740 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004741 case STAC_HP_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004742 stac92xx_hp_detect(codec);
Takashi Iwai3d21d3f2009-07-29 14:32:56 +02004743 break;
4744 case STAC_MIC_EVENT:
4745 stac92xx_mic_detect(codec);
4746 break;
4747 }
4748
4749 switch (event->type) {
4750 case STAC_HP_EVENT:
4751 case STAC_MIC_EVENT:
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004752 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004753 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004754 if (spec->num_pwrs > 0)
4755 stac92xx_pin_sense(codec, event->nid);
4756 stac92xx_report_jack(codec, event->nid);
Matthew Ranostayfd60cc82009-04-06 09:30:46 -04004757
4758 switch (codec->subsystem_id) {
4759 case 0x103c308f:
4760 if (event->nid == 0xb) {
4761 int pin = AC_PINCTL_IN_EN;
4762
4763 if (get_pin_presence(codec, 0xa)
4764 && get_pin_presence(codec, 0xb))
4765 pin |= AC_PINCTL_VREF_80;
4766 if (!get_pin_presence(codec, 0xb))
4767 pin |= AC_PINCTL_VREF_80;
4768
4769 /* toggle VREF state based on mic + hp pin
4770 * status
4771 */
4772 stac92xx_auto_set_pinctl(codec, 0x0a, pin);
4773 }
4774 }
Matthew Ranostay72474be2008-10-09 09:32:17 -04004775 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004776 case STAC_VREF_EVENT:
4777 data = snd_hda_codec_read(codec, codec->afg, 0,
4778 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004779 /* toggle VREF state based on GPIOx status */
4780 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004781 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004782 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004783 }
4784}
4785
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004786#ifdef CONFIG_PROC_FS
4787static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4788 struct hda_codec *codec, hda_nid_t nid)
4789{
4790 if (nid == codec->afg)
4791 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4792 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4793}
4794
4795static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4796 struct hda_codec *codec,
4797 unsigned int verb)
4798{
4799 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4800 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4801}
4802
4803/* stac92hd71bxx, stac92hd73xx */
4804static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4805 struct hda_codec *codec, hda_nid_t nid)
4806{
4807 stac92hd_proc_hook(buffer, codec, nid);
4808 if (nid == codec->afg)
4809 analog_loop_proc_hook(buffer, codec, 0xfa0);
4810}
4811
4812static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4813 struct hda_codec *codec, hda_nid_t nid)
4814{
4815 if (nid == codec->afg)
4816 analog_loop_proc_hook(buffer, codec, 0xfe0);
4817}
4818
4819static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4820 struct hda_codec *codec, hda_nid_t nid)
4821{
4822 if (nid == codec->afg)
4823 analog_loop_proc_hook(buffer, codec, 0xfeb);
4824}
4825#else
4826#define stac92hd_proc_hook NULL
4827#define stac92hd7x_proc_hook NULL
4828#define stac9205_proc_hook NULL
4829#define stac927x_proc_hook NULL
4830#endif
4831
Takashi Iwaicb53c622007-08-10 17:21:45 +02004832#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004833static int stac92xx_resume(struct hda_codec *codec)
4834{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004835 struct sigmatel_spec *spec = codec->spec;
4836
Takashi Iwai2c885872008-11-18 09:36:55 +01004837 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004838 snd_hda_codec_resume_amp(codec);
4839 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004840 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004841 if (spec->hp_detect)
Takashi Iwai62558ce2009-07-29 14:23:09 +02004842 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
Mattff6fdc32005-06-27 15:06:52 +02004843 return 0;
4844}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004845
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004846/*
James Gardiner514bf542009-05-03 04:00:44 -04004847 * using power check for controlling mute led of HP notebooks
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004848 * check for mute state only on Speakers (nid = 0x10)
4849 *
4850 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4851 * the LED is NOT working properly !
James Gardiner514bf542009-05-03 04:00:44 -04004852 *
4853 * Changed name to reflect that it now works for any designated
4854 * model, not just HP HDX.
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004855 */
4856
4857#ifdef CONFIG_SND_HDA_POWER_SAVE
James Gardiner514bf542009-05-03 04:00:44 -04004858static int stac92xx_hp_check_power_status(struct hda_codec *codec,
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004859 hda_nid_t nid)
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004860{
4861 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004862
4863 if (nid == 0x10) {
4864 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004865 HDA_AMP_MUTE)
Takashi Iwai86d190e2009-05-26 15:18:58 +02004866 spec->gpio_data &= ~spec->gpio_led; /* orange */
Takashi Iwaiba84bfc2009-05-30 08:59:03 +02004867 else
4868 spec->gpio_data |= spec->gpio_led; /* white */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01004869
4870 stac_gpio_set(codec, spec->gpio_mask,
4871 spec->gpio_dir,
Christoph Plattnerae6241f2009-03-08 23:19:05 +01004872 spec->gpio_data);
4873 }
4874
4875 return 0;
4876}
4877#endif
4878
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004879static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4880{
4881 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004882 int i;
4883 hda_nid_t nid;
4884
4885 /* reset each pin before powering down DAC/ADC to avoid click noise */
4886 nid = codec->start_nid;
4887 for (i = 0; i < codec->num_nodes; i++, nid++) {
4888 unsigned int wcaps = get_wcaps(codec, nid);
Takashi Iwaia22d5432009-07-27 12:54:26 +02004889 unsigned int wid_type = get_wcaps_type(wcaps);
Takashi Iwai05ff7e12009-07-22 12:39:24 +02004890 if (wid_type == AC_WID_PIN)
4891 snd_hda_codec_read(codec, nid, 0,
4892 AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
4893 }
4894
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004895 if (spec->eapd_mask)
4896 stac_gpio_set(codec, spec->gpio_mask,
4897 spec->gpio_dir, spec->gpio_data &
4898 ~spec->eapd_mask);
4899 return 0;
4900}
Mattff6fdc32005-06-27 15:06:52 +02004901#endif
4902
Matt2f2f4252005-04-13 14:45:30 +02004903static struct hda_codec_ops stac92xx_patch_ops = {
4904 .build_controls = stac92xx_build_controls,
4905 .build_pcms = stac92xx_build_pcms,
4906 .init = stac92xx_init,
4907 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004908 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004909#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004910 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004911 .resume = stac92xx_resume,
4912#endif
Matt2f2f4252005-04-13 14:45:30 +02004913};
4914
4915static int patch_stac9200(struct hda_codec *codec)
4916{
4917 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004918 int err;
Matt2f2f4252005-04-13 14:45:30 +02004919
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004920 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004921 if (spec == NULL)
4922 return -ENOMEM;
4923
4924 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004925 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004926 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004927 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4928 stac9200_models,
4929 stac9200_cfg_tbl);
Takashi Iwai330ee992009-02-20 14:33:36 +01004930 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02004931 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4932 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01004933 else
4934 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004935 stac9200_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02004936
4937 spec->multiout.max_channels = 2;
4938 spec->multiout.num_dacs = 1;
4939 spec->multiout.dac_nids = stac9200_dac_nids;
4940 spec->adc_nids = stac9200_adc_nids;
4941 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004942 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004943 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004944 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004945 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004946
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02004947 if (spec->board_config == STAC_9200_M4 ||
4948 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01004949 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004950 spec->init = stac9200_eapd_init;
4951 else
4952 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004953 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004954
Takashi Iwai117f2572008-03-18 09:53:23 +01004955 if (spec->board_config == STAC_9200_PANASONIC) {
4956 spec->gpio_mask = spec->gpio_dir = 0x09;
4957 spec->gpio_data = 0x00;
4958 }
4959
Mattc7d4b2f2005-06-27 14:59:41 +02004960 err = stac9200_parse_auto_config(codec);
4961 if (err < 0) {
4962 stac92xx_free(codec);
4963 return err;
4964 }
Matt2f2f4252005-04-13 14:45:30 +02004965
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01004966 /* CF-74 has no headphone detection, and the driver should *NOT*
4967 * do detection and HP/speaker toggle because the hardware does it.
4968 */
4969 if (spec->board_config == STAC_9200_PANASONIC)
4970 spec->hp_detect = 0;
4971
Matt2f2f4252005-04-13 14:45:30 +02004972 codec->patch_ops = stac92xx_patch_ops;
4973
4974 return 0;
4975}
4976
Tobin Davis8e21c342007-01-08 11:04:17 +01004977static int patch_stac925x(struct hda_codec *codec)
4978{
4979 struct sigmatel_spec *spec;
4980 int err;
4981
4982 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4983 if (spec == NULL)
4984 return -ENOMEM;
4985
4986 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004987 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004988 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004989
4990 /* Check first for codec ID */
4991 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
4992 STAC_925x_MODELS,
4993 stac925x_models,
4994 stac925x_codec_id_cfg_tbl);
4995
4996 /* Now checks for PCI ID, if codec ID is not found */
4997 if (spec->board_config < 0)
4998 spec->board_config = snd_hda_check_board_config(codec,
4999 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01005000 stac925x_models,
5001 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005002 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005003 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005004 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5005 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005006 else
5007 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005008 stac925x_brd_tbl[spec->board_config]);
Tobin Davis8e21c342007-01-08 11:04:17 +01005009
5010 spec->multiout.max_channels = 2;
5011 spec->multiout.num_dacs = 1;
5012 spec->multiout.dac_nids = stac925x_dac_nids;
5013 spec->adc_nids = stac925x_adc_nids;
5014 spec->mux_nids = stac925x_mux_nids;
5015 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005016 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005017 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02005018 switch (codec->vendor_id) {
5019 case 0x83847632: /* STAC9202 */
5020 case 0x83847633: /* STAC9202D */
5021 case 0x83847636: /* STAC9251 */
5022 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02005023 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02005024 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005025 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
5026 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02005027 break;
5028 default:
5029 spec->num_dmics = 0;
5030 break;
5031 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005032
5033 spec->init = stac925x_core_init;
5034 spec->mixer = stac925x_mixer;
Takashi Iwai6479c632009-07-28 18:20:25 +02005035 spec->num_caps = 1;
5036 spec->capvols = stac925x_capvols;
5037 spec->capsws = stac925x_capsws;
Tobin Davis8e21c342007-01-08 11:04:17 +01005038
5039 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005040 if (!err) {
5041 if (spec->board_config < 0) {
5042 printk(KERN_WARNING "hda_codec: No auto-config is "
5043 "available, default to model=ref\n");
5044 spec->board_config = STAC_925x_REF;
5045 goto again;
5046 }
5047 err = -EINVAL;
5048 }
Tobin Davis8e21c342007-01-08 11:04:17 +01005049 if (err < 0) {
5050 stac92xx_free(codec);
5051 return err;
5052 }
5053
5054 codec->patch_ops = stac92xx_patch_ops;
5055
5056 return 0;
5057}
5058
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005059static struct hda_input_mux stac92hd73xx_dmux = {
5060 .num_items = 4,
5061 .items = {
5062 { "Analog Inputs", 0x0b },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005063 { "Digital Mic 1", 0x09 },
5064 { "Digital Mic 2", 0x0a },
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005065 { "CD", 0x08 },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005066 }
5067};
5068
5069static int patch_stac92hd73xx(struct hda_codec *codec)
5070{
5071 struct sigmatel_spec *spec;
5072 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
5073 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005074 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005075
5076 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5077 if (spec == NULL)
5078 return -ENOMEM;
5079
5080 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02005081 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005082 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
5083 spec->pin_nids = stac92hd73xx_pin_nids;
5084 spec->board_config = snd_hda_check_board_config(codec,
5085 STAC_92HD73XX_MODELS,
5086 stac92hd73xx_models,
5087 stac92hd73xx_cfg_tbl);
5088again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005089 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005090 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5091 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005092 else
5093 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005094 stac92hd73xx_brd_tbl[spec->board_config]);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005095
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005096 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005097 conn, STAC92HD73_DAC_COUNT + 2) - 1;
5098
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005099 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005100 printk(KERN_WARNING "hda_codec: Could not determine "
5101 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005102 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005103 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005104 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005105 case 0x3: /* 6 Channel */
5106 spec->mixer = stac92hd73xx_6ch_mixer;
5107 spec->init = stac92hd73xx_6ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005108 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005109 break;
5110 case 0x4: /* 8 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005111 spec->mixer = stac92hd73xx_8ch_mixer;
5112 spec->init = stac92hd73xx_8ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005113 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005114 break;
5115 case 0x5: /* 10 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005116 spec->mixer = stac92hd73xx_10ch_mixer;
5117 spec->init = stac92hd73xx_10ch_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005118 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
5119 break;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005120 }
5121 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005122
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005123 spec->aloopback_mask = 0x01;
5124 spec->aloopback_shift = 8;
5125
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005126 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005127 spec->mux_nids = stac92hd73xx_mux_nids;
5128 spec->adc_nids = stac92hd73xx_adc_nids;
5129 spec->dmic_nids = stac92hd73xx_dmic_nids;
5130 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005131 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04005132 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005133 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005134
5135 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
5136 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01005137 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005138 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
5139 sizeof(stac92hd73xx_dmux));
5140
Takashi Iwai6479c632009-07-28 18:20:25 +02005141 spec->num_caps = STAC92HD73XX_NUM_CAPS;
5142 spec->capvols = stac92hd73xx_capvols;
5143 spec->capsws = stac92hd73xx_capsws;
5144
Matthew Ranostaya7662642008-02-21 07:51:14 +01005145 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005146 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01005147 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005148 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005149 case STAC_DELL_M6_AMIC:
5150 case STAC_DELL_M6_DMIC:
5151 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005152 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005153 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
5154 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005155 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005156 spec->num_amps = 1;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005157
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005158 if (spec->board_config != STAC_DELL_EQ)
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05005159 spec->init = dell_m6_core_init;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005160 switch (spec->board_config) {
5161 case STAC_DELL_M6_AMIC: /* Analog Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005162 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005163 spec->num_dmics = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005164 spec->private_dimux.num_items = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005165 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005166 case STAC_DELL_M6_DMIC: /* Digital Mics */
Takashi Iwai330ee992009-02-20 14:33:36 +01005167 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005168 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005169 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005170 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01005171 case STAC_DELL_M6_BOTH: /* Both */
Takashi Iwai330ee992009-02-20 14:33:36 +01005172 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
5173 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
Matthew Ranostaya7662642008-02-21 07:51:14 +01005174 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005175 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005176 break;
5177 }
5178 break;
5179 default:
5180 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005181 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005182 spec->eapd_switch = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005183 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005184 if (spec->board_config > STAC_92HD73XX_REF) {
5185 /* GPIO0 High = Enable EAPD */
5186 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
5187 spec->gpio_data = 0x01;
5188 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04005189 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostaya7662642008-02-21 07:51:14 +01005190
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005191 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5192 spec->pwr_nids = stac92hd73xx_pwr_nids;
5193
Matthew Ranostayd9737752008-09-07 12:03:41 +02005194 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005195
5196 if (!err) {
5197 if (spec->board_config < 0) {
5198 printk(KERN_WARNING "hda_codec: No auto-config is "
5199 "available, default to model=ref\n");
5200 spec->board_config = STAC_92HD73XX_REF;
5201 goto again;
5202 }
5203 err = -EINVAL;
5204 }
5205
5206 if (err < 0) {
5207 stac92xx_free(codec);
5208 return err;
5209 }
5210
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01005211 if (spec->board_config == STAC_92HD73XX_NO_JD)
5212 spec->hp_detect = 0;
5213
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005214 codec->patch_ops = stac92xx_patch_ops;
5215
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005216 codec->proc_widget_hook = stac92hd7x_proc_hook;
5217
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005218 return 0;
5219}
5220
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005221static struct hda_input_mux stac92hd83xxx_dmux = {
5222 .num_items = 3,
5223 .items = {
5224 { "Analog Inputs", 0x03 },
5225 { "Digital Mic 1", 0x04 },
5226 { "Digital Mic 2", 0x05 },
5227 }
5228};
5229
5230static int patch_stac92hd83xxx(struct hda_codec *codec)
5231{
5232 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005233 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005234 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05005235 int num_dacs;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005236 hda_nid_t nid;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005237
5238 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5239 if (spec == NULL)
5240 return -ENOMEM;
5241
5242 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005243 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005244 spec->mono_nid = 0x19;
5245 spec->digbeep_nid = 0x21;
5246 spec->dmic_nids = stac92hd83xxx_dmic_nids;
5247 spec->dmux_nids = stac92hd83xxx_dmux_nids;
5248 spec->adc_nids = stac92hd83xxx_adc_nids;
5249 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayc15c5062009-01-13 13:30:07 -05005250 spec->amp_nids = stac92hd83xxx_amp_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005251 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5252 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005253 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005254
5255 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005256 spec->mixer = stac92hd83xxx_mixer;
5257 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
5258 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
5259 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayc15c5062009-01-13 13:30:07 -05005260 spec->num_amps = ARRAY_SIZE(stac92hd83xxx_amp_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005261 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
5262 spec->dinput_mux = &stac92hd83xxx_dmux;
5263 spec->pin_nids = stac92hd83xxx_pin_nids;
Takashi Iwai6479c632009-07-28 18:20:25 +02005264 spec->num_caps = STAC92HD83XXX_NUM_CAPS;
5265 spec->capvols = stac92hd83xxx_capvols;
5266 spec->capsws = stac92hd83xxx_capsws;
5267
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005268 spec->board_config = snd_hda_check_board_config(codec,
5269 STAC_92HD83XXX_MODELS,
5270 stac92hd83xxx_models,
5271 stac92hd83xxx_cfg_tbl);
5272again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005273 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005274 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5275 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005276 else
5277 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005278 stac92hd83xxx_brd_tbl[spec->board_config]);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005279
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005280 switch (codec->vendor_id) {
5281 case 0x111d7604:
5282 case 0x111d7605:
Matthew Ranostayff2e7332009-04-01 14:49:48 -04005283 case 0x111d76d5:
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05005284 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5285 break;
5286 spec->num_pwrs = 0;
5287 break;
5288 }
5289
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005290 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
5291 if (!err) {
5292 if (spec->board_config < 0) {
5293 printk(KERN_WARNING "hda_codec: No auto-config is "
5294 "available, default to model=ref\n");
5295 spec->board_config = STAC_92HD83XXX_REF;
5296 goto again;
5297 }
5298 err = -EINVAL;
5299 }
5300
5301 if (err < 0) {
5302 stac92xx_free(codec);
5303 return err;
5304 }
5305
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005306 switch (spec->board_config) {
5307 case STAC_DELL_S14:
5308 nid = 0xf;
5309 break;
5310 default:
5311 nid = 0xe;
5312 break;
5313 }
5314
5315 num_dacs = snd_hda_get_connections(codec, nid,
5316 conn, STAC92HD83_DAC_COUNT + 1) - 1;
Jaroslav Kysela16a433d2009-07-22 16:20:40 +02005317 if (num_dacs < 0)
5318 num_dacs = STAC92HD83_DAC_COUNT;
Matthew Ranostay8bb0ac52009-02-12 16:50:01 -05005319
5320 /* set port X to select the last DAC
5321 */
5322 snd_hda_codec_write_cache(codec, nid, 0,
5323 AC_VERB_SET_CONNECT_SEL, num_dacs);
5324
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005325 codec->patch_ops = stac92xx_patch_ops;
5326
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005327 codec->proc_widget_hook = stac92hd_proc_hook;
5328
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005329 return 0;
5330}
5331
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005332static struct hda_input_mux stac92hd71bxx_dmux_nomixer = {
5333 .num_items = 3,
5334 .items = {
5335 { "Analog Inputs", 0x00 },
5336 { "Digital Mic 1", 0x02 },
5337 { "Digital Mic 2", 0x03 },
5338 }
5339};
5340
5341static struct hda_input_mux stac92hd71bxx_dmux_amixer = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005342 .num_items = 4,
5343 .items = {
5344 { "Analog Inputs", 0x00 },
5345 { "Mixer", 0x01 },
5346 { "Digital Mic 1", 0x02 },
5347 { "Digital Mic 2", 0x03 },
5348 }
5349};
5350
Takashi Iwai330ee992009-02-20 14:33:36 +01005351/* get the pin connection (fixed, none, etc) */
5352static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
5353{
5354 struct sigmatel_spec *spec = codec->spec;
5355 unsigned int cfg;
5356
5357 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
5358 return get_defcfg_connect(cfg);
5359}
5360
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005361static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
5362 hda_nid_t *nids, int num_nids)
5363{
5364 struct sigmatel_spec *spec = codec->spec;
5365 int idx, num;
5366 unsigned int def_conf;
5367
5368 for (num = 0; num < num_nids; num++) {
5369 for (idx = 0; idx < spec->num_pins; idx++)
5370 if (spec->pin_nids[idx] == nids[num])
5371 break;
5372 if (idx >= spec->num_pins)
5373 break;
Takashi Iwai330ee992009-02-20 14:33:36 +01005374 def_conf = stac_get_defcfg_connect(codec, idx);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005375 if (def_conf == AC_JACK_PORT_NONE)
5376 break;
5377 }
5378 return num;
5379}
5380
5381static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
5382 hda_nid_t dig0pin)
5383{
5384 struct sigmatel_spec *spec = codec->spec;
5385 int idx;
5386
5387 for (idx = 0; idx < spec->num_pins; idx++)
5388 if (spec->pin_nids[idx] == dig0pin)
5389 break;
5390 if ((idx + 2) >= spec->num_pins)
5391 return 0;
5392
5393 /* dig1pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005394 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005395 return 2;
5396
5397 /* dig0pin + dig2pin case */
Takashi Iwai330ee992009-02-20 14:33:36 +01005398 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005399 return 2;
Takashi Iwai330ee992009-02-20 14:33:36 +01005400 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005401 return 1;
5402 else
5403 return 0;
5404}
5405
Matthew Ranostaye035b842007-11-06 11:53:55 +01005406static int patch_stac92hd71bxx(struct hda_codec *codec)
5407{
5408 struct sigmatel_spec *spec;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005409 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005410 int err = 0;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005411 unsigned int ndmic_nids = 0;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005412
5413 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5414 if (spec == NULL)
5415 return -ENOMEM;
5416
5417 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005418 codec->patch_ops = stac92xx_patch_ops;
Herton Ronaldo Krzesinski616f89e2009-02-04 11:23:19 -05005419 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5420 switch (codec->vendor_id) {
5421 case 0x111d76b6:
5422 case 0x111d76b7:
5423 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5424 break;
5425 case 0x111d7603:
5426 case 0x111d7608:
5427 /* On 92HD75Bx 0x27 isn't a pin nid */
5428 spec->num_pins--;
5429 /* fallthrough */
5430 default:
5431 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5432 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005433 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005434 spec->board_config = snd_hda_check_board_config(codec,
5435 STAC_92HD71BXX_MODELS,
5436 stac92hd71bxx_models,
5437 stac92hd71bxx_cfg_tbl);
5438again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005439 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005440 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5441 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005442 else
5443 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005444 stac92hd71bxx_brd_tbl[spec->board_config]);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005445
Takashi Iwai41c3b642008-11-18 10:45:15 +01005446 if (spec->board_config > STAC_92HD71BXX_REF) {
5447 /* GPIO0 = EAPD */
5448 spec->gpio_mask = 0x01;
5449 spec->gpio_dir = 0x01;
5450 spec->gpio_data = 0x01;
5451 }
5452
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005453 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5454 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5455
Takashi Iwai6479c632009-07-28 18:20:25 +02005456 spec->num_caps = STAC92HD71BXX_NUM_CAPS;
5457 spec->capvols = stac92hd71bxx_capvols;
5458 spec->capsws = stac92hd71bxx_capsws;
5459
Matthew Ranostay541eee82007-12-14 12:08:04 +01005460 switch (codec->vendor_id) {
5461 case 0x111d76b6: /* 4 Port without Analog Mixer */
5462 case 0x111d76b7:
Herton Ronaldo Krzesinski23c7b522009-02-08 19:51:28 -02005463 unmute_init++;
5464 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005465 case 0x111d76b4: /* 6 Port without Analog Mixer */
5466 case 0x111d76b5:
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005467 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_nomixer,
5468 sizeof(stac92hd71bxx_dmux_nomixer));
Matthew Ranostay541eee82007-12-14 12:08:04 +01005469 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005470 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005471 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5472 stac92hd71bxx_dmic_nids,
5473 STAC92HD71BXX_NUM_DMICS);
5474 if (spec->num_dmics) {
5475 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5476 spec->dinput_mux = &spec->private_dimux;
5477 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5478 }
Matthew Ranostay541eee82007-12-14 12:08:04 +01005479 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005480 case 0x111d7608: /* 5 Port with Analog Mixer */
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005481 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5482 sizeof(stac92hd71bxx_dmux_amixer));
5483 spec->private_dimux.num_items--;
Takashi Iwai8e5f2622008-11-15 19:28:54 +01005484 switch (spec->board_config) {
5485 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04005486 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005487 err = stac_add_event(spec, codec->afg,
5488 STAC_VREF_EVENT, 0x02);
5489 if (err < 0)
5490 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005491 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04005492 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5493 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04005494 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005495 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04005496 spec->gpio_mask |= 0x02;
5497 break;
5498 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005499 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005500 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005501 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005502
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005503 /* no output amps */
5504 spec->num_pwrs = 0;
Takashi Iwai50c62f02009-07-28 18:25:29 +02005505 if (snd_hda_get_bool_hint(codec, "analog_mixer") == 1)
5506 spec->mixer = stac92hd71bxx_analog_mixer;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005507
5508 /* disable VSW */
Takashi Iwai26a27982009-07-29 16:28:09 +02005509 spec->init = stac92hd71bxx_core_init;
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005510 unmute_init++;
Takashi Iwai330ee992009-02-20 14:33:36 +01005511 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5512 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005513 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5514 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5515 stac92hd71bxx_dmic_nids,
5516 STAC92HD71BXX_NUM_DMICS - 1);
Takashi Iwai44179322009-07-28 17:03:49 +02005517 if (spec->num_dmics) {
5518 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5519 spec->dinput_mux = &spec->private_dimux;
5520 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 2;
5521 }
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005522 break;
5523 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01005524 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005525 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005526
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005527 /* no output amps */
5528 spec->num_pwrs = 0;
5529 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01005530 default:
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005531 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5532 sizeof(stac92hd71bxx_dmux_amixer));
Takashi Iwai50c62f02009-07-28 18:25:29 +02005533 if (snd_hda_get_bool_hint(codec, "analog_mixer") == 1)
5534 spec->mixer = stac92hd71bxx_analog_mixer;
Takashi Iwai26a27982009-07-29 16:28:09 +02005535 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04005536 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005537 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5538 stac92hd71bxx_dmic_nids,
5539 STAC92HD71BXX_NUM_DMICS);
Takashi Iwai44179322009-07-28 17:03:49 +02005540 if (spec->num_dmics) {
5541 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5542 spec->dinput_mux = &spec->private_dimux;
5543 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5544 }
Matthew Ranostay541eee82007-12-14 12:08:04 +01005545 }
5546
Matthew Ranostayca8d33f2009-01-26 09:33:52 -05005547 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5548 snd_hda_sequence_write_cache(codec, unmute_init);
5549
Takashi Iwaib20f3b82009-06-02 01:20:22 +02005550 /* Some HP machines seem to have unstable codec communications
5551 * especially with ATI fglrx driver. For recovering from the
5552 * CORB/RIRB stall, allow the BUS reset and keep always sync
5553 */
5554 if (spec->board_config == STAC_HP_DV5) {
5555 codec->bus->sync_write = 1;
5556 codec->bus->allow_bus_reset = 1;
5557 }
5558
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005559 spec->aloopback_ctl = stac92hd71bxx_loopback;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005560 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005561 spec->aloopback_shift = 0;
5562
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005563 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005564 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005565 spec->mux_nids = stac92hd71bxx_mux_nids;
5566 spec->adc_nids = stac92hd71bxx_adc_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005567 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005568 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005569
5570 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5571 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005572 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005573
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005574 switch (spec->board_config) {
5575 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005576 /* enable internal microphone */
Takashi Iwai330ee992009-02-20 14:33:36 +01005577 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005578 stac92xx_auto_set_pinctl(codec, 0x0e,
5579 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005580 /* fallthru */
5581 case STAC_DELL_M4_2:
5582 spec->num_dmics = 0;
5583 spec->num_smuxes = 0;
5584 spec->num_dmuxes = 0;
5585 break;
5586 case STAC_DELL_M4_1:
5587 case STAC_DELL_M4_3:
5588 spec->num_dmics = 1;
5589 spec->num_smuxes = 0;
Takashi Iwaiea18aa42009-02-27 17:36:33 +01005590 spec->num_dmuxes = 1;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005591 break;
James Gardiner514bf542009-05-03 04:00:44 -04005592 case STAC_HP_DV4_1222NR:
5593 spec->num_dmics = 1;
5594 /* I don't know if it needs 1 or 2 smuxes - will wait for
5595 * bug reports to fix if needed
5596 */
5597 spec->num_smuxes = 1;
5598 spec->num_dmuxes = 1;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005599 spec->gpio_led = 0x01;
James Gardiner514bf542009-05-03 04:00:44 -04005600 /* fallthrough */
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005601 case STAC_HP_DV5:
Takashi Iwai330ee992009-02-20 14:33:36 +01005602 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
Herton Ronaldo Krzesinskie2ea57a2009-02-16 10:23:00 +01005603 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
5604 break;
Christoph Plattnerae6241f2009-03-08 23:19:05 +01005605 case STAC_HP_HDX:
5606 spec->num_dmics = 1;
5607 spec->num_dmuxes = 1;
5608 spec->num_smuxes = 1;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005609 /* orange/white mute led on GPIO3, orange=0, white=1 */
Takashi Iwai86d190e2009-05-26 15:18:58 +02005610 spec->gpio_led = 0x08;
5611 break;
5612 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005613
Takashi Iwai86d190e2009-05-26 15:18:58 +02005614#ifdef CONFIG_SND_HDA_POWER_SAVE
5615 if (spec->gpio_led) {
5616 spec->gpio_mask |= spec->gpio_led;
5617 spec->gpio_dir |= spec->gpio_led;
5618 spec->gpio_data |= spec->gpio_led;
Christoph Plattner443e26d2009-03-10 00:05:56 +01005619 /* register check_power_status callback. */
Takashi Iwai6fce61a2009-03-10 07:48:57 +01005620 codec->patch_ops.check_power_status =
Takashi Iwai86d190e2009-05-26 15:18:58 +02005621 stac92xx_hp_check_power_status;
5622 }
Christoph Plattner443e26d2009-03-10 00:05:56 +01005623#endif
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005624
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005625 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005626 if (spec->dinput_mux)
Herton Ronaldo Krzesinski6df703a2009-02-04 11:34:22 -05005627 spec->private_dimux.num_items += spec->num_dmics - ndmic_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005628
Herton Ronaldo Krzesinski29d4ab42009-02-04 11:37:27 -05005629 err = stac92xx_parse_auto_config(codec, 0x21, 0);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005630 if (!err) {
5631 if (spec->board_config < 0) {
5632 printk(KERN_WARNING "hda_codec: No auto-config is "
5633 "available, default to model=ref\n");
5634 spec->board_config = STAC_92HD71BXX_REF;
5635 goto again;
5636 }
5637 err = -EINVAL;
5638 }
5639
5640 if (err < 0) {
5641 stac92xx_free(codec);
5642 return err;
5643 }
5644
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005645 codec->proc_widget_hook = stac92hd7x_proc_hook;
5646
Matthew Ranostaye035b842007-11-06 11:53:55 +01005647 return 0;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005648}
Matthew Ranostaye035b842007-11-06 11:53:55 +01005649
Matt2f2f4252005-04-13 14:45:30 +02005650static int patch_stac922x(struct hda_codec *codec)
5651{
5652 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005653 int err;
Matt2f2f4252005-04-13 14:45:30 +02005654
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005655 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005656 if (spec == NULL)
5657 return -ENOMEM;
5658
5659 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005660 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005661 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005662 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5663 stac922x_models,
5664 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005665 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005666 spec->gpio_mask = spec->gpio_dir = 0x03;
5667 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005668 /* Intel Macs have all same PCI SSID, so we need to check
5669 * codec SSID to distinguish the exact models
5670 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005671 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005672 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005673
5674 case 0x106b0800:
5675 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005676 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005677 case 0x106b0600:
5678 case 0x106b0700:
5679 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005680 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005681 case 0x106b0e00:
5682 case 0x106b0f00:
5683 case 0x106b1600:
5684 case 0x106b1700:
5685 case 0x106b0200:
5686 case 0x106b1e00:
5687 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005688 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005689 case 0x106b1a00:
5690 case 0x00000100:
5691 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005692 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005693 case 0x106b0a00:
5694 case 0x106b2200:
5695 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005696 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005697 default:
5698 spec->board_config = STAC_INTEL_MAC_V3;
5699 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005700 }
5701 }
5702
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005703 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005704 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005705 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5706 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005707 else
5708 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005709 stac922x_brd_tbl[spec->board_config]);
Matt2f2f4252005-04-13 14:45:30 +02005710
Matt2f2f4252005-04-13 14:45:30 +02005711 spec->adc_nids = stac922x_adc_nids;
5712 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005713 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005714 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005715 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005716 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005717
5718 spec->init = stac922x_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02005719
5720 spec->num_caps = STAC922X_NUM_CAPS;
5721 spec->capvols = stac922x_capvols;
5722 spec->capsws = stac922x_capsws;
Mattc7d4b2f2005-06-27 14:59:41 +02005723
5724 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005725
Matt Porter3cc08dc2006-01-23 15:27:49 +01005726 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005727 if (!err) {
5728 if (spec->board_config < 0) {
5729 printk(KERN_WARNING "hda_codec: No auto-config is "
5730 "available, default to model=ref\n");
5731 spec->board_config = STAC_D945_REF;
5732 goto again;
5733 }
5734 err = -EINVAL;
5735 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005736 if (err < 0) {
5737 stac92xx_free(codec);
5738 return err;
5739 }
5740
5741 codec->patch_ops = stac92xx_patch_ops;
5742
Takashi Iwai807a46362007-05-29 19:01:37 +02005743 /* Fix Mux capture level; max to 2 */
5744 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5745 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5746 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5747 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5748 (0 << AC_AMPCAP_MUTE_SHIFT));
5749
Matt Porter3cc08dc2006-01-23 15:27:49 +01005750 return 0;
5751}
5752
5753static int patch_stac927x(struct hda_codec *codec)
5754{
5755 struct sigmatel_spec *spec;
5756 int err;
5757
5758 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5759 if (spec == NULL)
5760 return -ENOMEM;
5761
5762 codec->spec = spec;
Matthew Ranostay45c1d852009-02-04 17:49:41 -05005763 codec->slave_dig_outs = stac927x_slave_dig_outs;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005764 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005765 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005766 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5767 stac927x_models,
5768 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005769 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005770 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005771 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5772 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005773 else
5774 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005775 stac927x_brd_tbl[spec->board_config]);
Matt Porter3cc08dc2006-01-23 15:27:49 +01005776
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005777 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005778 spec->adc_nids = stac927x_adc_nids;
5779 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5780 spec->mux_nids = stac927x_mux_nids;
5781 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005782 spec->smux_nids = stac927x_smux_nids;
5783 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005784 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005785 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005786 spec->multiout.dac_nids = spec->dac_nids;
5787
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005788 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005789 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005790 case STAC_D965_5ST:
5791 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005792 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005793 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005794 spec->num_dmics = 0;
5795
Tobin Davis93ed1502006-09-01 21:03:12 +02005796 spec->init = d965_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005797 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005798 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005799 switch (codec->subsystem_id) {
5800 case 0x10280209:
5801 case 0x1028022e:
5802 /* correct the device field to SPDIF out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005803 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005804 break;
Takashi Iwai86d190e2009-05-26 15:18:58 +02005805 }
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005806 /* configure the analog microphone on some laptops */
Takashi Iwai330ee992009-02-20 14:33:36 +01005807 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005808 /* correct the front output jack as a hp out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005809 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005810 /* correct the front input jack as a mic */
Takashi Iwai330ee992009-02-20 14:33:36 +01005811 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005812 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005813 case STAC_DELL_3ST:
5814 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005815 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005816 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005817 spec->dmic_nids = stac927x_dmic_nids;
5818 spec->num_dmics = STAC927X_NUM_DMICS;
5819
Tobin Davis93ed1502006-09-01 21:03:12 +02005820 spec->init = d965_core_init;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005821 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005822 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005823 break;
5824 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005825 if (spec->board_config > STAC_D965_REF) {
5826 /* GPIO0 High = Enable EAPD */
5827 spec->eapd_mask = spec->gpio_mask = 0x01;
5828 spec->gpio_dir = spec->gpio_data = 0x01;
5829 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005830 spec->num_dmics = 0;
5831
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005832 spec->init = stac927x_core_init;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005833 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005834
Takashi Iwai6479c632009-07-28 18:20:25 +02005835 spec->num_caps = STAC927X_NUM_CAPS;
5836 spec->capvols = stac927x_capvols;
5837 spec->capsws = stac927x_capsws;
5838
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005839 spec->num_pwrs = 0;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005840 spec->aloopback_ctl = stac927x_loopback;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005841 spec->aloopback_mask = 0x40;
5842 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005843 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005844
Matt Porter3cc08dc2006-01-23 15:27:49 +01005845 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005846 if (!err) {
5847 if (spec->board_config < 0) {
5848 printk(KERN_WARNING "hda_codec: No auto-config is "
5849 "available, default to model=ref\n");
5850 spec->board_config = STAC_D965_REF;
5851 goto again;
5852 }
5853 err = -EINVAL;
5854 }
Mattc7d4b2f2005-06-27 14:59:41 +02005855 if (err < 0) {
5856 stac92xx_free(codec);
5857 return err;
5858 }
Matt2f2f4252005-04-13 14:45:30 +02005859
5860 codec->patch_ops = stac92xx_patch_ops;
5861
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005862 codec->proc_widget_hook = stac927x_proc_hook;
5863
Takashi Iwai52987652008-01-16 16:09:47 +01005864 /*
5865 * !!FIXME!!
5866 * The STAC927x seem to require fairly long delays for certain
5867 * command sequences. With too short delays (even if the answer
5868 * is set to RIRB properly), it results in the silence output
5869 * on some hardwares like Dell.
5870 *
5871 * The below flag enables the longer delay (see get_response
5872 * in hda_intel.c).
5873 */
5874 codec->bus->needs_damn_long_delay = 1;
5875
Takashi Iwaie28d8322008-12-17 13:48:29 +01005876 /* no jack detecion for ref-no-jd model */
5877 if (spec->board_config == STAC_D965_REF_NO_JD)
5878 spec->hp_detect = 0;
5879
Matt2f2f4252005-04-13 14:45:30 +02005880 return 0;
5881}
5882
Matt Porterf3302a52006-07-31 12:49:34 +02005883static int patch_stac9205(struct hda_codec *codec)
5884{
5885 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005886 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005887
5888 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5889 if (spec == NULL)
5890 return -ENOMEM;
5891
5892 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005893 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005894 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005895 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5896 stac9205_models,
5897 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005898 again:
Takashi Iwai330ee992009-02-20 14:33:36 +01005899 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005900 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5901 codec->chip_name);
Takashi Iwai330ee992009-02-20 14:33:36 +01005902 else
5903 stac92xx_set_config_regs(codec,
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005904 stac9205_brd_tbl[spec->board_config]);
Matt Porterf3302a52006-07-31 12:49:34 +02005905
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005906 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005907 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005908 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005909 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005910 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005911 spec->smux_nids = stac9205_smux_nids;
5912 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005913 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005914 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005915 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005916 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005917 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005918
5919 spec->init = stac9205_core_init;
Takashi Iwaid78d7a92009-03-02 14:26:25 +01005920 spec->aloopback_ctl = stac9205_loopback;
Matt Porterf3302a52006-07-31 12:49:34 +02005921
Takashi Iwai6479c632009-07-28 18:20:25 +02005922 spec->num_caps = STAC9205_NUM_CAPS;
5923 spec->capvols = stac9205_capvols;
5924 spec->capsws = stac9205_capsws;
5925
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005926 spec->aloopback_mask = 0x40;
5927 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01005928 /* Turn on/off EAPD per HP plugging */
5929 if (spec->board_config != STAC_9205_EAPD)
5930 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005931 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005932
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005933 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005934 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005935 /* Enable SPDIF in/out */
Takashi Iwai330ee992009-02-20 14:33:36 +01005936 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5937 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005938
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005939 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005940 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5941 if (err < 0)
5942 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005943 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005944 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5945 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005946 AC_VERB_SET_UNSOLICITED_ENABLE,
5947 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005948
5949 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005950 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005951 spec->gpio_mask = 0x1b;
5952 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005953 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005954 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005955 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005956 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005957 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005958 case STAC_9205_REF:
5959 /* SPDIF-In enabled */
5960 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005961 default:
5962 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005963 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005964 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005965 break;
5966 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005967
Matt Porterf3302a52006-07-31 12:49:34 +02005968 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005969 if (!err) {
5970 if (spec->board_config < 0) {
5971 printk(KERN_WARNING "hda_codec: No auto-config is "
5972 "available, default to model=ref\n");
5973 spec->board_config = STAC_9205_REF;
5974 goto again;
5975 }
5976 err = -EINVAL;
5977 }
Matt Porterf3302a52006-07-31 12:49:34 +02005978 if (err < 0) {
5979 stac92xx_free(codec);
5980 return err;
5981 }
5982
5983 codec->patch_ops = stac92xx_patch_ops;
5984
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005985 codec->proc_widget_hook = stac9205_proc_hook;
5986
Matt Porterf3302a52006-07-31 12:49:34 +02005987 return 0;
5988}
5989
Matt2f2f4252005-04-13 14:45:30 +02005990/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005991 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005992 */
5993
Takashi Iwai1e137f92009-01-21 07:41:22 +01005994static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02005995 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005996 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5997 {}
5998};
5999
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006000static hda_nid_t stac9872_pin_nids[] = {
6001 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
6002 0x11, 0x13, 0x14,
6003};
6004
6005static hda_nid_t stac9872_adc_nids[] = {
6006 0x8 /*,0x6*/
6007};
6008
6009static hda_nid_t stac9872_mux_nids[] = {
6010 0x15
6011};
6012
Takashi Iwai6479c632009-07-28 18:20:25 +02006013static unsigned long stac9872_capvols[] = {
6014 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
6015};
6016#define stac9872_capsws stac9872_capvols
6017
Takashi Iwai307282c2009-03-12 18:17:58 +01006018static unsigned int stac9872_vaio_pin_configs[9] = {
6019 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
6020 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
6021 0x90a7013e
6022};
6023
6024static const char *stac9872_models[STAC_9872_MODELS] = {
6025 [STAC_9872_AUTO] = "auto",
6026 [STAC_9872_VAIO] = "vaio",
6027};
6028
6029static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
6030 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
6031};
6032
6033static struct snd_pci_quirk stac9872_cfg_tbl[] = {
Takashi Iwaib04add92009-07-20 08:01:36 +02006034 SND_PCI_QUIRK_MASK(0x104d, 0xfff0, 0x81e0,
6035 "Sony VAIO F/S", STAC_9872_VAIO),
Takashi Iwai307282c2009-03-12 18:17:58 +01006036 {} /* terminator */
6037};
6038
Guillaume Munch6d859062006-08-22 17:15:47 +02006039static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01006040{
6041 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006042 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006043
Takashi Iwaidb064e52006-03-16 16:04:58 +01006044 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6045 if (spec == NULL)
6046 return -ENOMEM;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006047 codec->spec = spec;
Takashi Iwaib04add92009-07-20 08:01:36 +02006048 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
6049 spec->pin_nids = stac9872_pin_nids;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006050
6051 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
6052 stac9872_models,
6053 stac9872_cfg_tbl);
Takashi Iwai307282c2009-03-12 18:17:58 +01006054 if (spec->board_config < 0)
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02006055 snd_printdd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
6056 codec->chip_name);
Takashi Iwai307282c2009-03-12 18:17:58 +01006057 else
6058 stac92xx_set_config_regs(codec,
6059 stac9872_brd_tbl[spec->board_config]);
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006060
Takashi Iwai1e137f92009-01-21 07:41:22 +01006061 spec->multiout.dac_nids = spec->dac_nids;
6062 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
6063 spec->adc_nids = stac9872_adc_nids;
6064 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
6065 spec->mux_nids = stac9872_mux_nids;
Takashi Iwai1e137f92009-01-21 07:41:22 +01006066 spec->init = stac9872_core_init;
Takashi Iwai6479c632009-07-28 18:20:25 +02006067 spec->num_caps = 1;
6068 spec->capvols = stac9872_capvols;
6069 spec->capsws = stac9872_capsws;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006070
Takashi Iwai1e137f92009-01-21 07:41:22 +01006071 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
6072 if (err < 0) {
6073 stac92xx_free(codec);
6074 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01006075 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01006076 spec->input_mux = &spec->private_imux;
6077 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01006078 return 0;
6079}
6080
6081
6082/*
Matt2f2f4252005-04-13 14:45:30 +02006083 * patch entries
6084 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006085static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02006086 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
6087 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
6088 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
6089 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
6090 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
6091 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
6092 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02006093 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
6094 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
6095 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
6096 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
6097 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
6098 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01006099 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
6100 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
6101 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
6102 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
6103 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
6104 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
6105 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
6106 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
6107 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
6108 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01006109 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
6110 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
6111 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
6112 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
6113 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
6114 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02006115 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
6116 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02006117 /* The following does not take into account .id=0x83847661 when subsys =
6118 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
6119 * currently not fully supported.
6120 */
6121 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
6122 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
6123 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Simos Xenitellisa5c0f882009-06-10 16:33:31 +01006124 { .id = 0x83847698, .name = "STAC9205", .patch = patch_stac9205 },
Matt Porterf3302a52006-07-31 12:49:34 +02006125 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
6126 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
6127 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
6128 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
6129 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
6130 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
6131 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
6132 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006133 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02006134 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
6135 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayff2e7332009-04-01 14:49:48 -04006136 { .id = 0x111d76d5, .name = "92HD81B1C5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02006137 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01006138 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
6139 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01006140 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01006141 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6142 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
6143 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6144 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
6145 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6146 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
6147 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
6148 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02006149 {} /* terminator */
6150};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006151
6152MODULE_ALIAS("snd-hda-codec-id:8384*");
6153MODULE_ALIAS("snd-hda-codec-id:111d*");
6154
6155MODULE_LICENSE("GPL");
6156MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
6157
6158static struct hda_codec_preset_list sigmatel_list = {
6159 .preset = snd_hda_preset_sigmatel,
6160 .owner = THIS_MODULE,
6161};
6162
6163static int __init patch_sigmatel_init(void)
6164{
6165 return snd_hda_add_codec_preset(&sigmatel_list);
6166}
6167
6168static void __exit patch_sigmatel_exit(void)
6169{
6170 snd_hda_delete_codec_preset(&sigmatel_list);
6171}
6172
6173module_init(patch_sigmatel_init)
6174module_exit(patch_sigmatel_exit)