blob: 08170dff75e0a8bc67880801355d389e585c64f3 [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,
Takashi Iwai1194b5b2007-10-10 10:04:26 +020058 STAC_9200_GATEWAY,
Takashi Iwai117f2572008-03-18 09:53:23 +010059 STAC_9200_PANASONIC,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010060 STAC_9200_MODELS
61};
62
63enum {
64 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020065 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020066 STAC_9205_DELL_M43,
67 STAC_9205_DELL_M44,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010068 STAC_9205_MODELS
69};
70
71enum {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010072 STAC_92HD73XX_REF,
Takashi Iwai661cd8f2008-11-25 15:18:29 +010073 STAC_DELL_M6_AMIC,
74 STAC_DELL_M6_DMIC,
75 STAC_DELL_M6_BOTH,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -050076 STAC_DELL_EQ,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010077 STAC_92HD73XX_MODELS
78};
79
80enum {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +020081 STAC_92HD83XXX_REF,
82 STAC_92HD83XXX_MODELS
83};
84
85enum {
Matthew Ranostaye035b842007-11-06 11:53:55 +010086 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010087 STAC_DELL_M4_1,
88 STAC_DELL_M4_2,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -050089 STAC_DELL_M4_3,
Matthew Ranostay6a14f582008-09-12 12:02:30 -040090 STAC_HP_M4,
Matthew Ranostaye035b842007-11-06 11:53:55 +010091 STAC_92HD71BXX_MODELS
92};
93
94enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010095 STAC_925x_REF,
96 STAC_M2_2,
97 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020098 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +010099 STAC_925x_MODELS
100};
101
102enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100103 STAC_D945_REF,
104 STAC_D945GTP3,
105 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +0200106 STAC_INTEL_MAC_V1,
107 STAC_INTEL_MAC_V2,
108 STAC_INTEL_MAC_V3,
109 STAC_INTEL_MAC_V4,
110 STAC_INTEL_MAC_V5,
Nicolas Boichat536319a2008-07-21 22:18:01 +0800111 STAC_INTEL_MAC_AUTO, /* This model is selected if no module parameter
112 * is given, one of the above models will be
113 * chosen according to the subsystem id. */
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200114 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100115 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +0100116 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +0100117 STAC_MACBOOK_PRO_V1,
118 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200119 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200120 STAC_IMAC_INTEL_20,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -0300121 STAC_ECS_202,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200122 STAC_922X_DELL_D81,
123 STAC_922X_DELL_D82,
124 STAC_922X_DELL_M81,
125 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100126 STAC_922X_MODELS
127};
128
129enum {
130 STAC_D965_REF,
131 STAC_D965_3ST,
132 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200133 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100134 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100135 STAC_927X_MODELS
136};
Matt Porter403d1942005-11-29 15:00:51 +0100137
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400138struct sigmatel_event {
139 hda_nid_t nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +0100140 unsigned char type;
141 unsigned char tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400142 int data;
143};
144
145struct sigmatel_jack {
146 hda_nid_t nid;
147 int type;
148 struct snd_jack *jack;
149};
150
Matt2f2f4252005-04-13 14:45:30 +0200151struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100152 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200153 unsigned int num_mixers;
154
Matt Porter403d1942005-11-29 15:00:51 +0100155 int board_config;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -0500156 unsigned int eapd_switch: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200157 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +0100158 unsigned int line_switch: 1;
159 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100160 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100161 unsigned int hp_detect: 1;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400162 unsigned int spdif_mute: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200163
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100164 /* gpio lines */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +0200165 unsigned int eapd_mask;
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100166 unsigned int gpio_mask;
167 unsigned int gpio_dir;
168 unsigned int gpio_data;
169 unsigned int gpio_mute;
170
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200171 /* stream */
172 unsigned int stream_delay;
173
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100174 /* analog loopback */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100175 unsigned char aloopback_mask;
176 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200177
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100178 /* power management */
179 unsigned int num_pwrs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200180 unsigned int *pwr_mapping;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100181 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100182 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100183
Matthew Ranostay74aeaab2008-10-25 01:06:04 -0400184 /* jack detection */
185 struct snd_array jacks;
186
187 /* events */
188 struct snd_array events;
189
Matt2f2f4252005-04-13 14:45:30 +0200190 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100191 struct hda_input_mux *mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400192 struct hda_input_mux *amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100193 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200194 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100195 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200196
197 /* capture */
198 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200199 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200200 hda_nid_t *mux_nids;
201 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200202 hda_nid_t *dmic_nids;
203 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100204 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100205 unsigned int num_dmuxes;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200206 hda_nid_t *smux_nids;
207 unsigned int num_smuxes;
Matthew Ranostay65973632008-09-16 10:39:37 -0400208 const char **spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200209
Mattdabbed62005-06-14 10:19:34 +0200210 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100211 hda_nid_t mono_nid;
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200212 hda_nid_t anabeep_nid;
213 hda_nid_t digbeep_nid;
Matt2f2f4252005-04-13 14:45:30 +0200214
Matt2f2f4252005-04-13 14:45:30 +0200215 /* pin widgets */
216 hda_nid_t *pin_nids;
217 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200218 unsigned int *pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200219
220 /* codec specific stuff */
221 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100222 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200223
224 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200225 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100226 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200227 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100228 unsigned int cur_mux[3];
Matthew Ranostayd9737752008-09-07 12:03:41 +0200229 struct hda_input_mux *sinput_mux;
230 unsigned int cur_smux[2];
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400231 unsigned int cur_amux;
232 hda_nid_t *amp_nids;
233 unsigned int num_amps;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +0200234 unsigned int powerdown_adcs;
Matt2f2f4252005-04-13 14:45:30 +0200235
Matt Porter403d1942005-11-29 15:00:51 +0100236 /* i/o switches */
237 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200238 unsigned int clfe_swap;
Takashi Iwaid7a89432008-11-12 09:48:04 +0100239 unsigned int hp_switch; /* NID of HP as line-out */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200240 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200241
Mattc7d4b2f2005-06-27 14:59:41 +0200242 struct hda_pcm pcm_rec[2]; /* PCM information */
243
244 /* dynamic controls and input_mux */
245 struct auto_pin_cfg autocfg;
Takashi Iwai603c4012008-07-30 15:01:44 +0200246 struct snd_array kctls;
Matt Porter8b657272006-10-26 17:12:59 +0200247 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200248 struct hda_input_mux private_imux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200249 struct hda_input_mux private_smux;
Matthew Ranostay89385032008-09-11 09:49:39 -0400250 struct hda_input_mux private_amp_mux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100251 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200252};
253
254static hda_nid_t stac9200_adc_nids[1] = {
255 0x03,
256};
257
258static hda_nid_t stac9200_mux_nids[1] = {
259 0x0c,
260};
261
262static hda_nid_t stac9200_dac_nids[1] = {
263 0x02,
264};
265
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100266static hda_nid_t stac92hd73xx_pwr_nids[8] = {
267 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
268 0x0f, 0x10, 0x11
269};
270
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400271static hda_nid_t stac92hd73xx_slave_dig_outs[2] = {
272 0x26, 0,
273};
274
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100275static hda_nid_t stac92hd73xx_adc_nids[2] = {
276 0x1a, 0x1b
277};
278
Matthew Ranostay2a9c7812008-09-13 16:45:39 -0400279#define DELL_M6_AMP 2
280static hda_nid_t stac92hd73xx_amp_nids[3] = {
281 0x0b, 0x0c, 0x0e
Matthew Ranostay89385032008-09-11 09:49:39 -0400282};
283
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100284#define STAC92HD73XX_NUM_DMICS 2
285static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
286 0x13, 0x14, 0
287};
288
289#define STAC92HD73_DAC_COUNT 5
290static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
291 0x15, 0x16, 0x17, 0x18, 0x19,
292};
293
294static hda_nid_t stac92hd73xx_mux_nids[4] = {
295 0x28, 0x29, 0x2a, 0x2b,
296};
297
298static hda_nid_t stac92hd73xx_dmux_nids[2] = {
299 0x20, 0x21,
300};
301
Matthew Ranostayd9737752008-09-07 12:03:41 +0200302static hda_nid_t stac92hd73xx_smux_nids[2] = {
303 0x22, 0x23,
304};
305
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200306#define STAC92HD83XXX_NUM_DMICS 2
307static hda_nid_t stac92hd83xxx_dmic_nids[STAC92HD83XXX_NUM_DMICS + 1] = {
308 0x11, 0x12, 0
309};
310
311#define STAC92HD81_DAC_COUNT 2
312#define STAC92HD83_DAC_COUNT 3
313static hda_nid_t stac92hd83xxx_dac_nids[STAC92HD73_DAC_COUNT] = {
314 0x13, 0x14, 0x22,
315};
316
317static hda_nid_t stac92hd83xxx_dmux_nids[2] = {
318 0x17, 0x18,
319};
320
321static hda_nid_t stac92hd83xxx_adc_nids[2] = {
322 0x15, 0x16,
323};
324
325static hda_nid_t stac92hd83xxx_pwr_nids[4] = {
326 0xa, 0xb, 0xd, 0xe,
327};
328
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400329static hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
330 0x1e, 0,
331};
332
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200333static unsigned int stac92hd83xxx_pwr_mapping[4] = {
334 0x03, 0x0c, 0x10, 0x40,
335};
336
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100337static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
338 0x0a, 0x0d, 0x0f
339};
340
Matthew Ranostaye035b842007-11-06 11:53:55 +0100341static hda_nid_t stac92hd71bxx_adc_nids[2] = {
342 0x12, 0x13,
343};
344
345static hda_nid_t stac92hd71bxx_mux_nids[2] = {
346 0x1a, 0x1b
347};
348
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400349static hda_nid_t stac92hd71bxx_dmux_nids[2] = {
350 0x1c, 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100351};
352
Matthew Ranostayd9737752008-09-07 12:03:41 +0200353static hda_nid_t stac92hd71bxx_smux_nids[2] = {
354 0x24, 0x25,
355};
356
Takashi Iwaiaea7bb02008-02-25 18:26:41 +0100357static hda_nid_t stac92hd71bxx_dac_nids[1] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100358 0x10, /*0x11, */
359};
360
361#define STAC92HD71BXX_NUM_DMICS 2
362static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
363 0x18, 0x19, 0
364};
365
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400366static hda_nid_t stac92hd71bxx_slave_dig_outs[2] = {
367 0x22, 0
368};
369
Tobin Davis8e21c342007-01-08 11:04:17 +0100370static hda_nid_t stac925x_adc_nids[1] = {
371 0x03,
372};
373
374static hda_nid_t stac925x_mux_nids[1] = {
375 0x0f,
376};
377
378static hda_nid_t stac925x_dac_nids[1] = {
379 0x02,
380};
381
Takashi Iwaif6e98522007-10-16 14:27:04 +0200382#define STAC925X_NUM_DMICS 1
383static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
384 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200385};
386
Takashi Iwai1697055e2007-12-18 18:05:52 +0100387static hda_nid_t stac925x_dmux_nids[1] = {
388 0x14,
389};
390
Matt2f2f4252005-04-13 14:45:30 +0200391static hda_nid_t stac922x_adc_nids[2] = {
392 0x06, 0x07,
393};
394
395static hda_nid_t stac922x_mux_nids[2] = {
396 0x12, 0x13,
397};
398
Matt Porter3cc08dc2006-01-23 15:27:49 +0100399static hda_nid_t stac927x_adc_nids[3] = {
400 0x07, 0x08, 0x09
401};
402
403static hda_nid_t stac927x_mux_nids[3] = {
404 0x15, 0x16, 0x17
405};
406
Matthew Ranostayd9737752008-09-07 12:03:41 +0200407static hda_nid_t stac927x_smux_nids[1] = {
408 0x21,
409};
410
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100411static hda_nid_t stac927x_dac_nids[6] = {
412 0x02, 0x03, 0x04, 0x05, 0x06, 0
413};
414
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100415static hda_nid_t stac927x_dmux_nids[1] = {
416 0x1b,
417};
418
Matthew Ranostay7f168592007-10-18 17:38:17 +0200419#define STAC927X_NUM_DMICS 2
420static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
421 0x13, 0x14, 0
422};
423
Matthew Ranostay65973632008-09-16 10:39:37 -0400424static const char *stac927x_spdif_labels[5] = {
425 "Digital Playback", "ADAT", "Analog Mux 1",
426 "Analog Mux 2", "Analog Mux 3"
427};
428
Matt Porterf3302a52006-07-31 12:49:34 +0200429static hda_nid_t stac9205_adc_nids[2] = {
430 0x12, 0x13
431};
432
433static hda_nid_t stac9205_mux_nids[2] = {
434 0x19, 0x1a
435};
436
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100437static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100438 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100439};
440
Matthew Ranostayd9737752008-09-07 12:03:41 +0200441static hda_nid_t stac9205_smux_nids[1] = {
442 0x21,
443};
444
Takashi Iwaif6e98522007-10-16 14:27:04 +0200445#define STAC9205_NUM_DMICS 2
446static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
447 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200448};
449
Mattc7d4b2f2005-06-27 14:59:41 +0200450static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200451 0x08, 0x09, 0x0d, 0x0e,
452 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200453};
454
Tobin Davis8e21c342007-01-08 11:04:17 +0100455static hda_nid_t stac925x_pin_nids[8] = {
456 0x07, 0x08, 0x0a, 0x0b,
457 0x0c, 0x0d, 0x10, 0x11,
458};
459
Matt2f2f4252005-04-13 14:45:30 +0200460static hda_nid_t stac922x_pin_nids[10] = {
461 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
462 0x0f, 0x10, 0x11, 0x15, 0x1b,
463};
464
Matthew Ranostaya7662642008-02-21 07:51:14 +0100465static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100466 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
467 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200468 0x14, 0x22, 0x23
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100469};
470
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200471static hda_nid_t stac92hd83xxx_pin_nids[14] = {
472 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
473 0x0f, 0x10, 0x11, 0x12, 0x13,
474 0x1d, 0x1e, 0x1f, 0x20
475};
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400476static hda_nid_t stac92hd71bxx_pin_nids[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100477 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
478 0x0f, 0x14, 0x18, 0x19, 0x1e,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -0400479 0x1f,
Matthew Ranostaye035b842007-11-06 11:53:55 +0100480};
481
Matt Porter3cc08dc2006-01-23 15:27:49 +0100482static hda_nid_t stac927x_pin_nids[14] = {
483 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
484 0x0f, 0x10, 0x11, 0x12, 0x13,
485 0x14, 0x21, 0x22, 0x23,
486};
487
Matt Porterf3302a52006-07-31 12:49:34 +0200488static hda_nid_t stac9205_pin_nids[12] = {
489 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
490 0x0f, 0x14, 0x16, 0x17, 0x18,
491 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200492};
493
Matthew Ranostay89385032008-09-11 09:49:39 -0400494#define stac92xx_amp_volume_info snd_hda_mixer_amp_volume_info
495
496static int stac92xx_amp_volume_get(struct snd_kcontrol *kcontrol,
497 struct snd_ctl_elem_value *ucontrol)
498{
499 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
500 struct sigmatel_spec *spec = codec->spec;
501 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
502
503 kcontrol->private_value ^= get_amp_nid(kcontrol);
504 kcontrol->private_value |= nid;
505
506 return snd_hda_mixer_amp_volume_get(kcontrol, ucontrol);
507}
508
509static int stac92xx_amp_volume_put(struct snd_kcontrol *kcontrol,
510 struct snd_ctl_elem_value *ucontrol)
511{
512 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
513 struct sigmatel_spec *spec = codec->spec;
514 hda_nid_t nid = spec->amp_nids[spec->cur_amux];
515
516 kcontrol->private_value ^= get_amp_nid(kcontrol);
517 kcontrol->private_value |= nid;
518
519 return snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
520}
521
Matt Porter8b657272006-10-26 17:12:59 +0200522static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
523 struct snd_ctl_elem_info *uinfo)
524{
525 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
526 struct sigmatel_spec *spec = codec->spec;
527 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
528}
529
530static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
531 struct snd_ctl_elem_value *ucontrol)
532{
533 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
534 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100535 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200536
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100537 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200538 return 0;
539}
540
541static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
542 struct snd_ctl_elem_value *ucontrol)
543{
544 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
545 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100546 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200547
548 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100549 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200550}
551
Matthew Ranostayd9737752008-09-07 12:03:41 +0200552static int stac92xx_smux_enum_info(struct snd_kcontrol *kcontrol,
553 struct snd_ctl_elem_info *uinfo)
554{
555 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
556 struct sigmatel_spec *spec = codec->spec;
557 return snd_hda_input_mux_info(spec->sinput_mux, uinfo);
558}
559
560static int stac92xx_smux_enum_get(struct snd_kcontrol *kcontrol,
561 struct snd_ctl_elem_value *ucontrol)
562{
563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
564 struct sigmatel_spec *spec = codec->spec;
565 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
566
567 ucontrol->value.enumerated.item[0] = spec->cur_smux[smux_idx];
568 return 0;
569}
570
571static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
572 struct snd_ctl_elem_value *ucontrol)
573{
574 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
575 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400576 struct hda_input_mux *smux = &spec->private_smux;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200577 unsigned int smux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400578 int err, val;
579 hda_nid_t nid;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200580
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400581 err = snd_hda_input_mux_put(codec, spec->sinput_mux, ucontrol,
Matthew Ranostayd9737752008-09-07 12:03:41 +0200582 spec->smux_nids[smux_idx], &spec->cur_smux[smux_idx]);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400583 if (err < 0)
584 return err;
585
586 if (spec->spdif_mute) {
587 if (smux_idx == 0)
588 nid = spec->multiout.dig_out_nid;
589 else
590 nid = codec->slave_dig_outs[smux_idx - 1];
591 if (spec->cur_smux[smux_idx] == smux->num_items - 1)
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100592 val = HDA_AMP_MUTE;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400593 else
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100594 val = 0;
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400595 /* un/mute SPDIF out */
Takashi Iwaic9b46f92008-12-01 11:42:09 +0100596 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
597 HDA_AMP_MUTE, val);
Matthew Ranostay00ef50c2008-09-27 18:13:47 -0400598 }
599 return 0;
Matthew Ranostayd9737752008-09-07 12:03:41 +0200600}
601
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100602static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200603{
604 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
605 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200606 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200607}
608
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100609static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200610{
611 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
612 struct sigmatel_spec *spec = codec->spec;
613 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
614
615 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
616 return 0;
617}
618
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100619static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200620{
621 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
622 struct sigmatel_spec *spec = codec->spec;
623 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
624
Mattc7d4b2f2005-06-27 14:59:41 +0200625 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200626 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
627}
628
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100629static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
630 struct snd_ctl_elem_info *uinfo)
631{
632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
633 struct sigmatel_spec *spec = codec->spec;
634 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
635}
636
637static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
638 struct snd_ctl_elem_value *ucontrol)
639{
640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
641 struct sigmatel_spec *spec = codec->spec;
642
643 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
644 return 0;
645}
646
647static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
648 struct snd_ctl_elem_value *ucontrol)
649{
650 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
651 struct sigmatel_spec *spec = codec->spec;
652
653 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
654 spec->mono_nid, &spec->cur_mmux);
655}
656
Matthew Ranostay89385032008-09-11 09:49:39 -0400657static int stac92xx_amp_mux_enum_info(struct snd_kcontrol *kcontrol,
658 struct snd_ctl_elem_info *uinfo)
659{
660 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
661 struct sigmatel_spec *spec = codec->spec;
662 return snd_hda_input_mux_info(spec->amp_mux, uinfo);
663}
664
665static int stac92xx_amp_mux_enum_get(struct snd_kcontrol *kcontrol,
666 struct snd_ctl_elem_value *ucontrol)
667{
668 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
669 struct sigmatel_spec *spec = codec->spec;
670
671 ucontrol->value.enumerated.item[0] = spec->cur_amux;
672 return 0;
673}
674
675static int stac92xx_amp_mux_enum_put(struct snd_kcontrol *kcontrol,
676 struct snd_ctl_elem_value *ucontrol)
677{
678 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
679 struct sigmatel_spec *spec = codec->spec;
680 struct snd_kcontrol *ctl =
681 snd_hda_find_mixer_ctl(codec, "Amp Capture Volume");
682 if (!ctl)
683 return -EINVAL;
684
685 snd_ctl_notify(codec->bus->card, SNDRV_CTL_EVENT_MASK_VALUE |
686 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
687
688 return snd_hda_input_mux_put(codec, spec->amp_mux, ucontrol,
689 0, &spec->cur_amux);
690}
691
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200692#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
693
694static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
695 struct snd_ctl_elem_value *ucontrol)
696{
697 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100698 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200699 struct sigmatel_spec *spec = codec->spec;
700
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100701 ucontrol->value.integer.value[0] = !!(spec->aloopback &
702 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200703 return 0;
704}
705
706static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
707 struct snd_ctl_elem_value *ucontrol)
708{
709 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
710 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100711 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200712 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100713 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200714
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100715 idx_val = spec->aloopback_mask << idx;
716 if (ucontrol->value.integer.value[0])
717 val = spec->aloopback | idx_val;
718 else
719 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100720 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200721 return 0;
722
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100723 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200724
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100725 /* Only return the bits defined by the shift value of the
726 * first two bytes of the mask
727 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200728 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100729 kcontrol->private_value & 0xFFFF, 0x0);
730 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200731
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100732 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200733 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100734 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200735 } else {
736 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100737 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200738 }
739
740 snd_hda_codec_write_cache(codec, codec->afg, 0,
741 kcontrol->private_value >> 16, dac_mode);
742
743 return 1;
744}
745
Mattc7d4b2f2005-06-27 14:59:41 +0200746static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200747 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200748 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200749 {}
750};
751
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200752static struct hda_verb stac9200_eapd_init[] = {
753 /* set dac0mux for dac converter */
754 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
755 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
756 {}
757};
758
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100759static struct hda_verb stac92hd73xx_6ch_core_init[] = {
760 /* set master volume and direct control */
761 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
762 /* setup audio connections */
763 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
764 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
765 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
766 /* setup adcs to point to mixer */
767 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
768 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100769 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
770 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
771 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
772 /* setup import muxs */
773 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
774 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
775 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
776 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
777 {}
778};
779
Matthew Ranostayd654a662008-03-14 08:46:51 +0100780static struct hda_verb dell_eq_core_init[] = {
781 /* set master volume to max value without distortion
782 * and direct control */
783 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
784 /* setup audio connections */
785 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
Matthew Ranostayf7cf0a72008-09-13 10:36:58 -0400786 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x02},
787 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostayd654a662008-03-14 08:46:51 +0100788 /* setup adcs to point to mixer */
789 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
790 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
791 /* setup import muxs */
792 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
793 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
794 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
795 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
796 {}
797};
798
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100799static struct hda_verb dell_m6_core_init[] = {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -0500800 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100801 /* setup audio connections */
Matthew Ranostay7747ecc2008-03-10 11:30:04 +0100802 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
803 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay52fe0f92008-02-29 12:08:20 +0100804 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
805 /* setup adcs to point to mixer */
806 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
807 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
808 /* setup import muxs */
809 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
810 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
811 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
812 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
813 {}
814};
815
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100816static struct hda_verb stac92hd73xx_8ch_core_init[] = {
817 /* set master volume and direct control */
818 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
819 /* setup audio connections */
820 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
821 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
822 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
823 /* connect hp ports to dac3 */
824 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
825 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
826 /* setup adcs to point to mixer */
827 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
828 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100829 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
830 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
831 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
832 /* setup import muxs */
833 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
834 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
835 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
836 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
837 {}
838};
839
840static struct hda_verb stac92hd73xx_10ch_core_init[] = {
841 /* set master volume and direct control */
842 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
843 /* setup audio connections */
844 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
845 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
846 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
847 /* dac3 is connected to import3 mux */
848 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
849 /* connect hp ports to dac4 */
850 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
851 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
852 /* setup adcs to point to mixer */
853 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
854 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100855 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
856 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
857 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
858 /* setup import muxs */
859 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
860 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
861 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
862 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
863 {}
864};
865
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200866static struct hda_verb stac92hd83xxx_core_init[] = {
867 /* start of config #1 */
868 { 0xe, AC_VERB_SET_CONNECT_SEL, 0x3},
869
870 /* start of config #2 */
871 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0},
872 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0},
873 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1},
874
875 /* power state controls amps */
876 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
877};
878
Matthew Ranostaye035b842007-11-06 11:53:55 +0100879static struct hda_verb stac92hd71bxx_core_init[] = {
880 /* set master volume and direct control */
881 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
882 /* connect headphone jack to dac1 */
883 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100884 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
885 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
886 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
887 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100888};
889
Matthew Ranostay4b33c762008-10-10 09:07:23 -0400890#define HD_DISABLE_PORTF 2
Matthew Ranostay541eee82007-12-14 12:08:04 +0100891static struct hda_verb stac92hd71bxx_analog_core_init[] = {
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200892 /* start of config #1 */
893
894 /* connect port 0f to audio mixer */
895 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200896 /* unmute right and left channels for node 0x0f */
897 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
898 /* start of config #2 */
899
Matthew Ranostay541eee82007-12-14 12:08:04 +0100900 /* set master volume and direct control */
901 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
902 /* connect headphone jack to dac1 */
903 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostayaafc4412008-06-13 18:04:33 +0200904 /* unmute right and left channels for nodes 0x0a, 0xd */
Matthew Ranostaye035b842007-11-06 11:53:55 +0100905 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
906 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100907 {}
908};
909
Tobin Davis8e21c342007-01-08 11:04:17 +0100910static struct hda_verb stac925x_core_init[] = {
911 /* set dac0mux for dac converter */
912 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
913 {}
914};
915
Mattc7d4b2f2005-06-27 14:59:41 +0200916static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200917 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200918 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200919 {}
920};
921
Tobin Davis93ed1502006-09-01 21:03:12 +0200922static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200923 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200924 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200925 /* unmute node 0x1b */
926 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
927 /* select node 0x03 as DAC */
928 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
929 {}
930};
931
Matt Porter3cc08dc2006-01-23 15:27:49 +0100932static struct hda_verb stac927x_core_init[] = {
933 /* set master volume and direct control */
934 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostay1cd22242008-07-18 18:20:52 +0200935 /* enable analog pc beep path */
936 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porter3cc08dc2006-01-23 15:27:49 +0100937 {}
938};
939
Matt Porterf3302a52006-07-31 12:49:34 +0200940static struct hda_verb stac9205_core_init[] = {
941 /* set master volume and direct control */
942 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +0200943 /* enable analog pc beep path */
944 { 0x01, AC_VERB_SET_DIGI_CONVERT_2, 1 << 5},
Matt Porterf3302a52006-07-31 12:49:34 +0200945 {}
946};
947
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100948#define STAC_MONO_MUX \
949 { \
950 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
951 .name = "Mono Mux", \
952 .count = 1, \
953 .info = stac92xx_mono_mux_enum_info, \
954 .get = stac92xx_mono_mux_enum_get, \
955 .put = stac92xx_mono_mux_enum_put, \
956 }
957
Matthew Ranostay89385032008-09-11 09:49:39 -0400958#define STAC_AMP_MUX \
959 { \
960 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
961 .name = "Amp Selector Capture Switch", \
962 .count = 1, \
963 .info = stac92xx_amp_mux_enum_info, \
964 .get = stac92xx_amp_mux_enum_get, \
965 .put = stac92xx_amp_mux_enum_put, \
966 }
967
968#define STAC_AMP_VOL(xname, nid, chs, idx, dir) \
969 { \
970 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
971 .name = xname, \
972 .index = 0, \
973 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
974 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
975 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
976 .info = stac92xx_amp_volume_info, \
977 .get = stac92xx_amp_volume_get, \
978 .put = stac92xx_amp_volume_put, \
979 .tlv = { .c = snd_hda_mixer_amp_tlv }, \
980 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
981 }
982
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200983#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200984 { \
985 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
986 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200987 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200988 .info = stac92xx_mux_enum_info, \
989 .get = stac92xx_mux_enum_get, \
990 .put = stac92xx_mux_enum_put, \
991 }
992
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100993#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200994 { \
995 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
996 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100997 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200998 .info = stac92xx_aloopback_info, \
999 .get = stac92xx_aloopback_get, \
1000 .put = stac92xx_aloopback_put, \
1001 .private_value = verb_read | (verb_write << 16), \
1002 }
1003
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001004static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +02001005 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
1006 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001007 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +02001008 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
1009 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +02001010 { } /* end */
1011};
1012
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001013#define DELL_M6_MIXER 6
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001014static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04001015 /* start of config #1 */
1016 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1017 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1018
1019 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1020 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1021
1022 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1023 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1024
1025 /* start of config #2 */
1026 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1027 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1028
1029 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1030 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1031
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001032 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1033
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001034 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1035 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1036
1037 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1038 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1039
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001040 { } /* end */
1041};
1042
1043static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001044 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1045
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001046 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1047 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1048
1049 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1050 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1051
1052 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1053 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1054
1055 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1056 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1057
1058 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1059 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1060
1061 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1062 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1063
1064 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1065 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1066 { } /* end */
1067};
1068
1069static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001070 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1071
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001072 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1073 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1074
1075 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
1076 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
1077
1078 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
1079 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
1080
1081 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
1082 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
1083
1084 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
1085 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
1086
1087 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1088 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1089
1090 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
1091 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
1092 { } /* end */
1093};
1094
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001095
1096static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1097 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_OUTPUT),
1098 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_OUTPUT),
1099
1100 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_OUTPUT),
1101 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_OUTPUT),
1102
1103 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x1b, 0, HDA_INPUT),
1104 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x1b, 0, HDA_INPUT),
1105
1106 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x1b, 0x1, HDA_INPUT),
1107 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x1b, 0x1, HDA_INPUT),
1108
1109 HDA_CODEC_VOLUME("Front Mic Capture Volume", 0x1b, 0x2, HDA_INPUT),
1110 HDA_CODEC_MUTE("Front Mic Capture Switch", 0x1b, 0x2, HDA_INPUT),
1111
1112 HDA_CODEC_VOLUME("Line In Capture Volume", 0x1b, 0x3, HDA_INPUT),
1113 HDA_CODEC_MUTE("Line In Capture Switch", 0x1b, 0x3, HDA_INPUT),
1114
1115 /*
1116 HDA_CODEC_VOLUME("Mic Capture Volume", 0x1b, 0x4, HDA_INPUT),
1117 HDA_CODEC_MUTE("Mic Capture Switch", 0x1b 0x4, HDA_INPUT),
1118 */
1119 { } /* end */
1120};
1121
Matthew Ranostay541eee82007-12-14 12:08:04 +01001122static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001123 STAC_INPUT_SOURCE(2),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001124 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001125
Matthew Ranostay9b359472007-11-07 13:03:12 +01001126 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1127 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay9b359472007-11-07 13:03:12 +01001128
1129 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1130 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001131 /* analog pc-beep replaced with digital beep support */
1132 /*
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001133 HDA_CODEC_VOLUME("PC Beep Volume", 0x17, 0x2, HDA_INPUT),
1134 HDA_CODEC_MUTE("PC Beep Switch", 0x17, 0x2, HDA_INPUT),
Matthew Ranostay1cd22242008-07-18 18:20:52 +02001135 */
Matthew Ranostayf7c5dda2008-07-10 17:49:11 +02001136
Matthew Ranostay687cb982008-10-11 13:52:43 -04001137 HDA_CODEC_MUTE("Import0 Mux Capture Switch", 0x17, 0x0, HDA_INPUT),
1138 HDA_CODEC_VOLUME("Import0 Mux Capture Volume", 0x17, 0x0, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001139
Matthew Ranostay687cb982008-10-11 13:52:43 -04001140 HDA_CODEC_MUTE("Import1 Mux Capture Switch", 0x17, 0x1, HDA_INPUT),
1141 HDA_CODEC_VOLUME("Import1 Mux Capture Volume", 0x17, 0x1, HDA_INPUT),
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001142
1143 HDA_CODEC_MUTE("DAC0 Capture Switch", 0x17, 0x3, HDA_INPUT),
1144 HDA_CODEC_VOLUME("DAC0 Capture Volume", 0x17, 0x3, HDA_INPUT),
1145
1146 HDA_CODEC_MUTE("DAC1 Capture Switch", 0x17, 0x4, HDA_INPUT),
1147 HDA_CODEC_VOLUME("DAC1 Capture Volume", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001148 { } /* end */
1149};
1150
Matthew Ranostay541eee82007-12-14 12:08:04 +01001151static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +01001152 STAC_INPUT_SOURCE(2),
1153 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1154
Matthew Ranostay541eee82007-12-14 12:08:04 +01001155 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1156 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001157
1158 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
1159 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
Matthew Ranostay541eee82007-12-14 12:08:04 +01001160 { } /* end */
1161};
1162
Tobin Davis8e21c342007-01-08 11:04:17 +01001163static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001164 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +01001165 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
Mauro Carvalho Chehab587755f2008-05-25 18:20:06 +02001166 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
Tobin Davis8e21c342007-01-08 11:04:17 +01001167 { } /* end */
1168};
1169
Takashi Iwaid1d985f2006-11-23 19:27:12 +01001170static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001171 STAC_INPUT_SOURCE(2),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001172 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001173
1174 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1175 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001176
1177 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
1178 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001179 { } /* end */
1180};
1181
1182/* This needs to be generated dynamically based on sequence */
1183static struct snd_kcontrol_new stac922x_mixer[] = {
1184 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001185 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1186 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001187
1188 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
1189 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001190 { } /* end */
1191};
1192
1193
1194static struct snd_kcontrol_new stac927x_mixer[] = {
1195 STAC_INPUT_SOURCE(3),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001196 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001197
1198 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1199 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001200
1201 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
1202 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001203
1204 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
1205 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +02001206 { } /* end */
1207};
1208
Takashi Iwai1697055e2007-12-18 18:05:52 +01001209static struct snd_kcontrol_new stac_dmux_mixer = {
1210 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1211 .name = "Digital Input Source",
1212 /* count set later */
1213 .info = stac92xx_dmux_enum_info,
1214 .get = stac92xx_dmux_enum_get,
1215 .put = stac92xx_dmux_enum_put,
1216};
1217
Matthew Ranostayd9737752008-09-07 12:03:41 +02001218static struct snd_kcontrol_new stac_smux_mixer = {
1219 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
Matthew Ranostaye3487972008-09-08 11:36:59 -04001220 .name = "IEC958 Playback Source",
Matthew Ranostayd9737752008-09-07 12:03:41 +02001221 /* count set later */
1222 .info = stac92xx_smux_enum_info,
1223 .get = stac92xx_smux_enum_get,
1224 .put = stac92xx_smux_enum_put,
1225};
1226
Takashi Iwai2134ea42008-01-10 16:53:55 +01001227static const char *slave_vols[] = {
1228 "Front Playback Volume",
1229 "Surround Playback Volume",
1230 "Center Playback Volume",
1231 "LFE Playback Volume",
1232 "Side Playback Volume",
1233 "Headphone Playback Volume",
1234 "Headphone Playback Volume",
1235 "Speaker Playback Volume",
1236 "External Speaker Playback Volume",
1237 "Speaker2 Playback Volume",
1238 NULL
1239};
1240
1241static const char *slave_sws[] = {
1242 "Front Playback Switch",
1243 "Surround Playback Switch",
1244 "Center Playback Switch",
1245 "LFE Playback Switch",
1246 "Side Playback Switch",
1247 "Headphone Playback Switch",
1248 "Headphone Playback Switch",
1249 "Speaker Playback Switch",
1250 "External Speaker Playback Switch",
1251 "Speaker2 Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001252 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001253 NULL
1254};
1255
Takashi Iwai603c4012008-07-30 15:01:44 +02001256static void stac92xx_free_kctls(struct hda_codec *codec);
Takashi Iwaie4973e12008-11-18 09:32:42 +01001257static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
Takashi Iwai603c4012008-07-30 15:01:44 +02001258
Matt2f2f4252005-04-13 14:45:30 +02001259static int stac92xx_build_controls(struct hda_codec *codec)
1260{
1261 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaie4973e12008-11-18 09:32:42 +01001262 struct auto_pin_cfg *cfg = &spec->autocfg;
1263 hda_nid_t nid;
Matt2f2f4252005-04-13 14:45:30 +02001264 int err;
Mattc7d4b2f2005-06-27 14:59:41 +02001265 int i;
Matt2f2f4252005-04-13 14:45:30 +02001266
1267 err = snd_hda_add_new_ctls(codec, spec->mixer);
1268 if (err < 0)
1269 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02001270
1271 for (i = 0; i < spec->num_mixers; i++) {
1272 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1273 if (err < 0)
1274 return err;
1275 }
Takashi Iwai1697055e2007-12-18 18:05:52 +01001276 if (spec->num_dmuxes > 0) {
1277 stac_dmux_mixer.count = spec->num_dmuxes;
Takashi Iwaid13bd412008-07-30 15:01:45 +02001278 err = snd_hda_ctl_add(codec,
Takashi Iwai1697055e2007-12-18 18:05:52 +01001279 snd_ctl_new1(&stac_dmux_mixer, codec));
1280 if (err < 0)
1281 return err;
1282 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001283 if (spec->num_smuxes > 0) {
Matthew Ranostay00ef50c2008-09-27 18:13:47 -04001284 int wcaps = get_wcaps(codec, spec->multiout.dig_out_nid);
1285 struct hda_input_mux *smux = &spec->private_smux;
1286 /* check for mute support on SPDIF out */
1287 if (wcaps & AC_WCAP_OUT_AMP) {
1288 smux->items[smux->num_items].label = "Off";
1289 smux->items[smux->num_items].index = 0;
1290 smux->num_items++;
1291 spec->spdif_mute = 1;
1292 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02001293 stac_smux_mixer.count = spec->num_smuxes;
1294 err = snd_ctl_add(codec->bus->card,
1295 snd_ctl_new1(&stac_smux_mixer, codec));
1296 if (err < 0)
1297 return err;
1298 }
Mattc7d4b2f2005-06-27 14:59:41 +02001299
Mattdabbed62005-06-14 10:19:34 +02001300 if (spec->multiout.dig_out_nid) {
1301 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
1302 if (err < 0)
1303 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +01001304 err = snd_hda_create_spdif_share_sw(codec,
1305 &spec->multiout);
1306 if (err < 0)
1307 return err;
1308 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +02001309 }
Harvey Harrisonda74ae32008-10-21 20:28:04 -07001310 if (spec->dig_in_nid && !(spec->gpio_dir & 0x01)) {
Mattdabbed62005-06-14 10:19:34 +02001311 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1312 if (err < 0)
1313 return err;
1314 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001315
1316 /* if we have no master control, let's create it */
1317 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001318 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001319 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001320 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001321 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001322 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001323 if (err < 0)
1324 return err;
1325 }
1326 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
1327 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1328 NULL, slave_sws);
1329 if (err < 0)
1330 return err;
1331 }
1332
Takashi Iwai603c4012008-07-30 15:01:44 +02001333 stac92xx_free_kctls(codec); /* no longer needed */
Takashi Iwaie4973e12008-11-18 09:32:42 +01001334
1335 /* create jack input elements */
1336 if (spec->hp_detect) {
1337 for (i = 0; i < cfg->hp_outs; i++) {
1338 int type = SND_JACK_HEADPHONE;
1339 nid = cfg->hp_pins[i];
1340 /* jack detection */
1341 if (cfg->hp_outs == i)
1342 type |= SND_JACK_LINEOUT;
1343 err = stac92xx_add_jack(codec, nid, type);
1344 if (err < 0)
1345 return err;
1346 }
1347 }
1348 for (i = 0; i < cfg->line_outs; i++) {
1349 err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1350 SND_JACK_LINEOUT);
1351 if (err < 0)
1352 return err;
1353 }
1354 for (i = 0; i < AUTO_PIN_LAST; i++) {
1355 nid = cfg->input_pins[i];
1356 if (nid) {
1357 err = stac92xx_add_jack(codec, nid,
1358 SND_JACK_MICROPHONE);
1359 if (err < 0)
1360 return err;
1361 }
1362 }
1363
Mattdabbed62005-06-14 10:19:34 +02001364 return 0;
Matt2f2f4252005-04-13 14:45:30 +02001365}
1366
Matt Porter403d1942005-11-29 15:00:51 +01001367static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +02001368 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +02001369 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
1370};
1371
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001372/*
1373 STAC 9200 pin configs for
1374 102801A8
1375 102801DE
1376 102801E8
1377*/
1378static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001379 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
1380 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001381};
1382
1383/*
1384 STAC 9200 pin configs for
1385 102801C0
1386 102801C1
1387*/
1388static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001389 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1390 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001391};
1392
1393/*
1394 STAC 9200 pin configs for
1395 102801C4 (Dell Dimension E310)
1396 102801C5
1397 102801C7
1398 102801D9
1399 102801DA
1400 102801E3
1401*/
1402static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001403 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
1404 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001405};
1406
1407
1408/*
1409 STAC 9200-32 pin configs for
1410 102801B5 (Dell Inspiron 630m)
1411 102801D8 (Dell Inspiron 640m)
1412*/
1413static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001414 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
1415 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001416};
1417
1418/*
1419 STAC 9200-32 pin configs for
1420 102801C2 (Dell Latitude D620)
1421 102801C8
1422 102801CC (Dell Latitude D820)
1423 102801D4
1424 102801D6
1425*/
1426static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001427 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1428 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001429};
1430
1431/*
1432 STAC 9200-32 pin configs for
1433 102801CE (Dell XPS M1710)
1434 102801CF (Dell Precision M90)
1435*/
1436static unsigned int dell9200_m23_pin_configs[8] = {
1437 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1438 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1439};
1440
1441/*
1442 STAC 9200-32 pin configs for
1443 102801C9
1444 102801CA
1445 102801CB (Dell Latitude 120L)
1446 102801D3
1447*/
1448static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001449 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1450 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001451};
1452
1453/*
1454 STAC 9200-32 pin configs for
1455 102801BD (Dell Inspiron E1505n)
1456 102801EE
1457 102801EF
1458*/
1459static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001460 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1461 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001462};
1463
1464/*
1465 STAC 9200-32 pin configs for
1466 102801F5 (Dell Inspiron 1501)
1467 102801F6
1468*/
1469static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001470 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1471 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001472};
1473
1474/*
1475 STAC 9200-32
1476 102801CD (Dell Inspiron E1705/9400)
1477*/
1478static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001479 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1480 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001481};
1482
Tobin Davisbf277782008-02-03 20:31:47 +01001483static unsigned int oqo9200_pin_configs[8] = {
1484 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1485 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1486};
1487
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001488
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001489static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1490 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001491 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001492 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1493 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1494 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1495 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1496 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1497 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1498 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1499 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1500 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1501 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Takashi Iwai117f2572008-03-18 09:53:23 +01001502 [STAC_9200_PANASONIC] = ref9200_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001503};
1504
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001505static const char *stac9200_models[STAC_9200_MODELS] = {
1506 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001507 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001508 [STAC_9200_DELL_D21] = "dell-d21",
1509 [STAC_9200_DELL_D22] = "dell-d22",
1510 [STAC_9200_DELL_D23] = "dell-d23",
1511 [STAC_9200_DELL_M21] = "dell-m21",
1512 [STAC_9200_DELL_M22] = "dell-m22",
1513 [STAC_9200_DELL_M23] = "dell-m23",
1514 [STAC_9200_DELL_M24] = "dell-m24",
1515 [STAC_9200_DELL_M25] = "dell-m25",
1516 [STAC_9200_DELL_M26] = "dell-m26",
1517 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001518 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwai117f2572008-03-18 09:53:23 +01001519 [STAC_9200_PANASONIC] = "panasonic",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001520};
1521
1522static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1523 /* SigmaTel reference board */
1524 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1525 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001526 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001527 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1528 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001529 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001530 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1531 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1532 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1533 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1534 "unknown Dell", STAC_9200_DELL_D22),
1535 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1536 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001537 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001538 "Dell Latitude D620", STAC_9200_DELL_M22),
1539 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1540 "unknown Dell", STAC_9200_DELL_D23),
1541 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1542 "unknown Dell", STAC_9200_DELL_D23),
1543 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1544 "unknown Dell", STAC_9200_DELL_M22),
1545 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1546 "unknown Dell", STAC_9200_DELL_M24),
1547 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1548 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001549 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001550 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001551 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001552 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001553 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001554 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001555 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001556 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001557 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001558 "Dell Precision M90", STAC_9200_DELL_M23),
1559 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1560 "unknown Dell", STAC_9200_DELL_M22),
1561 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1562 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001563 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001564 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001565 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001566 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1567 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1568 "unknown Dell", STAC_9200_DELL_D23),
1569 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1570 "unknown Dell", STAC_9200_DELL_D23),
1571 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1572 "unknown Dell", STAC_9200_DELL_D21),
1573 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1574 "unknown Dell", STAC_9200_DELL_D23),
1575 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1576 "unknown Dell", STAC_9200_DELL_D21),
1577 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1578 "unknown Dell", STAC_9200_DELL_M25),
1579 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1580 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001581 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001582 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1583 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1584 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001585 /* Panasonic */
Takashi Iwai117f2572008-03-18 09:53:23 +01001586 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001587 /* Gateway machines needs EAPD to be set on resume */
1588 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1589 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1590 STAC_9200_GATEWAY),
1591 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1592 STAC_9200_GATEWAY),
Tobin Davisbf277782008-02-03 20:31:47 +01001593 /* OQO Mobile */
1594 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001595 {} /* terminator */
1596};
1597
Tobin Davis8e21c342007-01-08 11:04:17 +01001598static unsigned int ref925x_pin_configs[8] = {
1599 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001600 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001601};
1602
1603static unsigned int stac925x_MA6_pin_configs[8] = {
1604 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1605 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
1606};
1607
Tobin Davis2c11f952007-05-17 09:36:34 +02001608static unsigned int stac925x_PA6_pin_configs[8] = {
1609 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1610 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
1611};
1612
Tobin Davis8e21c342007-01-08 11:04:17 +01001613static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +02001614 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
1615 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001616};
1617
1618static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1619 [STAC_REF] = ref925x_pin_configs,
1620 [STAC_M2_2] = stac925xM2_2_pin_configs,
1621 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +02001622 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001623};
1624
1625static const char *stac925x_models[STAC_925x_MODELS] = {
1626 [STAC_REF] = "ref",
1627 [STAC_M2_2] = "m2-2",
1628 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +02001629 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001630};
1631
1632static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1633 /* SigmaTel reference board */
1634 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001635 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +01001636 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
1637 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
1638 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +02001639 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +01001640 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
1641 {} /* terminator */
1642};
1643
Matthew Ranostaya7662642008-02-21 07:51:14 +01001644static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001645 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1646 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1647 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001648 0x01452050,
1649};
1650
1651static unsigned int dell_m6_pin_configs[13] = {
1652 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02001653 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001654 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1655 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001656};
1657
1658static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001659 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001660 [STAC_DELL_M6_AMIC] = dell_m6_pin_configs,
1661 [STAC_DELL_M6_DMIC] = dell_m6_pin_configs,
1662 [STAC_DELL_M6_BOTH] = dell_m6_pin_configs,
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001663 [STAC_DELL_EQ] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001664};
1665
1666static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1667 [STAC_92HD73XX_REF] = "ref",
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001668 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
1669 [STAC_DELL_M6_DMIC] = "dell-m6-dmic",
1670 [STAC_DELL_M6_BOTH] = "dell-m6",
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05001671 [STAC_DELL_EQ] = "dell-eq",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001672};
1673
1674static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1675 /* SigmaTel reference board */
1676 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001677 "DFI LanParty", STAC_92HD73XX_REF),
1678 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001679 "Dell Studio 1535", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001680 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001681 "unknown Dell", STAC_DELL_M6_DMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001682 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001683 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001684 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001685 "unknown Dell", STAC_DELL_M6_BOTH),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001686 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001687 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001688 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001689 "unknown Dell", STAC_DELL_M6_AMIC),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001690 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001691 "unknown Dell", STAC_DELL_M6_DMIC),
1692 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0272,
1693 "unknown Dell", STAC_DELL_M6_DMIC),
Takashi Iwaib0fc5e02008-11-21 08:37:03 +01001694 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x029f,
Takashi Iwai661cd8f2008-11-25 15:18:29 +01001695 "Dell Studio 1537", STAC_DELL_M6_DMIC),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001696 {} /* terminator */
1697};
1698
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02001699static unsigned int ref92hd83xxx_pin_configs[14] = {
1700 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1701 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1702 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1703 0x01451160, 0x98560170,
1704};
1705
1706static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1707 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1708};
1709
1710static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1711 [STAC_92HD83XXX_REF] = "ref",
1712};
1713
1714static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1715 /* SigmaTel reference board */
1716 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1717 "DFI LanParty", STAC_92HD71BXX_REF),
1718};
1719
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001720static unsigned int ref92hd71bxx_pin_configs[11] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +01001721 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostay4b33c762008-10-10 09:07:23 -04001722 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001723 0x90a000f0, 0x01452050, 0x01452050,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001724};
1725
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001726static unsigned int dell_m4_1_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001727 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
Matthew Ranostay07bcb312008-03-20 12:10:57 +01001728 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001729 0x40f000f0, 0x4f0000f0, 0x4f0000f0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001730};
1731
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001732static unsigned int dell_m4_2_pin_configs[11] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001733 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1734 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04001735 0x40f000f0, 0x044413b0, 0x044413b0,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001736};
1737
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001738static unsigned int dell_m4_3_pin_configs[11] = {
1739 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1740 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1741 0x40f000f0, 0x044413b0, 0x044413b0,
1742};
1743
Matthew Ranostaye035b842007-11-06 11:53:55 +01001744static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1745 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001746 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1747 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001748 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001749 [STAC_HP_M4] = NULL,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001750};
1751
1752static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1753 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001754 [STAC_DELL_M4_1] = "dell-m4-1",
1755 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001756 [STAC_DELL_M4_3] = "dell-m4-3",
Matthew Ranostay6a14f582008-09-12 12:02:30 -04001757 [STAC_HP_M4] = "hp-m4",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001758};
1759
1760static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1761 /* SigmaTel reference board */
1762 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1763 "DFI LanParty", STAC_92HD71BXX_REF),
Takashi Iwai80bf2722008-11-18 10:48:41 +01001764 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f2,
1765 "HP dv5", STAC_HP_M4),
1766 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4,
1767 "HP dv7", STAC_HP_M4),
Matthew Ranostay9a9e2352008-09-26 10:37:03 -04001768 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1769 "unknown HP", STAC_HP_M4),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001770 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1771 "unknown Dell", STAC_DELL_M4_1),
1772 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1773 "unknown Dell", STAC_DELL_M4_1),
1774 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1775 "unknown Dell", STAC_DELL_M4_1),
1776 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1777 "unknown Dell", STAC_DELL_M4_1),
1778 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1779 "unknown Dell", STAC_DELL_M4_1),
1780 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1781 "unknown Dell", STAC_DELL_M4_1),
1782 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1783 "unknown Dell", STAC_DELL_M4_1),
1784 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1785 "unknown Dell", STAC_DELL_M4_2),
1786 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1787 "unknown Dell", STAC_DELL_M4_2),
1788 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1789 "unknown Dell", STAC_DELL_M4_2),
1790 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1791 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05001792 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02aa,
1793 "unknown Dell", STAC_DELL_M4_3),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001794 {} /* terminator */
1795};
1796
Matt Porter403d1942005-11-29 15:00:51 +01001797static unsigned int ref922x_pin_configs[10] = {
1798 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1799 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001800 0x40000100, 0x40000100,
1801};
1802
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001803/*
1804 STAC 922X pin configs for
1805 102801A7
1806 102801AB
1807 102801A9
1808 102801D1
1809 102801D2
1810*/
1811static unsigned int dell_922x_d81_pin_configs[10] = {
1812 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1813 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1814 0x01813122, 0x400001f2,
1815};
1816
1817/*
1818 STAC 922X pin configs for
1819 102801AC
1820 102801D0
1821*/
1822static unsigned int dell_922x_d82_pin_configs[10] = {
1823 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1824 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1825 0x01813122, 0x400001f1,
1826};
1827
1828/*
1829 STAC 922X pin configs for
1830 102801BF
1831*/
1832static unsigned int dell_922x_m81_pin_configs[10] = {
1833 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1834 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1835 0x40C003f1, 0x405003f0,
1836};
1837
1838/*
1839 STAC 9221 A1 pin configs for
1840 102801D7 (Dell XPS M1210)
1841*/
1842static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001843 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1844 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001845 0x508003f3, 0x405003f4,
1846};
1847
Matt Porter403d1942005-11-29 15:00:51 +01001848static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001849 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001850 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1851 0x02a19120, 0x40000100,
1852};
1853
1854static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001855 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1856 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001857 0x02a19320, 0x40000100,
1858};
1859
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001860static unsigned int intel_mac_v1_pin_configs[10] = {
1861 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1862 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001863 0x400000fc, 0x400000fb,
1864};
1865
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001866static unsigned int intel_mac_v2_pin_configs[10] = {
1867 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1868 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001869 0x400000fc, 0x400000fb,
1870};
1871
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001872static unsigned int intel_mac_v3_pin_configs[10] = {
1873 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1874 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1875 0x400000fc, 0x400000fb,
1876};
1877
1878static unsigned int intel_mac_v4_pin_configs[10] = {
1879 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1880 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1881 0x400000fc, 0x400000fb,
1882};
1883
1884static unsigned int intel_mac_v5_pin_configs[10] = {
1885 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1886 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1887 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001888};
1889
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001890static unsigned int ecs202_pin_configs[10] = {
1891 0x0221401f, 0x02a19020, 0x01a19020, 0x01114010,
1892 0x408000f0, 0x01813022, 0x074510a0, 0x40c400f1,
1893 0x9037012e, 0x40e000f2,
1894};
Takashi Iwai76c08822007-06-19 12:17:42 +02001895
Takashi Iwai19039bd2006-06-28 15:52:16 +02001896static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001897 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001898 [STAC_D945GTP3] = d945gtp3_pin_configs,
1899 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001900 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1901 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1902 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1903 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1904 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Nicolas Boichat536319a2008-07-21 22:18:01 +08001905 [STAC_INTEL_MAC_AUTO] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001906 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001907 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1908 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1909 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1910 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1911 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1912 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001913 [STAC_ECS_202] = ecs202_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001914 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1915 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1916 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1917 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001918};
1919
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001920static const char *stac922x_models[STAC_922X_MODELS] = {
1921 [STAC_D945_REF] = "ref",
1922 [STAC_D945GTP5] = "5stack",
1923 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001924 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1925 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1926 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1927 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1928 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Nicolas Boichat536319a2008-07-21 22:18:01 +08001929 [STAC_INTEL_MAC_AUTO] = "intel-mac-auto",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001930 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001931 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001932 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001933 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1934 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001935 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001936 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03001937 [STAC_ECS_202] = "ecs202",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001938 [STAC_922X_DELL_D81] = "dell-d81",
1939 [STAC_922X_DELL_D82] = "dell-d82",
1940 [STAC_922X_DELL_M81] = "dell-m81",
1941 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001942};
1943
1944static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1945 /* SigmaTel reference board */
1946 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1947 "DFI LanParty", STAC_D945_REF),
1948 /* Intel 945G based systems */
1949 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1950 "Intel D945G", STAC_D945GTP3),
1951 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1952 "Intel D945G", STAC_D945GTP3),
1953 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1954 "Intel D945G", STAC_D945GTP3),
1955 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1956 "Intel D945G", STAC_D945GTP3),
1957 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1958 "Intel D945G", STAC_D945GTP3),
1959 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1960 "Intel D945G", STAC_D945GTP3),
1961 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1962 "Intel D945G", STAC_D945GTP3),
1963 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1964 "Intel D945G", STAC_D945GTP3),
1965 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1966 "Intel D945G", STAC_D945GTP3),
1967 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1968 "Intel D945G", STAC_D945GTP3),
1969 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1970 "Intel D945G", STAC_D945GTP3),
1971 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1972 "Intel D945G", STAC_D945GTP3),
1973 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1974 "Intel D945G", STAC_D945GTP3),
1975 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1976 "Intel D945G", STAC_D945GTP3),
1977 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1978 "Intel D945G", STAC_D945GTP3),
1979 /* Intel D945G 5-stack systems */
1980 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1981 "Intel D945G", STAC_D945GTP5),
1982 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1983 "Intel D945G", STAC_D945GTP5),
1984 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1985 "Intel D945G", STAC_D945GTP5),
1986 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1987 "Intel D945G", STAC_D945GTP5),
1988 /* Intel 945P based systems */
1989 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1990 "Intel D945P", STAC_D945GTP3),
1991 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1992 "Intel D945P", STAC_D945GTP3),
1993 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1994 "Intel D945P", STAC_D945GTP3),
1995 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1996 "Intel D945P", STAC_D945GTP3),
1997 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1998 "Intel D945P", STAC_D945GTP3),
1999 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2000 "Intel D945P", STAC_D945GTP5),
2001 /* other systems */
Nicolas Boichat536319a2008-07-21 22:18:01 +08002002 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002003 SND_PCI_QUIRK(0x8384, 0x7680,
Nicolas Boichat536319a2008-07-21 22:18:01 +08002004 "Mac", STAC_INTEL_MAC_AUTO),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002005 /* Dell systems */
2006 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
2007 "unknown Dell", STAC_922X_DELL_D81),
2008 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
2009 "unknown Dell", STAC_922X_DELL_D81),
2010 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
2011 "unknown Dell", STAC_922X_DELL_D81),
2012 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
2013 "unknown Dell", STAC_922X_DELL_D82),
2014 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
2015 "unknown Dell", STAC_922X_DELL_M81),
2016 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
2017 "unknown Dell", STAC_922X_DELL_D82),
2018 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
2019 "unknown Dell", STAC_922X_DELL_D81),
2020 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
2021 "unknown Dell", STAC_922X_DELL_D81),
2022 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2023 "Dell XPS M1210", STAC_922X_DELL_M82),
Mauro Carvalho Chehab8c650082008-08-04 10:39:59 -03002024 /* ECS/PC Chips boards */
2025 SND_PCI_QUIRK(0x1019, 0x2144,
2026 "ECS/PC chips", STAC_ECS_202),
2027 SND_PCI_QUIRK(0x1019, 0x2608,
2028 "ECS/PC chips", STAC_ECS_202),
2029 SND_PCI_QUIRK(0x1019, 0x2633,
2030 "ECS/PC chips P17G/1333", STAC_ECS_202),
2031 SND_PCI_QUIRK(0x1019, 0x2811,
2032 "ECS/PC chips", STAC_ECS_202),
2033 SND_PCI_QUIRK(0x1019, 0x2812,
2034 "ECS/PC chips", STAC_ECS_202),
2035 SND_PCI_QUIRK(0x1019, 0x2813,
2036 "ECS/PC chips", STAC_ECS_202),
2037 SND_PCI_QUIRK(0x1019, 0x2814,
2038 "ECS/PC chips", STAC_ECS_202),
2039 SND_PCI_QUIRK(0x1019, 0x2815,
2040 "ECS/PC chips", STAC_ECS_202),
2041 SND_PCI_QUIRK(0x1019, 0x2816,
2042 "ECS/PC chips", STAC_ECS_202),
2043 SND_PCI_QUIRK(0x1019, 0x2817,
2044 "ECS/PC chips", STAC_ECS_202),
2045 SND_PCI_QUIRK(0x1019, 0x2818,
2046 "ECS/PC chips", STAC_ECS_202),
2047 SND_PCI_QUIRK(0x1019, 0x2819,
2048 "ECS/PC chips", STAC_ECS_202),
2049 SND_PCI_QUIRK(0x1019, 0x2820,
2050 "ECS/PC chips", STAC_ECS_202),
Matt Porter403d1942005-11-29 15:00:51 +01002051 {} /* terminator */
2052};
2053
Matt Porter3cc08dc2006-01-23 15:27:49 +01002054static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02002055 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2056 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
2057 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
2058 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002059};
2060
Tobin Davis93ed1502006-09-01 21:03:12 +02002061static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002062 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
2063 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
2064 0x40000100, 0x40000100, 0x40000100, 0x40000100,
2065 0x40000100, 0x40000100
2066};
2067
Tobin Davis93ed1502006-09-01 21:03:12 +02002068static unsigned int d965_5st_pin_configs[14] = {
2069 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
2070 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
2071 0x40000100, 0x40000100, 0x40000100, 0x01442070,
2072 0x40000100, 0x40000100
2073};
2074
Tobin Davis4ff076e2007-08-07 11:48:12 +02002075static unsigned int dell_3st_pin_configs[14] = {
2076 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
2077 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002078 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02002079 0x40c003fc, 0x40000100
2080};
2081
Tobin Davis93ed1502006-09-01 21:03:12 +02002082static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002083 [STAC_D965_REF] = ref927x_pin_configs,
2084 [STAC_D965_3ST] = d965_3st_pin_configs,
2085 [STAC_D965_5ST] = d965_5st_pin_configs,
2086 [STAC_DELL_3ST] = dell_3st_pin_configs,
2087 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01002088};
2089
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002090static const char *stac927x_models[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002091 [STAC_D965_REF] = "ref",
2092 [STAC_D965_3ST] = "3stack",
2093 [STAC_D965_5ST] = "5stack",
2094 [STAC_DELL_3ST] = "dell-3stack",
2095 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002096};
2097
2098static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2099 /* SigmaTel reference board */
2100 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2101 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02002102 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002103 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2104 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02002105 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002106 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
2107 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
2108 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
2109 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
2110 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
2111 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
2112 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
2113 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
2114 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
2115 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
2116 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
2117 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
2118 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
2119 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
2120 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
2121 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002122 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002123 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002124 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02002125 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
2126 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002127 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01002128 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
2129 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002130 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
Takashi Iwai24918b62008-09-30 12:58:54 +02002131 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell Inspiron 1525", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002132 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
2133 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
2134 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2135 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02002136 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002137 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
2138 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
2139 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
2140 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
2141 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
2142 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
2143 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
2144 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
2145 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01002146 {} /* terminator */
2147};
2148
Matt Porterf3302a52006-07-31 12:49:34 +02002149static unsigned int ref9205_pin_configs[12] = {
2150 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002151 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02002152 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02002153};
2154
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002155/*
2156 STAC 9205 pin configs for
2157 102801F1
2158 102801F2
2159 102801FC
2160 102801FD
2161 10280204
2162 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002163 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002164*/
2165static unsigned int dell_9205_m42_pin_configs[12] = {
2166 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
2167 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
2168 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
2169};
2170
2171/*
2172 STAC 9205 pin configs for
2173 102801F9
2174 102801FA
2175 102801FE
2176 102801FF (Dell Precision M4300)
2177 10280206
2178 10280200
2179 10280201
2180*/
2181static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002182 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
2183 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
2184 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
2185};
2186
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002187static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002188 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
2189 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
2190 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
2191};
2192
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002193static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002194 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002195 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2196 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2197 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02002198};
2199
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002200static const char *stac9205_models[STAC_9205_MODELS] = {
2201 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002202 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002203 [STAC_9205_DELL_M43] = "dell-m43",
2204 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01002205};
2206
2207static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2208 /* SigmaTel reference board */
2209 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2210 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002211 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2212 "unknown Dell", STAC_9205_DELL_M42),
2213 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
2214 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002215 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02002216 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002217 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
2218 "Dell Precision", STAC_9205_DELL_M43),
2219 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
2220 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002221 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
2222 "unknown Dell", STAC_9205_DELL_M42),
2223 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
2224 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002225 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
2226 "Dell Precision", STAC_9205_DELL_M43),
2227 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002228 "Dell Precision M4300", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02002229 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
2230 "unknown Dell", STAC_9205_DELL_M42),
Takashi Iwai45499152008-06-12 16:27:24 +02002231 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
2232 "Dell Precision", STAC_9205_DELL_M43),
2233 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
2234 "Dell Precision", STAC_9205_DELL_M43),
2235 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
2236 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02002237 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
2238 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01002239 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2240 "Dell Vostro 1500", STAC_9205_DELL_M42),
Matt Porterf3302a52006-07-31 12:49:34 +02002241 {} /* terminator */
2242};
2243
Richard Fish11b44bb2006-08-23 18:31:34 +02002244static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
2245{
2246 int i;
2247 struct sigmatel_spec *spec = codec->spec;
2248
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002249 kfree(spec->pin_configs);
2250 spec->pin_configs = kcalloc(spec->num_pins, sizeof(*spec->pin_configs),
2251 GFP_KERNEL);
2252 if (!spec->pin_configs)
2253 return -ENOMEM;
Richard Fish11b44bb2006-08-23 18:31:34 +02002254
2255 for (i = 0; i < spec->num_pins; i++) {
2256 hda_nid_t nid = spec->pin_nids[i];
2257 unsigned int pin_cfg;
2258
2259 pin_cfg = snd_hda_codec_read(codec, nid, 0,
2260 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2261 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2262 nid, pin_cfg);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002263 spec->pin_configs[i] = pin_cfg;
Richard Fish11b44bb2006-08-23 18:31:34 +02002264 }
2265
2266 return 0;
2267}
2268
Matthew Ranostay87d48362007-07-17 11:52:24 +02002269static void stac92xx_set_config_reg(struct hda_codec *codec,
2270 hda_nid_t pin_nid, unsigned int pin_config)
2271{
2272 int i;
2273 snd_hda_codec_write(codec, pin_nid, 0,
2274 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2275 pin_config & 0x000000ff);
2276 snd_hda_codec_write(codec, pin_nid, 0,
2277 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2278 (pin_config & 0x0000ff00) >> 8);
2279 snd_hda_codec_write(codec, pin_nid, 0,
2280 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2281 (pin_config & 0x00ff0000) >> 16);
2282 snd_hda_codec_write(codec, pin_nid, 0,
2283 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2284 pin_config >> 24);
2285 i = snd_hda_codec_read(codec, pin_nid, 0,
2286 AC_VERB_GET_CONFIG_DEFAULT,
2287 0x00);
2288 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
2289 pin_nid, i);
2290}
2291
Matt2f2f4252005-04-13 14:45:30 +02002292static void stac92xx_set_config_regs(struct hda_codec *codec)
2293{
2294 int i;
2295 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02002296
Matthew Ranostay87d48362007-07-17 11:52:24 +02002297 if (!spec->pin_configs)
2298 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02002299
Matthew Ranostay87d48362007-07-17 11:52:24 +02002300 for (i = 0; i < spec->num_pins; i++)
2301 stac92xx_set_config_reg(codec, spec->pin_nids[i],
2302 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02002303}
Matt2f2f4252005-04-13 14:45:30 +02002304
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01002305static int stac_save_pin_cfgs(struct hda_codec *codec, unsigned int *pins)
2306{
2307 struct sigmatel_spec *spec = codec->spec;
2308
2309 if (!pins)
2310 return stac92xx_save_bios_config_regs(codec);
2311
2312 kfree(spec->pin_configs);
2313 spec->pin_configs = kmemdup(pins,
2314 spec->num_pins * sizeof(*pins),
2315 GFP_KERNEL);
2316 if (!spec->pin_configs)
2317 return -ENOMEM;
2318
2319 stac92xx_set_config_regs(codec);
2320 return 0;
2321}
2322
2323static void stac_change_pin_config(struct hda_codec *codec, hda_nid_t nid,
2324 unsigned int cfg)
2325{
2326 struct sigmatel_spec *spec = codec->spec;
2327 int i;
2328
2329 for (i = 0; i < spec->num_pins; i++) {
2330 if (spec->pin_nids[i] == nid) {
2331 spec->pin_configs[i] = cfg;
2332 stac92xx_set_config_reg(codec, nid, cfg);
2333 break;
2334 }
2335 }
2336}
2337
Matt2f2f4252005-04-13 14:45:30 +02002338/*
2339 * Analog playback callbacks
2340 */
2341static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
2342 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002343 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002344{
2345 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002346 if (spec->stream_delay)
2347 msleep(spec->stream_delay);
Takashi Iwai9a081602008-02-12 18:37:26 +01002348 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2349 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02002350}
2351
2352static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2353 struct hda_codec *codec,
2354 unsigned int stream_tag,
2355 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002356 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002357{
2358 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01002359 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02002360}
2361
2362static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
2363 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002364 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002365{
2366 struct sigmatel_spec *spec = codec->spec;
2367 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2368}
2369
2370/*
Mattdabbed62005-06-14 10:19:34 +02002371 * Digital playback callbacks
2372 */
2373static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
2374 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002375 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002376{
2377 struct sigmatel_spec *spec = codec->spec;
2378 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2379}
2380
2381static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2382 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002383 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02002384{
2385 struct sigmatel_spec *spec = codec->spec;
2386 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2387}
2388
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002389static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2390 struct hda_codec *codec,
2391 unsigned int stream_tag,
2392 unsigned int format,
2393 struct snd_pcm_substream *substream)
2394{
2395 struct sigmatel_spec *spec = codec->spec;
2396 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2397 stream_tag, format, substream);
2398}
2399
Mattdabbed62005-06-14 10:19:34 +02002400
2401/*
Matt2f2f4252005-04-13 14:45:30 +02002402 * Analog capture callbacks
2403 */
2404static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
2405 struct hda_codec *codec,
2406 unsigned int stream_tag,
2407 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002408 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002409{
2410 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002411 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002412
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002413 if (spec->powerdown_adcs) {
2414 msleep(40);
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002415 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002416 AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
2417 }
2418 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
Matt2f2f4252005-04-13 14:45:30 +02002419 return 0;
2420}
2421
2422static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2423 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002424 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02002425{
2426 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002427 hda_nid_t nid = spec->adc_nids[substream->number];
Matt2f2f4252005-04-13 14:45:30 +02002428
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002429 snd_hda_codec_cleanup_stream(codec, nid);
2430 if (spec->powerdown_adcs)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01002431 snd_hda_codec_write(codec, nid, 0,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02002432 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Matt2f2f4252005-04-13 14:45:30 +02002433 return 0;
2434}
2435
Mattdabbed62005-06-14 10:19:34 +02002436static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
2437 .substreams = 1,
2438 .channels_min = 2,
2439 .channels_max = 2,
2440 /* NID is set in stac92xx_build_pcms */
2441 .ops = {
2442 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002443 .close = stac92xx_dig_playback_pcm_close,
2444 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02002445 },
2446};
2447
2448static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
2449 .substreams = 1,
2450 .channels_min = 2,
2451 .channels_max = 2,
2452 /* NID is set in stac92xx_build_pcms */
2453};
2454
Matt2f2f4252005-04-13 14:45:30 +02002455static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
2456 .substreams = 1,
2457 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02002458 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02002459 .nid = 0x02, /* NID to query formats and rates */
2460 .ops = {
2461 .open = stac92xx_playback_pcm_open,
2462 .prepare = stac92xx_playback_pcm_prepare,
2463 .cleanup = stac92xx_playback_pcm_cleanup
2464 },
2465};
2466
Matt Porter3cc08dc2006-01-23 15:27:49 +01002467static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
2468 .substreams = 1,
2469 .channels_min = 2,
2470 .channels_max = 2,
2471 .nid = 0x06, /* NID to query formats and rates */
2472 .ops = {
2473 .open = stac92xx_playback_pcm_open,
2474 .prepare = stac92xx_playback_pcm_prepare,
2475 .cleanup = stac92xx_playback_pcm_cleanup
2476 },
2477};
2478
Matt2f2f4252005-04-13 14:45:30 +02002479static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02002480 .channels_min = 2,
2481 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002482 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02002483 .ops = {
2484 .prepare = stac92xx_capture_pcm_prepare,
2485 .cleanup = stac92xx_capture_pcm_cleanup
2486 },
2487};
2488
2489static int stac92xx_build_pcms(struct hda_codec *codec)
2490{
2491 struct sigmatel_spec *spec = codec->spec;
2492 struct hda_pcm *info = spec->pcm_rec;
2493
2494 codec->num_pcms = 1;
2495 codec->pcm_info = info;
2496
Mattc7d4b2f2005-06-27 14:59:41 +02002497 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02002498 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02002499 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002500 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02002501 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01002502
2503 if (spec->alt_switch) {
2504 codec->num_pcms++;
2505 info++;
2506 info->name = "STAC92xx Analog Alt";
2507 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
2508 }
Matt2f2f4252005-04-13 14:45:30 +02002509
Mattdabbed62005-06-14 10:19:34 +02002510 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
2511 codec->num_pcms++;
2512 info++;
2513 info->name = "STAC92xx Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01002514 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Mattdabbed62005-06-14 10:19:34 +02002515 if (spec->multiout.dig_out_nid) {
2516 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2517 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2518 }
2519 if (spec->dig_in_nid) {
2520 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
2521 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2522 }
2523 }
2524
Matt2f2f4252005-04-13 14:45:30 +02002525 return 0;
2526}
2527
Takashi Iwaic960a032006-03-23 17:06:28 +01002528static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2529{
2530 unsigned int pincap = snd_hda_param_read(codec, nid,
2531 AC_PAR_PIN_CAP);
2532 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2533 if (pincap & AC_PINCAP_VREF_100)
2534 return AC_PINCTL_VREF_100;
2535 if (pincap & AC_PINCAP_VREF_80)
2536 return AC_PINCTL_VREF_80;
2537 if (pincap & AC_PINCAP_VREF_50)
2538 return AC_PINCTL_VREF_50;
2539 if (pincap & AC_PINCAP_VREF_GRD)
2540 return AC_PINCTL_VREF_GRD;
2541 return 0;
2542}
2543
Matt Porter403d1942005-11-29 15:00:51 +01002544static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2545
2546{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002547 snd_hda_codec_write_cache(codec, nid, 0,
2548 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002549}
2550
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002551#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2552
2553static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2554 struct snd_ctl_elem_value *ucontrol)
2555{
2556 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2557 struct sigmatel_spec *spec = codec->spec;
2558
Takashi Iwaid7a89432008-11-12 09:48:04 +01002559 ucontrol->value.integer.value[0] = !!spec->hp_switch;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002560 return 0;
2561}
2562
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002563static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
2564 unsigned char type);
2565
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002566static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2567 struct snd_ctl_elem_value *ucontrol)
2568{
2569 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2570 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaid7a89432008-11-12 09:48:04 +01002571 int nid = kcontrol->private_value;
2572
2573 spec->hp_switch = ucontrol->value.integer.value[0] ? nid : 0;
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002574
2575 /* check to be sure that the ports are upto date with
2576 * switch changes
2577 */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002578 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002579
2580 return 1;
2581}
2582
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002583#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01002584
2585static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2586{
2587 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2588 struct sigmatel_spec *spec = codec->spec;
2589 int io_idx = kcontrol-> private_value & 0xff;
2590
2591 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2592 return 0;
2593}
2594
2595static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2596{
2597 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2598 struct sigmatel_spec *spec = codec->spec;
2599 hda_nid_t nid = kcontrol->private_value >> 8;
2600 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002601 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01002602
2603 spec->io_switch[io_idx] = val;
2604
2605 if (val)
2606 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002607 else {
2608 unsigned int pinctl = AC_PINCTL_IN_EN;
2609 if (io_idx) /* set VREF for mic */
2610 pinctl |= stac92xx_get_vref(codec, nid);
2611 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2612 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002613
2614 /* check the auto-mute again: we need to mute/unmute the speaker
2615 * appropriately according to the pin direction
2616 */
2617 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01002618 stac_issue_unsol_event(codec, nid, STAC_HP_EVENT);
Jiang Zhe40c1d302007-11-12 13:05:16 +01002619
Matt Porter403d1942005-11-29 15:00:51 +01002620 return 1;
2621}
2622
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002623#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2624
2625static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2626 struct snd_ctl_elem_value *ucontrol)
2627{
2628 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2629 struct sigmatel_spec *spec = codec->spec;
2630
2631 ucontrol->value.integer.value[0] = spec->clfe_swap;
2632 return 0;
2633}
2634
2635static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2636 struct snd_ctl_elem_value *ucontrol)
2637{
2638 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2639 struct sigmatel_spec *spec = codec->spec;
2640 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002641 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002642
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002643 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002644 return 0;
2645
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002646 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002647
2648 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2649 spec->clfe_swap ? 0x4 : 0x0);
2650
2651 return 1;
2652}
2653
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002654#define STAC_CODEC_HP_SWITCH(xname) \
2655 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2656 .name = xname, \
2657 .index = 0, \
2658 .info = stac92xx_hp_switch_info, \
2659 .get = stac92xx_hp_switch_get, \
2660 .put = stac92xx_hp_switch_put, \
2661 }
2662
Matt Porter403d1942005-11-29 15:00:51 +01002663#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2664 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2665 .name = xname, \
2666 .index = 0, \
2667 .info = stac92xx_io_switch_info, \
2668 .get = stac92xx_io_switch_get, \
2669 .put = stac92xx_io_switch_put, \
2670 .private_value = xpval, \
2671 }
2672
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002673#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2674 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2675 .name = xname, \
2676 .index = 0, \
2677 .info = stac92xx_clfe_switch_info, \
2678 .get = stac92xx_clfe_switch_get, \
2679 .put = stac92xx_clfe_switch_put, \
2680 .private_value = xpval, \
2681 }
Matt Porter403d1942005-11-29 15:00:51 +01002682
Mattc7d4b2f2005-06-27 14:59:41 +02002683enum {
2684 STAC_CTL_WIDGET_VOL,
2685 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002686 STAC_CTL_WIDGET_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002687 STAC_CTL_WIDGET_AMP_MUX,
2688 STAC_CTL_WIDGET_AMP_VOL,
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002689 STAC_CTL_WIDGET_HP_SWITCH,
Matt Porter403d1942005-11-29 15:00:51 +01002690 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002691 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02002692};
2693
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002694static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002695 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2696 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002697 STAC_MONO_MUX,
Matthew Ranostay89385032008-09-11 09:49:39 -04002698 STAC_AMP_MUX,
2699 STAC_AMP_VOL(NULL, 0, 0, 0, 0),
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002700 STAC_CODEC_HP_SWITCH(NULL),
Matt Porter403d1942005-11-29 15:00:51 +01002701 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002702 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002703};
2704
2705/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002706static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2707 struct snd_kcontrol_new *ktemp,
2708 int idx, const char *name,
2709 unsigned long val)
Mattc7d4b2f2005-06-27 14:59:41 +02002710{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002711 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002712
Takashi Iwai603c4012008-07-30 15:01:44 +02002713 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2714 knew = snd_array_new(&spec->kctls);
2715 if (!knew)
2716 return -ENOMEM;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002717 *knew = *ktemp;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002718 knew->index = idx;
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002719 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002720 if (!knew->name)
Mattc7d4b2f2005-06-27 14:59:41 +02002721 return -ENOMEM;
2722 knew->private_value = val;
Mattc7d4b2f2005-06-27 14:59:41 +02002723 return 0;
2724}
2725
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002726static inline int stac92xx_add_control_idx(struct sigmatel_spec *spec,
2727 int type, int idx, const char *name,
2728 unsigned long val)
2729{
2730 return stac92xx_add_control_temp(spec,
2731 &stac92xx_control_templates[type],
2732 idx, name, val);
2733}
2734
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002735
2736/* add dynamic controls */
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01002737static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2738 const char *name, unsigned long val)
Matthew Ranostay4682eee2008-08-15 07:43:24 +02002739{
2740 return stac92xx_add_control_idx(spec, type, 0, name, val);
2741}
2742
Matt Porter403d1942005-11-29 15:00:51 +01002743/* flag inputs as additional dynamic lineouts */
2744static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2745{
2746 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002747 unsigned int wcaps, wtype;
2748 int i, num_dacs = 0;
2749
2750 /* use the wcaps cache to count all DACs available for line-outs */
2751 for (i = 0; i < codec->num_nodes; i++) {
2752 wcaps = codec->wcaps[i];
2753 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002754
Steve Longerbeam7b043892007-05-03 20:50:03 +02002755 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
2756 num_dacs++;
2757 }
Matt Porter403d1942005-11-29 15:00:51 +01002758
Steve Longerbeam7b043892007-05-03 20:50:03 +02002759 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
2760
Matt Porter403d1942005-11-29 15:00:51 +01002761 switch (cfg->line_outs) {
2762 case 3:
2763 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002764 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002765 cfg->line_out_pins[cfg->line_outs] =
2766 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002767 spec->line_switch = 1;
2768 cfg->line_outs++;
2769 }
2770 break;
2771 case 2:
2772 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002773 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002774 cfg->line_out_pins[cfg->line_outs] =
2775 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002776 spec->line_switch = 1;
2777 cfg->line_outs++;
2778 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002779 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002780 cfg->line_out_pins[cfg->line_outs] =
2781 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002782 spec->mic_switch = 1;
2783 cfg->line_outs++;
2784 }
2785 break;
2786 case 1:
2787 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002788 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002789 cfg->line_out_pins[cfg->line_outs] =
2790 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002791 spec->line_switch = 1;
2792 cfg->line_outs++;
2793 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002794 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002795 cfg->line_out_pins[cfg->line_outs] =
2796 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002797 spec->mic_switch = 1;
2798 cfg->line_outs++;
2799 }
2800 break;
2801 }
2802
2803 return 0;
2804}
2805
Steve Longerbeam7b043892007-05-03 20:50:03 +02002806
2807static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2808{
2809 int i;
2810
2811 for (i = 0; i < spec->multiout.num_dacs; i++) {
2812 if (spec->multiout.dac_nids[i] == nid)
2813 return 1;
2814 }
2815
2816 return 0;
2817}
2818
Matt Porter3cc08dc2006-01-23 15:27:49 +01002819/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002820 * Fill in the dac_nids table from the parsed pin configuration
2821 * This function only works when every pin in line_out_pins[]
2822 * contains atleast one DAC in its connection list. Some 92xx
2823 * codecs are not connected directly to a DAC, such as the 9200
2824 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002825 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002826static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02002827 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002828{
2829 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002830 int i, j, conn_len = 0;
2831 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2832 unsigned int wcaps, wtype;
2833
Mattc7d4b2f2005-06-27 14:59:41 +02002834 for (i = 0; i < cfg->line_outs; i++) {
2835 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02002836 conn_len = snd_hda_get_connections(codec, nid, conn,
2837 HDA_MAX_CONNECTIONS);
2838 for (j = 0; j < conn_len; j++) {
2839 wcaps = snd_hda_param_read(codec, conn[j],
2840 AC_PAR_AUDIO_WIDGET_CAP);
2841 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002842 if (wtype != AC_WID_AUD_OUT ||
2843 (wcaps & AC_WCAP_DIGITAL))
2844 continue;
2845 /* conn[j] is a DAC routed to this line-out */
2846 if (!is_in_dac_nids(spec, conn[j]))
2847 break;
2848 }
2849
2850 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002851 if (spec->multiout.num_dacs > 0) {
2852 /* we have already working output pins,
2853 * so let's drop the broken ones again
2854 */
2855 cfg->line_outs = spec->multiout.num_dacs;
2856 break;
2857 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002858 /* error out, no available DAC found */
2859 snd_printk(KERN_ERR
2860 "%s: No available DAC for pin 0x%x\n",
2861 __func__, nid);
2862 return -ENODEV;
2863 }
2864
2865 spec->multiout.dac_nids[i] = conn[j];
2866 spec->multiout.num_dacs++;
2867 if (conn_len > 1) {
2868 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002869 snd_hda_codec_write_cache(codec, nid, 0,
2870 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002871
2872 }
Mattc7d4b2f2005-06-27 14:59:41 +02002873 }
2874
Steve Longerbeam7b043892007-05-03 20:50:03 +02002875 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2876 spec->multiout.num_dacs,
2877 spec->multiout.dac_nids[0],
2878 spec->multiout.dac_nids[1],
2879 spec->multiout.dac_nids[2],
2880 spec->multiout.dac_nids[3],
2881 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02002882 return 0;
2883}
2884
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002885/* create volume control/switch for the given prefx type */
2886static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2887{
2888 char name[32];
2889 int err;
2890
2891 sprintf(name, "%s Playback Volume", pfx);
2892 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2893 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2894 if (err < 0)
2895 return err;
2896 sprintf(name, "%s Playback Switch", pfx);
2897 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2898 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2899 if (err < 0)
2900 return err;
2901 return 0;
2902}
2903
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002904static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2905{
2906 if (!spec->multiout.hp_nid)
2907 spec->multiout.hp_nid = nid;
2908 else if (spec->multiout.num_dacs > 4) {
2909 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2910 return 1;
2911 } else {
2912 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2913 spec->multiout.num_dacs++;
2914 }
2915 return 0;
2916}
2917
2918static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2919{
2920 if (is_in_dac_nids(spec, nid))
2921 return 1;
2922 if (spec->multiout.hp_nid == nid)
2923 return 1;
2924 return 0;
2925}
2926
Mattc7d4b2f2005-06-27 14:59:41 +02002927/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002928static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002929 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002930{
Takashi Iwai19039bd2006-06-28 15:52:16 +02002931 static const char *chname[4] = {
2932 "Front", "Surround", NULL /*CLFE*/, "Side"
2933 };
Matthew Ranostayd21995e2008-10-13 13:22:45 -04002934 hda_nid_t nid = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002935 int i, err;
2936
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002937 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002938 unsigned int wid_caps, pincap;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002939
2940
Takashi Iwai40ac8c42008-02-29 14:16:17 +01002941 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01002942 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02002943 continue;
2944
2945 nid = spec->multiout.dac_nids[i];
2946
2947 if (i == 2) {
2948 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002949 err = create_controls(spec, "Center", nid, 1);
2950 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002951 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002952 err = create_controls(spec, "LFE", nid, 2);
2953 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002954 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002955
2956 wid_caps = get_wcaps(codec, nid);
2957
2958 if (wid_caps & AC_WCAP_LR_SWAP) {
2959 err = stac92xx_add_control(spec,
2960 STAC_CTL_WIDGET_CLFE_SWITCH,
2961 "Swap Center/LFE Playback Switch", nid);
2962
2963 if (err < 0)
2964 return err;
2965 }
2966
Mattc7d4b2f2005-06-27 14:59:41 +02002967 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002968 err = create_controls(spec, chname[i], nid, 3);
2969 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002970 return err;
2971 }
2972 }
2973
Matthew Ranostayfedb7562008-09-23 21:46:30 -04002974 if ((spec->multiout.num_dacs - cfg->line_outs) > 0 &&
2975 cfg->hp_outs && !spec->multiout.hp_nid)
2976 spec->multiout.hp_nid = nid;
2977
Takashi Iwaia9cb5c92008-11-24 07:51:11 +01002978 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002979 err = stac92xx_add_control(spec,
2980 STAC_CTL_WIDGET_HP_SWITCH,
Takashi Iwaid7a89432008-11-12 09:48:04 +01002981 "Headphone as Line Out Switch",
2982 cfg->hp_pins[cfg->hp_outs - 1]);
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02002983 if (err < 0)
2984 return err;
2985 }
2986
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002987 if (spec->line_switch) {
2988 nid = cfg->input_pins[AUTO_PIN_LINE];
2989 pincap = snd_hda_param_read(codec, nid,
2990 AC_PAR_PIN_CAP);
2991 if (pincap & AC_PINCAP_OUT) {
2992 err = stac92xx_add_control(spec,
2993 STAC_CTL_WIDGET_IO_SWITCH,
2994 "Line In as Output Switch", nid << 8);
2995 if (err < 0)
2996 return err;
2997 }
2998 }
Matt Porter403d1942005-11-29 15:00:51 +01002999
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003000 if (spec->mic_switch) {
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003001 unsigned int def_conf;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003002 unsigned int mic_pin = AUTO_PIN_MIC;
3003again:
3004 nid = cfg->input_pins[mic_pin];
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003005 def_conf = snd_hda_codec_read(codec, nid, 0,
3006 AC_VERB_GET_CONFIG_DEFAULT, 0);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003007 /* some laptops have an internal analog microphone
3008 * which can't be used as a output */
3009 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
3010 pincap = snd_hda_param_read(codec, nid,
3011 AC_PAR_PIN_CAP);
3012 if (pincap & AC_PINCAP_OUT) {
3013 err = stac92xx_add_control(spec,
3014 STAC_CTL_WIDGET_IO_SWITCH,
3015 "Mic as Output Switch", (nid << 8) | 1);
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003016 nid = snd_hda_codec_read(codec, nid, 0,
3017 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3018 if (!check_in_dac_nids(spec, nid))
3019 add_spec_dacs(spec, nid);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01003020 if (err < 0)
3021 return err;
3022 }
Matthew Ranostayae0afd82008-02-22 17:55:05 +01003023 } else if (mic_pin == AUTO_PIN_MIC) {
3024 mic_pin = AUTO_PIN_FRONT_MIC;
3025 goto again;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01003026 }
3027 }
Matt Porter403d1942005-11-29 15:00:51 +01003028
Mattc7d4b2f2005-06-27 14:59:41 +02003029 return 0;
3030}
3031
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003032/* add playback controls for Speaker and HP outputs */
3033static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3034 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02003035{
3036 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003037 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003038 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02003039
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003040 old_num_dacs = spec->multiout.num_dacs;
3041 for (i = 0; i < cfg->hp_outs; i++) {
3042 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
3043 if (wid_caps & AC_WCAP_UNSOL_CAP)
3044 spec->hp_detect = 1;
3045 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
3046 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3047 if (check_in_dac_nids(spec, nid))
3048 nid = 0;
3049 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02003050 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003051 add_spec_dacs(spec, nid);
3052 }
3053 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02003054 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003055 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3056 if (check_in_dac_nids(spec, nid))
3057 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003058 if (! nid)
3059 continue;
3060 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02003061 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02003062 for (i = 0; i < cfg->line_outs; i++) {
3063 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
3064 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
3065 if (check_in_dac_nids(spec, nid))
3066 nid = 0;
3067 if (! nid)
3068 continue;
3069 add_spec_dacs(spec, nid);
3070 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003071 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
3072 static const char *pfxs[] = {
3073 "Speaker", "External Speaker", "Speaker2",
3074 };
3075 err = create_controls(spec, pfxs[i - old_num_dacs],
3076 spec->multiout.dac_nids[i], 3);
3077 if (err < 0)
3078 return err;
3079 }
3080 if (spec->multiout.hp_nid) {
Takashi Iwai2626a262008-03-14 09:18:32 +01003081 err = create_controls(spec, "Headphone",
3082 spec->multiout.hp_nid, 3);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003083 if (err < 0)
3084 return err;
3085 }
Mattc7d4b2f2005-06-27 14:59:41 +02003086
3087 return 0;
3088}
3089
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003090/* labels for mono mux outputs */
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003091static const char *stac92xx_mono_labels[4] = {
3092 "DAC0", "DAC1", "Mixer", "DAC2"
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003093};
3094
3095/* create mono mux for mono out on capable codecs */
3096static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
3097{
3098 struct sigmatel_spec *spec = codec->spec;
3099 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
3100 int i, num_cons;
3101 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
3102
3103 num_cons = snd_hda_get_connections(codec,
3104 spec->mono_nid,
3105 con_lst,
3106 HDA_MAX_NUM_INPUTS);
3107 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
3108 return -EINVAL;
3109
3110 for (i = 0; i < num_cons; i++) {
3111 mono_mux->items[mono_mux->num_items].label =
3112 stac92xx_mono_labels[i];
3113 mono_mux->items[mono_mux->num_items].index = i;
3114 mono_mux->num_items++;
3115 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003116
3117 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
3118 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003119}
3120
Matthew Ranostay89385032008-09-11 09:49:39 -04003121/* labels for amp mux outputs */
3122static const char *stac92xx_amp_labels[3] = {
Matthew Ranostay4b33c762008-10-10 09:07:23 -04003123 "Front Microphone", "Microphone", "Line In",
Matthew Ranostay89385032008-09-11 09:49:39 -04003124};
3125
3126/* create amp out controls mux on capable codecs */
3127static int stac92xx_auto_create_amp_output_ctls(struct hda_codec *codec)
3128{
3129 struct sigmatel_spec *spec = codec->spec;
3130 struct hda_input_mux *amp_mux = &spec->private_amp_mux;
3131 int i, err;
3132
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003133 for (i = 0; i < spec->num_amps; i++) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003134 amp_mux->items[amp_mux->num_items].label =
3135 stac92xx_amp_labels[i];
3136 amp_mux->items[amp_mux->num_items].index = i;
3137 amp_mux->num_items++;
3138 }
3139
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003140 if (spec->num_amps > 1) {
3141 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_MUX,
3142 "Amp Selector Capture Switch", 0);
3143 if (err < 0)
3144 return err;
3145 }
Matthew Ranostay89385032008-09-11 09:49:39 -04003146 return stac92xx_add_control(spec, STAC_CTL_WIDGET_AMP_VOL,
3147 "Amp Capture Volume",
3148 HDA_COMPOSE_AMP_VAL(spec->amp_nids[0], 3, 0, HDA_INPUT));
3149}
3150
3151
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003152/* create PC beep volume controls */
3153static int stac92xx_auto_create_beep_ctls(struct hda_codec *codec,
3154 hda_nid_t nid)
3155{
3156 struct sigmatel_spec *spec = codec->spec;
3157 u32 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3158 int err;
3159
3160 /* check for mute support for the the amp */
3161 if ((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT) {
3162 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3163 "PC Beep Playback Switch",
3164 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3165 if (err < 0)
3166 return err;
3167 }
3168
3169 /* check to see if there is volume support for the amp */
3170 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3171 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
3172 "PC Beep Playback Volume",
3173 HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT));
3174 if (err < 0)
3175 return err;
3176 }
3177 return 0;
3178}
3179
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003180#ifdef CONFIG_SND_HDA_INPUT_BEEP
3181#define stac92xx_dig_beep_switch_info snd_ctl_boolean_mono_info
3182
3183static int stac92xx_dig_beep_switch_get(struct snd_kcontrol *kcontrol,
3184 struct snd_ctl_elem_value *ucontrol)
3185{
3186 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3187 ucontrol->value.integer.value[0] = codec->beep->enabled;
3188 return 0;
3189}
3190
3191static int stac92xx_dig_beep_switch_put(struct snd_kcontrol *kcontrol,
3192 struct snd_ctl_elem_value *ucontrol)
3193{
3194 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3195 int enabled = !!ucontrol->value.integer.value[0];
3196 if (codec->beep->enabled != enabled) {
3197 codec->beep->enabled = enabled;
3198 return 1;
3199 }
3200 return 0;
3201}
3202
3203static struct snd_kcontrol_new stac92xx_dig_beep_ctrl = {
3204 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3205 .info = stac92xx_dig_beep_switch_info,
3206 .get = stac92xx_dig_beep_switch_get,
3207 .put = stac92xx_dig_beep_switch_put,
3208};
3209
3210static int stac92xx_beep_switch_ctl(struct hda_codec *codec)
3211{
3212 return stac92xx_add_control_temp(codec->spec, &stac92xx_dig_beep_ctrl,
3213 0, "PC Beep Playback Switch", 0);
3214}
3215#endif
3216
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003217static int stac92xx_auto_create_mux_input_ctls(struct hda_codec *codec)
3218{
3219 struct sigmatel_spec *spec = codec->spec;
3220 int wcaps, nid, i, err = 0;
3221
3222 for (i = 0; i < spec->num_muxes; i++) {
3223 nid = spec->mux_nids[i];
3224 wcaps = get_wcaps(codec, nid);
3225
3226 if (wcaps & AC_WCAP_OUT_AMP) {
3227 err = stac92xx_add_control_idx(spec,
3228 STAC_CTL_WIDGET_VOL, i, "Mux Capture Volume",
3229 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
3230 if (err < 0)
3231 return err;
3232 }
3233 }
3234 return 0;
3235};
3236
Matthew Ranostayd9737752008-09-07 12:03:41 +02003237static const char *stac92xx_spdif_labels[3] = {
Matthew Ranostay65973632008-09-16 10:39:37 -04003238 "Digital Playback", "Analog Mux 1", "Analog Mux 2",
Matthew Ranostayd9737752008-09-07 12:03:41 +02003239};
3240
3241static int stac92xx_auto_create_spdif_mux_ctls(struct hda_codec *codec)
3242{
3243 struct sigmatel_spec *spec = codec->spec;
3244 struct hda_input_mux *spdif_mux = &spec->private_smux;
Matthew Ranostay65973632008-09-16 10:39:37 -04003245 const char **labels = spec->spdif_labels;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003246 int i, num_cons;
Matthew Ranostay65973632008-09-16 10:39:37 -04003247 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003248
3249 num_cons = snd_hda_get_connections(codec,
3250 spec->smux_nids[0],
3251 con_lst,
3252 HDA_MAX_NUM_INPUTS);
Matthew Ranostay65973632008-09-16 10:39:37 -04003253 if (!num_cons)
Matthew Ranostayd9737752008-09-07 12:03:41 +02003254 return -EINVAL;
3255
Matthew Ranostay65973632008-09-16 10:39:37 -04003256 if (!labels)
3257 labels = stac92xx_spdif_labels;
3258
Matthew Ranostayd9737752008-09-07 12:03:41 +02003259 for (i = 0; i < num_cons; i++) {
Matthew Ranostay65973632008-09-16 10:39:37 -04003260 spdif_mux->items[spdif_mux->num_items].label = labels[i];
Matthew Ranostayd9737752008-09-07 12:03:41 +02003261 spdif_mux->items[spdif_mux->num_items].index = i;
3262 spdif_mux->num_items++;
3263 }
3264
3265 return 0;
3266}
3267
Matt Porter8b657272006-10-26 17:12:59 +02003268/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01003269static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02003270 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
3271 "Digital Mic 3", "Digital Mic 4"
3272};
3273
3274/* create playback/capture controls for input pins on dmic capable codecs */
3275static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3276 const struct auto_pin_cfg *cfg)
3277{
3278 struct sigmatel_spec *spec = codec->spec;
3279 struct hda_input_mux *dimux = &spec->private_dimux;
3280 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003281 int err, i, j;
3282 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02003283
3284 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
3285 dimux->items[dimux->num_items].index = 0;
3286 dimux->num_items++;
3287
3288 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003289 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02003290 int index;
3291 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003292 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02003293 unsigned int def_conf;
3294
3295 def_conf = snd_hda_codec_read(codec,
3296 spec->dmic_nids[i],
3297 0,
3298 AC_VERB_GET_CONFIG_DEFAULT,
3299 0);
3300 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3301 continue;
3302
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003303 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02003304 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003305 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02003306 con_lst,
3307 HDA_MAX_NUM_INPUTS);
3308 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003309 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02003310 index = j;
3311 goto found;
3312 }
3313 continue;
3314found:
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003315 wcaps = get_wcaps(codec, nid) &
3316 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003317
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003318 if (wcaps) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003319 sprintf(name, "%s Capture Volume",
3320 stac92xx_dmic_labels[dimux->num_items]);
3321
3322 err = stac92xx_add_control(spec,
3323 STAC_CTL_WIDGET_VOL,
3324 name,
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003325 HDA_COMPOSE_AMP_VAL(nid, 3, 0,
3326 (wcaps & AC_WCAP_OUT_AMP) ?
3327 HDA_OUTPUT : HDA_INPUT));
Matthew Ranostay0678acc2008-01-08 12:10:50 +01003328 if (err < 0)
3329 return err;
3330 }
3331
Matt Porter8b657272006-10-26 17:12:59 +02003332 dimux->items[dimux->num_items].label =
3333 stac92xx_dmic_labels[dimux->num_items];
3334 dimux->items[dimux->num_items].index = index;
3335 dimux->num_items++;
3336 }
3337
3338 return 0;
3339}
3340
Mattc7d4b2f2005-06-27 14:59:41 +02003341/* create playback/capture controls for input pins */
3342static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
3343{
3344 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003345 struct hda_input_mux *imux = &spec->private_imux;
3346 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
3347 int i, j, k;
3348
3349 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003350 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02003351
Takashi Iwai314634b2006-09-21 11:56:18 +02003352 if (!cfg->input_pins[i])
3353 continue;
3354 index = -1;
3355 for (j = 0; j < spec->num_muxes; j++) {
3356 int num_cons;
3357 num_cons = snd_hda_get_connections(codec,
3358 spec->mux_nids[j],
3359 con_lst,
3360 HDA_MAX_NUM_INPUTS);
3361 for (k = 0; k < num_cons; k++)
3362 if (con_lst[k] == cfg->input_pins[i]) {
3363 index = k;
3364 goto found;
3365 }
Mattc7d4b2f2005-06-27 14:59:41 +02003366 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003367 continue;
3368 found:
3369 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
3370 imux->items[imux->num_items].index = index;
3371 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02003372 }
3373
Steve Longerbeam7b043892007-05-03 20:50:03 +02003374 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02003375 /*
3376 * Set the current input for the muxes.
3377 * The STAC9221 has two input muxes with identical source
3378 * NID lists. Hopefully this won't get confused.
3379 */
3380 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003381 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
3382 AC_VERB_SET_CONNECT_SEL,
3383 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003384 }
3385 }
3386
Mattc7d4b2f2005-06-27 14:59:41 +02003387 return 0;
3388}
3389
Mattc7d4b2f2005-06-27 14:59:41 +02003390static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
3391{
3392 struct sigmatel_spec *spec = codec->spec;
3393 int i;
3394
3395 for (i = 0; i < spec->autocfg.line_outs; i++) {
3396 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3397 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3398 }
3399}
3400
3401static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3402{
3403 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003404 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003405
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003406 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3407 hda_nid_t pin;
3408 pin = spec->autocfg.hp_pins[i];
3409 if (pin) /* connect to front */
3410 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
3411 }
3412 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3413 hda_nid_t pin;
3414 pin = spec->autocfg.speaker_pins[i];
3415 if (pin) /* connect to front */
3416 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
3417 }
Mattc7d4b2f2005-06-27 14:59:41 +02003418}
3419
Matt Porter3cc08dc2006-01-23 15:27:49 +01003420static 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 +02003421{
3422 struct sigmatel_spec *spec = codec->spec;
3423 int err;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003424 int hp_speaker_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003425
Matt Porter8b657272006-10-26 17:12:59 +02003426 if ((err = snd_hda_parse_pin_def_config(codec,
3427 &spec->autocfg,
3428 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003429 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003430 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01003431 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02003432
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003433 /* If we have no real line-out pin and multiple hp-outs, HPs should
3434 * be set up as multi-channel outputs.
3435 */
3436 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
3437 spec->autocfg.hp_outs > 1) {
3438 /* Copy hp_outs to line_outs, backup line_outs in
3439 * speaker_outs so that the following routines can handle
3440 * HP pins as primary outputs.
3441 */
3442 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
3443 sizeof(spec->autocfg.line_out_pins));
3444 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
3445 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
3446 sizeof(spec->autocfg.hp_pins));
3447 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3448 hp_speaker_swap = 1;
3449 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003450 if (spec->autocfg.mono_out_pin) {
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003451 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3452 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
Matthew Ranostay09a99952008-01-24 11:49:21 +01003453 u32 caps = query_amp_caps(codec,
3454 spec->autocfg.mono_out_pin, dir);
3455 hda_nid_t conn_list[1];
3456
3457 /* get the mixer node and then the mono mux if it exists */
3458 if (snd_hda_get_connections(codec,
3459 spec->autocfg.mono_out_pin, conn_list, 1) &&
3460 snd_hda_get_connections(codec, conn_list[0],
3461 conn_list, 1)) {
3462
3463 int wcaps = get_wcaps(codec, conn_list[0]);
3464 int wid_type = (wcaps & AC_WCAP_TYPE)
3465 >> AC_WCAP_TYPE_SHIFT;
3466 /* LR swap check, some stac925x have a mux that
3467 * changes the DACs output path instead of the
3468 * mono-mux path.
3469 */
3470 if (wid_type == AC_WID_AUD_SEL &&
3471 !(wcaps & AC_WCAP_LR_SWAP))
3472 spec->mono_nid = conn_list[0];
3473 }
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003474 if (dir) {
3475 hda_nid_t nid = spec->autocfg.mono_out_pin;
3476
3477 /* most mono outs have a least a mute/unmute switch */
3478 dir = (dir & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
3479 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
3480 "Mono Playback Switch",
3481 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
Matthew Ranostay09a99952008-01-24 11:49:21 +01003482 if (err < 0)
3483 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003484 /* check for volume support for the amp */
3485 if ((caps & AC_AMPCAP_NUM_STEPS)
3486 >> AC_AMPCAP_NUM_STEPS_SHIFT) {
3487 err = stac92xx_add_control(spec,
3488 STAC_CTL_WIDGET_VOL,
3489 "Mono Playback Volume",
3490 HDA_COMPOSE_AMP_VAL(nid, 1, 0, dir));
3491 if (err < 0)
3492 return err;
3493 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01003494 }
3495
3496 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
3497 AC_PINCTL_OUT_EN);
3498 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003499
Matt Porter403d1942005-11-29 15:00:51 +01003500 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
3501 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003502 if (spec->multiout.num_dacs == 0)
3503 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
3504 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02003505
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003506 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
3507
3508 if (err < 0)
3509 return err;
3510
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003511 /* setup analog beep controls */
3512 if (spec->anabeep_nid > 0) {
3513 err = stac92xx_auto_create_beep_ctls(codec,
3514 spec->anabeep_nid);
3515 if (err < 0)
3516 return err;
3517 }
3518
3519 /* setup digital beep controls and input device */
3520#ifdef CONFIG_SND_HDA_INPUT_BEEP
3521 if (spec->digbeep_nid > 0) {
3522 hda_nid_t nid = spec->digbeep_nid;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003523 unsigned int caps;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003524
3525 err = stac92xx_auto_create_beep_ctls(codec, nid);
3526 if (err < 0)
3527 return err;
3528 err = snd_hda_attach_beep_device(codec, nid);
3529 if (err < 0)
3530 return err;
Takashi Iwai4d4e9bb2008-11-12 16:45:04 +01003531 /* if no beep switch is available, make its own one */
3532 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3533 if (codec->beep &&
3534 !((caps & AC_AMPCAP_MUTE) >> AC_AMPCAP_MUTE_SHIFT)) {
3535 err = stac92xx_beep_switch_ctl(codec);
3536 if (err < 0)
3537 return err;
3538 }
Matthew Ranostay1cd22242008-07-18 18:20:52 +02003539 }
3540#endif
3541
Jiang Zhebcecd9b2007-11-12 12:57:03 +01003542 if (hp_speaker_swap == 1) {
3543 /* Restore the hp_outs and line_outs */
3544 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3545 sizeof(spec->autocfg.line_out_pins));
3546 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3547 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
3548 sizeof(spec->autocfg.speaker_pins));
3549 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
3550 memset(spec->autocfg.speaker_pins, 0,
3551 sizeof(spec->autocfg.speaker_pins));
3552 spec->autocfg.speaker_outs = 0;
3553 }
3554
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02003555 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3556
3557 if (err < 0)
3558 return err;
3559
3560 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3561
3562 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003563 return err;
3564
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003565 if (spec->mono_nid > 0) {
3566 err = stac92xx_auto_create_mono_output_ctls(codec);
3567 if (err < 0)
3568 return err;
3569 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003570 if (spec->num_amps > 0) {
Matthew Ranostay89385032008-09-11 09:49:39 -04003571 err = stac92xx_auto_create_amp_output_ctls(codec);
3572 if (err < 0)
3573 return err;
3574 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003575 if (spec->num_dmics > 0 && !spec->dinput_mux)
Matt Porter8b657272006-10-26 17:12:59 +02003576 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
3577 &spec->autocfg)) < 0)
3578 return err;
Matthew Ranostay4682eee2008-08-15 07:43:24 +02003579 if (spec->num_muxes > 0) {
3580 err = stac92xx_auto_create_mux_input_ctls(codec);
3581 if (err < 0)
3582 return err;
3583 }
Matthew Ranostayd9737752008-09-07 12:03:41 +02003584 if (spec->num_smuxes > 0) {
3585 err = stac92xx_auto_create_spdif_mux_ctls(codec);
3586 if (err < 0)
3587 return err;
3588 }
Matt Porter8b657272006-10-26 17:12:59 +02003589
Mattc7d4b2f2005-06-27 14:59:41 +02003590 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01003591 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02003592 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02003593
Takashi Iwai82bc9552006-03-21 11:24:42 +01003594 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003595 spec->multiout.dig_out_nid = dig_out;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02003596 if (dig_in && spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01003597 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02003598
Takashi Iwai603c4012008-07-30 15:01:44 +02003599 if (spec->kctls.list)
3600 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003601
3602 spec->input_mux = &spec->private_imux;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04003603 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayd9737752008-09-07 12:03:41 +02003604 spec->sinput_mux = &spec->private_smux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01003605 spec->mono_mux = &spec->private_mono_mux;
Matthew Ranostay89385032008-09-11 09:49:39 -04003606 spec->amp_mux = &spec->private_amp_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02003607 return 1;
3608}
3609
Takashi Iwai82bc9552006-03-21 11:24:42 +01003610/* add playback controls for HP output */
3611static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
3612 struct auto_pin_cfg *cfg)
3613{
3614 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003615 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01003616 unsigned int wid_caps;
3617
3618 if (! pin)
3619 return 0;
3620
3621 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02003622 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01003623 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003624
3625 return 0;
3626}
3627
Richard Fish160ea0d2006-09-06 13:58:25 +02003628/* add playback controls for LFE output */
3629static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3630 struct auto_pin_cfg *cfg)
3631{
3632 struct sigmatel_spec *spec = codec->spec;
3633 int err;
3634 hda_nid_t lfe_pin = 0x0;
3635 int i;
3636
3637 /*
3638 * search speaker outs and line outs for a mono speaker pin
3639 * with an amp. If one is found, add LFE controls
3640 * for it.
3641 */
3642 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
3643 hda_nid_t pin = spec->autocfg.speaker_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003644 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003645 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3646 if (wcaps == AC_WCAP_OUT_AMP)
3647 /* found a mono speaker with an amp, must be lfe */
3648 lfe_pin = pin;
3649 }
3650
3651 /* if speaker_outs is 0, then speakers may be in line_outs */
3652 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
3653 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3654 hda_nid_t pin = spec->autocfg.line_out_pins[i];
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003655 unsigned int defcfg;
Harvey Harrison8b551782008-02-29 11:56:48 +01003656 defcfg = snd_hda_codec_read(codec, pin, 0,
Richard Fish160ea0d2006-09-06 13:58:25 +02003657 AC_VERB_GET_CONFIG_DEFAULT,
3658 0x00);
Harvey Harrison8b551782008-02-29 11:56:48 +01003659 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
Takashi Iwai64ed0df2008-02-29 11:57:53 +01003660 unsigned int wcaps = get_wcaps(codec, pin);
Richard Fish160ea0d2006-09-06 13:58:25 +02003661 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
3662 if (wcaps == AC_WCAP_OUT_AMP)
3663 /* found a mono speaker with an amp,
3664 must be lfe */
3665 lfe_pin = pin;
3666 }
3667 }
3668 }
3669
3670 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003671 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02003672 if (err < 0)
3673 return err;
3674 }
3675
3676 return 0;
3677}
3678
Mattc7d4b2f2005-06-27 14:59:41 +02003679static int stac9200_parse_auto_config(struct hda_codec *codec)
3680{
3681 struct sigmatel_spec *spec = codec->spec;
3682 int err;
3683
Kailang Yangdf694da2005-12-05 19:42:22 +01003684 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02003685 return err;
3686
3687 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
3688 return err;
3689
Takashi Iwai82bc9552006-03-21 11:24:42 +01003690 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
3691 return err;
3692
Richard Fish160ea0d2006-09-06 13:58:25 +02003693 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
3694 return err;
3695
Takashi Iwai355a0ec2008-11-11 16:46:19 +01003696 if (spec->num_muxes > 0) {
3697 err = stac92xx_auto_create_mux_input_ctls(codec);
3698 if (err < 0)
3699 return err;
3700 }
3701
Takashi Iwai82bc9552006-03-21 11:24:42 +01003702 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003703 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003704 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02003705 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02003706
Takashi Iwai603c4012008-07-30 15:01:44 +02003707 if (spec->kctls.list)
3708 spec->mixers[spec->num_mixers++] = spec->kctls.list;
Mattc7d4b2f2005-06-27 14:59:41 +02003709
3710 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02003711 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02003712
3713 return 1;
3714}
3715
Sam Revitch62fe78e2006-05-10 15:09:17 +02003716/*
3717 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
3718 * funky external mute control using GPIO pins.
3719 */
3720
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003721static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003722 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02003723{
3724 unsigned int gpiostate, gpiomask, gpiodir;
3725
3726 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
3727 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003728 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003729
3730 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
3731 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003732 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003733
3734 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
3735 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003736 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02003737
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003738 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003739 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
3740
3741 snd_hda_codec_write(codec, codec->afg, 0,
3742 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003743 snd_hda_codec_read(codec, codec->afg, 0,
3744 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003745
3746 msleep(1);
3747
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01003748 snd_hda_codec_read(codec, codec->afg, 0,
3749 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003750}
3751
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003752static int stac92xx_add_jack(struct hda_codec *codec,
3753 hda_nid_t nid, int type)
3754{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003755#ifdef CONFIG_SND_JACK
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003756 struct sigmatel_spec *spec = codec->spec;
3757 struct sigmatel_jack *jack;
3758 int def_conf = snd_hda_codec_read(codec, nid,
3759 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
3760 int connectivity = get_defcfg_connect(def_conf);
3761 char name[32];
3762
3763 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
3764 return 0;
3765
3766 snd_array_init(&spec->jacks, sizeof(*jack), 32);
3767 jack = snd_array_new(&spec->jacks);
3768 if (!jack)
3769 return -ENOMEM;
3770 jack->nid = nid;
3771 jack->type = type;
3772
3773 sprintf(name, "%s at %s %s Jack",
3774 snd_hda_get_jack_type(def_conf),
3775 snd_hda_get_jack_connectivity(def_conf),
3776 snd_hda_get_jack_location(def_conf));
3777
3778 return snd_jack_new(codec->bus->card, name, type, &jack->jack);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003779#else
3780 return 0;
3781#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003782}
3783
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003784static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
3785 unsigned char type, int data)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003786{
3787 struct sigmatel_event *event;
3788
3789 snd_array_init(&spec->events, sizeof(*event), 32);
3790 event = snd_array_new(&spec->events);
3791 if (!event)
3792 return -ENOMEM;
3793 event->nid = nid;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003794 event->type = type;
3795 event->tag = spec->events.used;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003796 event->data = data;
3797
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003798 return event->tag;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003799}
3800
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003801static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
3802 hda_nid_t nid, unsigned char type)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003803{
3804 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003805 struct sigmatel_event *event = spec->events.list;
3806 int i;
3807
3808 for (i = 0; i < spec->events.used; i++, event++) {
3809 if (event->nid == nid && event->type == type)
3810 return event;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003811 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003812 return NULL;
3813}
3814
3815static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
3816 unsigned char tag)
3817{
3818 struct sigmatel_spec *spec = codec->spec;
3819 struct sigmatel_event *event = spec->events.list;
3820 int i;
3821
3822 for (i = 0; i < spec->events.used; i++, event++) {
3823 if (event->tag == tag)
3824 return event;
3825 }
3826 return NULL;
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003827}
3828
Takashi Iwai314634b2006-09-21 11:56:18 +02003829static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003830 unsigned int type)
Takashi Iwai314634b2006-09-21 11:56:18 +02003831{
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003832 struct sigmatel_event *event;
3833 int tag;
3834
3835 if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
3836 return;
3837 event = stac_get_event(codec, nid, type);
3838 if (event)
3839 tag = event->tag;
3840 else
3841 tag = stac_add_event(codec->spec, nid, type, 0);
3842 if (tag < 0)
3843 return;
3844 snd_hda_codec_write_cache(codec, nid, 0,
3845 AC_VERB_SET_UNSOLICITED_ENABLE,
3846 AC_USRSP_EN | tag);
Takashi Iwai314634b2006-09-21 11:56:18 +02003847}
3848
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003849static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
3850{
3851 int i;
3852 for (i = 0; i < cfg->hp_outs; i++)
3853 if (cfg->hp_pins[i] == nid)
3854 return 1; /* nid is a HP-Out */
3855
3856 return 0; /* nid is not a HP-Out */
3857};
3858
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003859static void stac92xx_power_down(struct hda_codec *codec)
3860{
3861 struct sigmatel_spec *spec = codec->spec;
3862
3863 /* power down inactive DACs */
3864 hda_nid_t *dac;
3865 for (dac = spec->dac_list; *dac; dac++)
Matthew Ranostay44510892008-02-21 07:49:31 +01003866 if (!is_in_dac_nids(spec, *dac) &&
3867 spec->multiout.hp_nid != *dac)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01003868 snd_hda_codec_write(codec, *dac, 0,
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003869 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3870}
3871
Takashi Iwaif73d3582008-11-25 08:21:51 +01003872static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3873 int enable);
3874
Mattc7d4b2f2005-06-27 14:59:41 +02003875static int stac92xx_init(struct hda_codec *codec)
3876{
3877 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003878 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaif73d3582008-11-25 08:21:51 +01003879 unsigned int gpio;
Takashi Iwaie4973e12008-11-18 09:32:42 +01003880 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02003881
Mattc7d4b2f2005-06-27 14:59:41 +02003882 snd_hda_sequence_write(codec, spec->init);
3883
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02003884 /* power down adcs initially */
3885 if (spec->powerdown_adcs)
3886 for (i = 0; i < spec->num_adcs; i++)
Takashi Iwai8c2f7672008-12-01 11:54:35 +01003887 snd_hda_codec_write(codec,
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02003888 spec->adc_nids[i], 0,
3889 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003890
3891 /* set up GPIO */
3892 gpio = spec->gpio_data;
3893 /* turn on EAPD statically when spec->eapd_switch isn't set.
3894 * otherwise, unsol event will turn it on/off dynamically
3895 */
3896 if (!spec->eapd_switch)
3897 gpio |= spec->eapd_mask;
3898 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, gpio);
3899
Takashi Iwai82bc9552006-03-21 11:24:42 +01003900 /* set up pins */
3901 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02003902 /* Enable unsolicited responses on the HP widget */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003903 for (i = 0; i < cfg->hp_outs; i++) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003904 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003905 enable_pin_detect(codec, nid, STAC_HP_EVENT);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003906 }
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01003907 /* force to enable the first line-out; the others are set up
3908 * in unsol_event
3909 */
3910 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003911 AC_PINCTL_OUT_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003912 /* fake event to set up pins */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003913 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
3914 STAC_HP_EVENT);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003915 } else {
3916 stac92xx_auto_init_multi_out(codec);
3917 stac92xx_auto_init_hp_out(codec);
3918 }
3919 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01003920 hda_nid_t nid = cfg->input_pins[i];
3921 if (nid) {
Takashi Iwai4f1e6bc2008-11-11 16:47:24 +01003922 unsigned int pinctl;
3923 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC) {
3924 /* for mic pins, force to initialize */
3925 pinctl = stac92xx_get_vref(codec, nid);
3926 } else {
3927 pinctl = snd_hda_codec_read(codec, nid, 0,
3928 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3929 /* if PINCTL already set then skip */
3930 if (pinctl & AC_PINCTL_IN_EN)
3931 continue;
3932 }
3933 pinctl |= AC_PINCTL_IN_EN;
Takashi Iwaic960a032006-03-23 17:06:28 +01003934 stac92xx_auto_set_pinctl(codec, nid, pinctl);
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003935 enable_pin_detect(codec, nid, STAC_INSERT_EVENT);
Takashi Iwaic960a032006-03-23 17:06:28 +01003936 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01003937 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003938 for (i = 0; i < spec->num_dmics; i++)
3939 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
3940 AC_PINCTL_IN_EN);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003941 if (cfg->dig_out_pin)
3942 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
3943 AC_PINCTL_OUT_EN);
3944 if (cfg->dig_in_pin)
3945 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
3946 AC_PINCTL_IN_EN);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003947 for (i = 0; i < spec->num_pwrs; i++) {
3948 hda_nid_t nid = spec->pwr_nids[i];
3949 int pinctl, def_conf;
Takashi Iwai82bc9552006-03-21 11:24:42 +01003950
Takashi Iwaif73d3582008-11-25 08:21:51 +01003951 if (is_nid_hp_pin(cfg, nid) && spec->hp_detect)
3952 continue; /* already has an unsol event */
Sam Revitch62fe78e2006-05-10 15:09:17 +02003953
Takashi Iwaif73d3582008-11-25 08:21:51 +01003954 pinctl = snd_hda_codec_read(codec, nid, 0,
3955 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3956 /* outputs are only ports capable of power management
3957 * any attempts on powering down a input port cause the
3958 * referenced VREF to act quirky.
3959 */
3960 if (pinctl & AC_PINCTL_IN_EN)
3961 continue;
3962 def_conf = snd_hda_codec_read(codec, nid, 0,
3963 AC_VERB_GET_CONFIG_DEFAULT, 0);
3964 def_conf = get_defcfg_connect(def_conf);
3965 /* skip any ports that don't have jacks since presence
3966 * detection is useless */
3967 if (def_conf != AC_JACK_PORT_COMPLEX) {
3968 if (def_conf != AC_JACK_PORT_NONE)
3969 stac_toggle_power_map(codec, nid, 1);
3970 continue;
3971 }
Takashi Iwaic6e4c662008-11-25 11:58:19 +01003972 enable_pin_detect(codec, nid, STAC_PWR_EVENT);
3973 stac_issue_unsol_event(codec, nid, STAC_PWR_EVENT);
Takashi Iwaif73d3582008-11-25 08:21:51 +01003974 }
3975 if (spec->dac_list)
3976 stac92xx_power_down(codec);
Mattc7d4b2f2005-06-27 14:59:41 +02003977 return 0;
3978}
3979
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003980static void stac92xx_free_jacks(struct hda_codec *codec)
3981{
Takashi Iwaie4973e12008-11-18 09:32:42 +01003982#ifdef CONFIG_SND_JACK
Takashi Iwaib94d3532008-11-21 09:08:06 +01003983 /* free jack instances manually when clearing/reconfiguring */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003984 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaib94d3532008-11-21 09:08:06 +01003985 if (!codec->bus->shutdown && spec->jacks.list) {
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003986 struct sigmatel_jack *jacks = spec->jacks.list;
3987 int i;
3988 for (i = 0; i < spec->jacks.used; i++)
3989 snd_device_free(codec->bus->card, &jacks[i].jack);
3990 }
3991 snd_array_free(&spec->jacks);
Takashi Iwaie4973e12008-11-18 09:32:42 +01003992#endif
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04003993}
3994
Takashi Iwai603c4012008-07-30 15:01:44 +02003995static void stac92xx_free_kctls(struct hda_codec *codec)
3996{
3997 struct sigmatel_spec *spec = codec->spec;
3998
3999 if (spec->kctls.list) {
4000 struct snd_kcontrol_new *kctl = spec->kctls.list;
4001 int i;
4002 for (i = 0; i < spec->kctls.used; i++)
4003 kfree(kctl[i].name);
4004 }
4005 snd_array_free(&spec->kctls);
4006}
4007
Matt2f2f4252005-04-13 14:45:30 +02004008static void stac92xx_free(struct hda_codec *codec)
4009{
Mattc7d4b2f2005-06-27 14:59:41 +02004010 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004011
4012 if (! spec)
4013 return;
4014
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004015 kfree(spec->pin_configs);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004016 stac92xx_free_jacks(codec);
4017 snd_array_free(&spec->events);
Richard Fish11b44bb2006-08-23 18:31:34 +02004018
Mattc7d4b2f2005-06-27 14:59:41 +02004019 kfree(spec);
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004020 snd_hda_detach_beep_device(codec);
Matt2f2f4252005-04-13 14:45:30 +02004021}
4022
Matt4e550962005-07-04 17:51:39 +02004023static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4024 unsigned int flag)
4025{
4026 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4027 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02004028
Takashi Iwaif9acba42007-05-29 18:01:06 +02004029 if (pin_ctl & AC_PINCTL_IN_EN) {
4030 /*
4031 * we need to check the current set-up direction of
4032 * shared input pins since they can be switched via
4033 * "xxx as Output" mixer switch
4034 */
4035 struct sigmatel_spec *spec = codec->spec;
4036 struct auto_pin_cfg *cfg = &spec->autocfg;
4037 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
4038 spec->line_switch) ||
4039 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
4040 spec->mic_switch))
4041 return;
4042 }
4043
Steve Longerbeam7b043892007-05-03 20:50:03 +02004044 /* if setting pin direction bits, clear the current
4045 direction bits first */
4046 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4047 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4048
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004049 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02004050 AC_VERB_SET_PIN_WIDGET_CONTROL,
4051 pin_ctl | flag);
4052}
4053
4054static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4055 unsigned int flag)
4056{
4057 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4058 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004059 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02004060 AC_VERB_SET_PIN_WIDGET_CONTROL,
4061 pin_ctl & ~flag);
4062}
4063
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004064static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02004065{
4066 if (!nid)
4067 return 0;
4068 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004069 & (1 << 31))
4070 return 1;
Takashi Iwai314634b2006-09-21 11:56:18 +02004071 return 0;
4072}
4073
Takashi Iwaid7a89432008-11-12 09:48:04 +01004074/* return non-zero if the hp-pin of the given array index isn't
4075 * a jack-detection target
4076 */
4077static int no_hp_sensing(struct sigmatel_spec *spec, int i)
4078{
4079 struct auto_pin_cfg *cfg = &spec->autocfg;
4080
4081 /* ignore sensing of shared line and mic jacks */
4082 if (spec->line_switch &&
4083 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_LINE])
4084 return 1;
4085 if (spec->mic_switch &&
4086 cfg->hp_pins[i] == cfg->input_pins[AUTO_PIN_MIC])
4087 return 1;
4088 /* ignore if the pin is set as line-out */
4089 if (cfg->hp_pins[i] == spec->hp_switch)
4090 return 1;
4091 return 0;
4092}
4093
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004094static void stac92xx_hp_detect(struct hda_codec *codec)
Matt4e550962005-07-04 17:51:39 +02004095{
4096 struct sigmatel_spec *spec = codec->spec;
4097 struct auto_pin_cfg *cfg = &spec->autocfg;
4098 int i, presence;
4099
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004100 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004101 if (spec->gpio_mute)
4102 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
4103 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
4104
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004105 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004106 if (presence)
4107 break;
Takashi Iwaid7a89432008-11-12 09:48:04 +01004108 if (no_hp_sensing(spec, i))
4109 continue;
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004110 presence = get_pin_presence(codec, cfg->hp_pins[i]);
4111 if (presence) {
4112 unsigned int pinctl;
4113 pinctl = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
4114 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4115 if (pinctl & AC_PINCTL_IN_EN)
4116 presence = 0; /* mic- or line-input */
4117 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004118 }
Matt4e550962005-07-04 17:51:39 +02004119
4120 if (presence) {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004121 /* disable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004122 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004123 stac92xx_reset_pinctl(codec, spec->hp_switch,
4124 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004125 for (i = 0; i < cfg->line_outs; i++)
4126 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
4127 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004128 for (i = 0; i < cfg->speaker_outs; i++)
4129 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
4130 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004131 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004132 stac_gpio_set(codec, spec->gpio_mask,
4133 spec->gpio_dir, spec->gpio_data &
4134 ~spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004135 } else {
Takashi Iwaid7a89432008-11-12 09:48:04 +01004136 /* enable lineouts */
Matthew Ranostay7c2ba972008-04-16 13:13:59 +02004137 if (spec->hp_switch)
Takashi Iwaid7a89432008-11-12 09:48:04 +01004138 stac92xx_set_pinctl(codec, spec->hp_switch,
4139 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02004140 for (i = 0; i < cfg->line_outs; i++)
4141 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
4142 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02004143 for (i = 0; i < cfg->speaker_outs; i++)
4144 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
4145 AC_PINCTL_OUT_EN);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004146 if (spec->eapd_mask && spec->eapd_switch)
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02004147 stac_gpio_set(codec, spec->gpio_mask,
4148 spec->gpio_dir, spec->gpio_data |
4149 spec->eapd_mask);
Matt4e550962005-07-04 17:51:39 +02004150 }
Takashi Iwaid7a89432008-11-12 09:48:04 +01004151 /* toggle hp outs */
4152 for (i = 0; i < cfg->hp_outs; i++) {
4153 unsigned int val = AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN;
4154 if (no_hp_sensing(spec, i))
4155 continue;
4156 if (presence)
4157 stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
4158 else
4159 stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
4160 }
Matt4e550962005-07-04 17:51:39 +02004161}
4162
Takashi Iwaif73d3582008-11-25 08:21:51 +01004163static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
4164 int enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004165{
4166 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaif73d3582008-11-25 08:21:51 +01004167 unsigned int idx, val;
4168
4169 for (idx = 0; idx < spec->num_pwrs; idx++) {
4170 if (spec->pwr_nids[idx] == nid)
4171 break;
4172 }
4173 if (idx >= spec->num_pwrs)
4174 return;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004175
4176 /* several codecs have two power down bits */
4177 if (spec->pwr_mapping)
4178 idx = spec->pwr_mapping[idx];
4179 else
4180 idx = 1 << idx;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004181
Takashi Iwaif73d3582008-11-25 08:21:51 +01004182 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4183 if (enable)
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004184 val &= ~idx;
4185 else
4186 val |= idx;
4187
4188 /* power down unused output ports */
4189 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004190}
4191
Takashi Iwaif73d3582008-11-25 08:21:51 +01004192static void stac92xx_pin_sense(struct hda_codec *codec, hda_nid_t nid)
4193{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004194 stac_toggle_power_map(codec, nid, get_pin_presence(codec, nid));
Takashi Iwaif73d3582008-11-25 08:21:51 +01004195}
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004196
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004197static void stac92xx_report_jack(struct hda_codec *codec, hda_nid_t nid)
4198{
4199 struct sigmatel_spec *spec = codec->spec;
4200 struct sigmatel_jack *jacks = spec->jacks.list;
4201
4202 if (jacks) {
4203 int i;
4204 for (i = 0; i < spec->jacks.used; i++) {
4205 if (jacks->nid == nid) {
4206 unsigned int pin_ctl =
4207 snd_hda_codec_read(codec, nid,
4208 0, AC_VERB_GET_PIN_WIDGET_CONTROL,
4209 0x00);
4210 int type = jacks->type;
4211 if (type == (SND_JACK_LINEOUT
4212 | SND_JACK_HEADPHONE))
4213 type = (pin_ctl & AC_PINCTL_HP_EN)
4214 ? SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
4215 snd_jack_report(jacks->jack,
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01004216 get_pin_presence(codec, nid)
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004217 ? type : 0);
4218 }
4219 jacks++;
4220 }
4221 }
4222}
Matt2f2f4252005-04-13 14:45:30 +02004223
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004224static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid,
4225 unsigned char type)
4226{
4227 struct sigmatel_event *event = stac_get_event(codec, nid, type);
4228 if (!event)
4229 return;
4230 codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4231}
4232
Takashi Iwai314634b2006-09-21 11:56:18 +02004233static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
4234{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004235 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004236 struct sigmatel_event *event;
4237 int tag, data;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004238
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004239 tag = (res >> 26) & 0x7f;
4240 event = stac_get_event_from_tag(codec, tag);
4241 if (!event)
4242 return;
4243
4244 switch (event->type) {
Takashi Iwai314634b2006-09-21 11:56:18 +02004245 case STAC_HP_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004246 stac92xx_hp_detect(codec);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004247 /* fallthru */
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004248 case STAC_INSERT_EVENT:
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004249 case STAC_PWR_EVENT:
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004250 if (spec->num_pwrs > 0)
4251 stac92xx_pin_sense(codec, event->nid);
4252 stac92xx_report_jack(codec, event->nid);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004253 break;
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004254 case STAC_VREF_EVENT:
4255 data = snd_hda_codec_read(codec, codec->afg, 0,
4256 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004257 /* toggle VREF state based on GPIOx status */
4258 snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004259 !!(data & (1 << event->data)));
Matthew Ranostay72474be2008-10-09 09:32:17 -04004260 break;
Takashi Iwai314634b2006-09-21 11:56:18 +02004261 }
4262}
4263
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004264#ifdef CONFIG_PROC_FS
4265static void stac92hd_proc_hook(struct snd_info_buffer *buffer,
4266 struct hda_codec *codec, hda_nid_t nid)
4267{
4268 if (nid == codec->afg)
4269 snd_iprintf(buffer, "Power-Map: 0x%02x\n",
4270 snd_hda_codec_read(codec, nid, 0, 0x0fec, 0x0));
4271}
4272
4273static void analog_loop_proc_hook(struct snd_info_buffer *buffer,
4274 struct hda_codec *codec,
4275 unsigned int verb)
4276{
4277 snd_iprintf(buffer, "Analog Loopback: 0x%02x\n",
4278 snd_hda_codec_read(codec, codec->afg, 0, verb, 0));
4279}
4280
4281/* stac92hd71bxx, stac92hd73xx */
4282static void stac92hd7x_proc_hook(struct snd_info_buffer *buffer,
4283 struct hda_codec *codec, hda_nid_t nid)
4284{
4285 stac92hd_proc_hook(buffer, codec, nid);
4286 if (nid == codec->afg)
4287 analog_loop_proc_hook(buffer, codec, 0xfa0);
4288}
4289
4290static void stac9205_proc_hook(struct snd_info_buffer *buffer,
4291 struct hda_codec *codec, hda_nid_t nid)
4292{
4293 if (nid == codec->afg)
4294 analog_loop_proc_hook(buffer, codec, 0xfe0);
4295}
4296
4297static void stac927x_proc_hook(struct snd_info_buffer *buffer,
4298 struct hda_codec *codec, hda_nid_t nid)
4299{
4300 if (nid == codec->afg)
4301 analog_loop_proc_hook(buffer, codec, 0xfeb);
4302}
4303#else
4304#define stac92hd_proc_hook NULL
4305#define stac92hd7x_proc_hook NULL
4306#define stac9205_proc_hook NULL
4307#define stac927x_proc_hook NULL
4308#endif
4309
Takashi Iwaicb53c622007-08-10 17:21:45 +02004310#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02004311static int stac92xx_resume(struct hda_codec *codec)
4312{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004313 struct sigmatel_spec *spec = codec->spec;
4314
Richard Fish11b44bb2006-08-23 18:31:34 +02004315 stac92xx_set_config_regs(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004316 stac92xx_init(codec);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02004317 snd_hda_codec_resume_amp(codec);
4318 snd_hda_codec_resume_cache(codec);
Takashi Iwai2c885872008-11-18 09:36:55 +01004319 /* fake event to set up pins again to override cached values */
Takashi Iwaidc81bed2007-09-03 09:36:36 +02004320 if (spec->hp_detect)
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004321 stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0],
4322 STAC_HP_EVENT);
Mattff6fdc32005-06-27 15:06:52 +02004323 return 0;
4324}
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004325
4326static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4327{
4328 struct sigmatel_spec *spec = codec->spec;
4329 if (spec->eapd_mask)
4330 stac_gpio_set(codec, spec->gpio_mask,
4331 spec->gpio_dir, spec->gpio_data &
4332 ~spec->eapd_mask);
4333 return 0;
4334}
Mattff6fdc32005-06-27 15:06:52 +02004335#endif
4336
Matt2f2f4252005-04-13 14:45:30 +02004337static struct hda_codec_ops stac92xx_patch_ops = {
4338 .build_controls = stac92xx_build_controls,
4339 .build_pcms = stac92xx_build_pcms,
4340 .init = stac92xx_init,
4341 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02004342 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004343#ifdef SND_HDA_NEEDS_RESUME
Matthew Ranostayc6798d22008-11-18 20:54:17 -05004344 .suspend = stac92xx_suspend,
Mattff6fdc32005-06-27 15:06:52 +02004345 .resume = stac92xx_resume,
4346#endif
Matt2f2f4252005-04-13 14:45:30 +02004347};
4348
4349static int patch_stac9200(struct hda_codec *codec)
4350{
4351 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004352 int err;
Matt2f2f4252005-04-13 14:45:30 +02004353
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004354 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004355 if (spec == NULL)
4356 return -ENOMEM;
4357
4358 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004359 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004360 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004361 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4362 stac9200_models,
4363 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02004364 if (spec->board_config < 0) {
4365 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4366 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004367 } else
4368 err = stac_save_pin_cfgs(codec,
4369 stac9200_brd_tbl[spec->board_config]);
4370 if (err < 0) {
4371 stac92xx_free(codec);
4372 return err;
Matt Porter403d1942005-11-29 15:00:51 +01004373 }
Matt2f2f4252005-04-13 14:45:30 +02004374
4375 spec->multiout.max_channels = 2;
4376 spec->multiout.num_dacs = 1;
4377 spec->multiout.dac_nids = stac9200_dac_nids;
4378 spec->adc_nids = stac9200_adc_nids;
4379 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02004380 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02004381 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004382 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004383 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004384
Tobin Davisbf277782008-02-03 20:31:47 +01004385 if (spec->board_config == STAC_9200_GATEWAY ||
4386 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02004387 spec->init = stac9200_eapd_init;
4388 else
4389 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004390 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004391
Takashi Iwai117f2572008-03-18 09:53:23 +01004392 if (spec->board_config == STAC_9200_PANASONIC) {
4393 spec->gpio_mask = spec->gpio_dir = 0x09;
4394 spec->gpio_data = 0x00;
4395 }
4396
Mattc7d4b2f2005-06-27 14:59:41 +02004397 err = stac9200_parse_auto_config(codec);
4398 if (err < 0) {
4399 stac92xx_free(codec);
4400 return err;
4401 }
Matt2f2f4252005-04-13 14:45:30 +02004402
4403 codec->patch_ops = stac92xx_patch_ops;
4404
4405 return 0;
4406}
4407
Tobin Davis8e21c342007-01-08 11:04:17 +01004408static int patch_stac925x(struct hda_codec *codec)
4409{
4410 struct sigmatel_spec *spec;
4411 int err;
4412
4413 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4414 if (spec == NULL)
4415 return -ENOMEM;
4416
4417 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004418 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01004419 spec->pin_nids = stac925x_pin_nids;
4420 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
4421 stac925x_models,
4422 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004423 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01004424 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02004425 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
4426 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01004427 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004428 } else
4429 err = stac_save_pin_cfgs(codec,
4430 stac925x_brd_tbl[spec->board_config]);
4431 if (err < 0) {
4432 stac92xx_free(codec);
4433 return err;
Tobin Davis8e21c342007-01-08 11:04:17 +01004434 }
4435
4436 spec->multiout.max_channels = 2;
4437 spec->multiout.num_dacs = 1;
4438 spec->multiout.dac_nids = stac925x_dac_nids;
4439 spec->adc_nids = stac925x_adc_nids;
4440 spec->mux_nids = stac925x_mux_nids;
4441 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004442 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004443 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02004444 switch (codec->vendor_id) {
4445 case 0x83847632: /* STAC9202 */
4446 case 0x83847633: /* STAC9202D */
4447 case 0x83847636: /* STAC9251 */
4448 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02004449 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02004450 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01004451 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
4452 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02004453 break;
4454 default:
4455 spec->num_dmics = 0;
4456 break;
4457 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004458
4459 spec->init = stac925x_core_init;
4460 spec->mixer = stac925x_mixer;
4461
4462 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004463 if (!err) {
4464 if (spec->board_config < 0) {
4465 printk(KERN_WARNING "hda_codec: No auto-config is "
4466 "available, default to model=ref\n");
4467 spec->board_config = STAC_925x_REF;
4468 goto again;
4469 }
4470 err = -EINVAL;
4471 }
Tobin Davis8e21c342007-01-08 11:04:17 +01004472 if (err < 0) {
4473 stac92xx_free(codec);
4474 return err;
4475 }
4476
4477 codec->patch_ops = stac92xx_patch_ops;
4478
4479 return 0;
4480}
4481
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004482static struct hda_input_mux stac92hd73xx_dmux = {
4483 .num_items = 4,
4484 .items = {
4485 { "Analog Inputs", 0x0b },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004486 { "Digital Mic 1", 0x09 },
4487 { "Digital Mic 2", 0x0a },
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004488 { "CD", 0x08 },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004489 }
4490};
4491
4492static int patch_stac92hd73xx(struct hda_codec *codec)
4493{
4494 struct sigmatel_spec *spec;
4495 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
4496 int err = 0;
4497
4498 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4499 if (spec == NULL)
4500 return -ENOMEM;
4501
4502 codec->spec = spec;
Matthew Ranostaye99d32b2008-09-09 10:46:38 +02004503 codec->slave_dig_outs = stac92hd73xx_slave_dig_outs;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004504 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
4505 spec->pin_nids = stac92hd73xx_pin_nids;
4506 spec->board_config = snd_hda_check_board_config(codec,
4507 STAC_92HD73XX_MODELS,
4508 stac92hd73xx_models,
4509 stac92hd73xx_cfg_tbl);
4510again:
4511 if (spec->board_config < 0) {
4512 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4513 " STAC92HD73XX, using BIOS defaults\n");
4514 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004515 } else
4516 err = stac_save_pin_cfgs(codec,
4517 stac92hd73xx_brd_tbl[spec->board_config]);
4518 if (err < 0) {
4519 stac92xx_free(codec);
4520 return err;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004521 }
4522
4523 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
4524 conn, STAC92HD73_DAC_COUNT + 2) - 1;
4525
4526 if (spec->multiout.num_dacs < 0) {
4527 printk(KERN_WARNING "hda_codec: Could not determine "
4528 "number of channels defaulting to DAC count\n");
4529 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
4530 }
4531
4532 switch (spec->multiout.num_dacs) {
4533 case 0x3: /* 6 Channel */
4534 spec->mixer = stac92hd73xx_6ch_mixer;
4535 spec->init = stac92hd73xx_6ch_core_init;
4536 break;
4537 case 0x4: /* 8 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004538 spec->mixer = stac92hd73xx_8ch_mixer;
4539 spec->init = stac92hd73xx_8ch_core_init;
4540 break;
4541 case 0x5: /* 10 Channel */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004542 spec->mixer = stac92hd73xx_10ch_mixer;
4543 spec->init = stac92hd73xx_10ch_core_init;
4544 };
4545
4546 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
4547 spec->aloopback_mask = 0x01;
4548 spec->aloopback_shift = 8;
4549
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004550 spec->digbeep_nid = 0x1c;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004551 spec->mux_nids = stac92hd73xx_mux_nids;
4552 spec->adc_nids = stac92hd73xx_adc_nids;
4553 spec->dmic_nids = stac92hd73xx_dmic_nids;
4554 spec->dmux_nids = stac92hd73xx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004555 spec->smux_nids = stac92hd73xx_smux_nids;
Matthew Ranostay89385032008-09-11 09:49:39 -04004556 spec->amp_nids = stac92hd73xx_amp_nids;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004557 spec->num_amps = ARRAY_SIZE(stac92hd73xx_amp_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004558
4559 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
4560 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01004561 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004562 memcpy(&spec->private_dimux, &stac92hd73xx_dmux,
4563 sizeof(stac92hd73xx_dmux));
4564
Matthew Ranostaya7662642008-02-21 07:51:14 +01004565 switch (spec->board_config) {
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004566 case STAC_DELL_EQ:
Matthew Ranostayd654a662008-03-14 08:46:51 +01004567 spec->init = dell_eq_core_init;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004568 /* fallthru */
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004569 case STAC_DELL_M6_AMIC:
4570 case STAC_DELL_M6_DMIC:
4571 case STAC_DELL_M6_BOTH:
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004572 spec->num_smuxes = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004573 spec->mixer = &stac92hd73xx_6ch_mixer[DELL_M6_MIXER];
4574 spec->amp_nids = &stac92hd73xx_amp_nids[DELL_M6_AMP];
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004575 spec->eapd_switch = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004576 spec->num_amps = 1;
Matthew Ranostay6b3ab212008-11-03 08:12:43 -05004577
4578 if (!spec->init)
4579 spec->init = dell_m6_core_init;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004580 switch (spec->board_config) {
4581 case STAC_DELL_M6_AMIC: /* Analog Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004582 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4583 spec->num_dmics = 0;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004584 spec->private_dimux.num_items = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004585 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004586 case STAC_DELL_M6_DMIC: /* Digital Mics */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004587 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4588 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004589 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004590 break;
Takashi Iwai661cd8f2008-11-25 15:18:29 +01004591 case STAC_DELL_M6_BOTH: /* Both */
Matthew Ranostaya7662642008-02-21 07:51:14 +01004592 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
4593 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
4594 spec->num_dmics = 1;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004595 spec->private_dimux.num_items = 2;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004596 break;
4597 }
4598 break;
4599 default:
4600 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004601 spec->num_smuxes = ARRAY_SIZE(stac92hd73xx_smux_nids);
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05004602 spec->eapd_switch = 1;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004603 }
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04004604 if (spec->board_config > STAC_92HD73XX_REF) {
4605 /* GPIO0 High = Enable EAPD */
4606 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
4607 spec->gpio_data = 0x01;
4608 }
Matthew Ranostay2a9c7812008-09-13 16:45:39 -04004609 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostaya7662642008-02-21 07:51:14 +01004610
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004611 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
4612 spec->pwr_nids = stac92hd73xx_pwr_nids;
4613
Matthew Ranostayd9737752008-09-07 12:03:41 +02004614 err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004615
4616 if (!err) {
4617 if (spec->board_config < 0) {
4618 printk(KERN_WARNING "hda_codec: No auto-config is "
4619 "available, default to model=ref\n");
4620 spec->board_config = STAC_92HD73XX_REF;
4621 goto again;
4622 }
4623 err = -EINVAL;
4624 }
4625
4626 if (err < 0) {
4627 stac92xx_free(codec);
4628 return err;
4629 }
4630
4631 codec->patch_ops = stac92xx_patch_ops;
4632
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004633 codec->proc_widget_hook = stac92hd7x_proc_hook;
4634
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004635 return 0;
4636}
4637
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004638static struct hda_input_mux stac92hd83xxx_dmux = {
4639 .num_items = 3,
4640 .items = {
4641 { "Analog Inputs", 0x03 },
4642 { "Digital Mic 1", 0x04 },
4643 { "Digital Mic 2", 0x05 },
4644 }
4645};
4646
4647static int patch_stac92hd83xxx(struct hda_codec *codec)
4648{
4649 struct sigmatel_spec *spec;
4650 int err;
4651
4652 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4653 if (spec == NULL)
4654 return -ENOMEM;
4655
4656 codec->spec = spec;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004657 codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004658 spec->mono_nid = 0x19;
4659 spec->digbeep_nid = 0x21;
4660 spec->dmic_nids = stac92hd83xxx_dmic_nids;
4661 spec->dmux_nids = stac92hd83xxx_dmux_nids;
4662 spec->adc_nids = stac92hd83xxx_adc_nids;
4663 spec->pwr_nids = stac92hd83xxx_pwr_nids;
4664 spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
4665 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
4666 spec->multiout.dac_nids = stac92hd83xxx_dac_nids;
4667
4668 spec->init = stac92hd83xxx_core_init;
4669 switch (codec->vendor_id) {
4670 case 0x111d7605:
4671 spec->multiout.num_dacs = STAC92HD81_DAC_COUNT;
4672 break;
4673 default:
4674 spec->num_pwrs--;
4675 spec->init++; /* switch to config #2 */
4676 spec->multiout.num_dacs = STAC92HD83_DAC_COUNT;
4677 }
4678
4679 spec->mixer = stac92hd83xxx_mixer;
4680 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
4681 spec->num_dmuxes = ARRAY_SIZE(stac92hd83xxx_dmux_nids);
4682 spec->num_adcs = ARRAY_SIZE(stac92hd83xxx_adc_nids);
4683 spec->num_dmics = STAC92HD83XXX_NUM_DMICS;
4684 spec->dinput_mux = &stac92hd83xxx_dmux;
4685 spec->pin_nids = stac92hd83xxx_pin_nids;
4686 spec->board_config = snd_hda_check_board_config(codec,
4687 STAC_92HD83XXX_MODELS,
4688 stac92hd83xxx_models,
4689 stac92hd83xxx_cfg_tbl);
4690again:
4691 if (spec->board_config < 0) {
4692 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4693 " STAC92HD83XXX, using BIOS defaults\n");
4694 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004695 } else
4696 err = stac_save_pin_cfgs(codec,
4697 stac92hd83xxx_brd_tbl[spec->board_config]);
4698 if (err < 0) {
4699 stac92xx_free(codec);
4700 return err;
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004701 }
4702
4703 err = stac92xx_parse_auto_config(codec, 0x1d, 0);
4704 if (!err) {
4705 if (spec->board_config < 0) {
4706 printk(KERN_WARNING "hda_codec: No auto-config is "
4707 "available, default to model=ref\n");
4708 spec->board_config = STAC_92HD83XXX_REF;
4709 goto again;
4710 }
4711 err = -EINVAL;
4712 }
4713
4714 if (err < 0) {
4715 stac92xx_free(codec);
4716 return err;
4717 }
4718
4719 codec->patch_ops = stac92xx_patch_ops;
4720
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004721 codec->proc_widget_hook = stac92hd_proc_hook;
4722
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02004723 return 0;
4724}
4725
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004726static struct hda_input_mux stac92hd71bxx_dmux = {
4727 .num_items = 4,
4728 .items = {
4729 { "Analog Inputs", 0x00 },
4730 { "Mixer", 0x01 },
4731 { "Digital Mic 1", 0x02 },
4732 { "Digital Mic 2", 0x03 },
4733 }
4734};
4735
Matthew Ranostaye035b842007-11-06 11:53:55 +01004736static int patch_stac92hd71bxx(struct hda_codec *codec)
4737{
4738 struct sigmatel_spec *spec;
4739 int err = 0;
4740
4741 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4742 if (spec == NULL)
4743 return -ENOMEM;
4744
4745 codec->spec = spec;
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004746 codec->patch_ops = stac92xx_patch_ops;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004747 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004748 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004749 spec->pin_nids = stac92hd71bxx_pin_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004750 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4751 sizeof(stac92hd71bxx_dmux));
Matthew Ranostaye035b842007-11-06 11:53:55 +01004752 spec->board_config = snd_hda_check_board_config(codec,
4753 STAC_92HD71BXX_MODELS,
4754 stac92hd71bxx_models,
4755 stac92hd71bxx_cfg_tbl);
4756again:
4757 if (spec->board_config < 0) {
4758 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4759 " STAC92HD71BXX, using BIOS defaults\n");
4760 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004761 } else
4762 err = stac_save_pin_cfgs(codec,
4763 stac92hd71bxx_brd_tbl[spec->board_config]);
4764 if (err < 0) {
4765 stac92xx_free(codec);
4766 return err;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004767 }
4768
Takashi Iwai41c3b642008-11-18 10:45:15 +01004769 if (spec->board_config > STAC_92HD71BXX_REF) {
4770 /* GPIO0 = EAPD */
4771 spec->gpio_mask = 0x01;
4772 spec->gpio_dir = 0x01;
4773 spec->gpio_data = 0x01;
4774 }
4775
Matthew Ranostay541eee82007-12-14 12:08:04 +01004776 switch (codec->vendor_id) {
4777 case 0x111d76b6: /* 4 Port without Analog Mixer */
4778 case 0x111d76b7:
4779 case 0x111d76b4: /* 6 Port without Analog Mixer */
4780 case 0x111d76b5:
4781 spec->mixer = stac92hd71bxx_mixer;
4782 spec->init = stac92hd71bxx_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004783 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004784 break;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004785 case 0x111d7608: /* 5 Port with Analog Mixer */
Takashi Iwai8e5f2622008-11-15 19:28:54 +01004786 switch (spec->board_config) {
4787 case STAC_HP_M4:
Matthew Ranostay72474be2008-10-09 09:32:17 -04004788 /* Enable VREF power saving on GPIO1 detect */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004789 err = stac_add_event(spec, codec->afg,
4790 STAC_VREF_EVENT, 0x02);
4791 if (err < 0)
4792 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01004793 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay72474be2008-10-09 09:32:17 -04004794 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
4795 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay74aeaab2008-10-25 01:06:04 -04004796 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01004797 AC_USRSP_EN | err);
Matthew Ranostay72474be2008-10-09 09:32:17 -04004798 spec->gpio_mask |= 0x02;
4799 break;
4800 }
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004801 if ((codec->revision_id & 0xf) == 0 ||
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004802 (codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004803 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004804
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004805 /* no output amps */
4806 spec->num_pwrs = 0;
4807 spec->mixer = stac92hd71bxx_analog_mixer;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004808 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004809
4810 /* disable VSW */
4811 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004812 stac_change_pin_config(codec, 0xf, 0x40f000f0);
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004813 break;
4814 case 0x111d7603: /* 6 Port with Analog Mixer */
Takashi Iwai8c2f7672008-12-01 11:54:35 +01004815 if ((codec->revision_id & 0xf) == 1)
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004816 spec->stream_delay = 40; /* 40 milliseconds */
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004817
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004818 /* no output amps */
4819 spec->num_pwrs = 0;
4820 /* fallthru */
Matthew Ranostay541eee82007-12-14 12:08:04 +01004821 default:
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004822 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004823 spec->mixer = stac92hd71bxx_analog_mixer;
4824 spec->init = stac92hd71bxx_analog_core_init;
Matthew Ranostay0ffa9802008-09-08 11:20:05 -04004825 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004826 }
4827
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004828 spec->aloopback_mask = 0x50;
Matthew Ranostay541eee82007-12-14 12:08:04 +01004829 spec->aloopback_shift = 0;
4830
Matthew Ranostay8daaaa92008-08-15 07:45:52 +02004831 spec->powerdown_adcs = 1;
Matthew Ranostay1cd22242008-07-18 18:20:52 +02004832 spec->digbeep_nid = 0x26;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004833 spec->mux_nids = stac92hd71bxx_mux_nids;
4834 spec->adc_nids = stac92hd71bxx_adc_nids;
4835 spec->dmic_nids = stac92hd71bxx_dmic_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004836 spec->dmux_nids = stac92hd71bxx_dmux_nids;
Matthew Ranostayd9737752008-09-07 12:03:41 +02004837 spec->smux_nids = stac92hd71bxx_smux_nids;
Matthew Ranostayaafc4412008-06-13 18:04:33 +02004838 spec->pwr_nids = stac92hd71bxx_pwr_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004839
4840 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
4841 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004842
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004843 switch (spec->board_config) {
4844 case STAC_HP_M4:
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004845 /* enable internal microphone */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004846 stac_change_pin_config(codec, 0x0e, 0x01813040);
Matthew Ranostayb9aea712008-10-09 08:37:28 -04004847 stac92xx_auto_set_pinctl(codec, 0x0e,
4848 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
Matthew Ranostay3a7abfd2008-11-20 21:21:43 -05004849 /* fallthru */
4850 case STAC_DELL_M4_2:
4851 spec->num_dmics = 0;
4852 spec->num_smuxes = 0;
4853 spec->num_dmuxes = 0;
4854 break;
4855 case STAC_DELL_M4_1:
4856 case STAC_DELL_M4_3:
4857 spec->num_dmics = 1;
4858 spec->num_smuxes = 0;
4859 spec->num_dmuxes = 0;
Matthew Ranostay6a14f582008-09-12 12:02:30 -04004860 break;
4861 default:
4862 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
4863 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids);
4864 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
4865 };
4866
Takashi Iwaiaea7bb02008-02-25 18:26:41 +01004867 spec->multiout.num_dacs = 1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01004868 spec->multiout.hp_nid = 0x11;
4869 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
Matthew Ranostay4b33c762008-10-10 09:07:23 -04004870 if (spec->dinput_mux)
4871 spec->private_dimux.num_items +=
4872 spec->num_dmics -
4873 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
Matthew Ranostaye035b842007-11-06 11:53:55 +01004874
4875 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
4876 if (!err) {
4877 if (spec->board_config < 0) {
4878 printk(KERN_WARNING "hda_codec: No auto-config is "
4879 "available, default to model=ref\n");
4880 spec->board_config = STAC_92HD71BXX_REF;
4881 goto again;
4882 }
4883 err = -EINVAL;
4884 }
4885
4886 if (err < 0) {
4887 stac92xx_free(codec);
4888 return err;
4889 }
4890
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01004891 codec->proc_widget_hook = stac92hd7x_proc_hook;
4892
Matthew Ranostaye035b842007-11-06 11:53:55 +01004893 return 0;
4894};
4895
Matt2f2f4252005-04-13 14:45:30 +02004896static int patch_stac922x(struct hda_codec *codec)
4897{
4898 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02004899 int err;
Matt2f2f4252005-04-13 14:45:30 +02004900
Takashi Iwaie560d8d2005-09-09 14:21:46 +02004901 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02004902 if (spec == NULL)
4903 return -ENOMEM;
4904
4905 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02004906 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02004907 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004908 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
4909 stac922x_models,
4910 stac922x_cfg_tbl);
Nicolas Boichat536319a2008-07-21 22:18:01 +08004911 if (spec->board_config == STAC_INTEL_MAC_AUTO) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01004912 spec->gpio_mask = spec->gpio_dir = 0x03;
4913 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004914 /* Intel Macs have all same PCI SSID, so we need to check
4915 * codec SSID to distinguish the exact models
4916 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01004917 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004918 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004919
4920 case 0x106b0800:
4921 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02004922 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004923 case 0x106b0600:
4924 case 0x106b0700:
4925 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01004926 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004927 case 0x106b0e00:
4928 case 0x106b0f00:
4929 case 0x106b1600:
4930 case 0x106b1700:
4931 case 0x106b0200:
4932 case 0x106b1e00:
4933 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004934 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004935 case 0x106b1a00:
4936 case 0x00000100:
4937 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02004938 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02004939 case 0x106b0a00:
4940 case 0x106b2200:
4941 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02004942 break;
Nicolas Boichat536319a2008-07-21 22:18:01 +08004943 default:
4944 spec->board_config = STAC_INTEL_MAC_V3;
4945 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01004946 }
4947 }
4948
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004949 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02004950 if (spec->board_config < 0) {
4951 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
4952 "using BIOS defaults\n");
4953 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01004954 } else
4955 err = stac_save_pin_cfgs(codec,
4956 stac922x_brd_tbl[spec->board_config]);
4957 if (err < 0) {
4958 stac92xx_free(codec);
4959 return err;
Matt Porter403d1942005-11-29 15:00:51 +01004960 }
Matt2f2f4252005-04-13 14:45:30 +02004961
Matt2f2f4252005-04-13 14:45:30 +02004962 spec->adc_nids = stac922x_adc_nids;
4963 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01004964 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02004965 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02004966 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004967 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02004968
4969 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02004970 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02004971
4972 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02004973
Matt Porter3cc08dc2006-01-23 15:27:49 +01004974 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01004975 if (!err) {
4976 if (spec->board_config < 0) {
4977 printk(KERN_WARNING "hda_codec: No auto-config is "
4978 "available, default to model=ref\n");
4979 spec->board_config = STAC_D945_REF;
4980 goto again;
4981 }
4982 err = -EINVAL;
4983 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01004984 if (err < 0) {
4985 stac92xx_free(codec);
4986 return err;
4987 }
4988
4989 codec->patch_ops = stac92xx_patch_ops;
4990
Takashi Iwai807a46362007-05-29 19:01:37 +02004991 /* Fix Mux capture level; max to 2 */
4992 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
4993 (0 << AC_AMPCAP_OFFSET_SHIFT) |
4994 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
4995 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4996 (0 << AC_AMPCAP_MUTE_SHIFT));
4997
Matt Porter3cc08dc2006-01-23 15:27:49 +01004998 return 0;
4999}
5000
5001static int patch_stac927x(struct hda_codec *codec)
5002{
5003 struct sigmatel_spec *spec;
5004 int err;
5005
5006 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5007 if (spec == NULL)
5008 return -ENOMEM;
5009
5010 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005011 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005012 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005013 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5014 stac927x_models,
5015 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005016 again:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005017 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
5018 if (spec->board_config < 0)
5019 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5020 "STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02005021 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005022 } else
5023 err = stac_save_pin_cfgs(codec,
5024 stac927x_brd_tbl[spec->board_config]);
5025 if (err < 0) {
5026 stac92xx_free(codec);
5027 return err;
Matt Porter3cc08dc2006-01-23 15:27:49 +01005028 }
5029
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005030 spec->digbeep_nid = 0x23;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005031 spec->adc_nids = stac927x_adc_nids;
5032 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
5033 spec->mux_nids = stac927x_mux_nids;
5034 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005035 spec->smux_nids = stac927x_smux_nids;
5036 spec->num_smuxes = ARRAY_SIZE(stac927x_smux_nids);
Matthew Ranostay65973632008-09-16 10:39:37 -04005037 spec->spdif_labels = stac927x_spdif_labels;
Matthew Ranostayb76c8502008-02-06 14:49:44 +01005038 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005039 spec->multiout.dac_nids = spec->dac_nids;
5040
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005041 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02005042 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005043 case STAC_D965_5ST:
5044 /* GPIO0 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005045 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005046 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005047 spec->num_dmics = 0;
5048
Tobin Davis93ed1502006-09-01 21:03:12 +02005049 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005050 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005051 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005052 case STAC_DELL_BIOS:
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005053 switch (codec->subsystem_id) {
5054 case 0x10280209:
5055 case 0x1028022e:
5056 /* correct the device field to SPDIF out */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005057 stac_change_pin_config(codec, 0x21, 0x01442070);
Matthew Ranostay780c8be2008-04-14 13:32:27 +02005058 break;
5059 };
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01005060 /* configure the analog microphone on some laptops */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005061 stac_change_pin_config(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01005062 /* correct the front output jack as a hp out */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005063 stac_change_pin_config(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005064 /* correct the front input jack as a mic */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005065 stac_change_pin_config(codec, 0x0e, 0x02a79130);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01005066 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005067 case STAC_DELL_3ST:
5068 /* GPIO2 High = Enable EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005069 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005070 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005071 spec->dmic_nids = stac927x_dmic_nids;
5072 spec->num_dmics = STAC927X_NUM_DMICS;
5073
Tobin Davis93ed1502006-09-01 21:03:12 +02005074 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005075 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005076 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005077 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005078 break;
5079 default:
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005080 if (spec->board_config > STAC_D965_REF) {
5081 /* GPIO0 High = Enable EAPD */
5082 spec->eapd_mask = spec->gpio_mask = 0x01;
5083 spec->gpio_dir = spec->gpio_data = 0x01;
5084 }
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005085 spec->num_dmics = 0;
5086
Tobin Davis81d3dbd2006-08-22 19:44:45 +02005087 spec->init = stac927x_core_init;
5088 spec->mixer = stac927x_mixer;
5089 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01005090
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005091 spec->num_pwrs = 0;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005092 spec->aloopback_mask = 0x40;
5093 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005094 spec->eapd_switch = 1;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01005095
Matt Porter3cc08dc2006-01-23 15:27:49 +01005096 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005097 if (!err) {
5098 if (spec->board_config < 0) {
5099 printk(KERN_WARNING "hda_codec: No auto-config is "
5100 "available, default to model=ref\n");
5101 spec->board_config = STAC_D965_REF;
5102 goto again;
5103 }
5104 err = -EINVAL;
5105 }
Mattc7d4b2f2005-06-27 14:59:41 +02005106 if (err < 0) {
5107 stac92xx_free(codec);
5108 return err;
5109 }
Matt2f2f4252005-04-13 14:45:30 +02005110
5111 codec->patch_ops = stac92xx_patch_ops;
5112
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005113 codec->proc_widget_hook = stac927x_proc_hook;
5114
Takashi Iwai52987652008-01-16 16:09:47 +01005115 /*
5116 * !!FIXME!!
5117 * The STAC927x seem to require fairly long delays for certain
5118 * command sequences. With too short delays (even if the answer
5119 * is set to RIRB properly), it results in the silence output
5120 * on some hardwares like Dell.
5121 *
5122 * The below flag enables the longer delay (see get_response
5123 * in hda_intel.c).
5124 */
5125 codec->bus->needs_damn_long_delay = 1;
5126
Matt2f2f4252005-04-13 14:45:30 +02005127 return 0;
5128}
5129
Matt Porterf3302a52006-07-31 12:49:34 +02005130static int patch_stac9205(struct hda_codec *codec)
5131{
5132 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02005133 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02005134
5135 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5136 if (spec == NULL)
5137 return -ENOMEM;
5138
5139 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02005140 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02005141 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005142 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
5143 stac9205_models,
5144 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005145 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02005146 if (spec->board_config < 0) {
5147 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
5148 err = stac92xx_save_bios_config_regs(codec);
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005149 } else
5150 err = stac_save_pin_cfgs(codec,
5151 stac9205_brd_tbl[spec->board_config]);
5152 if (err < 0) {
5153 stac92xx_free(codec);
5154 return err;
Matt Porterf3302a52006-07-31 12:49:34 +02005155 }
5156
Matthew Ranostay1cd22242008-07-18 18:20:52 +02005157 spec->digbeep_nid = 0x23;
Matt Porterf3302a52006-07-31 12:49:34 +02005158 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02005159 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02005160 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01005161 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matthew Ranostayd9737752008-09-07 12:03:41 +02005162 spec->smux_nids = stac9205_smux_nids;
5163 spec->num_smuxes = ARRAY_SIZE(stac9205_smux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02005164 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02005165 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005166 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01005167 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005168 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02005169
5170 spec->init = stac9205_core_init;
5171 spec->mixer = stac9205_mixer;
5172
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005173 spec->aloopback_mask = 0x40;
5174 spec->aloopback_shift = 0;
Matthew Ranostayc0cea0d2008-11-16 11:42:34 -05005175 spec->eapd_switch = 1;
Matt Porterf3302a52006-07-31 12:49:34 +02005176 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02005177
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005178 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005179 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02005180 /* Enable SPDIF in/out */
Takashi Iwaiaf9f3412008-11-18 10:38:56 +01005181 stac_change_pin_config(codec, 0x1f, 0x01441030);
5182 stac_change_pin_config(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01005183
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005184 /* Enable unsol response for GPIO4/Dock HP connection */
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005185 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
5186 if (err < 0)
5187 return err;
Takashi Iwaic5d08bb2008-11-18 10:55:36 +01005188 snd_hda_codec_write_cache(codec, codec->afg, 0,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005189 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
5190 snd_hda_codec_write_cache(codec, codec->afg, 0,
Takashi Iwaic6e4c662008-11-25 11:58:19 +01005191 AC_VERB_SET_UNSOLICITED_ENABLE,
5192 AC_USRSP_EN | err);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005193
5194 spec->gpio_dir = 0x0b;
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005195 spec->eapd_mask = 0x01;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005196 spec->gpio_mask = 0x1b;
5197 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01005198 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005199 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02005200 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005201 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005202 break;
Matthew Ranostayb2c4f4d2008-09-26 10:06:40 -04005203 case STAC_9205_REF:
5204 /* SPDIF-In enabled */
5205 break;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005206 default:
5207 /* GPIO0 High = EAPD */
Matthew Ranostay0fc9dec2008-04-14 13:32:54 +02005208 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01005209 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02005210 break;
5211 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02005212
Matt Porterf3302a52006-07-31 12:49:34 +02005213 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01005214 if (!err) {
5215 if (spec->board_config < 0) {
5216 printk(KERN_WARNING "hda_codec: No auto-config is "
5217 "available, default to model=ref\n");
5218 spec->board_config = STAC_9205_REF;
5219 goto again;
5220 }
5221 err = -EINVAL;
5222 }
Matt Porterf3302a52006-07-31 12:49:34 +02005223 if (err < 0) {
5224 stac92xx_free(codec);
5225 return err;
5226 }
5227
5228 codec->patch_ops = stac92xx_patch_ops;
5229
Takashi Iwai2d34e1b2008-11-28 14:35:16 +01005230 codec->proc_widget_hook = stac9205_proc_hook;
5231
Matt Porterf3302a52006-07-31 12:49:34 +02005232 return 0;
5233}
5234
Matt2f2f4252005-04-13 14:45:30 +02005235/*
Guillaume Munch6d859062006-08-22 17:15:47 +02005236 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01005237 */
5238
Guillaume Munch99ccc562006-08-16 19:35:12 +02005239/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005240static hda_nid_t vaio_dacs[] = { 0x2 };
5241#define VAIO_HP_DAC 0x5
5242static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
5243static hda_nid_t vaio_mux_nids[] = { 0x15 };
5244
5245static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02005246 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01005247 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02005248 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005249 { "Mic Jack", 0x1 },
5250 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01005251 { "PCM", 0x3 },
5252 }
5253};
5254
5255static struct hda_verb vaio_init[] = {
5256 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005257 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01005258 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5259 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5260 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5261 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005262 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01005263 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5264 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5265 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5266 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5267 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5268 {}
5269};
5270
Guillaume Munch6d859062006-08-22 17:15:47 +02005271static struct hda_verb vaio_ar_init[] = {
5272 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5273 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5274 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5275 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5276/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
5277 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02005278 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02005279 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5280 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5281/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
5282 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5283 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5284 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5285 {}
5286};
5287
Takashi Iwaidb064e52006-03-16 16:04:58 +01005288static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwai127e82e2008-11-14 14:03:33 +01005289 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5290 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5291 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5292 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
Takashi Iwaidb064e52006-03-16 16:04:58 +01005293 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5294 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5295 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5296 {
5297 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5298 .name = "Capture Source",
5299 .count = 1,
5300 .info = stac92xx_mux_enum_info,
5301 .get = stac92xx_mux_enum_get,
5302 .put = stac92xx_mux_enum_put,
5303 },
5304 {}
5305};
5306
Guillaume Munch6d859062006-08-22 17:15:47 +02005307static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwai127e82e2008-11-14 14:03:33 +01005308 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5309 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5310 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5311 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
Guillaume Munch6d859062006-08-22 17:15:47 +02005312 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5313 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5314 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5315 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
5316 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
5317 {
5318 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5319 .name = "Capture Source",
5320 .count = 1,
5321 .info = stac92xx_mux_enum_info,
5322 .get = stac92xx_mux_enum_get,
5323 .put = stac92xx_mux_enum_put,
5324 },
5325 {}
5326};
5327
5328static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01005329 .build_controls = stac92xx_build_controls,
5330 .build_pcms = stac92xx_build_pcms,
5331 .init = stac92xx_init,
5332 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02005333#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01005334 .resume = stac92xx_resume,
5335#endif
5336};
5337
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005338static int stac9872_vaio_init(struct hda_codec *codec)
5339{
5340 int err;
5341
5342 err = stac92xx_init(codec);
5343 if (err < 0)
5344 return err;
5345 if (codec->patch_ops.unsol_event)
5346 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
5347 return 0;
5348}
5349
5350static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
5351{
Takashi Iwaie6e3ea22008-12-05 12:54:56 +01005352 if (get_pin_presence(codec, 0x0a)) {
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005353 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5354 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5355 } else {
5356 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5357 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5358 }
5359}
5360
5361static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
5362{
5363 switch (res >> 26) {
5364 case STAC_HP_EVENT:
5365 stac9872_vaio_hp_detect(codec, res);
5366 break;
5367 }
5368}
5369
5370static struct hda_codec_ops stac9872_vaio_patch_ops = {
5371 .build_controls = stac92xx_build_controls,
5372 .build_pcms = stac92xx_build_pcms,
5373 .init = stac9872_vaio_init,
5374 .free = stac92xx_free,
5375 .unsol_event = stac9872_vaio_unsol_event,
5376#ifdef CONFIG_PM
5377 .resume = stac92xx_resume,
5378#endif
5379};
5380
Guillaume Munch6d859062006-08-22 17:15:47 +02005381enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
5382 CXD9872RD_VAIO,
5383 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
5384 STAC9872AK_VAIO,
5385 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
5386 STAC9872K_VAIO,
5387 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005388 CXD9872AKD_VAIO,
5389 STAC_9872_MODELS,
5390};
Takashi Iwaidb064e52006-03-16 16:04:58 +01005391
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005392static const char *stac9872_models[STAC_9872_MODELS] = {
5393 [CXD9872RD_VAIO] = "vaio",
5394 [CXD9872AKD_VAIO] = "vaio-ar",
5395};
5396
5397static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5398 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
5399 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
5400 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01005401 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01005402 {}
5403};
5404
Guillaume Munch6d859062006-08-22 17:15:47 +02005405static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01005406{
5407 struct sigmatel_spec *spec;
5408 int board_config;
5409
Takashi Iwaif5fcc132006-11-24 17:07:44 +01005410 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5411 stac9872_models,
5412 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01005413 if (board_config < 0)
5414 /* unknown config, let generic-parser do its job... */
5415 return snd_hda_parse_generic_codec(codec);
5416
5417 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5418 if (spec == NULL)
5419 return -ENOMEM;
5420
5421 codec->spec = spec;
5422 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02005423 case CXD9872RD_VAIO:
5424 case STAC9872AK_VAIO:
5425 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01005426 spec->mixer = vaio_mixer;
5427 spec->init = vaio_init;
5428 spec->multiout.max_channels = 2;
5429 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5430 spec->multiout.dac_nids = vaio_dacs;
5431 spec->multiout.hp_nid = VAIO_HP_DAC;
5432 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5433 spec->adc_nids = vaio_adcs;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005434 spec->num_pwrs = 0;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005435 spec->input_mux = &vaio_mux;
5436 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005437 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005438 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02005439
5440 case CXD9872AKD_VAIO:
5441 spec->mixer = vaio_ar_mixer;
5442 spec->init = vaio_ar_init;
5443 spec->multiout.max_channels = 2;
5444 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5445 spec->multiout.dac_nids = vaio_dacs;
5446 spec->multiout.hp_nid = VAIO_HP_DAC;
5447 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01005448 spec->num_pwrs = 0;
Guillaume Munch6d859062006-08-22 17:15:47 +02005449 spec->adc_nids = vaio_adcs;
5450 spec->input_mux = &vaio_mux;
5451 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02005452 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02005453 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01005454 }
5455
Takashi Iwaidb064e52006-03-16 16:04:58 +01005456 return 0;
5457}
5458
5459
5460/*
Matt2f2f4252005-04-13 14:45:30 +02005461 * patch entries
5462 */
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005463static struct hda_codec_preset snd_hda_preset_sigmatel[] = {
Matt2f2f4252005-04-13 14:45:30 +02005464 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
5465 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
5466 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
5467 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
5468 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
5469 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
5470 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02005471 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
5472 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
5473 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
5474 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
5475 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
5476 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01005477 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
5478 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
5479 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
5480 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
5481 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
5482 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
5483 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
5484 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
5485 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
5486 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01005487 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
5488 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
5489 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
5490 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
5491 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
5492 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Takashi Iwai7bd3c0f2008-05-02 12:28:02 +02005493 { .id = 0x83847645, .name = "92HD206X", .patch = patch_stac927x },
5494 { .id = 0x83847646, .name = "92HD206D", .patch = patch_stac927x },
Guillaume Munch6d859062006-08-22 17:15:47 +02005495 /* The following does not take into account .id=0x83847661 when subsys =
5496 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
5497 * currently not fully supported.
5498 */
5499 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
5500 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
5501 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02005502 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
5503 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
5504 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
5505 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
5506 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
5507 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
5508 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
5509 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005510 { .id = 0x111d7603, .name = "92HD75B3X5", .patch = patch_stac92hd71bxx},
Matthew Ranostayd0513fc2008-07-27 10:30:30 +02005511 { .id = 0x111d7604, .name = "92HD83C1X5", .patch = patch_stac92hd83xxx},
5512 { .id = 0x111d7605, .name = "92HD81B1X5", .patch = patch_stac92hd83xxx},
Matthew Ranostayaafc4412008-06-13 18:04:33 +02005513 { .id = 0x111d7608, .name = "92HD75B2X5", .patch = patch_stac92hd71bxx},
Matthew Ranostay541eee82007-12-14 12:08:04 +01005514 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
5515 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01005516 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01005517 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5518 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
5519 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5520 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
5521 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5522 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
5523 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
5524 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02005525 {} /* terminator */
5526};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005527
5528MODULE_ALIAS("snd-hda-codec-id:8384*");
5529MODULE_ALIAS("snd-hda-codec-id:111d*");
5530
5531MODULE_LICENSE("GPL");
5532MODULE_DESCRIPTION("IDT/Sigmatel HD-audio codec");
5533
5534static struct hda_codec_preset_list sigmatel_list = {
5535 .preset = snd_hda_preset_sigmatel,
5536 .owner = THIS_MODULE,
5537};
5538
5539static int __init patch_sigmatel_init(void)
5540{
5541 return snd_hda_add_codec_preset(&sigmatel_list);
5542}
5543
5544static void __exit patch_sigmatel_exit(void)
5545{
5546 snd_hda_delete_codec_preset(&sigmatel_list);
5547}
5548
5549module_init(patch_sigmatel_init)
5550module_exit(patch_sigmatel_exit)