blob: ed2fa431b03f23254c6bb3487b9d27d60255a9c0 [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,
85 STAC_92HD83XXX_MODELS
86};
87
88enum {
Matthew Ranostaye035b842007-11-06 11:53:55 +010089 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010090 STAC_DELL_M4_1,
91 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -050092 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -040093 STAC_HP_M4,
Takashi Iwai1b0652e2009-01-14 08:27:35 +010094 STAC_HP_DV5,
Matthew Ranostaye035b842007-11-06 11:53:55 +010095 STAC_92HD71BXX_MODELS
96};
97
98enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010099 STAC_925x_REF,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200100 STAC_M1,
101 STAC_M1_2,
102 STAC_M2,
Tobin Davis8e21c342007-01-08 11:04:17 +0100103 STAC_M2_2,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +0200104 STAC_M3,
105 STAC_M5,
106 STAC_M6,
Tobin Davis8e21c342007-01-08 11:04:17 +0100107 STAC_925x_MODELS
108};
109
110enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100111 STAC_D945_REF,
112 STAC_D945GTP3,
113 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200114 STAC_INTEL_MAC_V1,
115 STAC_INTEL_MAC_V2,
116 STAC_INTEL_MAC_V3,
117 STAC_INTEL_MAC_V4,
118 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800119 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
120 * is given, one of the above models will be
121 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200122 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100123 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100124 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100125 STAC_MACBOOK_PRO_V1,
126 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200127 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200128 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300129 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200130 STAC_922X_DELL_D81,
131 STAC_922X_DELL_D82,
132 STAC_922X_DELL_M81,
133 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100134 STAC_922X_MODELS
135};
136
137enum {
Takashi Iwaie28d8322008-12-17 13:48:29 +0100138 STAC_D965_REF_NO_JD, /* no jack-detection */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100139 STAC_D965_REF,
140 STAC_D965_3ST,
141 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200142 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100143 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100144 STAC_927X_MODELS
145};
Matt Porter403d1942005-11-29 15:00:51 +0100146
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400147struct sigmatel_event {
148 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100149 unsigned char type;
150 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400151 int data;
152};
153
154struct sigmatel_jack {
155 hda_nid_t nid;
156 int type;
157 struct snd_jack *jack;
158};
159
Matt2f2f4252005-04-13 14:45:30 +0200160struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100161 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200162 unsigned int num_mixers;
163
Matt Porter403d1942005-11-29 15:00:51 +0100164 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500165 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200166 unsigned int surr_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100167 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100168 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400169 unsigned int spdif_mute: 1;
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100170 unsigned int check_volume_offset:1;
Mattc7d4b2f2005-06-27 14:59:41 +0200171
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100172 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200173 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100174 unsigned int gpio_mask;
175 unsigned int gpio_dir;
176 unsigned int gpio_data;
177 unsigned int gpio_mute;
178
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200179 /* stream */
180 unsigned int stream_delay;
181
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100182 /* analog loopback */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100183 unsigned char aloopback_mask;
184 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200185
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100186 /* power management */
187 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200188 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100189 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100190 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100191
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400192 /* jack detection */
193 struct snd_array jacks;
194
195 /* events */
196 struct snd_array events;
197
Matt2f2f4252005-04-13 14:45:30 +0200198 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100199 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400200 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100201 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200202 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100203 hda_nid_t dac_nids[5];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100204 hda_nid_t hp_dacs[5];
205 hda_nid_t speaker_dacs[5];
Matt2f2f4252005-04-13 14:45:30 +0200206
Takashi Iwai7c7767e2009-01-20 15:28:38 +0100207 int volume_offset;
208
Matt2f2f4252005-04-13 14:45:30 +0200209 /* capture */
210 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200211 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200212 hda_nid_t *mux_nids;
213 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200214 hda_nid_t *dmic_nids;
215 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100216 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100217 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200218 hda_nid_t *smux_nids;
219 unsigned int num_smuxes;
Matthew Ranostay65973632008-09-16 10:39:37 -0400220 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200221
Mattdabbed62005-06-14 10:19:34 +0200222 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100223 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200224 hda_nid_t anabeep_nid;
225 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200226
Matt2f2f4252005-04-13 14:45:30 +0200227 /* pin widgets */
228 hda_nid_t *pin_nids;
229 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200230 unsigned int *pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200231
232 /* codec specific stuff */
233 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100234 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200235
236 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200237 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100238 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200239 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100240 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200241 struct hda_input_mux *sinput_mux;
242 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400243 unsigned int cur_amux;
244 hda_nid_t *amp_nids;
245 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200246 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200247
Matt Porter403d1942005-11-29 15:00:51 +0100248 /* i/o switches */
249 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200250 unsigned int clfe_swap;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +0100251 hda_nid_t line_switch; /* shared line-in for input and output */
252 hda_nid_t mic_switch; /* shared mic-in for input and output */
253 hda_nid_t hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200254 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200255
Mattc7d4b2f2005-06-27 14:59:41 +0200256 struct hda_pcm pcm_rec[2]; /* PCM information */
257
258 /* dynamic controls and input_mux */
259 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200260 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200261 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200262 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200263 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400264 struct hda_input_mux private_amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100265 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200266};
267
268static hda_nid_t stac9200_adc_nids[1] = {
269 0x03,
270};
271
272static hda_nid_t stac9200_mux_nids[1] = {
273 0x0c,
274};
275
276static hda_nid_t stac9200_dac_nids[1] = {
277 0x02,
278};
279
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100280static hda_nid_t stac92hd73xx_pwr_nids[8] = {
281 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
282 0x0f, 0x10, 0x11
283};
284
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400285static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
286 0x26, 0,
287};
288
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100289static hda_nid_t stac92hd73xx_adc_nids[2] = {
290 0x1a, 0x1b
291};
292
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400293#define DELL_M6_AMP 2
294static hda_nid_t stac92hd73xx_amp_nids[3] = {
295 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400296};
297
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100298#define STAC92HD73XX_NUM_DMICS 2
299static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
300 0x13, 0x14, 0
301};
302
303#define STAC92HD73_DAC_COUNT 5
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100304
305static hda_nid_t stac92hd73xx_mux_nids[4] = {
306 0x28, 0x29, 0x2a, 0x2b,
307};
308
309static hda_nid_t stac92hd73xx_dmux_nids[2] = {
310 0x20, 0x21,
311};
312
Matthew Ranostayd9737752008-09-07 12:03:41 +0200313static hda_nid_t stac92hd73xx_smux_nids[2] = {
314 0x22, 0x23,
315};
316
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200317#define STAC92HD83XXX_NUM_DMICS 2
318static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
319 0x11, 0x12, 0
320};
321
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200322#define STAC92HD83_DAC_COUNT 3
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200323
324static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
325 0x17, 0x18,
326};
327
328static hda_nid_t stac92hd83xxx_adc_nids[2] = {
329 0x15, 0x16,
330};
331
332static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
333 0xa, 0xb, 0xd, 0xe,
334};
335
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400336static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
337 0x1e, 0,
338};
339
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200340static unsigned int stac92hd83xxx_pwr_mapping[4] = {
Matthew Ranostay989738c2009-01-17 18:47:27 -0500341 0x03, 0x0c, 0x20, 0x80,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200342};
343
Takashi Iwai9248f262009-01-14 09:40:25 +0100344static hda_nid_t stac92hd83xxx_amp_nids[1] = {
Matthew Ranostayc15c5062009-01-13 13:30:07 -0500345 0xc,
346};
347
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100348static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
349 0x0a, 0x0d, 0x0f
350};
351
Matthew Ranostaye035b842007-11-06 11:53:55 +0100352static hda_nid_t stac92hd71bxx_adc_nids[2] = {
353 0x12, 0x13,
354};
355
356static hda_nid_t stac92hd71bxx_mux_nids[2] = {
357 0x1a, 0x1b
358};
359
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400360static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
361 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100362};
363
Matthew Ranostayd9737752008-09-07 12:03:41 +0200364static hda_nid_t stac92hd71bxx_smux_nids[2] = {
365 0x24, 0x25,
366};
367
Matthew Ranostaye035b842007-11-06 11:53:55 +0100368#define STAC92HD71BXX_NUM_DMICS 2
369static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
370 0x18, 0x19, 0
371};
372
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400373static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
374 0x22, 0
375};
376
Tobin Davis8e21c342007-01-08 11:04:17 +0100377static hda_nid_t stac925x_adc_nids[1] = {
378 0x03,
379};
380
381static hda_nid_t stac925x_mux_nids[1] = {
382 0x0f,
383};
384
385static hda_nid_t stac925x_dac_nids[1] = {
386 0x02,
387};
388
Takashi Iwaif6e98522007-10-16 14:27:04 +0200389#define STAC925X_NUM_DMICS 1
390static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
391 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200392};
393
Takashi Iwai1697055e2007-12-18 18:05:52 +0100394static hda_nid_t stac925x_dmux_nids[1] = {
395 0x14,
396};
397
Matt2f2f4252005-04-13 14:45:30 +0200398static hda_nid_t stac922x_adc_nids[2] = {
399 0x06, 0x07,
400};
401
402static hda_nid_t stac922x_mux_nids[2] = {
403 0x12, 0x13,
404};
405
Matt Porter3cc08dc2006-01-23 15:27:49 +0100406static hda_nid_t stac927x_adc_nids[3] = {
407 0x07, 0x08, 0x09
408};
409
410static hda_nid_t stac927x_mux_nids[3] = {
411 0x15, 0x16, 0x17
412};
413
Matthew Ranostayd9737752008-09-07 12:03:41 +0200414static hda_nid_t stac927x_smux_nids[1] = {
415 0x21,
416};
417
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100418static hda_nid_t stac927x_dac_nids[6] = {
419 0x02, 0x03, 0x04, 0x05, 0x06, 0
420};
421
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100422static hda_nid_t stac927x_dmux_nids[1] = {
423 0x1b,
424};
425
Matthew Ranostay7f168592007-10-18 17:38:17 +0200426#define STAC927X_NUM_DMICS 2
427static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
428 0x13, 0x14, 0
429};
430
Matthew Ranostay65973632008-09-16 10:39:37 -0400431static const char *stac927x_spdif_labels[5] = {
432 "Digital Playback", "ADAT", "Analog Mux 1",
433 "Analog Mux 2", "Analog Mux 3"
434};
435
Matt Porterf3302a52006-07-31 12:49:34 +0200436static hda_nid_t stac9205_adc_nids[2] = {
437 0x12, 0x13
438};
439
440static hda_nid_t stac9205_mux_nids[2] = {
441 0x19, 0x1a
442};
443
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100444static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100445 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100446};
447
Matthew Ranostayd9737752008-09-07 12:03:41 +0200448static hda_nid_t stac9205_smux_nids[1] = {
449 0x21,
450};
451
Takashi Iwaif6e98522007-10-16 14:27:04 +0200452#define STAC9205_NUM_DMICS 2
453static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
454 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200455};
456
Mattc7d4b2f2005-06-27 14:59:41 +0200457static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200458 0x08, 0x09, 0x0d, 0x0e,
459 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200460};
461
Tobin Davis8e21c342007-01-08 11:04:17 +0100462static hda_nid_t stac925x_pin_nids[8] = {
463 0x07, 0x08, 0x0a, 0x0b,
464 0x0c, 0x0d, 0x10, 0x11,
465};
466
Matt2f2f4252005-04-13 14:45:30 +0200467static hda_nid_t stac922x_pin_nids[10] = {
468 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
469 0x0f, 0x10, 0x11, 0x15, 0x1b,
470};
471
Matthew Ranostaya7662642008-02-21 07:51:14 +0100472static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100473 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
474 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200475 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100476};
477
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200478static hda_nid_t stac92hd83xxx_pin_nids[14] = {
479 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
480 0x0f, 0x10, 0x11, 0x12, 0x13,
481 0x1d, 0x1e, 0x1f, 0x20
482};
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400483static hda_nid_t stac92hd71bxx_pin_nids[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100484 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
485 0x0f, 0x14, 0x18, 0x19, 0x1e,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400486 0x1f,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100487};
488
Matt Porter3cc08dc2006-01-23 15:27:49 +0100489static hda_nid_t stac927x_pin_nids[14] = {
490 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
491 0x0f, 0x10, 0x11, 0x12, 0x13,
492 0x14, 0x21, 0x22, 0x23,
493};
494
Matt Porterf3302a52006-07-31 12:49:34 +0200495static hda_nid_t stac9205_pin_nids[12] = {
496 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
497 0x0f, 0x14, 0x16, 0x17, 0x18,
498 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200499};
500
Matthew Ranostay89385032008-09-11 09:49:39 -0400501#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
502
503static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
504 struct snd_ctl_elem_value *ucontrol)
505{
506 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
507 struct sigmatel_spec *spec = codec->spec;
508 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
509
510 kcontrol->private_value ^= get_amp_nid(kcontrol);
511 kcontrol->private_value |= nid;
512
513 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
514}
515
516static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
517 struct snd_ctl_elem_value *ucontrol)
518{
519 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
520 struct sigmatel_spec *spec = codec->spec;
521 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
522
523 kcontrol->private_value ^= get_amp_nid(kcontrol);
524 kcontrol->private_value |= nid;
525
526 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
527}
528
Matt Porter8b657272006-10-26 17:12:59 +0200529static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
530 struct snd_ctl_elem_info *uinfo)
531{
532 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
533 struct sigmatel_spec *spec = codec->spec;
534 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
535}
536
537static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
538 struct snd_ctl_elem_value *ucontrol)
539{
540 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
541 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100542 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200543
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100544 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200545 return 0;
546}
547
548static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
549 struct snd_ctl_elem_value *ucontrol)
550{
551 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
552 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100553 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200554
555 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100556 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200557}
558
Matthew Ranostayd9737752008-09-07 12:03:41 +0200559static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
560 struct snd_ctl_elem_info *uinfo)
561{
562 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
563 struct sigmatel_spec *spec = codec->spec;
564 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
565}
566
567static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
568 struct snd_ctl_elem_value *ucontrol)
569{
570 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
571 struct sigmatel_spec *spec = codec->spec;
572 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
573
574 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
575 return 0;
576}
577
578static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
579 struct snd_ctl_elem_value *ucontrol)
580{
581 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
582 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400583 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200584 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400585 int err, val;
586 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200587
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400588 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200589 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400590 if (err < 0)
591 return err;
592
593 if (spec->spdif_mute) {
594 if (smux_idx == 0)
595 nid = spec->multiout.dig_out_nid;
596 else
597 nid = codec->slave_dig_outs[smux_idx - 1];
598 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100599 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400600 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100601 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400602 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100603 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
604 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400605 }
606 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200607}
608
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100609static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200610{
611 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
612 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200613 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200614}
615
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100616static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200617{
618 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
619 struct sigmatel_spec *spec = codec->spec;
620 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
621
622 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
623 return 0;
624}
625
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100626static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200627{
628 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
629 struct sigmatel_spec *spec = codec->spec;
630 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
631
Mattc7d4b2f2005-06-27 14:59:41 +0200632 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200633 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
634}
635
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100636static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
637 struct snd_ctl_elem_info *uinfo)
638{
639 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
640 struct sigmatel_spec *spec = codec->spec;
641 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
642}
643
644static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
645 struct snd_ctl_elem_value *ucontrol)
646{
647 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
648 struct sigmatel_spec *spec = codec->spec;
649
650 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
651 return 0;
652}
653
654static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
655 struct snd_ctl_elem_value *ucontrol)
656{
657 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
658 struct sigmatel_spec *spec = codec->spec;
659
660 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
661 spec->mono_nid, &spec->cur_mmux);
662}
663
Matthew Ranostay89385032008-09-11 09:49:39 -0400664static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
665 struct snd_ctl_elem_info *uinfo)
666{
667 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
668 struct sigmatel_spec *spec = codec->spec;
669 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
670}
671
672static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
673 struct snd_ctl_elem_value *ucontrol)
674{
675 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
676 struct sigmatel_spec *spec = codec->spec;
677
678 ucontrol->value.enumerated.item[0] = spec->cur_amux;
679 return 0;
680}
681
682static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
683 struct snd_ctl_elem_value *ucontrol)
684{
685 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
686 struct sigmatel_spec *spec = codec->spec;
687 struct snd_kcontrol *ctl =
688 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
689 if (!ctl)
690 return -EINVAL;
691
692 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
693 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
694
695 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
696 0, &spec->cur_amux);
697}
698
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200699#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
700
701static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
702 struct snd_ctl_elem_value *ucontrol)
703{
704 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100705 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200706 struct sigmatel_spec *spec = codec->spec;
707
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100708 ucontrol->value.integer.value[0] = !!(spec->aloopback &
709 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200710 return 0;
711}
712
713static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
714 struct snd_ctl_elem_value *ucontrol)
715{
716 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
717 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100718 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200719 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100720 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200721
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100722 idx_val = spec->aloopback_mask << idx;
723 if (ucontrol->value.integer.value[0])
724 val = spec->aloopback | idx_val;
725 else
726 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100727 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200728 return 0;
729
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100730 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200731
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100732 /* Only return the bits defined by the shift value of the
733 * first two bytes of the mask
734 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200735 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100736 kcontrol->private_value & 0xFFFF, 0x0);
737 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200738
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100739 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200740 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100741 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200742 } else {
743 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100744 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200745 }
746
747 snd_hda_codec_write_cache(codec, codec->afg, 0,
748 kcontrol->private_value >> 16, dac_mode);
749
750 return 1;
751}
752
Mattc7d4b2f2005-06-27 14:59:41 +0200753static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200754 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200755 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200756 {}
757};
758
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200759static struct hda_verb stac9200_eapd_init[] = {
760 /* set dac0mux for dac converter */
761 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
762 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
763 {}
764};
765
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100766static struct hda_verb stac92hd73xx_6ch_core_init[] = {
767 /* set master volume and direct control */
768 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100769 /* setup adcs to point to mixer */
770 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
771 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100772 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
773 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
774 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
775 /* setup import muxs */
776 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
777 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
778 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
779 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
780 {}
781};
782
Matthew Ranostayd654a662008-03-14 08:46:51 +0100783static struct hda_verb dell_eq_core_init[] = {
784 /* set master volume to max value without distortion
785 * and direct control */
786 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100787 /* setup adcs to point to mixer */
788 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
789 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
790 /* setup import muxs */
791 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
792 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
793 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
794 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
795 {}
796};
797
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100798static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500799 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100800 /* setup adcs to point to mixer */
801 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
802 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
803 /* setup import muxs */
804 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
805 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
806 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
807 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
808 {}
809};
810
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100811static struct hda_verb stac92hd73xx_8ch_core_init[] = {
812 /* set master volume and direct control */
813 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100814 /* setup adcs to point to mixer */
815 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
816 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100817 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
818 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
819 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
820 /* setup import muxs */
821 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
822 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
823 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
824 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
825 {}
826};
827
828static struct hda_verb stac92hd73xx_10ch_core_init[] = {
829 /* set master volume and direct control */
830 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100831 /* dac3 is connected to import3 mux */
832 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100833 /* setup adcs to point to mixer */
834 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
835 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100836 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
837 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
838 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
839 /* setup import muxs */
840 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
841 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
842 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
843 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
844 {}
845};
846
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200847static struct hda_verb stac92hd83xxx_core_init[] = {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200848 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0},
849 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0},
850 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1},
851
852 /* power state controls amps */
853 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200854 {}
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200855};
856
Matthew Ranostaye035b842007-11-06 11:53:55 +0100857static struct hda_verb stac92hd71bxx_core_init[] = {
858 /* set master volume and direct control */
859 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100860 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
861 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
862 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
863 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -0200864 {}
Matthew Ranostay541eee82007-12-14 12:08:04 +0100865};
866
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400867#define HD_DISABLE_PORTF 2
Matthew Ranostay541eee82007-12-14 12:08:04 +0100868static struct hda_verb stac92hd71bxx_analog_core_init[] = {
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200869 /* start of config #1 */
870
871 /* connect port 0f to audio mixer */
872 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200873 /* unmute right and left channels for node 0x0f */
874 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
875 /* start of config #2 */
876
Matthew Ranostay541eee82007-12-14 12:08:04 +0100877 /* set master volume and direct control */
878 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200879 /* unmute right and left channels for nodes 0x0a, 0xd */
Matthew Ranostaye035b842007-11-06 11:53:55 +0100880 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
881 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100882 {}
883};
884
Tobin Davis8e21c342007-01-08 11:04:17 +0100885static struct hda_verb stac925x_core_init[] = {
886 /* set dac0mux for dac converter */
887 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
Takashi Iwaic9280d62009-01-15 17:31:00 +0100888 /* mute the master volume */
889 { 0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
Tobin Davis8e21c342007-01-08 11:04:17 +0100890 {}
891};
892
Mattc7d4b2f2005-06-27 14:59:41 +0200893static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200894 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200895 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200896 {}
897};
898
Tobin Davis93ed1502006-09-01 21:03:12 +0200899static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200900 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200901 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200902 /* unmute node 0x1b */
903 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
904 /* select node 0x03 as DAC */
905 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
906 {}
907};
908
Matt Porter3cc08dc2006-01-23 15:27:49 +0100909static struct hda_verb stac927x_core_init[] = {
910 /* set master volume and direct control */
911 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200912 /* enable analog pc beep path */
913 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100914 {}
915};
916
Matt Porterf3302a52006-07-31 12:49:34 +0200917static struct hda_verb stac9205_core_init[] = {
918 /* set master volume and direct control */
919 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200920 /* enable analog pc beep path */
921 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200922 {}
923};
924
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100925#define STAC_MONO_MUX \
926 { \
927 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
928 .name = "Mono Mux", \
929 .count = 1, \
930 .info = stac92xx_mono_mux_enum_info, \
931 .get = stac92xx_mono_mux_enum_get, \
932 .put = stac92xx_mono_mux_enum_put, \
933 }
934
Matthew Ranostay89385032008-09-11 09:49:39 -0400935#define STAC_AMP_MUX \
936 { \
937 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
938 .name = "Amp Selector Capture Switch", \
939 .count = 1, \
940 .info = stac92xx_amp_mux_enum_info, \
941 .get = stac92xx_amp_mux_enum_get, \
942 .put = stac92xx_amp_mux_enum_put, \
943 }
944
945#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
946 { \
947 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
948 .name = xname, \
949 .index = 0, \
950 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
951 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
952 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
953 .info = stac92xx_amp_volume_info, \
954 .get = stac92xx_amp_volume_get, \
955 .put = stac92xx_amp_volume_put, \
956 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
957 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
958 }
959
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200960#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200961 { \
962 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
963 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200964 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200965 .info = stac92xx_mux_enum_info, \
966 .get = stac92xx_mux_enum_get, \
967 .put = stac92xx_mux_enum_put, \
968 }
969
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100970#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200971 { \
972 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
973 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100974 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200975 .info = stac92xx_aloopback_info, \
976 .get = stac92xx_aloopback_get, \
977 .put = stac92xx_aloopback_put, \
978 .private_value = verb_read | (verb_write << 16), \
979 }
980
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100981static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200982 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
983 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200984 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200985 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
986 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200987 { } /* end */
988};
989
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400990#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100991static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400992 /* start of config #1 */
993 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
994 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
995
996 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
997 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
998
999 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1000 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1001
1002 /* start of config #2 */
1003 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1004 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1005
1006 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1007 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1008
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001009 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1010
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001011 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1012 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1013
1014 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1015 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1016
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001017 { } /* end */
1018};
1019
1020static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001021 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1022
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001023 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1024 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1025
1026 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1027 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1028
1029 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1030 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1031
1032 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1033 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1034
1035 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1036 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1037
1038 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1039 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1040
1041 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1042 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1043 { } /* end */
1044};
1045
1046static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001047 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1048
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001049 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1050 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1051
1052 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1053 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1054
1055 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1056 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1057
1058 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1059 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1060
1061 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1062 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1063
1064 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1065 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1066
1067 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1068 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1069 { } /* end */
1070};
1071
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001072
1073static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1074 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1075 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1076
1077 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1078 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1079
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001080 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0x3, HDA_INPUT),
1081 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0x3, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001082
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001083 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x4, HDA_INPUT),
1084 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x4, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001085
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001086 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x0, HDA_INPUT),
1087 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x0, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001088
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001089 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x2, HDA_INPUT),
1090 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x2, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001091
1092 /*
Matthew Ranostay74b7ff42008-12-20 17:47:24 -05001093 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x1, HDA_INPUT),
1094 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x1, HDA_INPUT),
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001095 */
1096 { } /* end */
1097};
1098
Matthew Ranostay541eee82007-12-14 12:08:04 +01001099static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001100 STAC_INPUT_SOURCE(2),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001101 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001102
Matthew Ranostay9b359472007-11-07 13:03:12 +01001103 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1104 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay9b359472007-11-07 13:03:12 +01001105
1106 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1107 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001108 /* analog pc-beep replaced with digital beep support */
1109 /*
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001110 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1111 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001112 */
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001113
Matthew Ranostay687cb982008-10-11 13:52:43 -04001114 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1115 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001116
Matthew Ranostay687cb982008-10-11 13:52:43 -04001117 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1118 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001119
1120 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1121 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1122
1123 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1124 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001125 { } /* end */
1126};
1127
Matthew Ranostay541eee82007-12-14 12:08:04 +01001128static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +01001129 STAC_INPUT_SOURCE(2),
1130 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1131
Matthew Ranostay541eee82007-12-14 12:08:04 +01001132 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1133 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001134
1135 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1136 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001137 { } /* end */
1138};
1139
Tobin Davis8e21c342007-01-08 11:04:17 +01001140static struct snd_kcontrol_new stac925x_mixer[] = {
Takashi Iwaic9280d62009-01-15 17:31:00 +01001141 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1142 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001143 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +01001144 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
Mauro Carvalho Chehab587755f2008-05-25 18:20:06 +02001145 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
Tobin Davis8e21c342007-01-08 11:04:17 +01001146 { } /* end */
1147};
1148
Takashi Iwaid1d985f2006-11-23 19:27:12 +01001149static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001150 STAC_INPUT_SOURCE(2),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001151 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001152
1153 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1154 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001155
1156 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1157 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001158 { } /* end */
1159};
1160
1161/* This needs to be generated dynamically based on sequence */
1162static struct snd_kcontrol_new stac922x_mixer[] = {
1163 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001164 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1165 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001166
1167 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1168 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001169 { } /* end */
1170};
1171
1172
1173static struct snd_kcontrol_new stac927x_mixer[] = {
1174 STAC_INPUT_SOURCE(3),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001175 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001176
1177 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1178 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001179
1180 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1181 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001182
1183 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1184 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +02001185 { } /* end */
1186};
1187
Takashi Iwai1697055e2007-12-18 18:05:52 +01001188static struct snd_kcontrol_new stac_dmux_mixer = {
1189 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1190 .name = "Digital Input Source",
1191 /* count set later */
1192 .info = stac92xx_dmux_enum_info,
1193 .get = stac92xx_dmux_enum_get,
1194 .put = stac92xx_dmux_enum_put,
1195};
1196
Matthew Ranostayd9737752008-09-07 12:03:41 +02001197static struct snd_kcontrol_new stac_smux_mixer = {
1198 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001199 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001200 /* count set later */
1201 .info = stac92xx_smux_enum_info,
1202 .get = stac92xx_smux_enum_get,
1203 .put = stac92xx_smux_enum_put,
1204};
1205
Takashi Iwai2134ea42008-01-10 16:53:55 +01001206static const char *slave_vols[] = {
1207 "Front Playback Volume",
1208 "Surround Playback Volume",
1209 "Center Playback Volume",
1210 "LFE Playback Volume",
1211 "Side Playback Volume",
1212 "Headphone Playback Volume",
1213 "Headphone Playback Volume",
1214 "Speaker Playback Volume",
1215 "External Speaker Playback Volume",
1216 "Speaker2 Playback Volume",
1217 NULL
1218};
1219
1220static const char *slave_sws[] = {
1221 "Front Playback Switch",
1222 "Surround Playback Switch",
1223 "Center Playback Switch",
1224 "LFE Playback Switch",
1225 "Side Playback Switch",
1226 "Headphone Playback Switch",
1227 "Headphone Playback Switch",
1228 "Speaker Playback Switch",
1229 "External Speaker Playback Switch",
1230 "Speaker2 Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001231 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001232 NULL
1233};
1234
Takashi Iwai603c4012008-07-30 15:01:44 +02001235static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001236static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001237
Matt2f2f4252005-04-13 14:45:30 +02001238static int stac92xx_build_controls(struct hda_codec *codec)
1239{
1240 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001241 struct auto_pin_cfg *cfg = &spec->autocfg;
1242 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001243 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001244 int i;
Matt2f2f4252005-04-13 14:45:30 +02001245
1246 err = snd_hda_add_new_ctls(codec, spec->mixer);
1247 if (err < 0)
1248 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001249
1250 for (i = 0; i < spec->num_mixers; i++) {
1251 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1252 if (err < 0)
1253 return err;
1254 }
Takashi Iwai1697055e2007-12-18 18:05:52 +01001255 if (spec->num_dmuxes > 0) {
1256 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001257 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001258 snd_ctl_new1(&stac_dmux_mixer, codec));
1259 if (err < 0)
1260 return err;
1261 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001262 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001263 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1264 struct hda_input_mux *smux = &spec->private_smux;
1265 /* check for mute support on SPDIF out */
1266 if (wcaps & AC_WCAP_OUT_AMP) {
1267 smux->items[smux->num_items].label = "Off";
1268 smux->items[smux->num_items].index = 0;
1269 smux->num_items++;
1270 spec->spdif_mute = 1;
1271 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001272 stac_smux_mixer.count = spec->num_smuxes;
Takashi Iwai4f2d23e2008-12-19 10:14:13 +01001273 err = snd_hda_ctl_add(codec,
Matthew Ranostayd9737752008-09-07 12:03:41 +02001274 snd_ctl_new1(&stac_smux_mixer, codec));
1275 if (err < 0)
1276 return err;
1277 }
Mattc7d4b2f2005-06-27 14:59:41 +02001278
Mattdabbed62005-06-14 10:19:34 +02001279 if (spec->multiout.dig_out_nid) {
1280 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1281 if (err < 0)
1282 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001283 err = snd_hda_create_spdif_share_sw(codec,
1284 &spec->multiout);
1285 if (err < 0)
1286 return err;
1287 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001288 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001289 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001290 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1291 if (err < 0)
1292 return err;
1293 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001294
1295 /* if we have no master control, let's create it */
1296 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001297 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001298 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001299 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai7c7767e2009-01-20 15:28:38 +01001300 /* correct volume offset */
1301 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
Takashi Iwai2134ea42008-01-10 16:53:55 +01001302 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001303 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001304 if (err < 0)
1305 return err;
1306 }
1307 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1308 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1309 NULL, slave_sws);
1310 if (err < 0)
1311 return err;
1312 }
1313
Takashi Iwai603c4012008-07-30 15:01:44 +02001314 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001315
1316 /* create jack input elements */
1317 if (spec->hp_detect) {
1318 for (i = 0; i < cfg->hp_outs; i++) {
1319 int type = SND_JACK_HEADPHONE;
1320 nid = cfg->hp_pins[i];
1321 /* jack detection */
1322 if (cfg->hp_outs == i)
1323 type |= SND_JACK_LINEOUT;
1324 err = stac92xx_add_jack(codec, nid, type);
1325 if (err < 0)
1326 return err;
1327 }
1328 }
1329 for (i = 0; i < cfg->line_outs; i++) {
1330 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1331 SND_JACK_LINEOUT);
1332 if (err < 0)
1333 return err;
1334 }
1335 for (i = 0; i < AUTO_PIN_LAST; i++) {
1336 nid = cfg->input_pins[i];
1337 if (nid) {
1338 err = stac92xx_add_jack(codec, nid,
1339 SND_JACK_MICROPHONE);
1340 if (err < 0)
1341 return err;
1342 }
1343 }
1344
Mattdabbed62005-06-14 10:19:34 +02001345 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001346}
1347
Matt Porter403d1942005-11-29 15:00:51 +01001348static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001349 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001350 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1351};
1352
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001353static unsigned int gateway9200_m4_pin_configs[8] = {
1354 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1355 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1356};
1357static unsigned int gateway9200_m4_2_pin_configs[8] = {
1358 0x400000fe, 0x404500f4, 0x400100f0, 0x90110010,
1359 0x400100f1, 0x02a1902e, 0x500000f2, 0x500000f3,
1360};
1361
1362/*
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001363 STAC 9200 pin configs for
1364 102801A8
1365 102801DE
1366 102801E8
1367*/
1368static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001369 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1370 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001371};
1372
1373/*
1374 STAC 9200 pin configs for
1375 102801C0
1376 102801C1
1377*/
1378static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001379 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1380 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001381};
1382
1383/*
1384 STAC 9200 pin configs for
1385 102801C4 (Dell Dimension E310)
1386 102801C5
1387 102801C7
1388 102801D9
1389 102801DA
1390 102801E3
1391*/
1392static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001393 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1394 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001395};
1396
1397
1398/*
1399 STAC 9200-32 pin configs for
1400 102801B5 (Dell Inspiron 630m)
1401 102801D8 (Dell Inspiron 640m)
1402*/
1403static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001404 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1405 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001406};
1407
1408/*
1409 STAC 9200-32 pin configs for
1410 102801C2 (Dell Latitude D620)
1411 102801C8
1412 102801CC (Dell Latitude D820)
1413 102801D4
1414 102801D6
1415*/
1416static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001417 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1418 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001419};
1420
1421/*
1422 STAC 9200-32 pin configs for
1423 102801CE (Dell XPS M1710)
1424 102801CF (Dell Precision M90)
1425*/
1426static unsigned int dell9200_m23_pin_configs[8] = {
1427 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1428 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1429};
1430
1431/*
1432 STAC 9200-32 pin configs for
1433 102801C9
1434 102801CA
1435 102801CB (Dell Latitude 120L)
1436 102801D3
1437*/
1438static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001439 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1440 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001441};
1442
1443/*
1444 STAC 9200-32 pin configs for
1445 102801BD (Dell Inspiron E1505n)
1446 102801EE
1447 102801EF
1448*/
1449static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001450 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1451 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001452};
1453
1454/*
1455 STAC 9200-32 pin configs for
1456 102801F5 (Dell Inspiron 1501)
1457 102801F6
1458*/
1459static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001460 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1461 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001462};
1463
1464/*
1465 STAC 9200-32
1466 102801CD (Dell Inspiron E1705/9400)
1467*/
1468static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001469 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1470 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001471};
1472
Tobin Davisbf277782008-02-03 20:31:47 +01001473static unsigned int oqo9200_pin_configs[8] = {
1474 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1475 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1476};
1477
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001478
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001479static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1480 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001481 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001482 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1483 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1484 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1485 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1486 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1487 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1488 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1489 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1490 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1491 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001492 [STAC_9200_M4] = gateway9200_m4_pin_configs,
1493 [STAC_9200_M4_2] = gateway9200_m4_2_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001494 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001495};
1496
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001497static const char *stac9200_models[STAC_9200_MODELS] = {
1498 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001499 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001500 [STAC_9200_DELL_D21] = "dell-d21",
1501 [STAC_9200_DELL_D22] = "dell-d22",
1502 [STAC_9200_DELL_D23] = "dell-d23",
1503 [STAC_9200_DELL_M21] = "dell-m21",
1504 [STAC_9200_DELL_M22] = "dell-m22",
1505 [STAC_9200_DELL_M23] = "dell-m23",
1506 [STAC_9200_DELL_M24] = "dell-m24",
1507 [STAC_9200_DELL_M25] = "dell-m25",
1508 [STAC_9200_DELL_M26] = "dell-m26",
1509 [STAC_9200_DELL_M27] = "dell-m27",
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001510 [STAC_9200_M4] = "gateway-m4",
1511 [STAC_9200_M4_2] = "gateway-m4-2",
Takashi Iwai117f2572008-03-18 09:53:23 +01001512 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001513};
1514
1515static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1516 /* SigmaTel reference board */
1517 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1518 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001519 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001520 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1521 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001522 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001523 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1524 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1525 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1526 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1527 "unknown Dell", STAC_9200_DELL_D22),
1528 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1529 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001530 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001531 "Dell Latitude D620", STAC_9200_DELL_M22),
1532 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1533 "unknown Dell", STAC_9200_DELL_D23),
1534 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1535 "unknown Dell", STAC_9200_DELL_D23),
1536 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1537 "unknown Dell", STAC_9200_DELL_M22),
1538 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1539 "unknown Dell", STAC_9200_DELL_M24),
1540 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1541 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001542 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001543 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001544 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001545 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001546 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001547 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001548 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001549 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001550 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001551 "Dell Precision M90", STAC_9200_DELL_M23),
1552 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1553 "unknown Dell", STAC_9200_DELL_M22),
1554 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1555 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001556 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001557 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001558 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001559 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1560 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1561 "unknown Dell", STAC_9200_DELL_D23),
1562 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1563 "unknown Dell", STAC_9200_DELL_D23),
1564 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1565 "unknown Dell", STAC_9200_DELL_D21),
1566 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1567 "unknown Dell", STAC_9200_DELL_D23),
1568 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1569 "unknown Dell", STAC_9200_DELL_D21),
1570 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1571 "unknown Dell", STAC_9200_DELL_M25),
1572 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1573 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001574 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001575 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1576 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1577 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001578 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001579 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001580 /* Gateway machines needs EAPD to be set on resume */
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001581 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_M4),
1582 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", STAC_9200_M4_2),
1583 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", STAC_9200_M4_2),
Tobin Davisbf277782008-02-03 20:31:47 +01001584 /* OQO Mobile */
1585 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001586 {} /* terminator */
1587};
1588
Tobin Davis8e21c342007-01-08 11:04:17 +01001589static unsigned int ref925x_pin_configs[8] = {
1590 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001591 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001592};
1593
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001594static unsigned int stac925xM1_pin_configs[8] = {
1595 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1596 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001597};
1598
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001599static unsigned int stac925xM1_2_pin_configs[8] = {
1600 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1601 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1602};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001603
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001604static unsigned int stac925xM2_pin_configs[8] = {
1605 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1606 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
Tobin Davis2c11f952007-05-17 09:36:34 +02001607};
1608
Tobin Davis8e21c342007-01-08 11:04:17 +01001609static unsigned int stac925xM2_2_pin_configs[8] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001610 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1611 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1612};
1613
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001614static unsigned int stac925xM3_pin_configs[8] = {
1615 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1616 0x40a000f0, 0x90100210, 0x400003f1, 0x503303f3,
1617};
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001618
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001619static unsigned int stac925xM5_pin_configs[8] = {
1620 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1621 0x40a000f0, 0x90100210, 0x400003f1, 0x9033032e,
1622};
1623
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001624static unsigned int stac925xM6_pin_configs[8] = {
1625 0x40c003f4, 0x424503f2, 0x400000f3, 0x02a19020,
1626 0x40a000f0, 0x90100210, 0x400003f1, 0x90330320,
Tobin Davis8e21c342007-01-08 11:04:17 +01001627};
1628
1629static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1630 [STAC_REF] = ref925x_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001631 [STAC_M1] = stac925xM1_pin_configs,
1632 [STAC_M1_2] = stac925xM1_2_pin_configs,
1633 [STAC_M2] = stac925xM2_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001634 [STAC_M2_2] = stac925xM2_2_pin_configs,
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001635 [STAC_M3] = stac925xM3_pin_configs,
1636 [STAC_M5] = stac925xM5_pin_configs,
1637 [STAC_M6] = stac925xM6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001638};
1639
1640static const char *stac925x_models[STAC_925x_MODELS] = {
1641 [STAC_REF] = "ref",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001642 [STAC_M1] = "m1",
1643 [STAC_M1_2] = "m1-2",
1644 [STAC_M2] = "m2",
Tobin Davis8e21c342007-01-08 11:04:17 +01001645 [STAC_M2_2] = "m2-2",
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001646 [STAC_M3] = "m3",
1647 [STAC_M5] = "m5",
1648 [STAC_M6] = "m6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001649};
1650
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001651static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02001652 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_M2),
1653 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_M5),
1654 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_M1),
1655 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_M2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001656 SND_PCI_QUIRK(0x107b, 0x0367, "Gateway MX6453", STAC_M1_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001657 /* Not sure about the brand name for those */
1658 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M1),
1659 SND_PCI_QUIRK(0x107b, 0x0507, "Gateway mobile", STAC_M3),
1660 SND_PCI_QUIRK(0x107b, 0x0281, "Gateway mobile", STAC_M6),
1661 SND_PCI_QUIRK(0x107b, 0x0685, "Gateway mobile", STAC_M2_2),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001662 {} /* terminator */
Tobin Davis8e21c342007-01-08 11:04:17 +01001663};
1664
1665static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1666 /* SigmaTel reference board */
1667 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001668 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02001669
1670 /* Default table for unknown ID */
1671 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway mobile", STAC_M2_2),
1672
Tobin Davis8e21c342007-01-08 11:04:17 +01001673 {} /* terminator */
1674};
1675
Matthew Ranostaya7662642008-02-21 07:51:14 +01001676static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001677 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1678 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1679 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001680 0x01452050,
1681};
1682
1683static unsigned int dell_m6_pin_configs[13] = {
1684 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001685 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001686 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1687 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001688};
1689
1690static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001691 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001692 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1693 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1694 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001695 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001696};
1697
1698static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01001699 [STAC_92HD73XX_NO_JD] = "no-jd",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001700 [STAC_92HD73XX_REF] = "ref",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001701 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1702 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1703 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001704 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001705};
1706
1707static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1708 /* SigmaTel reference board */
1709 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001710 "DFI LanParty", STAC_92HD73XX_REF),
1711 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001712 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001713 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001714 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001715 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001716 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001717 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001718 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001719 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001720 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001721 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001722 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001723 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001724 "unknown Dell", STAC_DELL_M6_DMIC),
1725 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1726 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001727 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001728 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Joerg Schirottkefa620e92008-12-19 08:13:49 +01001729 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02a0,
1730 "Dell Studio 17", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001731 {} /* terminator */
1732};
1733
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001734static unsigned int ref92hd83xxx_pin_configs[14] = {
1735 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1736 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1737 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1738 0x01451160, 0x98560170,
1739};
1740
1741static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1742 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1743};
1744
1745static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1746 [STAC_92HD83XXX_REF] = "ref",
1747};
1748
1749static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1750 /* SigmaTel reference board */
1751 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Takashi Iwaif9d088b2009-01-13 11:54:49 +01001752 "DFI LanParty", STAC_92HD83XXX_REF),
Herton Ronaldo Krzesinski574f3c42008-12-23 16:53:00 -02001753 {} /* terminator */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001754};
1755
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001756static unsigned int ref92hd71bxx_pin_configs[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001757 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001758 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001759 0x90a000f0, 0x01452050, 0x01452050,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001760};
1761
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001762static unsigned int dell_m4_1_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001763 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001764 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001765 0x40f000f0, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001766};
1767
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001768static unsigned int dell_m4_2_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001769 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1770 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001771 0x40f000f0, 0x044413b0, 0x044413b0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001772};
1773
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001774static unsigned int dell_m4_3_pin_configs[11] = {
1775 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1776 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1777 0x40f000f0, 0x044413b0, 0x044413b0,
1778};
1779
Matthew Ranostaye035b842007-11-06 11:53:55 +01001780static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1781 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001782 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1783 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001784 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001785 [STAC_HP_M4] = NULL,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001786 [STAC_HP_DV5] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001787};
1788
1789static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1790 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001791 [STAC_DELL_M4_1] = "dell-m4-1",
1792 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001793 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001794 [STAC_HP_M4] = "hp-m4",
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001795 [STAC_HP_DV5] = "hp-dv5",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001796};
1797
1798static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1799 /* SigmaTel reference board */
1800 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1801 "DFI LanParty", STAC_92HD71BXX_REF),
Takashi Iwai80bf2722008-11-18 10:48:41 +01001802 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f2,
1803 "HP dv5", STAC_HP_M4),
1804 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4,
1805 "HP dv7", STAC_HP_M4),
Takashi Iwaie0c0e942009-01-22 12:58:11 +01001806 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f7,
1807 "HP dv4", STAC_HP_DV5),
Takashi Iwai69dfaef2008-12-20 16:57:50 +01001808 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fc,
1809 "HP dv7", STAC_HP_M4),
Giuseppe Bilottadafb70c2009-01-13 08:58:49 -05001810 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3603,
Takashi Iwai1b0652e2009-01-14 08:27:35 +01001811 "HP dv5", STAC_HP_DV5),
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001812 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1813 "unknown HP", STAC_HP_M4),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001814 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1815 "unknown Dell", STAC_DELL_M4_1),
1816 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1817 "unknown Dell", STAC_DELL_M4_1),
1818 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1819 "unknown Dell", STAC_DELL_M4_1),
1820 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1821 "unknown Dell", STAC_DELL_M4_1),
1822 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1823 "unknown Dell", STAC_DELL_M4_1),
1824 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1825 "unknown Dell", STAC_DELL_M4_1),
1826 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1827 "unknown Dell", STAC_DELL_M4_1),
1828 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1829 "unknown Dell", STAC_DELL_M4_2),
1830 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1831 "unknown Dell", STAC_DELL_M4_2),
1832 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1833 "unknown Dell", STAC_DELL_M4_2),
1834 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1835 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001836 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1837 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001838 {} /* terminator */
1839};
1840
Matt Porter403d1942005-11-29 15:00:51 +01001841static unsigned int ref922x_pin_configs[10] = {
1842 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1843 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001844 0x40000100, 0x40000100,
1845};
1846
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001847/*
1848 STAC 922X pin configs for
1849 102801A7
1850 102801AB
1851 102801A9
1852 102801D1
1853 102801D2
1854*/
1855static unsigned int dell_922x_d81_pin_configs[10] = {
1856 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1857 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1858 0x01813122, 0x400001f2,
1859};
1860
1861/*
1862 STAC 922X pin configs for
1863 102801AC
1864 102801D0
1865*/
1866static unsigned int dell_922x_d82_pin_configs[10] = {
1867 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1868 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1869 0x01813122, 0x400001f1,
1870};
1871
1872/*
1873 STAC 922X pin configs for
1874 102801BF
1875*/
1876static unsigned int dell_922x_m81_pin_configs[10] = {
1877 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1878 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1879 0x40C003f1, 0x405003f0,
1880};
1881
1882/*
1883 STAC 9221 A1 pin configs for
1884 102801D7 (Dell XPS M1210)
1885*/
1886static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001887 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1888 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001889 0x508003f3, 0x405003f4,
1890};
1891
Matt Porter403d1942005-11-29 15:00:51 +01001892static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001893 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001894 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1895 0x02a19120, 0x40000100,
1896};
1897
1898static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001899 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1900 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001901 0x02a19320, 0x40000100,
1902};
1903
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001904static unsigned int intel_mac_v1_pin_configs[10] = {
1905 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1906 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001907 0x400000fc, 0x400000fb,
1908};
1909
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001910static unsigned int intel_mac_v2_pin_configs[10] = {
1911 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1912 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001913 0x400000fc, 0x400000fb,
1914};
1915
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001916static unsigned int intel_mac_v3_pin_configs[10] = {
1917 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1918 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1919 0x400000fc, 0x400000fb,
1920};
1921
1922static unsigned int intel_mac_v4_pin_configs[10] = {
1923 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1924 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1925 0x400000fc, 0x400000fb,
1926};
1927
1928static unsigned int intel_mac_v5_pin_configs[10] = {
1929 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1930 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1931 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001932};
1933
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001934static unsigned int ecs202_pin_configs[10] = {
1935 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1936 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1937 0x9037012e, 0x40e000f2,
1938};
Takashi Iwai76c08822007-06-19 12:17:42 +02001939
Takashi Iwai19039bd2006-06-28 15:52:16 +02001940static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001941 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001942 [STAC_D945GTP3] = d945gtp3_pin_configs,
1943 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001944 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1945 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1946 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1947 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1948 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001949 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001950 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001951 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1952 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1953 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1954 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1955 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1956 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001957 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001958 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1959 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1960 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1961 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001962};
1963
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001964static const char *stac922x_models[STAC_922X_MODELS] = {
1965 [STAC_D945_REF] = "ref",
1966 [STAC_D945GTP5] = "5stack",
1967 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001968 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1969 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1970 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1971 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1972 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001973 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001974 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001975 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001976 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001977 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1978 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001979 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001980 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001981 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001982 [STAC_922X_DELL_D81] = "dell-d81",
1983 [STAC_922X_DELL_D82] = "dell-d82",
1984 [STAC_922X_DELL_M81] = "dell-m81",
1985 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001986};
1987
1988static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1989 /* SigmaTel reference board */
1990 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1991 "DFI LanParty", STAC_D945_REF),
1992 /* Intel 945G based systems */
1993 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1994 "Intel D945G", STAC_D945GTP3),
1995 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1996 "Intel D945G", STAC_D945GTP3),
1997 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1998 "Intel D945G", STAC_D945GTP3),
1999 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
2000 "Intel D945G", STAC_D945GTP3),
2001 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
2002 "Intel D945G", STAC_D945GTP3),
2003 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
2004 "Intel D945G", STAC_D945GTP3),
2005 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
2006 "Intel D945G", STAC_D945GTP3),
2007 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
2008 "Intel D945G", STAC_D945GTP3),
2009 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
2010 "Intel D945G", STAC_D945GTP3),
2011 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
2012 "Intel D945G", STAC_D945GTP3),
2013 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
2014 "Intel D945G", STAC_D945GTP3),
2015 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
2016 "Intel D945G", STAC_D945GTP3),
2017 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
2018 "Intel D945G", STAC_D945GTP3),
2019 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
2020 "Intel D945G", STAC_D945GTP3),
2021 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
2022 "Intel D945G", STAC_D945GTP3),
2023 /* Intel D945G 5-stack systems */
2024 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
2025 "Intel D945G", STAC_D945GTP5),
2026 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
2027 "Intel D945G", STAC_D945GTP5),
2028 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
2029 "Intel D945G", STAC_D945GTP5),
2030 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
2031 "Intel D945G", STAC_D945GTP5),
2032 /* Intel 945P based systems */
2033 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
2034 "Intel D945P", STAC_D945GTP3),
2035 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
2036 "Intel D945P", STAC_D945GTP3),
2037 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
2038 "Intel D945P", STAC_D945GTP3),
2039 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
2040 "Intel D945P", STAC_D945GTP3),
2041 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
2042 "Intel D945P", STAC_D945GTP3),
2043 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2044 "Intel D945P", STAC_D945GTP5),
2045 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002046 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002047 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002048 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002049 /* Dell systems */
2050 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2051 "unknown Dell", STAC_922X_DELL_D81),
2052 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2053 "unknown Dell", STAC_922X_DELL_D81),
2054 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2055 "unknown Dell", STAC_922X_DELL_D81),
2056 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2057 "unknown Dell", STAC_922X_DELL_D82),
2058 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2059 "unknown Dell", STAC_922X_DELL_M81),
2060 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2061 "unknown Dell", STAC_922X_DELL_D82),
2062 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2063 "unknown Dell", STAC_922X_DELL_D81),
2064 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2065 "unknown Dell", STAC_922X_DELL_D81),
2066 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2067 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002068 /* ECS/PC Chips boards */
2069 SND_PCI_QUIRK(0x1019, 0x2144,
2070 "ECS/PC chips", STAC_ECS_202),
2071 SND_PCI_QUIRK(0x1019, 0x2608,
2072 "ECS/PC chips", STAC_ECS_202),
2073 SND_PCI_QUIRK(0x1019, 0x2633,
2074 "ECS/PC chips P17G/1333", STAC_ECS_202),
2075 SND_PCI_QUIRK(0x1019, 0x2811,
2076 "ECS/PC chips", STAC_ECS_202),
2077 SND_PCI_QUIRK(0x1019, 0x2812,
2078 "ECS/PC chips", STAC_ECS_202),
2079 SND_PCI_QUIRK(0x1019, 0x2813,
2080 "ECS/PC chips", STAC_ECS_202),
2081 SND_PCI_QUIRK(0x1019, 0x2814,
2082 "ECS/PC chips", STAC_ECS_202),
2083 SND_PCI_QUIRK(0x1019, 0x2815,
2084 "ECS/PC chips", STAC_ECS_202),
2085 SND_PCI_QUIRK(0x1019, 0x2816,
2086 "ECS/PC chips", STAC_ECS_202),
2087 SND_PCI_QUIRK(0x1019, 0x2817,
2088 "ECS/PC chips", STAC_ECS_202),
2089 SND_PCI_QUIRK(0x1019, 0x2818,
2090 "ECS/PC chips", STAC_ECS_202),
2091 SND_PCI_QUIRK(0x1019, 0x2819,
2092 "ECS/PC chips", STAC_ECS_202),
2093 SND_PCI_QUIRK(0x1019, 0x2820,
2094 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002095 {} /* terminator */
2096};
2097
Matt Porter3cc08dc2006-01-23 15:27:49 +01002098static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002099 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2100 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2101 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2102 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002103};
2104
Tobin Davis93ed1502006-09-01 21:03:12 +02002105static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002106 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2107 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2108 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2109 0x40000100, 0x40000100
2110};
2111
Tobin Davis93ed1502006-09-01 21:03:12 +02002112static unsigned int d965_5st_pin_configs[14] = {
2113 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2114 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2115 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2116 0x40000100, 0x40000100
2117};
2118
Tobin Davis4ff076e2007-08-07 11:48:12 +02002119static unsigned int dell_3st_pin_configs[14] = {
2120 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2121 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002122 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002123 0x40c003fc, 0x40000100
2124};
2125
Tobin Davis93ed1502006-09-01 21:03:12 +02002126static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002127 [STAC_D965_REF_NO_JD] = ref927x_pin_configs,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002128 [STAC_D965_REF] = ref927x_pin_configs,
2129 [STAC_D965_3ST] = d965_3st_pin_configs,
2130 [STAC_D965_5ST] = d965_5st_pin_configs,
2131 [STAC_DELL_3ST] = dell_3st_pin_configs,
2132 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002133};
2134
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002135static const char *stac927x_models[STAC_927X_MODELS] = {
Takashi Iwaie28d8322008-12-17 13:48:29 +01002136 [STAC_D965_REF_NO_JD] = "ref-no-jd",
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002137 [STAC_D965_REF] = "ref",
2138 [STAC_D965_3ST] = "3stack",
2139 [STAC_D965_5ST] = "5stack",
2140 [STAC_DELL_3ST] = "dell-3stack",
2141 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002142};
2143
2144static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2145 /* SigmaTel reference board */
2146 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2147 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002148 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002149 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2150 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002151 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002152 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
2153 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
2154 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
2155 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
2156 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
2157 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
2158 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
2159 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
2160 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
2161 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
2162 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
2163 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
2164 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
2165 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
2166 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
2167 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002168 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002169 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002170 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002171 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2172 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002173 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002174 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2175 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002176 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Takashi Iwai24918b62008-09-30 12:58:54 +02002177 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002178 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2179 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2180 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2181 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002182 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002183 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
2184 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
2185 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
2186 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
2187 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
2188 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
2189 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
2190 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
2191 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002192 {} /* terminator */
2193};
2194
Matt Porterf3302a52006-07-31 12:49:34 +02002195static unsigned int ref9205_pin_configs[12] = {
2196 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002197 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002198 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002199};
2200
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002201/*
2202 STAC 9205 pin configs for
2203 102801F1
2204 102801F2
2205 102801FC
2206 102801FD
2207 10280204
2208 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002209 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002210*/
2211static unsigned int dell_9205_m42_pin_configs[12] = {
2212 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2213 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2214 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2215};
2216
2217/*
2218 STAC 9205 pin configs for
2219 102801F9
2220 102801FA
2221 102801FE
2222 102801FF (Dell Precision M4300)
2223 10280206
2224 10280200
2225 10280201
2226*/
2227static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002228 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2229 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2230 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2231};
2232
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002233static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002234 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2235 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2236 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2237};
2238
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002239static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002240 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002241 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2242 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2243 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Takashi Iwaid9a42682009-01-22 17:40:18 +01002244 [STAC_9205_EAPD] = NULL,
Matt Porterf3302a52006-07-31 12:49:34 +02002245};
2246
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002247static const char *stac9205_models[STAC_9205_MODELS] = {
2248 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002249 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002250 [STAC_9205_DELL_M43] = "dell-m43",
2251 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaid9a42682009-01-22 17:40:18 +01002252 [STAC_9205_EAPD] = "eapd",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002253};
2254
2255static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2256 /* SigmaTel reference board */
2257 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2258 "DFI LanParty", STAC_9205_REF),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002259 /* Dell */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002260 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2261 "unknown Dell", STAC_9205_DELL_M42),
2262 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2263 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002264 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002265 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002266 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2267 "Dell Precision", STAC_9205_DELL_M43),
2268 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2269 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002270 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2271 "unknown Dell", STAC_9205_DELL_M42),
2272 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2273 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002274 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2275 "Dell Precision", STAC_9205_DELL_M43),
2276 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002277 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002278 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2279 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002280 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2281 "Dell Precision", STAC_9205_DELL_M43),
2282 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2283 "Dell Precision", STAC_9205_DELL_M43),
2284 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2285 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002286 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2287 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002288 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2289 "Dell Vostro 1500", STAC_9205_DELL_M42),
Takashi Iwaid9a42682009-01-22 17:40:18 +01002290 /* Gateway */
2291 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
Matt Porterf3302a52006-07-31 12:49:34 +02002292 {} /* terminator */
2293};
2294
Richard Fish11b44bb2006-08-23 18:31:34 +02002295static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2296{
2297 int i;
2298 struct sigmatel_spec *spec = codec->spec;
2299
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002300 kfree(spec->pin_configs);
2301 spec->pin_configs = kcalloc(spec->num_pins, sizeof(*spec->pin_configs),
2302 GFP_KERNEL);
2303 if (!spec->pin_configs)
2304 return -ENOMEM;
Richard Fish11b44bb2006-08-23 18:31:34 +02002305
2306 for (i = 0; i < spec->num_pins; i++) {
2307 hda_nid_t nid = spec->pin_nids[i];
2308 unsigned int pin_cfg;
2309
2310 pin_cfg = snd_hda_codec_read(codec, nid, 0,
2311 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2312 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2313 nid, pin_cfg);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002314 spec->pin_configs[i] = pin_cfg;
Richard Fish11b44bb2006-08-23 18:31:34 +02002315 }
2316
2317 return 0;
2318}
2319
Matthew Ranostay87d48362007-07-17 11:52:24 +02002320static void stac92xx_set_config_reg(struct hda_codec *codec,
2321 hda_nid_t pin_nid, unsigned int pin_config)
2322{
2323 int i;
2324 snd_hda_codec_write(codec, pin_nid, 0,
2325 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2326 pin_config & 0x000000ff);
2327 snd_hda_codec_write(codec, pin_nid, 0,
2328 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2329 (pin_config & 0x0000ff00) >> 8);
2330 snd_hda_codec_write(codec, pin_nid, 0,
2331 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2332 (pin_config & 0x00ff0000) >> 16);
2333 snd_hda_codec_write(codec, pin_nid, 0,
2334 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2335 pin_config >> 24);
2336 i = snd_hda_codec_read(codec, pin_nid, 0,
2337 AC_VERB_GET_CONFIG_DEFAULT,
2338 0x00);
2339 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
2340 pin_nid, i);
2341}
2342
Matt2f2f4252005-04-13 14:45:30 +02002343static void stac92xx_set_config_regs(struct hda_codec *codec)
2344{
2345 int i;
2346 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002347
Matthew Ranostay87d48362007-07-17 11:52:24 +02002348 if (!spec->pin_configs)
2349 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002350
Matthew Ranostay87d48362007-07-17 11:52:24 +02002351 for (i = 0; i < spec->num_pins; i++)
2352 stac92xx_set_config_reg(codec, spec->pin_nids[i],
2353 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02002354}
Matt2f2f4252005-04-13 14:45:30 +02002355
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01002356static int stac_save_pin_cfgs(struct hda_codec *codec, unsigned int *pins)
2357{
2358 struct sigmatel_spec *spec = codec->spec;
2359
2360 if (!pins)
2361 return stac92xx_save_bios_config_regs(codec);
2362
2363 kfree(spec->pin_configs);
2364 spec->pin_configs = kmemdup(pins,
2365 spec->num_pins * sizeof(*pins),
2366 GFP_KERNEL);
2367 if (!spec->pin_configs)
2368 return -ENOMEM;
2369
2370 stac92xx_set_config_regs(codec);
2371 return 0;
2372}
2373
2374static void stac_change_pin_config(struct hda_codec *codec, hda_nid_t nid,
2375 unsigned int cfg)
2376{
2377 struct sigmatel_spec *spec = codec->spec;
2378 int i;
2379
2380 for (i = 0; i < spec->num_pins; i++) {
2381 if (spec->pin_nids[i] == nid) {
2382 spec->pin_configs[i] = cfg;
2383 stac92xx_set_config_reg(codec, nid, cfg);
2384 break;
2385 }
2386 }
2387}
2388
Matt2f2f4252005-04-13 14:45:30 +02002389/*
2390 * Analog playback callbacks
2391 */
2392static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2393 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002394 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002395{
2396 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002397 if (spec->stream_delay)
2398 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002399 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2400 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002401}
2402
2403static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2404 struct hda_codec *codec,
2405 unsigned int stream_tag,
2406 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002407 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002408{
2409 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002410 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002411}
2412
2413static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2414 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002415 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002416{
2417 struct sigmatel_spec *spec = codec->spec;
2418 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2419}
2420
2421/*
Mattdabbed62005-06-14 10:19:34 +02002422 * Digital playback callbacks
2423 */
2424static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2425 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002426 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002427{
2428 struct sigmatel_spec *spec = codec->spec;
2429 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2430}
2431
2432static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2433 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002434 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002435{
2436 struct sigmatel_spec *spec = codec->spec;
2437 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2438}
2439
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002440static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2441 struct hda_codec *codec,
2442 unsigned int stream_tag,
2443 unsigned int format,
2444 struct snd_pcm_substream *substream)
2445{
2446 struct sigmatel_spec *spec = codec->spec;
2447 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2448 stream_tag, format, substream);
2449}
2450
Mattdabbed62005-06-14 10:19:34 +02002451
2452/*
Matt2f2f4252005-04-13 14:45:30 +02002453 * Analog capture callbacks
2454 */
2455static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2456 struct hda_codec *codec,
2457 unsigned int stream_tag,
2458 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002459 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002460{
2461 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002462 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002463
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002464 if (spec->powerdown_adcs) {
2465 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002466 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002467 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2468 }
2469 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002470 return 0;
2471}
2472
2473static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2474 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002475 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002476{
2477 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002478 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002479
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002480 snd_hda_codec_cleanup_stream(codec, nid);
2481 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002482 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002483 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002484 return 0;
2485}
2486
Mattdabbed62005-06-14 10:19:34 +02002487static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2488 .substreams = 1,
2489 .channels_min = 2,
2490 .channels_max = 2,
2491 /* NID is set in stac92xx_build_pcms */
2492 .ops = {
2493 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002494 .close = stac92xx_dig_playback_pcm_close,
2495 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02002496 },
2497};
2498
2499static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2500 .substreams = 1,
2501 .channels_min = 2,
2502 .channels_max = 2,
2503 /* NID is set in stac92xx_build_pcms */
2504};
2505
Matt2f2f4252005-04-13 14:45:30 +02002506static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2507 .substreams = 1,
2508 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002509 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002510 .nid = 0x02, /* NID to query formats and rates */
2511 .ops = {
2512 .open = stac92xx_playback_pcm_open,
2513 .prepare = stac92xx_playback_pcm_prepare,
2514 .cleanup = stac92xx_playback_pcm_cleanup
2515 },
2516};
2517
Matt Porter3cc08dc2006-01-23 15:27:49 +01002518static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2519 .substreams = 1,
2520 .channels_min = 2,
2521 .channels_max = 2,
2522 .nid = 0x06, /* NID to query formats and rates */
2523 .ops = {
2524 .open = stac92xx_playback_pcm_open,
2525 .prepare = stac92xx_playback_pcm_prepare,
2526 .cleanup = stac92xx_playback_pcm_cleanup
2527 },
2528};
2529
Matt2f2f4252005-04-13 14:45:30 +02002530static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002531 .channels_min = 2,
2532 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002533 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002534 .ops = {
2535 .prepare = stac92xx_capture_pcm_prepare,
2536 .cleanup = stac92xx_capture_pcm_cleanup
2537 },
2538};
2539
2540static int stac92xx_build_pcms(struct hda_codec *codec)
2541{
2542 struct sigmatel_spec *spec = codec->spec;
2543 struct hda_pcm *info = spec->pcm_rec;
2544
2545 codec->num_pcms = 1;
2546 codec->pcm_info = info;
2547
Mattc7d4b2f2005-06-27 14:59:41 +02002548 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002549 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02002550 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002551 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002552 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002553
2554 if (spec->alt_switch) {
2555 codec->num_pcms++;
2556 info++;
2557 info->name = "STAC92xx Analog Alt";
2558 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2559 }
Matt2f2f4252005-04-13 14:45:30 +02002560
Mattdabbed62005-06-14 10:19:34 +02002561 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2562 codec->num_pcms++;
2563 info++;
2564 info->name = "STAC92xx Digital";
Takashi Iwai8c441982009-01-20 18:30:20 +01002565 info->pcm_type = spec->autocfg.dig_out_type;
Mattdabbed62005-06-14 10:19:34 +02002566 if (spec->multiout.dig_out_nid) {
2567 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2568 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2569 }
2570 if (spec->dig_in_nid) {
2571 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2572 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2573 }
2574 }
2575
Matt2f2f4252005-04-13 14:45:30 +02002576 return 0;
2577}
2578
Takashi Iwaic960a032006-03-23 17:06:28 +01002579static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2580{
2581 unsigned int pincap = snd_hda_param_read(codec, nid,
2582 AC_PAR_PIN_CAP);
2583 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2584 if (pincap & AC_PINCAP_VREF_100)
2585 return AC_PINCTL_VREF_100;
2586 if (pincap & AC_PINCAP_VREF_80)
2587 return AC_PINCTL_VREF_80;
2588 if (pincap & AC_PINCAP_VREF_50)
2589 return AC_PINCTL_VREF_50;
2590 if (pincap & AC_PINCAP_VREF_GRD)
2591 return AC_PINCTL_VREF_GRD;
2592 return 0;
2593}
2594
Matt Porter403d1942005-11-29 15:00:51 +01002595static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2596
2597{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002598 snd_hda_codec_write_cache(codec, nid, 0,
2599 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002600}
2601
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002602#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2603
2604static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2605 struct snd_ctl_elem_value *ucontrol)
2606{
2607 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2608 struct sigmatel_spec *spec = codec->spec;
2609
Takashi Iwaid7a89432008-11-12 09:48:04 +01002610 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002611 return 0;
2612}
2613
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002614static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2615 unsigned char type);
2616
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002617static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2618 struct snd_ctl_elem_value *ucontrol)
2619{
2620 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2621 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002622 int nid = kcontrol->private_value;
2623
2624 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002625
2626 /* check to be sure that the ports are upto date with
2627 * switch changes
2628 */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002629 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002630
2631 return 1;
2632}
2633
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002634#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01002635
2636static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2637{
2638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2639 struct sigmatel_spec *spec = codec->spec;
2640 int io_idx = kcontrol-> private_value & 0xff;
2641
2642 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2643 return 0;
2644}
2645
2646static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2647{
2648 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2649 struct sigmatel_spec *spec = codec->spec;
2650 hda_nid_t nid = kcontrol->private_value >> 8;
2651 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002652 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01002653
2654 spec->io_switch[io_idx] = val;
2655
2656 if (val)
2657 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002658 else {
2659 unsigned int pinctl = AC_PINCTL_IN_EN;
2660 if (io_idx) /* set VREF for mic */
2661 pinctl |= stac92xx_get_vref(codec, nid);
2662 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2663 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002664
2665 /* check the auto-mute again: we need to mute/unmute the speaker
2666 * appropriately according to the pin direction
2667 */
2668 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002669 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002670
Matt Porter403d1942005-11-29 15:00:51 +01002671 return 1;
2672}
2673
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002674#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2675
2676static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2677 struct snd_ctl_elem_value *ucontrol)
2678{
2679 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2680 struct sigmatel_spec *spec = codec->spec;
2681
2682 ucontrol->value.integer.value[0] = spec->clfe_swap;
2683 return 0;
2684}
2685
2686static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2687 struct snd_ctl_elem_value *ucontrol)
2688{
2689 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2690 struct sigmatel_spec *spec = codec->spec;
2691 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002692 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002693
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002694 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002695 return 0;
2696
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002697 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002698
2699 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2700 spec->clfe_swap ? 0x4 : 0x0);
2701
2702 return 1;
2703}
2704
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002705#define STAC_CODEC_HP_SWITCH(xname) \
2706 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2707 .name = xname, \
2708 .index = 0, \
2709 .info = stac92xx_hp_switch_info, \
2710 .get = stac92xx_hp_switch_get, \
2711 .put = stac92xx_hp_switch_put, \
2712 }
2713
Matt Porter403d1942005-11-29 15:00:51 +01002714#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2715 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2716 .name = xname, \
2717 .index = 0, \
2718 .info = stac92xx_io_switch_info, \
2719 .get = stac92xx_io_switch_get, \
2720 .put = stac92xx_io_switch_put, \
2721 .private_value = xpval, \
2722 }
2723
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002724#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2725 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2726 .name = xname, \
2727 .index = 0, \
2728 .info = stac92xx_clfe_switch_info, \
2729 .get = stac92xx_clfe_switch_get, \
2730 .put = stac92xx_clfe_switch_put, \
2731 .private_value = xpval, \
2732 }
Matt Porter403d1942005-11-29 15:00:51 +01002733
Mattc7d4b2f2005-06-27 14:59:41 +02002734enum {
2735 STAC_CTL_WIDGET_VOL,
2736 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002737 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002738 STAC_CTL_WIDGET_AMP_MUX,
2739 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002740 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002741 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002742 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02002743};
2744
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002745static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002746 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2747 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002748 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002749 STAC_AMP_MUX,
2750 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002751 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002752 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002753 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002754};
2755
2756/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002757static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2758 struct snd_kcontrol_new *ktemp,
2759 int idx, const char *name,
2760 unsigned long val)
Mattc7d4b2f2005-06-27 14:59:41 +02002761{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002762 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002763
Takashi Iwai603c4012008-07-30 15:01:44 +02002764 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2765 knew = snd_array_new(&spec->kctls);
2766 if (!knew)
2767 return -ENOMEM;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002768 *knew = *ktemp;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002769 knew->index = idx;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002770 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002771 if (!knew->name)
Mattc7d4b2f2005-06-27 14:59:41 +02002772 return -ENOMEM;
2773 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002774 return 0;
2775}
2776
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002777static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2778 int type, int idx, const char *name,
2779 unsigned long val)
2780{
2781 return stac92xx_add_control_temp(spec,
2782 &stac92xx_control_templates[type],
2783 idx, name, val);
2784}
2785
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002786
2787/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002788static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2789 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002790{
2791 return stac92xx_add_control_idx(spec, type, 0, name, val);
2792}
2793
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002794/* check whether the line-input can be used as line-out */
2795static hda_nid_t check_line_out_switch(struct hda_codec *codec)
Matt Porter403d1942005-11-29 15:00:51 +01002796{
2797 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002798 struct auto_pin_cfg *cfg = &spec->autocfg;
2799 hda_nid_t nid;
2800 unsigned int pincap;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002801
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002802 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2803 return 0;
2804 nid = cfg->input_pins[AUTO_PIN_LINE];
2805 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
2806 if (pincap & AC_PINCAP_OUT)
2807 return nid;
Matt Porter403d1942005-11-29 15:00:51 +01002808 return 0;
2809}
2810
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002811/* check whether the mic-input can be used as line-out */
2812static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2813{
2814 struct sigmatel_spec *spec = codec->spec;
2815 struct auto_pin_cfg *cfg = &spec->autocfg;
2816 unsigned int def_conf, pincap;
2817 unsigned int mic_pin;
2818
2819 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2820 return 0;
2821 mic_pin = AUTO_PIN_MIC;
2822 for (;;) {
2823 hda_nid_t nid = cfg->input_pins[mic_pin];
2824 def_conf = snd_hda_codec_read(codec, nid, 0,
2825 AC_VERB_GET_CONFIG_DEFAULT, 0);
2826 /* some laptops have an internal analog microphone
2827 * which can't be used as a output */
2828 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2829 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
2830 if (pincap & AC_PINCAP_OUT)
2831 return nid;
2832 }
2833 if (mic_pin == AUTO_PIN_MIC)
2834 mic_pin = AUTO_PIN_FRONT_MIC;
2835 else
2836 break;
2837 }
2838 return 0;
2839}
Steve Longerbeam7b043892007-05-03 20:50:03 +02002840
2841static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2842{
2843 int i;
2844
2845 for (i = 0; i < spec->multiout.num_dacs; i++) {
2846 if (spec->multiout.dac_nids[i] == nid)
2847 return 1;
2848 }
2849
2850 return 0;
2851}
2852
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002853static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2854{
2855 int i;
2856 if (is_in_dac_nids(spec, nid))
2857 return 1;
2858 for (i = 0; i < spec->autocfg.hp_outs; i++)
2859 if (spec->hp_dacs[i] == nid)
2860 return 1;
2861 for (i = 0; i < spec->autocfg.speaker_outs; i++)
2862 if (spec->speaker_dacs[i] == nid)
2863 return 1;
2864 return 0;
2865}
2866
2867static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2868{
2869 struct sigmatel_spec *spec = codec->spec;
2870 int j, conn_len;
2871 hda_nid_t conn[HDA_MAX_CONNECTIONS];
2872 unsigned int wcaps, wtype;
2873
2874 conn_len = snd_hda_get_connections(codec, nid, conn,
2875 HDA_MAX_CONNECTIONS);
2876 for (j = 0; j < conn_len; j++) {
2877 wcaps = snd_hda_param_read(codec, conn[j],
2878 AC_PAR_AUDIO_WIDGET_CAP);
2879 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2880 /* we check only analog outputs */
2881 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
2882 continue;
2883 /* if this route has a free DAC, assign it */
2884 if (!check_all_dac_nids(spec, conn[j])) {
2885 if (conn_len > 1) {
2886 /* select this DAC in the pin's input mux */
2887 snd_hda_codec_write_cache(codec, nid, 0,
2888 AC_VERB_SET_CONNECT_SEL, j);
2889 }
2890 return conn[j];
2891 }
2892 }
2893 return 0;
2894}
2895
2896static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2897static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid);
2898
Matt Porter3cc08dc2006-01-23 15:27:49 +01002899/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002900 * Fill in the dac_nids table from the parsed pin configuration
2901 * This function only works when every pin in line_out_pins[]
2902 * contains atleast one DAC in its connection list. Some 92xx
2903 * codecs are not connected directly to a DAC, such as the 9200
2904 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002905 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002906static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
Mattc7d4b2f2005-06-27 14:59:41 +02002907{
2908 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002909 struct auto_pin_cfg *cfg = &spec->autocfg;
2910 int i;
2911 hda_nid_t nid, dac;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002912
Mattc7d4b2f2005-06-27 14:59:41 +02002913 for (i = 0; i < cfg->line_outs; i++) {
2914 nid = cfg->line_out_pins[i];
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002915 dac = get_unassigned_dac(codec, nid);
2916 if (!dac) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002917 if (spec->multiout.num_dacs > 0) {
2918 /* we have already working output pins,
2919 * so let's drop the broken ones again
2920 */
2921 cfg->line_outs = spec->multiout.num_dacs;
2922 break;
2923 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002924 /* error out, no available DAC found */
2925 snd_printk(KERN_ERR
2926 "%s: No available DAC for pin 0x%x\n",
2927 __func__, nid);
2928 return -ENODEV;
2929 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002930 add_spec_dacs(spec, dac);
2931 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002932
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002933 /* add line-in as output */
2934 nid = check_line_out_switch(codec);
2935 if (nid) {
2936 dac = get_unassigned_dac(codec, nid);
2937 if (dac) {
2938 snd_printdd("STAC: Add line-in 0x%x as output %d\n",
2939 nid, cfg->line_outs);
2940 cfg->line_out_pins[cfg->line_outs] = nid;
2941 cfg->line_outs++;
2942 spec->line_switch = nid;
2943 add_spec_dacs(spec, dac);
2944 }
2945 }
2946 /* add mic as output */
2947 nid = check_mic_out_switch(codec);
2948 if (nid) {
2949 dac = get_unassigned_dac(codec, nid);
2950 if (dac) {
2951 snd_printdd("STAC: Add mic-in 0x%x as output %d\n",
2952 nid, cfg->line_outs);
2953 cfg->line_out_pins[cfg->line_outs] = nid;
2954 cfg->line_outs++;
2955 spec->mic_switch = nid;
2956 add_spec_dacs(spec, dac);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002957 }
Mattc7d4b2f2005-06-27 14:59:41 +02002958 }
2959
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002960 for (i = 0; i < cfg->hp_outs; i++) {
2961 nid = cfg->hp_pins[i];
2962 dac = get_unassigned_dac(codec, nid);
2963 if (dac) {
2964 if (!spec->multiout.hp_nid)
2965 spec->multiout.hp_nid = dac;
2966 else
2967 add_spec_extra_dacs(spec, dac);
2968 }
2969 spec->hp_dacs[i] = dac;
2970 }
2971
2972 for (i = 0; i < cfg->speaker_outs; i++) {
2973 nid = cfg->speaker_pins[i];
2974 dac = get_unassigned_dac(codec, nid);
2975 if (dac)
2976 add_spec_extra_dacs(spec, dac);
2977 spec->speaker_dacs[i] = dac;
2978 }
2979
2980 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
Steve Longerbeam7b043892007-05-03 20:50:03 +02002981 spec->multiout.num_dacs,
2982 spec->multiout.dac_nids[0],
2983 spec->multiout.dac_nids[1],
2984 spec->multiout.dac_nids[2],
2985 spec->multiout.dac_nids[3],
2986 spec->multiout.dac_nids[4]);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01002987
Mattc7d4b2f2005-06-27 14:59:41 +02002988 return 0;
2989}
2990
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002991/* create volume control/switch for the given prefx type */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002992static int create_controls(struct hda_codec *codec, const char *pfx,
2993 hda_nid_t nid, int chs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002994{
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002995 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002996 char name[32];
2997 int err;
2998
Takashi Iwai7c7767e2009-01-20 15:28:38 +01002999 if (!spec->check_volume_offset) {
3000 unsigned int caps, step, nums, db_scale;
3001 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3002 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3003 AC_AMPCAP_STEP_SIZE_SHIFT;
3004 step = (step + 1) * 25; /* in .01dB unit */
3005 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3006 AC_AMPCAP_NUM_STEPS_SHIFT;
3007 db_scale = nums * step;
3008 /* if dB scale is over -64dB, and finer enough,
3009 * let's reduce it to half
3010 */
3011 if (db_scale > 6400 && nums >= 0x1f)
3012 spec->volume_offset = nums / 2;
3013 spec->check_volume_offset = 1;
3014 }
3015
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003016 sprintf(name, "%s Playback Volume", pfx);
3017 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003018 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3019 spec->volume_offset));
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003020 if (err < 0)
3021 return err;
3022 sprintf(name, "%s Playback Switch", pfx);
3023 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
3024 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3025 if (err < 0)
3026 return err;
3027 return 0;
3028}
3029
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003030static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3031{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003032 if (spec->multiout.num_dacs > 4) {
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003033 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
3034 return 1;
3035 } else {
3036 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
3037 spec->multiout.num_dacs++;
3038 }
3039 return 0;
3040}
3041
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003042static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003043{
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003044 int i;
3045 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++) {
3046 if (!spec->multiout.extra_out_nid[i]) {
3047 spec->multiout.extra_out_nid[i] = nid;
3048 return 0;
3049 }
3050 }
3051 printk(KERN_WARNING "stac92xx: No space for extra DAC 0x%x\n", nid);
3052 return 1;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003053}
3054
Takashi Iwai76624532008-12-19 10:09:47 +01003055static int is_unique_dac(struct sigmatel_spec *spec, hda_nid_t nid)
3056{
3057 int i;
3058
3059 if (spec->autocfg.line_outs != 1)
3060 return 0;
3061 if (spec->multiout.hp_nid == nid)
3062 return 0;
3063 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++)
3064 if (spec->multiout.extra_out_nid[i] == nid)
3065 return 0;
3066 return 1;
3067}
3068
Mattc7d4b2f2005-06-27 14:59:41 +02003069/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003070static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02003071 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003072{
Takashi Iwai76624532008-12-19 10:09:47 +01003073 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003074 static const char *chname[4] = {
3075 "Front", "Surround", NULL /*CLFE*/, "Side"
3076 };
Matthew Ranostayd21995e2008-10-13 13:22:45 -04003077 hda_nid_t nid = 0;
Takashi Iwai91589232008-12-19 15:59:40 +01003078 int i, err;
3079 unsigned int wid_caps;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003080
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003081 for (i = 0; i < cfg->line_outs && spec->multiout.dac_nids[i]; i++) {
Mattc7d4b2f2005-06-27 14:59:41 +02003082 nid = spec->multiout.dac_nids[i];
Mattc7d4b2f2005-06-27 14:59:41 +02003083 if (i == 2) {
3084 /* Center/LFE */
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003085 err = create_controls(codec, "Center", nid, 1);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003086 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003087 return err;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003088 err = create_controls(codec, "LFE", nid, 2);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003089 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003090 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003091
3092 wid_caps = get_wcaps(codec, nid);
3093
3094 if (wid_caps & AC_WCAP_LR_SWAP) {
3095 err = stac92xx_add_control(spec,
3096 STAC_CTL_WIDGET_CLFE_SWITCH,
3097 "Swap Center/LFE Playback Switch", nid);
3098
3099 if (err < 0)
3100 return err;
3101 }
3102
Mattc7d4b2f2005-06-27 14:59:41 +02003103 } else {
Takashi Iwai76624532008-12-19 10:09:47 +01003104 const char *name = chname[i];
3105 /* if it's a single DAC, assign a better name */
3106 if (!i && is_unique_dac(spec, nid)) {
3107 switch (cfg->line_out_type) {
3108 case AUTO_PIN_HP_OUT:
3109 name = "Headphone";
3110 break;
3111 case AUTO_PIN_SPEAKER_OUT:
3112 name = "Speaker";
3113 break;
3114 }
3115 }
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003116 err = create_controls(codec, name, nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003117 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003118 return err;
3119 }
3120 }
3121
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01003122 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003123 err = stac92xx_add_control(spec,
3124 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01003125 "Headphone as Line Out Switch",
3126 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02003127 if (err < 0)
3128 return err;
3129 }
3130
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003131 if (spec->line_switch) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003132 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH,
3133 "Line In as Output Switch",
3134 spec->line_switch << 8);
3135 if (err < 0)
3136 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003137 }
Matt Porter403d1942005-11-29 15:00:51 +01003138
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003139 if (spec->mic_switch) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003140 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH,
3141 "Mic as Output Switch",
3142 (spec->mic_switch << 8) | 1);
3143 if (err < 0)
3144 return err;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003145 }
Matt Porter403d1942005-11-29 15:00:51 +01003146
Mattc7d4b2f2005-06-27 14:59:41 +02003147 return 0;
3148}
3149
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003150/* add playback controls for Speaker and HP outputs */
3151static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3152 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003153{
3154 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003155 hda_nid_t nid;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003156 int i, err, nums;
Mattc7d4b2f2005-06-27 14:59:41 +02003157
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003158 nums = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003159 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003160 static const char *pfxs[] = {
3161 "Headphone", "Headphone2", "Headphone3",
3162 };
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003163 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
3164 if (wid_caps & AC_WCAP_UNSOL_CAP)
3165 spec->hp_detect = 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003166 if (nums >= ARRAY_SIZE(pfxs))
Mattc7d4b2f2005-06-27 14:59:41 +02003167 continue;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003168 nid = spec->hp_dacs[i];
3169 if (!nid)
3170 continue;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003171 err = create_controls(codec, pfxs[nums++], nid, 3);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003172 if (err < 0)
3173 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003174 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003175 nums = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003176 for (i = 0; i < cfg->speaker_outs; i++) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003177 static const char *pfxs[] = {
3178 "Speaker", "External Speaker", "Speaker2",
3179 };
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003180 if (nums >= ARRAY_SIZE(pfxs))
3181 continue;
3182 nid = spec->speaker_dacs[i];
3183 if (!nid)
3184 continue;
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003185 err = create_controls(codec, pfxs[nums++], nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003186 if (err < 0)
3187 return err;
3188 }
Mattc7d4b2f2005-06-27 14:59:41 +02003189 return 0;
3190}
3191
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003192/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003193static const char *stac92xx_mono_labels[4] = {
3194 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003195};
3196
3197/* create mono mux for mono out on capable codecs */
3198static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3199{
3200 struct sigmatel_spec *spec = codec->spec;
3201 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3202 int i, num_cons;
3203 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3204
3205 num_cons = snd_hda_get_connections(codec,
3206 spec->mono_nid,
3207 con_lst,
3208 HDA_MAX_NUM_INPUTS);
3209 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3210 return -EINVAL;
3211
3212 for (i = 0; i < num_cons; i++) {
3213 mono_mux->items[mono_mux->num_items].label =
3214 stac92xx_mono_labels[i];
3215 mono_mux->items[mono_mux->num_items].index = i;
3216 mono_mux->num_items++;
3217 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003218
3219 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3220 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003221}
3222
Matthew Ranostay89385032008-09-11 09:49:39 -04003223/* labels for amp mux outputs */
3224static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003225 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003226};
3227
3228/* create amp out controls mux on capable codecs */
3229static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3230{
3231 struct sigmatel_spec *spec = codec->spec;
3232 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3233 int i, err;
3234
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003235 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003236 amp_mux->items[amp_mux->num_items].label =
3237 stac92xx_amp_labels[i];
3238 amp_mux->items[amp_mux->num_items].index = i;
3239 amp_mux->num_items++;
3240 }
3241
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003242 if (spec->num_amps > 1) {
3243 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3244 "Amp Selector Capture Switch", 0);
3245 if (err < 0)
3246 return err;
3247 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003248 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3249 "Amp Capture Volume",
3250 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3251}
3252
3253
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003254/* create PC beep volume controls */
3255static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3256 hda_nid_t nid)
3257{
3258 struct sigmatel_spec *spec = codec->spec;
3259 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3260 int err;
3261
3262 /* check for mute support for the the amp */
3263 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3264 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3265 "PC Beep Playback Switch",
3266 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3267 if (err < 0)
3268 return err;
3269 }
3270
3271 /* check to see if there is volume support for the amp */
3272 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3273 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3274 "PC Beep Playback Volume",
3275 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3276 if (err < 0)
3277 return err;
3278 }
3279 return 0;
3280}
3281
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003282#ifdef CONFIG_SND_HDA_INPUT_BEEP
3283#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3284
3285static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3286 struct snd_ctl_elem_value *ucontrol)
3287{
3288 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3289 ucontrol->value.integer.value[0] = codec->beep->enabled;
3290 return 0;
3291}
3292
3293static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3294 struct snd_ctl_elem_value *ucontrol)
3295{
3296 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3297 int enabled = !!ucontrol->value.integer.value[0];
3298 if (codec->beep->enabled != enabled) {
3299 codec->beep->enabled = enabled;
3300 return 1;
3301 }
3302 return 0;
3303}
3304
3305static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3306 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3307 .info = stac92xx_dig_beep_switch_info,
3308 .get = stac92xx_dig_beep_switch_get,
3309 .put = stac92xx_dig_beep_switch_put,
3310};
3311
3312static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3313{
3314 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3315 0, "PC Beep Playback Switch", 0);
3316}
3317#endif
3318
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003319static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3320{
3321 struct sigmatel_spec *spec = codec->spec;
3322 int wcaps, nid, i, err = 0;
3323
3324 for (i = 0; i < spec->num_muxes; i++) {
3325 nid = spec->mux_nids[i];
3326 wcaps = get_wcaps(codec, nid);
3327
3328 if (wcaps & AC_WCAP_OUT_AMP) {
3329 err = stac92xx_add_control_idx(spec,
3330 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3331 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3332 if (err < 0)
3333 return err;
3334 }
3335 }
3336 return 0;
3337};
3338
Matthew Ranostayd9737752008-09-07 12:03:41 +02003339static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003340 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003341};
3342
3343static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3344{
3345 struct sigmatel_spec *spec = codec->spec;
3346 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003347 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003348 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003349 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003350
3351 num_cons = snd_hda_get_connections(codec,
3352 spec->smux_nids[0],
3353 con_lst,
3354 HDA_MAX_NUM_INPUTS);
Matthew Ranostay65973632008-09-16 10:39:37 -04003355 if (!num_cons)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003356 return -EINVAL;
3357
Matthew Ranostay65973632008-09-16 10:39:37 -04003358 if (!labels)
3359 labels = stac92xx_spdif_labels;
3360
Matthew Ranostayd9737752008-09-07 12:03:41 +02003361 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003362 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003363 spdif_mux->items[spdif_mux->num_items].index = i;
3364 spdif_mux->num_items++;
3365 }
3366
3367 return 0;
3368}
3369
Matt Porter8b657272006-10-26 17:12:59 +02003370/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003371static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003372 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3373 "Digital Mic 3", "Digital Mic 4"
3374};
3375
3376/* create playback/capture controls for input pins on dmic capable codecs */
3377static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3378 const struct auto_pin_cfg *cfg)
3379{
3380 struct sigmatel_spec *spec = codec->spec;
3381 struct hda_input_mux *dimux = &spec->private_dimux;
3382 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003383 int err, i, j;
3384 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02003385
3386 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3387 dimux->items[dimux->num_items].index = 0;
3388 dimux->num_items++;
3389
3390 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003391 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003392 int index;
3393 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003394 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02003395 unsigned int def_conf;
3396
3397 def_conf = snd_hda_codec_read(codec,
3398 spec->dmic_nids[i],
3399 0,
3400 AC_VERB_GET_CONFIG_DEFAULT,
3401 0);
3402 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3403 continue;
3404
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003405 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02003406 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003407 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02003408 con_lst,
3409 HDA_MAX_NUM_INPUTS);
3410 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003411 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02003412 index = j;
3413 goto found;
3414 }
3415 continue;
3416found:
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003417 wcaps = get_wcaps(codec, nid) &
3418 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003419
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003420 if (wcaps) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003421 sprintf(name, "%s Capture Volume",
3422 stac92xx_dmic_labels[dimux->num_items]);
3423
3424 err = stac92xx_add_control(spec,
3425 STAC_CTL_WIDGET_VOL,
3426 name,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003427 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3428 (wcaps & AC_WCAP_OUT_AMP) ?
3429 HDA_OUTPUT : HDA_INPUT));
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003430 if (err < 0)
3431 return err;
3432 }
3433
Matt Porter8b657272006-10-26 17:12:59 +02003434 dimux->items[dimux->num_items].label =
3435 stac92xx_dmic_labels[dimux->num_items];
3436 dimux->items[dimux->num_items].index = index;
3437 dimux->num_items++;
3438 }
3439
3440 return 0;
3441}
3442
Mattc7d4b2f2005-06-27 14:59:41 +02003443/* create playback/capture controls for input pins */
3444static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3445{
3446 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003447 struct hda_input_mux *imux = &spec->private_imux;
3448 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3449 int i, j, k;
3450
3451 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003452 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02003453
Takashi Iwai314634b2006-09-21 11:56:18 +02003454 if (!cfg->input_pins[i])
3455 continue;
3456 index = -1;
3457 for (j = 0; j < spec->num_muxes; j++) {
3458 int num_cons;
3459 num_cons = snd_hda_get_connections(codec,
3460 spec->mux_nids[j],
3461 con_lst,
3462 HDA_MAX_NUM_INPUTS);
3463 for (k = 0; k < num_cons; k++)
3464 if (con_lst[k] == cfg->input_pins[i]) {
3465 index = k;
3466 goto found;
3467 }
Mattc7d4b2f2005-06-27 14:59:41 +02003468 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003469 continue;
3470 found:
3471 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3472 imux->items[imux->num_items].index = index;
3473 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003474 }
3475
Steve Longerbeam7b043892007-05-03 20:50:03 +02003476 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003477 /*
3478 * Set the current input for the muxes.
3479 * The STAC9221 has two input muxes with identical source
3480 * NID lists. Hopefully this won't get confused.
3481 */
3482 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003483 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3484 AC_VERB_SET_CONNECT_SEL,
3485 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003486 }
3487 }
3488
Mattc7d4b2f2005-06-27 14:59:41 +02003489 return 0;
3490}
3491
Mattc7d4b2f2005-06-27 14:59:41 +02003492static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3493{
3494 struct sigmatel_spec *spec = codec->spec;
3495 int i;
3496
3497 for (i = 0; i < spec->autocfg.line_outs; i++) {
3498 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3499 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3500 }
3501}
3502
3503static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3504{
3505 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003506 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003507
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003508 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3509 hda_nid_t pin;
3510 pin = spec->autocfg.hp_pins[i];
3511 if (pin) /* connect to front */
3512 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3513 }
3514 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3515 hda_nid_t pin;
3516 pin = spec->autocfg.speaker_pins[i];
3517 if (pin) /* connect to front */
3518 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3519 }
Mattc7d4b2f2005-06-27 14:59:41 +02003520}
3521
Matt Porter3cc08dc2006-01-23 15:27:49 +01003522static 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 +02003523{
3524 struct sigmatel_spec *spec = codec->spec;
3525 int err;
3526
Matt Porter8b657272006-10-26 17:12:59 +02003527 if ((err = snd_hda_parse_pin_def_config(codec,
3528 &spec->autocfg,
3529 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003530 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003531 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003532 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003533
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003534 /* If we have no real line-out pin and multiple hp-outs, HPs should
3535 * be set up as multi-channel outputs.
3536 */
3537 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3538 spec->autocfg.hp_outs > 1) {
3539 /* Copy hp_outs to line_outs, backup line_outs in
3540 * speaker_outs so that the following routines can handle
3541 * HP pins as primary outputs.
3542 */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003543 snd_printdd("stac92xx: Enabling multi-HPs workaround\n");
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003544 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3545 sizeof(spec->autocfg.line_out_pins));
3546 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3547 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3548 sizeof(spec->autocfg.hp_pins));
3549 spec->autocfg.line_outs = spec->autocfg.hp_outs;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003550 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3551 spec->autocfg.hp_outs = 0;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003552 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003553 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003554 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3555 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003556 u32 caps = query_amp_caps(codec,
3557 spec->autocfg.mono_out_pin, dir);
3558 hda_nid_t conn_list[1];
3559
3560 /* get the mixer node and then the mono mux if it exists */
3561 if (snd_hda_get_connections(codec,
3562 spec->autocfg.mono_out_pin, conn_list, 1) &&
3563 snd_hda_get_connections(codec, conn_list[0],
3564 conn_list, 1)) {
3565
3566 int wcaps = get_wcaps(codec, conn_list[0]);
3567 int wid_type = (wcaps & AC_WCAP_TYPE)
3568 >> AC_WCAP_TYPE_SHIFT;
3569 /* LR swap check, some stac925x have a mux that
3570 * changes the DACs output path instead of the
3571 * mono-mux path.
3572 */
3573 if (wid_type == AC_WID_AUD_SEL &&
3574 !(wcaps & AC_WCAP_LR_SWAP))
3575 spec->mono_nid = conn_list[0];
3576 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003577 if (dir) {
3578 hda_nid_t nid = spec->autocfg.mono_out_pin;
3579
3580 /* most mono outs have a least a mute/unmute switch */
3581 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3582 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3583 "Mono Playback Switch",
3584 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003585 if (err < 0)
3586 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003587 /* check for volume support for the amp */
3588 if ((caps & AC_AMPCAP_NUM_STEPS)
3589 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3590 err = stac92xx_add_control(spec,
3591 STAC_CTL_WIDGET_VOL,
3592 "Mono Playback Volume",
3593 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3594 if (err < 0)
3595 return err;
3596 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003597 }
3598
3599 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3600 AC_PINCTL_OUT_EN);
3601 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003602
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003603 if (!spec->multiout.num_dacs) {
3604 err = stac92xx_auto_fill_dac_nids(codec);
3605 if (err < 0)
Takashi Iwai19039bd2006-06-28 15:52:16 +02003606 return err;
Takashi Iwaic9280d62009-01-15 17:31:00 +01003607 err = stac92xx_auto_create_multi_out_ctls(codec,
3608 &spec->autocfg);
3609 if (err < 0)
3610 return err;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003611 }
Mattc7d4b2f2005-06-27 14:59:41 +02003612
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003613 /* setup analog beep controls */
3614 if (spec->anabeep_nid > 0) {
3615 err = stac92xx_auto_create_beep_ctls(codec,
3616 spec->anabeep_nid);
3617 if (err < 0)
3618 return err;
3619 }
3620
3621 /* setup digital beep controls and input device */
3622#ifdef CONFIG_SND_HDA_INPUT_BEEP
3623 if (spec->digbeep_nid > 0) {
3624 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003625 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003626
3627 err = stac92xx_auto_create_beep_ctls(codec, nid);
3628 if (err < 0)
3629 return err;
3630 err = snd_hda_attach_beep_device(codec, nid);
3631 if (err < 0)
3632 return err;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003633 /* if no beep switch is available, make its own one */
3634 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3635 if (codec->beep &&
3636 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3637 err = stac92xx_beep_switch_ctl(codec);
3638 if (err < 0)
3639 return err;
3640 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003641 }
3642#endif
3643
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003644 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3645
3646 if (err < 0)
3647 return err;
3648
3649 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3650
3651 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003652 return err;
3653
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003654 if (spec->mono_nid > 0) {
3655 err = stac92xx_auto_create_mono_output_ctls(codec);
3656 if (err < 0)
3657 return err;
3658 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003659 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003660 err = stac92xx_auto_create_amp_output_ctls(codec);
3661 if (err < 0)
3662 return err;
3663 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003664 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003665 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3666 &spec->autocfg)) < 0)
3667 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003668 if (spec->num_muxes > 0) {
3669 err = stac92xx_auto_create_mux_input_ctls(codec);
3670 if (err < 0)
3671 return err;
3672 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003673 if (spec->num_smuxes > 0) {
3674 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3675 if (err < 0)
3676 return err;
3677 }
Matt Porter8b657272006-10-26 17:12:59 +02003678
Mattc7d4b2f2005-06-27 14:59:41 +02003679 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003680 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003681 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003682
Takashi Iwai82bc9552006-03-21 11:24:42 +01003683 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003684 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003685 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003686 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003687
Takashi Iwai603c4012008-07-30 15:01:44 +02003688 if (spec->kctls.list)
3689 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003690
3691 spec->input_mux = &spec->private_imux;
Matthew Ranostayf8ccbf62008-12-20 17:36:28 -05003692 if (!spec->dinput_mux)
3693 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003694 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003695 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04003696 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003697 return 1;
3698}
3699
Takashi Iwai82bc9552006-03-21 11:24:42 +01003700/* add playback controls for HP output */
3701static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3702 struct auto_pin_cfg *cfg)
3703{
3704 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003705 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003706 unsigned int wid_caps;
3707
3708 if (! pin)
3709 return 0;
3710
3711 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003712 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003713 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003714
3715 return 0;
3716}
3717
Richard Fish160ea0d2006-09-06 13:58:25 +02003718/* add playback controls for LFE output */
3719static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3720 struct auto_pin_cfg *cfg)
3721{
3722 struct sigmatel_spec *spec = codec->spec;
3723 int err;
3724 hda_nid_t lfe_pin = 0x0;
3725 int i;
3726
3727 /*
3728 * search speaker outs and line outs for a mono speaker pin
3729 * with an amp. If one is found, add LFE controls
3730 * for it.
3731 */
3732 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3733 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003734 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003735 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3736 if (wcaps == AC_WCAP_OUT_AMP)
3737 /* found a mono speaker with an amp, must be lfe */
3738 lfe_pin = pin;
3739 }
3740
3741 /* if speaker_outs is 0, then speakers may be in line_outs */
3742 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3743 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3744 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003745 unsigned int defcfg;
Harvey Harrison8b551782008-02-29 11:56:48 +01003746 defcfg = snd_hda_codec_read(codec, pin, 0,
Richard Fish160ea0d2006-09-06 13:58:25 +02003747 AC_VERB_GET_CONFIG_DEFAULT,
3748 0x00);
Harvey Harrison8b551782008-02-29 11:56:48 +01003749 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003750 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003751 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3752 if (wcaps == AC_WCAP_OUT_AMP)
3753 /* found a mono speaker with an amp,
3754 must be lfe */
3755 lfe_pin = pin;
3756 }
3757 }
3758 }
3759
3760 if (lfe_pin) {
Takashi Iwai7c7767e2009-01-20 15:28:38 +01003761 err = create_controls(codec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003762 if (err < 0)
3763 return err;
3764 }
3765
3766 return 0;
3767}
3768
Mattc7d4b2f2005-06-27 14:59:41 +02003769static int stac9200_parse_auto_config(struct hda_codec *codec)
3770{
3771 struct sigmatel_spec *spec = codec->spec;
3772 int err;
3773
Kailang Yangdf694da2005-12-05 19:42:22 +01003774 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003775 return err;
3776
3777 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3778 return err;
3779
Takashi Iwai82bc9552006-03-21 11:24:42 +01003780 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3781 return err;
3782
Richard Fish160ea0d2006-09-06 13:58:25 +02003783 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3784 return err;
3785
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003786 if (spec->num_muxes > 0) {
3787 err = stac92xx_auto_create_mux_input_ctls(codec);
3788 if (err < 0)
3789 return err;
3790 }
3791
Takashi Iwai82bc9552006-03-21 11:24:42 +01003792 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003793 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003794 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003795 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003796
Takashi Iwai603c4012008-07-30 15:01:44 +02003797 if (spec->kctls.list)
3798 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003799
3800 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003801 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003802
3803 return 1;
3804}
3805
Sam Revitch62fe78e2006-05-10 15:09:17 +02003806/*
3807 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3808 * funky external mute control using GPIO pins.
3809 */
3810
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003811static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003812 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003813{
3814 unsigned int gpiostate, gpiomask, gpiodir;
3815
3816 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3817 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003818 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003819
3820 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3821 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003822 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003823
3824 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3825 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003826 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003827
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003828 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003829 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3830
3831 snd_hda_codec_write(codec, codec->afg, 0,
3832 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003833 snd_hda_codec_read(codec, codec->afg, 0,
3834 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003835
3836 msleep(1);
3837
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003838 snd_hda_codec_read(codec, codec->afg, 0,
3839 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003840}
3841
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003842static int stac92xx_add_jack(struct hda_codec *codec,
3843 hda_nid_t nid, int type)
3844{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003845#ifdef CONFIG_SND_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003846 struct sigmatel_spec *spec = codec->spec;
3847 struct sigmatel_jack *jack;
3848 int def_conf = snd_hda_codec_read(codec, nid,
3849 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
3850 int connectivity = get_defcfg_connect(def_conf);
3851 char name[32];
3852
3853 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3854 return 0;
3855
3856 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3857 jack = snd_array_new(&spec->jacks);
3858 if (!jack)
3859 return -ENOMEM;
3860 jack->nid = nid;
3861 jack->type = type;
3862
3863 sprintf(name, "%s at %s %s Jack",
3864 snd_hda_get_jack_type(def_conf),
3865 snd_hda_get_jack_connectivity(def_conf),
3866 snd_hda_get_jack_location(def_conf));
3867
3868 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003869#else
3870 return 0;
3871#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003872}
3873
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003874static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3875 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003876{
3877 struct sigmatel_event *event;
3878
3879 snd_array_init(&spec->events, sizeof(*event), 32);
3880 event = snd_array_new(&spec->events);
3881 if (!event)
3882 return -ENOMEM;
3883 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003884 event->type = type;
3885 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003886 event->data = data;
3887
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003888 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003889}
3890
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003891static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
3892 hda_nid_t nid, unsigned char type)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003893{
3894 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003895 struct sigmatel_event *event = spec->events.list;
3896 int i;
3897
3898 for (i = 0; i < spec->events.used; i++, event++) {
3899 if (event->nid == nid && event->type == type)
3900 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003901 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003902 return NULL;
3903}
3904
3905static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
3906 unsigned char tag)
3907{
3908 struct sigmatel_spec *spec = codec->spec;
3909 struct sigmatel_event *event = spec->events.list;
3910 int i;
3911
3912 for (i = 0; i < spec->events.used; i++, event++) {
3913 if (event->tag == tag)
3914 return event;
3915 }
3916 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003917}
3918
Takashi Iwai314634b2006-09-21 11:56:18 +02003919static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003920 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02003921{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003922 struct sigmatel_event *event;
3923 int tag;
3924
3925 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
3926 return;
3927 event = stac_get_event(codec, nid, type);
3928 if (event)
3929 tag = event->tag;
3930 else
3931 tag = stac_add_event(codec->spec, nid, type, 0);
3932 if (tag < 0)
3933 return;
3934 snd_hda_codec_write_cache(codec, nid, 0,
3935 AC_VERB_SET_UNSOLICITED_ENABLE,
3936 AC_USRSP_EN | tag);
Takashi Iwai314634b2006-09-21 11:56:18 +02003937}
3938
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003939static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3940{
3941 int i;
3942 for (i = 0; i < cfg->hp_outs; i++)
3943 if (cfg->hp_pins[i] == nid)
3944 return 1; /* nid is a HP-Out */
3945
3946 return 0; /* nid is not a HP-Out */
3947};
3948
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003949static void stac92xx_power_down(struct hda_codec *codec)
3950{
3951 struct sigmatel_spec *spec = codec->spec;
3952
3953 /* power down inactive DACs */
3954 hda_nid_t *dac;
3955 for (dac = spec->dac_list; *dac; dac++)
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01003956 if (!check_all_dac_nids(spec, *dac))
Takashi Iwai8c2f7672008-12-01 11:54:35 +01003957 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003958 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3959}
3960
Takashi Iwaif73d3582008-11-25 08:21:51 +01003961static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3962 int enable);
3963
Mattc7d4b2f2005-06-27 14:59:41 +02003964static int stac92xx_init(struct hda_codec *codec)
3965{
3966 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003967 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01003968 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01003969 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003970
Mattc7d4b2f2005-06-27 14:59:41 +02003971 snd_hda_sequence_write(codec, spec->init);
3972
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02003973 /* power down adcs initially */
3974 if (spec->powerdown_adcs)
3975 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01003976 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02003977 spec->adc_nids[i], 0,
3978 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003979
3980 /* set up GPIO */
3981 gpio = spec->gpio_data;
3982 /* turn on EAPD statically when spec->eapd_switch isn't set.
3983 * otherwise, unsol event will turn it on/off dynamically
3984 */
3985 if (!spec->eapd_switch)
3986 gpio |= spec->eapd_mask;
3987 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
3988
Takashi Iwai82bc9552006-03-21 11:24:42 +01003989 /* set up pins */
3990 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02003991 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003992 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003993 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003994 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003995 }
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01003996 /* force to enable the first line-out; the others are set up
3997 * in unsol_event
3998 */
3999 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004000 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004001 /* fake event to set up pins */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004002 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4003 STAC_HP_EVENT);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004004 } else {
4005 stac92xx_auto_init_multi_out(codec);
4006 stac92xx_auto_init_hp_out(codec);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004007 for (i = 0; i < cfg->hp_outs; i++)
4008 stac_toggle_power_map(codec, cfg->hp_pins[i], 1);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004009 }
4010 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01004011 hda_nid_t nid = cfg->input_pins[i];
4012 if (nid) {
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004013 unsigned int pinctl, conf;
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004014 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
4015 /* for mic pins, force to initialize */
4016 pinctl = stac92xx_get_vref(codec, nid);
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004017 pinctl |= AC_PINCTL_IN_EN;
4018 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004019 } else {
4020 pinctl = snd_hda_codec_read(codec, nid, 0,
4021 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4022 /* if PINCTL already set then skip */
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004023 if (!(pinctl & AC_PINCTL_IN_EN)) {
4024 pinctl |= AC_PINCTL_IN_EN;
4025 stac92xx_auto_set_pinctl(codec, nid,
4026 pinctl);
4027 }
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01004028 }
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004029 conf = snd_hda_codec_read(codec, nid, 0,
4030 AC_VERB_GET_CONFIG_DEFAULT, 0);
4031 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4032 enable_pin_detect(codec, nid,
4033 STAC_INSERT_EVENT);
4034 stac_issue_unsol_event(codec, nid,
4035 STAC_INSERT_EVENT);
4036 }
Takashi Iwaic960a032006-03-23 17:06:28 +01004037 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01004038 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004039 for (i = 0; i < spec->num_dmics; i++)
4040 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4041 AC_PINCTL_IN_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01004042 if (cfg->dig_out_pin)
4043 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
4044 AC_PINCTL_OUT_EN);
4045 if (cfg->dig_in_pin)
4046 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
4047 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004048 for (i = 0; i < spec->num_pwrs; i++) {
4049 hda_nid_t nid = spec->pwr_nids[i];
4050 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01004051
Takashi Iwaieb632122008-12-19 16:39:48 +01004052 /* power on when no jack detection is available */
4053 if (!spec->hp_detect) {
4054 stac_toggle_power_map(codec, nid, 1);
4055 continue;
4056 }
4057
4058 if (is_nid_hp_pin(cfg, nid))
Takashi Iwaif73d3582008-11-25 08:21:51 +01004059 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02004060
Takashi Iwaif73d3582008-11-25 08:21:51 +01004061 pinctl = snd_hda_codec_read(codec, nid, 0,
4062 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4063 /* outputs are only ports capable of power management
4064 * any attempts on powering down a input port cause the
4065 * referenced VREF to act quirky.
4066 */
Takashi Iwaieb632122008-12-19 16:39:48 +01004067 if (pinctl & AC_PINCTL_IN_EN) {
4068 stac_toggle_power_map(codec, nid, 1);
Takashi Iwaif73d3582008-11-25 08:21:51 +01004069 continue;
Takashi Iwaieb632122008-12-19 16:39:48 +01004070 }
Takashi Iwaif73d3582008-11-25 08:21:51 +01004071 def_conf = snd_hda_codec_read(codec, nid, 0,
4072 AC_VERB_GET_CONFIG_DEFAULT, 0);
4073 def_conf = get_defcfg_connect(def_conf);
4074 /* skip any ports that don't have jacks since presence
4075 * detection is useless */
4076 if (def_conf != AC_JACK_PORT_COMPLEX) {
4077 if (def_conf != AC_JACK_PORT_NONE)
4078 stac_toggle_power_map(codec, nid, 1);
4079 continue;
4080 }
Takashi Iwai12dde4c2008-12-05 13:09:27 +01004081 if (!stac_get_event(codec, nid, STAC_INSERT_EVENT)) {
4082 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
4083 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
4084 }
Takashi Iwaif73d3582008-11-25 08:21:51 +01004085 }
4086 if (spec->dac_list)
4087 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02004088 return 0;
4089}
4090
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004091static void stac92xx_free_jacks(struct hda_codec *codec)
4092{
Takashi Iwaie4973e12008-11-18 09:32:42 +01004093#ifdef CONFIG_SND_JACK
Takashi Iwaib94d35392008-11-21 09:08:06 +01004094 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004095 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d35392008-11-21 09:08:06 +01004096 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004097 struct sigmatel_jack *jacks = spec->jacks.list;
4098 int i;
4099 for (i = 0; i < spec->jacks.used; i++)
4100 snd_device_free(codec->bus->card, &jacks[i].jack);
4101 }
4102 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01004103#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004104}
4105
Takashi Iwai603c4012008-07-30 15:01:44 +02004106static void stac92xx_free_kctls(struct hda_codec *codec)
4107{
4108 struct sigmatel_spec *spec = codec->spec;
4109
4110 if (spec->kctls.list) {
4111 struct snd_kcontrol_new *kctl = spec->kctls.list;
4112 int i;
4113 for (i = 0; i < spec->kctls.used; i++)
4114 kfree(kctl[i].name);
4115 }
4116 snd_array_free(&spec->kctls);
4117}
4118
Matt2f2f4252005-04-13 14:45:30 +02004119static void stac92xx_free(struct hda_codec *codec)
4120{
Mattc7d4b2f2005-06-27 14:59:41 +02004121 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004122
4123 if (! spec)
4124 return;
4125
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004126 kfree(spec->pin_configs);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004127 stac92xx_free_jacks(codec);
4128 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004129
Mattc7d4b2f2005-06-27 14:59:41 +02004130 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004131 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004132}
4133
Matt4e550962005-07-04 17:51:39 +02004134static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4135 unsigned int flag)
4136{
Takashi Iwai8ce84192009-01-22 16:59:20 +01004137 unsigned int old_ctl, pin_ctl;
4138
4139 pin_ctl = snd_hda_codec_read(codec, nid,
Matt4e550962005-07-04 17:51:39 +02004140 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004141
Takashi Iwaif9acba42007-05-29 18:01:06 +02004142 if (pin_ctl & AC_PINCTL_IN_EN) {
4143 /*
4144 * we need to check the current set-up direction of
4145 * shared input pins since they can be switched via
4146 * "xxx as Output" mixer switch
4147 */
4148 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004149 if (nid == spec->line_switch || nid == spec->mic_switch)
Takashi Iwaif9acba42007-05-29 18:01:06 +02004150 return;
4151 }
4152
Takashi Iwai8ce84192009-01-22 16:59:20 +01004153 old_ctl = pin_ctl;
Steve Longerbeam7b043892007-05-03 20:50:03 +02004154 /* if setting pin direction bits, clear the current
4155 direction bits first */
4156 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4157 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4158
Takashi Iwai8ce84192009-01-22 16:59:20 +01004159 pin_ctl |= flag;
4160 if (old_ctl != pin_ctl)
4161 snd_hda_codec_write_cache(codec, nid, 0,
4162 AC_VERB_SET_PIN_WIDGET_CONTROL,
4163 pin_ctl);
Matt4e550962005-07-04 17:51:39 +02004164}
4165
4166static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4167 unsigned int flag)
4168{
4169 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4170 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai8ce84192009-01-22 16:59:20 +01004171 if (pin_ctl & flag)
4172 snd_hda_codec_write_cache(codec, nid, 0,
4173 AC_VERB_SET_PIN_WIDGET_CONTROL,
4174 pin_ctl & ~flag);
Matt4e550962005-07-04 17:51:39 +02004175}
4176
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004177static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004178{
4179 if (!nid)
4180 return 0;
4181 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004182 & (1 << 31))
4183 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004184 return 0;
4185}
4186
Takashi Iwaid7a89432008-11-12 09:48:04 +01004187/* return non-zero if the hp-pin of the given array index isn't
4188 * a jack-detection target
4189 */
4190static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4191{
4192 struct auto_pin_cfg *cfg = &spec->autocfg;
4193
4194 /* ignore sensing of shared line and mic jacks */
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004195 if (cfg->hp_pins[i] == spec->line_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004196 return 1;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004197 if (cfg->hp_pins[i] == spec->mic_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004198 return 1;
4199 /* ignore if the pin is set as line-out */
4200 if (cfg->hp_pins[i] == spec->hp_switch)
4201 return 1;
4202 return 0;
4203}
4204
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004205static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004206{
4207 struct sigmatel_spec *spec = codec->spec;
4208 struct auto_pin_cfg *cfg = &spec->autocfg;
4209 int i, presence;
4210
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004211 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004212 if (spec->gpio_mute)
4213 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4214 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4215
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004216 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004217 if (presence)
4218 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004219 if (no_hp_sensing(spec, i))
4220 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004221 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4222 if (presence) {
4223 unsigned int pinctl;
4224 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4225 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4226 if (pinctl & AC_PINCTL_IN_EN)
4227 presence = 0; /* mic- or line-input */
4228 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004229 }
Matt4e550962005-07-04 17:51:39 +02004230
4231 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004232 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004233 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004234 stac92xx_reset_pinctl(codec, spec->hp_switch,
4235 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004236 for (i = 0; i < cfg->line_outs; i++)
4237 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4238 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004239 for (i = 0; i < cfg->speaker_outs; i++)
4240 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4241 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004242 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004243 stac_gpio_set(codec, spec->gpio_mask,
4244 spec->gpio_dir, spec->gpio_data &
4245 ~spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004246 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004247 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004248 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004249 stac92xx_set_pinctl(codec, spec->hp_switch,
4250 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004251 for (i = 0; i < cfg->line_outs; i++)
4252 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4253 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004254 for (i = 0; i < cfg->speaker_outs; i++)
4255 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4256 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004257 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004258 stac_gpio_set(codec, spec->gpio_mask,
4259 spec->gpio_dir, spec->gpio_data |
4260 spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004261 }
Takashi Iwaid7a89432008-11-12 09:48:04 +01004262 /* toggle hp outs */
4263 for (i = 0; i < cfg->hp_outs; i++) {
4264 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4265 if (no_hp_sensing(spec, i))
4266 continue;
4267 if (presence)
4268 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004269#if 0 /* FIXME */
4270/* Resetting the pinctl like below may lead to (a sort of) regressions
4271 * on some devices since they use the HP pin actually for line/speaker
4272 * outs although the default pin config shows a different pin (that is
4273 * wrong and useless).
4274 *
4275 * So, it's basically a problem of default pin configs, likely a BIOS issue.
4276 * But, disabling the code below just works around it, and I'm too tired of
4277 * bug reports with such devices...
4278 */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004279 else
4280 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
Takashi Iwai8317e0b2009-01-14 07:56:51 +01004281#endif /* FIXME */
Takashi Iwaid7a89432008-11-12 09:48:04 +01004282 }
Matt4e550962005-07-04 17:51:39 +02004283}
4284
Takashi Iwaif73d3582008-11-25 08:21:51 +01004285static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4286 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004287{
4288 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004289 unsigned int idx, val;
4290
4291 for (idx = 0; idx < spec->num_pwrs; idx++) {
4292 if (spec->pwr_nids[idx] == nid)
4293 break;
4294 }
4295 if (idx >= spec->num_pwrs)
4296 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004297
4298 /* several codecs have two power down bits */
4299 if (spec->pwr_mapping)
4300 idx = spec->pwr_mapping[idx];
4301 else
4302 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004303
Takashi Iwaif73d3582008-11-25 08:21:51 +01004304 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4305 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004306 val &= ~idx;
4307 else
4308 val |= idx;
4309
4310 /* power down unused output ports */
4311 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004312}
4313
Takashi Iwaif73d3582008-11-25 08:21:51 +01004314static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4315{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004316 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004317}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004318
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004319static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4320{
4321 struct sigmatel_spec *spec = codec->spec;
4322 struct sigmatel_jack *jacks = spec->jacks.list;
4323
4324 if (jacks) {
4325 int i;
4326 for (i = 0; i < spec->jacks.used; i++) {
4327 if (jacks->nid == nid) {
4328 unsigned int pin_ctl =
4329 snd_hda_codec_read(codec, nid,
4330 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4331 0x00);
4332 int type = jacks->type;
4333 if (type == (SND_JACK_LINEOUT
4334 | SND_JACK_HEADPHONE))
4335 type = (pin_ctl & AC_PINCTL_HP_EN)
4336 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4337 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004338 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004339 ? type : 0);
4340 }
4341 jacks++;
4342 }
4343 }
4344}
Matt2f2f4252005-04-13 14:45:30 +02004345
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004346static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4347 unsigned char type)
4348{
4349 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4350 if (!event)
4351 return;
4352 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4353}
4354
Takashi Iwai314634b2006-09-21 11:56:18 +02004355static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4356{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004357 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004358 struct sigmatel_event *event;
4359 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004360
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004361 tag = (res >> 26) & 0x7f;
4362 event = stac_get_event_from_tag(codec, tag);
4363 if (!event)
4364 return;
4365
4366 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004367 case STAC_HP_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004368 stac92xx_hp_detect(codec);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004369 /* fallthru */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004370 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004371 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004372 if (spec->num_pwrs > 0)
4373 stac92xx_pin_sense(codec, event->nid);
4374 stac92xx_report_jack(codec, event->nid);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004375 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004376 case STAC_VREF_EVENT:
4377 data = snd_hda_codec_read(codec, codec->afg, 0,
4378 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004379 /* toggle VREF state based on GPIOx status */
4380 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004381 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004382 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004383 }
4384}
4385
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004386#ifdef CONFIG_PROC_FS
4387static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4388 struct hda_codec *codec, hda_nid_t nid)
4389{
4390 if (nid == codec->afg)
4391 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4392 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4393}
4394
4395static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4396 struct hda_codec *codec,
4397 unsigned int verb)
4398{
4399 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4400 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4401}
4402
4403/* stac92hd71bxx, stac92hd73xx */
4404static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4405 struct hda_codec *codec, hda_nid_t nid)
4406{
4407 stac92hd_proc_hook(buffer, codec, nid);
4408 if (nid == codec->afg)
4409 analog_loop_proc_hook(buffer, codec, 0xfa0);
4410}
4411
4412static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4413 struct hda_codec *codec, hda_nid_t nid)
4414{
4415 if (nid == codec->afg)
4416 analog_loop_proc_hook(buffer, codec, 0xfe0);
4417}
4418
4419static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4420 struct hda_codec *codec, hda_nid_t nid)
4421{
4422 if (nid == codec->afg)
4423 analog_loop_proc_hook(buffer, codec, 0xfeb);
4424}
4425#else
4426#define stac92hd_proc_hook NULL
4427#define stac92hd7x_proc_hook NULL
4428#define stac9205_proc_hook NULL
4429#define stac927x_proc_hook NULL
4430#endif
4431
Takashi Iwaicb53c622007-08-10 17:21:45 +02004432#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004433static int stac92xx_resume(struct hda_codec *codec)
4434{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004435 struct sigmatel_spec *spec = codec->spec;
4436
Richard Fish11b44bb2006-08-23 18:31:34 +02004437 stac92xx_set_config_regs(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004438 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004439 snd_hda_codec_resume_amp(codec);
4440 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004441 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004442 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004443 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4444 STAC_HP_EVENT);
Mattff6fdc32005-06-27 15:06:52 +02004445 return 0;
4446}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004447
4448static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4449{
4450 struct sigmatel_spec *spec = codec->spec;
4451 if (spec->eapd_mask)
4452 stac_gpio_set(codec, spec->gpio_mask,
4453 spec->gpio_dir, spec->gpio_data &
4454 ~spec->eapd_mask);
4455 return 0;
4456}
Mattff6fdc32005-06-27 15:06:52 +02004457#endif
4458
Matt2f2f4252005-04-13 14:45:30 +02004459static struct hda_codec_ops stac92xx_patch_ops = {
4460 .build_controls = stac92xx_build_controls,
4461 .build_pcms = stac92xx_build_pcms,
4462 .init = stac92xx_init,
4463 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004464 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004465#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004466 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004467 .resume = stac92xx_resume,
4468#endif
Matt2f2f4252005-04-13 14:45:30 +02004469};
4470
4471static int patch_stac9200(struct hda_codec *codec)
4472{
4473 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004474 int err;
Matt2f2f4252005-04-13 14:45:30 +02004475
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004476 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004477 if (spec == NULL)
4478 return -ENOMEM;
4479
4480 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004481 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004482 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004483 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4484 stac9200_models,
4485 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02004486 if (spec->board_config < 0) {
4487 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4488 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004489 } else
4490 err = stac_save_pin_cfgs(codec,
4491 stac9200_brd_tbl[spec->board_config]);
4492 if (err < 0) {
4493 stac92xx_free(codec);
4494 return err;
Matt Porter403d1942005-11-29 15:00:51 +01004495 }
Matt2f2f4252005-04-13 14:45:30 +02004496
4497 spec->multiout.max_channels = 2;
4498 spec->multiout.num_dacs = 1;
4499 spec->multiout.dac_nids = stac9200_dac_nids;
4500 spec->adc_nids = stac9200_adc_nids;
4501 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004502 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004503 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004504 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004505 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004506
Mauro Carvalho Chehab58eec422008-08-11 10:18:39 +02004507 if (spec->board_config == STAC_9200_M4 ||
4508 spec->board_config == STAC_9200_M4_2 ||
Tobin Davisbf277782008-02-03 20:31:47 +01004509 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004510 spec->init = stac9200_eapd_init;
4511 else
4512 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004513 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004514
Takashi Iwai117f2572008-03-18 09:53:23 +01004515 if (spec->board_config == STAC_9200_PANASONIC) {
4516 spec->gpio_mask = spec->gpio_dir = 0x09;
4517 spec->gpio_data = 0x00;
4518 }
4519
Mattc7d4b2f2005-06-27 14:59:41 +02004520 err = stac9200_parse_auto_config(codec);
4521 if (err < 0) {
4522 stac92xx_free(codec);
4523 return err;
4524 }
Matt2f2f4252005-04-13 14:45:30 +02004525
Takashi Iwai2acc9dc2009-01-09 16:57:14 +01004526 /* CF-74 has no headphone detection, and the driver should *NOT*
4527 * do detection and HP/speaker toggle because the hardware does it.
4528 */
4529 if (spec->board_config == STAC_9200_PANASONIC)
4530 spec->hp_detect = 0;
4531
Matt2f2f4252005-04-13 14:45:30 +02004532 codec->patch_ops = stac92xx_patch_ops;
4533
4534 return 0;
4535}
4536
Tobin Davis8e21c342007-01-08 11:04:17 +01004537static int patch_stac925x(struct hda_codec *codec)
4538{
4539 struct sigmatel_spec *spec;
4540 int err;
4541
4542 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4543 if (spec == NULL)
4544 return -ENOMEM;
4545
4546 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004547 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004548 spec->pin_nids = stac925x_pin_nids;
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004549
4550 /* Check first for codec ID */
4551 spec->board_config = snd_hda_check_board_codec_sid_config(codec,
4552 STAC_925x_MODELS,
4553 stac925x_models,
4554 stac925x_codec_id_cfg_tbl);
4555
4556 /* Now checks for PCI ID, if codec ID is not found */
4557 if (spec->board_config < 0)
4558 spec->board_config = snd_hda_check_board_config(codec,
4559 STAC_925x_MODELS,
Tobin Davis8e21c342007-01-08 11:04:17 +01004560 stac925x_models,
4561 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004562 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01004563 if (spec->board_config < 0) {
Mauro Carvalho Chehab9cb36c22008-08-11 10:18:39 +02004564 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
Tobin Davis2c11f952007-05-17 09:36:34 +02004565 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01004566 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004567 } else
4568 err = stac_save_pin_cfgs(codec,
4569 stac925x_brd_tbl[spec->board_config]);
4570 if (err < 0) {
4571 stac92xx_free(codec);
4572 return err;
Tobin Davis8e21c342007-01-08 11:04:17 +01004573 }
4574
4575 spec->multiout.max_channels = 2;
4576 spec->multiout.num_dacs = 1;
4577 spec->multiout.dac_nids = stac925x_dac_nids;
4578 spec->adc_nids = stac925x_adc_nids;
4579 spec->mux_nids = stac925x_mux_nids;
4580 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004581 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004582 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004583 switch (codec->vendor_id) {
4584 case 0x83847632: /* STAC9202 */
4585 case 0x83847633: /* STAC9202D */
4586 case 0x83847636: /* STAC9251 */
4587 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004588 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004589 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004590 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4591 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004592 break;
4593 default:
4594 spec->num_dmics = 0;
4595 break;
4596 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004597
4598 spec->init = stac925x_core_init;
4599 spec->mixer = stac925x_mixer;
4600
4601 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004602 if (!err) {
4603 if (spec->board_config < 0) {
4604 printk(KERN_WARNING "hda_codec: No auto-config is "
4605 "available, default to model=ref\n");
4606 spec->board_config = STAC_925x_REF;
4607 goto again;
4608 }
4609 err = -EINVAL;
4610 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004611 if (err < 0) {
4612 stac92xx_free(codec);
4613 return err;
4614 }
4615
4616 codec->patch_ops = stac92xx_patch_ops;
4617
4618 return 0;
4619}
4620
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004621static struct hda_input_mux stac92hd73xx_dmux = {
4622 .num_items = 4,
4623 .items = {
4624 { "Analog Inputs", 0x0b },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004625 { "Digital Mic 1", 0x09 },
4626 { "Digital Mic 2", 0x0a },
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004627 { "CD", 0x08 },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004628 }
4629};
4630
4631static int patch_stac92hd73xx(struct hda_codec *codec)
4632{
4633 struct sigmatel_spec *spec;
4634 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4635 int err = 0;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004636 int num_dacs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004637
4638 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4639 if (spec == NULL)
4640 return -ENOMEM;
4641
4642 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004643 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004644 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4645 spec->pin_nids = stac92hd73xx_pin_nids;
4646 spec->board_config = snd_hda_check_board_config(codec,
4647 STAC_92HD73XX_MODELS,
4648 stac92hd73xx_models,
4649 stac92hd73xx_cfg_tbl);
4650again:
4651 if (spec->board_config < 0) {
4652 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4653 " STAC92HD73XX, using BIOS defaults\n");
4654 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004655 } else
4656 err = stac_save_pin_cfgs(codec,
4657 stac92hd73xx_brd_tbl[spec->board_config]);
4658 if (err < 0) {
4659 stac92xx_free(codec);
4660 return err;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004661 }
4662
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004663 num_dacs = snd_hda_get_connections(codec, 0x0a,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004664 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4665
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004666 if (num_dacs < 3 || num_dacs > 5) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004667 printk(KERN_WARNING "hda_codec: Could not determine "
4668 "number of channels defaulting to DAC count\n");
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004669 num_dacs = STAC92HD73_DAC_COUNT;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004670 }
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004671 switch (num_dacs) {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004672 case 0x3: /* 6 Channel */
4673 spec->mixer = stac92hd73xx_6ch_mixer;
4674 spec->init = stac92hd73xx_6ch_core_init;
4675 break;
4676 case 0x4: /* 8 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004677 spec->mixer = stac92hd73xx_8ch_mixer;
4678 spec->init = stac92hd73xx_8ch_core_init;
4679 break;
4680 case 0x5: /* 10 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004681 spec->mixer = stac92hd73xx_10ch_mixer;
4682 spec->init = stac92hd73xx_10ch_core_init;
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004683 }
4684 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004685
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004686 spec->aloopback_mask = 0x01;
4687 spec->aloopback_shift = 8;
4688
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004689 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004690 spec->mux_nids = stac92hd73xx_mux_nids;
4691 spec->adc_nids = stac92hd73xx_adc_nids;
4692 spec->dmic_nids = stac92hd73xx_dmic_nids;
4693 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004694 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04004695 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004696 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004697
4698 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4699 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01004700 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004701 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4702 sizeof(stac92hd73xx_dmux));
4703
Matthew Ranostaya7662642008-02-21 07:51:14 +01004704 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004705 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004706 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004707 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004708 case STAC_DELL_M6_AMIC:
4709 case STAC_DELL_M6_DMIC:
4710 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004711 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004712 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4713 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004714 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004715 spec->num_amps = 1;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004716
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004717 if (spec->board_config != STAC_DELL_EQ)
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004718 spec->init = dell_m6_core_init;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004719 switch (spec->board_config) {
4720 case STAC_DELL_M6_AMIC: /* Analog Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004721 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4722 spec->num_dmics = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004723 spec->private_dimux.num_items = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004724 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004725 case STAC_DELL_M6_DMIC: /* Digital Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004726 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4727 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004728 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004729 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004730 case STAC_DELL_M6_BOTH: /* Both */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004731 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4732 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4733 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004734 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004735 break;
4736 }
4737 break;
4738 default:
4739 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004740 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004741 spec->eapd_switch = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004742 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04004743 if (spec->board_config > STAC_92HD73XX_REF) {
4744 /* GPIO0 High = Enable EAPD */
4745 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4746 spec->gpio_data = 0x01;
4747 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004748 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004749
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004750 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4751 spec->pwr_nids = stac92hd73xx_pwr_nids;
4752
Matthew Ranostayd9737752008-09-07 12:03:41 +02004753 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004754
4755 if (!err) {
4756 if (spec->board_config < 0) {
4757 printk(KERN_WARNING "hda_codec: No auto-config is "
4758 "available, default to model=ref\n");
4759 spec->board_config = STAC_92HD73XX_REF;
4760 goto again;
4761 }
4762 err = -EINVAL;
4763 }
4764
4765 if (err < 0) {
4766 stac92xx_free(codec);
4767 return err;
4768 }
4769
Takashi Iwai9e43f0d2008-12-17 14:51:01 +01004770 if (spec->board_config == STAC_92HD73XX_NO_JD)
4771 spec->hp_detect = 0;
4772
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004773 codec->patch_ops = stac92xx_patch_ops;
4774
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004775 codec->proc_widget_hook = stac92hd7x_proc_hook;
4776
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004777 return 0;
4778}
4779
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004780static struct hda_input_mux stac92hd83xxx_dmux = {
4781 .num_items = 3,
4782 .items = {
4783 { "Analog Inputs", 0x03 },
4784 { "Digital Mic 1", 0x04 },
4785 { "Digital Mic 2", 0x05 },
4786 }
4787};
4788
4789static int patch_stac92hd83xxx(struct hda_codec *codec)
4790{
4791 struct sigmatel_spec *spec;
Matthew Ranostay65557f32009-01-20 16:50:25 -05004792 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004793 int err;
Matthew Ranostay65557f32009-01-20 16:50:25 -05004794 int num_dacs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004795
4796 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4797 if (spec == NULL)
4798 return -ENOMEM;
4799
4800 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004801 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004802 spec->mono_nid = 0x19;
4803 spec->digbeep_nid = 0x21;
4804 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4805 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4806 spec->adc_nids = stac92hd83xxx_adc_nids;
4807 spec->pwr_nids = stac92hd83xxx_pwr_nids;
Matthew Ranostayc15c5062009-01-13 13:30:07 -05004808 spec->amp_nids = stac92hd83xxx_amp_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004809 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4810 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01004811 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004812
Matthew Ranostay65557f32009-01-20 16:50:25 -05004813
4814 /* set port 0xe to select the last DAC
4815 */
4816 num_dacs = snd_hda_get_connections(codec, 0x0e,
4817 conn, STAC92HD83_DAC_COUNT + 1) - 1;
4818
4819 snd_hda_codec_write_cache(codec, 0xe, 0,
4820 AC_VERB_SET_CONNECT_SEL, num_dacs);
4821
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004822 spec->init = stac92hd83xxx_core_init;
4823 switch (codec->vendor_id) {
4824 case 0x111d7605:
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004825 break;
4826 default:
4827 spec->num_pwrs--;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004828 }
4829
4830 spec->mixer = stac92hd83xxx_mixer;
4831 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4832 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4833 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
Matthew Ranostayc15c5062009-01-13 13:30:07 -05004834 spec->num_amps = ARRAY_SIZE(stac92hd83xxx_amp_nids);
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004835 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4836 spec->dinput_mux = &stac92hd83xxx_dmux;
4837 spec->pin_nids = stac92hd83xxx_pin_nids;
4838 spec->board_config = snd_hda_check_board_config(codec,
4839 STAC_92HD83XXX_MODELS,
4840 stac92hd83xxx_models,
4841 stac92hd83xxx_cfg_tbl);
4842again:
4843 if (spec->board_config < 0) {
4844 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4845 " STAC92HD83XXX, using BIOS defaults\n");
4846 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004847 } else
4848 err = stac_save_pin_cfgs(codec,
4849 stac92hd83xxx_brd_tbl[spec->board_config]);
4850 if (err < 0) {
4851 stac92xx_free(codec);
4852 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004853 }
4854
4855 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4856 if (!err) {
4857 if (spec->board_config < 0) {
4858 printk(KERN_WARNING "hda_codec: No auto-config is "
4859 "available, default to model=ref\n");
4860 spec->board_config = STAC_92HD83XXX_REF;
4861 goto again;
4862 }
4863 err = -EINVAL;
4864 }
4865
4866 if (err < 0) {
4867 stac92xx_free(codec);
4868 return err;
4869 }
4870
4871 codec->patch_ops = stac92xx_patch_ops;
4872
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004873 codec->proc_widget_hook = stac92hd_proc_hook;
4874
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004875 return 0;
4876}
4877
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004878static struct hda_input_mux stac92hd71bxx_dmux = {
4879 .num_items = 4,
4880 .items = {
4881 { "Analog Inputs", 0x00 },
4882 { "Mixer", 0x01 },
4883 { "Digital Mic 1", 0x02 },
4884 { "Digital Mic 2", 0x03 },
4885 }
4886};
4887
Matthew Ranostaye035b842007-11-06 11:53:55 +01004888static int patch_stac92hd71bxx(struct hda_codec *codec)
4889{
4890 struct sigmatel_spec *spec;
4891 int err = 0;
4892
4893 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4894 if (spec == NULL)
4895 return -ENOMEM;
4896
4897 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004898 codec->patch_ops = stac92xx_patch_ops;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004899 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004900 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004901 spec->pin_nids = stac92hd71bxx_pin_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004902 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4903 sizeof(stac92hd71bxx_dmux));
Matthew Ranostaye035b842007-11-06 11:53:55 +01004904 spec->board_config = snd_hda_check_board_config(codec,
4905 STAC_92HD71BXX_MODELS,
4906 stac92hd71bxx_models,
4907 stac92hd71bxx_cfg_tbl);
4908again:
4909 if (spec->board_config < 0) {
4910 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4911 " STAC92HD71BXX, using BIOS defaults\n");
4912 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004913 } else
4914 err = stac_save_pin_cfgs(codec,
4915 stac92hd71bxx_brd_tbl[spec->board_config]);
4916 if (err < 0) {
4917 stac92xx_free(codec);
4918 return err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004919 }
4920
Takashi Iwai41c3b642008-11-18 10:45:15 +01004921 if (spec->board_config > STAC_92HD71BXX_REF) {
4922 /* GPIO0 = EAPD */
4923 spec->gpio_mask = 0x01;
4924 spec->gpio_dir = 0x01;
4925 spec->gpio_data = 0x01;
4926 }
4927
Matthew Ranostay541eee82007-12-14 12:08:04 +01004928 switch (codec->vendor_id) {
4929 case 0x111d76b6: /* 4 Port without Analog Mixer */
4930 case 0x111d76b7:
4931 case 0x111d76b4: /* 6 Port without Analog Mixer */
4932 case 0x111d76b5:
4933 spec->mixer = stac92hd71bxx_mixer;
4934 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004935 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004936 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004937 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01004938 switch (spec->board_config) {
4939 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04004940 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004941 err = stac_add_event(spec, codec->afg,
4942 STAC_VREF_EVENT, 0x02);
4943 if (err < 0)
4944 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01004945 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04004946 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4947 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004948 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004949 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004950 spec->gpio_mask |= 0x02;
4951 break;
4952 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004953 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004954 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004955 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004956
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004957 /* no output amps */
4958 spec->num_pwrs = 0;
4959 spec->mixer = stac92hd71bxx_analog_mixer;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004960 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004961
4962 /* disable VSW */
4963 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004964 stac_change_pin_config(codec, 0xf, 0x40f000f0);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004965 break;
4966 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004967 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004968 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004969
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004970 /* no output amps */
4971 spec->num_pwrs = 0;
4972 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01004973 default:
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004974 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004975 spec->mixer = stac92hd71bxx_analog_mixer;
4976 spec->init = stac92hd71bxx_analog_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004977 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004978 }
4979
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004980 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004981 spec->aloopback_shift = 0;
4982
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004983 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004984 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004985 spec->mux_nids = stac92hd71bxx_mux_nids;
4986 spec->adc_nids = stac92hd71bxx_adc_nids;
4987 spec->dmic_nids = stac92hd71bxx_dmic_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004988 spec->dmux_nids = stac92hd71bxx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004989 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004990 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004991
4992 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
4993 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004994
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004995 switch (spec->board_config) {
4996 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004997 /* enable internal microphone */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01004998 stac_change_pin_config(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04004999 stac92xx_auto_set_pinctl(codec, 0x0e,
5000 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05005001 /* fallthru */
5002 case STAC_DELL_M4_2:
5003 spec->num_dmics = 0;
5004 spec->num_smuxes = 0;
5005 spec->num_dmuxes = 0;
5006 break;
5007 case STAC_DELL_M4_1:
5008 case STAC_DELL_M4_3:
5009 spec->num_dmics = 1;
5010 spec->num_smuxes = 0;
5011 spec->num_dmuxes = 0;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04005012 break;
5013 default:
5014 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
5015 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
5016 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5017 };
5018
Takashi Iwaic21ca4a2008-12-19 09:26:08 +01005019 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04005020 if (spec->dinput_mux)
5021 spec->private_dimux.num_items +=
5022 spec->num_dmics -
5023 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
Matthew Ranostaye035b842007-11-06 11:53:55 +01005024
5025 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
5026 if (!err) {
5027 if (spec->board_config < 0) {
5028 printk(KERN_WARNING "hda_codec: No auto-config is "
5029 "available, default to model=ref\n");
5030 spec->board_config = STAC_92HD71BXX_REF;
5031 goto again;
5032 }
5033 err = -EINVAL;
5034 }
5035
5036 if (err < 0) {
5037 stac92xx_free(codec);
5038 return err;
5039 }
5040
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005041 codec->proc_widget_hook = stac92hd7x_proc_hook;
5042
Matthew Ranostaye035b842007-11-06 11:53:55 +01005043 return 0;
5044};
5045
Matt2f2f4252005-04-13 14:45:30 +02005046static int patch_stac922x(struct hda_codec *codec)
5047{
5048 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02005049 int err;
Matt2f2f4252005-04-13 14:45:30 +02005050
Takashi Iwaie560d8d2005-09-09 14:21:46 +02005051 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02005052 if (spec == NULL)
5053 return -ENOMEM;
5054
5055 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005056 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005057 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005058 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
5059 stac922x_models,
5060 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08005061 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005062 spec->gpio_mask = spec->gpio_dir = 0x03;
5063 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005064 /* Intel Macs have all same PCI SSID, so we need to check
5065 * codec SSID to distinguish the exact models
5066 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005067 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005068 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005069
5070 case 0x106b0800:
5071 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02005072 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005073 case 0x106b0600:
5074 case 0x106b0700:
5075 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01005076 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005077 case 0x106b0e00:
5078 case 0x106b0f00:
5079 case 0x106b1600:
5080 case 0x106b1700:
5081 case 0x106b0200:
5082 case 0x106b1e00:
5083 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005084 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005085 case 0x106b1a00:
5086 case 0x00000100:
5087 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02005088 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02005089 case 0x106b0a00:
5090 case 0x106b2200:
5091 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02005092 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08005093 default:
5094 spec->board_config = STAC_INTEL_MAC_V3;
5095 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01005096 }
5097 }
5098
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005099 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02005100 if (spec->board_config < 0) {
5101 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
5102 "using BIOS defaults\n");
5103 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005104 } else
5105 err = stac_save_pin_cfgs(codec,
5106 stac922x_brd_tbl[spec->board_config]);
5107 if (err < 0) {
5108 stac92xx_free(codec);
5109 return err;
Matt Porter403d1942005-11-29 15:00:51 +01005110 }
Matt2f2f4252005-04-13 14:45:30 +02005111
Matt2f2f4252005-04-13 14:45:30 +02005112 spec->adc_nids = stac922x_adc_nids;
5113 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005114 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005115 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005116 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005117 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02005118
5119 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02005120 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02005121
5122 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02005123
Matt Porter3cc08dc2006-01-23 15:27:49 +01005124 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005125 if (!err) {
5126 if (spec->board_config < 0) {
5127 printk(KERN_WARNING "hda_codec: No auto-config is "
5128 "available, default to model=ref\n");
5129 spec->board_config = STAC_D945_REF;
5130 goto again;
5131 }
5132 err = -EINVAL;
5133 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005134 if (err < 0) {
5135 stac92xx_free(codec);
5136 return err;
5137 }
5138
5139 codec->patch_ops = stac92xx_patch_ops;
5140
Takashi Iwai807a46362007-05-29 19:01:37 +02005141 /* Fix Mux capture level; max to 2 */
5142 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
5143 (0 << AC_AMPCAP_OFFSET_SHIFT) |
5144 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
5145 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5146 (0 << AC_AMPCAP_MUTE_SHIFT));
5147
Matt Porter3cc08dc2006-01-23 15:27:49 +01005148 return 0;
5149}
5150
5151static int patch_stac927x(struct hda_codec *codec)
5152{
5153 struct sigmatel_spec *spec;
5154 int err;
5155
5156 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5157 if (spec == NULL)
5158 return -ENOMEM;
5159
5160 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005161 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005162 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005163 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5164 stac927x_models,
5165 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005166 again:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005167 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
5168 if (spec->board_config < 0)
5169 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5170 "STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02005171 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005172 } else
5173 err = stac_save_pin_cfgs(codec,
5174 stac927x_brd_tbl[spec->board_config]);
5175 if (err < 0) {
5176 stac92xx_free(codec);
5177 return err;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005178 }
5179
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005180 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005181 spec->adc_nids = stac927x_adc_nids;
5182 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5183 spec->mux_nids = stac927x_mux_nids;
5184 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005185 spec->smux_nids = stac927x_smux_nids;
5186 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005187 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005188 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005189 spec->multiout.dac_nids = spec->dac_nids;
5190
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005191 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005192 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005193 case STAC_D965_5ST:
5194 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005195 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005196 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005197 spec->num_dmics = 0;
5198
Tobin Davis93ed1502006-09-01 21:03:12 +02005199 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005200 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005201 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005202 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005203 switch (codec->subsystem_id) {
5204 case 0x10280209:
5205 case 0x1028022e:
5206 /* correct the device field to SPDIF out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005207 stac_change_pin_config(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005208 break;
5209 };
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005210 /* configure the analog microphone on some laptops */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005211 stac_change_pin_config(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005212 /* correct the front output jack as a hp out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005213 stac_change_pin_config(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005214 /* correct the front input jack as a mic */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005215 stac_change_pin_config(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005216 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005217 case STAC_DELL_3ST:
5218 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005219 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005220 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005221 spec->dmic_nids = stac927x_dmic_nids;
5222 spec->num_dmics = STAC927X_NUM_DMICS;
5223
Tobin Davis93ed1502006-09-01 21:03:12 +02005224 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005225 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005226 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005227 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005228 break;
5229 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005230 if (spec->board_config > STAC_D965_REF) {
5231 /* GPIO0 High = Enable EAPD */
5232 spec->eapd_mask = spec->gpio_mask = 0x01;
5233 spec->gpio_dir = spec->gpio_data = 0x01;
5234 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005235 spec->num_dmics = 0;
5236
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005237 spec->init = stac927x_core_init;
5238 spec->mixer = stac927x_mixer;
5239 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005240
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005241 spec->num_pwrs = 0;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005242 spec->aloopback_mask = 0x40;
5243 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005244 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005245
Matt Porter3cc08dc2006-01-23 15:27:49 +01005246 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005247 if (!err) {
5248 if (spec->board_config < 0) {
5249 printk(KERN_WARNING "hda_codec: No auto-config is "
5250 "available, default to model=ref\n");
5251 spec->board_config = STAC_D965_REF;
5252 goto again;
5253 }
5254 err = -EINVAL;
5255 }
Mattc7d4b2f2005-06-27 14:59:41 +02005256 if (err < 0) {
5257 stac92xx_free(codec);
5258 return err;
5259 }
Matt2f2f4252005-04-13 14:45:30 +02005260
5261 codec->patch_ops = stac92xx_patch_ops;
5262
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005263 codec->proc_widget_hook = stac927x_proc_hook;
5264
Takashi Iwai52987652008-01-16 16:09:47 +01005265 /*
5266 * !!FIXME!!
5267 * The STAC927x seem to require fairly long delays for certain
5268 * command sequences. With too short delays (even if the answer
5269 * is set to RIRB properly), it results in the silence output
5270 * on some hardwares like Dell.
5271 *
5272 * The below flag enables the longer delay (see get_response
5273 * in hda_intel.c).
5274 */
5275 codec->bus->needs_damn_long_delay = 1;
5276
Takashi Iwaie28d8322008-12-17 13:48:29 +01005277 /* no jack detecion for ref-no-jd model */
5278 if (spec->board_config == STAC_D965_REF_NO_JD)
5279 spec->hp_detect = 0;
5280
Matt2f2f4252005-04-13 14:45:30 +02005281 return 0;
5282}
5283
Matt Porterf3302a52006-07-31 12:49:34 +02005284static int patch_stac9205(struct hda_codec *codec)
5285{
5286 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005287 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005288
5289 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5290 if (spec == NULL)
5291 return -ENOMEM;
5292
5293 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005294 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005295 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005296 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5297 stac9205_models,
5298 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005299 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02005300 if (spec->board_config < 0) {
5301 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
5302 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005303 } else
5304 err = stac_save_pin_cfgs(codec,
5305 stac9205_brd_tbl[spec->board_config]);
5306 if (err < 0) {
5307 stac92xx_free(codec);
5308 return err;
Matt Porterf3302a52006-07-31 12:49:34 +02005309 }
5310
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005311 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005312 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005313 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005314 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005315 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005316 spec->smux_nids = stac9205_smux_nids;
5317 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005318 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005319 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005320 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005321 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005322 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005323
5324 spec->init = stac9205_core_init;
5325 spec->mixer = stac9205_mixer;
5326
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005327 spec->aloopback_mask = 0x40;
5328 spec->aloopback_shift = 0;
Takashi Iwaid9a42682009-01-22 17:40:18 +01005329 /* Turn on/off EAPD per HP plugging */
5330 if (spec->board_config != STAC_9205_EAPD)
5331 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005332 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005333
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005334 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005335 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005336 /* Enable SPDIF in/out */
Takashi Iwaiaf9f341a2008-11-18 10:38:56 +01005337 stac_change_pin_config(codec, 0x1f, 0x01441030);
5338 stac_change_pin_config(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005339
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005340 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005341 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5342 if (err < 0)
5343 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005344 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005345 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5346 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005347 AC_VERB_SET_UNSOLICITED_ENABLE,
5348 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005349
5350 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005351 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005352 spec->gpio_mask = 0x1b;
5353 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005354 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005355 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005356 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005357 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005358 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005359 case STAC_9205_REF:
5360 /* SPDIF-In enabled */
5361 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005362 default:
5363 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005364 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005365 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005366 break;
5367 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005368
Matt Porterf3302a52006-07-31 12:49:34 +02005369 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005370 if (!err) {
5371 if (spec->board_config < 0) {
5372 printk(KERN_WARNING "hda_codec: No auto-config is "
5373 "available, default to model=ref\n");
5374 spec->board_config = STAC_9205_REF;
5375 goto again;
5376 }
5377 err = -EINVAL;
5378 }
Matt Porterf3302a52006-07-31 12:49:34 +02005379 if (err < 0) {
5380 stac92xx_free(codec);
5381 return err;
5382 }
5383
5384 codec->patch_ops = stac92xx_patch_ops;
5385
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005386 codec->proc_widget_hook = stac9205_proc_hook;
5387
Matt Porterf3302a52006-07-31 12:49:34 +02005388 return 0;
5389}
5390
Matt2f2f4252005-04-13 14:45:30 +02005391/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005392 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005393 */
5394
Takashi Iwai1e137f92009-01-21 07:41:22 +01005395static struct hda_verb stac9872_core_init[] = {
Takashi Iwai1624cb92007-07-05 13:10:51 +02005396 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005397 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5398 {}
5399};
5400
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005401static struct snd_kcontrol_new stac9872_mixer[] = {
5402 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5403 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5404 STAC_INPUT_SOURCE(1),
5405 { } /* end */
5406};
5407
5408static hda_nid_t stac9872_pin_nids[] = {
5409 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5410 0x11, 0x13, 0x14,
5411};
5412
5413static hda_nid_t stac9872_adc_nids[] = {
5414 0x8 /*,0x6*/
5415};
5416
5417static hda_nid_t stac9872_mux_nids[] = {
5418 0x15
5419};
5420
Guillaume Munch6d859062006-08-22 17:15:47 +02005421static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005422{
5423 struct sigmatel_spec *spec;
Takashi Iwai1e137f92009-01-21 07:41:22 +01005424 int err;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005425
Takashi Iwaidb064e52006-03-16 16:04:58 +01005426 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5427 if (spec == NULL)
5428 return -ENOMEM;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005429 codec->spec = spec;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005430
Takashi Iwai1e137f92009-01-21 07:41:22 +01005431#if 0 /* no model right now */
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005432 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5433 stac9872_models,
5434 stac9872_cfg_tbl);
Takashi Iwai1e137f92009-01-21 07:41:22 +01005435#endif
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005436
Takashi Iwai1e137f92009-01-21 07:41:22 +01005437 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5438 spec->pin_nids = stac9872_pin_nids;
5439 spec->multiout.dac_nids = spec->dac_nids;
5440 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5441 spec->adc_nids = stac9872_adc_nids;
5442 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5443 spec->mux_nids = stac9872_mux_nids;
5444 spec->mixer = stac9872_mixer;
5445 spec->init = stac9872_core_init;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005446
Takashi Iwai1e137f92009-01-21 07:41:22 +01005447 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5448 if (err < 0) {
5449 stac92xx_free(codec);
5450 return -EINVAL;
Takashi Iwaicaa10b62009-01-20 17:19:01 +01005451 }
Takashi Iwai1e137f92009-01-21 07:41:22 +01005452 spec->input_mux = &spec->private_imux;
5453 codec->patch_ops = stac92xx_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005454 return 0;
5455}
5456
5457
5458/*
Matt2f2f4252005-04-13 14:45:30 +02005459 * patch entries
5460 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005461static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02005462 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5463 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5464 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5465 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5466 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5467 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5468 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005469 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5470 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5471 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5472 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5473 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5474 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005475 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5476 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5477 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5478 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5479 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5480 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5481 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5482 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5483 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5484 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005485 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5486 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5487 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5488 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5489 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5490 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005491 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5492 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005493 /* The following does not take into account .id=0x83847661 when subsys =
5494 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5495 * currently not fully supported.
5496 */
5497 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5498 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5499 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02005500 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5501 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5502 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5503 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5504 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5505 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5506 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5507 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005508 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005509 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5510 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005511 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005512 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5513 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005514 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005515 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5516 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5517 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5518 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5519 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5520 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5521 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5522 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005523 {} /* terminator */
5524};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005525
5526MODULE_ALIAS("snd-hda-codec-id:8384*");
5527MODULE_ALIAS("snd-hda-codec-id:111d*");
5528
5529MODULE_LICENSE("GPL");
5530MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5531
5532static struct hda_codec_preset_list sigmatel_list = {
5533 .preset = snd_hda_preset_sigmatel,
5534 .owner = THIS_MODULE,
5535};
5536
5537static int __init patch_sigmatel_init(void)
5538{
5539 return snd_hda_add_codec_preset(&sigmatel_list);
5540}
5541
5542static void __exit patch_sigmatel_exit(void)
5543{
5544 snd_hda_delete_codec_preset(&sigmatel_list);
5545}
5546
5547module_init(patch_sigmatel_init)
5548module_exit(patch_sigmatel_exit)