blob: 3fbe22053b3f09643992b4dd836ebce0b04ef119 [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,
43};
Matt4e550962005-07-04 17:51:39 +020044
Takashi Iwaif5fcc132006-11-24 17:07:44 +010045enum {
46 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010047 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020048 STAC_9200_DELL_D21,
49 STAC_9200_DELL_D22,
50 STAC_9200_DELL_D23,
51 STAC_9200_DELL_M21,
52 STAC_9200_DELL_M22,
53 STAC_9200_DELL_M23,
54 STAC_9200_DELL_M24,
55 STAC_9200_DELL_M25,
56 STAC_9200_DELL_M26,
57 STAC_9200_DELL_M27,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +020058 STAC_9200_M4,
59 STAC_9200_M4_2,
Takashi Iwai117f2572008-03-18 09:53:23 +010060 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010061 STAC_9200_MODELS
62};
63
64enum {
65 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020066 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020067 STAC_9205_DELL_M43,
68 STAC_9205_DELL_M44,
Takashi Iwaid9a42682009-01-22 17:40:18 +010069 STAC_9205_EAPD,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010070 STAC_9205_MODELS
71};
72
73enum {
Takashi Iwai9e43f0d2008-12-17 14:51:01 +010074 STAC_92HD73XX_NO_JD, /* no jack-detection */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010075 STAC_92HD73XX_REF,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010076 STAC_DELL_M6_AMIC,
77 STAC_DELL_M6_DMIC,
78 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050079 STAC_DELL_EQ,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010080 STAC_92HD73XX_MODELS
81};
82
83enum {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020084 STAC_92HD83XXX_REF,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -050085 STAC_92HD83XXX_PWR_REF,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020086 STAC_92HD83XXX_MODELS
87};
88
89enum {
Matthew Ranostaye035b842007-11-06 11:53:55 +010090 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010091 STAC_DELL_M4_1,
92 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -050093 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -040094 STAC_HP_M4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +010095 STAC_HP_DV5,
Matthew Ranostaye035b842007-11-06 11:53:55 +010096 STAC_92HD71BXX_MODELS
97};
98
99enum {
Tobin Davis8e21c342007-01-08 11:04:17 +0100100 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200101 STAC_M1,
102 STAC_M1_2,
103 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100104 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200105 STAC_M3,
106 STAC_M5,
107 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100108 STAC_925x_MODELS
109};
110
111enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100112 STAC_D945_REF,
113 STAC_D945GTP3,
114 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200115 STAC_INTEL_MAC_V1,
116 STAC_INTEL_MAC_V2,
117 STAC_INTEL_MAC_V3,
118 STAC_INTEL_MAC_V4,
119 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800120 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
121 * is given, one of the above models will be
122 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200123 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100124 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100125 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100126 STAC_MACBOOK_PRO_V1,
127 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200128 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200129 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300130 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200131 STAC_922X_DELL_D81,
132 STAC_922X_DELL_D82,
133 STAC_922X_DELL_M81,
134 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100135 STAC_922X_MODELS
136};
137
138enum {
Takashi Iwaie28d8322008-12-17 13:48:29 +0100139 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100140 STAC_D965_REF,
141 STAC_D965_3ST,
142 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200143 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100144 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100145 STAC_927X_MODELS
146};
Matt Porter403d1942005-11-29 15:00:51 +0100147
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400148struct sigmatel_event {
149 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100150 unsigned char type;
151 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400152 int data;
153};
154
155struct sigmatel_jack {
156 hda_nid_t nid;
157 int type;
158 struct snd_jack *jack;
159};
160
Matt2f2f4252005-04-13 14:45:30 +0200161struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100162 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200163 unsigned int num_mixers;
164
Matt Porter403d1942005-11-29 15:00:51 +0100165 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500166 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200167 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100168 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100169 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400170 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100171 unsigned int check_volume_offset:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200172
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100173 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200174 unsigned int eapd_mask;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100175 unsigned int gpio_mask;
176 unsigned int gpio_dir;
177 unsigned int gpio_data;
178 unsigned int gpio_mute;
179
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200180 /* stream */
181 unsigned int stream_delay;
182
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +0100183 /* analog loopback */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100184 unsigned char aloopback_mask;
185 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200186
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100187 /* power management */
188 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200189 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100190 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100191 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100192
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400193 /* jack detection */
194 struct snd_array jacks;
195
196 /* events */
197 struct snd_array events;
198
Matt2f2f4252005-04-13 14:45:30 +0200199 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100200 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400201 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100202 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200203 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100204 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100205 hda_nid_t hp_dacs[5];
206 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200207
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100208 int volume_offset;
209
Matt2f2f4252005-04-13 14:45:30 +0200210 /* capture */
211 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200212 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200213 hda_nid_t *mux_nids;
214 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200215 hda_nid_t *dmic_nids;
216 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100217 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100218 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200219 hda_nid_t *smux_nids;
220 unsigned int num_smuxes;
Matthew Ranostay65973632008-09-16 10:39:37 -0400221 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200222
Mattdabbed62005-06-14 10:19:34 +0200223 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100224 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200225 hda_nid_t anabeep_nid;
226 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200227
Matt2f2f4252005-04-13 14:45:30 +0200228 /* pin widgets */
229 hda_nid_t *pin_nids;
230 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200231 unsigned int *pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200232
233 /* codec specific stuff */
234 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100235 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200236
237 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200238 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100239 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200240 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100241 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200242 struct hda_input_mux *sinput_mux;
243 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400244 unsigned int cur_amux;
245 hda_nid_t *amp_nids;
246 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200247 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200248
Matt Porter403d1942005-11-29 15:00:51 +0100249 /* i/o switches */
250 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200251 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100252 hda_nid_t line_switch; /* shared line-in for input and output */
253 hda_nid_t mic_switch; /* shared mic-in for input and output */
254 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200255 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200256
Mattc7d4b2f2005-06-27 14:59:41 +0200257 struct hda_pcm pcm_rec[2]; /* PCM information */
258
259 /* dynamic controls and input_mux */
260 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200261 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200262 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200263 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200264 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400265 struct hda_input_mux private_amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100266 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200267};
268
269static hda_nid_t stac9200_adc_nids[1] = {
270 0x03,
271};
272
273static hda_nid_t stac9200_mux_nids[1] = {
274 0x0c,
275};
276
277static hda_nid_t stac9200_dac_nids[1] = {
278 0x02,
279};
280
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100281static hda_nid_t stac92hd73xx_pwr_nids[8] = {
282 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
283 0x0f, 0x10, 0x11
284};
285
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400286static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
287 0x26, 0,
288};
289
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100290static hda_nid_t stac92hd73xx_adc_nids[2] = {
291 0x1a, 0x1b
292};
293
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400294#define DELL_M6_AMP 2
295static hda_nid_t stac92hd73xx_amp_nids[3] = {
296 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400297};
298
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100299#define STAC92HD73XX_NUM_DMICS 2
300static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
301 0x13, 0x14, 0
302};
303
304#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100305
306static hda_nid_t stac92hd73xx_mux_nids[4] = {
307 0x28, 0x29, 0x2a, 0x2b,
308};
309
310static hda_nid_t stac92hd73xx_dmux_nids[2] = {
311 0x20, 0x21,
312};
313
Matthew Ranostayd9737752008-09-07 12:03:41 +0200314static hda_nid_t stac92hd73xx_smux_nids[2] = {
315 0x22, 0x23,
316};
317
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200318#define STAC92HD83XXX_NUM_DMICS 2
319static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
320 0x11, 0x12, 0
321};
322
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200323#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200324
325static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
326 0x17, 0x18,
327};
328
329static hda_nid_t stac92hd83xxx_adc_nids[2] = {
330 0x15, 0x16,
331};
332
333static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
334 0xa, 0xb, 0xd, 0xe,
335};
336
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400337static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
338 0x1e, 0,
339};
340
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200341static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay87e88a72009-01-22 20:38:42 -0500342 0x03, 0x0c, 0x20, 0x40,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200343};
344
Takashi Iwai9248f262009-01-14 09:40:25 +0100345static hda_nid_t stac92hd83xxx_amp_nids[1] = {
Matthew Ranostayc15c5062009-01-13 13:30:07 -0500346 0xc,
347};
348
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100349static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
350 0x0a, 0x0d, 0x0f
351};
352
Matthew Ranostaye035b842007-11-06 11:53:55 +0100353static hda_nid_t stac92hd71bxx_adc_nids[2] = {
354 0x12, 0x13,
355};
356
357static hda_nid_t stac92hd71bxx_mux_nids[2] = {
358 0x1a, 0x1b
359};
360
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400361static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
362 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100363};
364
Matthew Ranostayd9737752008-09-07 12:03:41 +0200365static hda_nid_t stac92hd71bxx_smux_nids[2] = {
366 0x24, 0x25,
367};
368
Matthew Ranostaye035b842007-11-06 11:53:55 +0100369#define STAC92HD71BXX_NUM_DMICS 2
370static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
371 0x18, 0x19, 0
372};
373
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400374static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
375 0x22, 0
376};
377
Tobin Davis8e21c342007-01-08 11:04:17 +0100378static hda_nid_t stac925x_adc_nids[1] = {
379 0x03,
380};
381
382static hda_nid_t stac925x_mux_nids[1] = {
383 0x0f,
384};
385
386static hda_nid_t stac925x_dac_nids[1] = {
387 0x02,
388};
389
Takashi Iwaif6e98522007-10-16 14:27:04 +0200390#define STAC925X_NUM_DMICS 1
391static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
392 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200393};
394
Takashi Iwai1697055e2007-12-18 18:05:52 +0100395static hda_nid_t stac925x_dmux_nids[1] = {
396 0x14,
397};
398
Matt2f2f4252005-04-13 14:45:30 +0200399static hda_nid_t stac922x_adc_nids[2] = {
400 0x06, 0x07,
401};
402
403static hda_nid_t stac922x_mux_nids[2] = {
404 0x12, 0x13,
405};
406
Matt Porter3cc08dc2006-01-23 15:27:49 +0100407static hda_nid_t stac927x_adc_nids[3] = {
408 0x07, 0x08, 0x09
409};
410
411static hda_nid_t stac927x_mux_nids[3] = {
412 0x15, 0x16, 0x17
413};
414
Matthew Ranostayd9737752008-09-07 12:03:41 +0200415static hda_nid_t stac927x_smux_nids[1] = {
416 0x21,
417};
418
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100419static hda_nid_t stac927x_dac_nids[6] = {
420 0x02, 0x03, 0x04, 0x05, 0x06, 0
421};
422
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100423static hda_nid_t stac927x_dmux_nids[1] = {
424 0x1b,
425};
426
Matthew Ranostay7f168592007-10-18 17:38:17 +0200427#define STAC927X_NUM_DMICS 2
428static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
429 0x13, 0x14, 0
430};
431
Matthew Ranostay65973632008-09-16 10:39:37 -0400432static const char *stac927x_spdif_labels[5] = {
433 "Digital Playback", "ADAT", "Analog Mux 1",
434 "Analog Mux 2", "Analog Mux 3"
435};
436
Matt Porterf3302a52006-07-31 12:49:34 +0200437static hda_nid_t stac9205_adc_nids[2] = {
438 0x12, 0x13
439};
440
441static hda_nid_t stac9205_mux_nids[2] = {
442 0x19, 0x1a
443};
444
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100445static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100446 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100447};
448
Matthew Ranostayd9737752008-09-07 12:03:41 +0200449static hda_nid_t stac9205_smux_nids[1] = {
450 0x21,
451};
452
Takashi Iwaif6e98522007-10-16 14:27:04 +0200453#define STAC9205_NUM_DMICS 2
454static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
455 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200456};
457
Mattc7d4b2f2005-06-27 14:59:41 +0200458static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200459 0x08, 0x09, 0x0d, 0x0e,
460 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200461};
462
Tobin Davis8e21c342007-01-08 11:04:17 +0100463static hda_nid_t stac925x_pin_nids[8] = {
464 0x07, 0x08, 0x0a, 0x0b,
465 0x0c, 0x0d, 0x10, 0x11,
466};
467
Matt2f2f4252005-04-13 14:45:30 +0200468static hda_nid_t stac922x_pin_nids[10] = {
469 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
470 0x0f, 0x10, 0x11, 0x15, 0x1b,
471};
472
Matthew Ranostaya7662642008-02-21 07:51:14 +0100473static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100474 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
475 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200476 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100477};
478
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200479static hda_nid_t stac92hd83xxx_pin_nids[14] = {
480 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
481 0x0f, 0x10, 0x11, 0x12, 0x13,
482 0x1d, 0x1e, 0x1f, 0x20
483};
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400484static hda_nid_t stac92hd71bxx_pin_nids[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100485 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
486 0x0f, 0x14, 0x18, 0x19, 0x1e,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400487 0x1f,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100488};
489
Matt Porter3cc08dc2006-01-23 15:27:49 +0100490static hda_nid_t stac927x_pin_nids[14] = {
491 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
492 0x0f, 0x10, 0x11, 0x12, 0x13,
493 0x14, 0x21, 0x22, 0x23,
494};
495
Matt Porterf3302a52006-07-31 12:49:34 +0200496static hda_nid_t stac9205_pin_nids[12] = {
497 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
498 0x0f, 0x14, 0x16, 0x17, 0x18,
499 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200500};
501
Matthew Ranostay89385032008-09-11 09:49:39 -0400502#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
503
504static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
505 struct snd_ctl_elem_value *ucontrol)
506{
507 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
508 struct sigmatel_spec *spec = codec->spec;
509 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
510
511 kcontrol->private_value ^= get_amp_nid(kcontrol);
512 kcontrol->private_value |= nid;
513
514 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
515}
516
517static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
518 struct snd_ctl_elem_value *ucontrol)
519{
520 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
521 struct sigmatel_spec *spec = codec->spec;
522 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
523
524 kcontrol->private_value ^= get_amp_nid(kcontrol);
525 kcontrol->private_value |= nid;
526
527 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
528}
529
Matt Porter8b657272006-10-26 17:12:59 +0200530static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
531 struct snd_ctl_elem_info *uinfo)
532{
533 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
534 struct sigmatel_spec *spec = codec->spec;
535 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
536}
537
538static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
539 struct snd_ctl_elem_value *ucontrol)
540{
541 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
542 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100543 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200544
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100545 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200546 return 0;
547}
548
549static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
550 struct snd_ctl_elem_value *ucontrol)
551{
552 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
553 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100554 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200555
556 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100557 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200558}
559
Matthew Ranostayd9737752008-09-07 12:03:41 +0200560static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
561 struct snd_ctl_elem_info *uinfo)
562{
563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
564 struct sigmatel_spec *spec = codec->spec;
565 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
566}
567
568static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
569 struct snd_ctl_elem_value *ucontrol)
570{
571 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
572 struct sigmatel_spec *spec = codec->spec;
573 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
574
575 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
576 return 0;
577}
578
579static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
580 struct snd_ctl_elem_value *ucontrol)
581{
582 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
583 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400584 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200585 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400586 int err, val;
587 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200588
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400589 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200590 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400591 if (err < 0)
592 return err;
593
594 if (spec->spdif_mute) {
595 if (smux_idx == 0)
596 nid = spec->multiout.dig_out_nid;
597 else
598 nid = codec->slave_dig_outs[smux_idx - 1];
599 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100600 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400601 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100602 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400603 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100604 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
605 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400606 }
607 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200608}
609
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100610static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200611{
612 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
613 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200614 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200615}
616
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100617static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200618{
619 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
620 struct sigmatel_spec *spec = codec->spec;
621 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
622
623 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
624 return 0;
625}
626
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100627static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200628{
629 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
630 struct sigmatel_spec *spec = codec->spec;
631 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
632
Mattc7d4b2f2005-06-27 14:59:41 +0200633 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200634 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
635}
636
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100637static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
638 struct snd_ctl_elem_info *uinfo)
639{
640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
641 struct sigmatel_spec *spec = codec->spec;
642 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
643}
644
645static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
646 struct snd_ctl_elem_value *ucontrol)
647{
648 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
649 struct sigmatel_spec *spec = codec->spec;
650
651 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
652 return 0;
653}
654
655static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
656 struct snd_ctl_elem_value *ucontrol)
657{
658 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
659 struct sigmatel_spec *spec = codec->spec;
660
661 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
662 spec->mono_nid, &spec->cur_mmux);
663}
664
Matthew Ranostay89385032008-09-11 09:49:39 -0400665static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
666 struct snd_ctl_elem_info *uinfo)
667{
668 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
669 struct sigmatel_spec *spec = codec->spec;
670 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
671}
672
673static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
674 struct snd_ctl_elem_value *ucontrol)
675{
676 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
677 struct sigmatel_spec *spec = codec->spec;
678
679 ucontrol->value.enumerated.item[0] = spec->cur_amux;
680 return 0;
681}
682
683static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
684 struct snd_ctl_elem_value *ucontrol)
685{
686 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
687 struct sigmatel_spec *spec = codec->spec;
688 struct snd_kcontrol *ctl =
689 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
690 if (!ctl)
691 return -EINVAL;
692
693 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
694 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
695
696 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
697 0, &spec->cur_amux);
698}
699
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200700#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
701
702static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
703 struct snd_ctl_elem_value *ucontrol)
704{
705 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100706 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200707 struct sigmatel_spec *spec = codec->spec;
708
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100709 ucontrol->value.integer.value[0] = !!(spec->aloopback &
710 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200711 return 0;
712}
713
714static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
715 struct snd_ctl_elem_value *ucontrol)
716{
717 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
718 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100719 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200720 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100721 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200722
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100723 idx_val = spec->aloopback_mask << idx;
724 if (ucontrol->value.integer.value[0])
725 val = spec->aloopback | idx_val;
726 else
727 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100728 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200729 return 0;
730
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100731 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200732
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100733 /* Only return the bits defined by the shift value of the
734 * first two bytes of the mask
735 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200736 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100737 kcontrol->private_value & 0xFFFF, 0x0);
738 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200739
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100740 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200741 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100742 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200743 } else {
744 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100745 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200746 }
747
748 snd_hda_codec_write_cache(codec, codec->afg, 0,
749 kcontrol->private_value >> 16, dac_mode);
750
751 return 1;
752}
753
Mattc7d4b2f2005-06-27 14:59:41 +0200754static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200755 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200756 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200757 {}
758};
759
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200760static struct hda_verb stac9200_eapd_init[] = {
761 /* set dac0mux for dac converter */
762 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
763 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
764 {}
765};
766
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100767static struct hda_verb stac92hd73xx_6ch_core_init[] = {
768 /* set master volume and direct control */
769 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100770 /* setup adcs to point to mixer */
771 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
772 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100773 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
774 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
775 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
776 /* setup import muxs */
777 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
778 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
779 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
780 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
781 {}
782};
783
Matthew Ranostayd654a662008-03-14 08:46:51 +0100784static struct hda_verb dell_eq_core_init[] = {
785 /* set master volume to max value without distortion
786 * and direct control */
787 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100788 /* setup adcs to point to mixer */
789 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
790 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
791 /* setup import muxs */
792 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
793 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
794 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
795 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
796 {}
797};
798
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100799static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500800 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100801 /* setup adcs to point to mixer */
802 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
803 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
804 /* setup import muxs */
805 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
806 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
807 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
808 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
809 {}
810};
811
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100812static struct hda_verb stac92hd73xx_8ch_core_init[] = {
813 /* set master volume and direct control */
814 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100815 /* setup adcs to point to mixer */
816 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
817 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100818 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
819 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
820 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
821 /* setup import muxs */
822 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
823 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
824 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
825 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
826 {}
827};
828
829static struct hda_verb stac92hd73xx_10ch_core_init[] = {
830 /* set master volume and direct control */
831 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100832 /* dac3 is connected to import3 mux */
833 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100834 /* setup adcs to point to mixer */
835 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
836 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100837 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
838 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
839 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
840 /* setup import muxs */
841 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
842 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
843 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
844 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
845 {}
846};
847
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200848static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200849 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0},
850 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0},
851 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1},
852
853 /* power state controls amps */
854 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200855 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200856};
857
Matthew Ranostaye035b842007-11-06 11:53:55 +0100858static struct hda_verb stac92hd71bxx_core_init[] = {
859 /* set master volume and direct control */
860 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100861 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
862 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
863 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
864 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200865 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100866};
867
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400868#define HD_DISABLE_PORTF 2
Matthew Ranostay541eee82007-12-14 12:08:04 +0100869static struct hda_verb stac92hd71bxx_analog_core_init[] = {
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200870 /* start of config #1 */
871
872 /* connect port 0f to audio mixer */
873 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200874 /* unmute right and left channels for node 0x0f */
875 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
876 /* start of config #2 */
877
Matthew Ranostay541eee82007-12-14 12:08:04 +0100878 /* set master volume and direct control */
879 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200880 /* unmute right and left channels for nodes 0x0a, 0xd */
Matthew Ranostaye035b842007-11-06 11:53:55 +0100881 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
882 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100883 {}
884};
885
Tobin Davis8e21c342007-01-08 11:04:17 +0100886static struct hda_verb stac925x_core_init[] = {
887 /* set dac0mux for dac converter */
888 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100889 /* mute the master volume */
890 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100891 {}
892};
893
Mattc7d4b2f2005-06-27 14:59:41 +0200894static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200895 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200896 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200897 {}
898};
899
Tobin Davis93ed1502006-09-01 21:03:12 +0200900static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200901 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200902 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200903 /* unmute node 0x1b */
904 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
905 /* select node 0x03 as DAC */
906 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
907 {}
908};
909
Matt Porter3cc08dc2006-01-23 15:27:49 +0100910static struct hda_verb stac927x_core_init[] = {
911 /* set master volume and direct control */
912 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200913 /* enable analog pc beep path */
914 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100915 {}
916};
917
Matt Porterf3302a52006-07-31 12:49:34 +0200918static struct hda_verb stac9205_core_init[] = {
919 /* set master volume and direct control */
920 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200921 /* enable analog pc beep path */
922 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200923 {}
924};
925
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100926#define STAC_MONO_MUX \
927 { \
928 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
929 .name = "Mono Mux", \
930 .count = 1, \
931 .info = stac92xx_mono_mux_enum_info, \
932 .get = stac92xx_mono_mux_enum_get, \
933 .put = stac92xx_mono_mux_enum_put, \
934 }
935
Matthew Ranostay89385032008-09-11 09:49:39 -0400936#define STAC_AMP_MUX \
937 { \
938 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
939 .name = "Amp Selector Capture Switch", \
940 .count = 1, \
941 .info = stac92xx_amp_mux_enum_info, \
942 .get = stac92xx_amp_mux_enum_get, \
943 .put = stac92xx_amp_mux_enum_put, \
944 }
945
946#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
947 { \
948 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
949 .name = xname, \
950 .index = 0, \
951 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
952 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
953 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
954 .info = stac92xx_amp_volume_info, \
955 .get = stac92xx_amp_volume_get, \
956 .put = stac92xx_amp_volume_put, \
957 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
958 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
959 }
960
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200961#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200962 { \
963 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
964 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200965 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200966 .info = stac92xx_mux_enum_info, \
967 .get = stac92xx_mux_enum_get, \
968 .put = stac92xx_mux_enum_put, \
969 }
970
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100971#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200972 { \
973 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
974 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100975 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200976 .info = stac92xx_aloopback_info, \
977 .get = stac92xx_aloopback_get, \
978 .put = stac92xx_aloopback_put, \
979 .private_value = verb_read | (verb_write << 16), \
980 }
981
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100982static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200983 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
984 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200985 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200986 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
987 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200988 { } /* end */
989};
990
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400991#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100992static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400993 /* start of config #1 */
994 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
995 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
996
997 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
998 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
999
1000 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1001 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1002
1003 /* start of config #2 */
1004 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1005 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1006
1007 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1008 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1009
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001010 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1011
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001012 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1013 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1014
1015 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1016 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1017
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001018 { } /* end */
1019};
1020
1021static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001022 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1023
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001024 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1025 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1026
1027 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1028 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1029
1030 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1031 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1032
1033 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1034 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1035
1036 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1037 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1038
1039 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1040 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1041
1042 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1043 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1044 { } /* end */
1045};
1046
1047static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001048 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1049
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001050 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1051 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1052
1053 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1054 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1055
1056 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1057 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1058
1059 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1060 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1061
1062 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1063 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1064
1065 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1066 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1067
1068 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1069 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1070 { } /* end */
1071};
1072
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001073
1074static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1075 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1076 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1077
1078 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1079 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1080
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001081 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1082 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001083
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001084 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1085 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001086
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001087 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1088 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001089
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001090 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1091 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001092
1093 /*
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001094 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1095 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001096 */
1097 { } /* end */
1098};
1099
Matthew Ranostay541eee82007-12-14 12:08:04 +01001100static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001101 STAC_INPUT_SOURCE(2),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001102 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001103
Matthew Ranostay9b359472007-11-07 13:03:12 +01001104 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1105 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay9b359472007-11-07 13:03:12 +01001106
1107 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1108 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001109 /* analog pc-beep replaced with digital beep support */
1110 /*
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001111 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1112 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001113 */
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001114
Matthew Ranostay687cb982008-10-11 13:52:43 -04001115 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1116 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001117
Matthew Ranostay687cb982008-10-11 13:52:43 -04001118 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1119 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001120
1121 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1122 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1123
1124 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1125 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001126 { } /* end */
1127};
1128
Matthew Ranostay541eee82007-12-14 12:08:04 +01001129static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +01001130 STAC_INPUT_SOURCE(2),
1131 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1132
Matthew Ranostay541eee82007-12-14 12:08:04 +01001133 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1134 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001135
1136 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1137 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001138 { } /* end */
1139};
1140
Tobin Davis8e21c342007-01-08 11:04:17 +01001141static struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwaic9280d62009-01-15 17:31:00 +01001142 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1143 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001144 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +01001145 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
Mauro Carvalho Chehab587755f2008-05-25 18:20:06 +02001146 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
Tobin Davis8e21c342007-01-08 11:04:17 +01001147 { } /* end */
1148};
1149
Takashi Iwaid1d985f2006-11-23 19:27:12 +01001150static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001151 STAC_INPUT_SOURCE(2),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001152 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001153
1154 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1155 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001156
1157 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1158 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001159 { } /* end */
1160};
1161
1162/* This needs to be generated dynamically based on sequence */
1163static struct snd_kcontrol_new stac922x_mixer[] = {
1164 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001165 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1166 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001167
1168 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1169 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001170 { } /* end */
1171};
1172
1173
1174static struct snd_kcontrol_new stac927x_mixer[] = {
1175 STAC_INPUT_SOURCE(3),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001176 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001177
1178 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1179 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001180
1181 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1182 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001183
1184 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1185 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +02001186 { } /* end */
1187};
1188
Takashi Iwai1697055e2007-12-18 18:05:52 +01001189static struct snd_kcontrol_new stac_dmux_mixer = {
1190 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1191 .name = "Digital Input Source",
1192 /* count set later */
1193 .info = stac92xx_dmux_enum_info,
1194 .get = stac92xx_dmux_enum_get,
1195 .put = stac92xx_dmux_enum_put,
1196};
1197
Matthew Ranostayd9737752008-09-07 12:03:41 +02001198static struct snd_kcontrol_new stac_smux_mixer = {
1199 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001200 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001201 /* count set later */
1202 .info = stac92xx_smux_enum_info,
1203 .get = stac92xx_smux_enum_get,
1204 .put = stac92xx_smux_enum_put,
1205};
1206
Takashi Iwai2134ea42008-01-10 16:53:55 +01001207static const char *slave_vols[] = {
1208 "Front Playback Volume",
1209 "Surround Playback Volume",
1210 "Center Playback Volume",
1211 "LFE Playback Volume",
1212 "Side Playback Volume",
1213 "Headphone Playback Volume",
1214 "Headphone Playback Volume",
1215 "Speaker Playback Volume",
1216 "External Speaker Playback Volume",
1217 "Speaker2 Playback Volume",
1218 NULL
1219};
1220
1221static const char *slave_sws[] = {
1222 "Front Playback Switch",
1223 "Surround Playback Switch",
1224 "Center Playback Switch",
1225 "LFE Playback Switch",
1226 "Side Playback Switch",
1227 "Headphone Playback Switch",
1228 "Headphone Playback Switch",
1229 "Speaker Playback Switch",
1230 "External Speaker Playback Switch",
1231 "Speaker2 Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001232 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001233 NULL
1234};
1235
Takashi Iwai603c4012008-07-30 15:01:44 +02001236static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001237static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001238
Matt2f2f4252005-04-13 14:45:30 +02001239static int stac92xx_build_controls(struct hda_codec *codec)
1240{
1241 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001242 struct auto_pin_cfg *cfg = &spec->autocfg;
1243 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001244 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001245 int i;
Matt2f2f4252005-04-13 14:45:30 +02001246
1247 err = snd_hda_add_new_ctls(codec, spec->mixer);
1248 if (err < 0)
1249 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001250
1251 for (i = 0; i < spec->num_mixers; i++) {
1252 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1253 if (err < 0)
1254 return err;
1255 }
Takashi Iwai1697055e2007-12-18 18:05:52 +01001256 if (spec->num_dmuxes > 0) {
1257 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001258 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001259 snd_ctl_new1(&stac_dmux_mixer, codec));
1260 if (err < 0)
1261 return err;
1262 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001263 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001264 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1265 struct hda_input_mux *smux = &spec->private_smux;
1266 /* check for mute support on SPDIF out */
1267 if (wcaps & AC_WCAP_OUT_AMP) {
1268 smux->items[smux->num_items].label = "Off";
1269 smux->items[smux->num_items].index = 0;
1270 smux->num_items++;
1271 spec->spdif_mute = 1;
1272 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001273 stac_smux_mixer.count = spec->num_smuxes;
Takashi Iwai4f2d23e2008-12-19 10:14:13 +01001274 err = snd_hda_ctl_add(codec,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001275 snd_ctl_new1(&stac_smux_mixer, codec));
1276 if (err < 0)
1277 return err;
1278 }
Mattc7d4b2f2005-06-27 14:59:41 +02001279
Mattdabbed62005-06-14 10:19:34 +02001280 if (spec->multiout.dig_out_nid) {
1281 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1282 if (err < 0)
1283 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001284 err = snd_hda_create_spdif_share_sw(codec,
1285 &spec->multiout);
1286 if (err < 0)
1287 return err;
1288 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001289 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001290 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001291 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1292 if (err < 0)
1293 return err;
1294 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001295
1296 /* if we have no master control, let's create it */
1297 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001298 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001299 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001300 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001301 /* correct volume offset */
1302 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001303 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001304 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001305 if (err < 0)
1306 return err;
1307 }
1308 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1309 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1310 NULL, slave_sws);
1311 if (err < 0)
1312 return err;
1313 }
1314
Takashi Iwai603c4012008-07-30 15:01:44 +02001315 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001316
1317 /* create jack input elements */
1318 if (spec->hp_detect) {
1319 for (i = 0; i < cfg->hp_outs; i++) {
1320 int type = SND_JACK_HEADPHONE;
1321 nid = cfg->hp_pins[i];
1322 /* jack detection */
1323 if (cfg->hp_outs == i)
1324 type |= SND_JACK_LINEOUT;
1325 err = stac92xx_add_jack(codec, nid, type);
1326 if (err < 0)
1327 return err;
1328 }
1329 }
1330 for (i = 0; i < cfg->line_outs; i++) {
1331 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1332 SND_JACK_LINEOUT);
1333 if (err < 0)
1334 return err;
1335 }
1336 for (i = 0; i < AUTO_PIN_LAST; i++) {
1337 nid = cfg->input_pins[i];
1338 if (nid) {
1339 err = stac92xx_add_jack(codec, nid,
1340 SND_JACK_MICROPHONE);
1341 if (err < 0)
1342 return err;
1343 }
1344 }
1345
Mattdabbed62005-06-14 10:19:34 +02001346 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001347}
1348
Matt Porter403d1942005-11-29 15:00:51 +01001349static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001350 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001351 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1352};
1353
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001354static unsigned int gateway9200_m4_pin_configs[8] = {
1355 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1356 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1357};
1358static unsigned int gateway9200_m4_2_pin_configs[8] = {
1359 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1360 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1361};
1362
1363/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001364 STAC 9200 pin configs for
1365 102801A8
1366 102801DE
1367 102801E8
1368*/
1369static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001370 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1371 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001372};
1373
1374/*
1375 STAC 9200 pin configs for
1376 102801C0
1377 102801C1
1378*/
1379static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001380 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1381 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001382};
1383
1384/*
1385 STAC 9200 pin configs for
1386 102801C4 (Dell Dimension E310)
1387 102801C5
1388 102801C7
1389 102801D9
1390 102801DA
1391 102801E3
1392*/
1393static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001394 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1395 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001396};
1397
1398
1399/*
1400 STAC 9200-32 pin configs for
1401 102801B5 (Dell Inspiron 630m)
1402 102801D8 (Dell Inspiron 640m)
1403*/
1404static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001405 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1406 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001407};
1408
1409/*
1410 STAC 9200-32 pin configs for
1411 102801C2 (Dell Latitude D620)
1412 102801C8
1413 102801CC (Dell Latitude D820)
1414 102801D4
1415 102801D6
1416*/
1417static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001418 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1419 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001420};
1421
1422/*
1423 STAC 9200-32 pin configs for
1424 102801CE (Dell XPS M1710)
1425 102801CF (Dell Precision M90)
1426*/
1427static unsigned int dell9200_m23_pin_configs[8] = {
1428 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1429 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1430};
1431
1432/*
1433 STAC 9200-32 pin configs for
1434 102801C9
1435 102801CA
1436 102801CB (Dell Latitude 120L)
1437 102801D3
1438*/
1439static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001440 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1441 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001442};
1443
1444/*
1445 STAC 9200-32 pin configs for
1446 102801BD (Dell Inspiron E1505n)
1447 102801EE
1448 102801EF
1449*/
1450static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001451 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1452 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001453};
1454
1455/*
1456 STAC 9200-32 pin configs for
1457 102801F5 (Dell Inspiron 1501)
1458 102801F6
1459*/
1460static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001461 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1462 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001463};
1464
1465/*
1466 STAC 9200-32
1467 102801CD (Dell Inspiron E1705/9400)
1468*/
1469static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001470 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1471 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001472};
1473
Tobin Davisbf277782008-02-03 20:31:47 +01001474static unsigned int oqo9200_pin_configs[8] = {
1475 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1476 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1477};
1478
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001479
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001480static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1481 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001482 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001483 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1484 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1485 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1486 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1487 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1488 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1489 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1490 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1491 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1492 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001493 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1494 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001495 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001496};
1497
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001498static const char *stac9200_models[STAC_9200_MODELS] = {
1499 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001500 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001501 [STAC_9200_DELL_D21] = "dell-d21",
1502 [STAC_9200_DELL_D22] = "dell-d22",
1503 [STAC_9200_DELL_D23] = "dell-d23",
1504 [STAC_9200_DELL_M21] = "dell-m21",
1505 [STAC_9200_DELL_M22] = "dell-m22",
1506 [STAC_9200_DELL_M23] = "dell-m23",
1507 [STAC_9200_DELL_M24] = "dell-m24",
1508 [STAC_9200_DELL_M25] = "dell-m25",
1509 [STAC_9200_DELL_M26] = "dell-m26",
1510 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001511 [STAC_9200_M4] = "gateway-m4",
1512 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001513 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001514};
1515
1516static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1517 /* SigmaTel reference board */
1518 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1519 "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001520 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1521 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001522 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001523 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1524 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001525 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001526 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1527 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1528 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1529 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1530 "unknown Dell", STAC_9200_DELL_D22),
1531 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1532 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001533 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001534 "Dell Latitude D620", STAC_9200_DELL_M22),
1535 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1536 "unknown Dell", STAC_9200_DELL_D23),
1537 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1538 "unknown Dell", STAC_9200_DELL_D23),
1539 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1540 "unknown Dell", STAC_9200_DELL_M22),
1541 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1542 "unknown Dell", STAC_9200_DELL_M24),
1543 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1544 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001545 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001546 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001547 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001548 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001549 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001550 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001551 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001552 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001553 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001554 "Dell Precision M90", STAC_9200_DELL_M23),
1555 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1556 "unknown Dell", STAC_9200_DELL_M22),
1557 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1558 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001559 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001560 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001561 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001562 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1563 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1564 "unknown Dell", STAC_9200_DELL_D23),
1565 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1566 "unknown Dell", STAC_9200_DELL_D23),
1567 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1568 "unknown Dell", STAC_9200_DELL_D21),
1569 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1570 "unknown Dell", STAC_9200_DELL_D23),
1571 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1572 "unknown Dell", STAC_9200_DELL_D21),
1573 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1574 "unknown Dell", STAC_9200_DELL_M25),
1575 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1576 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001577 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001578 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1579 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1580 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001581 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001582 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001583 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001584 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1585 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1586 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001587 /* OQO Mobile */
1588 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001589 {} /* terminator */
1590};
1591
Tobin Davis8e21c342007-01-08 11:04:17 +01001592static unsigned int ref925x_pin_configs[8] = {
1593 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001594 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001595};
1596
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001597static unsigned int stac925xM1_pin_configs[8] = {
1598 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1599 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001600};
1601
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001602static unsigned int stac925xM1_2_pin_configs[8] = {
1603 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1604 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1605};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001606
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001607static unsigned int stac925xM2_pin_configs[8] = {
1608 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1609 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001610};
1611
Tobin Davis8e21c342007-01-08 11:04:17 +01001612static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001613 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1614 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1615};
1616
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001617static unsigned int stac925xM3_pin_configs[8] = {
1618 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1619 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1620};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001621
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001622static unsigned int stac925xM5_pin_configs[8] = {
1623 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1624 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1625};
1626
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001627static unsigned int stac925xM6_pin_configs[8] = {
1628 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1629 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001630};
1631
1632static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1633 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001634 [STAC_M1] = stac925xM1_pin_configs,
1635 [STAC_M1_2] = stac925xM1_2_pin_configs,
1636 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001637 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001638 [STAC_M3] = stac925xM3_pin_configs,
1639 [STAC_M5] = stac925xM5_pin_configs,
1640 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001641};
1642
1643static const char *stac925x_models[STAC_925x_MODELS] = {
1644 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001645 [STAC_M1] = "m1",
1646 [STAC_M1_2] = "m1-2",
1647 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001648 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001649 [STAC_M3] = "m3",
1650 [STAC_M5] = "m5",
1651 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001652};
1653
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001654static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001655 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1656 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1657 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1658 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001659 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001660 /* Not sure about the brand name for those */
1661 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1662 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1663 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1664 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001665 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001666};
1667
1668static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1669 /* SigmaTel reference board */
1670 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001671 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001672 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001673
1674 /* Default table for unknown ID */
1675 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1676
Tobin Davis8e21c342007-01-08 11:04:17 +01001677 {} /* terminator */
1678};
1679
Matthew Ranostaya7662642008-02-21 07:51:14 +01001680static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001681 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1682 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1683 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001684 0x01452050,
1685};
1686
1687static unsigned int dell_m6_pin_configs[13] = {
1688 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001689 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001690 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1691 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001692};
1693
1694static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001695 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001696 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1697 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1698 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001699 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001700};
1701
1702static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001703 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001704 [STAC_92HD73XX_REF] = "ref",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001705 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1706 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1707 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001708 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001709};
1710
1711static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1712 /* SigmaTel reference board */
1713 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001714 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001715 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1716 "DFI LanParty", STAC_92HD73XX_REF),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001717 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001718 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001719 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001720 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001721 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001722 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001723 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001724 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001725 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001726 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001727 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001728 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001729 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001730 "unknown Dell", STAC_DELL_M6_DMIC),
1731 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1732 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001733 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001734 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001735 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1736 "Dell Studio 17", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001737 {} /* terminator */
1738};
1739
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001740static unsigned int ref92hd83xxx_pin_configs[14] = {
1741 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1742 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1743 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1744 0x01451160, 0x98560170,
1745};
1746
1747static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1748 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001749 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001750};
1751
1752static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1753 [STAC_92HD83XXX_REF] = "ref",
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05001754 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001755};
1756
1757static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1758 /* SigmaTel reference board */
1759 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001760 "DFI LanParty", STAC_92HD83XXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001761 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1762 "DFI LanParty", STAC_92HD83XXX_REF),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001763 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001764};
1765
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001766static unsigned int ref92hd71bxx_pin_configs[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001767 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001768 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001769 0x90a000f0, 0x01452050, 0x01452050,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001770};
1771
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001772static unsigned int dell_m4_1_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001773 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001774 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001775 0x40f000f0, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001776};
1777
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001778static unsigned int dell_m4_2_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001779 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1780 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001781 0x40f000f0, 0x044413b0, 0x044413b0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001782};
1783
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001784static unsigned int dell_m4_3_pin_configs[11] = {
1785 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1786 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1787 0x40f000f0, 0x044413b0, 0x044413b0,
1788};
1789
Matthew Ranostaye035b842007-11-06 11:53:55 +01001790static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1791 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001792 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1793 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001794 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001795 [STAC_HP_M4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001796 [STAC_HP_DV5] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001797};
1798
1799static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1800 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001801 [STAC_DELL_M4_1] = "dell-m4-1",
1802 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001803 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001804 [STAC_HP_M4] = "hp-m4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001805 [STAC_HP_DV5] = "hp-dv5",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001806};
1807
1808static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1809 /* SigmaTel reference board */
1810 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1811 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05001812 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1813 "DFI LanParty", STAC_92HD71BXX_REF),
Takashi Iwai80bf2722008-11-18 10:48:41 +01001814 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f2,
1815 "HP dv5", STAC_HP_M4),
1816 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4,
1817 "HP dv7", STAC_HP_M4),
Takashi Iwaie0c0e942009-01-22 12:58:11 +01001818 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f7,
1819 "HP dv4", STAC_HP_DV5),
Takashi Iwai69dfaef2008-12-20 16:57:50 +01001820 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fc,
1821 "HP dv7", STAC_HP_M4),
Giuseppe Bilottadafb70c2009-01-13 08:58:49 -05001822 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3603,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001823 "HP dv5", STAC_HP_DV5),
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001824 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1825 "unknown HP", STAC_HP_M4),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001826 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1827 "unknown Dell", STAC_DELL_M4_1),
1828 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1829 "unknown Dell", STAC_DELL_M4_1),
1830 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1831 "unknown Dell", STAC_DELL_M4_1),
1832 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1833 "unknown Dell", STAC_DELL_M4_1),
1834 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1835 "unknown Dell", STAC_DELL_M4_1),
1836 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1837 "unknown Dell", STAC_DELL_M4_1),
1838 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1839 "unknown Dell", STAC_DELL_M4_1),
1840 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1841 "unknown Dell", STAC_DELL_M4_2),
1842 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1843 "unknown Dell", STAC_DELL_M4_2),
1844 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1845 "unknown Dell", STAC_DELL_M4_2),
1846 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1847 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001848 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1849 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001850 {} /* terminator */
1851};
1852
Matt Porter403d1942005-11-29 15:00:51 +01001853static unsigned int ref922x_pin_configs[10] = {
1854 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1855 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001856 0x40000100, 0x40000100,
1857};
1858
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001859/*
1860 STAC 922X pin configs for
1861 102801A7
1862 102801AB
1863 102801A9
1864 102801D1
1865 102801D2
1866*/
1867static unsigned int dell_922x_d81_pin_configs[10] = {
1868 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1869 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1870 0x01813122, 0x400001f2,
1871};
1872
1873/*
1874 STAC 922X pin configs for
1875 102801AC
1876 102801D0
1877*/
1878static unsigned int dell_922x_d82_pin_configs[10] = {
1879 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1880 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1881 0x01813122, 0x400001f1,
1882};
1883
1884/*
1885 STAC 922X pin configs for
1886 102801BF
1887*/
1888static unsigned int dell_922x_m81_pin_configs[10] = {
1889 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1890 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1891 0x40C003f1, 0x405003f0,
1892};
1893
1894/*
1895 STAC 9221 A1 pin configs for
1896 102801D7 (Dell XPS M1210)
1897*/
1898static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001899 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1900 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001901 0x508003f3, 0x405003f4,
1902};
1903
Matt Porter403d1942005-11-29 15:00:51 +01001904static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001905 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001906 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1907 0x02a19120, 0x40000100,
1908};
1909
1910static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001911 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1912 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001913 0x02a19320, 0x40000100,
1914};
1915
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001916static unsigned int intel_mac_v1_pin_configs[10] = {
1917 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1918 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001919 0x400000fc, 0x400000fb,
1920};
1921
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001922static unsigned int intel_mac_v2_pin_configs[10] = {
1923 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1924 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001925 0x400000fc, 0x400000fb,
1926};
1927
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001928static unsigned int intel_mac_v3_pin_configs[10] = {
1929 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1930 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1931 0x400000fc, 0x400000fb,
1932};
1933
1934static unsigned int intel_mac_v4_pin_configs[10] = {
1935 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1936 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1937 0x400000fc, 0x400000fb,
1938};
1939
1940static unsigned int intel_mac_v5_pin_configs[10] = {
1941 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1942 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1943 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001944};
1945
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001946static unsigned int ecs202_pin_configs[10] = {
1947 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1948 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1949 0x9037012e, 0x40e000f2,
1950};
Takashi Iwai76c08822007-06-19 12:17:42 +02001951
Takashi Iwai19039bd2006-06-28 15:52:16 +02001952static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001953 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001954 [STAC_D945GTP3] = d945gtp3_pin_configs,
1955 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001956 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1957 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1958 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1959 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1960 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001961 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001962 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001963 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1964 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1965 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1966 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1967 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1968 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001969 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001970 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1971 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1972 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1973 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001974};
1975
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001976static const char *stac922x_models[STAC_922X_MODELS] = {
1977 [STAC_D945_REF] = "ref",
1978 [STAC_D945GTP5] = "5stack",
1979 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001980 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1981 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1982 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1983 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1984 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001985 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001986 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001987 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001988 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001989 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1990 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001991 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001992 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001993 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001994 [STAC_922X_DELL_D81] = "dell-d81",
1995 [STAC_922X_DELL_D82] = "dell-d82",
1996 [STAC_922X_DELL_M81] = "dell-m81",
1997 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001998};
1999
2000static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2001 /* SigmaTel reference board */
2002 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2003 "DFI LanParty", STAC_D945_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002004 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2005 "DFI LanParty", STAC_D945_REF),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002006 /* Intel 945G based systems */
2007 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
2008 "Intel D945G", STAC_D945GTP3),
2009 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
2010 "Intel D945G", STAC_D945GTP3),
2011 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
2012 "Intel D945G", STAC_D945GTP3),
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2014 "Intel D945G", STAC_D945GTP3),
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2016 "Intel D945G", STAC_D945GTP3),
2017 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2018 "Intel D945G", STAC_D945GTP3),
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2020 "Intel D945G", STAC_D945GTP3),
2021 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2022 "Intel D945G", STAC_D945GTP3),
2023 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2024 "Intel D945G", STAC_D945GTP3),
2025 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2026 "Intel D945G", STAC_D945GTP3),
2027 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2028 "Intel D945G", STAC_D945GTP3),
2029 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2030 "Intel D945G", STAC_D945GTP3),
2031 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2032 "Intel D945G", STAC_D945GTP3),
2033 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2034 "Intel D945G", STAC_D945GTP3),
2035 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2036 "Intel D945G", STAC_D945GTP3),
2037 /* Intel D945G 5-stack systems */
2038 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2039 "Intel D945G", STAC_D945GTP5),
2040 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2041 "Intel D945G", STAC_D945GTP5),
2042 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2043 "Intel D945G", STAC_D945GTP5),
2044 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2045 "Intel D945G", STAC_D945GTP5),
2046 /* Intel 945P based systems */
2047 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2048 "Intel D945P", STAC_D945GTP3),
2049 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2050 "Intel D945P", STAC_D945GTP3),
2051 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2052 "Intel D945P", STAC_D945GTP3),
2053 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2054 "Intel D945P", STAC_D945GTP3),
2055 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2056 "Intel D945P", STAC_D945GTP3),
2057 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2058 "Intel D945P", STAC_D945GTP5),
2059 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002060 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002061 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002062 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002063 /* Dell systems */
2064 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2065 "unknown Dell", STAC_922X_DELL_D81),
2066 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2067 "unknown Dell", STAC_922X_DELL_D81),
2068 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2069 "unknown Dell", STAC_922X_DELL_D81),
2070 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2071 "unknown Dell", STAC_922X_DELL_D82),
2072 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2073 "unknown Dell", STAC_922X_DELL_M81),
2074 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2075 "unknown Dell", STAC_922X_DELL_D82),
2076 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2077 "unknown Dell", STAC_922X_DELL_D81),
2078 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2079 "unknown Dell", STAC_922X_DELL_D81),
2080 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2081 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002082 /* ECS/PC Chips boards */
2083 SND_PCI_QUIRK(0x1019, 0x2144,
2084 "ECS/PC chips", STAC_ECS_202),
2085 SND_PCI_QUIRK(0x1019, 0x2608,
2086 "ECS/PC chips", STAC_ECS_202),
2087 SND_PCI_QUIRK(0x1019, 0x2633,
2088 "ECS/PC chips P17G/1333", STAC_ECS_202),
2089 SND_PCI_QUIRK(0x1019, 0x2811,
2090 "ECS/PC chips", STAC_ECS_202),
2091 SND_PCI_QUIRK(0x1019, 0x2812,
2092 "ECS/PC chips", STAC_ECS_202),
2093 SND_PCI_QUIRK(0x1019, 0x2813,
2094 "ECS/PC chips", STAC_ECS_202),
2095 SND_PCI_QUIRK(0x1019, 0x2814,
2096 "ECS/PC chips", STAC_ECS_202),
2097 SND_PCI_QUIRK(0x1019, 0x2815,
2098 "ECS/PC chips", STAC_ECS_202),
2099 SND_PCI_QUIRK(0x1019, 0x2816,
2100 "ECS/PC chips", STAC_ECS_202),
2101 SND_PCI_QUIRK(0x1019, 0x2817,
2102 "ECS/PC chips", STAC_ECS_202),
2103 SND_PCI_QUIRK(0x1019, 0x2818,
2104 "ECS/PC chips", STAC_ECS_202),
2105 SND_PCI_QUIRK(0x1019, 0x2819,
2106 "ECS/PC chips", STAC_ECS_202),
2107 SND_PCI_QUIRK(0x1019, 0x2820,
2108 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002109 {} /* terminator */
2110};
2111
Matt Porter3cc08dc2006-01-23 15:27:49 +01002112static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002113 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2114 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2115 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2116 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002117};
2118
Tobin Davis93ed1502006-09-01 21:03:12 +02002119static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002120 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2121 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2122 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2123 0x40000100, 0x40000100
2124};
2125
Tobin Davis93ed1502006-09-01 21:03:12 +02002126static unsigned int d965_5st_pin_configs[14] = {
2127 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2128 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2129 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2130 0x40000100, 0x40000100
2131};
2132
Tobin Davis4ff076e2007-08-07 11:48:12 +02002133static unsigned int dell_3st_pin_configs[14] = {
2134 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2135 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002136 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002137 0x40c003fc, 0x40000100
2138};
2139
Tobin Davis93ed1502006-09-01 21:03:12 +02002140static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002141 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002142 [STAC_D965_REF] = ref927x_pin_configs,
2143 [STAC_D965_3ST] = d965_3st_pin_configs,
2144 [STAC_D965_5ST] = d965_5st_pin_configs,
2145 [STAC_DELL_3ST] = dell_3st_pin_configs,
2146 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002147};
2148
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002149static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002150 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002151 [STAC_D965_REF] = "ref",
2152 [STAC_D965_3ST] = "3stack",
2153 [STAC_D965_5ST] = "5stack",
2154 [STAC_DELL_3ST] = "dell-3stack",
2155 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002156};
2157
2158static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2159 /* SigmaTel reference board */
2160 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2161 "DFI LanParty", STAC_D965_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002162 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2163 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002164 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002165 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2166 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002167 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002168 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
2169 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
2170 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
2171 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
2172 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
2173 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
2174 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
2175 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
2176 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
2177 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
2178 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
2179 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
2180 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
2181 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
2182 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
2183 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002184 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002185 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002186 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002187 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2188 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002189 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002190 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2191 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002192 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Takashi Iwai24918b62008-09-30 12:58:54 +02002193 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002194 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2195 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2196 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2197 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002198 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002199 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
2200 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
2201 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
2202 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
2203 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
2204 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
2205 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
2206 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
2207 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002208 {} /* terminator */
2209};
2210
Matt Porterf3302a52006-07-31 12:49:34 +02002211static unsigned int ref9205_pin_configs[12] = {
2212 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002213 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002214 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002215};
2216
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002217/*
2218 STAC 9205 pin configs for
2219 102801F1
2220 102801F2
2221 102801FC
2222 102801FD
2223 10280204
2224 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002225 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002226*/
2227static unsigned int dell_9205_m42_pin_configs[12] = {
2228 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2229 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2230 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2231};
2232
2233/*
2234 STAC 9205 pin configs for
2235 102801F9
2236 102801FA
2237 102801FE
2238 102801FF (Dell Precision M4300)
2239 10280206
2240 10280200
2241 10280201
2242*/
2243static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002244 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2245 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2246 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2247};
2248
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002249static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002250 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2251 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2252 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2253};
2254
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002255static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002256 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002257 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2258 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2259 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002260 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002261};
2262
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002263static const char *stac9205_models[STAC_9205_MODELS] = {
2264 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002265 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002266 [STAC_9205_DELL_M43] = "dell-m43",
2267 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002268 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002269};
2270
2271static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2272 /* SigmaTel reference board */
2273 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2274 "DFI LanParty", STAC_9205_REF),
Matthew Ranostay577aa2c2009-01-22 22:55:44 -05002275 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2276 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002277 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002278 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2279 "unknown Dell", STAC_9205_DELL_M42),
2280 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2281 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002282 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002283 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002284 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2285 "Dell Precision", STAC_9205_DELL_M43),
2286 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2287 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002288 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2289 "unknown Dell", STAC_9205_DELL_M42),
2290 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2291 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002292 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2293 "Dell Precision", STAC_9205_DELL_M43),
2294 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002295 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002296 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2297 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002298 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2299 "Dell Precision", STAC_9205_DELL_M43),
2300 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2301 "Dell Precision", STAC_9205_DELL_M43),
2302 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2303 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002304 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2305 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002306 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2307 "Dell Vostro 1500", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002308 /* Gateway */
2309 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002310 {} /* terminator */
2311};
2312
Richard Fish11b44bb2006-08-23 18:31:34 +02002313static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2314{
2315 int i;
2316 struct sigmatel_spec *spec = codec->spec;
2317
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002318 kfree(spec->pin_configs);
2319 spec->pin_configs = kcalloc(spec->num_pins, sizeof(*spec->pin_configs),
2320 GFP_KERNEL);
2321 if (!spec->pin_configs)
2322 return -ENOMEM;
Richard Fish11b44bb2006-08-23 18:31:34 +02002323
2324 for (i = 0; i < spec->num_pins; i++) {
2325 hda_nid_t nid = spec->pin_nids[i];
2326 unsigned int pin_cfg;
2327
2328 pin_cfg = snd_hda_codec_read(codec, nid, 0,
2329 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2330 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2331 nid, pin_cfg);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002332 spec->pin_configs[i] = pin_cfg;
Richard Fish11b44bb2006-08-23 18:31:34 +02002333 }
2334
2335 return 0;
2336}
2337
Matthew Ranostay87d48362007-07-17 11:52:24 +02002338static void stac92xx_set_config_reg(struct hda_codec *codec,
2339 hda_nid_t pin_nid, unsigned int pin_config)
2340{
2341 int i;
2342 snd_hda_codec_write(codec, pin_nid, 0,
2343 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2344 pin_config & 0x000000ff);
2345 snd_hda_codec_write(codec, pin_nid, 0,
2346 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2347 (pin_config & 0x0000ff00) >> 8);
2348 snd_hda_codec_write(codec, pin_nid, 0,
2349 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2350 (pin_config & 0x00ff0000) >> 16);
2351 snd_hda_codec_write(codec, pin_nid, 0,
2352 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2353 pin_config >> 24);
2354 i = snd_hda_codec_read(codec, pin_nid, 0,
2355 AC_VERB_GET_CONFIG_DEFAULT,
2356 0x00);
2357 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
2358 pin_nid, i);
2359}
2360
Matt2f2f4252005-04-13 14:45:30 +02002361static void stac92xx_set_config_regs(struct hda_codec *codec)
2362{
2363 int i;
2364 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002365
Matthew Ranostay87d48362007-07-17 11:52:24 +02002366 if (!spec->pin_configs)
2367 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002368
Matthew Ranostay87d48362007-07-17 11:52:24 +02002369 for (i = 0; i < spec->num_pins; i++)
2370 stac92xx_set_config_reg(codec, spec->pin_nids[i],
2371 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02002372}
Matt2f2f4252005-04-13 14:45:30 +02002373
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002374static int stac_save_pin_cfgs(struct hda_codec *codec, unsigned int *pins)
2375{
2376 struct sigmatel_spec *spec = codec->spec;
2377
2378 if (!pins)
2379 return stac92xx_save_bios_config_regs(codec);
2380
2381 kfree(spec->pin_configs);
2382 spec->pin_configs = kmemdup(pins,
2383 spec->num_pins * sizeof(*pins),
2384 GFP_KERNEL);
2385 if (!spec->pin_configs)
2386 return -ENOMEM;
2387
2388 stac92xx_set_config_regs(codec);
2389 return 0;
2390}
2391
2392static void stac_change_pin_config(struct hda_codec *codec, hda_nid_t nid,
2393 unsigned int cfg)
2394{
2395 struct sigmatel_spec *spec = codec->spec;
2396 int i;
2397
2398 for (i = 0; i < spec->num_pins; i++) {
2399 if (spec->pin_nids[i] == nid) {
2400 spec->pin_configs[i] = cfg;
2401 stac92xx_set_config_reg(codec, nid, cfg);
2402 break;
2403 }
2404 }
2405}
2406
Matt2f2f4252005-04-13 14:45:30 +02002407/*
2408 * Analog playback callbacks
2409 */
2410static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2411 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002412 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002413{
2414 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002415 if (spec->stream_delay)
2416 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002417 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2418 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002419}
2420
2421static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2422 struct hda_codec *codec,
2423 unsigned int stream_tag,
2424 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002425 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002426{
2427 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002428 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002429}
2430
2431static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2432 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002433 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002434{
2435 struct sigmatel_spec *spec = codec->spec;
2436 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2437}
2438
2439/*
Mattdabbed62005-06-14 10:19:34 +02002440 * Digital playback callbacks
2441 */
2442static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2443 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002444 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002445{
2446 struct sigmatel_spec *spec = codec->spec;
2447 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2448}
2449
2450static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2451 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002452 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002453{
2454 struct sigmatel_spec *spec = codec->spec;
2455 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2456}
2457
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002458static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2459 struct hda_codec *codec,
2460 unsigned int stream_tag,
2461 unsigned int format,
2462 struct snd_pcm_substream *substream)
2463{
2464 struct sigmatel_spec *spec = codec->spec;
2465 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2466 stream_tag, format, substream);
2467}
2468
Mattdabbed62005-06-14 10:19:34 +02002469
2470/*
Matt2f2f4252005-04-13 14:45:30 +02002471 * Analog capture callbacks
2472 */
2473static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2474 struct hda_codec *codec,
2475 unsigned int stream_tag,
2476 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002477 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002478{
2479 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002480 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002481
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002482 if (spec->powerdown_adcs) {
2483 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002484 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002485 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2486 }
2487 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002488 return 0;
2489}
2490
2491static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2492 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002493 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002494{
2495 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002496 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002497
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002498 snd_hda_codec_cleanup_stream(codec, nid);
2499 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002500 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002501 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002502 return 0;
2503}
2504
Mattdabbed62005-06-14 10:19:34 +02002505static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2506 .substreams = 1,
2507 .channels_min = 2,
2508 .channels_max = 2,
2509 /* NID is set in stac92xx_build_pcms */
2510 .ops = {
2511 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002512 .close = stac92xx_dig_playback_pcm_close,
2513 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02002514 },
2515};
2516
2517static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2518 .substreams = 1,
2519 .channels_min = 2,
2520 .channels_max = 2,
2521 /* NID is set in stac92xx_build_pcms */
2522};
2523
Matt2f2f4252005-04-13 14:45:30 +02002524static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2525 .substreams = 1,
2526 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002527 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002528 .nid = 0x02, /* NID to query formats and rates */
2529 .ops = {
2530 .open = stac92xx_playback_pcm_open,
2531 .prepare = stac92xx_playback_pcm_prepare,
2532 .cleanup = stac92xx_playback_pcm_cleanup
2533 },
2534};
2535
Matt Porter3cc08dc2006-01-23 15:27:49 +01002536static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2537 .substreams = 1,
2538 .channels_min = 2,
2539 .channels_max = 2,
2540 .nid = 0x06, /* NID to query formats and rates */
2541 .ops = {
2542 .open = stac92xx_playback_pcm_open,
2543 .prepare = stac92xx_playback_pcm_prepare,
2544 .cleanup = stac92xx_playback_pcm_cleanup
2545 },
2546};
2547
Matt2f2f4252005-04-13 14:45:30 +02002548static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002549 .channels_min = 2,
2550 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002551 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002552 .ops = {
2553 .prepare = stac92xx_capture_pcm_prepare,
2554 .cleanup = stac92xx_capture_pcm_cleanup
2555 },
2556};
2557
2558static int stac92xx_build_pcms(struct hda_codec *codec)
2559{
2560 struct sigmatel_spec *spec = codec->spec;
2561 struct hda_pcm *info = spec->pcm_rec;
2562
2563 codec->num_pcms = 1;
2564 codec->pcm_info = info;
2565
Mattc7d4b2f2005-06-27 14:59:41 +02002566 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002567 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02002568 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002569 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002570 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002571
2572 if (spec->alt_switch) {
2573 codec->num_pcms++;
2574 info++;
2575 info->name = "STAC92xx Analog Alt";
2576 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2577 }
Matt2f2f4252005-04-13 14:45:30 +02002578
Mattdabbed62005-06-14 10:19:34 +02002579 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2580 codec->num_pcms++;
2581 info++;
2582 info->name = "STAC92xx Digital";
Takashi Iwai8c441982009-01-20 18:30:20 +01002583 info->pcm_type = spec->autocfg.dig_out_type;
Mattdabbed62005-06-14 10:19:34 +02002584 if (spec->multiout.dig_out_nid) {
2585 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2586 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2587 }
2588 if (spec->dig_in_nid) {
2589 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2590 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2591 }
2592 }
2593
Matt2f2f4252005-04-13 14:45:30 +02002594 return 0;
2595}
2596
Takashi Iwaic960a032006-03-23 17:06:28 +01002597static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2598{
2599 unsigned int pincap = snd_hda_param_read(codec, nid,
2600 AC_PAR_PIN_CAP);
2601 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2602 if (pincap & AC_PINCAP_VREF_100)
2603 return AC_PINCTL_VREF_100;
2604 if (pincap & AC_PINCAP_VREF_80)
2605 return AC_PINCTL_VREF_80;
2606 if (pincap & AC_PINCAP_VREF_50)
2607 return AC_PINCTL_VREF_50;
2608 if (pincap & AC_PINCAP_VREF_GRD)
2609 return AC_PINCTL_VREF_GRD;
2610 return 0;
2611}
2612
Matt Porter403d1942005-11-29 15:00:51 +01002613static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2614
2615{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002616 snd_hda_codec_write_cache(codec, nid, 0,
2617 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002618}
2619
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002620#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2621
2622static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2623 struct snd_ctl_elem_value *ucontrol)
2624{
2625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2626 struct sigmatel_spec *spec = codec->spec;
2627
Takashi Iwaid7a89432008-11-12 09:48:04 +01002628 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002629 return 0;
2630}
2631
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002632static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2633 unsigned char type);
2634
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002635static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2636 struct snd_ctl_elem_value *ucontrol)
2637{
2638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2639 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002640 int nid = kcontrol->private_value;
2641
2642 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002643
2644 /* check to be sure that the ports are upto date with
2645 * switch changes
2646 */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002647 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002648
2649 return 1;
2650}
2651
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002652#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01002653
2654static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2655{
2656 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2657 struct sigmatel_spec *spec = codec->spec;
2658 int io_idx = kcontrol-> private_value & 0xff;
2659
2660 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2661 return 0;
2662}
2663
2664static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2665{
2666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2667 struct sigmatel_spec *spec = codec->spec;
2668 hda_nid_t nid = kcontrol->private_value >> 8;
2669 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002670 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01002671
2672 spec->io_switch[io_idx] = val;
2673
2674 if (val)
2675 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002676 else {
2677 unsigned int pinctl = AC_PINCTL_IN_EN;
2678 if (io_idx) /* set VREF for mic */
2679 pinctl |= stac92xx_get_vref(codec, nid);
2680 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2681 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002682
2683 /* check the auto-mute again: we need to mute/unmute the speaker
2684 * appropriately according to the pin direction
2685 */
2686 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002687 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002688
Matt Porter403d1942005-11-29 15:00:51 +01002689 return 1;
2690}
2691
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002692#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2693
2694static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2695 struct snd_ctl_elem_value *ucontrol)
2696{
2697 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2698 struct sigmatel_spec *spec = codec->spec;
2699
2700 ucontrol->value.integer.value[0] = spec->clfe_swap;
2701 return 0;
2702}
2703
2704static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2705 struct snd_ctl_elem_value *ucontrol)
2706{
2707 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2708 struct sigmatel_spec *spec = codec->spec;
2709 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002710 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002711
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002712 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002713 return 0;
2714
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002715 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002716
2717 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2718 spec->clfe_swap ? 0x4 : 0x0);
2719
2720 return 1;
2721}
2722
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002723#define STAC_CODEC_HP_SWITCH(xname) \
2724 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2725 .name = xname, \
2726 .index = 0, \
2727 .info = stac92xx_hp_switch_info, \
2728 .get = stac92xx_hp_switch_get, \
2729 .put = stac92xx_hp_switch_put, \
2730 }
2731
Matt Porter403d1942005-11-29 15:00:51 +01002732#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2733 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2734 .name = xname, \
2735 .index = 0, \
2736 .info = stac92xx_io_switch_info, \
2737 .get = stac92xx_io_switch_get, \
2738 .put = stac92xx_io_switch_put, \
2739 .private_value = xpval, \
2740 }
2741
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002742#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2743 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2744 .name = xname, \
2745 .index = 0, \
2746 .info = stac92xx_clfe_switch_info, \
2747 .get = stac92xx_clfe_switch_get, \
2748 .put = stac92xx_clfe_switch_put, \
2749 .private_value = xpval, \
2750 }
Matt Porter403d1942005-11-29 15:00:51 +01002751
Mattc7d4b2f2005-06-27 14:59:41 +02002752enum {
2753 STAC_CTL_WIDGET_VOL,
2754 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002755 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002756 STAC_CTL_WIDGET_AMP_MUX,
2757 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002758 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002759 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002760 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02002761};
2762
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002763static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002764 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2765 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002766 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002767 STAC_AMP_MUX,
2768 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002769 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002770 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002771 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002772};
2773
2774/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002775static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2776 struct snd_kcontrol_new *ktemp,
2777 int idx, const char *name,
2778 unsigned long val)
Mattc7d4b2f2005-06-27 14:59:41 +02002779{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002780 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002781
Takashi Iwai603c4012008-07-30 15:01:44 +02002782 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2783 knew = snd_array_new(&spec->kctls);
2784 if (!knew)
2785 return -ENOMEM;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002786 *knew = *ktemp;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002787 knew->index = idx;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002788 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002789 if (!knew->name)
Mattc7d4b2f2005-06-27 14:59:41 +02002790 return -ENOMEM;
2791 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002792 return 0;
2793}
2794
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002795static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2796 int type, int idx, const char *name,
2797 unsigned long val)
2798{
2799 return stac92xx_add_control_temp(spec,
2800 &stac92xx_control_templates[type],
2801 idx, name, val);
2802}
2803
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002804
2805/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002806static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2807 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002808{
2809 return stac92xx_add_control_idx(spec, type, 0, name, val);
2810}
2811
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002812/* check whether the line-input can be used as line-out */
2813static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002814{
2815 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002816 struct auto_pin_cfg *cfg = &spec->autocfg;
2817 hda_nid_t nid;
2818 unsigned int pincap;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002819
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002820 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2821 return 0;
2822 nid = cfg->input_pins[AUTO_PIN_LINE];
2823 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
2824 if (pincap & AC_PINCAP_OUT)
2825 return nid;
Matt Porter403d1942005-11-29 15:00:51 +01002826 return 0;
2827}
2828
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002829/* check whether the mic-input can be used as line-out */
2830static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2831{
2832 struct sigmatel_spec *spec = codec->spec;
2833 struct auto_pin_cfg *cfg = &spec->autocfg;
2834 unsigned int def_conf, pincap;
2835 unsigned int mic_pin;
2836
2837 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2838 return 0;
2839 mic_pin = AUTO_PIN_MIC;
2840 for (;;) {
2841 hda_nid_t nid = cfg->input_pins[mic_pin];
2842 def_conf = snd_hda_codec_read(codec, nid, 0,
2843 AC_VERB_GET_CONFIG_DEFAULT, 0);
2844 /* some laptops have an internal analog microphone
2845 * which can't be used as a output */
2846 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2847 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
2848 if (pincap & AC_PINCAP_OUT)
2849 return nid;
2850 }
2851 if (mic_pin == AUTO_PIN_MIC)
2852 mic_pin = AUTO_PIN_FRONT_MIC;
2853 else
2854 break;
2855 }
2856 return 0;
2857}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002858
2859static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2860{
2861 int i;
2862
2863 for (i = 0; i < spec->multiout.num_dacs; i++) {
2864 if (spec->multiout.dac_nids[i] == nid)
2865 return 1;
2866 }
2867
2868 return 0;
2869}
2870
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002871static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2872{
2873 int i;
2874 if (is_in_dac_nids(spec, nid))
2875 return 1;
2876 for (i = 0; i < spec->autocfg.hp_outs; i++)
2877 if (spec->hp_dacs[i] == nid)
2878 return 1;
2879 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2880 if (spec->speaker_dacs[i] == nid)
2881 return 1;
2882 return 0;
2883}
2884
2885static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2886{
2887 struct sigmatel_spec *spec = codec->spec;
2888 int j, conn_len;
2889 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2890 unsigned int wcaps, wtype;
2891
2892 conn_len = snd_hda_get_connections(codec, nid, conn,
2893 HDA_MAX_CONNECTIONS);
2894 for (j = 0; j < conn_len; j++) {
2895 wcaps = snd_hda_param_read(codec, conn[j],
2896 AC_PAR_AUDIO_WIDGET_CAP);
2897 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2898 /* we check only analog outputs */
2899 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2900 continue;
2901 /* if this route has a free DAC, assign it */
2902 if (!check_all_dac_nids(spec, conn[j])) {
2903 if (conn_len > 1) {
2904 /* select this DAC in the pin's input mux */
2905 snd_hda_codec_write_cache(codec, nid, 0,
2906 AC_VERB_SET_CONNECT_SEL, j);
2907 }
2908 return conn[j];
2909 }
2910 }
2911 return 0;
2912}
2913
2914static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2915static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2916
Matt Porter3cc08dc2006-01-23 15:27:49 +01002917/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002918 * Fill in the dac_nids table from the parsed pin configuration
2919 * This function only works when every pin in line_out_pins[]
2920 * contains atleast one DAC in its connection list. Some 92xx
2921 * codecs are not connected directly to a DAC, such as the 9200
2922 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002923 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002924static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002925{
2926 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002927 struct auto_pin_cfg *cfg = &spec->autocfg;
2928 int i;
2929 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002930
Mattc7d4b2f2005-06-27 14:59:41 +02002931 for (i = 0; i < cfg->line_outs; i++) {
2932 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002933 dac = get_unassigned_dac(codec, nid);
2934 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002935 if (spec->multiout.num_dacs > 0) {
2936 /* we have already working output pins,
2937 * so let's drop the broken ones again
2938 */
2939 cfg->line_outs = spec->multiout.num_dacs;
2940 break;
2941 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002942 /* error out, no available DAC found */
2943 snd_printk(KERN_ERR
2944 "%s: No available DAC for pin 0x%x\n",
2945 __func__, nid);
2946 return -ENODEV;
2947 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002948 add_spec_dacs(spec, dac);
2949 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002950
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002951 /* add line-in as output */
2952 nid = check_line_out_switch(codec);
2953 if (nid) {
2954 dac = get_unassigned_dac(codec, nid);
2955 if (dac) {
2956 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2957 nid, cfg->line_outs);
2958 cfg->line_out_pins[cfg->line_outs] = nid;
2959 cfg->line_outs++;
2960 spec->line_switch = nid;
2961 add_spec_dacs(spec, dac);
2962 }
2963 }
2964 /* add mic as output */
2965 nid = check_mic_out_switch(codec);
2966 if (nid) {
2967 dac = get_unassigned_dac(codec, nid);
2968 if (dac) {
2969 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
2970 nid, cfg->line_outs);
2971 cfg->line_out_pins[cfg->line_outs] = nid;
2972 cfg->line_outs++;
2973 spec->mic_switch = nid;
2974 add_spec_dacs(spec, dac);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002975 }
Mattc7d4b2f2005-06-27 14:59:41 +02002976 }
2977
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002978 for (i = 0; i < cfg->hp_outs; i++) {
2979 nid = cfg->hp_pins[i];
2980 dac = get_unassigned_dac(codec, nid);
2981 if (dac) {
2982 if (!spec->multiout.hp_nid)
2983 spec->multiout.hp_nid = dac;
2984 else
2985 add_spec_extra_dacs(spec, dac);
2986 }
2987 spec->hp_dacs[i] = dac;
2988 }
2989
2990 for (i = 0; i < cfg->speaker_outs; i++) {
2991 nid = cfg->speaker_pins[i];
2992 dac = get_unassigned_dac(codec, nid);
2993 if (dac)
2994 add_spec_extra_dacs(spec, dac);
2995 spec->speaker_dacs[i] = dac;
2996 }
2997
2998 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02002999 spec->multiout.num_dacs,
3000 spec->multiout.dac_nids[0],
3001 spec->multiout.dac_nids[1],
3002 spec->multiout.dac_nids[2],
3003 spec->multiout.dac_nids[3],
3004 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003005
Mattc7d4b2f2005-06-27 14:59:41 +02003006 return 0;
3007}
3008
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003009/* create volume control/switch for the given prefx type */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003010static int create_controls(struct hda_codec *codec, const char *pfx,
3011 hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003012{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003013 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003014 char name[32];
3015 int err;
3016
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003017 if (!spec->check_volume_offset) {
3018 unsigned int caps, step, nums, db_scale;
3019 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3020 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3021 AC_AMPCAP_STEP_SIZE_SHIFT;
3022 step = (step + 1) * 25; /* in .01dB unit */
3023 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3024 AC_AMPCAP_NUM_STEPS_SHIFT;
3025 db_scale = nums * step;
3026 /* if dB scale is over -64dB, and finer enough,
3027 * let's reduce it to half
3028 */
3029 if (db_scale > 6400 && nums >= 0x1f)
3030 spec->volume_offset = nums / 2;
3031 spec->check_volume_offset = 1;
3032 }
3033
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003034 sprintf(name, "%s Playback Volume", pfx);
3035 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003036 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3037 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003038 if (err < 0)
3039 return err;
3040 sprintf(name, "%s Playback Switch", pfx);
3041 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
3042 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3043 if (err < 0)
3044 return err;
3045 return 0;
3046}
3047
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003048static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3049{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003050 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003051 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3052 return 1;
3053 } else {
3054 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3055 spec->multiout.num_dacs++;
3056 }
3057 return 0;
3058}
3059
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003060static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003061{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003062 int i;
3063 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3064 if (!spec->multiout.extra_out_nid[i]) {
3065 spec->multiout.extra_out_nid[i] = nid;
3066 return 0;
3067 }
3068 }
3069 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3070 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003071}
3072
Takashi Iwai76624532008-12-19 10:09:47 +01003073static int is_unique_dac(struct sigmatel_spec *spec, hda_nid_t nid)
3074{
3075 int i;
3076
3077 if (spec->autocfg.line_outs != 1)
3078 return 0;
3079 if (spec->multiout.hp_nid == nid)
3080 return 0;
3081 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++)
3082 if (spec->multiout.extra_out_nid[i] == nid)
3083 return 0;
3084 return 1;
3085}
3086
Mattc7d4b2f2005-06-27 14:59:41 +02003087/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003088static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02003089 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003090{
Takashi Iwai76624532008-12-19 10:09:47 +01003091 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003092 static const char *chname[4] = {
3093 "Front", "Surround", NULL /*CLFE*/, "Side"
3094 };
Matthew Ranostayd21995e2008-10-13 13:22:45 -04003095 hda_nid_t nid = 0;
Takashi Iwai91589232008-12-19 15:59:40 +01003096 int i, err;
3097 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003098
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003099 for (i = 0; i < cfg->line_outs && spec->multiout.dac_nids[i]; i++) {
Mattc7d4b2f2005-06-27 14:59:41 +02003100 nid = spec->multiout.dac_nids[i];
Mattc7d4b2f2005-06-27 14:59:41 +02003101 if (i == 2) {
3102 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003103 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003104 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003105 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003106 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003107 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003108 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003109
3110 wid_caps = get_wcaps(codec, nid);
3111
3112 if (wid_caps & AC_WCAP_LR_SWAP) {
3113 err = stac92xx_add_control(spec,
3114 STAC_CTL_WIDGET_CLFE_SWITCH,
3115 "Swap Center/LFE Playback Switch", nid);
3116
3117 if (err < 0)
3118 return err;
3119 }
3120
Mattc7d4b2f2005-06-27 14:59:41 +02003121 } else {
Takashi Iwai76624532008-12-19 10:09:47 +01003122 const char *name = chname[i];
3123 /* if it's a single DAC, assign a better name */
3124 if (!i && is_unique_dac(spec, nid)) {
3125 switch (cfg->line_out_type) {
3126 case AUTO_PIN_HP_OUT:
3127 name = "Headphone";
3128 break;
3129 case AUTO_PIN_SPEAKER_OUT:
3130 name = "Speaker";
3131 break;
3132 }
3133 }
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003134 err = create_controls(codec, name, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003135 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003136 return err;
3137 }
3138 }
3139
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003140 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003141 err = stac92xx_add_control(spec,
3142 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003143 "Headphone as Line Out Switch",
3144 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003145 if (err < 0)
3146 return err;
3147 }
3148
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003149 if (spec->line_switch) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003150 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH,
3151 "Line In as Output Switch",
3152 spec->line_switch << 8);
3153 if (err < 0)
3154 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003155 }
Matt Porter403d1942005-11-29 15:00:51 +01003156
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003157 if (spec->mic_switch) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003158 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH,
3159 "Mic as Output Switch",
3160 (spec->mic_switch << 8) | 1);
3161 if (err < 0)
3162 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003163 }
Matt Porter403d1942005-11-29 15:00:51 +01003164
Mattc7d4b2f2005-06-27 14:59:41 +02003165 return 0;
3166}
3167
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003168/* add playback controls for Speaker and HP outputs */
3169static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3170 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003171{
3172 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003173 hda_nid_t nid;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003174 int i, err, nums;
Mattc7d4b2f2005-06-27 14:59:41 +02003175
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003176 nums = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003177 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003178 static const char *pfxs[] = {
3179 "Headphone", "Headphone2", "Headphone3",
3180 };
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003181 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
3182 if (wid_caps & AC_WCAP_UNSOL_CAP)
3183 spec->hp_detect = 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003184 if (nums >= ARRAY_SIZE(pfxs))
Mattc7d4b2f2005-06-27 14:59:41 +02003185 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003186 nid = spec->hp_dacs[i];
3187 if (!nid)
3188 continue;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003189 err = create_controls(codec, pfxs[nums++], nid, 3);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003190 if (err < 0)
3191 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003192 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003193 nums = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003194 for (i = 0; i < cfg->speaker_outs; i++) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003195 static const char *pfxs[] = {
3196 "Speaker", "External Speaker", "Speaker2",
3197 };
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003198 if (nums >= ARRAY_SIZE(pfxs))
3199 continue;
3200 nid = spec->speaker_dacs[i];
3201 if (!nid)
3202 continue;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003203 err = create_controls(codec, pfxs[nums++], nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003204 if (err < 0)
3205 return err;
3206 }
Mattc7d4b2f2005-06-27 14:59:41 +02003207 return 0;
3208}
3209
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003210/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003211static const char *stac92xx_mono_labels[4] = {
3212 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003213};
3214
3215/* create mono mux for mono out on capable codecs */
3216static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3217{
3218 struct sigmatel_spec *spec = codec->spec;
3219 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3220 int i, num_cons;
3221 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3222
3223 num_cons = snd_hda_get_connections(codec,
3224 spec->mono_nid,
3225 con_lst,
3226 HDA_MAX_NUM_INPUTS);
3227 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3228 return -EINVAL;
3229
3230 for (i = 0; i < num_cons; i++) {
3231 mono_mux->items[mono_mux->num_items].label =
3232 stac92xx_mono_labels[i];
3233 mono_mux->items[mono_mux->num_items].index = i;
3234 mono_mux->num_items++;
3235 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003236
3237 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3238 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003239}
3240
Matthew Ranostay89385032008-09-11 09:49:39 -04003241/* labels for amp mux outputs */
3242static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003243 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003244};
3245
3246/* create amp out controls mux on capable codecs */
3247static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3248{
3249 struct sigmatel_spec *spec = codec->spec;
3250 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3251 int i, err;
3252
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003253 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003254 amp_mux->items[amp_mux->num_items].label =
3255 stac92xx_amp_labels[i];
3256 amp_mux->items[amp_mux->num_items].index = i;
3257 amp_mux->num_items++;
3258 }
3259
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003260 if (spec->num_amps > 1) {
3261 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3262 "Amp Selector Capture Switch", 0);
3263 if (err < 0)
3264 return err;
3265 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003266 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3267 "Amp Capture Volume",
3268 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3269}
3270
3271
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003272/* create PC beep volume controls */
3273static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3274 hda_nid_t nid)
3275{
3276 struct sigmatel_spec *spec = codec->spec;
3277 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3278 int err;
3279
3280 /* check for mute support for the the amp */
3281 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3282 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3283 "PC Beep Playback Switch",
3284 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3285 if (err < 0)
3286 return err;
3287 }
3288
3289 /* check to see if there is volume support for the amp */
3290 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3291 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3292 "PC Beep Playback Volume",
3293 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3294 if (err < 0)
3295 return err;
3296 }
3297 return 0;
3298}
3299
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003300#ifdef CONFIG_SND_HDA_INPUT_BEEP
3301#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3302
3303static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3304 struct snd_ctl_elem_value *ucontrol)
3305{
3306 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3307 ucontrol->value.integer.value[0] = codec->beep->enabled;
3308 return 0;
3309}
3310
3311static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3312 struct snd_ctl_elem_value *ucontrol)
3313{
3314 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3315 int enabled = !!ucontrol->value.integer.value[0];
3316 if (codec->beep->enabled != enabled) {
3317 codec->beep->enabled = enabled;
3318 return 1;
3319 }
3320 return 0;
3321}
3322
3323static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3324 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3325 .info = stac92xx_dig_beep_switch_info,
3326 .get = stac92xx_dig_beep_switch_get,
3327 .put = stac92xx_dig_beep_switch_put,
3328};
3329
3330static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3331{
3332 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3333 0, "PC Beep Playback Switch", 0);
3334}
3335#endif
3336
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003337static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3338{
3339 struct sigmatel_spec *spec = codec->spec;
3340 int wcaps, nid, i, err = 0;
3341
3342 for (i = 0; i < spec->num_muxes; i++) {
3343 nid = spec->mux_nids[i];
3344 wcaps = get_wcaps(codec, nid);
3345
3346 if (wcaps & AC_WCAP_OUT_AMP) {
3347 err = stac92xx_add_control_idx(spec,
3348 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3349 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3350 if (err < 0)
3351 return err;
3352 }
3353 }
3354 return 0;
3355};
3356
Matthew Ranostayd9737752008-09-07 12:03:41 +02003357static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003358 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003359};
3360
3361static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3362{
3363 struct sigmatel_spec *spec = codec->spec;
3364 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003365 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003366 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003367 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003368
3369 num_cons = snd_hda_get_connections(codec,
3370 spec->smux_nids[0],
3371 con_lst,
3372 HDA_MAX_NUM_INPUTS);
Matthew Ranostay65973632008-09-16 10:39:37 -04003373 if (!num_cons)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003374 return -EINVAL;
3375
Matthew Ranostay65973632008-09-16 10:39:37 -04003376 if (!labels)
3377 labels = stac92xx_spdif_labels;
3378
Matthew Ranostayd9737752008-09-07 12:03:41 +02003379 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003380 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003381 spdif_mux->items[spdif_mux->num_items].index = i;
3382 spdif_mux->num_items++;
3383 }
3384
3385 return 0;
3386}
3387
Matt Porter8b657272006-10-26 17:12:59 +02003388/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003389static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003390 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3391 "Digital Mic 3", "Digital Mic 4"
3392};
3393
3394/* create playback/capture controls for input pins on dmic capable codecs */
3395static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3396 const struct auto_pin_cfg *cfg)
3397{
3398 struct sigmatel_spec *spec = codec->spec;
3399 struct hda_input_mux *dimux = &spec->private_dimux;
3400 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003401 int err, i, j;
3402 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02003403
3404 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3405 dimux->items[dimux->num_items].index = 0;
3406 dimux->num_items++;
3407
3408 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003409 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003410 int index;
3411 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003412 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02003413 unsigned int def_conf;
3414
3415 def_conf = snd_hda_codec_read(codec,
3416 spec->dmic_nids[i],
3417 0,
3418 AC_VERB_GET_CONFIG_DEFAULT,
3419 0);
3420 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3421 continue;
3422
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003423 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02003424 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003425 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02003426 con_lst,
3427 HDA_MAX_NUM_INPUTS);
3428 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003429 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02003430 index = j;
3431 goto found;
3432 }
3433 continue;
3434found:
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003435 wcaps = get_wcaps(codec, nid) &
3436 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003437
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003438 if (wcaps) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003439 sprintf(name, "%s Capture Volume",
3440 stac92xx_dmic_labels[dimux->num_items]);
3441
3442 err = stac92xx_add_control(spec,
3443 STAC_CTL_WIDGET_VOL,
3444 name,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003445 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3446 (wcaps & AC_WCAP_OUT_AMP) ?
3447 HDA_OUTPUT : HDA_INPUT));
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003448 if (err < 0)
3449 return err;
3450 }
3451
Matt Porter8b657272006-10-26 17:12:59 +02003452 dimux->items[dimux->num_items].label =
3453 stac92xx_dmic_labels[dimux->num_items];
3454 dimux->items[dimux->num_items].index = index;
3455 dimux->num_items++;
3456 }
3457
3458 return 0;
3459}
3460
Mattc7d4b2f2005-06-27 14:59:41 +02003461/* create playback/capture controls for input pins */
3462static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3463{
3464 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003465 struct hda_input_mux *imux = &spec->private_imux;
3466 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3467 int i, j, k;
3468
3469 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003470 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02003471
Takashi Iwai314634b2006-09-21 11:56:18 +02003472 if (!cfg->input_pins[i])
3473 continue;
3474 index = -1;
3475 for (j = 0; j < spec->num_muxes; j++) {
3476 int num_cons;
3477 num_cons = snd_hda_get_connections(codec,
3478 spec->mux_nids[j],
3479 con_lst,
3480 HDA_MAX_NUM_INPUTS);
3481 for (k = 0; k < num_cons; k++)
3482 if (con_lst[k] == cfg->input_pins[i]) {
3483 index = k;
3484 goto found;
3485 }
Mattc7d4b2f2005-06-27 14:59:41 +02003486 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003487 continue;
3488 found:
3489 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3490 imux->items[imux->num_items].index = index;
3491 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003492 }
3493
Steve Longerbeam7b043892007-05-03 20:50:03 +02003494 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003495 /*
3496 * Set the current input for the muxes.
3497 * The STAC9221 has two input muxes with identical source
3498 * NID lists. Hopefully this won't get confused.
3499 */
3500 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003501 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3502 AC_VERB_SET_CONNECT_SEL,
3503 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003504 }
3505 }
3506
Mattc7d4b2f2005-06-27 14:59:41 +02003507 return 0;
3508}
3509
Mattc7d4b2f2005-06-27 14:59:41 +02003510static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3511{
3512 struct sigmatel_spec *spec = codec->spec;
3513 int i;
3514
3515 for (i = 0; i < spec->autocfg.line_outs; i++) {
3516 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3517 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3518 }
3519}
3520
3521static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3522{
3523 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003524 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003525
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003526 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3527 hda_nid_t pin;
3528 pin = spec->autocfg.hp_pins[i];
3529 if (pin) /* connect to front */
3530 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3531 }
3532 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3533 hda_nid_t pin;
3534 pin = spec->autocfg.speaker_pins[i];
3535 if (pin) /* connect to front */
3536 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3537 }
Mattc7d4b2f2005-06-27 14:59:41 +02003538}
3539
Matt Porter3cc08dc2006-01-23 15:27:49 +01003540static 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 +02003541{
3542 struct sigmatel_spec *spec = codec->spec;
3543 int err;
3544
Matt Porter8b657272006-10-26 17:12:59 +02003545 if ((err = snd_hda_parse_pin_def_config(codec,
3546 &spec->autocfg,
3547 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003548 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003549 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003550 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003551
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003552 /* If we have no real line-out pin and multiple hp-outs, HPs should
3553 * be set up as multi-channel outputs.
3554 */
3555 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3556 spec->autocfg.hp_outs > 1) {
3557 /* Copy hp_outs to line_outs, backup line_outs in
3558 * speaker_outs so that the following routines can handle
3559 * HP pins as primary outputs.
3560 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003561 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003562 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3563 sizeof(spec->autocfg.line_out_pins));
3564 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3565 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3566 sizeof(spec->autocfg.hp_pins));
3567 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003568 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3569 spec->autocfg.hp_outs = 0;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003570 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003571 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003572 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3573 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003574 u32 caps = query_amp_caps(codec,
3575 spec->autocfg.mono_out_pin, dir);
3576 hda_nid_t conn_list[1];
3577
3578 /* get the mixer node and then the mono mux if it exists */
3579 if (snd_hda_get_connections(codec,
3580 spec->autocfg.mono_out_pin, conn_list, 1) &&
3581 snd_hda_get_connections(codec, conn_list[0],
3582 conn_list, 1)) {
3583
3584 int wcaps = get_wcaps(codec, conn_list[0]);
3585 int wid_type = (wcaps & AC_WCAP_TYPE)
3586 >> AC_WCAP_TYPE_SHIFT;
3587 /* LR swap check, some stac925x have a mux that
3588 * changes the DACs output path instead of the
3589 * mono-mux path.
3590 */
3591 if (wid_type == AC_WID_AUD_SEL &&
3592 !(wcaps & AC_WCAP_LR_SWAP))
3593 spec->mono_nid = conn_list[0];
3594 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003595 if (dir) {
3596 hda_nid_t nid = spec->autocfg.mono_out_pin;
3597
3598 /* most mono outs have a least a mute/unmute switch */
3599 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3600 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3601 "Mono Playback Switch",
3602 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003603 if (err < 0)
3604 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003605 /* check for volume support for the amp */
3606 if ((caps & AC_AMPCAP_NUM_STEPS)
3607 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3608 err = stac92xx_add_control(spec,
3609 STAC_CTL_WIDGET_VOL,
3610 "Mono Playback Volume",
3611 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3612 if (err < 0)
3613 return err;
3614 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003615 }
3616
3617 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3618 AC_PINCTL_OUT_EN);
3619 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003620
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003621 if (!spec->multiout.num_dacs) {
3622 err = stac92xx_auto_fill_dac_nids(codec);
3623 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003624 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003625 err = stac92xx_auto_create_multi_out_ctls(codec,
3626 &spec->autocfg);
3627 if (err < 0)
3628 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003629 }
Mattc7d4b2f2005-06-27 14:59:41 +02003630
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003631 /* setup analog beep controls */
3632 if (spec->anabeep_nid > 0) {
3633 err = stac92xx_auto_create_beep_ctls(codec,
3634 spec->anabeep_nid);
3635 if (err < 0)
3636 return err;
3637 }
3638
3639 /* setup digital beep controls and input device */
3640#ifdef CONFIG_SND_HDA_INPUT_BEEP
3641 if (spec->digbeep_nid > 0) {
3642 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003643 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003644
3645 err = stac92xx_auto_create_beep_ctls(codec, nid);
3646 if (err < 0)
3647 return err;
3648 err = snd_hda_attach_beep_device(codec, nid);
3649 if (err < 0)
3650 return err;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003651 /* if no beep switch is available, make its own one */
3652 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3653 if (codec->beep &&
3654 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3655 err = stac92xx_beep_switch_ctl(codec);
3656 if (err < 0)
3657 return err;
3658 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003659 }
3660#endif
3661
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003662 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3663
3664 if (err < 0)
3665 return err;
3666
3667 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3668
3669 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003670 return err;
3671
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003672 if (spec->mono_nid > 0) {
3673 err = stac92xx_auto_create_mono_output_ctls(codec);
3674 if (err < 0)
3675 return err;
3676 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003677 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003678 err = stac92xx_auto_create_amp_output_ctls(codec);
3679 if (err < 0)
3680 return err;
3681 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003682 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003683 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3684 &spec->autocfg)) < 0)
3685 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003686 if (spec->num_muxes > 0) {
3687 err = stac92xx_auto_create_mux_input_ctls(codec);
3688 if (err < 0)
3689 return err;
3690 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003691 if (spec->num_smuxes > 0) {
3692 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3693 if (err < 0)
3694 return err;
3695 }
Matt Porter8b657272006-10-26 17:12:59 +02003696
Mattc7d4b2f2005-06-27 14:59:41 +02003697 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003698 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003699 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003700
Takashi Iwai82bc9552006-03-21 11:24:42 +01003701 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003702 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003703 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003704 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003705
Takashi Iwai603c4012008-07-30 15:01:44 +02003706 if (spec->kctls.list)
3707 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003708
3709 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003710 if (!spec->dinput_mux)
3711 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003712 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003713 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04003714 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003715 return 1;
3716}
3717
Takashi Iwai82bc9552006-03-21 11:24:42 +01003718/* add playback controls for HP output */
3719static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3720 struct auto_pin_cfg *cfg)
3721{
3722 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003723 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003724 unsigned int wid_caps;
3725
3726 if (! pin)
3727 return 0;
3728
3729 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003730 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003731 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003732
3733 return 0;
3734}
3735
Richard Fish160ea0d2006-09-06 13:58:25 +02003736/* add playback controls for LFE output */
3737static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3738 struct auto_pin_cfg *cfg)
3739{
3740 struct sigmatel_spec *spec = codec->spec;
3741 int err;
3742 hda_nid_t lfe_pin = 0x0;
3743 int i;
3744
3745 /*
3746 * search speaker outs and line outs for a mono speaker pin
3747 * with an amp. If one is found, add LFE controls
3748 * for it.
3749 */
3750 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3751 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003752 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003753 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3754 if (wcaps == AC_WCAP_OUT_AMP)
3755 /* found a mono speaker with an amp, must be lfe */
3756 lfe_pin = pin;
3757 }
3758
3759 /* if speaker_outs is 0, then speakers may be in line_outs */
3760 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3761 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3762 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003763 unsigned int defcfg;
Harvey Harrison8b551782008-02-29 11:56:48 +01003764 defcfg = snd_hda_codec_read(codec, pin, 0,
Richard Fish160ea0d2006-09-06 13:58:25 +02003765 AC_VERB_GET_CONFIG_DEFAULT,
3766 0x00);
Harvey Harrison8b551782008-02-29 11:56:48 +01003767 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003768 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003769 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3770 if (wcaps == AC_WCAP_OUT_AMP)
3771 /* found a mono speaker with an amp,
3772 must be lfe */
3773 lfe_pin = pin;
3774 }
3775 }
3776 }
3777
3778 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003779 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003780 if (err < 0)
3781 return err;
3782 }
3783
3784 return 0;
3785}
3786
Mattc7d4b2f2005-06-27 14:59:41 +02003787static int stac9200_parse_auto_config(struct hda_codec *codec)
3788{
3789 struct sigmatel_spec *spec = codec->spec;
3790 int err;
3791
Kailang Yangdf694da2005-12-05 19:42:22 +01003792 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003793 return err;
3794
3795 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3796 return err;
3797
Takashi Iwai82bc9552006-03-21 11:24:42 +01003798 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3799 return err;
3800
Richard Fish160ea0d2006-09-06 13:58:25 +02003801 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3802 return err;
3803
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003804 if (spec->num_muxes > 0) {
3805 err = stac92xx_auto_create_mux_input_ctls(codec);
3806 if (err < 0)
3807 return err;
3808 }
3809
Takashi Iwai82bc9552006-03-21 11:24:42 +01003810 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003811 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003812 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003813 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003814
Takashi Iwai603c4012008-07-30 15:01:44 +02003815 if (spec->kctls.list)
3816 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003817
3818 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003819 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003820
3821 return 1;
3822}
3823
Sam Revitch62fe78e2006-05-10 15:09:17 +02003824/*
3825 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3826 * funky external mute control using GPIO pins.
3827 */
3828
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003829static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003830 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003831{
3832 unsigned int gpiostate, gpiomask, gpiodir;
3833
3834 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3835 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003836 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003837
3838 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3839 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003840 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003841
3842 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3843 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01003844 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003845
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003846 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003847 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3848
3849 snd_hda_codec_write(codec, codec->afg, 0,
3850 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003851 snd_hda_codec_read(codec, codec->afg, 0,
3852 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003853
3854 msleep(1);
3855
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003856 snd_hda_codec_read(codec, codec->afg, 0,
3857 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003858}
3859
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003860static int stac92xx_add_jack(struct hda_codec *codec,
3861 hda_nid_t nid, int type)
3862{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003863#ifdef CONFIG_SND_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003864 struct sigmatel_spec *spec = codec->spec;
3865 struct sigmatel_jack *jack;
3866 int def_conf = snd_hda_codec_read(codec, nid,
3867 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
3868 int connectivity = get_defcfg_connect(def_conf);
3869 char name[32];
3870
3871 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3872 return 0;
3873
3874 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3875 jack = snd_array_new(&spec->jacks);
3876 if (!jack)
3877 return -ENOMEM;
3878 jack->nid = nid;
3879 jack->type = type;
3880
3881 sprintf(name, "%s at %s %s Jack",
3882 snd_hda_get_jack_type(def_conf),
3883 snd_hda_get_jack_connectivity(def_conf),
3884 snd_hda_get_jack_location(def_conf));
3885
3886 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003887#else
3888 return 0;
3889#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003890}
3891
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003892static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3893 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003894{
3895 struct sigmatel_event *event;
3896
3897 snd_array_init(&spec->events, sizeof(*event), 32);
3898 event = snd_array_new(&spec->events);
3899 if (!event)
3900 return -ENOMEM;
3901 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003902 event->type = type;
3903 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003904 event->data = data;
3905
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003906 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003907}
3908
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003909static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
3910 hda_nid_t nid, unsigned char type)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003911{
3912 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003913 struct sigmatel_event *event = spec->events.list;
3914 int i;
3915
3916 for (i = 0; i < spec->events.used; i++, event++) {
3917 if (event->nid == nid && event->type == type)
3918 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003919 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003920 return NULL;
3921}
3922
3923static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
3924 unsigned char tag)
3925{
3926 struct sigmatel_spec *spec = codec->spec;
3927 struct sigmatel_event *event = spec->events.list;
3928 int i;
3929
3930 for (i = 0; i < spec->events.used; i++, event++) {
3931 if (event->tag == tag)
3932 return event;
3933 }
3934 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003935}
3936
Takashi Iwai314634b2006-09-21 11:56:18 +02003937static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003938 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02003939{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003940 struct sigmatel_event *event;
3941 int tag;
3942
3943 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
3944 return;
3945 event = stac_get_event(codec, nid, type);
3946 if (event)
3947 tag = event->tag;
3948 else
3949 tag = stac_add_event(codec->spec, nid, type, 0);
3950 if (tag < 0)
3951 return;
3952 snd_hda_codec_write_cache(codec, nid, 0,
3953 AC_VERB_SET_UNSOLICITED_ENABLE,
3954 AC_USRSP_EN | tag);
Takashi Iwai314634b2006-09-21 11:56:18 +02003955}
3956
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003957static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3958{
3959 int i;
3960 for (i = 0; i < cfg->hp_outs; i++)
3961 if (cfg->hp_pins[i] == nid)
3962 return 1; /* nid is a HP-Out */
3963
3964 return 0; /* nid is not a HP-Out */
3965};
3966
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003967static void stac92xx_power_down(struct hda_codec *codec)
3968{
3969 struct sigmatel_spec *spec = codec->spec;
3970
3971 /* power down inactive DACs */
3972 hda_nid_t *dac;
3973 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003974 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01003975 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003976 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3977}
3978
Takashi Iwaif73d3582008-11-25 08:21:51 +01003979static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3980 int enable);
3981
Mattc7d4b2f2005-06-27 14:59:41 +02003982static int stac92xx_init(struct hda_codec *codec)
3983{
3984 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003985 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01003986 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01003987 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003988
Mattc7d4b2f2005-06-27 14:59:41 +02003989 snd_hda_sequence_write(codec, spec->init);
3990
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02003991 /* power down adcs initially */
3992 if (spec->powerdown_adcs)
3993 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01003994 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02003995 spec->adc_nids[i], 0,
3996 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003997
3998 /* set up GPIO */
3999 gpio = spec->gpio_data;
4000 /* turn on EAPD statically when spec->eapd_switch isn't set.
4001 * otherwise, unsol event will turn it on/off dynamically
4002 */
4003 if (!spec->eapd_switch)
4004 gpio |= spec->eapd_mask;
4005 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
4006
Takashi Iwai82bc9552006-03-21 11:24:42 +01004007 /* set up pins */
4008 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02004009 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004010 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004011 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004012 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004013 }
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01004014 /* force to enable the first line-out; the others are set up
4015 * in unsol_event
4016 */
4017 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004018 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004019 /* fake event to set up pins */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004020 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4021 STAC_HP_EVENT);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004022 } else {
4023 stac92xx_auto_init_multi_out(codec);
4024 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004025 for (i = 0; i < cfg->hp_outs; i++)
4026 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004027 }
4028 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01004029 hda_nid_t nid = cfg->input_pins[i];
4030 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004031 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004032 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4033 /* for mic pins, force to initialize */
4034 pinctl = stac92xx_get_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004035 pinctl |= AC_PINCTL_IN_EN;
4036 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004037 } else {
4038 pinctl = snd_hda_codec_read(codec, nid, 0,
4039 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4040 /* if PINCTL already set then skip */
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004041 if (!(pinctl & AC_PINCTL_IN_EN)) {
4042 pinctl |= AC_PINCTL_IN_EN;
4043 stac92xx_auto_set_pinctl(codec, nid,
4044 pinctl);
4045 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004046 }
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004047 conf = snd_hda_codec_read(codec, nid, 0,
4048 AC_VERB_GET_CONFIG_DEFAULT, 0);
4049 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4050 enable_pin_detect(codec, nid,
4051 STAC_INSERT_EVENT);
4052 stac_issue_unsol_event(codec, nid,
4053 STAC_INSERT_EVENT);
4054 }
Takashi Iwaic960a032006-03-23 17:06:28 +01004055 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004056 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004057 for (i = 0; i < spec->num_dmics; i++)
4058 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4059 AC_PINCTL_IN_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004060 if (cfg->dig_out_pin)
4061 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
4062 AC_PINCTL_OUT_EN);
4063 if (cfg->dig_in_pin)
4064 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4065 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004066 for (i = 0; i < spec->num_pwrs; i++) {
4067 hda_nid_t nid = spec->pwr_nids[i];
4068 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004069
Takashi Iwaieb632122008-12-19 16:39:48 +01004070 /* power on when no jack detection is available */
4071 if (!spec->hp_detect) {
4072 stac_toggle_power_map(codec, nid, 1);
4073 continue;
4074 }
4075
4076 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004077 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004078
Takashi Iwaif73d3582008-11-25 08:21:51 +01004079 pinctl = snd_hda_codec_read(codec, nid, 0,
4080 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4081 /* outputs are only ports capable of power management
4082 * any attempts on powering down a input port cause the
4083 * referenced VREF to act quirky.
4084 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004085 if (pinctl & AC_PINCTL_IN_EN) {
4086 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004087 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004088 }
Takashi Iwaif73d3582008-11-25 08:21:51 +01004089 def_conf = snd_hda_codec_read(codec, nid, 0,
4090 AC_VERB_GET_CONFIG_DEFAULT, 0);
4091 def_conf = get_defcfg_connect(def_conf);
4092 /* skip any ports that don't have jacks since presence
4093 * detection is useless */
4094 if (def_conf != AC_JACK_PORT_COMPLEX) {
4095 if (def_conf != AC_JACK_PORT_NONE)
4096 stac_toggle_power_map(codec, nid, 1);
4097 continue;
4098 }
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004099 if (!stac_get_event(codec, nid, STAC_INSERT_EVENT)) {
4100 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
4101 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
4102 }
Takashi Iwaif73d3582008-11-25 08:21:51 +01004103 }
4104 if (spec->dac_list)
4105 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004106 return 0;
4107}
4108
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004109static void stac92xx_free_jacks(struct hda_codec *codec)
4110{
Takashi Iwaie4973e12008-11-18 09:32:42 +01004111#ifdef CONFIG_SND_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01004112 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004113 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01004114 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004115 struct sigmatel_jack *jacks = spec->jacks.list;
4116 int i;
4117 for (i = 0; i < spec->jacks.used; i++)
4118 snd_device_free(codec->bus->card, &jacks[i].jack);
4119 }
4120 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004121#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004122}
4123
Takashi Iwai603c4012008-07-30 15:01:44 +02004124static void stac92xx_free_kctls(struct hda_codec *codec)
4125{
4126 struct sigmatel_spec *spec = codec->spec;
4127
4128 if (spec->kctls.list) {
4129 struct snd_kcontrol_new *kctl = spec->kctls.list;
4130 int i;
4131 for (i = 0; i < spec->kctls.used; i++)
4132 kfree(kctl[i].name);
4133 }
4134 snd_array_free(&spec->kctls);
4135}
4136
Matt2f2f4252005-04-13 14:45:30 +02004137static void stac92xx_free(struct hda_codec *codec)
4138{
Mattc7d4b2f2005-06-27 14:59:41 +02004139 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004140
4141 if (! spec)
4142 return;
4143
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004144 kfree(spec->pin_configs);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004145 stac92xx_free_jacks(codec);
4146 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004147
Mattc7d4b2f2005-06-27 14:59:41 +02004148 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004149 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004150}
4151
Matt4e550962005-07-04 17:51:39 +02004152static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4153 unsigned int flag)
4154{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004155 unsigned int old_ctl, pin_ctl;
4156
4157 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004158 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004159
Takashi Iwaif9acba42007-05-29 18:01:06 +02004160 if (pin_ctl & AC_PINCTL_IN_EN) {
4161 /*
4162 * we need to check the current set-up direction of
4163 * shared input pins since they can be switched via
4164 * "xxx as Output" mixer switch
4165 */
4166 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004167 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004168 return;
4169 }
4170
Takashi Iwai8ce84192009-01-22 16:59:20 +01004171 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004172 /* if setting pin direction bits, clear the current
4173 direction bits first */
4174 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4175 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4176
Takashi Iwai8ce84192009-01-22 16:59:20 +01004177 pin_ctl |= flag;
4178 if (old_ctl != pin_ctl)
4179 snd_hda_codec_write_cache(codec, nid, 0,
4180 AC_VERB_SET_PIN_WIDGET_CONTROL,
4181 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004182}
4183
4184static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4185 unsigned int flag)
4186{
4187 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4188 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004189 if (pin_ctl & flag)
4190 snd_hda_codec_write_cache(codec, nid, 0,
4191 AC_VERB_SET_PIN_WIDGET_CONTROL,
4192 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004193}
4194
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004195static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004196{
4197 if (!nid)
4198 return 0;
4199 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004200 & (1 << 31))
4201 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004202 return 0;
4203}
4204
Takashi Iwaid7a89432008-11-12 09:48:04 +01004205/* return non-zero if the hp-pin of the given array index isn't
4206 * a jack-detection target
4207 */
4208static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4209{
4210 struct auto_pin_cfg *cfg = &spec->autocfg;
4211
4212 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004213 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004214 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004215 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004216 return 1;
4217 /* ignore if the pin is set as line-out */
4218 if (cfg->hp_pins[i] == spec->hp_switch)
4219 return 1;
4220 return 0;
4221}
4222
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004223static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004224{
4225 struct sigmatel_spec *spec = codec->spec;
4226 struct auto_pin_cfg *cfg = &spec->autocfg;
4227 int i, presence;
4228
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004229 presence = 0;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01004230 if (spec->gpio_mute)
4231 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4232 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4233
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004234 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004235 if (presence)
4236 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004237 if (no_hp_sensing(spec, i))
4238 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004239 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4240 if (presence) {
4241 unsigned int pinctl;
4242 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4243 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4244 if (pinctl & AC_PINCTL_IN_EN)
4245 presence = 0; /* mic- or line-input */
4246 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004247 }
Matt4e550962005-07-04 17:51:39 +02004248
4249 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004250 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004251 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004252 stac92xx_reset_pinctl(codec, spec->hp_switch,
4253 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004254 for (i = 0; i < cfg->line_outs; i++)
4255 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4256 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004257 for (i = 0; i < cfg->speaker_outs; i++)
4258 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4259 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004260 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004261 stac_gpio_set(codec, spec->gpio_mask,
4262 spec->gpio_dir, spec->gpio_data &
4263 ~spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004264 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004265 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004266 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004267 stac92xx_set_pinctl(codec, spec->hp_switch,
4268 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004269 for (i = 0; i < cfg->line_outs; i++)
4270 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4271 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004272 for (i = 0; i < cfg->speaker_outs; i++)
4273 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4274 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004275 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004276 stac_gpio_set(codec, spec->gpio_mask,
4277 spec->gpio_dir, spec->gpio_data |
4278 spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004279 }
Takashi Iwaid7a89432008-11-12 09:48:04 +01004280 /* toggle hp outs */
4281 for (i = 0; i < cfg->hp_outs; i++) {
4282 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4283 if (no_hp_sensing(spec, i))
4284 continue;
4285 if (presence)
4286 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004287#if 0 /* FIXME */
4288/* Resetting the pinctl like below may lead to (a sort of) regressions
4289 * on some devices since they use the HP pin actually for line/speaker
4290 * outs although the default pin config shows a different pin (that is
4291 * wrong and useless).
4292 *
4293 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4294 * But, disabling the code below just works around it, and I'm too tired of
4295 * bug reports with such devices...
4296 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004297 else
4298 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004299#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004300 }
Matt4e550962005-07-04 17:51:39 +02004301}
4302
Takashi Iwaif73d3582008-11-25 08:21:51 +01004303static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4304 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004305{
4306 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004307 unsigned int idx, val;
4308
4309 for (idx = 0; idx < spec->num_pwrs; idx++) {
4310 if (spec->pwr_nids[idx] == nid)
4311 break;
4312 }
4313 if (idx >= spec->num_pwrs)
4314 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004315
4316 /* several codecs have two power down bits */
4317 if (spec->pwr_mapping)
4318 idx = spec->pwr_mapping[idx];
4319 else
4320 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004321
Takashi Iwaif73d3582008-11-25 08:21:51 +01004322 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4323 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004324 val &= ~idx;
4325 else
4326 val |= idx;
4327
4328 /* power down unused output ports */
4329 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004330}
4331
Takashi Iwaif73d3582008-11-25 08:21:51 +01004332static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4333{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004334 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004335}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004336
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004337static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4338{
4339 struct sigmatel_spec *spec = codec->spec;
4340 struct sigmatel_jack *jacks = spec->jacks.list;
4341
4342 if (jacks) {
4343 int i;
4344 for (i = 0; i < spec->jacks.used; i++) {
4345 if (jacks->nid == nid) {
4346 unsigned int pin_ctl =
4347 snd_hda_codec_read(codec, nid,
4348 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4349 0x00);
4350 int type = jacks->type;
4351 if (type == (SND_JACK_LINEOUT
4352 | SND_JACK_HEADPHONE))
4353 type = (pin_ctl & AC_PINCTL_HP_EN)
4354 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4355 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004356 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004357 ? type : 0);
4358 }
4359 jacks++;
4360 }
4361 }
4362}
Matt2f2f4252005-04-13 14:45:30 +02004363
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004364static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4365 unsigned char type)
4366{
4367 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4368 if (!event)
4369 return;
4370 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4371}
4372
Takashi Iwai314634b2006-09-21 11:56:18 +02004373static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4374{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004375 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004376 struct sigmatel_event *event;
4377 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004378
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004379 tag = (res >> 26) & 0x7f;
4380 event = stac_get_event_from_tag(codec, tag);
4381 if (!event)
4382 return;
4383
4384 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004385 case STAC_HP_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004386 stac92xx_hp_detect(codec);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004387 /* fallthru */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004388 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004389 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004390 if (spec->num_pwrs > 0)
4391 stac92xx_pin_sense(codec, event->nid);
4392 stac92xx_report_jack(codec, event->nid);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004393 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004394 case STAC_VREF_EVENT:
4395 data = snd_hda_codec_read(codec, codec->afg, 0,
4396 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004397 /* toggle VREF state based on GPIOx status */
4398 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004399 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004400 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004401 }
4402}
4403
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004404#ifdef CONFIG_PROC_FS
4405static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4406 struct hda_codec *codec, hda_nid_t nid)
4407{
4408 if (nid == codec->afg)
4409 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4410 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4411}
4412
4413static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4414 struct hda_codec *codec,
4415 unsigned int verb)
4416{
4417 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4418 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4419}
4420
4421/* stac92hd71bxx, stac92hd73xx */
4422static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4423 struct hda_codec *codec, hda_nid_t nid)
4424{
4425 stac92hd_proc_hook(buffer, codec, nid);
4426 if (nid == codec->afg)
4427 analog_loop_proc_hook(buffer, codec, 0xfa0);
4428}
4429
4430static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4431 struct hda_codec *codec, hda_nid_t nid)
4432{
4433 if (nid == codec->afg)
4434 analog_loop_proc_hook(buffer, codec, 0xfe0);
4435}
4436
4437static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4438 struct hda_codec *codec, hda_nid_t nid)
4439{
4440 if (nid == codec->afg)
4441 analog_loop_proc_hook(buffer, codec, 0xfeb);
4442}
4443#else
4444#define stac92hd_proc_hook NULL
4445#define stac92hd7x_proc_hook NULL
4446#define stac9205_proc_hook NULL
4447#define stac927x_proc_hook NULL
4448#endif
4449
Takashi Iwaicb53c622007-08-10 17:21:45 +02004450#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004451static int stac92xx_resume(struct hda_codec *codec)
4452{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004453 struct sigmatel_spec *spec = codec->spec;
4454
Richard Fish11b44bb2006-08-23 18:31:34 +02004455 stac92xx_set_config_regs(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004456 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004457 snd_hda_codec_resume_amp(codec);
4458 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004459 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004460 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004461 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4462 STAC_HP_EVENT);
Mattff6fdc32005-06-27 15:06:52 +02004463 return 0;
4464}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004465
4466static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4467{
4468 struct sigmatel_spec *spec = codec->spec;
4469 if (spec->eapd_mask)
4470 stac_gpio_set(codec, spec->gpio_mask,
4471 spec->gpio_dir, spec->gpio_data &
4472 ~spec->eapd_mask);
4473 return 0;
4474}
Mattff6fdc32005-06-27 15:06:52 +02004475#endif
4476
Matt2f2f4252005-04-13 14:45:30 +02004477static struct hda_codec_ops stac92xx_patch_ops = {
4478 .build_controls = stac92xx_build_controls,
4479 .build_pcms = stac92xx_build_pcms,
4480 .init = stac92xx_init,
4481 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004482 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004483#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004484 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004485 .resume = stac92xx_resume,
4486#endif
Matt2f2f4252005-04-13 14:45:30 +02004487};
4488
4489static int patch_stac9200(struct hda_codec *codec)
4490{
4491 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004492 int err;
Matt2f2f4252005-04-13 14:45:30 +02004493
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004494 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004495 if (spec == NULL)
4496 return -ENOMEM;
4497
4498 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004499 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004500 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004501 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4502 stac9200_models,
4503 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02004504 if (spec->board_config < 0) {
4505 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4506 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004507 } else
4508 err = stac_save_pin_cfgs(codec,
4509 stac9200_brd_tbl[spec->board_config]);
4510 if (err < 0) {
4511 stac92xx_free(codec);
4512 return err;
Matt Porter403d1942005-11-29 15:00:51 +01004513 }
Matt2f2f4252005-04-13 14:45:30 +02004514
4515 spec->multiout.max_channels = 2;
4516 spec->multiout.num_dacs = 1;
4517 spec->multiout.dac_nids = stac9200_dac_nids;
4518 spec->adc_nids = stac9200_adc_nids;
4519 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004520 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004521 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004522 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004523 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004524
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02004525 if (spec->board_config == STAC_9200_M4 ||
4526 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01004527 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004528 spec->init = stac9200_eapd_init;
4529 else
4530 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004531 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004532
Takashi Iwai117f2572008-03-18 09:53:23 +01004533 if (spec->board_config == STAC_9200_PANASONIC) {
4534 spec->gpio_mask = spec->gpio_dir = 0x09;
4535 spec->gpio_data = 0x00;
4536 }
4537
Mattc7d4b2f2005-06-27 14:59:41 +02004538 err = stac9200_parse_auto_config(codec);
4539 if (err < 0) {
4540 stac92xx_free(codec);
4541 return err;
4542 }
Matt2f2f4252005-04-13 14:45:30 +02004543
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01004544 /* CF-74 has no headphone detection, and the driver should *NOT*
4545 * do detection and HP/speaker toggle because the hardware does it.
4546 */
4547 if (spec->board_config == STAC_9200_PANASONIC)
4548 spec->hp_detect = 0;
4549
Matt2f2f4252005-04-13 14:45:30 +02004550 codec->patch_ops = stac92xx_patch_ops;
4551
4552 return 0;
4553}
4554
Tobin Davis8e21c342007-01-08 11:04:17 +01004555static int patch_stac925x(struct hda_codec *codec)
4556{
4557 struct sigmatel_spec *spec;
4558 int err;
4559
4560 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4561 if (spec == NULL)
4562 return -ENOMEM;
4563
4564 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004565 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004566 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004567
4568 /* Check first for codec ID */
4569 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
4570 STAC_925x_MODELS,
4571 stac925x_models,
4572 stac925x_codec_id_cfg_tbl);
4573
4574 /* Now checks for PCI ID, if codec ID is not found */
4575 if (spec->board_config < 0)
4576 spec->board_config = snd_hda_check_board_config(codec,
4577 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01004578 stac925x_models,
4579 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004580 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01004581 if (spec->board_config < 0) {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004582 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
Tobin Davis2c11f952007-05-17 09:36:34 +02004583 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01004584 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004585 } else
4586 err = stac_save_pin_cfgs(codec,
4587 stac925x_brd_tbl[spec->board_config]);
4588 if (err < 0) {
4589 stac92xx_free(codec);
4590 return err;
Tobin Davis8e21c342007-01-08 11:04:17 +01004591 }
4592
4593 spec->multiout.max_channels = 2;
4594 spec->multiout.num_dacs = 1;
4595 spec->multiout.dac_nids = stac925x_dac_nids;
4596 spec->adc_nids = stac925x_adc_nids;
4597 spec->mux_nids = stac925x_mux_nids;
4598 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004599 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004600 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004601 switch (codec->vendor_id) {
4602 case 0x83847632: /* STAC9202 */
4603 case 0x83847633: /* STAC9202D */
4604 case 0x83847636: /* STAC9251 */
4605 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004606 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004607 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004608 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4609 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004610 break;
4611 default:
4612 spec->num_dmics = 0;
4613 break;
4614 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004615
4616 spec->init = stac925x_core_init;
4617 spec->mixer = stac925x_mixer;
4618
4619 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004620 if (!err) {
4621 if (spec->board_config < 0) {
4622 printk(KERN_WARNING "hda_codec: No auto-config is "
4623 "available, default to model=ref\n");
4624 spec->board_config = STAC_925x_REF;
4625 goto again;
4626 }
4627 err = -EINVAL;
4628 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004629 if (err < 0) {
4630 stac92xx_free(codec);
4631 return err;
4632 }
4633
4634 codec->patch_ops = stac92xx_patch_ops;
4635
4636 return 0;
4637}
4638
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004639static struct hda_input_mux stac92hd73xx_dmux = {
4640 .num_items = 4,
4641 .items = {
4642 { "Analog Inputs", 0x0b },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004643 { "Digital Mic 1", 0x09 },
4644 { "Digital Mic 2", 0x0a },
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004645 { "CD", 0x08 },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004646 }
4647};
4648
4649static int patch_stac92hd73xx(struct hda_codec *codec)
4650{
4651 struct sigmatel_spec *spec;
4652 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4653 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004654 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004655
4656 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4657 if (spec == NULL)
4658 return -ENOMEM;
4659
4660 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004661 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004662 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4663 spec->pin_nids = stac92hd73xx_pin_nids;
4664 spec->board_config = snd_hda_check_board_config(codec,
4665 STAC_92HD73XX_MODELS,
4666 stac92hd73xx_models,
4667 stac92hd73xx_cfg_tbl);
4668again:
4669 if (spec->board_config < 0) {
4670 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4671 " STAC92HD73XX, using BIOS defaults\n");
4672 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004673 } else
4674 err = stac_save_pin_cfgs(codec,
4675 stac92hd73xx_brd_tbl[spec->board_config]);
4676 if (err < 0) {
4677 stac92xx_free(codec);
4678 return err;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004679 }
4680
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004681 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004682 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4683
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004684 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004685 printk(KERN_WARNING "hda_codec: Could not determine "
4686 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004687 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004688 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004689 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004690 case 0x3: /* 6 Channel */
4691 spec->mixer = stac92hd73xx_6ch_mixer;
4692 spec->init = stac92hd73xx_6ch_core_init;
4693 break;
4694 case 0x4: /* 8 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004695 spec->mixer = stac92hd73xx_8ch_mixer;
4696 spec->init = stac92hd73xx_8ch_core_init;
4697 break;
4698 case 0x5: /* 10 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004699 spec->mixer = stac92hd73xx_10ch_mixer;
4700 spec->init = stac92hd73xx_10ch_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004701 }
4702 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004703
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004704 spec->aloopback_mask = 0x01;
4705 spec->aloopback_shift = 8;
4706
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004707 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004708 spec->mux_nids = stac92hd73xx_mux_nids;
4709 spec->adc_nids = stac92hd73xx_adc_nids;
4710 spec->dmic_nids = stac92hd73xx_dmic_nids;
4711 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004712 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04004713 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004714 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004715
4716 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4717 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01004718 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004719 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4720 sizeof(stac92hd73xx_dmux));
4721
Matthew Ranostaya7662642008-02-21 07:51:14 +01004722 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004723 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004724 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004725 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004726 case STAC_DELL_M6_AMIC:
4727 case STAC_DELL_M6_DMIC:
4728 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004729 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004730 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4731 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004732 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004733 spec->num_amps = 1;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004734
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004735 if (spec->board_config != STAC_DELL_EQ)
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004736 spec->init = dell_m6_core_init;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004737 switch (spec->board_config) {
4738 case STAC_DELL_M6_AMIC: /* Analog Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004739 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4740 spec->num_dmics = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004741 spec->private_dimux.num_items = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004742 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004743 case STAC_DELL_M6_DMIC: /* Digital Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004744 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4745 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004746 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004747 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004748 case STAC_DELL_M6_BOTH: /* Both */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004749 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4750 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4751 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004752 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004753 break;
4754 }
4755 break;
4756 default:
4757 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004758 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004759 spec->eapd_switch = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004760 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04004761 if (spec->board_config > STAC_92HD73XX_REF) {
4762 /* GPIO0 High = Enable EAPD */
4763 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4764 spec->gpio_data = 0x01;
4765 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004766 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004767
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004768 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4769 spec->pwr_nids = stac92hd73xx_pwr_nids;
4770
Matthew Ranostayd9737752008-09-07 12:03:41 +02004771 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004772
4773 if (!err) {
4774 if (spec->board_config < 0) {
4775 printk(KERN_WARNING "hda_codec: No auto-config is "
4776 "available, default to model=ref\n");
4777 spec->board_config = STAC_92HD73XX_REF;
4778 goto again;
4779 }
4780 err = -EINVAL;
4781 }
4782
4783 if (err < 0) {
4784 stac92xx_free(codec);
4785 return err;
4786 }
4787
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01004788 if (spec->board_config == STAC_92HD73XX_NO_JD)
4789 spec->hp_detect = 0;
4790
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004791 codec->patch_ops = stac92xx_patch_ops;
4792
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004793 codec->proc_widget_hook = stac92hd7x_proc_hook;
4794
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004795 return 0;
4796}
4797
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004798static struct hda_input_mux stac92hd83xxx_dmux = {
4799 .num_items = 3,
4800 .items = {
4801 { "Analog Inputs", 0x03 },
4802 { "Digital Mic 1", 0x04 },
4803 { "Digital Mic 2", 0x05 },
4804 }
4805};
4806
4807static int patch_stac92hd83xxx(struct hda_codec *codec)
4808{
4809 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05004810 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004811 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05004812 int num_dacs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004813
4814 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4815 if (spec == NULL)
4816 return -ENOMEM;
4817
4818 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004819 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004820 spec->mono_nid = 0x19;
4821 spec->digbeep_nid = 0x21;
4822 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4823 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4824 spec->adc_nids = stac92hd83xxx_adc_nids;
4825 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayc15c5062009-01-13 13:30:07 -05004826 spec->amp_nids = stac92hd83xxx_amp_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004827 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4828 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004829 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004830
Matthew Ranostay65557f32009-01-20 16:50:25 -05004831
4832 /* set port 0xe to select the last DAC
4833 */
4834 num_dacs = snd_hda_get_connections(codec, 0x0e,
4835 conn, STAC92HD83_DAC_COUNT + 1) - 1;
4836
4837 snd_hda_codec_write_cache(codec, 0xe, 0,
4838 AC_VERB_SET_CONNECT_SEL, num_dacs);
4839
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004840 spec->init = stac92hd83xxx_core_init;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004841 spec->mixer = stac92hd83xxx_mixer;
4842 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4843 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4844 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayc15c5062009-01-13 13:30:07 -05004845 spec->num_amps = ARRAY_SIZE(stac92hd83xxx_amp_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004846 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4847 spec->dinput_mux = &stac92hd83xxx_dmux;
4848 spec->pin_nids = stac92hd83xxx_pin_nids;
4849 spec->board_config = snd_hda_check_board_config(codec,
4850 STAC_92HD83XXX_MODELS,
4851 stac92hd83xxx_models,
4852 stac92hd83xxx_cfg_tbl);
4853again:
4854 if (spec->board_config < 0) {
4855 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4856 " STAC92HD83XXX, using BIOS defaults\n");
4857 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004858 } else
4859 err = stac_save_pin_cfgs(codec,
4860 stac92hd83xxx_brd_tbl[spec->board_config]);
4861 if (err < 0) {
4862 stac92xx_free(codec);
4863 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004864 }
4865
Matthew Ranostay32ed3f42009-01-22 20:53:29 -05004866 switch (codec->vendor_id) {
4867 case 0x111d7604:
4868 case 0x111d7605:
4869 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
4870 break;
4871 spec->num_pwrs = 0;
4872 break;
4873 }
4874
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004875 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4876 if (!err) {
4877 if (spec->board_config < 0) {
4878 printk(KERN_WARNING "hda_codec: No auto-config is "
4879 "available, default to model=ref\n");
4880 spec->board_config = STAC_92HD83XXX_REF;
4881 goto again;
4882 }
4883 err = -EINVAL;
4884 }
4885
4886 if (err < 0) {
4887 stac92xx_free(codec);
4888 return err;
4889 }
4890
4891 codec->patch_ops = stac92xx_patch_ops;
4892
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004893 codec->proc_widget_hook = stac92hd_proc_hook;
4894
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004895 return 0;
4896}
4897
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004898static struct hda_input_mux stac92hd71bxx_dmux = {
4899 .num_items = 4,
4900 .items = {
4901 { "Analog Inputs", 0x00 },
4902 { "Mixer", 0x01 },
4903 { "Digital Mic 1", 0x02 },
4904 { "Digital Mic 2", 0x03 },
4905 }
4906};
4907
Matthew Ranostaye035b842007-11-06 11:53:55 +01004908static int patch_stac92hd71bxx(struct hda_codec *codec)
4909{
4910 struct sigmatel_spec *spec;
4911 int err = 0;
4912
4913 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4914 if (spec == NULL)
4915 return -ENOMEM;
4916
4917 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004918 codec->patch_ops = stac92xx_patch_ops;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004919 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004920 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004921 spec->pin_nids = stac92hd71bxx_pin_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004922 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4923 sizeof(stac92hd71bxx_dmux));
Matthew Ranostaye035b842007-11-06 11:53:55 +01004924 spec->board_config = snd_hda_check_board_config(codec,
4925 STAC_92HD71BXX_MODELS,
4926 stac92hd71bxx_models,
4927 stac92hd71bxx_cfg_tbl);
4928again:
4929 if (spec->board_config < 0) {
4930 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4931 " STAC92HD71BXX, using BIOS defaults\n");
4932 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004933 } else
4934 err = stac_save_pin_cfgs(codec,
4935 stac92hd71bxx_brd_tbl[spec->board_config]);
4936 if (err < 0) {
4937 stac92xx_free(codec);
4938 return err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004939 }
4940
Takashi Iwai41c3b642008-11-18 10:45:15 +01004941 if (spec->board_config > STAC_92HD71BXX_REF) {
4942 /* GPIO0 = EAPD */
4943 spec->gpio_mask = 0x01;
4944 spec->gpio_dir = 0x01;
4945 spec->gpio_data = 0x01;
4946 }
4947
Matthew Ranostay541eee82007-12-14 12:08:04 +01004948 switch (codec->vendor_id) {
4949 case 0x111d76b6: /* 4 Port without Analog Mixer */
4950 case 0x111d76b7:
4951 case 0x111d76b4: /* 6 Port without Analog Mixer */
4952 case 0x111d76b5:
4953 spec->mixer = stac92hd71bxx_mixer;
4954 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004955 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004956 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004957 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01004958 switch (spec->board_config) {
4959 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04004960 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004961 err = stac_add_event(spec, codec->afg,
4962 STAC_VREF_EVENT, 0x02);
4963 if (err < 0)
4964 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01004965 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04004966 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4967 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004968 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004969 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004970 spec->gpio_mask |= 0x02;
4971 break;
4972 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004973 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004974 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004975 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004976
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004977 /* no output amps */
4978 spec->num_pwrs = 0;
4979 spec->mixer = stac92hd71bxx_analog_mixer;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004980 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004981
4982 /* disable VSW */
4983 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004984 stac_change_pin_config(codec, 0xf, 0x40f000f0);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004985 break;
4986 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004987 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004988 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004989
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004990 /* no output amps */
4991 spec->num_pwrs = 0;
4992 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01004993 default:
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004994 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004995 spec->mixer = stac92hd71bxx_analog_mixer;
4996 spec->init = stac92hd71bxx_analog_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004997 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004998 }
4999
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005000 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01005001 spec->aloopback_shift = 0;
5002
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02005003 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005004 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005005 spec->mux_nids = stac92hd71bxx_mux_nids;
5006 spec->adc_nids = stac92hd71bxx_adc_nids;
5007 spec->dmic_nids = stac92hd71bxx_dmic_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005008 spec->dmux_nids = stac92hd71bxx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02005009 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005010 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01005011
5012 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
5013 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005014
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005015 switch (spec->board_config) {
5016 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005017 /* enable internal microphone */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005018 stac_change_pin_config(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04005019 stac92xx_auto_set_pinctl(codec, 0x0e,
5020 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005021 /* fallthru */
5022 case STAC_DELL_M4_2:
5023 spec->num_dmics = 0;
5024 spec->num_smuxes = 0;
5025 spec->num_dmuxes = 0;
5026 break;
5027 case STAC_DELL_M4_1:
5028 case STAC_DELL_M4_3:
5029 spec->num_dmics = 1;
5030 spec->num_smuxes = 0;
5031 spec->num_dmuxes = 0;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005032 break;
5033 default:
5034 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
5035 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
5036 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5037 };
5038
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005039 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005040 if (spec->dinput_mux)
5041 spec->private_dimux.num_items +=
5042 spec->num_dmics -
5043 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005044
5045 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
5046 if (!err) {
5047 if (spec->board_config < 0) {
5048 printk(KERN_WARNING "hda_codec: No auto-config is "
5049 "available, default to model=ref\n");
5050 spec->board_config = STAC_92HD71BXX_REF;
5051 goto again;
5052 }
5053 err = -EINVAL;
5054 }
5055
5056 if (err < 0) {
5057 stac92xx_free(codec);
5058 return err;
5059 }
5060
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005061 codec->proc_widget_hook = stac92hd7x_proc_hook;
5062
Matthew Ranostaye035b842007-11-06 11:53:55 +01005063 return 0;
5064};
5065
Matt2f2f4252005-04-13 14:45:30 +02005066static int patch_stac922x(struct hda_codec *codec)
5067{
5068 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005069 int err;
Matt2f2f4252005-04-13 14:45:30 +02005070
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005071 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005072 if (spec == NULL)
5073 return -ENOMEM;
5074
5075 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005076 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005077 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005078 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5079 stac922x_models,
5080 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005081 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005082 spec->gpio_mask = spec->gpio_dir = 0x03;
5083 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005084 /* Intel Macs have all same PCI SSID, so we need to check
5085 * codec SSID to distinguish the exact models
5086 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005087 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005088 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005089
5090 case 0x106b0800:
5091 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005092 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005093 case 0x106b0600:
5094 case 0x106b0700:
5095 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005096 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005097 case 0x106b0e00:
5098 case 0x106b0f00:
5099 case 0x106b1600:
5100 case 0x106b1700:
5101 case 0x106b0200:
5102 case 0x106b1e00:
5103 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005104 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005105 case 0x106b1a00:
5106 case 0x00000100:
5107 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005108 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005109 case 0x106b0a00:
5110 case 0x106b2200:
5111 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005112 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005113 default:
5114 spec->board_config = STAC_INTEL_MAC_V3;
5115 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005116 }
5117 }
5118
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005119 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02005120 if (spec->board_config < 0) {
5121 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
5122 "using BIOS defaults\n");
5123 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005124 } else
5125 err = stac_save_pin_cfgs(codec,
5126 stac922x_brd_tbl[spec->board_config]);
5127 if (err < 0) {
5128 stac92xx_free(codec);
5129 return err;
Matt Porter403d1942005-11-29 15:00:51 +01005130 }
Matt2f2f4252005-04-13 14:45:30 +02005131
Matt2f2f4252005-04-13 14:45:30 +02005132 spec->adc_nids = stac922x_adc_nids;
5133 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005134 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005135 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005136 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005137 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005138
5139 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005140 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005141
5142 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005143
Matt Porter3cc08dc2006-01-23 15:27:49 +01005144 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005145 if (!err) {
5146 if (spec->board_config < 0) {
5147 printk(KERN_WARNING "hda_codec: No auto-config is "
5148 "available, default to model=ref\n");
5149 spec->board_config = STAC_D945_REF;
5150 goto again;
5151 }
5152 err = -EINVAL;
5153 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005154 if (err < 0) {
5155 stac92xx_free(codec);
5156 return err;
5157 }
5158
5159 codec->patch_ops = stac92xx_patch_ops;
5160
Takashi Iwai807a46362007-05-29 19:01:37 +02005161 /* Fix Mux capture level; max to 2 */
5162 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5163 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5164 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5165 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5166 (0 << AC_AMPCAP_MUTE_SHIFT));
5167
Matt Porter3cc08dc2006-01-23 15:27:49 +01005168 return 0;
5169}
5170
5171static int patch_stac927x(struct hda_codec *codec)
5172{
5173 struct sigmatel_spec *spec;
5174 int err;
5175
5176 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5177 if (spec == NULL)
5178 return -ENOMEM;
5179
5180 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005181 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005182 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005183 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5184 stac927x_models,
5185 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005186 again:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005187 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
5188 if (spec->board_config < 0)
5189 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5190 "STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02005191 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005192 } else
5193 err = stac_save_pin_cfgs(codec,
5194 stac927x_brd_tbl[spec->board_config]);
5195 if (err < 0) {
5196 stac92xx_free(codec);
5197 return err;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005198 }
5199
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005200 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005201 spec->adc_nids = stac927x_adc_nids;
5202 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5203 spec->mux_nids = stac927x_mux_nids;
5204 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005205 spec->smux_nids = stac927x_smux_nids;
5206 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005207 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005208 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005209 spec->multiout.dac_nids = spec->dac_nids;
5210
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005211 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005212 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005213 case STAC_D965_5ST:
5214 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005215 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005216 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005217 spec->num_dmics = 0;
5218
Tobin Davis93ed1502006-09-01 21:03:12 +02005219 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005220 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005221 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005222 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005223 switch (codec->subsystem_id) {
5224 case 0x10280209:
5225 case 0x1028022e:
5226 /* correct the device field to SPDIF out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005227 stac_change_pin_config(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005228 break;
5229 };
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005230 /* configure the analog microphone on some laptops */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005231 stac_change_pin_config(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005232 /* correct the front output jack as a hp out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005233 stac_change_pin_config(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005234 /* correct the front input jack as a mic */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005235 stac_change_pin_config(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005236 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005237 case STAC_DELL_3ST:
5238 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005239 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005240 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005241 spec->dmic_nids = stac927x_dmic_nids;
5242 spec->num_dmics = STAC927X_NUM_DMICS;
5243
Tobin Davis93ed1502006-09-01 21:03:12 +02005244 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005245 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005246 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005247 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005248 break;
5249 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005250 if (spec->board_config > STAC_D965_REF) {
5251 /* GPIO0 High = Enable EAPD */
5252 spec->eapd_mask = spec->gpio_mask = 0x01;
5253 spec->gpio_dir = spec->gpio_data = 0x01;
5254 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005255 spec->num_dmics = 0;
5256
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005257 spec->init = stac927x_core_init;
5258 spec->mixer = stac927x_mixer;
5259 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005260
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005261 spec->num_pwrs = 0;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005262 spec->aloopback_mask = 0x40;
5263 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005264 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005265
Matt Porter3cc08dc2006-01-23 15:27:49 +01005266 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005267 if (!err) {
5268 if (spec->board_config < 0) {
5269 printk(KERN_WARNING "hda_codec: No auto-config is "
5270 "available, default to model=ref\n");
5271 spec->board_config = STAC_D965_REF;
5272 goto again;
5273 }
5274 err = -EINVAL;
5275 }
Mattc7d4b2f2005-06-27 14:59:41 +02005276 if (err < 0) {
5277 stac92xx_free(codec);
5278 return err;
5279 }
Matt2f2f4252005-04-13 14:45:30 +02005280
5281 codec->patch_ops = stac92xx_patch_ops;
5282
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005283 codec->proc_widget_hook = stac927x_proc_hook;
5284
Takashi Iwai52987652008-01-16 16:09:47 +01005285 /*
5286 * !!FIXME!!
5287 * The STAC927x seem to require fairly long delays for certain
5288 * command sequences. With too short delays (even if the answer
5289 * is set to RIRB properly), it results in the silence output
5290 * on some hardwares like Dell.
5291 *
5292 * The below flag enables the longer delay (see get_response
5293 * in hda_intel.c).
5294 */
5295 codec->bus->needs_damn_long_delay = 1;
5296
Takashi Iwaie28d8322008-12-17 13:48:29 +01005297 /* no jack detecion for ref-no-jd model */
5298 if (spec->board_config == STAC_D965_REF_NO_JD)
5299 spec->hp_detect = 0;
5300
Matt2f2f4252005-04-13 14:45:30 +02005301 return 0;
5302}
5303
Matt Porterf3302a52006-07-31 12:49:34 +02005304static int patch_stac9205(struct hda_codec *codec)
5305{
5306 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005307 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005308
5309 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5310 if (spec == NULL)
5311 return -ENOMEM;
5312
5313 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005314 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005315 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005316 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5317 stac9205_models,
5318 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005319 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02005320 if (spec->board_config < 0) {
5321 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
5322 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005323 } else
5324 err = stac_save_pin_cfgs(codec,
5325 stac9205_brd_tbl[spec->board_config]);
5326 if (err < 0) {
5327 stac92xx_free(codec);
5328 return err;
Matt Porterf3302a52006-07-31 12:49:34 +02005329 }
5330
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005331 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005332 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005333 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005334 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005335 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005336 spec->smux_nids = stac9205_smux_nids;
5337 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005338 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005339 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005340 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005341 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005342 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005343
5344 spec->init = stac9205_core_init;
5345 spec->mixer = stac9205_mixer;
5346
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005347 spec->aloopback_mask = 0x40;
5348 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01005349 /* Turn on/off EAPD per HP plugging */
5350 if (spec->board_config != STAC_9205_EAPD)
5351 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005352 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005353
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005354 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005355 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005356 /* Enable SPDIF in/out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005357 stac_change_pin_config(codec, 0x1f, 0x01441030);
5358 stac_change_pin_config(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005359
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005360 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005361 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5362 if (err < 0)
5363 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005364 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005365 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5366 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005367 AC_VERB_SET_UNSOLICITED_ENABLE,
5368 AC_USRSP_EN | err);
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005369
5370 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005371 spec->eapd_mask = 0x01;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005372 spec->gpio_mask = 0x1b;
5373 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005374 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005375 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005376 */
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005377 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005378 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005379 case STAC_9205_REF:
5380 /* SPDIF-In enabled */
5381 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005382 default:
5383 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005384 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe5195c2008-01-29 15:28:44 +01005385 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005386 break;
5387 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005388
Matt Porterf3302a52006-07-31 12:49:34 +02005389 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005390 if (!err) {
5391 if (spec->board_config < 0) {
5392 printk(KERN_WARNING "hda_codec: No auto-config is "
5393 "available, default to model=ref\n");
5394 spec->board_config = STAC_9205_REF;
5395 goto again;
5396 }
5397 err = -EINVAL;
5398 }
Matt Porterf3302a52006-07-31 12:49:34 +02005399 if (err < 0) {
5400 stac92xx_free(codec);
5401 return err;
5402 }
5403
5404 codec->patch_ops = stac92xx_patch_ops;
5405
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005406 codec->proc_widget_hook = stac9205_proc_hook;
5407
Matt Porterf3302a52006-07-31 12:49:34 +02005408 return 0;
5409}
5410
Matt2f2f4252005-04-13 14:45:30 +02005411/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005412 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005413 */
5414
Takashi Iwai1e137f92009-01-21 07:41:22 +01005415static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02005416 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005417 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5418 {}
5419};
5420
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005421static struct snd_kcontrol_new stac9872_mixer[] = {
5422 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5423 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5424 STAC_INPUT_SOURCE(1),
5425 { } /* end */
5426};
5427
5428static hda_nid_t stac9872_pin_nids[] = {
5429 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5430 0x11, 0x13, 0x14,
5431};
5432
5433static hda_nid_t stac9872_adc_nids[] = {
5434 0x8 /*,0x6*/
5435};
5436
5437static hda_nid_t stac9872_mux_nids[] = {
5438 0x15
5439};
5440
Guillaume Munch6d859062006-08-22 17:15:47 +02005441static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005442{
5443 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01005444 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005445
Takashi Iwaidb064e52006-03-16 16:04:58 +01005446 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5447 if (spec == NULL)
5448 return -ENOMEM;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005449 codec->spec = spec;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005450
Takashi Iwai1e137f92009-01-21 07:41:22 +01005451#if 0 /* no model right now */
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005452 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5453 stac9872_models,
5454 stac9872_cfg_tbl);
Takashi Iwai1e137f92009-01-21 07:41:22 +01005455#endif
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005456
Takashi Iwai1e137f92009-01-21 07:41:22 +01005457 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5458 spec->pin_nids = stac9872_pin_nids;
5459 spec->multiout.dac_nids = spec->dac_nids;
5460 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5461 spec->adc_nids = stac9872_adc_nids;
5462 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5463 spec->mux_nids = stac9872_mux_nids;
5464 spec->mixer = stac9872_mixer;
5465 spec->init = stac9872_core_init;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005466
Takashi Iwai1e137f92009-01-21 07:41:22 +01005467 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5468 if (err < 0) {
5469 stac92xx_free(codec);
5470 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005471 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01005472 spec->input_mux = &spec->private_imux;
5473 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005474 return 0;
5475}
5476
5477
5478/*
Matt2f2f4252005-04-13 14:45:30 +02005479 * patch entries
5480 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005481static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02005482 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5483 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5484 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5485 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5486 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5487 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5488 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005489 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5490 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5491 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5492 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5493 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5494 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005495 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5496 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5497 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5498 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5499 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5500 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5501 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5502 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5503 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5504 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005505 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5506 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5507 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5508 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5509 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5510 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005511 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5512 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005513 /* The following does not take into account .id=0x83847661 when subsys =
5514 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5515 * currently not fully supported.
5516 */
5517 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5518 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5519 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02005520 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5521 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5522 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5523 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5524 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5525 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5526 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5527 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005528 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005529 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5530 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005531 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005532 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5533 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005534 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005535 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5536 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5537 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5538 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5539 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5540 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5541 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5542 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005543 {} /* terminator */
5544};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005545
5546MODULE_ALIAS("snd-hda-codec-id:8384*");
5547MODULE_ALIAS("snd-hda-codec-id:111d*");
5548
5549MODULE_LICENSE("GPL");
5550MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5551
5552static struct hda_codec_preset_list sigmatel_list = {
5553 .preset = snd_hda_preset_sigmatel,
5554 .owner = THIS_MODULE,
5555};
5556
5557static int __init patch_sigmatel_init(void)
5558{
5559 return snd_hda_add_codec_preset(&sigmatel_list);
5560}
5561
5562static void __exit patch_sigmatel_exit(void)
5563{
5564 snd_hda_delete_codec_preset(&sigmatel_list);
5565}
5566
5567module_init(patch_sigmatel_init)
5568module_exit(patch_sigmatel_exit)