blob: ef86402d7e67bfc0c650041a3fad776c154695fe [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>
Matt2f2f4252005-04-13 14:45:30 +020033#include "hda_codec.h"
34#include "hda_local.h"
35
Matt4e550962005-07-04 17:51:39 +020036#define NUM_CONTROL_ALLOC 32
Matthew Ranostaya64135a2008-01-10 16:55:06 +010037#define STAC_PWR_EVENT 0x20
38#define STAC_HP_EVENT 0x30
Matt4e550962005-07-04 17:51:39 +020039
Takashi Iwaif5fcc132006-11-24 17:07:44 +010040enum {
41 STAC_REF,
Tobin Davisbf277782008-02-03 20:31:47 +010042 STAC_9200_OQO,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020043 STAC_9200_DELL_D21,
44 STAC_9200_DELL_D22,
45 STAC_9200_DELL_D23,
46 STAC_9200_DELL_M21,
47 STAC_9200_DELL_M22,
48 STAC_9200_DELL_M23,
49 STAC_9200_DELL_M24,
50 STAC_9200_DELL_M25,
51 STAC_9200_DELL_M26,
52 STAC_9200_DELL_M27,
Takashi Iwai1194b5b2007-10-10 10:04:26 +020053 STAC_9200_GATEWAY,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010054 STAC_9200_MODELS
55};
56
57enum {
58 STAC_9205_REF,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020059 STAC_9205_DELL_M42,
Tobin Davisae0a8ed2007-08-13 15:50:29 +020060 STAC_9205_DELL_M43,
61 STAC_9205_DELL_M44,
Takashi Iwaif5fcc132006-11-24 17:07:44 +010062 STAC_9205_MODELS
63};
64
65enum {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010066 STAC_92HD73XX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010067 STAC_DELL_M6,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +010068 STAC_92HD73XX_MODELS
69};
70
71enum {
Matthew Ranostaye035b842007-11-06 11:53:55 +010072 STAC_92HD71BXX_REF,
Matthew Ranostaya7662642008-02-21 07:51:14 +010073 STAC_DELL_M4_1,
74 STAC_DELL_M4_2,
Matthew Ranostaye035b842007-11-06 11:53:55 +010075 STAC_92HD71BXX_MODELS
76};
77
78enum {
Tobin Davis8e21c342007-01-08 11:04:17 +010079 STAC_925x_REF,
80 STAC_M2_2,
81 STAC_MA6,
Tobin Davis2c11f952007-05-17 09:36:34 +020082 STAC_PA6,
Tobin Davis8e21c342007-01-08 11:04:17 +010083 STAC_925x_MODELS
84};
85
86enum {
Takashi Iwaif5fcc132006-11-24 17:07:44 +010087 STAC_D945_REF,
88 STAC_D945GTP3,
89 STAC_D945GTP5,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +020090 STAC_INTEL_MAC_V1,
91 STAC_INTEL_MAC_V2,
92 STAC_INTEL_MAC_V3,
93 STAC_INTEL_MAC_V4,
94 STAC_INTEL_MAC_V5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +020095 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +010096 STAC_MACMINI,
Takashi Iwai3fc24d82007-02-16 13:27:18 +010097 STAC_MACBOOK,
Nicolas Boichat6f0778d2007-03-15 12:38:15 +010098 STAC_MACBOOK_PRO_V1,
99 STAC_MACBOOK_PRO_V2,
Sylvain FORETf16928f2007-04-27 14:22:36 +0200100 STAC_IMAC_INTEL,
Takashi Iwai0dae0f82007-05-21 12:41:29 +0200101 STAC_IMAC_INTEL_20,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200102 STAC_922X_DELL_D81,
103 STAC_922X_DELL_D82,
104 STAC_922X_DELL_M81,
105 STAC_922X_DELL_M82,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100106 STAC_922X_MODELS
107};
108
109enum {
110 STAC_D965_REF,
111 STAC_D965_3ST,
112 STAC_D965_5ST,
Tobin Davis4ff076e2007-08-07 11:48:12 +0200113 STAC_DELL_3ST,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +0100114 STAC_DELL_BIOS,
Takashi Iwaif5fcc132006-11-24 17:07:44 +0100115 STAC_927X_MODELS
116};
Matt Porter403d1942005-11-29 15:00:51 +0100117
Matt2f2f4252005-04-13 14:45:30 +0200118struct sigmatel_spec {
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100119 struct snd_kcontrol_new *mixers[4];
Mattc7d4b2f2005-06-27 14:59:41 +0200120 unsigned int num_mixers;
121
Matt Porter403d1942005-11-29 15:00:51 +0100122 int board_config;
Mattc7d4b2f2005-06-27 14:59:41 +0200123 unsigned int surr_switch: 1;
Matt Porter403d1942005-11-29 15:00:51 +0100124 unsigned int line_switch: 1;
125 unsigned int mic_switch: 1;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100126 unsigned int alt_switch: 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +0100127 unsigned int hp_detect: 1;
Mattc7d4b2f2005-06-27 14:59:41 +0200128
Matthew Ranostay4fe51952008-01-29 15:28:44 +0100129 /* gpio lines */
130 unsigned int gpio_mask;
131 unsigned int gpio_dir;
132 unsigned int gpio_data;
133 unsigned int gpio_mute;
134
135 /* analog loopback */
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100136 unsigned char aloopback_mask;
137 unsigned char aloopback_shift;
Takashi Iwai82599802007-07-31 15:56:24 +0200138
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100139 /* power management */
140 unsigned int num_pwrs;
141 hda_nid_t *pwr_nids;
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100142 hda_nid_t *dac_list;
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100143
Matt2f2f4252005-04-13 14:45:30 +0200144 /* playback */
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100145 struct hda_input_mux *mono_mux;
146 unsigned int cur_mmux;
Matt2f2f4252005-04-13 14:45:30 +0200147 struct hda_multi_out multiout;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100148 hda_nid_t dac_nids[5];
Matt2f2f4252005-04-13 14:45:30 +0200149
150 /* capture */
151 hda_nid_t *adc_nids;
Matt2f2f4252005-04-13 14:45:30 +0200152 unsigned int num_adcs;
Mattdabbed62005-06-14 10:19:34 +0200153 hda_nid_t *mux_nids;
154 unsigned int num_muxes;
Matt Porter8b657272006-10-26 17:12:59 +0200155 hda_nid_t *dmic_nids;
156 unsigned int num_dmics;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100157 hda_nid_t *dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +0100158 unsigned int num_dmuxes;
Mattdabbed62005-06-14 10:19:34 +0200159 hda_nid_t dig_in_nid;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100160 hda_nid_t mono_nid;
Matt2f2f4252005-04-13 14:45:30 +0200161
Matt2f2f4252005-04-13 14:45:30 +0200162 /* pin widgets */
163 hda_nid_t *pin_nids;
164 unsigned int num_pins;
Matt2f2f4252005-04-13 14:45:30 +0200165 unsigned int *pin_configs;
Richard Fish11b44bb2006-08-23 18:31:34 +0200166 unsigned int *bios_pin_configs;
Matt2f2f4252005-04-13 14:45:30 +0200167
168 /* codec specific stuff */
169 struct hda_verb *init;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100170 struct snd_kcontrol_new *mixer;
Matt2f2f4252005-04-13 14:45:30 +0200171
172 /* capture source */
Matt Porter8b657272006-10-26 17:12:59 +0200173 struct hda_input_mux *dinput_mux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100174 unsigned int cur_dmux[2];
Mattc7d4b2f2005-06-27 14:59:41 +0200175 struct hda_input_mux *input_mux;
Matt Porter3cc08dc2006-01-23 15:27:49 +0100176 unsigned int cur_mux[3];
Matt2f2f4252005-04-13 14:45:30 +0200177
Matt Porter403d1942005-11-29 15:00:51 +0100178 /* i/o switches */
179 unsigned int io_switch[2];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +0200180 unsigned int clfe_swap;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200181 unsigned int aloopback;
Matt2f2f4252005-04-13 14:45:30 +0200182
Mattc7d4b2f2005-06-27 14:59:41 +0200183 struct hda_pcm pcm_rec[2]; /* PCM information */
184
185 /* dynamic controls and input_mux */
186 struct auto_pin_cfg autocfg;
187 unsigned int num_kctl_alloc, num_kctl_used;
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100188 struct snd_kcontrol_new *kctl_alloc;
Matt Porter8b657272006-10-26 17:12:59 +0200189 struct hda_input_mux private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +0200190 struct hda_input_mux private_imux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100191 struct hda_input_mux private_mono_mux;
Matt2f2f4252005-04-13 14:45:30 +0200192};
193
194static hda_nid_t stac9200_adc_nids[1] = {
195 0x03,
196};
197
198static hda_nid_t stac9200_mux_nids[1] = {
199 0x0c,
200};
201
202static hda_nid_t stac9200_dac_nids[1] = {
203 0x02,
204};
205
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100206static hda_nid_t stac92hd73xx_pwr_nids[8] = {
207 0x0a, 0x0b, 0x0c, 0xd, 0x0e,
208 0x0f, 0x10, 0x11
209};
210
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100211static hda_nid_t stac92hd73xx_adc_nids[2] = {
212 0x1a, 0x1b
213};
214
215#define STAC92HD73XX_NUM_DMICS 2
216static hda_nid_t stac92hd73xx_dmic_nids[STAC92HD73XX_NUM_DMICS + 1] = {
217 0x13, 0x14, 0
218};
219
220#define STAC92HD73_DAC_COUNT 5
221static hda_nid_t stac92hd73xx_dac_nids[STAC92HD73_DAC_COUNT] = {
222 0x15, 0x16, 0x17, 0x18, 0x19,
223};
224
225static hda_nid_t stac92hd73xx_mux_nids[4] = {
226 0x28, 0x29, 0x2a, 0x2b,
227};
228
229static hda_nid_t stac92hd73xx_dmux_nids[2] = {
230 0x20, 0x21,
231};
232
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100233static hda_nid_t stac92hd71bxx_pwr_nids[3] = {
234 0x0a, 0x0d, 0x0f
235};
236
Matthew Ranostaye035b842007-11-06 11:53:55 +0100237static hda_nid_t stac92hd71bxx_adc_nids[2] = {
238 0x12, 0x13,
239};
240
241static hda_nid_t stac92hd71bxx_mux_nids[2] = {
242 0x1a, 0x1b
243};
244
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100245static hda_nid_t stac92hd71bxx_dmux_nids[1] = {
246 0x1c,
247};
248
Matthew Ranostaye035b842007-11-06 11:53:55 +0100249static hda_nid_t stac92hd71bxx_dac_nids[2] = {
250 0x10, /*0x11, */
251};
252
253#define STAC92HD71BXX_NUM_DMICS 2
254static hda_nid_t stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS + 1] = {
255 0x18, 0x19, 0
256};
257
Tobin Davis8e21c342007-01-08 11:04:17 +0100258static hda_nid_t stac925x_adc_nids[1] = {
259 0x03,
260};
261
262static hda_nid_t stac925x_mux_nids[1] = {
263 0x0f,
264};
265
266static hda_nid_t stac925x_dac_nids[1] = {
267 0x02,
268};
269
Takashi Iwaif6e98522007-10-16 14:27:04 +0200270#define STAC925X_NUM_DMICS 1
271static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
272 0x15, 0
Tobin Davis2c11f952007-05-17 09:36:34 +0200273};
274
Takashi Iwai1697055e2007-12-18 18:05:52 +0100275static hda_nid_t stac925x_dmux_nids[1] = {
276 0x14,
277};
278
Matt2f2f4252005-04-13 14:45:30 +0200279static hda_nid_t stac922x_adc_nids[2] = {
280 0x06, 0x07,
281};
282
283static hda_nid_t stac922x_mux_nids[2] = {
284 0x12, 0x13,
285};
286
Matt Porter3cc08dc2006-01-23 15:27:49 +0100287static hda_nid_t stac927x_adc_nids[3] = {
288 0x07, 0x08, 0x09
289};
290
291static hda_nid_t stac927x_mux_nids[3] = {
292 0x15, 0x16, 0x17
293};
294
Matthew Ranostayb76c8502008-02-06 14:49:44 +0100295static hda_nid_t stac927x_dac_nids[6] = {
296 0x02, 0x03, 0x04, 0x05, 0x06, 0
297};
298
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100299static hda_nid_t stac927x_dmux_nids[1] = {
300 0x1b,
301};
302
Matthew Ranostay7f168592007-10-18 17:38:17 +0200303#define STAC927X_NUM_DMICS 2
304static hda_nid_t stac927x_dmic_nids[STAC927X_NUM_DMICS + 1] = {
305 0x13, 0x14, 0
306};
307
Matt Porterf3302a52006-07-31 12:49:34 +0200308static hda_nid_t stac9205_adc_nids[2] = {
309 0x12, 0x13
310};
311
312static hda_nid_t stac9205_mux_nids[2] = {
313 0x19, 0x1a
314};
315
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100316static hda_nid_t stac9205_dmux_nids[1] = {
Takashi Iwai1697055e2007-12-18 18:05:52 +0100317 0x1d,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100318};
319
Takashi Iwaif6e98522007-10-16 14:27:04 +0200320#define STAC9205_NUM_DMICS 2
321static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
322 0x17, 0x18, 0
Matt Porter8b657272006-10-26 17:12:59 +0200323};
324
Mattc7d4b2f2005-06-27 14:59:41 +0200325static hda_nid_t stac9200_pin_nids[8] = {
Tobin Davis93ed1502006-09-01 21:03:12 +0200326 0x08, 0x09, 0x0d, 0x0e,
327 0x0f, 0x10, 0x11, 0x12,
Matt2f2f4252005-04-13 14:45:30 +0200328};
329
Tobin Davis8e21c342007-01-08 11:04:17 +0100330static hda_nid_t stac925x_pin_nids[8] = {
331 0x07, 0x08, 0x0a, 0x0b,
332 0x0c, 0x0d, 0x10, 0x11,
333};
334
Matt2f2f4252005-04-13 14:45:30 +0200335static hda_nid_t stac922x_pin_nids[10] = {
336 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
337 0x0f, 0x10, 0x11, 0x15, 0x1b,
338};
339
Matthew Ranostaya7662642008-02-21 07:51:14 +0100340static hda_nid_t stac92hd73xx_pin_nids[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100341 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
342 0x0f, 0x10, 0x11, 0x12, 0x13,
Matthew Ranostaya7662642008-02-21 07:51:14 +0100343 0x14, 0x1e, 0x22
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100344};
345
Matthew Ranostaye035b842007-11-06 11:53:55 +0100346static hda_nid_t stac92hd71bxx_pin_nids[10] = {
347 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
348 0x0f, 0x14, 0x18, 0x19, 0x1e,
349};
350
Matt Porter3cc08dc2006-01-23 15:27:49 +0100351static hda_nid_t stac927x_pin_nids[14] = {
352 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
353 0x0f, 0x10, 0x11, 0x12, 0x13,
354 0x14, 0x21, 0x22, 0x23,
355};
356
Matt Porterf3302a52006-07-31 12:49:34 +0200357static hda_nid_t stac9205_pin_nids[12] = {
358 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
359 0x0f, 0x14, 0x16, 0x17, 0x18,
360 0x21, 0x22,
Matt Porterf3302a52006-07-31 12:49:34 +0200361};
362
Matt Porter8b657272006-10-26 17:12:59 +0200363static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
364 struct snd_ctl_elem_info *uinfo)
365{
366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
367 struct sigmatel_spec *spec = codec->spec;
368 return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
369}
370
371static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
372 struct snd_ctl_elem_value *ucontrol)
373{
374 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
375 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100376 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200377
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100378 ucontrol->value.enumerated.item[0] = spec->cur_dmux[dmux_idx];
Matt Porter8b657272006-10-26 17:12:59 +0200379 return 0;
380}
381
382static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
383 struct snd_ctl_elem_value *ucontrol)
384{
385 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
386 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100387 unsigned int dmux_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Matt Porter8b657272006-10-26 17:12:59 +0200388
389 return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100390 spec->dmux_nids[dmux_idx], &spec->cur_dmux[dmux_idx]);
Matt Porter8b657272006-10-26 17:12:59 +0200391}
392
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100393static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
Matt2f2f4252005-04-13 14:45:30 +0200394{
395 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
396 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +0200397 return snd_hda_input_mux_info(spec->input_mux, uinfo);
Matt2f2f4252005-04-13 14:45:30 +0200398}
399
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100400static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200401{
402 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
403 struct sigmatel_spec *spec = codec->spec;
404 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
405
406 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
407 return 0;
408}
409
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100410static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
Matt2f2f4252005-04-13 14:45:30 +0200411{
412 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
413 struct sigmatel_spec *spec = codec->spec;
414 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
415
Mattc7d4b2f2005-06-27 14:59:41 +0200416 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
Matt2f2f4252005-04-13 14:45:30 +0200417 spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
418}
419
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100420static int stac92xx_mono_mux_enum_info(struct snd_kcontrol *kcontrol,
421 struct snd_ctl_elem_info *uinfo)
422{
423 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
424 struct sigmatel_spec *spec = codec->spec;
425 return snd_hda_input_mux_info(spec->mono_mux, uinfo);
426}
427
428static int stac92xx_mono_mux_enum_get(struct snd_kcontrol *kcontrol,
429 struct snd_ctl_elem_value *ucontrol)
430{
431 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
432 struct sigmatel_spec *spec = codec->spec;
433
434 ucontrol->value.enumerated.item[0] = spec->cur_mmux;
435 return 0;
436}
437
438static int stac92xx_mono_mux_enum_put(struct snd_kcontrol *kcontrol,
439 struct snd_ctl_elem_value *ucontrol)
440{
441 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
442 struct sigmatel_spec *spec = codec->spec;
443
444 return snd_hda_input_mux_put(codec, spec->mono_mux, ucontrol,
445 spec->mono_nid, &spec->cur_mmux);
446}
447
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200448#define stac92xx_aloopback_info snd_ctl_boolean_mono_info
449
450static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
451 struct snd_ctl_elem_value *ucontrol)
452{
453 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100454 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200455 struct sigmatel_spec *spec = codec->spec;
456
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100457 ucontrol->value.integer.value[0] = !!(spec->aloopback &
458 (spec->aloopback_mask << idx));
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200459 return 0;
460}
461
462static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
463 struct snd_ctl_elem_value *ucontrol)
464{
465 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
466 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100467 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200468 unsigned int dac_mode;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100469 unsigned int val, idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200470
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100471 idx_val = spec->aloopback_mask << idx;
472 if (ucontrol->value.integer.value[0])
473 val = spec->aloopback | idx_val;
474 else
475 val = spec->aloopback & ~idx_val;
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100476 if (spec->aloopback == val)
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200477 return 0;
478
Takashi Iwai68ea7b22007-11-15 15:54:38 +0100479 spec->aloopback = val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200480
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100481 /* Only return the bits defined by the shift value of the
482 * first two bytes of the mask
483 */
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200484 dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100485 kcontrol->private_value & 0xFFFF, 0x0);
486 dac_mode >>= spec->aloopback_shift;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200487
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100488 if (spec->aloopback & idx_val) {
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200489 snd_hda_power_up(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100490 dac_mode |= idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200491 } else {
492 snd_hda_power_down(codec);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100493 dac_mode &= ~idx_val;
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200494 }
495
496 snd_hda_codec_write_cache(codec, codec->afg, 0,
497 kcontrol->private_value >> 16, dac_mode);
498
499 return 1;
500}
501
Mattc7d4b2f2005-06-27 14:59:41 +0200502static struct hda_verb stac9200_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200503 /* set dac0mux for dac converter */
Mattc7d4b2f2005-06-27 14:59:41 +0200504 { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
Matt2f2f4252005-04-13 14:45:30 +0200505 {}
506};
507
Takashi Iwai1194b5b2007-10-10 10:04:26 +0200508static struct hda_verb stac9200_eapd_init[] = {
509 /* set dac0mux for dac converter */
510 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
511 {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
512 {}
513};
514
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100515static struct hda_verb stac92hd73xx_6ch_core_init[] = {
516 /* set master volume and direct control */
517 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
518 /* setup audio connections */
519 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
520 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
521 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
522 /* setup adcs to point to mixer */
523 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
524 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100525 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
526 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
527 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
528 /* setup import muxs */
529 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
530 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
531 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
532 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
533 {}
534};
535
536static struct hda_verb stac92hd73xx_8ch_core_init[] = {
537 /* set master volume and direct control */
538 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
539 /* setup audio connections */
540 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00},
541 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01},
542 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02},
543 /* connect hp ports to dac3 */
544 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x03},
545 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x03},
546 /* setup adcs to point to mixer */
547 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
548 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100549 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
550 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
551 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
552 /* setup import muxs */
553 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
554 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
555 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
556 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
557 {}
558};
559
560static struct hda_verb stac92hd73xx_10ch_core_init[] = {
561 /* set master volume and direct control */
562 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
563 /* setup audio connections */
564 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
565 { 0x10, AC_VERB_SET_CONNECT_SEL, 0x01 },
566 { 0x11, AC_VERB_SET_CONNECT_SEL, 0x02 },
567 /* dac3 is connected to import3 mux */
568 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb07f},
569 /* connect hp ports to dac4 */
570 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x04},
571 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x04},
572 /* setup adcs to point to mixer */
573 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
574 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100575 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
576 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
577 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
578 /* setup import muxs */
579 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
580 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
581 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
582 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x03},
583 {}
584};
585
Matthew Ranostaye035b842007-11-06 11:53:55 +0100586static struct hda_verb stac92hd71bxx_core_init[] = {
587 /* set master volume and direct control */
588 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
589 /* connect headphone jack to dac1 */
590 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100591 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
592 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
593 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
594 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
595 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostay541eee82007-12-14 12:08:04 +0100596};
597
598static struct hda_verb stac92hd71bxx_analog_core_init[] = {
599 /* set master volume and direct control */
600 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
601 /* connect headphone jack to dac1 */
602 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
Matthew Ranostay9b359472007-11-07 13:03:12 +0100603 /* connect ports 0d and 0f to audio mixer */
604 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x2},
605 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
Matthew Ranostaya64135a2008-01-10 16:55:06 +0100606 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* Speaker */
Matthew Ranostay9b359472007-11-07 13:03:12 +0100607 /* unmute dac0 input in audio mixer */
608 { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100609 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
610 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
611 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
612 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
Matthew Ranostaye035b842007-11-06 11:53:55 +0100613 {}
614};
615
Tobin Davis8e21c342007-01-08 11:04:17 +0100616static struct hda_verb stac925x_core_init[] = {
617 /* set dac0mux for dac converter */
618 { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
619 {}
620};
621
Mattc7d4b2f2005-06-27 14:59:41 +0200622static struct hda_verb stac922x_core_init[] = {
Matt2f2f4252005-04-13 14:45:30 +0200623 /* set master volume and direct control */
Mattc7d4b2f2005-06-27 14:59:41 +0200624 { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Matt2f2f4252005-04-13 14:45:30 +0200625 {}
626};
627
Tobin Davis93ed1502006-09-01 21:03:12 +0200628static struct hda_verb d965_core_init[] = {
Takashi Iwai19039bd2006-06-28 15:52:16 +0200629 /* set master volume and direct control */
Tobin Davis93ed1502006-09-01 21:03:12 +0200630 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
Takashi Iwai19039bd2006-06-28 15:52:16 +0200631 /* unmute node 0x1b */
632 { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
633 /* select node 0x03 as DAC */
634 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
635 {}
636};
637
Matt Porter3cc08dc2006-01-23 15:27:49 +0100638static struct hda_verb stac927x_core_init[] = {
639 /* set master volume and direct control */
640 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
641 {}
642};
643
Matt Porterf3302a52006-07-31 12:49:34 +0200644static struct hda_verb stac9205_core_init[] = {
645 /* set master volume and direct control */
646 { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
647 {}
648};
649
Matthew Ranostayb22b4822008-01-22 12:32:30 +0100650#define STAC_MONO_MUX \
651 { \
652 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
653 .name = "Mono Mux", \
654 .count = 1, \
655 .info = stac92xx_mono_mux_enum_info, \
656 .get = stac92xx_mono_mux_enum_get, \
657 .put = stac92xx_mono_mux_enum_put, \
658 }
659
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200660#define STAC_INPUT_SOURCE(cnt) \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200661 { \
662 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
663 .name = "Input Source", \
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200664 .count = cnt, \
Maxim Levitskyca7c5a82007-08-31 12:52:19 +0200665 .info = stac92xx_mux_enum_info, \
666 .get = stac92xx_mux_enum_get, \
667 .put = stac92xx_mux_enum_put, \
668 }
669
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100670#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200671 { \
672 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
673 .name = "Analog Loopback", \
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100674 .count = cnt, \
Maxim Levitsky5f10c4a2007-09-03 15:29:37 +0200675 .info = stac92xx_aloopback_info, \
676 .get = stac92xx_aloopback_get, \
677 .put = stac92xx_aloopback_put, \
678 .private_value = verb_read | (verb_write << 16), \
679 }
680
Takashi Iwaic8b6bf92005-11-17 14:57:47 +0100681static struct snd_kcontrol_new stac9200_mixer[] = {
Matt2f2f4252005-04-13 14:45:30 +0200682 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
683 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200684 STAC_INPUT_SOURCE(1),
Matt2f2f4252005-04-13 14:45:30 +0200685 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
686 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
Mattc7d4b2f2005-06-27 14:59:41 +0200687 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
Matt2f2f4252005-04-13 14:45:30 +0200688 { } /* end */
689};
690
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100691static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100692 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
693
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100694 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
695 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
696
697 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
698 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
699
700 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
701 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
702
703 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
704 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
705
706 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
707 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
708
709 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
710 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
711
712 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
713 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
714 { } /* end */
715};
716
717static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100718 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
719
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100720 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
721 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
722
723 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
724 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
725
726 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
727 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
728
729 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
730 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
731
732 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
733 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
734
735 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
736 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
737
738 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
739 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
740 { } /* end */
741};
742
743static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100744 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
745
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100746 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
747 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
748
749 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x21, 0x0, HDA_OUTPUT),
750 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x21, 0x0, HDA_OUTPUT),
751
752 HDA_CODEC_VOLUME("Front Mic Mixer Capture Volume", 0x1d, 0, HDA_INPUT),
753 HDA_CODEC_MUTE("Front Mic Mixer Capture Switch", 0x1d, 0, HDA_INPUT),
754
755 HDA_CODEC_VOLUME("Mic Mixer Capture Volume", 0x1d, 0x1, HDA_INPUT),
756 HDA_CODEC_MUTE("Mic Mixer Capture Switch", 0x1d, 0x1, HDA_INPUT),
757
758 HDA_CODEC_VOLUME("Line In Mixer Capture Volume", 0x1d, 0x2, HDA_INPUT),
759 HDA_CODEC_MUTE("Line In Mixer Capture Switch", 0x1d, 0x2, HDA_INPUT),
760
761 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
762 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
763
764 HDA_CODEC_VOLUME("CD Mixer Capture Volume", 0x1d, 0x4, HDA_INPUT),
765 HDA_CODEC_MUTE("CD Mixer Capture Switch", 0x1d, 0x4, HDA_INPUT),
766 { } /* end */
767};
768
Matthew Ranostay541eee82007-12-14 12:08:04 +0100769static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
Matthew Ranostaye035b842007-11-06 11:53:55 +0100770 STAC_INPUT_SOURCE(2),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100771
Matthew Ranostay9b359472007-11-07 13:03:12 +0100772 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
773 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
774 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
775
776 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
777 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
778 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
779
780 HDA_CODEC_MUTE("Analog Loopback 1", 0x17, 0x3, HDA_INPUT),
781 HDA_CODEC_MUTE("Analog Loopback 2", 0x17, 0x4, HDA_INPUT),
Matthew Ranostaye035b842007-11-06 11:53:55 +0100782 { } /* end */
783};
784
Matthew Ranostay541eee82007-12-14 12:08:04 +0100785static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
Matthew Ranostay541eee82007-12-14 12:08:04 +0100786 STAC_INPUT_SOURCE(2),
787 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
788
Matthew Ranostay541eee82007-12-14 12:08:04 +0100789 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
790 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
791 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x0, 0x1a, 0x0, HDA_OUTPUT),
792
793 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1d, 0x0, HDA_OUTPUT),
794 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1d, 0x0, HDA_OUTPUT),
795 HDA_CODEC_VOLUME_IDX("Capture Mux Volume", 0x1, 0x1b, 0x0, HDA_OUTPUT),
796 { } /* end */
797};
798
Tobin Davis8e21c342007-01-08 11:04:17 +0100799static struct snd_kcontrol_new stac925x_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200800 STAC_INPUT_SOURCE(1),
Tobin Davis8e21c342007-01-08 11:04:17 +0100801 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
802 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
803 HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
804 { } /* end */
805};
806
Takashi Iwaid1d985f2006-11-23 19:27:12 +0100807static struct snd_kcontrol_new stac9205_mixer[] = {
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200808 STAC_INPUT_SOURCE(2),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100809 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200810
811 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
812 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
813 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
814
815 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
816 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
817 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
818
819 { } /* end */
820};
821
822/* This needs to be generated dynamically based on sequence */
823static struct snd_kcontrol_new stac922x_mixer[] = {
824 STAC_INPUT_SOURCE(2),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200825 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
826 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
827 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
828
829 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
830 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
831 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
832 { } /* end */
833};
834
835
836static struct snd_kcontrol_new stac927x_mixer[] = {
837 STAC_INPUT_SOURCE(3),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +0100838 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +0200839
840 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
841 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
842 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
843
844 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
845 HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
846 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
847
848 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
849 HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
850 HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
Matt Porterf3302a52006-07-31 12:49:34 +0200851 { } /* end */
852};
853
Takashi Iwai1697055e2007-12-18 18:05:52 +0100854static struct snd_kcontrol_new stac_dmux_mixer = {
855 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
856 .name = "Digital Input Source",
857 /* count set later */
858 .info = stac92xx_dmux_enum_info,
859 .get = stac92xx_dmux_enum_get,
860 .put = stac92xx_dmux_enum_put,
861};
862
Takashi Iwai2134ea42008-01-10 16:53:55 +0100863static const char *slave_vols[] = {
864 "Front Playback Volume",
865 "Surround Playback Volume",
866 "Center Playback Volume",
867 "LFE Playback Volume",
868 "Side Playback Volume",
869 "Headphone Playback Volume",
870 "Headphone Playback Volume",
871 "Speaker Playback Volume",
872 "External Speaker Playback Volume",
873 "Speaker2 Playback Volume",
874 NULL
875};
876
877static const char *slave_sws[] = {
878 "Front Playback Switch",
879 "Surround Playback Switch",
880 "Center Playback Switch",
881 "LFE Playback Switch",
882 "Side Playback Switch",
883 "Headphone Playback Switch",
884 "Headphone Playback Switch",
885 "Speaker Playback Switch",
886 "External Speaker Playback Switch",
887 "Speaker2 Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +0100888 "IEC958 Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +0100889 NULL
890};
891
Matt2f2f4252005-04-13 14:45:30 +0200892static int stac92xx_build_controls(struct hda_codec *codec)
893{
894 struct sigmatel_spec *spec = codec->spec;
895 int err;
Mattc7d4b2f2005-06-27 14:59:41 +0200896 int i;
Matt2f2f4252005-04-13 14:45:30 +0200897
898 err = snd_hda_add_new_ctls(codec, spec->mixer);
899 if (err < 0)
900 return err;
Mattc7d4b2f2005-06-27 14:59:41 +0200901
902 for (i = 0; i < spec->num_mixers; i++) {
903 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
904 if (err < 0)
905 return err;
906 }
Takashi Iwai1697055e2007-12-18 18:05:52 +0100907 if (spec->num_dmuxes > 0) {
908 stac_dmux_mixer.count = spec->num_dmuxes;
909 err = snd_ctl_add(codec->bus->card,
910 snd_ctl_new1(&stac_dmux_mixer, codec));
911 if (err < 0)
912 return err;
913 }
Mattc7d4b2f2005-06-27 14:59:41 +0200914
Mattdabbed62005-06-14 10:19:34 +0200915 if (spec->multiout.dig_out_nid) {
916 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
917 if (err < 0)
918 return err;
Takashi Iwai9a081602008-02-12 18:37:26 +0100919 err = snd_hda_create_spdif_share_sw(codec,
920 &spec->multiout);
921 if (err < 0)
922 return err;
923 spec->multiout.share_spdif = 1;
Mattdabbed62005-06-14 10:19:34 +0200924 }
925 if (spec->dig_in_nid) {
926 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
927 if (err < 0)
928 return err;
929 }
Takashi Iwai2134ea42008-01-10 16:53:55 +0100930
931 /* if we have no master control, let's create it */
932 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100933 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +0100934 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100935 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +0100936 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +0100937 vmaster_tlv, slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +0100938 if (err < 0)
939 return err;
940 }
941 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
942 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
943 NULL, slave_sws);
944 if (err < 0)
945 return err;
946 }
947
Mattdabbed62005-06-14 10:19:34 +0200948 return 0;
Matt2f2f4252005-04-13 14:45:30 +0200949}
950
Matt Porter403d1942005-11-29 15:00:51 +0100951static unsigned int ref9200_pin_configs[8] = {
Mattdabbed62005-06-14 10:19:34 +0200952 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
Matt2f2f4252005-04-13 14:45:30 +0200953 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
954};
955
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200956/*
957 STAC 9200 pin configs for
958 102801A8
959 102801DE
960 102801E8
961*/
962static unsigned int dell9200_d21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200963 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
964 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200965};
966
967/*
968 STAC 9200 pin configs for
969 102801C0
970 102801C1
971*/
972static unsigned int dell9200_d22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200973 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
974 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200975};
976
977/*
978 STAC 9200 pin configs for
979 102801C4 (Dell Dimension E310)
980 102801C5
981 102801C7
982 102801D9
983 102801DA
984 102801E3
985*/
986static unsigned int dell9200_d23_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200987 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
988 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +0200989};
990
991
992/*
993 STAC 9200-32 pin configs for
994 102801B5 (Dell Inspiron 630m)
995 102801D8 (Dell Inspiron 640m)
996*/
997static unsigned int dell9200_m21_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +0200998 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
999 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001000};
1001
1002/*
1003 STAC 9200-32 pin configs for
1004 102801C2 (Dell Latitude D620)
1005 102801C8
1006 102801CC (Dell Latitude D820)
1007 102801D4
1008 102801D6
1009*/
1010static unsigned int dell9200_m22_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001011 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
1012 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001013};
1014
1015/*
1016 STAC 9200-32 pin configs for
1017 102801CE (Dell XPS M1710)
1018 102801CF (Dell Precision M90)
1019*/
1020static unsigned int dell9200_m23_pin_configs[8] = {
1021 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
1022 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
1023};
1024
1025/*
1026 STAC 9200-32 pin configs for
1027 102801C9
1028 102801CA
1029 102801CB (Dell Latitude 120L)
1030 102801D3
1031*/
1032static unsigned int dell9200_m24_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001033 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
1034 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001035};
1036
1037/*
1038 STAC 9200-32 pin configs for
1039 102801BD (Dell Inspiron E1505n)
1040 102801EE
1041 102801EF
1042*/
1043static unsigned int dell9200_m25_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001044 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1045 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001046};
1047
1048/*
1049 STAC 9200-32 pin configs for
1050 102801F5 (Dell Inspiron 1501)
1051 102801F6
1052*/
1053static unsigned int dell9200_m26_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001054 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
1055 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001056};
1057
1058/*
1059 STAC 9200-32
1060 102801CD (Dell Inspiron E1705/9400)
1061*/
1062static unsigned int dell9200_m27_pin_configs[8] = {
Takashi Iwaiaf6c0162007-09-05 23:46:03 +02001063 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
1064 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001065};
1066
Tobin Davisbf277782008-02-03 20:31:47 +01001067static unsigned int oqo9200_pin_configs[8] = {
1068 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1069 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1070};
1071
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001072
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001073static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1074 [STAC_REF] = ref9200_pin_configs,
Tobin Davisbf277782008-02-03 20:31:47 +01001075 [STAC_9200_OQO] = oqo9200_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001076 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1077 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1078 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
1079 [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
1080 [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
1081 [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
1082 [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
1083 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1084 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1085 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001086};
1087
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001088static const char *stac9200_models[STAC_9200_MODELS] = {
1089 [STAC_REF] = "ref",
Tobin Davisbf277782008-02-03 20:31:47 +01001090 [STAC_9200_OQO] = "oqo",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001091 [STAC_9200_DELL_D21] = "dell-d21",
1092 [STAC_9200_DELL_D22] = "dell-d22",
1093 [STAC_9200_DELL_D23] = "dell-d23",
1094 [STAC_9200_DELL_M21] = "dell-m21",
1095 [STAC_9200_DELL_M22] = "dell-m22",
1096 [STAC_9200_DELL_M23] = "dell-m23",
1097 [STAC_9200_DELL_M24] = "dell-m24",
1098 [STAC_9200_DELL_M25] = "dell-m25",
1099 [STAC_9200_DELL_M26] = "dell-m26",
1100 [STAC_9200_DELL_M27] = "dell-m27",
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001101 [STAC_9200_GATEWAY] = "gateway",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001102};
1103
1104static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1105 /* SigmaTel reference board */
1106 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1107 "DFI LanParty", STAC_REF),
Matt Portere7377072006-11-06 11:20:38 +01001108 /* Dell laptops have BIOS problem */
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001109 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1110 "unknown Dell", STAC_9200_DELL_D21),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001111 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001112 "Dell Inspiron 630m", STAC_9200_DELL_M21),
1113 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
1114 "Dell Inspiron E1505n", STAC_9200_DELL_M25),
1115 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
1116 "unknown Dell", STAC_9200_DELL_D22),
1117 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
1118 "unknown Dell", STAC_9200_DELL_D22),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001119 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001120 "Dell Latitude D620", STAC_9200_DELL_M22),
1121 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
1122 "unknown Dell", STAC_9200_DELL_D23),
1123 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
1124 "unknown Dell", STAC_9200_DELL_D23),
1125 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
1126 "unknown Dell", STAC_9200_DELL_M22),
1127 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
1128 "unknown Dell", STAC_9200_DELL_M24),
1129 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
1130 "unknown Dell", STAC_9200_DELL_M24),
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001131 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001132 "Dell Latitude 120L", STAC_9200_DELL_M24),
Cory T. Tusar877b8662007-01-30 17:30:55 +01001133 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001134 "Dell Latitude D820", STAC_9200_DELL_M22),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001135 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001136 "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
Mikael Nilsson46f02ca2007-02-13 12:46:16 +01001137 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001138 "Dell XPS M1710", STAC_9200_DELL_M23),
Takashi Iwaif0f96742007-02-14 00:59:17 +01001139 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001140 "Dell Precision M90", STAC_9200_DELL_M23),
1141 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
1142 "unknown Dell", STAC_9200_DELL_M22),
1143 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
1144 "unknown Dell", STAC_9200_DELL_M22),
Daniel T Chen8286c532007-05-15 11:46:23 +02001145 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001146 "unknown Dell", STAC_9200_DELL_M22),
Tobin Davis49c605d2007-05-17 09:38:24 +02001147 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001148 "Dell Inspiron 640m", STAC_9200_DELL_M21),
1149 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
1150 "unknown Dell", STAC_9200_DELL_D23),
1151 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
1152 "unknown Dell", STAC_9200_DELL_D23),
1153 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
1154 "unknown Dell", STAC_9200_DELL_D21),
1155 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
1156 "unknown Dell", STAC_9200_DELL_D23),
1157 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
1158 "unknown Dell", STAC_9200_DELL_D21),
1159 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
1160 "unknown Dell", STAC_9200_DELL_M25),
1161 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
1162 "unknown Dell", STAC_9200_DELL_M25),
Tobin Davis49c605d2007-05-17 09:38:24 +02001163 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001164 "Dell Inspiron 1501", STAC_9200_DELL_M26),
1165 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1166 "unknown Dell", STAC_9200_DELL_M26),
Tobin Davis49c605d2007-05-17 09:38:24 +02001167 /* Panasonic */
1168 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
Takashi Iwai1194b5b2007-10-10 10:04:26 +02001169 /* Gateway machines needs EAPD to be set on resume */
1170 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1171 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1172 STAC_9200_GATEWAY),
1173 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1174 STAC_9200_GATEWAY),
Tobin Davisbf277782008-02-03 20:31:47 +01001175 /* OQO Mobile */
1176 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
Matt Porter403d1942005-11-29 15:00:51 +01001177 {} /* terminator */
1178};
1179
Tobin Davis8e21c342007-01-08 11:04:17 +01001180static unsigned int ref925x_pin_configs[8] = {
1181 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001182 0x90a70320, 0x02214210, 0x01019020, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001183};
1184
1185static unsigned int stac925x_MA6_pin_configs[8] = {
1186 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1187 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
1188};
1189
Tobin Davis2c11f952007-05-17 09:36:34 +02001190static unsigned int stac925x_PA6_pin_configs[8] = {
1191 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
1192 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
1193};
1194
Tobin Davis8e21c342007-01-08 11:04:17 +01001195static unsigned int stac925xM2_2_pin_configs[8] = {
Steve Longerbeam7353e142007-05-29 14:36:17 +02001196 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
1197 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
Tobin Davis8e21c342007-01-08 11:04:17 +01001198};
1199
1200static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1201 [STAC_REF] = ref925x_pin_configs,
1202 [STAC_M2_2] = stac925xM2_2_pin_configs,
1203 [STAC_MA6] = stac925x_MA6_pin_configs,
Tobin Davis2c11f952007-05-17 09:36:34 +02001204 [STAC_PA6] = stac925x_PA6_pin_configs,
Tobin Davis8e21c342007-01-08 11:04:17 +01001205};
1206
1207static const char *stac925x_models[STAC_925x_MODELS] = {
1208 [STAC_REF] = "ref",
1209 [STAC_M2_2] = "m2-2",
1210 [STAC_MA6] = "m6",
Tobin Davis2c11f952007-05-17 09:36:34 +02001211 [STAC_PA6] = "pa6",
Tobin Davis8e21c342007-01-08 11:04:17 +01001212};
1213
1214static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1215 /* SigmaTel reference board */
1216 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
Tobin Davis2c11f952007-05-17 09:36:34 +02001217 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
Tobin Davis8e21c342007-01-08 11:04:17 +01001218 SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
1219 SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
1220 SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
Tobin Davis2c11f952007-05-17 09:36:34 +02001221 SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
Tobin Davis8e21c342007-01-08 11:04:17 +01001222 SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
1223 {} /* terminator */
1224};
1225
Matthew Ranostaya7662642008-02-21 07:51:14 +01001226static unsigned int ref92hd73xx_pin_configs[13] = {
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001227 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1228 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1229 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001230 0x01452050,
1231};
1232
1233static unsigned int dell_m6_pin_configs[13] = {
1234 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1235 0x03a11020, 0x03011050, 0x4f0000f0, 0x4f0000f0,
1236 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1237 0x4f0000f0,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001238};
1239
1240static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
Matthew Ranostaya7662642008-02-21 07:51:14 +01001241 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1242 [STAC_DELL_M6] = dell_m6_pin_configs,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001243};
1244
1245static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1246 [STAC_92HD73XX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001247 [STAC_DELL_M6] = "dell-m6",
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001248};
1249
1250static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1251 /* SigmaTel reference board */
1252 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001253 "DFI LanParty", STAC_92HD73XX_REF),
1254 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1255 "unknown Dell", STAC_DELL_M6),
1256 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1257 "unknown Dell", STAC_DELL_M6),
1258 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1259 "unknown Dell", STAC_DELL_M6),
1260 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1261 "unknown Dell", STAC_DELL_M6),
1262 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1263 "unknown Dell", STAC_DELL_M6),
1264 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1265 "unknown Dell", STAC_DELL_M6),
1266 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1267 "unknown Dell", STAC_DELL_M6),
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01001268 {} /* terminator */
1269};
1270
Matthew Ranostaye035b842007-11-06 11:53:55 +01001271static unsigned int ref92hd71bxx_pin_configs[10] = {
1272 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
Matthew Ranostayb22b4822008-01-22 12:32:30 +01001273 0x0181302e, 0x01114010, 0x01019020, 0x90a000f0,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001274 0x90a000f0, 0x01452050,
1275};
1276
Matthew Ranostaya7662642008-02-21 07:51:14 +01001277static unsigned int dell_m4_1_pin_configs[13] = {
1278 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1279 0x23a1902e, 0x23014250, 0x40f000f0, 0x4f0000f0,
1280 0x40f000f0, 0x4f0000f0,
1281};
1282
1283static unsigned int dell_m4_2_pin_configs[13] = {
1284 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1285 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1286 0x40f000f0, 0x044413b0,
1287};
1288
Matthew Ranostaye035b842007-11-06 11:53:55 +01001289static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1290 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
Matthew Ranostaya7662642008-02-21 07:51:14 +01001291 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1292 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
Matthew Ranostaye035b842007-11-06 11:53:55 +01001293};
1294
1295static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1296 [STAC_92HD71BXX_REF] = "ref",
Matthew Ranostaya7662642008-02-21 07:51:14 +01001297 [STAC_DELL_M4_1] = "dell-m4-1",
1298 [STAC_DELL_M4_2] = "dell-m4-2",
Matthew Ranostaye035b842007-11-06 11:53:55 +01001299};
1300
1301static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1302 /* SigmaTel reference board */
1303 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1304 "DFI LanParty", STAC_92HD71BXX_REF),
Matthew Ranostaya7662642008-02-21 07:51:14 +01001305 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1306 "unknown Dell", STAC_DELL_M4_1),
1307 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1308 "unknown Dell", STAC_DELL_M4_1),
1309 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1310 "unknown Dell", STAC_DELL_M4_1),
1311 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1312 "unknown Dell", STAC_DELL_M4_1),
1313 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1314 "unknown Dell", STAC_DELL_M4_1),
1315 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1316 "unknown Dell", STAC_DELL_M4_1),
1317 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1318 "unknown Dell", STAC_DELL_M4_1),
1319 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1320 "unknown Dell", STAC_DELL_M4_2),
1321 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1322 "unknown Dell", STAC_DELL_M4_2),
1323 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1324 "unknown Dell", STAC_DELL_M4_2),
1325 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1326 "unknown Dell", STAC_DELL_M4_2),
Matthew Ranostaye035b842007-11-06 11:53:55 +01001327 {} /* terminator */
1328};
1329
Matt Porter403d1942005-11-29 15:00:51 +01001330static unsigned int ref922x_pin_configs[10] = {
1331 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
1332 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
Matt2f2f4252005-04-13 14:45:30 +02001333 0x40000100, 0x40000100,
1334};
1335
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001336/*
1337 STAC 922X pin configs for
1338 102801A7
1339 102801AB
1340 102801A9
1341 102801D1
1342 102801D2
1343*/
1344static unsigned int dell_922x_d81_pin_configs[10] = {
1345 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1346 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
1347 0x01813122, 0x400001f2,
1348};
1349
1350/*
1351 STAC 922X pin configs for
1352 102801AC
1353 102801D0
1354*/
1355static unsigned int dell_922x_d82_pin_configs[10] = {
1356 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
1357 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
1358 0x01813122, 0x400001f1,
1359};
1360
1361/*
1362 STAC 922X pin configs for
1363 102801BF
1364*/
1365static unsigned int dell_922x_m81_pin_configs[10] = {
1366 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
1367 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
1368 0x40C003f1, 0x405003f0,
1369};
1370
1371/*
1372 STAC 9221 A1 pin configs for
1373 102801D7 (Dell XPS M1210)
1374*/
1375static unsigned int dell_922x_m82_pin_configs[10] = {
Jiang Zhe7f9310c2007-11-12 12:43:37 +01001376 0x02211211, 0x408103ff, 0x02a1123e, 0x90100310,
1377 0x408003f1, 0x0221121f, 0x03451340, 0x40c003f2,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001378 0x508003f3, 0x405003f4,
1379};
1380
Matt Porter403d1942005-11-29 15:00:51 +01001381static unsigned int d945gtp3_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001382 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
Matt Porter403d1942005-11-29 15:00:51 +01001383 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1384 0x02a19120, 0x40000100,
1385};
1386
1387static unsigned int d945gtp5_pin_configs[10] = {
Matt Porter869264c2006-01-25 19:20:50 +01001388 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
1389 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
Matt Porter403d1942005-11-29 15:00:51 +01001390 0x02a19320, 0x40000100,
1391};
1392
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001393static unsigned int intel_mac_v1_pin_configs[10] = {
1394 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
1395 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001396 0x400000fc, 0x400000fb,
1397};
1398
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001399static unsigned int intel_mac_v2_pin_configs[10] = {
1400 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1401 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
Sylvain FORETf16928f2007-04-27 14:22:36 +02001402 0x400000fc, 0x400000fb,
1403};
1404
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001405static unsigned int intel_mac_v3_pin_configs[10] = {
1406 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
1407 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
1408 0x400000fc, 0x400000fb,
1409};
1410
1411static unsigned int intel_mac_v4_pin_configs[10] = {
1412 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1413 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1414 0x400000fc, 0x400000fb,
1415};
1416
1417static unsigned int intel_mac_v5_pin_configs[10] = {
1418 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
1419 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
1420 0x400000fc, 0x400000fb,
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001421};
1422
Takashi Iwai76c08822007-06-19 12:17:42 +02001423
Takashi Iwai19039bd2006-06-28 15:52:16 +02001424static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001425 [STAC_D945_REF] = ref922x_pin_configs,
Takashi Iwai19039bd2006-06-28 15:52:16 +02001426 [STAC_D945GTP3] = d945gtp3_pin_configs,
1427 [STAC_D945GTP5] = d945gtp5_pin_configs,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001428 [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
1429 [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
1430 [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
1431 [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
1432 [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001433 /* for backward compatibility */
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001434 [STAC_MACMINI] = intel_mac_v3_pin_configs,
1435 [STAC_MACBOOK] = intel_mac_v5_pin_configs,
1436 [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
1437 [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
1438 [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
1439 [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001440 [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
1441 [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
1442 [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
1443 [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
Matt Porter403d1942005-11-29 15:00:51 +01001444};
1445
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001446static const char *stac922x_models[STAC_922X_MODELS] = {
1447 [STAC_D945_REF] = "ref",
1448 [STAC_D945GTP5] = "5stack",
1449 [STAC_D945GTP3] = "3stack",
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001450 [STAC_INTEL_MAC_V1] = "intel-mac-v1",
1451 [STAC_INTEL_MAC_V2] = "intel-mac-v2",
1452 [STAC_INTEL_MAC_V3] = "intel-mac-v3",
1453 [STAC_INTEL_MAC_V4] = "intel-mac-v4",
1454 [STAC_INTEL_MAC_V5] = "intel-mac-v5",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001455 /* for backward compatibility */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001456 [STAC_MACMINI] = "macmini",
Takashi Iwai3fc24d82007-02-16 13:27:18 +01001457 [STAC_MACBOOK] = "macbook",
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01001458 [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
1459 [STAC_MACBOOK_PRO_V2] = "macbook-pro",
Sylvain FORETf16928f2007-04-27 14:22:36 +02001460 [STAC_IMAC_INTEL] = "imac-intel",
Takashi Iwai0dae0f82007-05-21 12:41:29 +02001461 [STAC_IMAC_INTEL_20] = "imac-intel-20",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001462 [STAC_922X_DELL_D81] = "dell-d81",
1463 [STAC_922X_DELL_D82] = "dell-d82",
1464 [STAC_922X_DELL_M81] = "dell-m81",
1465 [STAC_922X_DELL_M82] = "dell-m82",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001466};
1467
1468static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1469 /* SigmaTel reference board */
1470 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1471 "DFI LanParty", STAC_D945_REF),
1472 /* Intel 945G based systems */
1473 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1474 "Intel D945G", STAC_D945GTP3),
1475 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
1476 "Intel D945G", STAC_D945GTP3),
1477 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
1478 "Intel D945G", STAC_D945GTP3),
1479 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
1480 "Intel D945G", STAC_D945GTP3),
1481 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
1482 "Intel D945G", STAC_D945GTP3),
1483 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
1484 "Intel D945G", STAC_D945GTP3),
1485 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
1486 "Intel D945G", STAC_D945GTP3),
1487 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
1488 "Intel D945G", STAC_D945GTP3),
1489 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
1490 "Intel D945G", STAC_D945GTP3),
1491 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
1492 "Intel D945G", STAC_D945GTP3),
1493 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
1494 "Intel D945G", STAC_D945GTP3),
1495 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
1496 "Intel D945G", STAC_D945GTP3),
1497 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
1498 "Intel D945G", STAC_D945GTP3),
1499 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
1500 "Intel D945G", STAC_D945GTP3),
1501 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
1502 "Intel D945G", STAC_D945GTP3),
1503 /* Intel D945G 5-stack systems */
1504 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
1505 "Intel D945G", STAC_D945GTP5),
1506 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
1507 "Intel D945G", STAC_D945GTP5),
1508 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
1509 "Intel D945G", STAC_D945GTP5),
1510 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
1511 "Intel D945G", STAC_D945GTP5),
1512 /* Intel 945P based systems */
1513 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
1514 "Intel D945P", STAC_D945GTP3),
1515 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
1516 "Intel D945P", STAC_D945GTP3),
1517 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
1518 "Intel D945P", STAC_D945GTP3),
1519 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
1520 "Intel D945P", STAC_D945GTP3),
1521 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
1522 "Intel D945P", STAC_D945GTP3),
1523 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
1524 "Intel D945P", STAC_D945GTP5),
1525 /* other systems */
1526 /* Apple Mac Mini (early 2006) */
1527 SND_PCI_QUIRK(0x8384, 0x7680,
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02001528 "Mac Mini", STAC_INTEL_MAC_V3),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001529 /* Dell systems */
1530 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
1531 "unknown Dell", STAC_922X_DELL_D81),
1532 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
1533 "unknown Dell", STAC_922X_DELL_D81),
1534 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
1535 "unknown Dell", STAC_922X_DELL_D81),
1536 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
1537 "unknown Dell", STAC_922X_DELL_D82),
1538 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
1539 "unknown Dell", STAC_922X_DELL_M81),
1540 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
1541 "unknown Dell", STAC_922X_DELL_D82),
1542 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
1543 "unknown Dell", STAC_922X_DELL_D81),
1544 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
1545 "unknown Dell", STAC_922X_DELL_D81),
1546 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
1547 "Dell XPS M1210", STAC_922X_DELL_M82),
Matt Porter403d1942005-11-29 15:00:51 +01001548 {} /* terminator */
1549};
1550
Matt Porter3cc08dc2006-01-23 15:27:49 +01001551static unsigned int ref927x_pin_configs[14] = {
Tobin Davis93ed1502006-09-01 21:03:12 +02001552 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1553 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
1554 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
1555 0x01c42190, 0x40000100,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001556};
1557
Tobin Davis93ed1502006-09-01 21:03:12 +02001558static unsigned int d965_3st_pin_configs[14] = {
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001559 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
1560 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
1561 0x40000100, 0x40000100, 0x40000100, 0x40000100,
1562 0x40000100, 0x40000100
1563};
1564
Tobin Davis93ed1502006-09-01 21:03:12 +02001565static unsigned int d965_5st_pin_configs[14] = {
1566 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
1567 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
1568 0x40000100, 0x40000100, 0x40000100, 0x01442070,
1569 0x40000100, 0x40000100
1570};
1571
Tobin Davis4ff076e2007-08-07 11:48:12 +02001572static unsigned int dell_3st_pin_configs[14] = {
1573 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
1574 0x01111212, 0x01116211, 0x01813050, 0x01112214,
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001575 0x403003fa, 0x90a60040, 0x90a60040, 0x404003fb,
Tobin Davis4ff076e2007-08-07 11:48:12 +02001576 0x40c003fc, 0x40000100
1577};
1578
Tobin Davis93ed1502006-09-01 21:03:12 +02001579static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001580 [STAC_D965_REF] = ref927x_pin_configs,
1581 [STAC_D965_3ST] = d965_3st_pin_configs,
1582 [STAC_D965_5ST] = d965_5st_pin_configs,
1583 [STAC_DELL_3ST] = dell_3st_pin_configs,
1584 [STAC_DELL_BIOS] = NULL,
Matt Porter3cc08dc2006-01-23 15:27:49 +01001585};
1586
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001587static const char *stac927x_models[STAC_927X_MODELS] = {
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001588 [STAC_D965_REF] = "ref",
1589 [STAC_D965_3ST] = "3stack",
1590 [STAC_D965_5ST] = "5stack",
1591 [STAC_DELL_3ST] = "dell-3stack",
1592 [STAC_DELL_BIOS] = "dell-bios",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001593};
1594
1595static struct snd_pci_quirk stac927x_cfg_tbl[] = {
1596 /* SigmaTel reference board */
1597 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1598 "DFI LanParty", STAC_D965_REF),
Tobin Davis81d3dbd2006-08-22 19:44:45 +02001599 /* Intel 946 based systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001600 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
1601 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
Tobin Davis93ed1502006-09-01 21:03:12 +02001602 /* 965 based 3 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001603 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
1604 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
1605 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
1606 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
1607 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
1608 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
1609 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
1610 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
1611 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
1612 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
1613 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
1614 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
1615 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
1616 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
1617 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
1618 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001619 /* Dell 3 stack systems */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001620 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001621 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
Tobin Davis4ff076e2007-08-07 11:48:12 +02001622 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
1623 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001624 /* Dell 3 stack systems with verb table in BIOS */
Matthew Ranostay2f32d902008-01-10 13:06:26 +01001625 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_DELL_BIOS),
1626 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0227, "Dell Vostro 1400 ", STAC_DELL_BIOS),
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01001627 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022f, "Dell ", STAC_DELL_BIOS),
1628 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x022e, "Dell ", STAC_DELL_BIOS),
1629 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0242, "Dell ", STAC_DELL_BIOS),
1630 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0243, "Dell ", STAC_DELL_BIOS),
1631 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
1632 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
Tobin Davis93ed1502006-09-01 21:03:12 +02001633 /* 965 based 5 stack systems */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001634 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
1635 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
1636 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
1637 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
1638 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
1639 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
1640 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
1641 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
1642 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
Matt Porter3cc08dc2006-01-23 15:27:49 +01001643 {} /* terminator */
1644};
1645
Matt Porterf3302a52006-07-31 12:49:34 +02001646static unsigned int ref9205_pin_configs[12] = {
1647 0x40000100, 0x40000100, 0x01016011, 0x01014010,
Matthew Ranostay09a99952008-01-24 11:49:21 +01001648 0x01813122, 0x01a19021, 0x01019020, 0x40000100,
Matt Porter8b657272006-10-26 17:12:59 +02001649 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
Matt Porterf3302a52006-07-31 12:49:34 +02001650};
1651
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001652/*
1653 STAC 9205 pin configs for
1654 102801F1
1655 102801F2
1656 102801FC
1657 102801FD
1658 10280204
1659 1028021F
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01001660 10280228 (Dell Vostro 1500)
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001661*/
1662static unsigned int dell_9205_m42_pin_configs[12] = {
1663 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
1664 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
1665 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
1666};
1667
1668/*
1669 STAC 9205 pin configs for
1670 102801F9
1671 102801FA
1672 102801FE
1673 102801FF (Dell Precision M4300)
1674 10280206
1675 10280200
1676 10280201
1677*/
1678static unsigned int dell_9205_m43_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001679 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
1680 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
1681 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
1682};
1683
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001684static unsigned int dell_9205_m44_pin_configs[12] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001685 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
1686 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
1687 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
1688};
1689
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001690static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001691 [STAC_9205_REF] = ref9205_pin_configs,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001692 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
1693 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
1694 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
Matt Porterf3302a52006-07-31 12:49:34 +02001695};
1696
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001697static const char *stac9205_models[STAC_9205_MODELS] = {
1698 [STAC_9205_REF] = "ref",
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001699 [STAC_9205_DELL_M42] = "dell-m42",
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001700 [STAC_9205_DELL_M43] = "dell-m43",
1701 [STAC_9205_DELL_M44] = "dell-m44",
Takashi Iwaif5fcc132006-11-24 17:07:44 +01001702};
1703
1704static struct snd_pci_quirk stac9205_cfg_tbl[] = {
1705 /* SigmaTel reference board */
1706 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1707 "DFI LanParty", STAC_9205_REF),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001708 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1709 "unknown Dell", STAC_9205_DELL_M42),
1710 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1711 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001712 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
Matthew Ranostayb44ef2f2007-09-18 00:52:38 +02001713 "Dell Precision", STAC_9205_DELL_M43),
1714 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
1715 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001716 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
1717 "Dell Precision", STAC_9205_DELL_M43),
Matthew Ranostaye45e4592007-09-10 23:09:42 +02001718 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
1719 "Dell Precision", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001720 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
1721 "Dell Precision", STAC_9205_DELL_M43),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001722 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1723 "unknown Dell", STAC_9205_DELL_M42),
1724 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1725 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001726 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
1727 "Dell Precision", STAC_9205_DELL_M43),
1728 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001729 "Dell Precision M4300", STAC_9205_DELL_M43),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001730 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
1731 "Dell Precision", STAC_9205_DELL_M43),
1732 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
1733 "Dell Inspiron", STAC_9205_DELL_M44),
1734 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
1735 "Dell Inspiron", STAC_9205_DELL_M44),
1736 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
1737 "Dell Inspiron", STAC_9205_DELL_M44),
1738 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
1739 "Dell Inspiron", STAC_9205_DELL_M44),
Takashi Iwaidfe495d2007-08-23 19:04:28 +02001740 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
1741 "unknown Dell", STAC_9205_DELL_M42),
Tobin Davisae0a8ed2007-08-13 15:50:29 +02001742 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
1743 "Dell Inspiron", STAC_9205_DELL_M44),
Matthew Ranostay3fa2ef72008-01-11 11:39:06 +01001744 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
1745 "Dell Vostro 1500", STAC_9205_DELL_M42),
Matt Porterf3302a52006-07-31 12:49:34 +02001746 {} /* terminator */
1747};
1748
Richard Fish11b44bb2006-08-23 18:31:34 +02001749static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
1750{
1751 int i;
1752 struct sigmatel_spec *spec = codec->spec;
1753
1754 if (! spec->bios_pin_configs) {
1755 spec->bios_pin_configs = kcalloc(spec->num_pins,
1756 sizeof(*spec->bios_pin_configs), GFP_KERNEL);
1757 if (! spec->bios_pin_configs)
1758 return -ENOMEM;
1759 }
1760
1761 for (i = 0; i < spec->num_pins; i++) {
1762 hda_nid_t nid = spec->pin_nids[i];
1763 unsigned int pin_cfg;
1764
1765 pin_cfg = snd_hda_codec_read(codec, nid, 0,
1766 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
1767 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
1768 nid, pin_cfg);
1769 spec->bios_pin_configs[i] = pin_cfg;
1770 }
1771
1772 return 0;
1773}
1774
Matthew Ranostay87d48362007-07-17 11:52:24 +02001775static void stac92xx_set_config_reg(struct hda_codec *codec,
1776 hda_nid_t pin_nid, unsigned int pin_config)
1777{
1778 int i;
1779 snd_hda_codec_write(codec, pin_nid, 0,
1780 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
1781 pin_config & 0x000000ff);
1782 snd_hda_codec_write(codec, pin_nid, 0,
1783 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
1784 (pin_config & 0x0000ff00) >> 8);
1785 snd_hda_codec_write(codec, pin_nid, 0,
1786 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
1787 (pin_config & 0x00ff0000) >> 16);
1788 snd_hda_codec_write(codec, pin_nid, 0,
1789 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1790 pin_config >> 24);
1791 i = snd_hda_codec_read(codec, pin_nid, 0,
1792 AC_VERB_GET_CONFIG_DEFAULT,
1793 0x00);
1794 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
1795 pin_nid, i);
1796}
1797
Matt2f2f4252005-04-13 14:45:30 +02001798static void stac92xx_set_config_regs(struct hda_codec *codec)
1799{
1800 int i;
1801 struct sigmatel_spec *spec = codec->spec;
Matt2f2f4252005-04-13 14:45:30 +02001802
Matthew Ranostay87d48362007-07-17 11:52:24 +02001803 if (!spec->pin_configs)
1804 return;
Richard Fish11b44bb2006-08-23 18:31:34 +02001805
Matthew Ranostay87d48362007-07-17 11:52:24 +02001806 for (i = 0; i < spec->num_pins; i++)
1807 stac92xx_set_config_reg(codec, spec->pin_nids[i],
1808 spec->pin_configs[i]);
Matt2f2f4252005-04-13 14:45:30 +02001809}
Matt2f2f4252005-04-13 14:45:30 +02001810
Matt2f2f4252005-04-13 14:45:30 +02001811/*
1812 * Analog playback callbacks
1813 */
1814static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1815 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001816 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001817{
1818 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01001819 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1820 hinfo);
Matt2f2f4252005-04-13 14:45:30 +02001821}
1822
1823static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1824 struct hda_codec *codec,
1825 unsigned int stream_tag,
1826 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001827 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001828{
1829 struct sigmatel_spec *spec = codec->spec;
Matt Porter403d1942005-11-29 15:00:51 +01001830 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
Matt2f2f4252005-04-13 14:45:30 +02001831}
1832
1833static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
1834 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001835 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001836{
1837 struct sigmatel_spec *spec = codec->spec;
1838 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1839}
1840
1841/*
Mattdabbed62005-06-14 10:19:34 +02001842 * Digital playback callbacks
1843 */
1844static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
1845 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001846 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001847{
1848 struct sigmatel_spec *spec = codec->spec;
1849 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1850}
1851
1852static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
1853 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001854 struct snd_pcm_substream *substream)
Mattdabbed62005-06-14 10:19:34 +02001855{
1856 struct sigmatel_spec *spec = codec->spec;
1857 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1858}
1859
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001860static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
1861 struct hda_codec *codec,
1862 unsigned int stream_tag,
1863 unsigned int format,
1864 struct snd_pcm_substream *substream)
1865{
1866 struct sigmatel_spec *spec = codec->spec;
1867 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1868 stream_tag, format, substream);
1869}
1870
Mattdabbed62005-06-14 10:19:34 +02001871
1872/*
Matt2f2f4252005-04-13 14:45:30 +02001873 * Analog capture callbacks
1874 */
1875static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
1876 struct hda_codec *codec,
1877 unsigned int stream_tag,
1878 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001879 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001880{
1881 struct sigmatel_spec *spec = codec->spec;
1882
1883 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
1884 stream_tag, 0, format);
1885 return 0;
1886}
1887
1888static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1889 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001890 struct snd_pcm_substream *substream)
Matt2f2f4252005-04-13 14:45:30 +02001891{
1892 struct sigmatel_spec *spec = codec->spec;
1893
1894 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
1895 return 0;
1896}
1897
Mattdabbed62005-06-14 10:19:34 +02001898static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
1899 .substreams = 1,
1900 .channels_min = 2,
1901 .channels_max = 2,
1902 /* NID is set in stac92xx_build_pcms */
1903 .ops = {
1904 .open = stac92xx_dig_playback_pcm_open,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001905 .close = stac92xx_dig_playback_pcm_close,
1906 .prepare = stac92xx_dig_playback_pcm_prepare
Mattdabbed62005-06-14 10:19:34 +02001907 },
1908};
1909
1910static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
1911 .substreams = 1,
1912 .channels_min = 2,
1913 .channels_max = 2,
1914 /* NID is set in stac92xx_build_pcms */
1915};
1916
Matt2f2f4252005-04-13 14:45:30 +02001917static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
1918 .substreams = 1,
1919 .channels_min = 2,
Mattc7d4b2f2005-06-27 14:59:41 +02001920 .channels_max = 8,
Matt2f2f4252005-04-13 14:45:30 +02001921 .nid = 0x02, /* NID to query formats and rates */
1922 .ops = {
1923 .open = stac92xx_playback_pcm_open,
1924 .prepare = stac92xx_playback_pcm_prepare,
1925 .cleanup = stac92xx_playback_pcm_cleanup
1926 },
1927};
1928
Matt Porter3cc08dc2006-01-23 15:27:49 +01001929static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
1930 .substreams = 1,
1931 .channels_min = 2,
1932 .channels_max = 2,
1933 .nid = 0x06, /* NID to query formats and rates */
1934 .ops = {
1935 .open = stac92xx_playback_pcm_open,
1936 .prepare = stac92xx_playback_pcm_prepare,
1937 .cleanup = stac92xx_playback_pcm_cleanup
1938 },
1939};
1940
Matt2f2f4252005-04-13 14:45:30 +02001941static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
Matt2f2f4252005-04-13 14:45:30 +02001942 .channels_min = 2,
1943 .channels_max = 2,
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001944 /* NID + .substreams is set in stac92xx_build_pcms */
Matt2f2f4252005-04-13 14:45:30 +02001945 .ops = {
1946 .prepare = stac92xx_capture_pcm_prepare,
1947 .cleanup = stac92xx_capture_pcm_cleanup
1948 },
1949};
1950
1951static int stac92xx_build_pcms(struct hda_codec *codec)
1952{
1953 struct sigmatel_spec *spec = codec->spec;
1954 struct hda_pcm *info = spec->pcm_rec;
1955
1956 codec->num_pcms = 1;
1957 codec->pcm_info = info;
1958
Mattc7d4b2f2005-06-27 14:59:41 +02001959 info->name = "STAC92xx Analog";
Matt2f2f4252005-04-13 14:45:30 +02001960 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
Matt2f2f4252005-04-13 14:45:30 +02001961 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001962 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02001963 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
Matt Porter3cc08dc2006-01-23 15:27:49 +01001964
1965 if (spec->alt_switch) {
1966 codec->num_pcms++;
1967 info++;
1968 info->name = "STAC92xx Analog Alt";
1969 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
1970 }
Matt2f2f4252005-04-13 14:45:30 +02001971
Mattdabbed62005-06-14 10:19:34 +02001972 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1973 codec->num_pcms++;
1974 info++;
1975 info->name = "STAC92xx Digital";
Takashi Iwai7ba72ba2008-02-06 14:03:20 +01001976 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Mattdabbed62005-06-14 10:19:34 +02001977 if (spec->multiout.dig_out_nid) {
1978 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1979 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
1980 }
1981 if (spec->dig_in_nid) {
1982 info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
1983 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
1984 }
1985 }
1986
Matt2f2f4252005-04-13 14:45:30 +02001987 return 0;
1988}
1989
Takashi Iwaic960a032006-03-23 17:06:28 +01001990static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
1991{
1992 unsigned int pincap = snd_hda_param_read(codec, nid,
1993 AC_PAR_PIN_CAP);
1994 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
1995 if (pincap & AC_PINCAP_VREF_100)
1996 return AC_PINCTL_VREF_100;
1997 if (pincap & AC_PINCAP_VREF_80)
1998 return AC_PINCTL_VREF_80;
1999 if (pincap & AC_PINCAP_VREF_50)
2000 return AC_PINCTL_VREF_50;
2001 if (pincap & AC_PINCAP_VREF_GRD)
2002 return AC_PINCTL_VREF_GRD;
2003 return 0;
2004}
2005
Matt Porter403d1942005-11-29 15:00:51 +01002006static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
2007
2008{
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002009 snd_hda_codec_write_cache(codec, nid, 0,
2010 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
Matt Porter403d1942005-11-29 15:00:51 +01002011}
2012
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002013#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
Matt Porter403d1942005-11-29 15:00:51 +01002014
2015static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2016{
2017 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2018 struct sigmatel_spec *spec = codec->spec;
2019 int io_idx = kcontrol-> private_value & 0xff;
2020
2021 ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
2022 return 0;
2023}
2024
2025static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2026{
2027 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2028 struct sigmatel_spec *spec = codec->spec;
2029 hda_nid_t nid = kcontrol->private_value >> 8;
2030 int io_idx = kcontrol-> private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002031 unsigned short val = !!ucontrol->value.integer.value[0];
Matt Porter403d1942005-11-29 15:00:51 +01002032
2033 spec->io_switch[io_idx] = val;
2034
2035 if (val)
2036 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
Takashi Iwaic960a032006-03-23 17:06:28 +01002037 else {
2038 unsigned int pinctl = AC_PINCTL_IN_EN;
2039 if (io_idx) /* set VREF for mic */
2040 pinctl |= stac92xx_get_vref(codec, nid);
2041 stac92xx_auto_set_pinctl(codec, nid, pinctl);
2042 }
Jiang Zhe40c1d302007-11-12 13:05:16 +01002043
2044 /* check the auto-mute again: we need to mute/unmute the speaker
2045 * appropriately according to the pin direction
2046 */
2047 if (spec->hp_detect)
2048 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2049
Matt Porter403d1942005-11-29 15:00:51 +01002050 return 1;
2051}
2052
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002053#define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
2054
2055static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
2056 struct snd_ctl_elem_value *ucontrol)
2057{
2058 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2059 struct sigmatel_spec *spec = codec->spec;
2060
2061 ucontrol->value.integer.value[0] = spec->clfe_swap;
2062 return 0;
2063}
2064
2065static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
2066 struct snd_ctl_elem_value *ucontrol)
2067{
2068 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2069 struct sigmatel_spec *spec = codec->spec;
2070 hda_nid_t nid = kcontrol->private_value & 0xff;
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002071 unsigned int val = !!ucontrol->value.integer.value[0];
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002072
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002073 if (spec->clfe_swap == val)
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002074 return 0;
2075
Takashi Iwai68ea7b22007-11-15 15:54:38 +01002076 spec->clfe_swap = val;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002077
2078 snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
2079 spec->clfe_swap ? 0x4 : 0x0);
2080
2081 return 1;
2082}
2083
Matt Porter403d1942005-11-29 15:00:51 +01002084#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2085 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2086 .name = xname, \
2087 .index = 0, \
2088 .info = stac92xx_io_switch_info, \
2089 .get = stac92xx_io_switch_get, \
2090 .put = stac92xx_io_switch_put, \
2091 .private_value = xpval, \
2092 }
2093
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002094#define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
2095 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2096 .name = xname, \
2097 .index = 0, \
2098 .info = stac92xx_clfe_switch_info, \
2099 .get = stac92xx_clfe_switch_get, \
2100 .put = stac92xx_clfe_switch_put, \
2101 .private_value = xpval, \
2102 }
Matt Porter403d1942005-11-29 15:00:51 +01002103
Mattc7d4b2f2005-06-27 14:59:41 +02002104enum {
2105 STAC_CTL_WIDGET_VOL,
2106 STAC_CTL_WIDGET_MUTE,
Matthew Ranostay09a99952008-01-24 11:49:21 +01002107 STAC_CTL_WIDGET_MONO_MUX,
Matt Porter403d1942005-11-29 15:00:51 +01002108 STAC_CTL_WIDGET_IO_SWITCH,
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002109 STAC_CTL_WIDGET_CLFE_SWITCH
Mattc7d4b2f2005-06-27 14:59:41 +02002110};
2111
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002112static struct snd_kcontrol_new stac92xx_control_templates[] = {
Mattc7d4b2f2005-06-27 14:59:41 +02002113 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2114 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Matthew Ranostay09a99952008-01-24 11:49:21 +01002115 STAC_MONO_MUX,
Matt Porter403d1942005-11-29 15:00:51 +01002116 STAC_CODEC_IO_SWITCH(NULL, 0),
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002117 STAC_CODEC_CLFE_SWITCH(NULL, 0),
Mattc7d4b2f2005-06-27 14:59:41 +02002118};
2119
2120/* add dynamic controls */
2121static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
2122{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002123 struct snd_kcontrol_new *knew;
Mattc7d4b2f2005-06-27 14:59:41 +02002124
2125 if (spec->num_kctl_used >= spec->num_kctl_alloc) {
2126 int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
2127
2128 knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
2129 if (! knew)
2130 return -ENOMEM;
2131 if (spec->kctl_alloc) {
2132 memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
2133 kfree(spec->kctl_alloc);
2134 }
2135 spec->kctl_alloc = knew;
2136 spec->num_kctl_alloc = num;
2137 }
2138
2139 knew = &spec->kctl_alloc[spec->num_kctl_used];
2140 *knew = stac92xx_control_templates[type];
Takashi Iwai82fe0c52005-06-30 10:54:33 +02002141 knew->name = kstrdup(name, GFP_KERNEL);
Mattc7d4b2f2005-06-27 14:59:41 +02002142 if (! knew->name)
2143 return -ENOMEM;
2144 knew->private_value = val;
2145 spec->num_kctl_used++;
2146 return 0;
2147}
2148
Matt Porter403d1942005-11-29 15:00:51 +01002149/* flag inputs as additional dynamic lineouts */
2150static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
2151{
2152 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002153 unsigned int wcaps, wtype;
2154 int i, num_dacs = 0;
2155
2156 /* use the wcaps cache to count all DACs available for line-outs */
2157 for (i = 0; i < codec->num_nodes; i++) {
2158 wcaps = codec->wcaps[i];
2159 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01002160
Steve Longerbeam7b043892007-05-03 20:50:03 +02002161 if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
2162 num_dacs++;
2163 }
Matt Porter403d1942005-11-29 15:00:51 +01002164
Steve Longerbeam7b043892007-05-03 20:50:03 +02002165 snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
2166
Matt Porter403d1942005-11-29 15:00:51 +01002167 switch (cfg->line_outs) {
2168 case 3:
2169 /* add line-in as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002170 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002171 cfg->line_out_pins[cfg->line_outs] =
2172 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002173 spec->line_switch = 1;
2174 cfg->line_outs++;
2175 }
2176 break;
2177 case 2:
2178 /* add line-in as clfe and mic as side */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002179 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002180 cfg->line_out_pins[cfg->line_outs] =
2181 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002182 spec->line_switch = 1;
2183 cfg->line_outs++;
2184 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002185 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002186 cfg->line_out_pins[cfg->line_outs] =
2187 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002188 spec->mic_switch = 1;
2189 cfg->line_outs++;
2190 }
2191 break;
2192 case 1:
2193 /* add line-in as surr and mic as clfe */
Steve Longerbeam7b043892007-05-03 20:50:03 +02002194 if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002195 cfg->line_out_pins[cfg->line_outs] =
2196 cfg->input_pins[AUTO_PIN_LINE];
Matt Porter403d1942005-11-29 15:00:51 +01002197 spec->line_switch = 1;
2198 cfg->line_outs++;
2199 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002200 if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
Takashi Iwaic480f792007-09-03 09:43:38 +02002201 cfg->line_out_pins[cfg->line_outs] =
2202 cfg->input_pins[AUTO_PIN_MIC];
Matt Porter403d1942005-11-29 15:00:51 +01002203 spec->mic_switch = 1;
2204 cfg->line_outs++;
2205 }
2206 break;
2207 }
2208
2209 return 0;
2210}
2211
Steve Longerbeam7b043892007-05-03 20:50:03 +02002212
2213static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2214{
2215 int i;
2216
2217 for (i = 0; i < spec->multiout.num_dacs; i++) {
2218 if (spec->multiout.dac_nids[i] == nid)
2219 return 1;
2220 }
2221
2222 return 0;
2223}
2224
Matt Porter3cc08dc2006-01-23 15:27:49 +01002225/*
Steve Longerbeam7b043892007-05-03 20:50:03 +02002226 * Fill in the dac_nids table from the parsed pin configuration
2227 * This function only works when every pin in line_out_pins[]
2228 * contains atleast one DAC in its connection list. Some 92xx
2229 * codecs are not connected directly to a DAC, such as the 9200
2230 * and 9202/925x. For those, dac_nids[] must be hard-coded.
Matt Porter3cc08dc2006-01-23 15:27:49 +01002231 */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002232static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
Takashi Iwaidf802952007-07-02 19:18:00 +02002233 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002234{
2235 struct sigmatel_spec *spec = codec->spec;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002236 int i, j, conn_len = 0;
2237 hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
2238 unsigned int wcaps, wtype;
2239
Mattc7d4b2f2005-06-27 14:59:41 +02002240 for (i = 0; i < cfg->line_outs; i++) {
2241 nid = cfg->line_out_pins[i];
Steve Longerbeam7b043892007-05-03 20:50:03 +02002242 conn_len = snd_hda_get_connections(codec, nid, conn,
2243 HDA_MAX_CONNECTIONS);
2244 for (j = 0; j < conn_len; j++) {
2245 wcaps = snd_hda_param_read(codec, conn[j],
2246 AC_PAR_AUDIO_WIDGET_CAP);
2247 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
Steve Longerbeam7b043892007-05-03 20:50:03 +02002248 if (wtype != AC_WID_AUD_OUT ||
2249 (wcaps & AC_WCAP_DIGITAL))
2250 continue;
2251 /* conn[j] is a DAC routed to this line-out */
2252 if (!is_in_dac_nids(spec, conn[j]))
2253 break;
2254 }
2255
2256 if (j == conn_len) {
Takashi Iwaidf802952007-07-02 19:18:00 +02002257 if (spec->multiout.num_dacs > 0) {
2258 /* we have already working output pins,
2259 * so let's drop the broken ones again
2260 */
2261 cfg->line_outs = spec->multiout.num_dacs;
2262 break;
2263 }
Steve Longerbeam7b043892007-05-03 20:50:03 +02002264 /* error out, no available DAC found */
2265 snd_printk(KERN_ERR
2266 "%s: No available DAC for pin 0x%x\n",
2267 __func__, nid);
2268 return -ENODEV;
2269 }
2270
2271 spec->multiout.dac_nids[i] = conn[j];
2272 spec->multiout.num_dacs++;
2273 if (conn_len > 1) {
2274 /* select this DAC in the pin's input mux */
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002275 snd_hda_codec_write_cache(codec, nid, 0,
2276 AC_VERB_SET_CONNECT_SEL, j);
Steve Longerbeam7b043892007-05-03 20:50:03 +02002277
2278 }
Mattc7d4b2f2005-06-27 14:59:41 +02002279 }
2280
Steve Longerbeam7b043892007-05-03 20:50:03 +02002281 snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2282 spec->multiout.num_dacs,
2283 spec->multiout.dac_nids[0],
2284 spec->multiout.dac_nids[1],
2285 spec->multiout.dac_nids[2],
2286 spec->multiout.dac_nids[3],
2287 spec->multiout.dac_nids[4]);
Mattc7d4b2f2005-06-27 14:59:41 +02002288 return 0;
2289}
2290
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002291/* create volume control/switch for the given prefx type */
2292static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
2293{
2294 char name[32];
2295 int err;
2296
2297 sprintf(name, "%s Playback Volume", pfx);
2298 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
2299 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2300 if (err < 0)
2301 return err;
2302 sprintf(name, "%s Playback Switch", pfx);
2303 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
2304 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
2305 if (err < 0)
2306 return err;
2307 return 0;
2308}
2309
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002310static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2311{
2312 if (!spec->multiout.hp_nid)
2313 spec->multiout.hp_nid = nid;
2314 else if (spec->multiout.num_dacs > 4) {
2315 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2316 return 1;
2317 } else {
2318 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2319 spec->multiout.num_dacs++;
2320 }
2321 return 0;
2322}
2323
2324static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2325{
2326 if (is_in_dac_nids(spec, nid))
2327 return 1;
2328 if (spec->multiout.hp_nid == nid)
2329 return 1;
2330 return 0;
2331}
2332
Mattc7d4b2f2005-06-27 14:59:41 +02002333/* add playback controls from the parsed DAC table */
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002334static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai19039bd2006-06-28 15:52:16 +02002335 const struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002336{
Takashi Iwai19039bd2006-06-28 15:52:16 +02002337 static const char *chname[4] = {
2338 "Front", "Surround", NULL /*CLFE*/, "Side"
2339 };
Mattc7d4b2f2005-06-27 14:59:41 +02002340 hda_nid_t nid;
2341 int i, err;
2342
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002343 struct sigmatel_spec *spec = codec->spec;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002344 unsigned int wid_caps, pincap;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002345
2346
Mattc7d4b2f2005-06-27 14:59:41 +02002347 for (i = 0; i < cfg->line_outs; i++) {
Matt Porter403d1942005-11-29 15:00:51 +01002348 if (!spec->multiout.dac_nids[i])
Mattc7d4b2f2005-06-27 14:59:41 +02002349 continue;
2350
2351 nid = spec->multiout.dac_nids[i];
2352
2353 if (i == 2) {
2354 /* Center/LFE */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002355 err = create_controls(spec, "Center", nid, 1);
2356 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002357 return err;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002358 err = create_controls(spec, "LFE", nid, 2);
2359 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002360 return err;
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002361
2362 wid_caps = get_wcaps(codec, nid);
2363
2364 if (wid_caps & AC_WCAP_LR_SWAP) {
2365 err = stac92xx_add_control(spec,
2366 STAC_CTL_WIDGET_CLFE_SWITCH,
2367 "Swap Center/LFE Playback Switch", nid);
2368
2369 if (err < 0)
2370 return err;
2371 }
2372
Mattc7d4b2f2005-06-27 14:59:41 +02002373 } else {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002374 err = create_controls(spec, chname[i], nid, 3);
2375 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002376 return err;
2377 }
2378 }
2379
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002380 if (spec->line_switch) {
2381 nid = cfg->input_pins[AUTO_PIN_LINE];
2382 pincap = snd_hda_param_read(codec, nid,
2383 AC_PAR_PIN_CAP);
2384 if (pincap & AC_PINCAP_OUT) {
2385 err = stac92xx_add_control(spec,
2386 STAC_CTL_WIDGET_IO_SWITCH,
2387 "Line In as Output Switch", nid << 8);
2388 if (err < 0)
2389 return err;
2390 }
2391 }
Matt Porter403d1942005-11-29 15:00:51 +01002392
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002393 if (spec->mic_switch) {
Matthew Ranostaycace16f2008-01-30 14:58:38 +01002394 unsigned int def_conf;
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002395 unsigned int mic_pin = AUTO_PIN_MIC;
2396again:
2397 nid = cfg->input_pins[mic_pin];
Matthew Ranostaycace16f2008-01-30 14:58:38 +01002398 def_conf = snd_hda_codec_read(codec, nid, 0,
2399 AC_VERB_GET_CONFIG_DEFAULT, 0);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01002400 /* some laptops have an internal analog microphone
2401 * which can't be used as a output */
2402 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2403 pincap = snd_hda_param_read(codec, nid,
2404 AC_PAR_PIN_CAP);
2405 if (pincap & AC_PINCAP_OUT) {
2406 err = stac92xx_add_control(spec,
2407 STAC_CTL_WIDGET_IO_SWITCH,
2408 "Mic as Output Switch", (nid << 8) | 1);
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002409 nid = snd_hda_codec_read(codec, nid, 0,
2410 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2411 if (!check_in_dac_nids(spec, nid))
2412 add_spec_dacs(spec, nid);
Matthew Ranostaycace16f2008-01-30 14:58:38 +01002413 if (err < 0)
2414 return err;
2415 }
Matthew Ranostayae0afd82008-02-22 17:55:05 +01002416 } else if (mic_pin == AUTO_PIN_MIC) {
2417 mic_pin = AUTO_PIN_FRONT_MIC;
2418 goto again;
Matthew Ranostayb5895dc2008-01-25 15:24:50 +01002419 }
2420 }
Matt Porter403d1942005-11-29 15:00:51 +01002421
Mattc7d4b2f2005-06-27 14:59:41 +02002422 return 0;
2423}
2424
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002425/* add playback controls for Speaker and HP outputs */
2426static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2427 struct auto_pin_cfg *cfg)
Mattc7d4b2f2005-06-27 14:59:41 +02002428{
2429 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002430 hda_nid_t nid;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002431 int i, old_num_dacs, err;
Mattc7d4b2f2005-06-27 14:59:41 +02002432
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002433 old_num_dacs = spec->multiout.num_dacs;
2434 for (i = 0; i < cfg->hp_outs; i++) {
2435 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
2436 if (wid_caps & AC_WCAP_UNSOL_CAP)
2437 spec->hp_detect = 1;
2438 nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
2439 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2440 if (check_in_dac_nids(spec, nid))
2441 nid = 0;
2442 if (! nid)
Mattc7d4b2f2005-06-27 14:59:41 +02002443 continue;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002444 add_spec_dacs(spec, nid);
2445 }
2446 for (i = 0; i < cfg->speaker_outs; i++) {
Steve Longerbeam7b043892007-05-03 20:50:03 +02002447 nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002448 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2449 if (check_in_dac_nids(spec, nid))
2450 nid = 0;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002451 if (! nid)
2452 continue;
2453 add_spec_dacs(spec, nid);
Mattc7d4b2f2005-06-27 14:59:41 +02002454 }
Matthew Ranostay1b290a52007-07-12 15:17:34 +02002455 for (i = 0; i < cfg->line_outs; i++) {
2456 nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
2457 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2458 if (check_in_dac_nids(spec, nid))
2459 nid = 0;
2460 if (! nid)
2461 continue;
2462 add_spec_dacs(spec, nid);
2463 }
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002464 for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
2465 static const char *pfxs[] = {
2466 "Speaker", "External Speaker", "Speaker2",
2467 };
2468 err = create_controls(spec, pfxs[i - old_num_dacs],
2469 spec->multiout.dac_nids[i], 3);
2470 if (err < 0)
2471 return err;
2472 }
2473 if (spec->multiout.hp_nid) {
2474 const char *pfx;
Takashi Iwai6020c002007-11-19 11:56:26 +01002475 if (old_num_dacs == spec->multiout.num_dacs)
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002476 pfx = "Master";
2477 else
2478 pfx = "Headphone";
2479 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
2480 if (err < 0)
2481 return err;
2482 }
Mattc7d4b2f2005-06-27 14:59:41 +02002483
2484 return 0;
2485}
2486
Matthew Ranostayb22b4822008-01-22 12:32:30 +01002487/* labels for mono mux outputs */
2488static const char *stac92xx_mono_labels[3] = {
2489 "DAC0", "DAC1", "Mixer"
2490};
2491
2492/* create mono mux for mono out on capable codecs */
2493static int stac92xx_auto_create_mono_output_ctls(struct hda_codec *codec)
2494{
2495 struct sigmatel_spec *spec = codec->spec;
2496 struct hda_input_mux *mono_mux = &spec->private_mono_mux;
2497 int i, num_cons;
2498 hda_nid_t con_lst[ARRAY_SIZE(stac92xx_mono_labels)];
2499
2500 num_cons = snd_hda_get_connections(codec,
2501 spec->mono_nid,
2502 con_lst,
2503 HDA_MAX_NUM_INPUTS);
2504 if (!num_cons || num_cons > ARRAY_SIZE(stac92xx_mono_labels))
2505 return -EINVAL;
2506
2507 for (i = 0; i < num_cons; i++) {
2508 mono_mux->items[mono_mux->num_items].label =
2509 stac92xx_mono_labels[i];
2510 mono_mux->items[mono_mux->num_items].index = i;
2511 mono_mux->num_items++;
2512 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01002513
2514 return stac92xx_add_control(spec, STAC_CTL_WIDGET_MONO_MUX,
2515 "Mono Mux", spec->mono_nid);
Matthew Ranostayb22b4822008-01-22 12:32:30 +01002516}
2517
Matt Porter8b657272006-10-26 17:12:59 +02002518/* labels for dmic mux inputs */
Adrian Bunkddc2cec2006-11-20 12:03:44 +01002519static const char *stac92xx_dmic_labels[5] = {
Matt Porter8b657272006-10-26 17:12:59 +02002520 "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
2521 "Digital Mic 3", "Digital Mic 4"
2522};
2523
2524/* create playback/capture controls for input pins on dmic capable codecs */
2525static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
2526 const struct auto_pin_cfg *cfg)
2527{
2528 struct sigmatel_spec *spec = codec->spec;
2529 struct hda_input_mux *dimux = &spec->private_dimux;
2530 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002531 int err, i, j;
2532 char name[32];
Matt Porter8b657272006-10-26 17:12:59 +02002533
2534 dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
2535 dimux->items[dimux->num_items].index = 0;
2536 dimux->num_items++;
2537
2538 for (i = 0; i < spec->num_dmics; i++) {
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002539 hda_nid_t nid;
Matt Porter8b657272006-10-26 17:12:59 +02002540 int index;
2541 int num_cons;
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002542 unsigned int wcaps;
Matt Porter8b657272006-10-26 17:12:59 +02002543 unsigned int def_conf;
2544
2545 def_conf = snd_hda_codec_read(codec,
2546 spec->dmic_nids[i],
2547 0,
2548 AC_VERB_GET_CONFIG_DEFAULT,
2549 0);
2550 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
2551 continue;
2552
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002553 nid = spec->dmic_nids[i];
Matt Porter8b657272006-10-26 17:12:59 +02002554 num_cons = snd_hda_get_connections(codec,
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01002555 spec->dmux_nids[0],
Matt Porter8b657272006-10-26 17:12:59 +02002556 con_lst,
2557 HDA_MAX_NUM_INPUTS);
2558 for (j = 0; j < num_cons; j++)
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002559 if (con_lst[j] == nid) {
Matt Porter8b657272006-10-26 17:12:59 +02002560 index = j;
2561 goto found;
2562 }
2563 continue;
2564found:
Matthew Ranostay0678acc2008-01-08 12:10:50 +01002565 wcaps = get_wcaps(codec, nid);
2566
2567 if (wcaps & AC_WCAP_OUT_AMP) {
2568 sprintf(name, "%s Capture Volume",
2569 stac92xx_dmic_labels[dimux->num_items]);
2570
2571 err = stac92xx_add_control(spec,
2572 STAC_CTL_WIDGET_VOL,
2573 name,
2574 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
2575 if (err < 0)
2576 return err;
2577 }
2578
Matt Porter8b657272006-10-26 17:12:59 +02002579 dimux->items[dimux->num_items].label =
2580 stac92xx_dmic_labels[dimux->num_items];
2581 dimux->items[dimux->num_items].index = index;
2582 dimux->num_items++;
2583 }
2584
2585 return 0;
2586}
2587
Mattc7d4b2f2005-06-27 14:59:41 +02002588/* create playback/capture controls for input pins */
2589static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
2590{
2591 struct sigmatel_spec *spec = codec->spec;
Mattc7d4b2f2005-06-27 14:59:41 +02002592 struct hda_input_mux *imux = &spec->private_imux;
2593 hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
2594 int i, j, k;
2595
2596 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02002597 int index;
Mattc7d4b2f2005-06-27 14:59:41 +02002598
Takashi Iwai314634b2006-09-21 11:56:18 +02002599 if (!cfg->input_pins[i])
2600 continue;
2601 index = -1;
2602 for (j = 0; j < spec->num_muxes; j++) {
2603 int num_cons;
2604 num_cons = snd_hda_get_connections(codec,
2605 spec->mux_nids[j],
2606 con_lst,
2607 HDA_MAX_NUM_INPUTS);
2608 for (k = 0; k < num_cons; k++)
2609 if (con_lst[k] == cfg->input_pins[i]) {
2610 index = k;
2611 goto found;
2612 }
Mattc7d4b2f2005-06-27 14:59:41 +02002613 }
Takashi Iwai314634b2006-09-21 11:56:18 +02002614 continue;
2615 found:
2616 imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
2617 imux->items[imux->num_items].index = index;
2618 imux->num_items++;
Mattc7d4b2f2005-06-27 14:59:41 +02002619 }
2620
Steve Longerbeam7b043892007-05-03 20:50:03 +02002621 if (imux->num_items) {
Sam Revitch62fe78e2006-05-10 15:09:17 +02002622 /*
2623 * Set the current input for the muxes.
2624 * The STAC9221 has two input muxes with identical source
2625 * NID lists. Hopefully this won't get confused.
2626 */
2627 for (i = 0; i < spec->num_muxes; i++) {
Takashi Iwai82beb8f2007-08-10 17:09:26 +02002628 snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
2629 AC_VERB_SET_CONNECT_SEL,
2630 imux->items[0].index);
Sam Revitch62fe78e2006-05-10 15:09:17 +02002631 }
2632 }
2633
Mattc7d4b2f2005-06-27 14:59:41 +02002634 return 0;
2635}
2636
Mattc7d4b2f2005-06-27 14:59:41 +02002637static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
2638{
2639 struct sigmatel_spec *spec = codec->spec;
2640 int i;
2641
2642 for (i = 0; i < spec->autocfg.line_outs; i++) {
2643 hda_nid_t nid = spec->autocfg.line_out_pins[i];
2644 stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
2645 }
2646}
2647
2648static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
2649{
2650 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002651 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002652
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002653 for (i = 0; i < spec->autocfg.hp_outs; i++) {
2654 hda_nid_t pin;
2655 pin = spec->autocfg.hp_pins[i];
2656 if (pin) /* connect to front */
2657 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
2658 }
2659 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
2660 hda_nid_t pin;
2661 pin = spec->autocfg.speaker_pins[i];
2662 if (pin) /* connect to front */
2663 stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
2664 }
Mattc7d4b2f2005-06-27 14:59:41 +02002665}
2666
Matt Porter3cc08dc2006-01-23 15:27:49 +01002667static 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 +02002668{
2669 struct sigmatel_spec *spec = codec->spec;
2670 int err;
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002671 int hp_speaker_swap = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02002672
Matt Porter8b657272006-10-26 17:12:59 +02002673 if ((err = snd_hda_parse_pin_def_config(codec,
2674 &spec->autocfg,
2675 spec->dmic_nids)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002676 return err;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002677 if (! spec->autocfg.line_outs)
Matt Porter869264c2006-01-25 19:20:50 +01002678 return 0; /* can't find valid pin config */
Takashi Iwai19039bd2006-06-28 15:52:16 +02002679
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002680 /* If we have no real line-out pin and multiple hp-outs, HPs should
2681 * be set up as multi-channel outputs.
2682 */
2683 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
2684 spec->autocfg.hp_outs > 1) {
2685 /* Copy hp_outs to line_outs, backup line_outs in
2686 * speaker_outs so that the following routines can handle
2687 * HP pins as primary outputs.
2688 */
2689 memcpy(spec->autocfg.speaker_pins, spec->autocfg.line_out_pins,
2690 sizeof(spec->autocfg.line_out_pins));
2691 spec->autocfg.speaker_outs = spec->autocfg.line_outs;
2692 memcpy(spec->autocfg.line_out_pins, spec->autocfg.hp_pins,
2693 sizeof(spec->autocfg.hp_pins));
2694 spec->autocfg.line_outs = spec->autocfg.hp_outs;
2695 hp_speaker_swap = 1;
2696 }
Matthew Ranostay09a99952008-01-24 11:49:21 +01002697 if (spec->autocfg.mono_out_pin) {
2698 int dir = (get_wcaps(codec, spec->autocfg.mono_out_pin)
2699 & AC_WCAP_OUT_AMP) ? HDA_OUTPUT : HDA_INPUT;
2700 u32 caps = query_amp_caps(codec,
2701 spec->autocfg.mono_out_pin, dir);
2702 hda_nid_t conn_list[1];
2703
2704 /* get the mixer node and then the mono mux if it exists */
2705 if (snd_hda_get_connections(codec,
2706 spec->autocfg.mono_out_pin, conn_list, 1) &&
2707 snd_hda_get_connections(codec, conn_list[0],
2708 conn_list, 1)) {
2709
2710 int wcaps = get_wcaps(codec, conn_list[0]);
2711 int wid_type = (wcaps & AC_WCAP_TYPE)
2712 >> AC_WCAP_TYPE_SHIFT;
2713 /* LR swap check, some stac925x have a mux that
2714 * changes the DACs output path instead of the
2715 * mono-mux path.
2716 */
2717 if (wid_type == AC_WID_AUD_SEL &&
2718 !(wcaps & AC_WCAP_LR_SWAP))
2719 spec->mono_nid = conn_list[0];
2720 }
2721 /* all mono outs have a least a mute/unmute switch */
2722 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE,
2723 "Mono Playback Switch",
2724 HDA_COMPOSE_AMP_VAL(spec->autocfg.mono_out_pin,
2725 1, 0, dir));
2726 if (err < 0)
2727 return err;
2728 /* check to see if there is volume support for the amp */
2729 if ((caps & AC_AMPCAP_NUM_STEPS) >> AC_AMPCAP_NUM_STEPS_SHIFT) {
2730 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL,
2731 "Mono Playback Volume",
2732 HDA_COMPOSE_AMP_VAL(spec->autocfg.mono_out_pin,
2733 1, 0, dir));
2734 if (err < 0)
2735 return err;
2736 }
2737
2738 stac92xx_auto_set_pinctl(codec, spec->autocfg.mono_out_pin,
2739 AC_PINCTL_OUT_EN);
2740 }
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002741
Matt Porter403d1942005-11-29 15:00:51 +01002742 if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
2743 return err;
Takashi Iwai19039bd2006-06-28 15:52:16 +02002744 if (spec->multiout.num_dacs == 0)
2745 if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
2746 return err;
Mattc7d4b2f2005-06-27 14:59:41 +02002747
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002748 err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
2749
2750 if (err < 0)
2751 return err;
2752
Jiang Zhebcecd9b2007-11-12 12:57:03 +01002753 if (hp_speaker_swap == 1) {
2754 /* Restore the hp_outs and line_outs */
2755 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
2756 sizeof(spec->autocfg.line_out_pins));
2757 spec->autocfg.hp_outs = spec->autocfg.line_outs;
2758 memcpy(spec->autocfg.line_out_pins, spec->autocfg.speaker_pins,
2759 sizeof(spec->autocfg.speaker_pins));
2760 spec->autocfg.line_outs = spec->autocfg.speaker_outs;
2761 memset(spec->autocfg.speaker_pins, 0,
2762 sizeof(spec->autocfg.speaker_pins));
2763 spec->autocfg.speaker_outs = 0;
2764 }
2765
Maxim Levitsky0fb87bb2007-09-03 15:29:04 +02002766 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
2767
2768 if (err < 0)
2769 return err;
2770
2771 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
2772
2773 if (err < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002774 return err;
2775
Matthew Ranostayb22b4822008-01-22 12:32:30 +01002776 if (spec->mono_nid > 0) {
2777 err = stac92xx_auto_create_mono_output_ctls(codec);
2778 if (err < 0)
2779 return err;
2780 }
2781
Matt Porter8b657272006-10-26 17:12:59 +02002782 if (spec->num_dmics > 0)
2783 if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
2784 &spec->autocfg)) < 0)
2785 return err;
2786
Mattc7d4b2f2005-06-27 14:59:41 +02002787 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
Matt Porter403d1942005-11-29 15:00:51 +01002788 if (spec->multiout.max_channels > 2)
Mattc7d4b2f2005-06-27 14:59:41 +02002789 spec->surr_switch = 1;
Mattc7d4b2f2005-06-27 14:59:41 +02002790
Takashi Iwai82bc9552006-03-21 11:24:42 +01002791 if (spec->autocfg.dig_out_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002792 spec->multiout.dig_out_nid = dig_out;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002793 if (spec->autocfg.dig_in_pin)
Matt Porter3cc08dc2006-01-23 15:27:49 +01002794 spec->dig_in_nid = dig_in;
Mattc7d4b2f2005-06-27 14:59:41 +02002795
2796 if (spec->kctl_alloc)
2797 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2798
2799 spec->input_mux = &spec->private_imux;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01002800 if (!spec->dinput_mux)
2801 spec->dinput_mux = &spec->private_dimux;
Matthew Ranostayb22b4822008-01-22 12:32:30 +01002802 spec->mono_mux = &spec->private_mono_mux;
Mattc7d4b2f2005-06-27 14:59:41 +02002803
2804 return 1;
2805}
2806
Takashi Iwai82bc9552006-03-21 11:24:42 +01002807/* add playback controls for HP output */
2808static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
2809 struct auto_pin_cfg *cfg)
2810{
2811 struct sigmatel_spec *spec = codec->spec;
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002812 hda_nid_t pin = cfg->hp_pins[0];
Takashi Iwai82bc9552006-03-21 11:24:42 +01002813 unsigned int wid_caps;
2814
2815 if (! pin)
2816 return 0;
2817
2818 wid_caps = get_wcaps(codec, pin);
Takashi Iwai505cb342006-03-27 12:51:52 +02002819 if (wid_caps & AC_WCAP_UNSOL_CAP)
Takashi Iwai82bc9552006-03-21 11:24:42 +01002820 spec->hp_detect = 1;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002821
2822 return 0;
2823}
2824
Richard Fish160ea0d2006-09-06 13:58:25 +02002825/* add playback controls for LFE output */
2826static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2827 struct auto_pin_cfg *cfg)
2828{
2829 struct sigmatel_spec *spec = codec->spec;
2830 int err;
2831 hda_nid_t lfe_pin = 0x0;
2832 int i;
2833
2834 /*
2835 * search speaker outs and line outs for a mono speaker pin
2836 * with an amp. If one is found, add LFE controls
2837 * for it.
2838 */
2839 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2840 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2841 unsigned long wcaps = get_wcaps(codec, pin);
2842 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2843 if (wcaps == AC_WCAP_OUT_AMP)
2844 /* found a mono speaker with an amp, must be lfe */
2845 lfe_pin = pin;
2846 }
2847
2848 /* if speaker_outs is 0, then speakers may be in line_outs */
2849 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2850 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2851 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2852 unsigned long cfg;
2853 cfg = snd_hda_codec_read(codec, pin, 0,
2854 AC_VERB_GET_CONFIG_DEFAULT,
2855 0x00);
2856 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
2857 unsigned long wcaps = get_wcaps(codec, pin);
2858 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2859 if (wcaps == AC_WCAP_OUT_AMP)
2860 /* found a mono speaker with an amp,
2861 must be lfe */
2862 lfe_pin = pin;
2863 }
2864 }
2865 }
2866
2867 if (lfe_pin) {
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002868 err = create_controls(spec, "LFE", lfe_pin, 1);
Richard Fish160ea0d2006-09-06 13:58:25 +02002869 if (err < 0)
2870 return err;
2871 }
2872
2873 return 0;
2874}
2875
Mattc7d4b2f2005-06-27 14:59:41 +02002876static int stac9200_parse_auto_config(struct hda_codec *codec)
2877{
2878 struct sigmatel_spec *spec = codec->spec;
2879 int err;
2880
Kailang Yangdf694da2005-12-05 19:42:22 +01002881 if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
Mattc7d4b2f2005-06-27 14:59:41 +02002882 return err;
2883
2884 if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
2885 return err;
2886
Takashi Iwai82bc9552006-03-21 11:24:42 +01002887 if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
2888 return err;
2889
Richard Fish160ea0d2006-09-06 13:58:25 +02002890 if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
2891 return err;
2892
Takashi Iwai82bc9552006-03-21 11:24:42 +01002893 if (spec->autocfg.dig_out_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002894 spec->multiout.dig_out_nid = 0x05;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002895 if (spec->autocfg.dig_in_pin)
Mattc7d4b2f2005-06-27 14:59:41 +02002896 spec->dig_in_nid = 0x04;
Mattc7d4b2f2005-06-27 14:59:41 +02002897
2898 if (spec->kctl_alloc)
2899 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
2900
2901 spec->input_mux = &spec->private_imux;
Matt Porter8b657272006-10-26 17:12:59 +02002902 spec->dinput_mux = &spec->private_dimux;
Mattc7d4b2f2005-06-27 14:59:41 +02002903
2904 return 1;
2905}
2906
Sam Revitch62fe78e2006-05-10 15:09:17 +02002907/*
2908 * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
2909 * funky external mute control using GPIO pins.
2910 */
2911
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01002912static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01002913 unsigned int dir_mask, unsigned int data)
Sam Revitch62fe78e2006-05-10 15:09:17 +02002914{
2915 unsigned int gpiostate, gpiomask, gpiodir;
2916
2917 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2918 AC_VERB_GET_GPIO_DATA, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01002919 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
Sam Revitch62fe78e2006-05-10 15:09:17 +02002920
2921 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2922 AC_VERB_GET_GPIO_MASK, 0);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01002923 gpiomask |= mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02002924
2925 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2926 AC_VERB_GET_GPIO_DIRECTION, 0);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01002927 gpiodir |= dir_mask;
Sam Revitch62fe78e2006-05-10 15:09:17 +02002928
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01002929 /* Configure GPIOx as CMOS */
Sam Revitch62fe78e2006-05-10 15:09:17 +02002930 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2931
2932 snd_hda_codec_write(codec, codec->afg, 0,
2933 AC_VERB_SET_GPIO_MASK, gpiomask);
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01002934 snd_hda_codec_read(codec, codec->afg, 0,
2935 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02002936
2937 msleep(1);
2938
Takashi Iwai76e1ddf2008-01-15 11:39:08 +01002939 snd_hda_codec_read(codec, codec->afg, 0,
2940 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
Sam Revitch62fe78e2006-05-10 15:09:17 +02002941}
2942
Takashi Iwai314634b2006-09-21 11:56:18 +02002943static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
2944 unsigned int event)
2945{
2946 if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
Takashi Iwaidc81bed2007-09-03 09:36:36 +02002947 snd_hda_codec_write_cache(codec, nid, 0,
2948 AC_VERB_SET_UNSOLICITED_ENABLE,
2949 (AC_USRSP_EN | event));
Takashi Iwai314634b2006-09-21 11:56:18 +02002950}
2951
Matthew Ranostaya64135a2008-01-10 16:55:06 +01002952static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
2953{
2954 int i;
2955 for (i = 0; i < cfg->hp_outs; i++)
2956 if (cfg->hp_pins[i] == nid)
2957 return 1; /* nid is a HP-Out */
2958
2959 return 0; /* nid is not a HP-Out */
2960};
2961
Matthew Ranostayb76c8502008-02-06 14:49:44 +01002962static void stac92xx_power_down(struct hda_codec *codec)
2963{
2964 struct sigmatel_spec *spec = codec->spec;
2965
2966 /* power down inactive DACs */
2967 hda_nid_t *dac;
2968 for (dac = spec->dac_list; *dac; dac++)
Matthew Ranostay44510892008-02-21 07:49:31 +01002969 if (!is_in_dac_nids(spec, *dac) &&
2970 spec->multiout.hp_nid != *dac)
Matthew Ranostayb76c8502008-02-06 14:49:44 +01002971 snd_hda_codec_write_cache(codec, *dac, 0,
2972 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
2973}
2974
Mattc7d4b2f2005-06-27 14:59:41 +02002975static int stac92xx_init(struct hda_codec *codec)
2976{
2977 struct sigmatel_spec *spec = codec->spec;
Takashi Iwai82bc9552006-03-21 11:24:42 +01002978 struct auto_pin_cfg *cfg = &spec->autocfg;
2979 int i;
Mattc7d4b2f2005-06-27 14:59:41 +02002980
Mattc7d4b2f2005-06-27 14:59:41 +02002981 snd_hda_sequence_write(codec, spec->init);
2982
Takashi Iwai82bc9552006-03-21 11:24:42 +01002983 /* set up pins */
2984 if (spec->hp_detect) {
Takashi Iwai505cb342006-03-27 12:51:52 +02002985 /* Enable unsolicited responses on the HP widget */
Takashi Iwaieb06ed82006-09-20 17:10:27 +02002986 for (i = 0; i < cfg->hp_outs; i++)
Takashi Iwai314634b2006-09-21 11:56:18 +02002987 enable_pin_detect(codec, cfg->hp_pins[i],
2988 STAC_HP_EVENT);
Takashi Iwai0a07acaf2007-03-13 10:40:23 +01002989 /* force to enable the first line-out; the others are set up
2990 * in unsol_event
2991 */
2992 stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
2993 AC_PINCTL_OUT_EN);
Takashi Iwaieb995a82006-09-21 14:28:21 +02002994 stac92xx_auto_init_hp_out(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01002995 /* fake event to set up pins */
2996 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2997 } else {
2998 stac92xx_auto_init_multi_out(codec);
2999 stac92xx_auto_init_hp_out(codec);
3000 }
3001 for (i = 0; i < AUTO_PIN_LAST; i++) {
Takashi Iwaic960a032006-03-23 17:06:28 +01003002 hda_nid_t nid = cfg->input_pins[i];
3003 if (nid) {
3004 unsigned int pinctl = AC_PINCTL_IN_EN;
3005 if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
3006 pinctl |= stac92xx_get_vref(codec, nid);
3007 stac92xx_auto_set_pinctl(codec, nid, pinctl);
3008 }
Takashi Iwai82bc9552006-03-21 11:24:42 +01003009 }
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003010 for (i = 0; i < spec->num_dmics; i++)
3011 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
3012 AC_PINCTL_IN_EN);
3013 for (i = 0; i < spec->num_pwrs; i++) {
3014 int event = is_nid_hp_pin(cfg, spec->pwr_nids[i])
3015 ? STAC_HP_EVENT : STAC_PWR_EVENT;
3016 int pinctl = snd_hda_codec_read(codec, spec->pwr_nids[i],
3017 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3018 /* outputs are only ports capable of power management
3019 * any attempts on powering down a input port cause the
3020 * referenced VREF to act quirky.
3021 */
3022 if (pinctl & AC_PINCTL_IN_EN)
3023 continue;
3024 enable_pin_detect(codec, spec->pwr_nids[i], event | i);
3025 codec->patch_ops.unsol_event(codec, (event | i) << 26);
3026 }
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003027 if (spec->dac_list)
3028 stac92xx_power_down(codec);
Takashi Iwai82bc9552006-03-21 11:24:42 +01003029 if (cfg->dig_out_pin)
3030 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
3031 AC_PINCTL_OUT_EN);
3032 if (cfg->dig_in_pin)
3033 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
3034 AC_PINCTL_IN_EN);
3035
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003036 stac_gpio_set(codec, spec->gpio_mask,
3037 spec->gpio_dir, spec->gpio_data);
Sam Revitch62fe78e2006-05-10 15:09:17 +02003038
Mattc7d4b2f2005-06-27 14:59:41 +02003039 return 0;
3040}
3041
Matt2f2f4252005-04-13 14:45:30 +02003042static void stac92xx_free(struct hda_codec *codec)
3043{
Mattc7d4b2f2005-06-27 14:59:41 +02003044 struct sigmatel_spec *spec = codec->spec;
3045 int i;
3046
3047 if (! spec)
3048 return;
3049
3050 if (spec->kctl_alloc) {
3051 for (i = 0; i < spec->num_kctl_used; i++)
3052 kfree(spec->kctl_alloc[i].name);
3053 kfree(spec->kctl_alloc);
3054 }
3055
Richard Fish11b44bb2006-08-23 18:31:34 +02003056 if (spec->bios_pin_configs)
3057 kfree(spec->bios_pin_configs);
3058
Mattc7d4b2f2005-06-27 14:59:41 +02003059 kfree(spec);
Matt2f2f4252005-04-13 14:45:30 +02003060}
3061
Matt4e550962005-07-04 17:51:39 +02003062static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
3063 unsigned int flag)
3064{
3065 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
3066 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Steve Longerbeam7b043892007-05-03 20:50:03 +02003067
Takashi Iwaif9acba42007-05-29 18:01:06 +02003068 if (pin_ctl & AC_PINCTL_IN_EN) {
3069 /*
3070 * we need to check the current set-up direction of
3071 * shared input pins since they can be switched via
3072 * "xxx as Output" mixer switch
3073 */
3074 struct sigmatel_spec *spec = codec->spec;
3075 struct auto_pin_cfg *cfg = &spec->autocfg;
3076 if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
3077 spec->line_switch) ||
3078 (nid == cfg->input_pins[AUTO_PIN_MIC] &&
3079 spec->mic_switch))
3080 return;
3081 }
3082
Steve Longerbeam7b043892007-05-03 20:50:03 +02003083 /* if setting pin direction bits, clear the current
3084 direction bits first */
3085 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
3086 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
3087
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003088 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02003089 AC_VERB_SET_PIN_WIDGET_CONTROL,
3090 pin_ctl | flag);
3091}
3092
3093static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
3094 unsigned int flag)
3095{
3096 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
3097 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003098 snd_hda_codec_write_cache(codec, nid, 0,
Matt4e550962005-07-04 17:51:39 +02003099 AC_VERB_SET_PIN_WIDGET_CONTROL,
3100 pin_ctl & ~flag);
3101}
3102
Jiang Zhe40c1d302007-11-12 13:05:16 +01003103static int get_hp_pin_presence(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai314634b2006-09-21 11:56:18 +02003104{
3105 if (!nid)
3106 return 0;
3107 if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
Jiang Zhe40c1d302007-11-12 13:05:16 +01003108 & (1 << 31)) {
3109 unsigned int pinctl;
3110 pinctl = snd_hda_codec_read(codec, nid, 0,
3111 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3112 if (pinctl & AC_PINCTL_IN_EN)
3113 return 0; /* mic- or line-input */
3114 else
3115 return 1; /* HP-output */
3116 }
Takashi Iwai314634b2006-09-21 11:56:18 +02003117 return 0;
3118}
3119
3120static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
Matt4e550962005-07-04 17:51:39 +02003121{
3122 struct sigmatel_spec *spec = codec->spec;
3123 struct auto_pin_cfg *cfg = &spec->autocfg;
3124 int i, presence;
3125
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003126 presence = 0;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003127 if (spec->gpio_mute)
3128 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
3129 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
3130
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003131 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003132 if (presence)
3133 break;
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003134 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003135 }
Matt4e550962005-07-04 17:51:39 +02003136
3137 if (presence) {
3138 /* disable lineouts, enable hp */
3139 for (i = 0; i < cfg->line_outs; i++)
3140 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
3141 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003142 for (i = 0; i < cfg->speaker_outs; i++)
3143 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
3144 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02003145 } else {
3146 /* enable lineouts, disable hp */
3147 for (i = 0; i < cfg->line_outs; i++)
3148 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
3149 AC_PINCTL_OUT_EN);
Takashi Iwaieb06ed82006-09-20 17:10:27 +02003150 for (i = 0; i < cfg->speaker_outs; i++)
3151 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
3152 AC_PINCTL_OUT_EN);
Matt4e550962005-07-04 17:51:39 +02003153 }
3154}
3155
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003156static void stac92xx_pin_sense(struct hda_codec *codec, int idx)
3157{
3158 struct sigmatel_spec *spec = codec->spec;
3159 hda_nid_t nid = spec->pwr_nids[idx];
3160 int presence, val;
3161 val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0)
3162 & 0x000000ff;
3163 presence = get_hp_pin_presence(codec, nid);
3164 idx = 1 << idx;
3165
3166 if (presence)
3167 val &= ~idx;
3168 else
3169 val |= idx;
3170
3171 /* power down unused output ports */
3172 snd_hda_codec_write(codec, codec->afg, 0, 0x7ec, val);
3173};
3174
Takashi Iwai314634b2006-09-21 11:56:18 +02003175static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
3176{
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003177 struct sigmatel_spec *spec = codec->spec;
3178 int idx = res >> 26 & 0x0f;
3179
3180 switch ((res >> 26) & 0x30) {
Takashi Iwai314634b2006-09-21 11:56:18 +02003181 case STAC_HP_EVENT:
3182 stac92xx_hp_detect(codec, res);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003183 /* fallthru */
3184 case STAC_PWR_EVENT:
3185 if (spec->num_pwrs > 0)
3186 stac92xx_pin_sense(codec, idx);
Takashi Iwai314634b2006-09-21 11:56:18 +02003187 }
3188}
3189
Takashi Iwaicb53c622007-08-10 17:21:45 +02003190#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02003191static int stac92xx_resume(struct hda_codec *codec)
3192{
Takashi Iwaidc81bed2007-09-03 09:36:36 +02003193 struct sigmatel_spec *spec = codec->spec;
3194
Richard Fish11b44bb2006-08-23 18:31:34 +02003195 stac92xx_set_config_regs(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02003196 snd_hda_sequence_write(codec, spec->init);
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003197 stac_gpio_set(codec, spec->gpio_mask,
3198 spec->gpio_dir, spec->gpio_data);
Takashi Iwai82beb8f2007-08-10 17:09:26 +02003199 snd_hda_codec_resume_amp(codec);
3200 snd_hda_codec_resume_cache(codec);
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003201 /* power down inactive DACs */
3202 if (spec->dac_list)
3203 stac92xx_power_down(codec);
Takashi Iwaidc81bed2007-09-03 09:36:36 +02003204 /* invoke unsolicited event to reset the HP state */
3205 if (spec->hp_detect)
3206 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
Mattff6fdc32005-06-27 15:06:52 +02003207 return 0;
3208}
3209#endif
3210
Matt2f2f4252005-04-13 14:45:30 +02003211static struct hda_codec_ops stac92xx_patch_ops = {
3212 .build_controls = stac92xx_build_controls,
3213 .build_pcms = stac92xx_build_pcms,
3214 .init = stac92xx_init,
3215 .free = stac92xx_free,
Matt4e550962005-07-04 17:51:39 +02003216 .unsol_event = stac92xx_unsol_event,
Takashi Iwaicb53c622007-08-10 17:21:45 +02003217#ifdef SND_HDA_NEEDS_RESUME
Mattff6fdc32005-06-27 15:06:52 +02003218 .resume = stac92xx_resume,
3219#endif
Matt2f2f4252005-04-13 14:45:30 +02003220};
3221
3222static int patch_stac9200(struct hda_codec *codec)
3223{
3224 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003225 int err;
Matt2f2f4252005-04-13 14:45:30 +02003226
Takashi Iwaie560d8d2005-09-09 14:21:46 +02003227 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02003228 if (spec == NULL)
3229 return -ENOMEM;
3230
3231 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003232 spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003233 spec->pin_nids = stac9200_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003234 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
3235 stac9200_models,
3236 stac9200_cfg_tbl);
Richard Fish11b44bb2006-08-23 18:31:34 +02003237 if (spec->board_config < 0) {
3238 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
3239 err = stac92xx_save_bios_config_regs(codec);
3240 if (err < 0) {
3241 stac92xx_free(codec);
3242 return err;
3243 }
3244 spec->pin_configs = spec->bios_pin_configs;
3245 } else {
Matt Porter403d1942005-11-29 15:00:51 +01003246 spec->pin_configs = stac9200_brd_tbl[spec->board_config];
3247 stac92xx_set_config_regs(codec);
3248 }
Matt2f2f4252005-04-13 14:45:30 +02003249
3250 spec->multiout.max_channels = 2;
3251 spec->multiout.num_dacs = 1;
3252 spec->multiout.dac_nids = stac9200_dac_nids;
3253 spec->adc_nids = stac9200_adc_nids;
3254 spec->mux_nids = stac9200_mux_nids;
Mattdabbed62005-06-14 10:19:34 +02003255 spec->num_muxes = 1;
Matt Porter8b657272006-10-26 17:12:59 +02003256 spec->num_dmics = 0;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003257 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003258 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003259
Tobin Davisbf277782008-02-03 20:31:47 +01003260 if (spec->board_config == STAC_9200_GATEWAY ||
3261 spec->board_config == STAC_9200_OQO)
Takashi Iwai1194b5b2007-10-10 10:04:26 +02003262 spec->init = stac9200_eapd_init;
3263 else
3264 spec->init = stac9200_core_init;
Matt2f2f4252005-04-13 14:45:30 +02003265 spec->mixer = stac9200_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02003266
3267 err = stac9200_parse_auto_config(codec);
3268 if (err < 0) {
3269 stac92xx_free(codec);
3270 return err;
3271 }
Matt2f2f4252005-04-13 14:45:30 +02003272
3273 codec->patch_ops = stac92xx_patch_ops;
3274
3275 return 0;
3276}
3277
Tobin Davis8e21c342007-01-08 11:04:17 +01003278static int patch_stac925x(struct hda_codec *codec)
3279{
3280 struct sigmatel_spec *spec;
3281 int err;
3282
3283 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3284 if (spec == NULL)
3285 return -ENOMEM;
3286
3287 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003288 spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
Tobin Davis8e21c342007-01-08 11:04:17 +01003289 spec->pin_nids = stac925x_pin_nids;
3290 spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
3291 stac925x_models,
3292 stac925x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003293 again:
Tobin Davis8e21c342007-01-08 11:04:17 +01003294 if (spec->board_config < 0) {
Tobin Davis2c11f952007-05-17 09:36:34 +02003295 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
3296 "using BIOS defaults\n");
Tobin Davis8e21c342007-01-08 11:04:17 +01003297 err = stac92xx_save_bios_config_regs(codec);
3298 if (err < 0) {
3299 stac92xx_free(codec);
3300 return err;
3301 }
3302 spec->pin_configs = spec->bios_pin_configs;
3303 } else if (stac925x_brd_tbl[spec->board_config] != NULL){
3304 spec->pin_configs = stac925x_brd_tbl[spec->board_config];
3305 stac92xx_set_config_regs(codec);
3306 }
3307
3308 spec->multiout.max_channels = 2;
3309 spec->multiout.num_dacs = 1;
3310 spec->multiout.dac_nids = stac925x_dac_nids;
3311 spec->adc_nids = stac925x_adc_nids;
3312 spec->mux_nids = stac925x_mux_nids;
3313 spec->num_muxes = 1;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003314 spec->num_adcs = 1;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003315 spec->num_pwrs = 0;
Tobin Davis2c11f952007-05-17 09:36:34 +02003316 switch (codec->vendor_id) {
3317 case 0x83847632: /* STAC9202 */
3318 case 0x83847633: /* STAC9202D */
3319 case 0x83847636: /* STAC9251 */
3320 case 0x83847637: /* STAC9251D */
Takashi Iwaif6e98522007-10-16 14:27:04 +02003321 spec->num_dmics = STAC925X_NUM_DMICS;
Tobin Davis2c11f952007-05-17 09:36:34 +02003322 spec->dmic_nids = stac925x_dmic_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003323 spec->num_dmuxes = ARRAY_SIZE(stac925x_dmux_nids);
3324 spec->dmux_nids = stac925x_dmux_nids;
Tobin Davis2c11f952007-05-17 09:36:34 +02003325 break;
3326 default:
3327 spec->num_dmics = 0;
3328 break;
3329 }
Tobin Davis8e21c342007-01-08 11:04:17 +01003330
3331 spec->init = stac925x_core_init;
3332 spec->mixer = stac925x_mixer;
3333
3334 err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003335 if (!err) {
3336 if (spec->board_config < 0) {
3337 printk(KERN_WARNING "hda_codec: No auto-config is "
3338 "available, default to model=ref\n");
3339 spec->board_config = STAC_925x_REF;
3340 goto again;
3341 }
3342 err = -EINVAL;
3343 }
Tobin Davis8e21c342007-01-08 11:04:17 +01003344 if (err < 0) {
3345 stac92xx_free(codec);
3346 return err;
3347 }
3348
3349 codec->patch_ops = stac92xx_patch_ops;
3350
3351 return 0;
3352}
3353
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003354static struct hda_input_mux stac92hd73xx_dmux = {
3355 .num_items = 4,
3356 .items = {
3357 { "Analog Inputs", 0x0b },
3358 { "CD", 0x08 },
3359 { "Digital Mic 1", 0x09 },
3360 { "Digital Mic 2", 0x0a },
3361 }
3362};
3363
3364static int patch_stac92hd73xx(struct hda_codec *codec)
3365{
3366 struct sigmatel_spec *spec;
3367 hda_nid_t conn[STAC92HD73_DAC_COUNT + 2];
3368 int err = 0;
3369
3370 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3371 if (spec == NULL)
3372 return -ENOMEM;
3373
3374 codec->spec = spec;
3375 spec->num_pins = ARRAY_SIZE(stac92hd73xx_pin_nids);
3376 spec->pin_nids = stac92hd73xx_pin_nids;
3377 spec->board_config = snd_hda_check_board_config(codec,
3378 STAC_92HD73XX_MODELS,
3379 stac92hd73xx_models,
3380 stac92hd73xx_cfg_tbl);
3381again:
3382 if (spec->board_config < 0) {
3383 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3384 " STAC92HD73XX, using BIOS defaults\n");
3385 err = stac92xx_save_bios_config_regs(codec);
3386 if (err < 0) {
3387 stac92xx_free(codec);
3388 return err;
3389 }
3390 spec->pin_configs = spec->bios_pin_configs;
3391 } else {
3392 spec->pin_configs = stac92hd73xx_brd_tbl[spec->board_config];
3393 stac92xx_set_config_regs(codec);
3394 }
3395
3396 spec->multiout.num_dacs = snd_hda_get_connections(codec, 0x0a,
3397 conn, STAC92HD73_DAC_COUNT + 2) - 1;
3398
3399 if (spec->multiout.num_dacs < 0) {
3400 printk(KERN_WARNING "hda_codec: Could not determine "
3401 "number of channels defaulting to DAC count\n");
3402 spec->multiout.num_dacs = STAC92HD73_DAC_COUNT;
3403 }
3404
3405 switch (spec->multiout.num_dacs) {
3406 case 0x3: /* 6 Channel */
3407 spec->mixer = stac92hd73xx_6ch_mixer;
3408 spec->init = stac92hd73xx_6ch_core_init;
3409 break;
3410 case 0x4: /* 8 Channel */
3411 spec->multiout.hp_nid = 0x18;
3412 spec->mixer = stac92hd73xx_8ch_mixer;
3413 spec->init = stac92hd73xx_8ch_core_init;
3414 break;
3415 case 0x5: /* 10 Channel */
3416 spec->multiout.hp_nid = 0x19;
3417 spec->mixer = stac92hd73xx_10ch_mixer;
3418 spec->init = stac92hd73xx_10ch_core_init;
3419 };
3420
3421 spec->multiout.dac_nids = stac92hd73xx_dac_nids;
3422 spec->aloopback_mask = 0x01;
3423 spec->aloopback_shift = 8;
3424
3425 spec->mux_nids = stac92hd73xx_mux_nids;
3426 spec->adc_nids = stac92hd73xx_adc_nids;
3427 spec->dmic_nids = stac92hd73xx_dmic_nids;
3428 spec->dmux_nids = stac92hd73xx_dmux_nids;
3429
3430 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
3431 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
Takashi Iwai1697055e2007-12-18 18:05:52 +01003432 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003433 spec->dinput_mux = &stac92hd73xx_dmux;
3434 /* GPIO0 High = Enable EAPD */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003435 spec->gpio_mask = spec->gpio_dir = 0x1;
3436 spec->gpio_data = 0x01;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003437
Matthew Ranostaya7662642008-02-21 07:51:14 +01003438 switch (spec->board_config) {
3439 case STAC_DELL_M6:
3440 switch (codec->subsystem_id) {
3441 case 0x1028025e: /* Analog Mics */
3442 case 0x1028025f:
3443 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
3444 spec->num_dmics = 0;
3445 break;
3446 case 0x10280254: /* Digital Mics */
3447 case 0x10280255:
3448 case 0x10280271:
3449 case 0x10280272:
3450 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
3451 spec->num_dmics = 1;
3452 break;
3453 case 0x10280256: /* Both */
3454 case 0x10280057:
3455 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
3456 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
3457 spec->num_dmics = 1;
3458 break;
3459 }
3460 break;
3461 default:
3462 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
3463 }
3464
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003465 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
3466 spec->pwr_nids = stac92hd73xx_pwr_nids;
3467
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003468 err = stac92xx_parse_auto_config(codec, 0x22, 0x24);
3469
3470 if (!err) {
3471 if (spec->board_config < 0) {
3472 printk(KERN_WARNING "hda_codec: No auto-config is "
3473 "available, default to model=ref\n");
3474 spec->board_config = STAC_92HD73XX_REF;
3475 goto again;
3476 }
3477 err = -EINVAL;
3478 }
3479
3480 if (err < 0) {
3481 stac92xx_free(codec);
3482 return err;
3483 }
3484
3485 codec->patch_ops = stac92xx_patch_ops;
3486
3487 return 0;
3488}
3489
Matthew Ranostaye035b842007-11-06 11:53:55 +01003490static int patch_stac92hd71bxx(struct hda_codec *codec)
3491{
3492 struct sigmatel_spec *spec;
3493 int err = 0;
3494
3495 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3496 if (spec == NULL)
3497 return -ENOMEM;
3498
3499 codec->spec = spec;
3500 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids);
3501 spec->pin_nids = stac92hd71bxx_pin_nids;
3502 spec->board_config = snd_hda_check_board_config(codec,
3503 STAC_92HD71BXX_MODELS,
3504 stac92hd71bxx_models,
3505 stac92hd71bxx_cfg_tbl);
3506again:
3507 if (spec->board_config < 0) {
3508 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3509 " STAC92HD71BXX, using BIOS defaults\n");
3510 err = stac92xx_save_bios_config_regs(codec);
3511 if (err < 0) {
3512 stac92xx_free(codec);
3513 return err;
3514 }
3515 spec->pin_configs = spec->bios_pin_configs;
3516 } else {
3517 spec->pin_configs = stac92hd71bxx_brd_tbl[spec->board_config];
3518 stac92xx_set_config_regs(codec);
3519 }
3520
Matthew Ranostay541eee82007-12-14 12:08:04 +01003521 switch (codec->vendor_id) {
3522 case 0x111d76b6: /* 4 Port without Analog Mixer */
3523 case 0x111d76b7:
3524 case 0x111d76b4: /* 6 Port without Analog Mixer */
3525 case 0x111d76b5:
3526 spec->mixer = stac92hd71bxx_mixer;
3527 spec->init = stac92hd71bxx_core_init;
3528 break;
3529 default:
3530 spec->mixer = stac92hd71bxx_analog_mixer;
3531 spec->init = stac92hd71bxx_analog_core_init;
3532 }
3533
3534 spec->aloopback_mask = 0x20;
3535 spec->aloopback_shift = 0;
3536
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003537 /* GPIO0 High = EAPD */
3538 spec->gpio_mask = spec->gpio_dir = spec->gpio_data = 0x1;
Matthew Ranostaye035b842007-11-06 11:53:55 +01003539
Matthew Ranostaye035b842007-11-06 11:53:55 +01003540 spec->mux_nids = stac92hd71bxx_mux_nids;
3541 spec->adc_nids = stac92hd71bxx_adc_nids;
3542 spec->dmic_nids = stac92hd71bxx_dmic_nids;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003543 spec->dmux_nids = stac92hd71bxx_dmux_nids;
Matthew Ranostaye035b842007-11-06 11:53:55 +01003544
3545 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
3546 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
3547 spec->num_dmics = STAC92HD71BXX_NUM_DMICS;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003548 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
Matthew Ranostaye035b842007-11-06 11:53:55 +01003549
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003550 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
3551 spec->pwr_nids = stac92hd71bxx_pwr_nids;
3552
Matthew Ranostaye035b842007-11-06 11:53:55 +01003553 spec->multiout.num_dacs = 2;
3554 spec->multiout.hp_nid = 0x11;
3555 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
3556
3557 err = stac92xx_parse_auto_config(codec, 0x21, 0x23);
3558 if (!err) {
3559 if (spec->board_config < 0) {
3560 printk(KERN_WARNING "hda_codec: No auto-config is "
3561 "available, default to model=ref\n");
3562 spec->board_config = STAC_92HD71BXX_REF;
3563 goto again;
3564 }
3565 err = -EINVAL;
3566 }
3567
3568 if (err < 0) {
3569 stac92xx_free(codec);
3570 return err;
3571 }
3572
3573 codec->patch_ops = stac92xx_patch_ops;
3574
3575 return 0;
3576};
3577
Matt2f2f4252005-04-13 14:45:30 +02003578static int patch_stac922x(struct hda_codec *codec)
3579{
3580 struct sigmatel_spec *spec;
Mattc7d4b2f2005-06-27 14:59:41 +02003581 int err;
Matt2f2f4252005-04-13 14:45:30 +02003582
Takashi Iwaie560d8d2005-09-09 14:21:46 +02003583 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
Matt2f2f4252005-04-13 14:45:30 +02003584 if (spec == NULL)
3585 return -ENOMEM;
3586
3587 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003588 spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003589 spec->pin_nids = stac922x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003590 spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
3591 stac922x_models,
3592 stac922x_cfg_tbl);
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003593 if (spec->board_config == STAC_INTEL_MAC_V3) {
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003594 spec->gpio_mask = spec->gpio_dir = 0x03;
3595 spec->gpio_data = 0x03;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003596 /* Intel Macs have all same PCI SSID, so we need to check
3597 * codec SSID to distinguish the exact models
3598 */
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01003599 printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003600 switch (codec->subsystem_id) {
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003601
3602 case 0x106b0800:
3603 spec->board_config = STAC_INTEL_MAC_V1;
Abhijit Bhopatkarc45e20e2007-04-17 11:57:16 +02003604 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003605 case 0x106b0600:
3606 case 0x106b0700:
3607 spec->board_config = STAC_INTEL_MAC_V2;
Nicolas Boichat6f0778d2007-03-15 12:38:15 +01003608 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003609 case 0x106b0e00:
3610 case 0x106b0f00:
3611 case 0x106b1600:
3612 case 0x106b1700:
3613 case 0x106b0200:
3614 case 0x106b1e00:
3615 spec->board_config = STAC_INTEL_MAC_V3;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003616 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003617 case 0x106b1a00:
3618 case 0x00000100:
3619 spec->board_config = STAC_INTEL_MAC_V4;
Sylvain FORETf16928f2007-04-27 14:22:36 +02003620 break;
Ivan N. Zlatev5d5d3bc2007-05-29 16:03:00 +02003621 case 0x106b0a00:
3622 case 0x106b2200:
3623 spec->board_config = STAC_INTEL_MAC_V5;
Takashi Iwai0dae0f82007-05-21 12:41:29 +02003624 break;
Takashi Iwai3fc24d82007-02-16 13:27:18 +01003625 }
3626 }
3627
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003628 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02003629 if (spec->board_config < 0) {
3630 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
3631 "using BIOS defaults\n");
3632 err = stac92xx_save_bios_config_regs(codec);
3633 if (err < 0) {
3634 stac92xx_free(codec);
3635 return err;
3636 }
3637 spec->pin_configs = spec->bios_pin_configs;
3638 } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
Matt Porter403d1942005-11-29 15:00:51 +01003639 spec->pin_configs = stac922x_brd_tbl[spec->board_config];
3640 stac92xx_set_config_regs(codec);
3641 }
Matt2f2f4252005-04-13 14:45:30 +02003642
Matt2f2f4252005-04-13 14:45:30 +02003643 spec->adc_nids = stac922x_adc_nids;
3644 spec->mux_nids = stac922x_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01003645 spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003646 spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
Matt Porter8b657272006-10-26 17:12:59 +02003647 spec->num_dmics = 0;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003648 spec->num_pwrs = 0;
Mattc7d4b2f2005-06-27 14:59:41 +02003649
3650 spec->init = stac922x_core_init;
Matt2f2f4252005-04-13 14:45:30 +02003651 spec->mixer = stac922x_mixer;
Mattc7d4b2f2005-06-27 14:59:41 +02003652
3653 spec->multiout.dac_nids = spec->dac_nids;
Takashi Iwai19039bd2006-06-28 15:52:16 +02003654
Matt Porter3cc08dc2006-01-23 15:27:49 +01003655 err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003656 if (!err) {
3657 if (spec->board_config < 0) {
3658 printk(KERN_WARNING "hda_codec: No auto-config is "
3659 "available, default to model=ref\n");
3660 spec->board_config = STAC_D945_REF;
3661 goto again;
3662 }
3663 err = -EINVAL;
3664 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01003665 if (err < 0) {
3666 stac92xx_free(codec);
3667 return err;
3668 }
3669
3670 codec->patch_ops = stac92xx_patch_ops;
3671
Takashi Iwai807a46362007-05-29 19:01:37 +02003672 /* Fix Mux capture level; max to 2 */
3673 snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
3674 (0 << AC_AMPCAP_OFFSET_SHIFT) |
3675 (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3676 (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3677 (0 << AC_AMPCAP_MUTE_SHIFT));
3678
Matt Porter3cc08dc2006-01-23 15:27:49 +01003679 return 0;
3680}
3681
3682static int patch_stac927x(struct hda_codec *codec)
3683{
3684 struct sigmatel_spec *spec;
3685 int err;
3686
3687 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3688 if (spec == NULL)
3689 return -ENOMEM;
3690
3691 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003692 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003693 spec->pin_nids = stac927x_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003694 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
3695 stac927x_models,
3696 stac927x_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003697 again:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003698 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) {
3699 if (spec->board_config < 0)
3700 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
3701 "STAC927x, using BIOS defaults\n");
Richard Fish11b44bb2006-08-23 18:31:34 +02003702 err = stac92xx_save_bios_config_regs(codec);
3703 if (err < 0) {
3704 stac92xx_free(codec);
3705 return err;
3706 }
3707 spec->pin_configs = spec->bios_pin_configs;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003708 } else {
Matt Porter3cc08dc2006-01-23 15:27:49 +01003709 spec->pin_configs = stac927x_brd_tbl[spec->board_config];
3710 stac92xx_set_config_regs(codec);
3711 }
3712
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003713 spec->adc_nids = stac927x_adc_nids;
3714 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
3715 spec->mux_nids = stac927x_mux_nids;
3716 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
Matthew Ranostayb76c8502008-02-06 14:49:44 +01003717 spec->dac_list = stac927x_dac_nids;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003718 spec->multiout.dac_nids = spec->dac_nids;
3719
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003720 switch (spec->board_config) {
Tobin Davis93ed1502006-09-01 21:03:12 +02003721 case STAC_D965_3ST:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003722 case STAC_D965_5ST:
3723 /* GPIO0 High = Enable EAPD */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003724 spec->gpio_mask = spec->gpio_dir = 0x01;
3725 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003726 spec->num_dmics = 0;
3727
Tobin Davis93ed1502006-09-01 21:03:12 +02003728 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003729 spec->mixer = stac927x_mixer;
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003730 break;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003731 case STAC_DELL_BIOS:
Matthew Ranostay03d7ca12008-02-21 07:51:46 +01003732 /* configure the analog microphone on some laptops */
3733 stac92xx_set_config_reg(codec, 0x0c, 0x90a79130);
Matthew Ranostay2f32d902008-01-10 13:06:26 +01003734 /* correct the front output jack as a hp out */
Matthew Ranostay7989fba2008-02-21 07:50:12 +01003735 stac92xx_set_config_reg(codec, 0x0f, 0x0227011f);
Matthew Ranostayc481fca2008-01-07 12:18:28 +01003736 /* correct the front input jack as a mic */
3737 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130);
3738 /* fallthru */
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003739 case STAC_DELL_3ST:
3740 /* GPIO2 High = Enable EAPD */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003741 spec->gpio_mask = spec->gpio_dir = 0x04;
3742 spec->gpio_data = 0x04;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003743 spec->dmic_nids = stac927x_dmic_nids;
3744 spec->num_dmics = STAC927X_NUM_DMICS;
3745
Tobin Davis93ed1502006-09-01 21:03:12 +02003746 spec->init = d965_core_init;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003747 spec->mixer = stac927x_mixer;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003748 spec->dmux_nids = stac927x_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003749 spec->num_dmuxes = ARRAY_SIZE(stac927x_dmux_nids);
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003750 break;
3751 default:
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003752 /* GPIO0 High = Enable EAPD */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003753 spec->gpio_mask = spec->gpio_dir = 0x1;
3754 spec->gpio_data = 0x01;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003755 spec->num_dmics = 0;
3756
Tobin Davis81d3dbd2006-08-22 19:44:45 +02003757 spec->init = stac927x_core_init;
3758 spec->mixer = stac927x_mixer;
3759 }
Matt Porter3cc08dc2006-01-23 15:27:49 +01003760
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003761 spec->num_pwrs = 0;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003762 spec->aloopback_mask = 0x40;
3763 spec->aloopback_shift = 0;
Matthew Ranostay8e9068b2007-12-17 11:58:13 +01003764
Matt Porter3cc08dc2006-01-23 15:27:49 +01003765 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003766 if (!err) {
3767 if (spec->board_config < 0) {
3768 printk(KERN_WARNING "hda_codec: No auto-config is "
3769 "available, default to model=ref\n");
3770 spec->board_config = STAC_D965_REF;
3771 goto again;
3772 }
3773 err = -EINVAL;
3774 }
Mattc7d4b2f2005-06-27 14:59:41 +02003775 if (err < 0) {
3776 stac92xx_free(codec);
3777 return err;
3778 }
Matt2f2f4252005-04-13 14:45:30 +02003779
3780 codec->patch_ops = stac92xx_patch_ops;
3781
Takashi Iwai52987652008-01-16 16:09:47 +01003782 /*
3783 * !!FIXME!!
3784 * The STAC927x seem to require fairly long delays for certain
3785 * command sequences. With too short delays (even if the answer
3786 * is set to RIRB properly), it results in the silence output
3787 * on some hardwares like Dell.
3788 *
3789 * The below flag enables the longer delay (see get_response
3790 * in hda_intel.c).
3791 */
3792 codec->bus->needs_damn_long_delay = 1;
3793
Matt2f2f4252005-04-13 14:45:30 +02003794 return 0;
3795}
3796
Matt Porterf3302a52006-07-31 12:49:34 +02003797static int patch_stac9205(struct hda_codec *codec)
3798{
3799 struct sigmatel_spec *spec;
Takashi Iwai82599802007-07-31 15:56:24 +02003800 int err;
Matt Porterf3302a52006-07-31 12:49:34 +02003801
3802 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3803 if (spec == NULL)
3804 return -ENOMEM;
3805
3806 codec->spec = spec;
Takashi Iwaia4eed132007-07-06 18:17:04 +02003807 spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
Richard Fish11b44bb2006-08-23 18:31:34 +02003808 spec->pin_nids = stac9205_pin_nids;
Takashi Iwaif5fcc132006-11-24 17:07:44 +01003809 spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
3810 stac9205_models,
3811 stac9205_cfg_tbl);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003812 again:
Richard Fish11b44bb2006-08-23 18:31:34 +02003813 if (spec->board_config < 0) {
3814 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
3815 err = stac92xx_save_bios_config_regs(codec);
3816 if (err < 0) {
3817 stac92xx_free(codec);
3818 return err;
3819 }
3820 spec->pin_configs = spec->bios_pin_configs;
3821 } else {
Matt Porterf3302a52006-07-31 12:49:34 +02003822 spec->pin_configs = stac9205_brd_tbl[spec->board_config];
3823 stac92xx_set_config_regs(codec);
3824 }
3825
3826 spec->adc_nids = stac9205_adc_nids;
Maxim Levitsky9e05b7a2007-09-03 15:31:02 +02003827 spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
Matt Porterf3302a52006-07-31 12:49:34 +02003828 spec->mux_nids = stac9205_mux_nids;
Takashi Iwai25494132007-03-12 12:36:16 +01003829 spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
Matt Porter8b657272006-10-26 17:12:59 +02003830 spec->dmic_nids = stac9205_dmic_nids;
Takashi Iwaif6e98522007-10-16 14:27:04 +02003831 spec->num_dmics = STAC9205_NUM_DMICS;
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003832 spec->dmux_nids = stac9205_dmux_nids;
Takashi Iwai1697055e2007-12-18 18:05:52 +01003833 spec->num_dmuxes = ARRAY_SIZE(stac9205_dmux_nids);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01003834 spec->num_pwrs = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02003835
3836 spec->init = stac9205_core_init;
3837 spec->mixer = stac9205_mixer;
3838
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01003839 spec->aloopback_mask = 0x40;
3840 spec->aloopback_shift = 0;
Matt Porterf3302a52006-07-31 12:49:34 +02003841 spec->multiout.dac_nids = spec->dac_nids;
Matthew Ranostay87d48362007-07-17 11:52:24 +02003842
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003843 switch (spec->board_config){
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003844 case STAC_9205_DELL_M43:
Matthew Ranostay87d48362007-07-17 11:52:24 +02003845 /* Enable SPDIF in/out */
3846 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
3847 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
Matt Porter33382402006-12-18 13:17:28 +01003848
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003849 /* Enable unsol response for GPIO4/Dock HP connection */
3850 snd_hda_codec_write(codec, codec->afg, 0,
3851 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
3852 snd_hda_codec_write_cache(codec, codec->afg, 0,
3853 AC_VERB_SET_UNSOLICITED_ENABLE,
3854 (AC_USRSP_EN | STAC_HP_EVENT));
3855
3856 spec->gpio_dir = 0x0b;
3857 spec->gpio_mask = 0x1b;
3858 spec->gpio_mute = 0x10;
Matthew Ranostaye2e7d622008-01-24 15:32:15 +01003859 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003860 * GPIO3 Low = DRM
Matthew Ranostay87d48362007-07-17 11:52:24 +02003861 */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003862 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003863 break;
3864 default:
3865 /* GPIO0 High = EAPD */
Matthew Ranostay4fe51952008-01-29 15:28:44 +01003866 spec->gpio_mask = spec->gpio_dir = 0x1;
3867 spec->gpio_data = 0x01;
Tobin Davisae0a8ed2007-08-13 15:50:29 +02003868 break;
3869 }
Matthew Ranostay87d48362007-07-17 11:52:24 +02003870
Matt Porterf3302a52006-07-31 12:49:34 +02003871 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
Takashi Iwai9e507ab2007-02-08 17:50:10 +01003872 if (!err) {
3873 if (spec->board_config < 0) {
3874 printk(KERN_WARNING "hda_codec: No auto-config is "
3875 "available, default to model=ref\n");
3876 spec->board_config = STAC_9205_REF;
3877 goto again;
3878 }
3879 err = -EINVAL;
3880 }
Matt Porterf3302a52006-07-31 12:49:34 +02003881 if (err < 0) {
3882 stac92xx_free(codec);
3883 return err;
3884 }
3885
3886 codec->patch_ops = stac92xx_patch_ops;
3887
3888 return 0;
3889}
3890
Matt2f2f4252005-04-13 14:45:30 +02003891/*
Guillaume Munch6d859062006-08-22 17:15:47 +02003892 * STAC9872 hack
Takashi Iwaidb064e52006-03-16 16:04:58 +01003893 */
3894
Guillaume Munch99ccc562006-08-16 19:35:12 +02003895/* static config for Sony VAIO FE550G and Sony VAIO AR */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003896static hda_nid_t vaio_dacs[] = { 0x2 };
3897#define VAIO_HP_DAC 0x5
3898static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
3899static hda_nid_t vaio_mux_nids[] = { 0x15 };
3900
3901static struct hda_input_mux vaio_mux = {
Takashi Iwaia3a2f422007-10-11 11:21:21 +02003902 .num_items = 3,
Takashi Iwaidb064e52006-03-16 16:04:58 +01003903 .items = {
Takashi Iwaid7737812006-04-25 13:05:43 +02003904 /* { "HP", 0x0 }, */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003905 { "Mic Jack", 0x1 },
3906 { "Internal Mic", 0x2 },
Takashi Iwaidb064e52006-03-16 16:04:58 +01003907 { "PCM", 0x3 },
3908 }
3909};
3910
3911static struct hda_verb vaio_init[] = {
3912 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02003913 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
Takashi Iwaidb064e52006-03-16 16:04:58 +01003914 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3915 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3916 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3917 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003918 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Takashi Iwaidb064e52006-03-16 16:04:58 +01003919 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3920 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3921 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3922 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3923 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3924 {}
3925};
3926
Guillaume Munch6d859062006-08-22 17:15:47 +02003927static struct hda_verb vaio_ar_init[] = {
3928 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
3929 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
3930 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
3931 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
3932/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
3933 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
Takashi Iwai1624cb92007-07-05 13:10:51 +02003934 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
Guillaume Munch6d859062006-08-22 17:15:47 +02003935 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
3936 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
3937/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
3938 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
3939 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
3940 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
3941 {}
3942};
3943
Takashi Iwaidb064e52006-03-16 16:04:58 +01003944/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003945static struct hda_bind_ctls vaio_bind_master_vol = {
3946 .ops = &snd_hda_bind_vol,
3947 .values = {
3948 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3949 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3950 0
3951 },
3952};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003953
3954/* bind volumes of both NID 0x02 and 0x05 */
Takashi Iwaicca3b372007-08-10 17:12:15 +02003955static struct hda_bind_ctls vaio_bind_master_sw = {
3956 .ops = &snd_hda_bind_sw,
3957 .values = {
3958 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
3959 HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
3960 0,
3961 },
3962};
Takashi Iwaidb064e52006-03-16 16:04:58 +01003963
3964static struct snd_kcontrol_new vaio_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003965 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3966 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Takashi Iwaidb064e52006-03-16 16:04:58 +01003967 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3968 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3969 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3970 {
3971 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3972 .name = "Capture Source",
3973 .count = 1,
3974 .info = stac92xx_mux_enum_info,
3975 .get = stac92xx_mux_enum_get,
3976 .put = stac92xx_mux_enum_put,
3977 },
3978 {}
3979};
3980
Guillaume Munch6d859062006-08-22 17:15:47 +02003981static struct snd_kcontrol_new vaio_ar_mixer[] = {
Takashi Iwaicca3b372007-08-10 17:12:15 +02003982 HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
3983 HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
Guillaume Munch6d859062006-08-22 17:15:47 +02003984 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
3985 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
3986 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
3987 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
3988 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
3989 {
3990 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3991 .name = "Capture Source",
3992 .count = 1,
3993 .info = stac92xx_mux_enum_info,
3994 .get = stac92xx_mux_enum_get,
3995 .put = stac92xx_mux_enum_put,
3996 },
3997 {}
3998};
3999
4000static struct hda_codec_ops stac9872_patch_ops = {
Takashi Iwaidb064e52006-03-16 16:04:58 +01004001 .build_controls = stac92xx_build_controls,
4002 .build_pcms = stac92xx_build_pcms,
4003 .init = stac92xx_init,
4004 .free = stac92xx_free,
Takashi Iwaicb53c622007-08-10 17:21:45 +02004005#ifdef SND_HDA_NEEDS_RESUME
Takashi Iwaidb064e52006-03-16 16:04:58 +01004006 .resume = stac92xx_resume,
4007#endif
4008};
4009
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02004010static int stac9872_vaio_init(struct hda_codec *codec)
4011{
4012 int err;
4013
4014 err = stac92xx_init(codec);
4015 if (err < 0)
4016 return err;
4017 if (codec->patch_ops.unsol_event)
4018 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
4019 return 0;
4020}
4021
4022static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
4023{
Jiang Zhe40c1d302007-11-12 13:05:16 +01004024 if (get_hp_pin_presence(codec, 0x0a)) {
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02004025 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
4026 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
4027 } else {
4028 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
4029 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
4030 }
4031}
4032
4033static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
4034{
4035 switch (res >> 26) {
4036 case STAC_HP_EVENT:
4037 stac9872_vaio_hp_detect(codec, res);
4038 break;
4039 }
4040}
4041
4042static struct hda_codec_ops stac9872_vaio_patch_ops = {
4043 .build_controls = stac92xx_build_controls,
4044 .build_pcms = stac92xx_build_pcms,
4045 .init = stac9872_vaio_init,
4046 .free = stac92xx_free,
4047 .unsol_event = stac9872_vaio_unsol_event,
4048#ifdef CONFIG_PM
4049 .resume = stac92xx_resume,
4050#endif
4051};
4052
Guillaume Munch6d859062006-08-22 17:15:47 +02004053enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
4054 CXD9872RD_VAIO,
4055 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
4056 STAC9872AK_VAIO,
4057 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
4058 STAC9872K_VAIO,
4059 /* AR Series. id=0x83847664 and subsys=104D1300 */
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004060 CXD9872AKD_VAIO,
4061 STAC_9872_MODELS,
4062};
Takashi Iwaidb064e52006-03-16 16:04:58 +01004063
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004064static const char *stac9872_models[STAC_9872_MODELS] = {
4065 [CXD9872RD_VAIO] = "vaio",
4066 [CXD9872AKD_VAIO] = "vaio-ar",
4067};
4068
4069static struct snd_pci_quirk stac9872_cfg_tbl[] = {
4070 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
4071 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
4072 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
Tobin Davis68e22542007-03-12 11:36:39 +01004073 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
Takashi Iwaidb064e52006-03-16 16:04:58 +01004074 {}
4075};
4076
Guillaume Munch6d859062006-08-22 17:15:47 +02004077static int patch_stac9872(struct hda_codec *codec)
Takashi Iwaidb064e52006-03-16 16:04:58 +01004078{
4079 struct sigmatel_spec *spec;
4080 int board_config;
4081
Takashi Iwaif5fcc132006-11-24 17:07:44 +01004082 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
4083 stac9872_models,
4084 stac9872_cfg_tbl);
Takashi Iwaidb064e52006-03-16 16:04:58 +01004085 if (board_config < 0)
4086 /* unknown config, let generic-parser do its job... */
4087 return snd_hda_parse_generic_codec(codec);
4088
4089 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4090 if (spec == NULL)
4091 return -ENOMEM;
4092
4093 codec->spec = spec;
4094 switch (board_config) {
Guillaume Munch6d859062006-08-22 17:15:47 +02004095 case CXD9872RD_VAIO:
4096 case STAC9872AK_VAIO:
4097 case STAC9872K_VAIO:
Takashi Iwaidb064e52006-03-16 16:04:58 +01004098 spec->mixer = vaio_mixer;
4099 spec->init = vaio_init;
4100 spec->multiout.max_channels = 2;
4101 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
4102 spec->multiout.dac_nids = vaio_dacs;
4103 spec->multiout.hp_nid = VAIO_HP_DAC;
4104 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
4105 spec->adc_nids = vaio_adcs;
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004106 spec->num_pwrs = 0;
Takashi Iwaidb064e52006-03-16 16:04:58 +01004107 spec->input_mux = &vaio_mux;
4108 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02004109 codec->patch_ops = stac9872_vaio_patch_ops;
Takashi Iwaidb064e52006-03-16 16:04:58 +01004110 break;
Guillaume Munch6d859062006-08-22 17:15:47 +02004111
4112 case CXD9872AKD_VAIO:
4113 spec->mixer = vaio_ar_mixer;
4114 spec->init = vaio_ar_init;
4115 spec->multiout.max_channels = 2;
4116 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
4117 spec->multiout.dac_nids = vaio_dacs;
4118 spec->multiout.hp_nid = VAIO_HP_DAC;
4119 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
Matthew Ranostaya64135a2008-01-10 16:55:06 +01004120 spec->num_pwrs = 0;
Guillaume Munch6d859062006-08-22 17:15:47 +02004121 spec->adc_nids = vaio_adcs;
4122 spec->input_mux = &vaio_mux;
4123 spec->mux_nids = vaio_mux_nids;
Takashi Iwai72e7b0d2007-08-16 17:33:55 +02004124 codec->patch_ops = stac9872_patch_ops;
Guillaume Munch6d859062006-08-22 17:15:47 +02004125 break;
Takashi Iwaidb064e52006-03-16 16:04:58 +01004126 }
4127
Takashi Iwaidb064e52006-03-16 16:04:58 +01004128 return 0;
4129}
4130
4131
4132/*
Matt2f2f4252005-04-13 14:45:30 +02004133 * patch entries
4134 */
4135struct hda_codec_preset snd_hda_preset_sigmatel[] = {
4136 { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
4137 { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
4138 { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
4139 { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
4140 { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
4141 { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
4142 { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
Matt Porter22a27c72006-07-06 18:49:10 +02004143 { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
4144 { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
4145 { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
4146 { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
4147 { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
4148 { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
Matt Porter3cc08dc2006-01-23 15:27:49 +01004149 { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
4150 { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
4151 { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
4152 { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
4153 { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
4154 { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
4155 { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
4156 { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
4157 { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
4158 { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
Tobin Davis8e21c342007-01-08 11:04:17 +01004159 { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
4160 { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
4161 { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
4162 { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
4163 { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
4164 { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
Guillaume Munch6d859062006-08-22 17:15:47 +02004165 /* The following does not take into account .id=0x83847661 when subsys =
4166 * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
4167 * currently not fully supported.
4168 */
4169 { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
4170 { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
4171 { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
Matt Porterf3302a52006-07-31 12:49:34 +02004172 { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
4173 { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
4174 { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
4175 { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
4176 { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
4177 { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
4178 { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
4179 { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
Matthew Ranostay541eee82007-12-14 12:08:04 +01004180 { .id = 0x111d7674, .name = "92HD73D1X5", .patch = patch_stac92hd73xx },
4181 { .id = 0x111d7675, .name = "92HD73C1X5", .patch = patch_stac92hd73xx },
Matthew Ranostaye1f0d662007-12-13 17:47:21 +01004182 { .id = 0x111d7676, .name = "92HD73E1X5", .patch = patch_stac92hd73xx },
Matthew Ranostay541eee82007-12-14 12:08:04 +01004183 { .id = 0x111d7608, .name = "92HD71BXX", .patch = patch_stac92hd71bxx },
4184 { .id = 0x111d76b0, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
4185 { .id = 0x111d76b1, .name = "92HD71B8X", .patch = patch_stac92hd71bxx },
4186 { .id = 0x111d76b2, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
4187 { .id = 0x111d76b3, .name = "92HD71B7X", .patch = patch_stac92hd71bxx },
4188 { .id = 0x111d76b4, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
4189 { .id = 0x111d76b5, .name = "92HD71B6X", .patch = patch_stac92hd71bxx },
4190 { .id = 0x111d76b6, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
4191 { .id = 0x111d76b7, .name = "92HD71B5X", .patch = patch_stac92hd71bxx },
Matt2f2f4252005-04-13 14:45:30 +02004192 {} /* terminator */
4193};